Jump to content
  • Advertisement
Sign in to follow this  

environment mapping with hlsl

This topic is 3712 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

ello. I try to have a environment mapping effect with hlsl shader and a cubemap. But it doesn't work reflection is not coherent. I don't see what's wrong. I think the texCUBE() function needs a float3 in world space, no? (world_matrix, viewproj_matrix and camera_position are given by Ogre) Your help is welcome. :) the vertex shader :
struct VS_OUTPUT
   float4 Pos					: POSITION;
   float3 Reflect				: TEXCOORD0;

   float4 Pos			: POSITION, 
   float3 Normal		: NORMAL,
   uniform float4x4  world_matrix,
   uniform float4x4  viewproj_matrix,
   uniform float4 	camera_position			//camera position in world space
	//init : 
	float4 posWS  	= 	mul( world_matrix, Pos );
	Out.Pos 		= 	mul( viewproj_matrix, posWS );
	//calculate normal in world space
	float3 normWS 	= normalize(mul( world_matrix, Normal ));
	// Calculate the view vector in world space.
	float3 viewVectorWS = (posW - camera_position);	
	//Calculate reflection vector
	float3 reflection_vector = reflect(viewVectorWS, normWS);
	Out.Reflect = normalize( reflection_vector );

	return Out;
and the fragment :
samplerCUBE envMap :register(s0); 
float4 main
	float4 Pos						: POSITION,
	float3 Reflect					: TEXCOORD0
	// Calculate the resulting reflection color.
   	float4 finalColor = texCUBE( envMap, normalize(Reflect) );
	return finalColor;


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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!