Jump to content
  • Advertisement
Sign in to follow this  

Reflective Bump mapping

This topic is 5132 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`m trying to add reflective bump mapping to my water surface. Ive read the papers on this at nvidias site and also in the nvidia CG toolkit user manual but cant quite figure things out. My main problem is tranforming my vectors between the different coordinate spaces. Ive implemented normal bump mapping so can get to tangent space but not sure what I need to do to do this. I think i need to convert my view direction to cubemap space from world space and my normals from tangent space to cubemap space. Any help on how to do this would be greatly appreciated? Just one more thing is that my reflection are created using render to texture methods and then projected onto the surface and so is not a cube map. Does this have any effect on the methos used or does it still work the same? My vertex and pixel shaders in HLSL are as follows. This just uses normal bump mapping which makes the surface look solid and doesnt take into account the reflections.
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);
	Out.Light = mul(worldToTangentSpace, vecLightDir);
	float3 PosWorld = mul(inPos, matWorld); 
	Out.View =  vecEye - PosWorld;         // V
	Out.Norm = mul(Normal, matWorld);
	float4 texture_projection_reflect = mul(inPos ,matTextureProjection);
	Out.Tex_reflect = texture_projection_reflect;
	float4 texture_projection_refract = mul(inPos ,matTextureProjection);
	Out.Tex_refract = texture_projection_refract;

	Out.Tex = inTex;

	return Out;

float4 PixelShader_water(float3 Light: TEXCOORD0, 
        float3 View : TEXCOORD1, float4 Tex_reflect : TEXCOORD2,  float4 Tex_refract : TEXCOORD3, float2 Tex: TEXCOORD4,  float3 Norm : TEXCOORD5) : COLOR

  float4 diffuse = { 0.34f, 0.41f, 0.51f, 1.0f};
  float4 reflectmap = tex2Dproj( reflection_texture, Tex_reflect);
  float4 refractmap = tex2Dproj( refraction_texture, Tex_refract);
  float4 ambient = {0.1, 0.1, 0.1, 1.0}; 
  float3 Normal = normalize(Norm);
  float3 LightDir = normalize(Light);
  float3 ViewDir = normalize(View); 

  float fresnel = tex1D(fresnel_texture,saturate(dot(Normal,ViewDir)));
  float4 colour = lerp(refractmap, reflectmap, fresnel);
  colour = lerp(diffuse, colour, 0.7);
  float3 bumpNormal = 2 * (tex2D(water_bump_texture, Tex*20) - 0.5); // bump map

  float4 diff = saturate(dot(bumpNormal, LightDir)); // diffuse comp.

  // compute self-shadowing term
  float shadow = saturate(4* diff);

  float3 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);  

Thanks. [Edited by - Paul7 on November 27, 2004 6:58:33 AM]

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!