Jump to content
  • Advertisement
Sign in to follow this  
PiCroft

Reflective textures

This topic is 4006 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 using shaders to create a Utah Teapot which reflects the cubemap surrounding it. Sorry, forgot to add this: The teapot is black. Completely black. I'm not sure if has something to do with the values (i.e am I miscalculating them?) Here are my vertex/fragment shaders respectively: vertex shader: struct vertex { float4 position : POSITION; float2 texCoord : TEXCOORD0; float3 normal : NORMAL; }; void main(vertex IN, out float4 oPosition : POSITION, out float2 oTexCoord : TEXCOORD0, out float3 oRefVector : TEXCOORD1, uniform float4x4 modelViewProj, uniform float4x4 modelMatrix, uniform float4x4 cgInvTransModelMatrix, uniform float3 eyepos) { oPosition = mul(modelViewProj,IN.position); //transform from model to clip space //step 1 oTexCoord = IN.texCoord; //step 2 float4 oPosWorldSpace = mul(modelMatrix, IN.position); //transform from model to world space //step 3 float3 oNormal = mul(cgInvTransModelMatrix, float4(IN.normal,1.0)).xyz; //step 4 oNormal = normalize(oNormal); //step 5 float3 eyePosWorldSpace; eyePosWorldSpace = mul(modelMatrix, float4(eyepos,1.0)).xyz; float3 viewVec = oPosWorldSpace - eyePosWorldSpace; //step 6 //now calculate the reflection vector oRefVector oRefVector = reflect(viewVec, oNormal); } fragment shader: void main(float2 texCoord : TEXCOORD0, float3 refVector : TEXCOORD1, uniform sampler2D decalMap, uniform samplerCUBE cubeMapTex, uniform float reflectivity, out float4 colour : COLOR) { colour = tex2D(decalMap,texCoord); float4 refCompCol = texCUBE(cubeMapTex, refVector); float4 texCompCol = tex2D(decalMap, refVector); colour = lerp(refCompCol, texCompCol, reflectivity); } I'd appreciate it if someone could let me know where I'm going wrong.

Share this post


Link to post
Share on other sites
Advertisement
I have no absolute solution, but if this were me debugging the problem I'd be commenting parts of the fragment shader out to see what was happening.

Actually though, I think your problem might be that you need to pass refVector in as two texture co-ordinates, i.e. duplicate the data. I've had problems with sampling from two textures using the same UV co-ordinate register not working.

But as a general answer: debug the output.

eg.

// Check the cube map
colour = refCompCol;

// Check just the texture map
colour = texCompCol;

// Debug the reflectivity
colour = float4( reflectivity, reflectivity, reflectivity, 1 );

etc.

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!