I have two textures that I want to use in my shader, but they both use the same texture coordinates. I think this should be fine, but I can’t seem to get the color of the lightmap from the texture. All that ends up happening is the variables from both maps seem to be the diffuse color. Here’s the code.
In Main.java:
Material mat = new Material(assetManager, "MatDefs/color_time.j3md");
mat.setTexture("m_DiffuseMap", assetManager.loadTexture("Textures/tube_straight/diffuse.png"));
mat.setTexture("m_LightMap", assetManager.loadTexture("Textures/tube_straight/lightmap.png"));
tube_straight.setMaterial(mat);
color_time.j3md:
MaterialDef ColorTime {
MaterialParameters {
Texture2D m_LightMap
Texture2D m_DiffuseMap
}
Technique {
WorldParameters {
WorldViewProjectionMatrix
Time
}
RenderState{
Blend Alpha
}
VertexShader GLSL100: Shaders/Imps/ColorTime.vert
FragmentShader GLSL100: Shaders/Imps/ColorTime100.frag
}
}
ColorTime.vert
//the global uniform World view projection matrix
//(more on global uniforms below)
uniform mat4 g_WorldViewProjectionMatrix;
//The attribute inPosition is the Object space position of the vertex
attribute vec3 inPosition;
attribute vec2 inTexCoord;
uniform float g_Time;
attribute vec4 inColor;
uniform sampler2D m_LightMap;
uniform sampler2D m_DiffuseMap;
varying vec2 uvCoord;
void main(){
//Transformation of the object space coordinate to projection space
//coordinates.
//- gl_Position is the standard GLSL variable holding projection space
//position. It must be filled in the vertex shader
//- To convert position we multiply the worldViewProjectionMatrix by
//by the position vector.
//The multiplication must be done in this order.
uvCoord = inTexCoord;
gl_Position = g_WorldViewProjectionMatrix * vec4(inPosition, 1.0);
}
ColorTime100.frag
uniform float g_Time;
uniform sampler2D m_LightMap;
uniform sampler2D m_DiffuseMap;
varying vec2 uvCoord;
void main(){
vec4 df_color = texture2D(m_DiffuseMap, uvCoord);
vec4 lp_color = texture2D(m_LightMap, uvCoord);
vec4 cur_color = lp_color;
gl_FragColor = lp_color;
}
In the frag shader, if I load both the Diffuse and LightMap, both lp_color and df_color are the same, and when either one is assigned to gl_FragColor produces the same result. If I do not load the DiffuseMap in Main.java, then lp_color is indeed the lightmap. What am I missing?