Shader help – recreating GL_SPHERE_MAP
I’m a relative noob when it comes to shaders, and I’m coming up against a wall. I’m trying use a vertex shader to generate texture coordinates for a jit.gl.mesh that re-create OpenGL’s GL_SPHERE_MAP mode for a reflection effect. This would ideally mimic the behavior of OB3D’s tex_map attribute (@tex_map 2).
I have created a shader (attached) that I believe should be doing this. The code is essentially a direct copy of the source taken from the Orange Book and the Shadergen program. Unfortunately the shader does not work as expected – it appears that it’s referencing a single coordinate rather than map across the entire texture.
I’m hoping that someone with more shader experience can comment. Any insight would be greatly appreciated!
One last try… hoping someone can help.
have you tried using non-rectangular textures? (@rectangle 0 on all textures in the patch, and changing sampler2DRect to sampler2D in the shader code)
just a thought.
Thanks Robert – that seems to have solved it.
The only remaining difference between this shader and @tex_map 2 is that the shader appears to flip the texture along the y axis. I’m getting around this with jit.dimmap but I’m sure it could be done more efficiently in the shader itself.
Is my understanding correct that with @rectangle 0 jit.gl.texture coerces incoming rectangular matrices to be square?
I’m attaching the corrected code in case this is useful to anyone else. Now if only jit.gl.mesh supported multi-texturing I would be a very happy camper!
The only remaining difference between this shader and @tex_map 2 is that the shader appears to flip the texture along the y axis
maybe the @flip attribute to gl.texture?
This appears to have no effect on the results of the shader’s application of the texture.
I’ve sorted this out — here is the modified shader that recreates @tex_map 2. It also includes some optimizations to the SphereMap function culled from the interwebs.