[GEM-dev] svn update break rectangular texture with shader

IOhannes m zmoelnig zmoelnig at iem.at
Tue Jan 19 15:02:28 CET 2010


cyrille henry wrote:
> 
> hello,
> 
> i just did an svn update. lots of file have changed. (last update was 21
> december)
> after building gem, i realized that few shaders example did not work
> any-more.
> it look to be related with rectangular texture : if you open shader
> example 1 : simple texture : it work ok with non rectangular texture
> (but the texture is upside down), but it does not work at all in
> rectangular mode...

hmm, the solution is "simple": you have to pre-multiply the texture
matrix with the current tex-coords.

something like

<diff>
Index: texture_rect.frag
===================================================================
--- texture_rect.frag   (Revision 3085)
+++ texture_rect.frag   (Arbeitskopie)
@@ -7,8 +7,7 @@

 void main (void)
 {
-vec4 color = texture2DRect(MyTex, gl_TexCoord[0].st);
-// vec4 color = texture2D(MyTex, gl_TexCoord[0].st);
+  vec4 color = texture2DRect(MyTex,  (gl_TextureMatrix[0] *
gl_TexCoord[0]).st);
  color *= B+1.; // brightness
  vec4 gray = vec4(dot(color.rgb,vec3(0.2125,  0.7154, 0.0721)));
  color = mix(gray, color, C+1.); // contrast
</diff>

now i know that this breaks about each shader written so far for Gem.

the change is rather trivial, but it has to be done for each shader (to
fix the upside down issue, it has also to be done for normalized
(sampler2D) textures.
the change in the shader code should (to the best of my knowledge) be
compatible with older versions of Gem.

i don't see a way how this change could be automated (without parsing
the shader and dynamically modifying it, which i would rather not :-)

the alternative would be to go back, which is also a bit problematic, as
the change did fix inconsistencies and bugs between various platforms.


does anybody have any other ideas how this could be handled with the
least annoyance for everybody?


fmgasdr
IOhannes

PS: a hackish solution could also be the use of [pix_coordinate] to
explicitely set the texture coordinates to "rectangular" values. this
has the main drawback that it only works for the most primitive Geos.
personally, i would not really recommend this, but i mention it for
completeness' sake.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3636 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.puredata.info/pipermail/gem-dev/attachments/20100119/18d9051a/attachment.bin>


More information about the GEM-dev mailing list