Jump to content
  • Advertisement
Sign in to follow this  

Reflective bump mapping artifacts

This topic is 4980 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I`ve added reflective bump mapping to my water surface to simulate waves. It appears to be working correctly apart from some artifacts. If I use a cube map (which I dont want 2 do in the final result) for my reflection I get this result which is pretty much perfect, only slight artifacts prob due to texture used. Then if i change this to a projected texture of the actual reflected geometry I get this. I have no idea why I am getting these artifacts. They are even worse if use perlin noise as my bump map which i want to do once i get it working properly. It also gets bands of dark areas across the screen in certain places that move with the cameras movement. My shader code is as follows, (its a bit messy at the moment hope it can be understood ok):
VS_OUTPUT VertexShader_water( float4 inPos: POSITION, float3 Normal : NORMAL,  float2 inTex: TEXCOORD)

	Out.Pos = mul(inPos, matWorldViewProjection);
	float3 tanvect; tanvect.x = 0.0; tanvect.y = 0.0; tanvect.z = 1.0;
	float3 tang = normalize(cross(tanvect, Normal));
	float3x3 worldToTangentSpace;
	worldToTangentSpace[0] = mul(tang, matWorld);
	worldToTangentSpace[1] = mul(cross(tang, Normal), matWorld);
	worldToTangentSpace[2] = mul(Normal, matWorld);

	float3x3 invworldToTangentSpace = transpose(worldToTangentSpace);
	Out.tan2world1 = invworldToTangentSpace[0];
	Out.tan2world2 = invworldToTangentSpace[1];
	Out.tan2world3 = invworldToTangentSpace[2];
	Out.Light = vecLightDir;
	float3 PosWorld = mul(inPos, matWorld); 
	Out.View =  vecEye - PosWorld;         // V
	Out.Norm = mul(Normal, matWorld);
	Out.Tex_reflect = inPos;

	Out.Tex = inTex;

	return Out;

float4 PixelShader_water(
		float3 Light: TEXCOORD0, 
        float3 View : TEXCOORD1,
        float4 Tex_reflect : TEXCOORD2,
        float2 Tex: TEXCOORD3,
        float3 Norm : TEXCOORD4,
        float3 tan2world1: TEXCOORD5,
		float3 tan2world2: TEXCOORD6,
		float3 tan2world3: TEXCOORD7
        ) : COLOR

  float4 diffuse = { 0.34f, 0.41f, 0.51f, 1.0f};
  float4 ambient = {0.1, 0.1, 0.1, 1.0}; 

  float3 LightDir = normalize(Light);
  float3 ViewDir = normalize(View); 
 float3 bumpNormal = 2 * (tex2D(water_bump_texture, Tex*20) - 0.5); // bump map

 float3x3 invworldToTangentSpace;
 invworldToTangentSpace[0] = tan2world1;
 invworldToTangentSpace[1] = tan2world2;
 invworldToTangentSpace[2] = tan2world3;
 bumpNormal = mul(invworldToTangentSpace, bumpNormal);

 float3 Reflect = normalize(reflect(-ViewDir,bumpNormal)); // R
 Tex_reflect.xz += Reflect.xz;
 float4 texture_projection_reflect = mul(Tex_reflect ,matTextureProjection);
 float4 reflectmap = tex2Dproj( reflection_texture, texture_projection_reflect);
  float4 colour = reflectmap;
  float4 diff = saturate(dot(bumpNormal, LightDir)); // diffuse comp.
  // compute self-shadowing term
  float shadow = saturate(4* diff);
  Reflect = normalize(2 * diff * bumpNormal - LightDir); // R
  float4 specular = pow(saturate(dot(Reflect, ViewDir)), 100); // R.V^n 
  return ambient * colour + shadow * (colour * diff + specular);  

Any suggestions as to why these artifacts are occuring? Thanks

Share this post

Link to post
Share on other sites
No one have any ideas?

Havent a clue how to get rid of it.

Does it matter what resolution my render to texture texture is, at the moment its 512x512, would this make a difference?

Heres a screenshot of it with perlin noise bump map and projective texturing if it helps!

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!