게임개발/게임 그래픽 프로그래밍
Diffuse Warping 기법2
pudding81
2024. 2. 22. 12:16
Normal Map
Shader "Custom/NormalWarp2"
{
Properties
{
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_RampTex ("Ramp", 2D) = "white" {}
_BumpMap("Normalmap",2D) ="bump"{}
}
SubShader
{
Tags { "RenderType"="Opaque" }
CGPROGRAM
#pragma surface surf _Warp //커스텀라이트
#pragma target 3.0
sampler2D _MainTex;
sampler2D _RampTex;
sampler2D _BumpMap;
struct Input
{
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o)
{
fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
//노멀맵
fixed4 n =tex2D (_BumpMap,IN.uv_MainTex);
o.Normal =UnpackNormal(n);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
//커스텀라이트
float4 Lighting_Warp(SurfaceOutput s,float3 lightDir,float atten)
{
//Lambert
float ndotl =dot(s.Normal,lightDir);
// Warping 기법
float2 uv = float2(ndotl,0.5);
float4 ramp = tex2D(_RampTex,uv);
float4 final;
final.rgb=ramp.rgb*s.Albedo;
final.a=s.Alpha;
return final;
}
ENDCG
}
FallBack "Diffuse"
}
2pass 외곽선 + RampTex
Shader "Custom/2PassWarp3"
{
Properties
{
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_RampTex ("Ramp", 2D) = "white" {}
_BumpMap("Normalmap",2D) ="bump"{}
}
SubShader
{
Tags { "RenderType"="Opaque" }
//1pass
Cull Front
CGPROGRAM
#pragma surface surf _Warp vertex:vert//vertex
#pragma target 3.0
struct Input
{
float4 color :COLOR;
};
void vert(inout appdata_full v)
{
v.vertex.xyz = v.vertex.xyz +v.normal.xyz*0.01; //line size
}
void surf (Input IN, inout SurfaceOutput o)
{
}
//커스텀라이트
float4 Lighting_Warp(SurfaceOutput s,float3 lightDir,float atten)
{
return float4(0,0,0,1); //line color
}
ENDCG
//2pass
Cull Back
CGPROGRAM
#pragma surface surf _Warp //커스텀라이트
#pragma target 3.0
sampler2D _MainTex;
sampler2D _RampTex;
sampler2D _BumpMap;
struct Input
{
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o)
{
fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
//노멀맵
fixed4 n =tex2D (_BumpMap,IN.uv_MainTex);
o.Normal =UnpackNormal(n);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
//커스텀라이트
float4 Lighting_Warp(SurfaceOutput s,float3 lightDir,float atten)
{
//Lambert
float ndotl =dot(s.Normal,lightDir);
//음영을 여러단계로
ndotl *=5;
ndotl =ceil(ndotl)/5;
// Warping 기법
float2 uv = float2(ndotl,0.5);
float4 ramp = tex2D(_RampTex,uv);
float4 final;
final.rgb=ramp.rgb*s.Albedo;
final.a=s.Alpha;
return final;
}
ENDCG
}
FallBack "Diffuse"
}
Fresnel 외곽선 + RampTex 적용하기
Shader "Custom/RimWarp4"
{
Properties
{
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_RampTex ("Ramp", 2D) = "white" {}
_BumpMap("Normalmap",2D) ="bump"{}
_Outline("Outline",Range(0,1))=0.1
}
SubShader
{
Tags { "RenderType"="Opaque" }
CGPROGRAM
#pragma surface surf _Warp //커스텀라이트
#pragma target 3.0
sampler2D _MainTex;
sampler2D _RampTex;
sampler2D _BumpMap;
float _Outline;
struct Input
{
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o)
{
fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
//노멀맵
fixed4 n =tex2D (_BumpMap,IN.uv_MainTex);
o.Normal =UnpackNormal(n);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
//커스텀라이트
float4 Lighting_Warp(SurfaceOutput s,float3 lightDir,float3 viewDir, float atten)
{
//Lambert
float ndotl =dot(s.Normal,lightDir);
// line Rim
float rim = dot(s.Normal,viewDir);
if(rim>0.3) rim=1;
else rim =-1;
// Warping 기법
float2 uv = float2(ndotl,0.5);
float4 ramp = tex2D(_RampTex,uv);
float4 final;
final.rgb=ramp.rgb*s.Albedo*rim;
final.a=s.Alpha;
return final;
}
ENDCG
}
FallBack "Diffuse"
}
2pass 외곽선 + RampTex +Specular
Shader "Custom/Specular Warp5"
{
Properties
{
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_RampTex ("Ramp", 2D) = "white" {}
_BumpMap("Normalmap",2D) ="bump"{}
}
SubShader
{
Tags { "RenderType"="Opaque" }
//1pass
Cull Front
CGPROGRAM
#pragma surface surf _Warp vertex:vert//vertex
#pragma target 3.0
struct Input
{
float4 color :COLOR;
};
void vert(inout appdata_full v)
{
v.vertex.xyz = v.vertex.xyz +v.normal.xyz*0.01; //line size
}
void surf (Input IN, inout SurfaceOutput o)
{
}
//커스텀라이트
float4 Lighting_Warp(SurfaceOutput s,float3 lightDir,float atten)
{
return float4(0,0,0,1); //line color
}
ENDCG
//2pass
Cull Back
CGPROGRAM
#pragma surface surf _Warp //커스텀라이트
#pragma target 3.0
sampler2D _MainTex;
sampler2D _RampTex;
sampler2D _BumpMap;
struct Input
{
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o)
{
fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
//노멀맵
fixed4 n =tex2D (_BumpMap,IN.uv_MainTex);
o.Normal =UnpackNormal(n);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
//커스텀라이트
float4 Lighting_Warp(SurfaceOutput s,float3 lightDir,float3 viewDir, float atten)
{
//Lambert
float ndotl =dot(s.Normal,lightDir);
//음영을 여러단계로
ndotl *=5;
ndotl =ceil(ndotl)/5;
//spec
float3 h =normalize(lightDir+viewDir);
float spec =saturate(dot(s.Normal,h));
spec = pow(spec,150); //150제곱
// Warping 기법
float2 uv = float2(ndotl,0.5);
float4 ramp = tex2D(_RampTex,uv);
float4 final;
final.rgb=ramp.rgb*s.Albedo+spec;
final.a=s.Alpha;
return final;
}
ENDCG
}
FallBack "Diffuse"
}