- Home /
How to achieve shadows in custom Vertex/Frag shaders?
Hi I am working on a custom vertex shader which gives the world objects a curve effect. But unfortunately when i use this shader in all the object in the scene, the objects doesn't show shadows.
I tried adding a second cast/collect shadow pass to the sub shader using the example in this manual: Vertex and Fragment shader Examples But it doesn't show shadows.
My custom vertex shaders is:
Shader "Custom/Curve/Normal"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_QOffset ("Offset", Vector) = (0,0,0,0)
_Dist ("Distance", Float) = 100.0
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// make fog work
#pragma multi_compile_fog
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST, _QOffset;
float _Dist;
v2f vert (appdata v)
{
v2f o;
float4 vPos = mul (UNITY_MATRIX_MV, v.vertex);
float zOff = vPos.z/_Dist;
vPos += _QOffset*zOff*zOff;
o.vertex = mul (UNITY_MATRIX_P, vPos);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
// sample the texture
fixed4 col = tex2D(_MainTex, i.uv);
// apply fog
UNITY_APPLY_FOG(i.fogCoord, col);
return col;
}
ENDCG
}
}
Fallback "Diffuse"
}
I am achieving the desired curve effect in the world using the suggested technique mentioned in this link: How to make plane look curved?
How to do I achieve shadows now using another pass and also have the desired curve effect?
Unity Vesrsion Used: 5.4.2f2 Personal
Your answer
Follow this Question
Related Questions
Have a problem about receiving shadows 1 Answer
How to access array elements in Surface Vertex shaders? 0 Answers
Need to get lighting to work on bending vertex shader... 1 Answer
How to modify shadows with an image effect 0 Answers
Is it possible to get shadows of each light in seperate channel ? 0 Answers