I’ve been toying with the shaders and if I add some blur (well, a lot really) I can have a decent reflection with just 10 rays/steps, with such a setting I got 25 -100% framerate increase, and it looks like this:
If anyone is interested I added the blur in the mix shader like this:
//Cg
void vshader(
float4 vtx_position : POSITION,
float2 vtx_texcoord0 : TEXCOORD0,
out float4 l_position : POSITION,
out float2 l_texcoord0 : TEXCOORD0,
out float2 l_texcoord1 : TEXCOORD1,
uniform float4 texpad_albedo,
uniform float4 texpad_reflection,
uniform float4x4 mat_modelproj)
{
l_position=mul(mat_modelproj, vtx_position);
l_texcoord0 = vtx_position.xz * texpad_albedo.xy + texpad_albedo.xy;
l_texcoord1 = vtx_position.xz * texpad_reflection.xy + texpad_reflection.xy;
}
void fshader(float2 l_texcoord0 : TEXCOORD0,
float2 l_texcoord1 : TEXCOORD1,
out float4 o_color : COLOR,
uniform sampler2D albedo : TEXUNIT0,
uniform sampler2D reflection : TEXUNIT1)
{
float4 A = tex2D(albedo, l_texcoord0);
//float4 R = tex2D(reflection, l_texcoord1);
//Hardcoded fast gaussian blur
float2 samples[12] = {
-0.326212, -0.405805,
-0.840144, -0.073580,
-0.695914, 0.457137,
-0.203345, 0.620716,
0.962340, -0.194983,
0.473434, -0.480026,
0.519456, 0.767022,
0.185461, -0.893124,
0.507431, 0.064425,
0.896420, 0.412458,
-0.321940, -0.932615,
-0.791559, -0.597705
};
float4 R = 0;
for(int i = 0 ; i < 12 ; i++)
{
R += tex2D(reflection, l_texcoord1 + samples[i] * 0.01);
}
R /=13;
o_color = float4(A.rgb * (1 - R.a) + R.rgb * R.a, A.a);
}
Of course I’m not the kind of person to know how to write a proper blur function, the code is from ninth lens flare shader, so all the fame and glory is his (and John Chapmans) to claim.