Multitexture base blending

Posted By: the_mehmaster

Multitexture base blending - 11/28/09 05:42

I have almost nil experience with shaders...

As you would know, the multitexture terrain shader (terraintex, not terraintex3) just 'splats' detail texture layers on top of the terrain, with no consideration for the texture underneath, which becomes invisible. What i would like to acheive is a shader with the same functionality, but where the detail textures are multiplied over the base texture.

Is this possible?
Posted By: bart_the_13th

Re: Multitexture base blending - 11/28/09 06:26

Sure, it's still possible...
You can use umm... I forgot the code but I think it should be:
Code:
ColorOps[X]=Add;//Where X is the stage number range from 0 to number of layers


You can change Add with Multiply, Multiply2X or Multiply4X...
Hope it helps laugh

[EDIT]
You can also add a bump map using
Code:
ColorOps[X]=DOT3//Or something like that



Sorry it's been a while since I do 3DGS and shaders...
Posted By: the_mehmaster

Re: Multitexture base blending - 11/28/09 06:52

Here's what I need to modify:

Code:
//////////////////////////////////////////////////////////////////////
// terraintex.fx
// Terrain material for an unlimited number of terrain textures
// Tiled texture on RGB, mask on alpha 

Texture entSkin1; // basic tiled terrain texture
Texture LightMap; // lightmap created by the map compiler

bool PASS_SOLID; // enforce rendering on the solid pass

bool AUTORELOAD;

//////////////////////////////////////////////////////////////////////

// technique without lightmap
technique terraintex
{
   pass multi_repeat11
   {
      ZWriteEnable = True;
		AlphaBlendEnable = True;
		SrcBlend = SrcAlpha;
      DestBlend = InvSrcAlpha;
		
		Texture[0] = <entSkin1>;
		TexCoordIndex[0] = 0;
		AlphaOp[0] = SelectArg1;
		AlphaArg1[0] = Texture;
		
		Texture[1] = <entSkin1>;
		TexCoordIndex[1] = 1;
      ColorArg1[1] = Texture; 
	   ColorArg2[1]= Diffuse;
	   ColorOp[1] = Modulate4x;
	   AlphaArg1[1] = Current;
	   AlphaOp[1] = SelectArg1;

	   ColorOp[2] = Disable;
	   AlphaOp[2] = Disable;
	}
}

// technique with lightmap
technique terraintex_lm
{
	pass multi_repeat11
	{
      ZWriteEnable = True;
		AlphaBlendEnable = True;
		SrcBlend = SrcAlpha;
      DestBlend = InvSrcAlpha;
		
		Texture[0] = <entSkin1>;
		TexCoordIndex[0] = 0;
		AlphaOp[0] = SelectArg1;
		AlphaArg1[0] = Texture;
		
		Texture[1] = <LightMap>;
		TexCoordIndex[1] = 0;
      ColorArg1[1] = Texture; 
	   ColorArg2[1]= Diffuse;
	   ColorOp[1] = AddSigned;
	   AlphaArg1[1] = Current;
	   AlphaOp[1] = SelectArg1;

		Texture[2] = <entSkin1>;
		TexCoordIndex[2] = 1;
      ColorArg1[2] = Texture; 
	   ColorArg2[2]= Current;
	   ColorOp[2] = Modulate2x;
	   AlphaArg1[2] = Current;
	   AlphaOp[2] = SelectArg1;

	   ColorOp[3] = Disable;
	   AlphaOp[3] = Disable;
	}
}

// fallback if nothing works
technique fallback { pass one { } }



I tried what you said, but that just made the terrain brighter. Maybe i'm doing something wrong... can you modify it please? Thanks!
Posted By: Spirit

Re: Multitexture base blending - 11/28/09 07:21

If you don't have a terrain lightmap, I would use the lightmap technique because it already does what you want, multiply all detail textures with the lightmap texture. You just need to define the terrain base skin as a bmap, and then copy it into the terrain lightmap pointer

my.lightmap = baseskin_bmap;

Then you dont need to modify the shader. At least thats the general idea - haven't tried it but might be worth a try.
Posted By: the_mehmaster

Re: Multitexture base blending - 11/28/09 07:42

Wow! Turns out you're right, that works perfectly.

Only issue is that the multiplication is a bit too harsh.. but I can resolve that myself.

Thanks Spiritsmile
© 2024 lite-C Forums