This topic is 4730 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 on other sites
Shouldn't the reflection vector be normalized too? Dunno, maybe it's done automated by reflect() but I don't think so.

##### 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 on other sites
reflect takes normal vector as second parameter.

1. 1
2. 2
Rutin
18
3. 3
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633735
• Total Posts
3013597
×