- Home /
Complete Flat Mirror Reflection shader
Greetings. I posted this on a topic on Unity comunity, but with no answers. So, I thought I'd post it here instead.
I've been testing the pro version, and I'm developing some small demos. There's a high probability that the company I'm working for will aquire a license, but I just have 3 trial days left ...
I'm trying to come up with a working mirror reflection shader, with reflection value, and most important, which still receives shadows!
Seems no one has come up with one, so I tried using my limited "code hacking" abilities and came up with a shader that does this. Problem is, and that's due to my ignorance, I can't "assign" the projection matrix to the reflection texture!
Shader "Reflective/Mirror Diffuse" { Properties { _Color ("Main Color", Color) = (1,1,1,1) _ReflectColor ("Reflection Color", Color) = (1,1,1,0.5) _MainTex ("Base (RGB) RefStrength (A)", 2D) = "white" {} _ReflectionTex ("Reflection", 2D) = "white" { TexGen ObjectLinear } } SubShader { LOD 200 Tags { "RenderType"="Opaque" }
CGPROGRAM #pragma surface surf Lambert
sampler2D _MainTex; sampler2D _ReflectionTex; //samplerCUBE _Cube;
float4 _Color; float4 _ReflectColor;
struct Input { float2 uv_MainTex; float2 uv_ReflectionTex; //float2 p_ProjectionMatrix; //float3 worldRefl; };
void surf (Input IN, inout SurfaceOutput o) { half4 tex = tex2D(_MainTex, IN.uv_MainTex); half4 c = tex * _Color; o.Albedo = c.rgb;
//half4 reflcol = texCUBE (_Cube, IN.worldRefl);
half4 reflcol = tex2D (_ReflectionTex, IN.uv_ReflectionTex);
//half4 reflcol = tex2D (_ReflectionTex, IN.worldRefl);
//half4 reflcol = tex2D (_ReflectionTex, IN.p_ProjectionMatrix);
reflcol *= tex.a;
o.Emission = reflcol.rgb * _ReflectColor.rgb;
o.Alpha = reflcol.a * _ReflectColor.a;
} ENDCG }
FallBack "Reflective/VertexLit" }
Obviously, the "IN.uv_ReflectionTex" is wrong. Now, on the mirror shader, I see a " matrix [_ProjMatrix] " on the _ReflectionTex SetTexture part, and this seems to be what I'm looking for.
But how can I access this correct projection matrix from within the CGPROGRAM shader section?
If anybody can give a helping hand, would be very thankfull, as I'm sure many more users!
just an idea ( Really could be a terrible idea of $$anonymous$$e) but if you ask a question in several places. You may end up with people giving double answers (or big similar scripts) $$anonymous$$aybe (and just maybe :D) it's smart to link all Q&A together referencing each other like peer to peer network. I would be pretty bummed to write a big answer just to find out John Doe wrote a slightly better one 10 seconds ago on the other site that looks just like $$anonymous$$e.
Heh! You're probably right, I'm not very handy with this intertubes stuff ;)
Still, on my behalf, I said I'm in a tight schedule (3 days), so...
And, if such double answering would occur, I'd be sure to update both threads with the correct answer ...
Anyway, this Unity forums and community stuff (not to mention Unity itself) is really new to me, and it can get overwhel$$anonymous$$g. Sorry for the incorrectness :)