Using extra UV maps - undefined variable "texCoord3"

Massive edit, starting over.

Hi, I am trying to make use of multiple UV maps beyond the standard 2 in the lighting shader. My model is an ogre.mesh.xml and is imported with 3 UV maps as it is correct.

I have copied the Lighting.j3md/.vert/.frag and adapted it to use the 3rd UV map instead of the 2nd for the lightmap (which is my ultimate goal).

I did this by using another value to say if there is a 3rd set of separate co-ords (I’m using the original “SEPARATE_TEXCOORD” for a diffuse overlay)

#ifdef SEPARATE_TEXCOORD2
  attribute vec2 inTexCoord3;
  varying vec2 texCoord3;
#endif

This is in the .vert file, and in main I copied this bit

texCoord = inTexCoord;
   #ifdef SEPARATE_TEXCOORD
      texCoord2 = inTexCoord2;
   #endif

and adapted it for my new texture coords, so

#ifdef SEPARATE_TEXCOORD2
      texCoord3 = inTexCoord3;
#endif

Then in my .frag I copied how it is done for the second uv map but changed for my third

varying vec2 texCoord;
#ifdef SEPARATE_TEXCOORD
  varying vec2 texCoord2;
#endif

#ifdef SEPERATE_TEXCOORD2
  varying vec2 texCoord3;
#endif

and finally for in main I set the lightmap to use either texcord1 or 3

vec3 lightMapColor;
       #ifdef SEPARATE_TEXCOORD2
          lightMapColor = texture2D(m_LightMap, texCoord3).rgb;
       #else
          lightMapColor = texture2D(m_LightMap, texCoord).rgb;
       #endif

This is where I get an error

com.jme3.renderer.RendererException: compile error in:ShaderSource[name=Shaders/Lighting.frag, defines, type=Fragment, language=GLSL100] error:0(363) : error C1008: undefined variable “texCoord3”

How do I properly define texCoord3?

I think the engine passes the the texCoord values to the shader, and I think it only passes texCoord and texCoord2, I think think defining textCoord3 yourself will do anything, since the engine doesn’t know anything about it… I think…

: / it looks that way. I can’t find anything on the forum though there are mentions of inTexCoord3 - do you know anything about where it would be passed in?

no, and I personally would put it in the too hard basket and find a way around the issue.

Why do you need 3 different sets of UV’s? normally 2 is enough, one for texturing one for light baking.

Essentially I have a large seamless texture, so I have a giant UV unwrap to make it repeat.

Next I have a texture that I overlay on top - this has relatively high resolution small details, so painted words, scratches things like that.

Then finally I have the UV unwrap for the lightmap.

I’m trying to create a small but extremely detailed scene.

ok i lied, it can handle up to 8 uv maps …

http://javadoc.jmonkeyengine.org/com/jme3/scene/VertexBuffer.Type.html

I guess check to see if the ogre exporter spits out more than 2 sets of uv textures (by looking at the xml file it creates) … I checked, it does … then I dont know if the loader will pick up on them.

Yeah it’s weird I must be missing something, there’s other shaders in existence that make use of inTexCoord3, I just can’t tell what they’re doing that I’m not. Thanks for looking for me btw.

There’s 3 other posts I’ve found with guys posting their shaders (I assume they are working from what I read - could be wrong) in which they all create attribute and varying texCoord3 inTexCoord3 and set texCoord3 = inTexCoord3, no idea what I am doing wrong.

edit: also found it in this jMonkey openVR project

attribute vec2 inTexCoord;   // m_inUVred
        attribute vec2 inTexCoord2;  // m_inUVgreen
        attribute vec2 inTexCoord3;  // m_inUVblue          
        varying vec2 UVred;
        varying vec2 UVgreen;
        varying vec2 UVblue;
      
        void main() {       
            gl_Position = inPosition;
            UVred = inTexCoord;
            UVgreen = inTexCoord2;
            UVblue = inTexCoord3;
        }

I couldnt find any other place in the shaders or the main code where it was set.

I think maybe your ifdef for TEXCOORD2 isn’t working.

Is this jME3 or 3.1? I have a project using texCoord3 but the closest I can come to reproducing that error is

RendererException: compile error in: ShaderSource[name=Shaders/BmShader.frag, defines, type=Fragment, language=GLSL100]
Fragment shader failed to compile with the following errors:
ERROR: 0:82: error(#143) Undeclared identifier: texCoord3

I see you have "undefined variable “texCoord3"”.

(Just because it was referred to later in the shader…) If it weren’t for the error being slightly different wording, it seems like that SEPERATE_TEXCOORD2 isn’t enabled. (Unless that different wording is from different jME versions… I’m on 3.1.)

Just to test, if you take the varying vec3 texCoord3; out of the ifdef, does the error change or go away?

Minus the ifdefs, it looks like I’m doing all the same stuff you are in the shaders, plus this:

From one of my j3md files:

    Technique {
        VertexShader GLSL100:   Shaders/BmShader.vert
        FragmentShader GLSL100: Shaders/BmShader.frag

        WorldParameters {
            WorldViewProjectionMatrix
            WorldMatrix
            Time
        }
        
        Defines {
        	USE_VERTEX_COLOR : useVertexColor
        	ENABLE_DEBUG_TEXTURES : enableDebugTextures
        }
    }

Java code clip setting a parameter on the Material I was using:

    mapMaterial.setParam("enableDebugTextures", VarType.Boolean, true);

Lighting.j3md has this - see comment I added:

Defines {           
            VERTEX_COLOR : UseVertexColor
            VERTEX_LIGHTING : VertexLighting           
            MATERIAL_COLORS : UseMaterialColors         
            DIFFUSEMAP : DiffuseMap
            NORMALMAP : NormalMap
            SPECULARMAP : SpecularMap
            PARALLAXMAP : ParallaxMap
            NORMALMAP_PARALLAX : PackedNormalParallax
            STEEP_PARALLAX : SteepParallax
            ALPHAMAP : AlphaMap
            COLORRAMP : ColorRamp
            LIGHTMAP : LightMap
            SEPARATE_TEXCOORD : SeparateTexCoord  <---See that?  Need one for TEXCOORD2
            DISCARD_ALPHA : AlphaDiscardThreshold
            USE_REFLECTION : EnvMap
            SPHERE_MAP : EnvMapAsSphereMap  
            NUM_BONES : NumberOfBones                        
            INSTANCING : UseInstancing
        }

Sorry if this was confusing or unclear (well, it probably is), the project I’m going off of was somewhat unconventional; I was doing some unusual stuff that you probably aren’t doing, but hopefully this isn’t any different from the solution you need.

Wait a second, you have two different spellings:

#ifdef SEPARATE_TEXCOORD2

#ifdef SEPERATE_TEXCOORD2

:stuck_out_tongue_winking_eye:

Change

#ifdef SEPERATE_TEXCOORD2
  varying vec2 texCoord3;
#endif

to 

#ifdef SEPARATE_TEXCOORD2
  varying vec2 texCoord3;
#endif
1 Like

Shit.

Thanks. Thank you so much… that probably stopped many potential headaches.That has got rid of the error.

My lightmap still isn’t working tho…

EDIT: Oh christ it’s still broken. I’m going to post the entire shader with the relevant bits highlighted because I’m getting the original error again

I hate that damn word myself - I do that same mistake all the time. Maybe my longer post has the other part you need though?

If you have a TexCoord3 type buffer in the mesh its values will be passed in an attribute inTexCoord3 for each vertex.
Now, you seem to mix up things with the defines. In the lighting shader, SEPARATE_TEXCOORD is true only if you set the material param “SeparateTexCoord” to true.
I really advise you test this without any conditional define first. Just a dead simple shader and see what happens.

Nehon’s talking about that single line Java example I have above… I believe this should do it for you:

yourMaterial.setParam("SeparateTexCoord", VarType.Boolean, true);
yourMaterial.setParam("SeparateTexCoord2", VarType.Boolean, true);

and both of those in the Defines block:

SEPARATE_TEXCOORD : SeparateTexCoord
SEPARATE_TEXCOORD2 : SeparateTexCoord2

But yeah, if that doesn’t fix it maybe you could try making smaller incremental changes without the ifdefs at first as suggested.

Ugh… thanks for the help everyone. It’s solved.

Today I went back to the beginning, copied the lighting vert frag and j3md and started over. I was originally working on a shader I had edited to have a diffuse overlay - which only had a custom .frag not .vert

VertexShader GLSL100 : Common/MatDefs/Shadow/PreShadow.vert
FragmentShader GLSL100 : Shaders/Lighting.frag

I hadn’t set it to use my .vert which had texCoord3 = inTexCoord3 :sweat_smile:

Again thanks for helping me out.