Shader "ryoo/DiffuseShader1"
{
Properties
{
_DiffuseTex ("Texture", 2D) = "white" {}
_Color("Color",Color) = (1,0,0,1)
_Ambient("Ambient",Range(0,1)) = 0.25
}
SubShader
{
Tags { "LightMode"="ForwardBase" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#include "UnityLightingCommon.cginc"
struct appdata
{
float4 vertex : POSITION;
float3 normal : NORMAL;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
float4 worldNormal : TEXCOORD1;
};
sampler2D _DiffuseTex;
float4 _DiffuseTex_ST;
fixed4 _Color;
float _Ambient;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _DiffuseTex);
float3 worldNormal = UnityObjectToWorldNormal(v.normal);
//o. worldNormal = worldNormal;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
float3 normalDirection = normalize(i.worldNormal);
float4 tex = tex2D(_DiffuseTex, i.uv);
float nl = max(_Ambient, dot(normalDirection, _WorldSpaceLightPos0.xyz));
float4 diffuseTerm = nl * _Color * tex *_LightColor0;
return diffuseTerm;
}
ENDCG
}
}
}
참고서적: 유니티 물리 기반 셰이더 개발
'Unity > Code base Shader' 카테고리의 다른 글
Specular 다 광원지원 (0) | 2020.12.21 |
---|---|
SpecularShader (0) | 2020.12.19 |
좌표공간 변환 (0) | 2020.12.12 |
내적(dot) (0) | 2020.12.12 |
UnlitShader (0) | 2020.12.11 |