outlineShader 생성
This commit is contained in:
8
Gameton-06/Assets/Gameton/Art/Material.meta
Normal file
8
Gameton-06/Assets/Gameton/Art/Material.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 3f58676c80e0a5340b2f8593db0ebc38
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
81
Gameton-06/Assets/Gameton/Art/Material/Sprite-Outline.shader
Normal file
81
Gameton-06/Assets/Gameton/Art/Material/Sprite-Outline.shader
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
Shader "Sprites/Outline"
|
||||||
|
{
|
||||||
|
Properties
|
||||||
|
{
|
||||||
|
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
|
||||||
|
_Color ("Tint", Color) = (1,1,1,1)
|
||||||
|
[MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
|
||||||
|
[HideInInspector] _RendererColor ("RendererColor", Color) = (1,1,1,1)
|
||||||
|
[HideInInspector] _Flip ("Flip", Vector) = (1,1,1,1)
|
||||||
|
[PerRendererData] _AlphaTex ("External Alpha", 2D) = "white" {}
|
||||||
|
[PerRendererData] _EnableExternalAlpha ("Enable External Alpha", Float) = 0
|
||||||
|
|
||||||
|
// Add values to determine if outlining is enabled and outline color.
|
||||||
|
[PerRendererData] _Outline("Outline", Float) = 0
|
||||||
|
[PerRendererData] _OutlineColor("Outline Color", Color) = (1,1,1,1)
|
||||||
|
[PerRendererData] _OutlineSize("Outline Size", int) = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
SubShader
|
||||||
|
{
|
||||||
|
Tags
|
||||||
|
{
|
||||||
|
"Queue"="Transparent"
|
||||||
|
"IgnoreProjector"="True"
|
||||||
|
"RenderType"="Transparent"
|
||||||
|
"PreviewType"="Plane"
|
||||||
|
"CanUseSpriteAtlas"="True"
|
||||||
|
}
|
||||||
|
|
||||||
|
Cull Off
|
||||||
|
Lighting Off
|
||||||
|
ZWrite Off
|
||||||
|
Blend One OneMinusSrcAlpha
|
||||||
|
|
||||||
|
Pass
|
||||||
|
{
|
||||||
|
CGPROGRAM
|
||||||
|
#pragma vertex SpriteVert
|
||||||
|
#pragma fragment frag
|
||||||
|
#pragma target 2.0
|
||||||
|
#pragma multi_compile_instancing
|
||||||
|
#pragma multi_compile _ PIXELSNAP_ON
|
||||||
|
#pragma multi_compile _ ETC1_EXTERNAL_ALPHA
|
||||||
|
#include "UnitySprites.cginc"
|
||||||
|
|
||||||
|
float _Outline;
|
||||||
|
fixed4 _OutlineColor;
|
||||||
|
int _OutlineSize;
|
||||||
|
float4 _MainTex_TexelSize;
|
||||||
|
|
||||||
|
fixed4 frag(v2f IN) : SV_Target
|
||||||
|
{
|
||||||
|
fixed4 c = SampleSpriteTexture(IN.texcoord) * IN.color;
|
||||||
|
|
||||||
|
// If outline is enabled and there is a pixel, try to draw an outline.
|
||||||
|
if (_Outline > 0 && c.a != 0) {
|
||||||
|
float totalAlpha = 1.0;
|
||||||
|
|
||||||
|
[unroll(16)]
|
||||||
|
for (int i = 1; i < _OutlineSize + 1; i++) {
|
||||||
|
fixed4 pixelUp = tex2D(_MainTex, IN.texcoord + fixed2(0, i * _MainTex_TexelSize.y));
|
||||||
|
fixed4 pixelDown = tex2D(_MainTex, IN.texcoord - fixed2(0,i * _MainTex_TexelSize.y));
|
||||||
|
fixed4 pixelRight = tex2D(_MainTex, IN.texcoord + fixed2(i * _MainTex_TexelSize.x, 0));
|
||||||
|
fixed4 pixelLeft = tex2D(_MainTex, IN.texcoord - fixed2(i * _MainTex_TexelSize.x, 0));
|
||||||
|
|
||||||
|
totalAlpha = totalAlpha * pixelUp.a * pixelDown.a * pixelRight.a * pixelLeft.a;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (totalAlpha == 0) {
|
||||||
|
c.rgba = fixed4(1, 1, 1, 1) * _OutlineColor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
c.rgb *= c.a;
|
||||||
|
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
ENDCG
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: f22e64e2b31da2d4a994900ca8134d29
|
||||||
|
ShaderImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
defaultTextures: []
|
||||||
|
nonModifiableTextures: []
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
61
Gameton-06/Assets/Gameton/Art/Material/SpriteOutline.cs
Normal file
61
Gameton-06/Assets/Gameton/Art/Material/SpriteOutline.cs
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Unity.VisualScripting;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace TON
|
||||||
|
{
|
||||||
|
[ExecuteInEditMode]
|
||||||
|
public class SpriteOutline : MonoBehaviour
|
||||||
|
{
|
||||||
|
public Color color = Color.white;
|
||||||
|
|
||||||
|
[Range(0, 16)]
|
||||||
|
public int outlineSize = 1;
|
||||||
|
|
||||||
|
private SpriteRenderer spriteRenderer;
|
||||||
|
|
||||||
|
void OnEnable()
|
||||||
|
{
|
||||||
|
spriteRenderer = GetComponent<SpriteRenderer>();
|
||||||
|
|
||||||
|
// UpdateOutline(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// void OnDisable()
|
||||||
|
// {
|
||||||
|
// UpdateOutline(false);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// void Update()
|
||||||
|
// {
|
||||||
|
// UpdateOutline(true);
|
||||||
|
// }
|
||||||
|
|
||||||
|
void OnTriggerEnter2D(Collider2D other)
|
||||||
|
{
|
||||||
|
if (other.CompareTag("Player")) // 플레이어가 접근하면
|
||||||
|
{
|
||||||
|
UpdateOutline(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnTriggerExit2D(Collider2D other)
|
||||||
|
{
|
||||||
|
if (other.CompareTag("Player")) // 플레이어가 나가면
|
||||||
|
{
|
||||||
|
UpdateOutline(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpdateOutline(bool outline)
|
||||||
|
{
|
||||||
|
MaterialPropertyBlock mpb = new MaterialPropertyBlock();
|
||||||
|
spriteRenderer.GetPropertyBlock(mpb);
|
||||||
|
mpb.SetFloat("_Outline", outline ? 1f : 0);
|
||||||
|
mpb.SetColor("_OutlineColor", color);
|
||||||
|
mpb.SetFloat("_OutlineSize", outlineSize);
|
||||||
|
spriteRenderer.SetPropertyBlock(mpb);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Gameton-06/Assets/Gameton/Art/Material/SpriteOutline.cs.meta
Normal file
11
Gameton-06/Assets/Gameton/Art/Material/SpriteOutline.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 5a4f80448bcd1dc408e6351abed25238
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
95
Gameton-06/Assets/Gameton/Art/Material/SpriteOutline.mat
Normal file
95
Gameton-06/Assets/Gameton/Art/Material/SpriteOutline.mat
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!21 &2100000
|
||||||
|
Material:
|
||||||
|
serializedVersion: 8
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_Name: SpriteOutline
|
||||||
|
m_Shader: {fileID: 4800000, guid: f22e64e2b31da2d4a994900ca8134d29, type: 3}
|
||||||
|
m_Parent: {fileID: 0}
|
||||||
|
m_ModifiedSerializedProperties: 0
|
||||||
|
m_ValidKeywords:
|
||||||
|
- PIXELSNAP_ON
|
||||||
|
m_InvalidKeywords: []
|
||||||
|
m_LightmapFlags: 4
|
||||||
|
m_EnableInstancingVariants: 0
|
||||||
|
m_DoubleSidedGI: 0
|
||||||
|
m_CustomRenderQueue: -1
|
||||||
|
stringTagMap: {}
|
||||||
|
disabledShaderPasses: []
|
||||||
|
m_LockedProperties:
|
||||||
|
m_SavedProperties:
|
||||||
|
serializedVersion: 3
|
||||||
|
m_TexEnvs:
|
||||||
|
- _AlphaTex:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _BumpMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _DetailAlbedoMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _DetailMask:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _DetailNormalMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _EmissionMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _MainTex:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _MetallicGlossMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _OcclusionMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _ParallaxMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
m_Ints: []
|
||||||
|
m_Floats:
|
||||||
|
- PixelSnap: 1
|
||||||
|
- _BumpScale: 1
|
||||||
|
- _Cutoff: 0.5
|
||||||
|
- _DetailNormalMapScale: 1
|
||||||
|
- _DstBlend: 0
|
||||||
|
- _EnableExternalAlpha: 0
|
||||||
|
- _GlossMapScale: 1
|
||||||
|
- _Glossiness: 0.5
|
||||||
|
- _GlossyReflections: 1
|
||||||
|
- _Metallic: 0
|
||||||
|
- _Mode: 0
|
||||||
|
- _OcclusionStrength: 1
|
||||||
|
- _Outline: 0
|
||||||
|
- _OutlineSize: 1
|
||||||
|
- _Parallax: 0.02
|
||||||
|
- _SmoothnessTextureChannel: 0
|
||||||
|
- _SpecularHighlights: 1
|
||||||
|
- _SrcBlend: 1
|
||||||
|
- _UVSec: 0
|
||||||
|
- _ZWrite: 1
|
||||||
|
m_Colors:
|
||||||
|
- _Color: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||||
|
- _Flip: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
- _OutlineColor: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
- _RendererColor: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
m_BuildTextureStacks: []
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e0e8dfd090d9b9242a44b05790ed39cd
|
||||||
|
NativeFormatImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
mainObjectFileID: 2100000
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
38
Gameton-06/Assets/Gameton/Scripts/Common/OutlineShader.cs
Normal file
38
Gameton-06/Assets/Gameton/Scripts/Common/OutlineShader.cs
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace TON
|
||||||
|
{
|
||||||
|
public class OutlineShader : MonoBehaviour
|
||||||
|
{
|
||||||
|
public Material outlineMaterial; // 아웃라인 쉐이더 머티리얼
|
||||||
|
public Material originalMaterial;
|
||||||
|
public SpriteRenderer spriteRenderer;
|
||||||
|
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
spriteRenderer = GetComponentInChildren<SpriteRenderer>();
|
||||||
|
if (spriteRenderer != null)
|
||||||
|
{
|
||||||
|
originalMaterial = spriteRenderer.material;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnTriggerEnter2D(Collider2D other)
|
||||||
|
{
|
||||||
|
if (other.CompareTag("Player")) // 플레이어가 접근하면
|
||||||
|
{
|
||||||
|
spriteRenderer.material = outlineMaterial;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnTriggerExit2D(Collider2D other)
|
||||||
|
{
|
||||||
|
if (other.CompareTag("Player")) // 플레이어가 나가면
|
||||||
|
{
|
||||||
|
spriteRenderer.material = originalMaterial;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b916e72c0fb53d646a81ead6f8252799
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Reference in New Issue
Block a user