I'm trying to make a floor with a wood texture and a reflection. It's works for my using the mirror reflection shader from Unity Community. But, i need to include shadows and i don't have idea how to do it. Thanks.
I got it, only modify the shader:
Shader "FX/Mirror Reflection" {
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) = "_Skybox" { TexGen ObjectLinear }
}
SubShader {
LOD 200
Tags { "RenderType"="Opaque" }
Pass {
Name "BASE"
Tags {"LightMode" = "Always"}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_fog_exp2
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
struct v2f {
V2F_POS_FOG;
float2 uv : TEXCOORD0;
float3 uv2 : TEXCOORD1;
};
uniform float4 _MainTex_ST;
uniform float3x3 _ProjMatrix;
v2f vert(appdata_tan v)
{
v2f o;
PositionFog( v.vertex, o.pos, o.fog );
float3 viewDir = ObjSpaceViewDir( v.vertex );
o.uv2 = mul( _ProjMatrix, viewDir );
o.uv = TRANSFORM_TEX(v.texcoord,_MainTex);
return o;
}
uniform sampler2D _MainTex;
uniform sampler2D _ReflectionTex;
uniform float4 _ReflectColor;
half4 frag (v2f i) : COLOR
{
half4 texcol = tex2D (_MainTex, i.uv);
half4 reflcol = tex2Dproj( _ReflectionTex, i.uv2 ) * 2;
reflcol *= _ReflectColor.a;
return reflcol * _ReflectColor;
}
ENDCG
}
UsePass "Diffuse/PPL"
}
FallBack "Reflective/VertexLit", 1
}
your shader doesnt seem to work like the original mirror shader does... I cant get it to reflect anything.
Same, it seems only my sky colour gets reflected.
Edit: I hacked this together from your mirror code and the water code that comes with unity pro, it seems to work well on my side.
Shader "FX/Mirror Reflection"
{
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" {}
_ReflDistort ("Reflection distort", Range (0,1.5)) = 0.44
_ReflectionTex ("Reflection", 2D) = "white" { TexGen ObjectLinear }
}
SubShader
{
LOD 200
Tags { "RenderType"="Opaque" }
Pass {
Name "BASE"
Tags {"LightMode" = "Always"}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_fog_exp2
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
uniform float4 _MainTex_ST;
uniform float3x3 _ProjMatrix;
struct appdata {
float4 vertex : POSITION;
float3 normal : NORMAL;
float2 texcoord : TEXCOORD1;
};
struct v2f {
V2F_POS_FOG;
float3 ref;
float2 uv;
float3 viewDir;
};
v2f vert(appdata v)
{
v2f o;
PositionFog( v.vertex, o.pos, o.fog );
// object space view direction (will normalize per pixel)
o.viewDir.xzy = ObjSpaceViewDir(v.vertex);
// calculate the reflection vector
float3x4 mat = float3x4 (
0.5, 0, 0, 0.5,
0, 0.5 * _ProjectionParams.x, 0, 0.5,
0, 0, 0, 1
);
o.ref = mul (mat, o.pos);
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
return o;
}
uniform sampler2D _MainTex;
uniform sampler2D _ReflectionTex;
uniform float4 _ReflectColor;
uniform float _ReflDistort;
half4 frag (v2f i) : COLOR
{
half4 texcol = tex2D (_MainTex, i.uv);
float3 uv2 = i.ref;
half4 reflcol = tex2Dproj( _ReflectionTex, uv2 ) * 1;
reflcol *= _ReflectColor.a;
return reflcol * _ReflectColor;
}
ENDCG
}
UsePass "Diffuse/PPL"
}
FallBack "Reflective/VertexLit", 1
}
I don’t know why this not work on my PC. Can you help me ?
Hello,
I would like to pass a matrix 4x4 to my shader from my csharp script.
In my shader I put in the CGPROGRAM part :
uniform float3x3 _ProjMatrix;
And in my script I put :
mat.SetMatrix( "_ProjMatrix", mtx );
If I use a shaderLab shader I can access it doing :
matrix [_ProjMatrix]
But in a vertex, fragment shader I cannot acces it.
Can you help me plase? In your shader, how do you supply _ProjMatrix?
Thanks.