Jump to content
  • Advertisement
Sign in to follow this  
Khaos Dragon

cubic environment mapping shader

This topic is 4646 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 am wondering if my vertex shader for cubic environment mapping looks sound. I am just focusing on a per vertex reflection component currently and leaving the lighting component until later in order to ease testing. I am however, not getting anything that looks right. I have verified that my cubemap is correctly filled and also that my normal seems to be ok. However my reflection vector is clearly not giving me accurate reflections for the object I am mapping. The following is the relevant portion of my vertex and pixel shaders.

VS_OUTPUT main( VS_INPUT IN )
{
    VS_OUTPUT OUT;

    OUT.hposition = mul( IN.position, ModelViewProj );
	
    //transforming vertex from object to worldspace
    float4 posWorld    = mul(IN.position, ModelWorld);
    //computing view vector
    float3 ViewVec     = normalize(eyePos.xyz-posWorld.xyz);

    //computing reflection vector to use as cubemap lookup
    OUT.reflectVec = reflect(IN.normal, ViewVec);
    return OUT;
}


PS_OUTPUT main( VS_OUTPUT IN )
{
     PS_OUTPUT OUT;

     OUT.color = texCUBE( reflectionCubemap, IN.reflectVec );
     return OUT;
}

Share this post


Link to post
Share on other sites
Advertisement
Shouldn't the reflection vector be normalized too? Dunno, maybe it's done automated by reflect() but I don't think so.

Share this post


Link to post
Share on other sites
Your matrix says ModelWorld. Is that actually what it is? Because then that would be Model^2 or World^2. Also make sure your normal is normalized. Check to see if reflectVec is getting interpolated correctly. You might have it bound to something it's not suppose to be bound to. Try using color=reflectvec for debug.

Good luck

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!