- Home /
Question by
Dascumaru · Sep 20, 2015 at 07:14 PM ·
shadershadowsurface shadervertex shader
How to get pure black shadow on gradient shader
I need some help with a gradient shader. The code is posted below and it should render the material as a gradient based on the screenspace y position. There's two issues with this code. One, it's probably best to shift it to a vertex (or frag?) calculation instead of doing it all in surface. Second, I want to add a custom lighting model so that all shadows would be pitch-black instead of a darkened shade.
Shader "Custom/shdGrad1" {
Properties {
_ColorLow ("Color Low", COLOR) = (1,1,1,1)
_ColorHigh ("Color High", COLOR) = (1,1,1,1)
_yPosLow ("Y Pos Low", Float) = 0
_yPosHigh ("Y Pos High", Float) = 10
_GradientStrength ("Gradient Strength", Float) = 1
_EmissiveStrength ("Emissive Strengh ", Float) = 1
_ColorX ("Color X", COLOR) = (1,1,1,1)
_ColorY ("Color Y", COLOR) = (1,1,1,1)
}
SubShader {
Tags {
"Queue" = "Geometry"
"RenderType" = "Opaque"
}
CGPROGRAM
#pragma surface surf Lambert addshadow
#define WHITE3 fixed3(1,1,1)
#define UP float3(0,0,1)
#define RIGHT float3(1,0,0)
fixed4 _ColorLow;
fixed4 _ColorHigh;
half _yPosLow;
half _yPosHigh;
half _GradientStrength;
half _EmissiveStrength;
struct Input {
float2 uv_MainTex;
float3 screenPos;
float3 normal;
};
half3 gradient;
half3 finalColor;
void surf (Input IN, inout SurfaceOutput o) {
// gradient color at this height
gradient = lerp(_ColorLow, _ColorHigh, smoothstep( _yPosLow, _yPosHigh, IN.screenPos.y )).rgb;
// lerp the
gradient = lerp(WHITE3, gradient, _GradientStrength);
// add the gradient color
finalColor = gradient;
// scale down to 0-1 values
//finalColor = saturate(finalColor);
// how much should go to emissive
o.Emission = lerp(half3(0,0,0), finalColor, _EmissiveStrength);
// the "color" before lighting is applied
o.Albedo = finalColor * saturate(1 - _EmissiveStrength);
// opaque
o.Alpha = 1;
}
ENDCG
}
fallback "VertexLit"
}
Any advice?
Many thanks to Reddit user CatchCo for the original code.
Comment