Shader help – recreating GL_SPHERE_MAP

Dec 27, 2010 at 8:50am

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!

Attachments:
  1. testshader.jxs
#54114
Dec 28, 2010 at 7:35pm

Anyone?

#194714
Jan 4, 2011 at 7:09pm

One last try… hoping someone can help.

#194715
Jan 4, 2011 at 7:20pm

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.

#194716
Jan 4, 2011 at 8:23pm

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!

Attachments:
  1. testshader.jxs
#194717
Jan 6, 2011 at 9:54pm

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?

#194718
Jan 6, 2011 at 11:35pm

This appears to have no effect on the results of the shader’s application of the texture.

#194719
Jan 6, 2011 at 11:42pm

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.

Attachments:
  1. testshader3.jxs
#194720

You must be logged in to reply to this topic.