JOGL/GLSL Sample no. 2 / Texture2D_2 doesn't work

Found a bug? Post here.
Post Reply
STRESS
Posts: 141
Joined: Mon 19. Jan 2009, 12:10

JOGL/GLSL Sample no. 2 / Texture2D_2 doesn't work

Post by STRESS » Wed 20. May 2009, 12:03

I've got a problem using multitextures in GLSL. I've got three samplers, sampler,sampler2,sampler3. And they should map to texture sampler 0,1,2 correspondingly. Unfortunately it seems that sampler no.2 and sampler no.1 are the same texture!

Here is my GLSL program:

Code: Select all

uniform sampler2D  sampler;
uniform sampler2D sampler2;
uniform sampler2D sampler3;

void main(void)
{
    vec4 currentSample = vec4(0.0,0.0,0.0,0.0);
    vec4 currentSample2 = vec4(0.0,0.0,0.0,0.0);
    vec4 currentSample3 = vec4(0.0,0.0,0.0,0.0);
    currentSample = texture2D(sampler,gl_TexCoord[0].st);
    currentSample2 = texture2D(sampler2,gl_TexCoord[0].st);
    currentSample3 = texture2D(sampler3,gl_TexCoord[0].st);
    gl_FragColor = currentSample + currentSample2 + currentSample3;
}
and this is how I create the textures

Code: Select all

Texture2D anotherTexture = (Texture2D)
			AttributeEntityUtility.createAttributeEntity(Texture2D.class,POLYGON_SHADER+"."+TEXTURE_2D_2,ap,true);
Texture2D lookupTexture = (Texture2D) 
			AttributeEntityUtility.createAttributeEntity(Texture2D.class, POLYGON_SHADER+"."+TEXTURE_2D_1, ap, true);
Texture2D tex = (Texture2D) 
			AttributeEntityUtility.createAttributeEntity(Texture2D.class, POLYGON_SHADER+"."+TEXTURE_2D, ap, true);
and setting the samplers with

Code: Select all

glslProg.setUniform("sampler", 0);
glslProg.setUniform("sampler2",1);
glslProg.setUniform("sampler3",2);
But it seems on sampler3 there is the same texture as on sampler2

STRESS
Posts: 141
Joined: Mon 19. Jan 2009, 12:10

Re: JOGL/GLSL Sample no. 2 / Texture2D_2 doesn't work

Post by STRESS » Wed 20. May 2009, 12:24

Hmm I think I know why, I had a quick look at GLSLPolygonShader it seems it uses Slot 2 for environment maps only. And otherwise it reads only Texture2D_1 and Texture2D_0 from the appearance attributes. Hmmmm this is a bit limited.

STRESS
Posts: 141
Joined: Mon 19. Jan 2009, 12:10

Re: JOGL/GLSL Sample no. 2 / Texture2D_2 doesn't work

Post by STRESS » Wed 20. May 2009, 15:00

Hmm that is not the only problem there is another one that the JOGLTexture2D for TEXTURE2D_2 never gets correctly generated. :cry: I added a System print out in the constructor of JOGLTexture2D and I never see the right texture coming in. I have not enough knowledge on how this part of the code is supposed to work, so I would greatly appreciate any hints.

STRESS
Posts: 141
Joined: Mon 19. Jan 2009, 12:10

Re: JOGL/GLSL Sample no. 2 / Texture2D_2 doesn't work

Post by STRESS » Wed 20. May 2009, 15:26

Found it :D , there is a typo in DefaultPolygonShader line 141:

Code: Select all

texture2D_2 = (Texture2D) AttributeEntityUtility.createAttributeEntity(Texture2D.class, ShaderUtility.nameSpace(name,TEXTURE_2D_1), eap);		    	
joglTexture2D_2 = new JOGLTexture2D(texture2D_2);
hasTextures = true;
should be

Code: Select all

texture2D_2 = (Texture2D) AttributeEntityUtility.createAttributeEntity(Texture2D.class, ShaderUtility.nameSpace(name,TEXTURE_2D_2), eap);		    	
joglTexture2D_2 = new JOGLTexture2D(texture2D_2);
hasTextures = true;
this means you also have to add the static import of TEXTURE_2D_2 as well :mrgreen:

User avatar
gunn
Posts: 323
Joined: Thu 14. Dec 2006, 09:56
Location: TU Berlin
Contact:

Re: JOGL/GLSL Sample no. 2 / Texture2D_2 doesn't work

Post by gunn » Wed 20. May 2009, 16:56

Thanks for the correction. Unfortunately there are no tutorials or other examples where this third texture is used, so the type went undetected. My apologies.

The problem with the GLSLPolygonShader is similar: I have been using the DefaultPolygonShader to run my GLSL shaders (see the tutorial example GLShadingLangExample03 for how that works) and consequently neglected to "upgrade" that class to include the third texture when it came online a few months ago.

Both these classes are now upgraded to allow you to use up to three textures in a single shader.

In general, the current state of the multi-texturing leaves something to be desired. Comments welcome.
jReality core developer

STRESS
Posts: 141
Joined: Mon 19. Jan 2009, 12:10

Re: JOGL/GLSL Sample no. 2 / Texture2D_2 doesn't work

Post by STRESS » Wed 27. May 2009, 10:56

gunn wrote: In general, the current state of the multi-texturing leaves something to be desired. Comments welcome.
I agree it isn't ideal at the moment at all.
The problem is I guess to find something that fits all the different backends. Assuming that Software backend probably doesn't support multitexturing at all? And for example RIB or RendermanSL is far more general when it comes down to texturing compared to OpenGL since it doesn't work with slots just named texture variables. It is a bit sad that OpenGL / GLSL isn't as general as that and it doesn't allow for named binding and does automatical slot binding just like HLSL/FX in Direct3D. It would make life a lot easier. Maybe it is worth looking what others did? For example OSG?

User avatar
gunn
Posts: 323
Joined: Thu 14. Dec 2006, 09:56
Location: TU Berlin
Contact:

Re: JOGL/GLSL Sample no. 2 / Texture2D_2 doesn't work

Post by gunn » Wed 27. May 2009, 12:33

We're currently working to prepare for the OpenSource Software Competition for Multimedia 2009 so haven't time now to go into details of this problem.

But a general remark: there are always 20 different improvements for a piece of software. Deciding which one to pursue in light of limited personel and time resources is always difficult. At the current time the multitexturing features of jReality -- imperfect as they are when compared to what is possible -- are still adequate for most if not all of the local needs. As long as that remains so, it's unlikely that will change dramatically. I could foresee implementing a simple extension, such as support for single-channel textures -- but a full-blown multi-texturing environment is a much more ambitious project.

Again, if you have concrete suggestions on how a design might look please share them.
jReality core developer

Post Reply