Notice
Recent Posts
Recent Comments
Link
스토리지
[5.3] Shader 연습 1 본문
Test1.shader
Shader "Custom/Test"
{
Properties
{
_MainTex ("Albedo (RGB)", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Standard fullforwardshadows
sampler2D _MainTex;
struct Input
{
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutputStandard o)
{
fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
Test2.shader
Shader "Custom/Test2"
{
Properties
{
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_SubTex ("Albedo (RGB)", 2D) = "white" {}
_LerpRatio ("Lerp Ratio", Range(0,1)) = 0
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Standard fullforwardshadows
sampler2D _MainTex;
sampler2D _SubTex;
float _LerpRatio;
struct Input
{
float2 uv_MainTex;
float2 uv_SubTex;
};
void surf (Input IN, inout SurfaceOutputStandard o)
{
fixed4 m = tex2D (_MainTex, IN.uv_MainTex);
fixed4 s = tex2D(_SubTex, IN.uv_SubTex);
o.Albedo = lerp(m.rgb, s.rgb, _LerpRatio);
}
ENDCG
}
FallBack "Diffuse"
}
Test3.shader
Shader "Custom/Test3"
{
Properties
{
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_SubTex("Albedo (RGB)", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Standard fullforwardshadows
sampler2D _MainTex;
sampler2D _SubTex;
struct Input
{
float2 uv_MainTex;
float2 uv_SubTex;
};
void surf (Input IN, inout SurfaceOutputStandard o)
{
fixed4 m = tex2D (_MainTex, IN.uv_MainTex);
fixed4 s = tex2D(_SubTex, IN.uv_SubTex);
o.Albedo = lerp(m.rgb, s.rgb, 1 - m.a);
}
ENDCG
}
FallBack "Diffuse"
}
* Lerp Function
lerp - returns linear interpolation of two scalars or vectors based on a weight
developer.download.nvidia.com/cg/lerp.html
lerp
Name lerp - returns linear interpolation of two scalars or vectors based on a weight Synopsis float lerp(float a, float b, float w); float1 lerp(float1 a, float1 b, float1 w); float2 lerp(float2 a, float2 b, float2 w); float3 lerp(float3 a, float3 b, float
developer.download.nvidia.com
lerp(a,b,w) => a + w * ( b - a )
땅 색깔 바꾸기
Test3.shader
Shader "Custom/Test3"
{
Properties
{
_MainTex("Albedo (RGB)", 2D) = "white" {}
_SubTex("Albedo (RGB)", 2D) = "white" {}
_Brightness("Brightness", Range(0,1)) = 0
}
SubShader
{
Tags { "RenderType" = "Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Standard fullforwardshadows
sampler2D _MainTex;
sampler2D _SubTex;
float _Brightness;
struct Input
{
float2 uv_MainTex;
float2 uv_SubTex;
};
void surf(Input IN, inout SurfaceOutputStandard o)
{
fixed4 m = tex2D(_MainTex, IN.uv_MainTex);
fixed4 s = tex2D(_SubTex, IN.uv_SubTex);
o.Albedo = lerp(m.rgb, s.rgb * float3(1, _Brightness, 0), 1 - m.a);
}
ENDCG
}
FallBack "Diffuse"
}
땅 색갈을 흑백으로 만들기
Shader "Custom/Test3"
{
Properties
{
_MainTex("Albedo (RGB)", 2D) = "white" {}
_SubTex("Albedo (RGB)", 2D) = "white" {}
_Brightness("Brightness", Range(0,1)) = 0
}
SubShader
{
Tags { "RenderType" = "Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Standard fullforwardshadows
sampler2D _MainTex;
sampler2D _SubTex;
float _Brightness;
struct Input
{
float2 uv_MainTex;
float2 uv_SubTex;
};
void surf(Input IN, inout SurfaceOutputStandard o)
{
fixed4 m = tex2D(_MainTex, IN.uv_MainTex);
fixed4 s = tex2D(_SubTex, IN.uv_SubTex);
o.Albedo = lerp(m.rgb, (s.r + s.g + s.b) / 3 * _Brightness, 1 - m.a);
}
ENDCG
}
FallBack "Diffuse"
}
'Unity > Shader' 카테고리의 다른 글
[5.3] UV _Time (0) | 2021.05.03 |
---|---|
[5.3] UV (0) | 2021.05.03 |
[5.3] Shader, Texture 받아오기 (0) | 2021.05.03 |
[5.3] ShaderLab (0) | 2021.05.03 |
[5.3] Shader (0) | 2021.05.03 |
Comments