Forums > Jitter

Shader help – recreating GL_SPHERE_MAP

December 27, 2010 | 8:50 am

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

December 28, 2010 | 7:35 pm

Anyone?


January 4, 2011 | 7:09 pm

One last try… hoping someone can help.


January 4, 2011 | 7:20 pm

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.


January 4, 2011 | 8:23 pm

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

January 6, 2011 | 9:54 pm

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?


January 6, 2011 | 11:35 pm

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


January 6, 2011 | 11:42 pm

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

Viewing 8 posts - 1 through 8 (of 8 total)