Sign in to follow this  

cubic environment mapping shader

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

This topic is 4397 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this