I have simple shader whit two textures.
But does not load second texture.
I use myTexture2 and he looks like myTexture.
It should look as follows(blender render):
But it looks like:
myTexture
myTexture2
node load:
Code: Select all
String psFileName = "opengl.frag";
String vsFileName = "opengl.vert";
IGPUProgrammingServices gpu = driver.getGPUProgrammingServices();
MyShaderCallback mc = new MyShaderCallback();
int shaderMaterial = (gpu.addHighLevelShaderMaterialFromFiles(
vsFileName, "vertexmain", E_VERTEX_SHADER_TYPE.EVST_VS_1_1,
psFileName, "pixelmain", E_PIXEL_SHADER_TYPE.EPST_PS_1_1,
mc, E_MATERIAL_TYPE.EMT_SOLID
));
mc.drop();
ISceneNode node1 = smgr.addMeshSceneNode(smgr.getMesh("monkey.b3d"));
node1.setPosition(new vector3df(0,0,0));
node1.setScale(new vector3df(50f,50f,50f));
node1.setMaterialTexture(0, driver.getTexture("monkey.png"));
node1.setMaterialTexture(1, driver.getTexture("monkey2.png"));
node1.setMaterialFlag(E_MATERIAL_FLAG.EMF_LIGHTING, false);
node1.setMaterialTypeByInt(shaderMaterial);
Code: Select all
float[] t = new float[1];
t[0] = 0;
services.setPixelShaderConstant("myTexture", t, 1);
float[] tt = new float[1];
tt[0] = 1;
services.setPixelShaderConstant("myTexture2", tt, 1);
vertex shader:
Code: Select all
uniform mat4 mWorldViewProj;
uniform mat4 mInvWorld;
uniform mat4 mTransWorld;
uniform vec3 mLightPos;
uniform vec4 mLightColor;
void main(void)
{
gl_Position = mWorldViewProj * gl_Vertex;
vec4 normal = vec4(gl_Normal, 0.0);
normal = mInvWorld * normal;
normal = normalize(normal);
vec4 worldpos = gl_Vertex * mTransWorld;
vec4 lightVector = worldpos - vec4(mLightPos,1.0);
lightVector = normalize(lightVector);
float tmp2 = dot(-lightVector, normal);
vec4 tmp = mLightColor * tmp2;
gl_FrontColor = gl_BackColor = vec4(tmp.x, tmp.y, tmp.z, 0.0);
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_TexCoord[1] = gl_MultiTexCoord1;
gl_Position = ftransform();
}
Code: Select all
uniform sampler2D myTexture;
uniform sampler2D myTexture2;
void main (void)
{
vec4 col = texture2D(myTexture, vec2(gl_TexCoord[0]));
col = col * texture2D(myTexture2, vec2(gl_TexCoord[1]));
col *= gl_Color;
gl_FragColor = col * 4.0;
}
Sorry for my bad english.