I am trying to create an effect that resembles polished marble, something very similar to the mirror setup found here.
This provides me with the realtime reflection I need, but I’d like to use a fragment shader to apply it to the surface so that I can have greater control over how the textures are blended/distorted. So far I have the following:
Shader "Playmat/Marble"
{
Properties
{
_MainTex ("Base (RGB)", 2D) = "white" {}
_ReflectionTex ("Reflection", 2D) = "white" { TexGen ObjectLinear }
}
SubShader
{
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex;
float4 _MainTex_ST;
sampler2D _ReflectionTex;
float4x4 _ProjMatrix;
struct appdata
{
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
};
struct v2f
{
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
};
v2f vert (appdata v)
{
v2f o;
o.pos = mul( UNITY_MATRIX_MVP, v.vertex );
o.uv = TRANSFORM_TEX( v.texcoord, _MainTex );
return o;
}
half4 frag( v2f i ) : COLOR
{
half4 c = tex2D(_MainTex, i.uv);
//Get Reflection color here
//half4 r = tex2D(_ReflectionTex, ??);
//combine with magic
return c;
}
ENDCG
}
}
}
Unfortunately I’m at a loss as to how to use the projection matrix to generate the UVs I would need to sample for the reflection texture. Any help would be appriciated.