Texture blending

Hi,

I have the following situation:
My models have:

  1. basic texture, which defines basic coloring (these are mostly neutral greyish colors)
  2. let’s call it “color” texture, which is supposed to be used for color blending on top of basic texture, similar to panda’s MBlend parameter, but my texture is not grayscale; in fact, each of RGB channels in my texture defines one color and one blending.

Theoretically, I could separate each channel into a separate texture, modify it to grayscale and do blend with it, but this way I have burned through 4 texturestages (1=basic tex, 2,3,4=blending textures)

Is there any clever way to do this, or should I look into writing shaders? :slight_smile:

Once you want to start assigning different purposes to the different channels, you’re in the realm of custom shaders. :slight_smile:

David

A feature like that (tint maps) is very, very useful, I wouldn’t mind if the auto shader would support that… some day :wink:

Hm, figured as much, thanks for the response.
Time to put my shader hat on and start carving away :slight_smile:

One other thing, if I use my custom shader will I be able to use Panda’s auto shader for normal and gloss maps, or do I need to have them in custom shader as well?

You’ll need to have them in your custom shader. You can’t have both the autoshader and your own shader applied.

But you can dump the generated shaders, so you don’t need to write everything from scratch. It doesn’t give you the most readable code in the world, but I thought I’ll point it out anyway.

Thanks for the answers guys, I’m looking forward to the shader challenge :slight_smile:

Wondering if any work had gotten done on this?
As I’m just starting to look at this for my game.

Unfortunately, I have been very busy with other stuff on the project so I haven’t done any real work on this so far…

Thanks for replying. If I can come up with anything, I will post.

For anyone who knows about shaders, I just need a hint:

As a test, I’m trying to recolor a part of a model (gloves - they are textured).
Here’s the Python code (which works fine):

		myShader = Shader.load("color.sha", Shader.SLCg)
		x = self.model.find("**/_arms_gloves-cav_hands")
		if x:
			x.setShader(myShader)

And here’s the very basic color.sha:

//Cg

void vshader(
	uniform float4x4 mat_modelproj,
	in float4 vtx_position : POSITION,
	out float4 l_position : POSITION)
{
	l_position = mul(mat_modelproj, vtx_position);
}

void fshader(
	out float4 o_color : COLOR)
{
	o_color = float4(1.0, 0.0, 0.0, 1.0);
}

As I said, it works, but it seems to be coloring the model, not the texture (which makes sense as there is no mention of texture in my shader).

What would I need to do to recolor the texture on that part of the model? Or am I going about this the wrong way?

If the problem is that you can’t see hand texture through the color you need to blend texture and your wanted color.

Here’s the shader. Tested with Panda3D-1.8.0.
You set color in your script with model.setShaderInput(“outColor”, (0, 1, 0, 0.1))

//Cg

void vshader(
    uniform float4x4 mat_modelproj,
    in float4 vtx_position : POSITION,
    in float4 vtx_color : COLOR,
    out float4 l_color : COLOR,
    out float4 l_position : POSITION,
    uniform float4 outColor,
    in float2 vtx_texcoord0 : TEXCOORD0,
    out float2 l_texcoord0 : TEXCOORD0
)
{
    l_color = outColor;
    l_position = mul(mat_modelproj, vtx_position);
    l_texcoord0 = vtx_texcoord0;
}
 
void fshader(
    in half4 l_color : COLOR,
    out half4 o_color : COLOR,
    in half2 l_texcoord0 : TEXCOORD0,
    uniform sampler2D tex_0)
{
    o_color = tex2D(tex_0, l_texcoord0) * l_color;
}

Thx for the reply. This is very helpful.

It blends the model color with the texture, which is good, but is there a way I can change the actual texture colors.? Similar to what photoshop or another paint program would do with its “hue” controls.

The code above is similar to what setcolor does.

Do I need to somehow just control the blending with the 4 params?

panda3d.org/forums/viewtopic … 3434#83434

Here I posted the shader for conversion to Hue. Though it’s probably not entirely correct. If you know what could be done to improve it please tell.