- Home /
Question by
CremaGames · Mar 05, 2014 at 02:26 PM ·
shaderlightingshadows
Making a shader receive light
I have this shader called Curved and it seems to be some kind of unlit material (I have no idea about shaders). I need it to receive lights and shadows like a regular diffuse shader, is it possible?
Shader "Custom/Curved" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_QOffset ("Offset", Vector) = (0,0,0,0)
_Dist ("Distance", Float) = 100.0
}
SubShader {
Tags { "RenderType"="Opaque" }
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex;
float4 _QOffset;
float _Dist;
struct v2f {
float4 pos : SV_POSITION;
float4 uv : TEXCOORD0;
};
v2f vert (appdata_base v)
{
v2f o;
float4 vPos = mul (UNITY_MATRIX_MV, v.vertex);
float zOff = vPos.z/_Dist;
vPos += _QOffset*zOff*zOff;
o.pos = mul (UNITY_MATRIX_P, vPos);
o.uv = v.texcoord;
return o;
}
half4 frag (v2f i) : COLOR
{
half4 col = tex2D(_MainTex, i.uv.xy);
return col;
}
ENDCG
}
}
FallBack "Diffuse"
}
Comment
Answer by MakeCodeNow · Mar 05, 2014 at 06:55 PM
If you want your shader to work with lights and shadows, you should seriously consider converting this shader to a Surface Shader. Also, note that shaders are a complex topic, so expect to spend some time learning about how they work.