플랫 쉐이딩(Flat Shading):
플랫 쉐이딩은 각 폴리곤의 한 점에서만 광원 계산을 수행합니다. 폴리곤의 모든 픽셀에 동일한 색상을 적용하여 폴리곤의 표면이 단색으로 보입니다. 이는 빠르고 간단하지만 표면이 부드럽게 보이지 않을 수 있습니다. 각 폴리곤마다 색상을 정확하게 계산하므로 가장 간단한 쉐이딩 기법 중 하나입니다.
고로 쉐이딩(Gouraud Shading):
고로 쉐이딩은 폴리곤의 꼭짓점에서 광원 계산을 수행하고 그 사이의 픽셀에 대해 보간을 사용하여 색상을 결정합니다. 이는 플랫 쉐이딩보다 부드럽고 자연스러운 표면을 생성합니다. 폴리곤의 꼭짓점에서의 색상 계산을 통해 보간된 색상이 생성됩니다.
퐁 쉐이딩(Phong Shading):
퐁 쉐이딩은 픽셀마다 광원 계산을 수행합니다. 폴리곤의 각 픽셀에 대해 표면의 노멀 벡터를 계산하여 광원 모델을 적용하고, 이러한 결과를 보간하여 부드러운 표면을 생성합니다. 이는 더 정확하고 자연스러운 결과를 얻을 수 있지만, 계산 비용이 많이 들기 때문에 고로 쉐이딩보다는 성능이 떨어질 수 있습니다.
-Chat GPT
ShaderPhong.shader
[Shader "KCH/08_Phong"
{
Properties
{
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_BumpMap ("NormalMap", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Test noambient
sampler2D _MainTex;
sampler2D _BumpMap;
struct Input
{
float2 uv_MainTex;
float2 uv_BumpMap;
};
void surf (Input IN, inout SurfaceOutput o)
{
fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
o.Alpha = c.a;
}
float4 LightingTest (SurfaceOutput s,
float3 lightDir,
float3 viewDir,
float atten) {
// Specular
float3 H = normalize(lightDir + viewDir);
float spec = saturate(dot(H, s.Normal));
spec = pow(spec, 100);
return spec;
}
ENDCG
}
FallBack "Diffuse"
}
외곽을 추출하는데 퍼포먼스나 편리함이 뛰어나지만
디테일 하지 못하다는 단점이 있다.
퍼포먼스 측면에서는 실제로 두개를 만드는것이 아니라 오직 두개를 그리기만 하게 때문에 퍼포먼스에 큰 영향은 없다.
ShaderNPR2Pass.shader
Shader "KCH/09_NPR2Pass"
{
Properties
{
_MainTex ("Albedo (RGB)", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
cull front
//지금부터 그리는것은 앞부분부터 그릴것이다 라고 하는것이다.
// Pass 1
CGPROGRAM
#pragma surface surf Nolight vertex:vert noshadow noambient
//sufrface surf
//Nolight
//vectext:vert
//noshadow 그림자가 생기면 안되고
//noambient 환경광을 받지 않아야한다.
void vert(inout appdata_full v)
// 파이프라인에 들어온 정보를 전부 다 가져온다.
{
v.vertex.xyz += v.normal.xyz * 0.01;
//지금 버텍스의 xyz 를 노말 방향으로 0.01씩 늘려주는 것이다.
}
struct Input { float4 color:COLOR; };
//버텍스 컬러 빈 것을 만들땐 어쨌든 필요하기 때문에 가져온다.
void surf (Input IN, inout SurfaceOutput o) {}
float4 LightingNolight (SurfaceOutput s, float3 lightDir, float atten) {
return float4(0, 1, 0, 1);
}
ENDCG
cull back
//빽을 컬링
CGPROGRAM
#pragma surface surf Lambert
// 조명은 램버트로
sampler2D _MainTex;
struct Input
{
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o)
{
fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
ShaderNPRShadow.shader
Shader "KCH/09_NPRShadow"
{
Properties
{
_MainTex ("Albedo (RGB)", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
CGPROGRAM
#pragma surface surf Toon noambient
sampler2D _MainTex;
struct Input
{
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o)
{
fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
float4 LightingToon(SurfaceOutput s, float3 lightDir, float atten)
{
float ndotl = dot(s.Normal, lightDir) * 0.5 + 0.5;
//if(ndotl > 0.5) ndotl = 1;
//else ndotl = 0.3;
ndotl = ndotl * 5;
ndotl = ceil(ndotl) / 5;
return ndotl;
}
ENDCG
}
FallBack "Diffuse"
}
ShaderNPRShadow.shader
Shader "KCH/09_NPRShadow"
{
Properties
{
_MainTex ("Albedo (RGB)", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
CGPROGRAM
#pragma surface surf Toon noambient
// Toon 으로 계산
sampler2D _MainTex;
struct Input
{
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o)
{
fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
float4 LightingToon(SurfaceOutput s, float3 lightDir, float atten)
{
float ndotl = dot(s.Normal, lightDir) * 0.5 + 0.5;
if(ndotl > 0.5) ndotl = 1;
else ndotl = 0.3;
// ndotl = ndotl * 5;
// ndotl = ceil(ndotl) / 5;
return ndotl;
}
ENDCG
}
FallBack "Diffuse"
}
ShaderNRPFresnel.shader
Shader "KCH/09_NPRFresnel"
{
Properties
{
_MainTex ("Albedo (RGB)", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
CGPROGRAM
#pragma surface surf Toon noambient
sampler2D _MainTex;
struct Input
{
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o)
{
fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
float4 LightingToon(SurfaceOutput s, float3 lightDir, float3 viewDir, float atten)
{
float ndotl = dot(s.Normal, lightDir) * 0.5 + 0.5;
if(ndotl > 0.5) ndotl = 1;
else ndotl = 0.3;
float rim = abs(dot(s.Normal, viewDir));
if (rim > 0.3) rim = 1;
else rim = -1;
float4 final;
final.rgb = s.Albedo * ndotl * _LightColor0.rgb * rim;
final.a = s.Alpha;
return final;
}
ENDCG
}
FallBack "Diffuse"
}
ShaderDiffuseWarping.shader
Shader "KCH/10_DiffuseWarping"
{
Properties
{
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_RampTex ("RampTex", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
CGPROGRAM
#pragma surface surf Warp noambient
sampler2D _MainTex;
sampler2D _RampTex;
struct Input
{
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o)
{
fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
float4 LightingWarp(SurfaceOutput s, float3 lightDir, float atten)
{
float ndotl = dot(s.Normal, lightDir) * 0.5 + 0.5;
float4 ramp = tex2D(_RampTex, float2(ndotl, 0.5));
return ramp;
}
ENDCG
}
FallBack "Diffuse"
}
ShaderCubemap.shader
Shader "KCH/11_Cubemap"
{
Properties
{
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_BumpMap ("NormalMap", 2D) = "bump" {}
_Cube ("CubeMap", Cube) = "" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
CGPROGRAM
#pragma surface surf Lambert noambient
sampler2D _MainTex;
sampler2D _BumpMap;
samplerCUBE _Cube;
struct Input
{
float2 uv_MainTex;
float2 uv_BumpMap;
float3 worldRefl;
INTERNAL_DATA
};
void surf (Input IN, inout SurfaceOutput o)
{
o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
float4 re = texCUBE(_Cube, WorldReflectionVector(IN, o.Normal));
o.Albedo = c.rgb * 0.5;
o.Emission = re.rgb * 0.5;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
ShaderMaskMap.shader
Shader "KCH/12_MaskMap"
{
Properties
{
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_BumpMap ("NormalMap", 2D) = "bump" {}
_MaskMap ("MaskMap", 2D) = "white" {}
_Cube ("CubeMap", Cube) = "" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
CGPROGRAM
#pragma surface surf Lambert noambient
sampler2D _MainTex;
sampler2D _BumpMap;
sampler2D _MaskMap;
samplerCUBE _Cube;
struct Input
{
float2 uv_MainTex;
float2 uv_BumpMap;
float2 uv_MaskMap;
float3 worldRefl;
INTERNAL_DATA
};
void surf (Input IN, inout SurfaceOutput o)
{
o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
float4 re = texCUBE(_Cube, WorldReflectionVector(IN, o.Normal));
float4 m = tex2D(_MaskMap, IN.uv_MaskMap);
o.Albedo = c.rgb * (1 - m.r);
o.Emission = re.rgb * m.r;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
ShaderAlpha.shader
Shader "KCH/13_Alpha"
{
SubShader {
Tags { "RenderType"="Opaque" }
CGPROGRAM
#pragma surface surf Lambert noambient noshadow
sampler2D _CameraDepthTexture;
struct Input {
float4 screenPos;
};
void surf (Input IN, inout SurfaceOutput o) {
float2 sPos = float2(IN.screenPos.x, IN.screenPos.y) / IN.screenPos.w;
float4 Depth = tex2D(_CameraDepthTexture, sPos);
o.Emission = Depth.r;
}
ENDCG
}
FallBack off
}
ShaderAlphaBlending.shader
Shader "KCH/13_AlphaBlending"
{
Properties
{
_MainTex ("Albedo (RGB)", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Transparent" "Queue"="Transparent" }
cull off
zwrite off
CGPROGRAM
#pragma surface surf Lambert alpha:fade
sampler2D _MainTex;
struct Input
{
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o)
{
fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Legacy Shaders/Transparent/VertexLit"
}
ShaderAlphaCutout.shader
Shader "KCH/13_AlphaCutout"
{
Properties {
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Cutoff ("Alpha cutoff", Range(0, 1)) = 0.5
}
SubShader {
Tags { "RenderType"="TransparentCutout" "Queue"="AlphaTest" }
CGPROGRAM
#pragma surface surf Lambert alphatest:_Cutoff
sampler2D _MainTex;
struct Input
{
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o)
{
fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Transparent/Cutout/Diffuse"
}
ShaderWave.shader ( ShockWave)
Shader "KCH/14_Wave"
{
Properties
{
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_RefStrength ("Reflection Strengrh", Range(0, 0.1)) = 0.05
}
SubShader
{
Tags { "RenderType"="Opaque" }
zwrite off
GrabPass{}
CGPROGRAM
#pragma surface surf Nolight noambient alpha:fade
sampler2D _GrabTexture;
sampler2D _MainTex;
float _RefStrength;
struct Input
{
float4 color:COLOR;
float4 screenPos;
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o)
{
float4 ref = tex2D(_MainTex, IN.uv_MainTex);
float3 screenUV = IN.screenPos.rgb / IN.screenPos.a;
//o.Emission = float3(screenUV.xy, 0);
//o.Emission = tex2D(_GrabTexture, screenUV.xy);
o.Emission = tex2D(_GrabTexture, (screenUV.xy + ref.x * _RefStrength));
}
float4 LightingNolight(SurfaceOutput s, float3 lightDir, float atten) {
return float4(0,0,0,1);
}
ENDCG
}
FallBack "Legacy Shaders/Transparent/Vertexlit"
}
ShaderDissolve.shader
Shader "KCH/15_Dissolve"
{
Properties
{
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_NoiseTex ("NoiseTex", 2D) = "white" {}
_Cut ("Alpha Cut", Range(0, 1)) = 0
[HDR]_OutColor ("OutColor", Color) = (1, 1, 1, 1)
}
SubShader
{
Tags { "RenderType"="Transparent" "Queue"="Transparent" }
CGPROGRAM
#pragma surface surf Lambert alpha:fade
sampler2D _MainTex;
sampler2D _NoiseTex;
float _Cut;
float4 _OutColor;
struct Input
{
float2 uv_MainTex;
float2 uv_NoiseTex;
};
void surf (Input IN, inout SurfaceOutput o)
{
float4 c = tex2D(_MainTex, IN.uv_MainTex);
float4 noise = tex2D(_NoiseTex, IN.uv_NoiseTex);
o.Albedo = c.rgb;
float alpha;
if (noise.r >= _Cut) alpha = 1;
else alpha = 0;
float outline;
if (noise.r >= _Cut * 1.5) outline = 0;
else outline = 1;
o.Emission = outline * _OutColor.rgb;
o.Alpha = alpha;
}
ENDCG
}
FallBack "Diffuse"
}