Sorry about the double post I just thought this would be a good piece of code to put here. I modified the reflection shader to accept the model’s own texture and blend the two together. I have to say that realtime this thing is a lot more impressive but even so- Here’s my results.
Youtube video: youtube.com/watch?v=dN1e9G9V7yo
Here’s the code.
//Cg
//Cg profile arbvp1 arbfp1
//clcheung Mar 2009, base on The Cg Tutorial
//modified by mavasher
void vshader(
in float4 vtx_position : POSITION,
in float2 vtx_texcoord0 : TEXCOORD0,
in float4 vtx_color : COLOR0,
in float3 vtx_normal: NORMAL,
in uniform float4 k_eyePositionW,
uniform float4x4 mat_modelproj,
uniform in float4x4 trans_model_to_world,
out float4 l_position : POSITION,
out float2 l_texcoord0 : TEXCOORD0,
out float4 l_color : COLOR0,
out float3 l_R : TEXCOORD1)
{
l_position = mul(mat_modelproj, vtx_position);
l_texcoord0 = vtx_texcoord0;
l_color = vtx_color;
float3 positionW = mul(trans_model_to_world,vtx_position).xyz;
float3 N = mul((float3x3)trans_model_to_world, vtx_normal);
N=normalize(N);
float3 I = positionW - k_eyePositionW;
l_R = reflect(I, N);
}
void fshader(
in uniform float4 k_param1,
in float3 l_R : TEXCOORD1,
in uniform samplerCUBE k_texcube : TEXUNIT1, //UNIT0
in float2 l_texcoord0: TEXCOORD0,
in float4 l_color : COLOR0,
in sampler2D tex_0 : TEXUNIT0,
out float4 o_color: COLOR0
)
{
float4 r;
r.xyz = l_R;
r.w = k_param1.y; // reflection blur
float4 tex = tex2D(tex_0, l_texcoord0);
float4 reflectedColor = texCUBEbias(k_texcube, r);
float4 partcolor = lerp(l_color, reflectedColor, 1) ;
o_color = lerp(tex, partcolor, k_param1.x);
}