Get in trouble with multi-texture support

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
hongjunyu128
Posts: 18
Joined: Tue Sep 04, 2012 8:27 am

Get in trouble with multi-texture support

Post by hongjunyu128 »

I got troubles in multi-texture supportting!
I'm trying to implement a multitexute demo using Irrlicht-1.7.3, I wrote my own glsl shaders and had been proved right in Rendermonkey, but it didn't work in my irrlicht demo project(this demo is modified from the "10.Shaders" example shipped in Irrlicht-1.7.3's examples).

I had created a custom material type to use my own shaders:

Code: Select all

newMaterialType1 = gpu->addHighLevelShaderMaterialFromFiles(
                    vsFileName, "main", video::EVST_VS_1_1,
                    psFileName, "main", video::EPST_PS_1_1,
                    mc, video::EMT_NORMAL_MAP_SOLID);
    ...
    scene::IAnimatedMesh* mesh = smgr->getMesh("../../media/GUN.3DS");
    scene::IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );
    node->setPosition(core::vector3df(0,0,0));
    node->setMaterialTexture(0, driver->getTexture("../../media/D.tga"));
    node->setMaterialTexture(1, driver->getTexture("../../media/E.tga"));
and set two global variables and sent them to shaders in the OnSetConstants callback:

Code: Select all

int base_map = GL_TEXTURE0_ARB;
    int emission_map = GL_TEXTURE1_ARB;
    ...
    services->setPixelShaderConstant("base_map",(float*)&base_map, 1);
    services->setPixelShaderConstant("emission_map",(float*)&emission_map, 1);
These are my shaders:
Vertex Shader:

Code: Select all

varying vec2 vTexCoord;
 
    void main(void)
    {
       vTexCoord = vec2(gl_MultiTexCoord0);
       gl_Position = ftransform();
    }

Pixel Shader:

Code: Select all

uniform sampler2D base_map;
uniform sampler2D emission_map;
 
varying vec2 vTexCoord;
 
    void main(void)
    {
       vec3 base_color = texture2D(base_map,vTexCoord).xyz;
       vec3 emission_color = texture2D(emission_map,vTexCoord).xyz;
       
       vec3 color0 = base_color + emission_color;
       
       float color0_a = 1.0;
       gl_FragColor = vec4(color0.xyz, color0_a);
    }
I had tried to solve these for a whole day now but still can't find any clue. Hope someone can help me. :D
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Get in trouble with multi-texture support

Post by mongoose7 »

Aren't they supposed to be 0 and 1. What *is* the value of GL_TEXTURE0_ARB? Not 0, I guess?
smso
Posts: 246
Joined: Fri Jun 04, 2010 3:28 pm
Location: Hong Kong

Re: Get in trouble with multi-texture support

Post by smso »

"it didn't work" is not a good cue to the problem.

Have you done:

Code: Select all

node->setMaterialType((video::E_MATERIAL_TYPE)shaderMaterial);
Regards,
smso
hongjunyu128
Posts: 18
Joined: Tue Sep 04, 2012 8:27 am

Re: Get in trouble with multi-texture support

Post by hongjunyu128 »

mongoose7 wrote:Aren't they supposed to be 0 and 1. What *is* the value of GL_TEXTURE0_ARB? Not 0, I guess?
It's OK now~just 0 and 1~thank you :D
Post Reply