I have been asking lots of questions and bugging alot of people for a few days but I have finnally made my first steps here.
I have made a simple texture shader material that accepts 2 tiled textures, and one mask texture, that blends the two together.
This is an example mask texture, just a brush stroke.
This is what the material looks like rendered on a plane.. It seems like it will be quite easy to extend this shader to accept more textures, but (I think) the drawback being dramatic drops in framerates. Maybe someone can look at it and tell me ways to speed it up?
Here are the shader files
Code: Select all
// my vertex shader
void main()
{
gl_TexCoord[1] = gl_MultiTexCoord1;
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform();
}
Code: Select all
// my fragment shader
uniform sampler2D grass;
uniform sampler2D soil;
uniform sampler2D mask;
void main()
{
vec4 first = texture2D(grass,vec2(gl_TexCoord[0]));
vec4 second = texture2D(soil,vec2(gl_TexCoord[0]));
vec4 third = texture2D(mask,vec2(gl_TexCoord[1]));
float x = clamp(third,0.0,1.0);
float y = 1.0-x;
vec4 color1 = first*x;
vec4 color2 = second*y;
gl_FragColor = vec4(color1+color2);
}
Here is what to put in the shader callback
Code: Select all
class MyShaderCallBack : public irr::video::IShaderConstantSetCallBack
{
public:
virtual void OnSetConstants(irr::video::IMaterialRendererServices* services, irr::s32 userData)
{
irr::s32 grass = 0;
services->setPixelShaderConstant ( "grass",reinterpret_cast<irr::f32*>(&grass),1);
irr::s32 soil = 1;
services->setPixelShaderConstant ("soil",reinterpret_cast<irr::f32*>(&soil),1);
irr::s32 mask = 2;
services->setPixelShaderConstant ("mask",reinterpret_cast<irr::f32*>(&mask),1);
}
};
Just open for discussion or whatever. Im gonna try it on my level and see how bad it slows everything down.
Edit: The tiled textures must be loaded into texture slots 0 and 1, and the mask texture loaded into slot 2. Also the mesh must contain 2 sets of UV coords, one for the tiled textures and one for the mask.(lightmap UV coords)