Materials setting wrong samplers?

Hi,

i am trying to make my own material definition template (its not the first one, i did some others before), and it uses multiple textures. So i have my shaders (currently pretty simple) ready to go, and the material definition template to, and then i created a new .j3m file, opened id in the editor, have set all the samplers to DIFFERENT images, but when i render a mesh with this material, all the samplers in the shader are containing the same image…

so first my shaders:
vertex shader:
[java]uniform mat4 g_WorldViewProjectionMatrix;

attribute vec3 inPosition;

void main() {
gl_Position = g_WorldViewProjectionMatrix * vec4(inPosition, 1.0);
}[/java]

fragment shader:
[java]uniform sampler2D worldpos;
uniform sampler2D worldnor;
uniform sampler2D lprops;

uniform vec2 g_Resolution;

void main() {
vec2 gcoord = gl_FragCoord.xy / g_Resolution.xy;
gl_FragColor = texture2D(worldpos, gcoord);
}[/java]

for testing i switch the sampler in texture2D() function…

and now finally my material definition template (just in case there could be something wrong with that:

MaterialDef BananaPointLight {
MaterialParameters {
Texture2D worldpos
Texture2D worldnor
Texture2D lprops
}
Technique {
VertexShader GLSL100: MatDefs/BananaRender/BananaPointLight.vert
FragmentShader GLSL100: MatDefs/BananaRender/BananaPointLight.frag

    WorldParameters {
        WorldViewProjectionMatrix
        Resolution
    }
}

Technique BananaLightPass {
    VertexShader GLSL100: MatDefs/BananaRender/BananaPointLight.vert
    FragmentShader GLSL100: MatDefs/BananaRender/BananaPointLight.frag

    WorldParameters {
        WorldViewProjectionMatrix
        Resolution
    }
}

so when i render the frame, i set the forced technique to “BananaLightPass” so that it uses the right technique (shouldnt make a difference by now, but maybe will in the future)

time for some screenshots…
as you might have noticed, i am not doing proper texture mapping with uv and stuff, but using the position of the pixel on the screen… i render a sphere right in the middle of the screen to test my material…

so with the sampler worldpos in the texture2D() function it looks like this:

with worldnor it looks like this:

and finally with lprops it looks like this:

what you are seeing right there is the actual normalmap i assigned to the material, i have also tried to set the textures manually in code using mat.setTexture and figured out that the texture shown on the screen is always the first texture i set. I first thought this is some kind of a random bug, but after restarting the sdk, restarting the pc, and recreating the material definition 3 times (with modifications in it, leaving out other parameters i had in there before etc) i think that this isnt just some random bug… i also tried rendering it without setting the forced technique to “BananaLightPass” but nothing changed… i wanted to ask if someone had this problem before or if someone has an idea how i can fix that problem? because i have other material definition templates with multiple textures that are working fine…

Thank you :slight_smile:

p.s.: i just tried rendering without using my sceneprocessor, but still the same problem…

You are still kind of lucky to see any texture… running a nvidia card? :wink:

The parameters require a m_ prefix…

[java]
uniform sampler2D m_worldpos;
uniform sampler2D m_worldnor;
uniform sampler2D m_lprops;

[/java]

Oh

i have seen that before but i didnt knew it was necessary, ill try it :slight_smile: thank you!

it worked :smiley: thank you :smiley:

and yes i am running nvidia… :smiley: