Float uniform not properly communicated to vertex shader

Hello,

I’m trying to work on reusing the shader posted there:

and I’m able to get something pretty close, however I have this weird issue where a float I’m setting in the material is not read. I see the vertex shader has it equal to 0.0 instead of what I am putting. What am I missing?

my main in jme is like this

Geometry geom = new Geometry(“Box”, b);

mat = new Material(assetManager, “Materials/scrollingTexture.j3md”);

Texture tex = assetManager.loadTexture(“Textures/waterCartoonreal 1.png”);
tex.setWrap(Texture.WrapMode.Repeat);

mat.setTexture(“m_ColorMap”, tex);
mat.setFloat(“m_ScrollSpeed”, 2f);

geom.setMaterial(mat);

the material is set like this
MaterialDef Scroll Texture {
MaterialParameters {
Texture2D m_ColorMap
Float m_ScrollSpeed
Boolean m_YCoCg
Boolean m_LATC
Boolean m_Normalize
Boolean m_ShowAlpha
}

Technique {

    WorldParameters {
        WorldViewProjectionMatrix
        Time
    }
    VertexShader GLSL100: Materials/scroller100.vert
    FragmentShader GLSL100: Materials/SimpleTextured.frag
    Defines {
        DXT_YCOCG : m_YCoCg
        NORMAL_LATC : m_LATC
        NORMALIZE : m_Normalize
        SHOW_ALPHA : m_ShowAlpha
    }

}

Technique FixedFunc {

}

}

The .vert

uniform mat4 g_WorldViewProjectionMatrix;

uniform float m_ScrollSpeed;
uniform float g_Time;

attribute vec3 inPosition;
attribute vec2 inTexCoord;

varying vec2 texCoord;

void main(){

gl_Position = g_WorldViewProjectionMatrix * vec4(inPosition, 1.0);
float offset = g_Time*m_ScrollSpeed-floor(g_Time*m_ScrollSpeed);
texCoord = vec2(inTexCoord[0] + offset, inTexCoord[1]);

}

The frag is the same as here

if i replace m_ScrollSpeed in the vertex shader by a fixed value, it works well

I’m puzzled because the frag shader is able to read the m_ColorMap well, but the vertex doesnt get the float i’m passing

Any clue?

Thanks
Adrien

Not sure if that’s the only way, but I was able to solve this by changing where I’m sending my parameter. Happy to have any input on this

Material is now:
MaterialDef Scroll Texture {
MaterialParameters {
Texture2D m_ColorMap
Float m_ScrollSpeed
Boolean m_YCoCg
Boolean m_LATC
Boolean m_Normalize
Boolean m_ShowAlpha
}

Technique {

    WorldParameters {
        WorldViewProjectionMatrix
        Time
    }
    VertexShader GLSL100: Materials/scroller100.vert
    FragmentShader GLSL100: Materials/SimpleTextured.frag
    Defines {
        DXT_YCOCG : m_YCoCg
        NORMAL_LATC : m_LATC
        NORMALIZE : m_Normalize
        SHOW_ALPHA : m_ShowAlpha
        SCROLL_SPEED : m_ScrollSpeed
    }

}

Technique FixedFunc {

}

}

And vertex shader is like this
uniform mat4 g_WorldViewProjectionMatrix;

uniform float m_ScrollSpeed;
uniform float g_Time;

attribute vec3 inPosition;
attribute vec2 inTexCoord;

varying vec2 texCoord;

void main(){

float scrollSpeed = 0.0;
#ifdef SCROLL_SPEED
    scrollSpeed = SCROLL_SPEED;
#endif
gl_Position = g_WorldViewProjectionMatrix * vec4(inPosition, 1.0);
float offset = g_Time*scrollSpeed-floor(g_Time*scrollSpeed);
texCoord = vec2(inTexCoord[0] + offset, inTexCoord[1] );

}

and it works fine

don’t define your parameters with the m_ prefix in the j3md file. The m_ will be appended when binding the uniform to the shader.
So for example, let’s say you have a float param called MyFloat.
j3md:
Float MyFloat

java code
mat.setFloat(“MyFloat”, floatValue);

Shader code
uniform float m_MyFloat;

1 Like

indeed!

it just confused me that for example the variables ColorMap and ShowAlpha do use the m_

No, they shouldn’t be. If it’s in a JME shader then it’s a huge giant humongous blistered puss infected wart-covered bug.