- Home /
A shader with transparent lit area
Hi there, I found this shader on the forums, it works well, but I need one that does the inverse: The 'non-lit' areas need to be opaque and the lit areas completely transparent. I'm really struggling with shaders. Could someone help me understand how to adapt it?
Shader "Lighting Only"
{
Properties
{
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader
{
Blend SrcAlpha One
ZWrite Off
Tags {Queue = Transparent}
ColorMask RGB
// Vertex lights
Pass
{
Tags {"LightMode" = "Vertex"}
Lighting On
Material
{
Diffuse [_Color]
}
SetTexture [_MainTex]
{
constantColor [_Color]
Combine texture * primary DOUBLE, texture * constant
}
}
}
Fallback "VertexLit", 2
}
Edit
Image for ScroodgeM:
Hey, this is what I get :/ Light is from left to right. There's another sphere inside, you can see it with the gizmo's on... but it doesn't appear visible through the outer sphere. I'm not sure why this is...
I was actually needing this "Lighting Only" shader, couldn't find it anywhere since i wasn't sure what to search for, thanks!
Answer by ScroodgeM · Jul 14, 2012 at 09:16 AM
Shader "Lighting Only"
{
Properties
{
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader
{
Blend SrcAlpha One
ZWrite Off
Tags
{
Queue = Transparent
}
ColorMask RGB
CGPROGRAM
#pragma surface surf MyLight alpha finalcolor:mycolor
sampler2D _MainTex;
fixed4 _Color;
struct Input
{
float2 uv_MainTex;
};
void surf(Input IN, inout SurfaceOutput o)
{
fixed4 tex = tex2D(_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = tex.rgb;
o.Alpha = tex.a;
}
float lightPower;
fixed4 LightingMyLight(SurfaceOutput s, half3 lightDir, fixed atten)
{
lightPower = 1 - saturate(dot(normalize(s.Normal), lightDir));
return fixed4((s.Albedo * _LightColor0.rgb) * (lightPower * atten * 2), 1);
}
void mycolor(Input IN, SurfaceOutput o, inout fixed4 color)
{
color.a = o.Alpha * lightPower;
}
ENDCG
}
Fallback "VertexLit", 2
}
edit 15.07.2012
on this screen two spheres. one inside other. small sphere have white opaque material (diffuse) and the second have this shader colored to red. light direction is right-to-left on screen. lighted surface is transparent on red sphere because lighted and we can see second one.
Hi Scroodge$$anonymous$$! Thanks for the edit, but it doesn't seem to produce the correct result. The object is lit in reverse which is what I wanted... but the unlit sections need to be transparent, which is my main problem at the moment. Do you know how I could edit what you've given me to produce that effect? Cheers!
in my example lighted surface is 100% transparent, not lighted is opaque (0%), that is reverse of your first example - there's lighted surface is 100% opaque and unlighted is 100% transparent
how can i reverse your first example (where unlit surface is transparent) and at the same time leave unlit sections in transparent as you said in last comment? 8)
I fear I am confusing myself... I think I wrote my last comment wrong so I'm going to write it all out and see if I can work out what I need. $$anonymous$$y first shader had:
Opaque and coloured lit areas
Transparent and black unlit areas
The shader you adapted for me has:
Opaque and black lit areas
Opaque and coloured unlit areas
The shader is only half there, the coloured 'highlight' is in the right place (on the unlit side) but the lit side remains opaque and cannot be seen through. Sorry if I'm making this really complicated. Do you know if I can places where I can learn how to do this myself?
look edit in answer (comment doesn't allow pictures)
what platform do you use?
Hi, I responded to your image by editing my original post... our images aren't the same though. :( Erm, I'm using Windows XP.
Your answer
Follow this Question
Related Questions
Transparent Shader Render Order Issue 0 Answers
Can i force a renderer with standard shader material to crossfade? 0 Answers
Transparent w/ Full Shadowcasting in Unity 5 1 Answer
Transparent Objects within Transparent Objects 1 Answer
Why my 2d character would not be displayed correctly at the very beginning? 0 Answers