Sending Textures and Lightmap of BSP to Shader

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
aguilmet
Posts: 8
Joined: Sun Feb 18, 2007 8:08 pm

Sending Textures and Lightmap of BSP to Shader

Post by aguilmet »

Is it even possible? I'm trying to write a shader that will negate the the bsp textures. I got the textures to turn negative easily but the only thing is that the lightmap does not render. I checked the shader with TyphoonLab's Shader Designer and it works fine but when I run my program with it, the lightmaps don't render? Does anyone know whats wrong or how to fix it?
Here is some of the code:

Vert shader:

Code: Select all

void main()
{		
	gl_TexCoord[0]=gl_MultiTexCoord0;
	gl_Position = ftransform();
} 
Frag shader:

Code: Select all

uniform sampler2D tex; //Texture
uniform sampler2D tex1; //Lightmap?
void main()
{    
   vec4 texval1 = texture2D(tex, vec2(gl_TexCoord[0]));
   vec4 texval2 = texture2D(tex1, vec2(gl_TexCoord[0]));
   gl_FragColor = ((1-texval1)+texval2)*.5;
}
OnSetConstants Callback:

Code: Select all

class MyShaderCallBack : public video::IShaderConstantSetCallBack
{
public:

    virtual void OnSetConstants(IMaterialRendererServices* services, s32 userData)
    {
        services->setPixelShaderConstant("tex1", reinterpret_cast<f32*>(1), 0);
 
    }
};
I figure that I have to send the lightmap to the shader somehow, but I don't know how...
TheC
Posts: 93
Joined: Fri May 05, 2006 7:50 am

Post by TheC »

Lightmaps often use a second set of texture coordinates.

in HLSL, you specify the texture or sampler register of the lightmap, irrlicht handles the setting for you. I don't know what this is in a GL equivalent.
aguilmet
Posts: 8
Joined: Sun Feb 18, 2007 8:08 pm

Post by aguilmet »

Okay, I generalized the problem. Multitexturing simply does not work. BSP isn't the only thing that doesn't cooperate. Here is the irrlicht test cube scene node. One is with my program and the other is from ShaderDesigner.

My Program:
Image
ShaderDesigner:
Image
[/img]
Here is the texture code:

Code: Select all

	
node->setMaterialTexture(0,driver->getTexture("textures/base_floor/tilefloor2.jpg"));
node->setMaterialTexture(1,driver->getTexture("textures/base_button/target.jpg"));	
The shader did not change.
In the ShaderDesigner, I used a uniform variable with an INT type named 'tex1' and with a value of 1. When I disable this, the cube looks exactly like the one in my program. In Irrlicht, I know there is a setPixelShaderConstant function, but it can only send an array of floats. Is there a way to send a single INT named 'tex1' with a value of 1? I think that this will solve my problem.
Thank you.
aguilmet
Posts: 8
Joined: Sun Feb 18, 2007 8:08 pm

Post by aguilmet »

I GOT IT! In the OnSetConstants callback, the 'tex1' constant wasn't being set correctly.
You have to make an INT, then cast it as (float *) &var
Post Reply