- Home /
shader for soft shadow on the inside
I am trying to create a shader that has a outline-like property, that applies a soft contour for an object. As you can see in the image, the shadow is applied on the inside of the object (please ignore the outer shadow).
I was able to create a radial effect, but that's not what i need. Here is the shader:
Shader "Custom/GradientToEdges" {
Properties
{
_Color ("_Color", Color) = (1,1,1,1)
_FinalEdgeColor ("_FinalEdgeColor", Color) = (1,1,1,1)
_MainTex ("Base (RGB)", 2D) = "white" {}
_OutlineColor ("Outline Color", Color) = (0,0,0,1)
_Outline ("Outline width", Range (0.0, 0.3)) = 0
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
void surf (Input IN, inout SurfaceOutput o)
{
half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
// half lum = c.r*.3 + c.g*.59 + c.b*.11;
//half3 bw = half3( lum, lum, lum );
o.Normal = (.5,.5,.5);
half xpow = (IN.uv_MainTex.x - .5f)*(IN.uv_MainTex.x - .5f);
half ypow = (IN.uv_MainTex.y - .5f)*(IN.uv_MainTex.y - .5f);
half radius =.3f;
half multiply = 1f/(1 - radius);
half3 finalDestCol = (c[0] - .2, c[1] - .2, c[2]-.2);
finalDestCol = (.2,.2,.2);
finalDestCol = _FinalEdgeColor.rgb;
if(sqrt(xpow + ypow) > radius && sqrt(xpow + ypow) <1)
{
c.rgb = lerp(c.rgb,finalDestCol, multiply*(sqrt(xpow + ypow) - radius));
o.Albedo = c;
}
//else
else if(sqrt(xpow+ypow)>1)
o.Albedo = finalDestCol;
else
o.Albedo = c;
o.Alpha = c.a;
}
ENDCG
}
Fallback "VertexLit"
}
Also, to be mentioned, i have an orthographic camera
i dunno about prgram$$anonymous$$g shaders but maybe lookin at the shield shader on the wiki can help?
Your answer
![](https://koobas.hobune.stream/wayback/20220613121946im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to use Camera.RenderWithShader() to modify rendered image? 0 Answers
How to make a submesh from part of my character 1 Answer
angrybot water shader lagging problem 0 Answers
Clamp cone shape from shader alpha 0 Answers
Unlit "diffuse" shader 2 Answers