Shader with two textures - uniform values not as expected


I’m trying to transition between two textures in a shader.
The uniforms don’t seem to hold the values I expect them to though.

I’ve narrowed the problem down to this short example.
The shader should draw “Texture”.
It shows the monkey loaded into “OldTexture” however.
It seems to always show the texture set with the first setTexture call, regardless of name.

Thanks in advance for any help with this.

(first post here so - hope the formatting works or I can edit this)

import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import com.jme3.system.AppSettings;
import com.jme3.scene.shape.Quad;
import com.jme3.renderer.queue.RenderQueue.Bucket;

public class Start extends SimpleApplication {
    public static void main(String[] args) {
        Start app = new Start();
        AppSettings settings = new AppSettings(true);
    public void simpleInitApp() {
			Quad quadMesh = new Quad(512, 512);
			Geometry quad = new Geometry("Quad", quadMesh);
			Material mat = new Material(assetManager, "prob2tex.j3md");
			mat.setTexture("OldTexture", assetManager.loadTexture("Monkey.png"));
			mat.setTexture("Texture", assetManager.loadTexture("vistest1.png"));
			guiNode.attachChildAt(quad, 0);
    public void simpleUpdate(float tpf) {

material file:

MaterialDef Solid Color {
    MaterialParameters {
        Texture2D Texture -LINEAR
        Texture2D OldTexture -LINEAR
    Technique {
        VertexShader GLSL150 GLSL100:  prob2tex.vert 
        FragmentShader GLSL150 GLSL100: prob2tex.frag

        WorldParameters {
		 RenderState {
			Blend Alpha

the fragment shader … should draw Texture ?

uniform sampler2D Texture;
uniform sampler2D OldTexture;
varying vec2 texCoord;

void main() {
	vec4 c=texture2D(Texture, texCoord);

for completeness:

uniform mat4 g_WorldViewProjectionMatrix;
attribute vec3 inPosition;
attribute vec2 inTexCoord;

varying vec2 texCoord;

void main(){
	texCoord = inTexCoord;
	gl_Position = g_WorldViewProjectionMatrix * vec4(inPosition, 1.0);

tested with 3.4.1-stable and 3.6.0-beta2


You are essentially referring to samplers that don’t really exist.

1 Like

ugh … makes sense.
never even considered that as it did give me a texture anyway.


1 Like