Cubemap problem

Started by
2 comments, last by Joshua Klint 16 years, 5 months ago
I got my cubemaps set up so they work with a "skybox" style mapping mode. Then I attempted to do a reflection in the fragment shader. Here is the result: As you can see, there is an odd vertical line where the cubemap gets flipped. This line moves with the camera. I have packaged up the demo here. If anyone can identity what is wrong with the shader, I would appreciate it. The section you should look at is line 91 of main.frag:
	#ifdef LW_CUBEMAP
		
		// Reflection
		gl_FragColor = gl_FragColor * alpha + textureCube( cubemap, reflect( N,gl_TexCoord[2].xyz ) ) * (1.0 - alpha);
		
		// Skybox (this works fine)
		//gl_FragColor = gl_FragColor * alpha + textureCube( cubemap, gl_TexCoord[2].xyz ) * (1.0 - alpha);
		
	#endif
It should be noted that I scale my modelview matrix by (0,0,-1) before doing anything, in order to switch the coordinate system to a left-handed one.
Advertisement
I don't understand what you meant by "the cubemap gets flipped".

But it seems to be the border problem of cubemap faces. In that case, if you are not using mipmap, you can solve this by edging each cubemap face with its neighbor faces and using the bordered texture. If you are using mipmap, you would need to do something radical to correct it (which is not worthy at all).

By the way, your call to reflect function is not correct.

It should be...

reflect( entering_ray, normal )

That line was caused by one of the vectors not being normalized. It has nothing to do with the cubemap borders. That's why I took the trouble to make a small demo and post it.

I switched the arguments. But the cubemap is rotating around with the camera, and I can't seem to find the right combination of flipped signs to fix it. Simple "skybox" mode works fine.
By copying some code from a generated ShaderGen shader, I was able to calculate the reflection vector in the vertex shader. It works perfectly. Thank you, 3DLabs.

There is still the matter of modulating the cubemap lookup by the bump vector, for EMBM, but the hard part is done.

I highly recommend ShaderGen any time you are trying to implement something that has an equivalent in the old fixed-function pipeline.

This topic is closed to new replies.

Advertisement