- Home /
Reflection and Transparency
Hi,
This shader is a transparency shader with reflection added. Currently it masks the reflection amount based on the base textures alpha - meaning that the higher the transparency, the less the reflection appears; how do I change the reflection power to be only effected by a slider? Or alternativly as well as or instead of; invert the masking effect so that the reflection shows up more, not less, wherever it's most transparent.
Here's the current shader code (thanks amirabiri):
Shader "Transparent/Reflective Specular" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 0)
_Shininess ("Shininess", Range (0.01, 1)) = 0.078125
_ReflectColor ("Reflection Color", Color) = (1,1,1,0.5)
_MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
_Cube ("Reflection Cubemap", Cube) = "_Skybox" { TexGen CubeReflect }
}
SubShader { LOD 300
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}}
CGPROGRAM
#pgragma surface surf BlinnPhong alpha
sampler2D _MainTex;
samplerCUBE_Cube;
fixed4 _Color;
fixed4 _ReflectColor;
half _Shininess;
struct Input {
float2 uv_MainTex;
float3 worldRefl;
};
void surf (Input IN, inout SurfaceOutput o) {
fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
o.Albedo = tex.rgb * _Color.rgb;
o.Gloss = tex.a;
o.Specular = _Shininess;
fixed4 reflcol = texCUBE (_Cube, IN.worldRefl);
reflcol *= tex.a;
o.Emission = reflcol.rgb * _ReflectColor.rgb;
o.Alpha = reflcol.a * _Color.a;
}
ENDCG
}
FallBack "Transparent/Specular"
}
Great Shader! Thank you very much.
...nasty typo, though. It took me well over an hour to spot the extra "g" in #pragma.
Thanks again.
Answer by Venryx · Mar 07, 2013 at 03:50 AM
I could explain how, since I had the same question a few hours ago, but since what I finished sounds about what you're looking for, (except with realtime reflections instead of cubemap ones), I'll just give you a link to its page on the Wiki: http://wiki.unity3d.com/index.php/SurfaceReflection
It requires Unity Pro, though.
If it's not quite what you want, I can try helping you get the original one working.
Answer by Cloud_Sky · Jul 06, 2021 at 11:00 PM
now that this works automatically, I am seeking for how to make it work the opposite way so that I could make glass material...