Quantcast
Channel: Questions in topic: "mirrorreflection"
Viewing all articles
Browse latest Browse all 98

Complete Flat Mirror Reflection shader

$
0
0

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!


Viewing all articles
Browse latest Browse all 98

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>