Splatting Shader test

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
Contact:

Splatting Shader test

Post by jacmoe » Sat Dec 27, 2008 5:46 pm

I just made another terrain splatting shader work! :D

This one splats up to 8 textures in one pass, using two RGBA alphamaps.

The CG shader:

Code: Select all

struct TerrainVSOutput
{
	// transformed vertex coordinate
	float4	position				: POSITION;
	
	// lighting intensity color multiplier
	float4	color					: COLOR0;
	
	// texture coordinate from vertex
	float2	texCoord				: TEXCOORD0;
	
	// texture coordinate from vertex that has been scaled
	float2	scaledTexCoord			: TEXCOORD2;
	
	// world coordinates of the vertex (one unit per meter)
	float2	worldTexCoord			: TEXCOORD3;
	
	// world coordinates of the vertex (one unit per page)
	float2	worldPageTexCoord		: TEXCOORD4;
	
	// offset of the vertex within the current terrain page (one unit per page, so its limited to 0..1)
	float2	pageTexCoord			: TEXCOORD5;
	
	// texture coordinates for alpha0 splatting map
	float2 alpha0TexCoord			: TEXCOORD6;
	
	// texture coordinates for alpha1 splatting map
	float2 alpha1TexCoord			: TEXCOORD7;
	
	// fog factor
	float  fog						: FOG;
};

// Vertex program for automatic terrain texture generation
TerrainVSOutput TerrainVP
(
	float4				iPosition			: POSITION,
	float3				iNormal				: NORMAL,
	float2				iTexcoord			: TEXCOORD0,

	// the full World/View/Proj combined matrix
	uniform float4x4	worldViewProj,
	
	// Just the world matrix.  Used to find the world coordinates of the vertices for generating
	// some texture coordinates
	uniform float4x4	worldMat,
	
	// Fog settings
	//	fogSettings[0] - fog near distance
	//	fogSettings[1] - fog far distance
	//	fogSettings[2] - fog scale
	uniform float4		fogSettings,

    uniform float4		LightPosition[2],
    uniform float4		LightAttenuation[2],
	
	// Diffuse color of the light
	uniform float4		LightDiffuse[2],

	// Color of the ambient light
	uniform float4		lightAmbient,
	
	// Diffuse color of the terrain
	uniform float4		materialDiffuse,
	
	// Ambient color of the terrain
	uniform float4		materialAmbient,
	
	// Size of a terrain page
	uniform float		pageSize,
	
	// How many meters is one tiling of the terrain textures
	uniform float		textureTileSize,
	
	// used to convert page texture coord to alpha map texture coords
	uniform float4		alpha0TextureCoordAdjust,
	uniform float4		alpha1TextureCoordAdjust
)
{
	TerrainVSOutput output;

    // Calculate the output position and texture coordinates
	output.position  = mul(worldViewProj,iPosition);
	output.texCoord = float2(iPosition.x, iPosition.z)/pageSize;
    output.scaledTexCoord = output.texCoord * 256.0f / textureTileSize;
    
    
    float3 lightDirection[2];
    float lightAttenuation[2];

      
    // transform position to world space
    float4 position = mul(worldMat, iPosition);
    
	
	// get the light and eye direction in world space (not normalized)
    for (int lightIndex = 0; lightIndex < 2; ++lightIndex) {
        float4 lightPosition = mul(worldMat, LightPosition[lightIndex]);

        // Account for whether the light is a point source.
        lightDirection[lightIndex] = lightPosition.xyz - (position * lightPosition.w).xyz;
        // set up attenuation params
        float lightDistance = length(lightDirection[lightIndex]);
        float lightDistanceSquared = lightDistance * lightDistance;

        //lightDistance = 1;
        //LightAttenuation[1].x = 0;

        lightAttenuation[lightIndex] = (lightDistance >
                                        LightAttenuation[lightIndex].x) ?
            0 : (1 / (LightAttenuation[lightIndex].y +
                      LightAttenuation[lightIndex].z * lightDistance +
                      LightAttenuation[lightIndex].w * lightDistanceSquared));
    }
    
    // Do lighting calculations
    output.color = saturate(
					max(dot(iNormal, normalize(lightDirection[0])), 0) *							// diffuse lighting
					LightDiffuse[0] * materialDiffuse * lightAttenuation[0] +	// diffuse color
					max(dot(iNormal, normalize(lightDirection[1])), 0) *							// diffuse lighting
					LightDiffuse[1] * materialDiffuse * lightAttenuation[1] +	// diffuse color
					lightAmbient * materialAmbient);								// ambient color

	// compute page relative offset of vertex, for use as a texture coord
	output.pageTexCoord = fmod( float2(worldMat._m03, worldMat._m23), float2(pageSize, pageSize) );
	if ( output.pageTexCoord.x < 0 ) {
		output.pageTexCoord.x += pageSize;
	}
	if ( output.pageTexCoord.y < 0 ) {
		output.pageTexCoord.y += pageSize;
	}	
	output.pageTexCoord = float2(iPosition.x, iPosition.z) / pageSize;
	
	// compute world world coordinates (just 2d) of vertex, for use as texture coord
	output.worldTexCoord = ( float2(worldMat._m03, worldMat._m23) + float2(iPosition.x, iPosition.z) );
	
	// scale world coords to page size (one unit is one page)
	output.worldPageTexCoord = output.worldTexCoord / pageSize;
	
	// scale world coords to be one unit per meter
	output.worldTexCoord /= 1000;
	
	// compute alpha map texture coords
	output.alpha0TexCoord = output.pageTexCoord * alpha0TextureCoordAdjust.yw + alpha0TextureCoordAdjust.xz;
	output.alpha1TexCoord = output.pageTexCoord * alpha1TextureCoordAdjust.yw + alpha1TextureCoordAdjust.xz;
	
	// compute fog
	float fog = clamp(( output.position.z - fogSettings[0] ) / (fogSettings[1] - fogSettings[0]),0.0,1.0) * fogSettings[2];
    output.fog = 1.0 - fog;
    
    return output;
}

//
// Fragment program for automatic terrain texture generation
// This fragment program splats 4 different terrain textures, and then applies a shade
// mask to vary the intensity of the terrain
//
float4 TerrainFP(
    // output of vertex shader
	TerrainVSOutput In,
	
	uniform float4		alpha0Mask,
	uniform float4		alpha1Mask,
	
	// alpha map 0
    uniform sampler2D   alphaMap0Sampler,
    
    // alpha map 1
    uniform sampler2D   alphaMap1Sampler,
    
    // layer 0 texture
    uniform sampler2D   layer0Sampler,
    
    // layer 1 texture
    uniform sampler2D   layer1Sampler,
    
    // layer 2 texture
    uniform sampler2D	layer2Sampler,
    
    // layer 3 texture
    uniform sampler2D   layer3Sampler,
    
    // layer 4 texture
    uniform sampler2D   layer4Sampler,
    
    // layer 5 texture
    uniform sampler2D	layer5Sampler,
    
    // layer 6 texture
    uniform sampler2D   layer6Sampler,
    
    // layer 7 texture
    uniform sampler2D	layer7Sampler,
    
    // detail texture
    uniform sampler2D	detailSampler    
        
) : COLOR
{
	float4 outputColor;
	
	//return In.color;
	
	// XXX - use worldPageTexCoord for now
	float4 alpha0 = tex2D(alphaMap0Sampler, In.alpha0TexCoord);
	float4 alpha1 = tex2D(alphaMap1Sampler, In.alpha1TexCoord);
	
	alpha0 = alpha0 * alpha0Mask;
	alpha1 = alpha1 * alpha1Mask;

 float4 l0 = tex2D(layer0Sampler, In.scaledTexCoord.xy);
	float4 l1 = tex2D(layer1Sampler, In.scaledTexCoord.xy);
	float4 l2 = tex2D(layer2Sampler, In.scaledTexCoord.xy);
	float4 l3 = tex2D(layer3Sampler, In.scaledTexCoord.xy);
	float4 l4 = tex2D(layer4Sampler, In.scaledTexCoord.xy);
	float4 l5 = tex2D(layer5Sampler, In.scaledTexCoord.xy);
	float4 l6 = tex2D(layer6Sampler, In.scaledTexCoord.xy);
	float4 l7 = tex2D(layer7Sampler, In.scaledTexCoord.xy);
	
	outputColor = alpha0.r * l0 + alpha0.g * l1 + alpha0.b * l2 + alpha0.a * l3
		+ alpha1.r * l4 + alpha1.g * l5 + alpha1.b * l6 + alpha1.a * l7;
	
	// scale output color by the color from the vertex shader, which is the
	// output of the lighting calculations
	outputColor *= In.color;
	
	// add detail map
	outputColor *= tex2D(detailSampler, In.pageTexCoord.xy);
	
	return outputColor;
}
The program decl:

Code: Select all

vertex_program AlphaSplatTerrain/VP cg
{
	source AlphaSplatTerrain.cg
	entry_point TerrainVP
    //target vs_2_0
	profiles vs_2_0 arbvp1
}

fragment_program AlphaSplatTerrain/FP cg
{
	source AlphaSplatTerrain.cg
	entry_point TerrainFP
    //target ps_2_0
	profiles ps_2_0 arbfp1
}
The material:

Code: Select all

material AlphaSplatTerrain
{
    technique
	{
		pass
		{
			vertex_program_ref AlphaSplatTerrain/VP
			{
                param_named_auto worldViewProj      worldviewproj_matrix

                param_named_auto LightDiffuse[0] light_diffuse_colour 0
                param_named_auto LightDiffuse[1] light_diffuse_colour 1
                
                param_named_auto LightPosition[0] light_position_object_space 0
                param_named_auto LightPosition[1] light_position_object_space 1
                
                param_named_auto LightAttenuation[0] light_attenuation 0
                param_named_auto LightAttenuation[1] light_attenuation 1
                
				param_named_auto lightAmbient ambient_light_colour
				param_named materialDiffuse float4 1.0 1.0 1.0 1.0
				param_named materialAmbient float4 0.6 0.6 0.6 1.0
				
				param_named pageSize float 1024
				param_named_auto worldMat world_matrix
                param_named_auto fogSettings fog_params
               	param_named textureTileSize float 10
               	param_named alpha0TextureCoordAdjust float4 0 1 0 1
               	param_named alpha1TextureCoordAdjust float4 0 1 0 1
			}


			fragment_program_ref AlphaSplatTerrain/FP
			{
				param_named alpha0Mask float4 1 1 1 1
				param_named alpha1Mask float4 1 1 1 1
			}
			texture_unit
			{
				texture_alias AlphaMap1
				tex_address_mode clamp
			}
			texture_unit
			{
				texture_alias AlphaMap2
				tex_address_mode clamp
			}
			texture_unit
			{
				texture_alias Splat1
				tex_address_mode wrap
			}
			texture_unit
			{
				texture_alias Splat2
				tex_address_mode wrap
			}
			texture_unit
			{	
				texture_alias Splat3
				tex_address_mode wrap
			}
			texture_unit
			{	
				texture_alias Splat4
				tex_address_mode wrap
			}
			texture_unit
			{	
				texture_alias Splat5
				tex_address_mode wrap
			}
			texture_unit
			{	
				texture_alias Splat6
				tex_address_mode wrap
			}
			
			texture_unit
			{	
				texture_alias Splat7
				tex_address_mode wrap
			}
			
			texture_unit
			{	
				texture_alias Splat8
				tex_address_mode wrap
			}
			
			texture_unit
			{
				texture_alias Detail
				tex_address_mode wrap
			}
		}
	}

	// Fallback technique
	technique
	{
		pass
		{
			shading gouraud

			texture_unit
			{
				texture Fallback
			}
		}
	}
}

material SplatTerrainShader : AlphaSplatTerrain
{
	set_texture_alias AlphaMap1		alphamap1.png
	set_texture_alias AlphaMap2		black.png
	set_texture_alias Splat1		moos1.jpg
	set_texture_alias Splat2		dirt.dds
	set_texture_alias Splat3		grass.dds
	set_texture_alias Splat4		dirt.dds
	set_texture_alias Splat5		moos1.jpg
	set_texture_alias Splat6		moos1.jpg
	set_texture_alias Splat7		moos1.jpg
	set_texture_alias Splat8		moos1.jpg
	set_texture_alias Detail		Detail3.jpg
	set_texture_alias Fallback		cooltex.jpg
}
Any testers? :)
0 x
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.

User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
Contact:

Re: Splatting Shader test

Post by jacmoe » Sun Dec 28, 2008 12:26 am

Look what I did:

http://forum.pnp-terraincreator.com/vie ... 54&start=0

A tutorial about exporting from PnP TerrainCreator to Ogre3D, standard terrain scenemanager with splatting shader. :)
0 x
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.

User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
Contact:

Re: Splatting Shader test

Post by jacmoe » Fri Jan 02, 2009 10:02 pm

0 x
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.

User avatar
aguru
Goblin
Posts: 236
Joined: Tue Feb 26, 2008 5:48 pm

Re: Splatting Shader test

Post by aguru » Fri Jan 02, 2009 10:22 pm

This is really great. Thanks for sharing :)
0 x

User avatar
will.i.am
Gnoblar
Posts: 10
Joined: Tue Aug 19, 2008 11:45 am
Location: Braunschweig, Germany
Contact:

Re: Splatting Shader test

Post by will.i.am » Sat Jan 03, 2009 1:11 am

Many thanks!

This is what im looking for my actual project. I try to implement it and give feedback.
0 x

CyberCop
Gnoblar
Posts: 5
Joined: Sat Jan 03, 2009 7:48 am

Re: Splatting Shader test

Post by CyberCop » Sat Jan 03, 2009 8:14 am

Great thanks, It helps a lot to understanding splatting terrain. :D
It works gracefully with Ogre 1.6.

BTW, there is a typo in material script for fallback technique.
I think "texture Fallback" should be "texture_alias Fallback" to avoid an EXCEPTION report of Ogre.log file.
0 x

User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
Contact:

Re: Splatting Shader test

Post by jacmoe » Sat Jan 03, 2009 1:55 pm

CyberCop wrote:BTW, there is a typo in material script for fallback technique.
I think "texture Fallback" should be "texture_alias Fallback" to avoid an EXCEPTION report of Ogre.log file.
Oops, fixed. :)
0 x
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.

Binxalot
Gnoblar
Posts: 5
Joined: Tue Jan 06, 2009 9:00 pm

Re: Splatting Shader test

Post by Binxalot » Fri Jan 09, 2009 2:38 pm

Does this work on static meshes or only on the a heightmap terrain?
0 x

User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
Contact:

Re: Splatting Shader test

Post by jacmoe » Fri Jan 09, 2009 4:05 pm

It should work on anything. :wink:
0 x
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.

User avatar
aguru
Goblin
Posts: 236
Joined: Tue Feb 26, 2008 5:48 pm

Re: Splatting Shader test

Post by aguru » Fri Feb 06, 2009 5:40 pm

I've been experimenting with this shader, too, and found it very easy to integrate and play around with thanks to the wiki documentation. Thanks again, jacmoe!
0 x

Thaimathai
Gnoblar
Posts: 1
Joined: Mon Mar 09, 2009 2:18 pm

Re: Splatting Shader test

Post by Thaimathai » Mon Mar 09, 2009 2:41 pm

Hello, I've been trying to get this splatting to work; but I'm stuck!

I've created a geometry(heightmap) that is 64x64, and a alphamap that has the same dimension.
I have initialized the alphamap to as grass, and set the right channel to 255, but I set the first pixel to be of something different than grass to see if it is shown correctly.
Been playing around with the numbers in the material too, but with the same result.

Anyone that could have a guess at what I've missed slash done wrong?

Image of result:
http://pici.se/376856/?size=fullsize

On a sidenote: I removed the light calculations and stuff since I ignore that when I splatt in the editor.
0 x

lansglenn
Gnoblar
Posts: 3
Joined: Fri Jul 24, 2009 3:32 am

Re: Splatting Shader test

Post by lansglenn » Tue Jul 28, 2009 10:22 am

After months of silence, I'm reviving this thread. Normally I don't bother to post on this forum because you guys tend to already have solutions to any given problem somewhere tucked around here.

BUT, I believe after several hundred different attempts at getting this shader to work without success and spending over 3 hours doing OGRE forum Search + Google Search w/o finding a proper solution merits a post.

First off, let it be known that I've finally solved my implementation problems with this shader. This post is not an ask-for-help post, but rather a solution post for other complete Ogre/Photoshop/C++/game_developing noobs like myself in the hopes that it may help them out and save them a day's worth of trouble as it has cost me.

But before I go any further, here are my files for those with little time or patience (in-depth information/analysis are after these files, in this post):

Cg file: TerrainAlphaSplat.cg

Code: Select all

struct TerrainVSOutput
{
	// transformed vertex coordinate
	float4	position				: POSITION;
	
	// lighting intensity color multiplier
	float4	color					: COLOR0;
	
	// texture coordinate from vertex
	float2	texCoord				: TEXCOORD0;
	
	// texture coordinate from vertex that has been scaled
	float2	scaledTexCoord			: TEXCOORD2;
	
	// world coordinates of the vertex (one unit per meter)
	float2	worldTexCoord			: TEXCOORD3;
	
	// world coordinates of the vertex (one unit per page)
	float2	worldPageTexCoord		: TEXCOORD4;
	
	// offset of the vertex within the current terrain page (one unit per page, so its limited to 0..1)
	float2	pageTexCoord			: TEXCOORD5;
	
	// texture coordinates for alpha0 splatting map
	float2 alpha0TexCoord			: TEXCOORD6;
	
	// texture coordinates for alpha1 splatting map
	float2 alpha1TexCoord			: TEXCOORD7;
	
	// fog factor
	float  fog						: FOG;
};

// Vertex program for automatic terrain texture generation
TerrainVSOutput TerrainVP
(
	float4				iPosition			: POSITION,
	float3				iNormal				: NORMAL,
	float2				iTexcoord			: TEXCOORD0,

	// the full World/View/Proj combined matrix
	uniform float4x4	worldViewProj,
	
	// Just the world matrix.  Used to find the world coordinates of the vertices for generating
	// some texture coordinates
	uniform float4x4	worldMat,
	
	// Fog settings
	//	fogSettings[0] - fog near distance
	//	fogSettings[1] - fog far distance
	//	fogSettings[2] - fog scale
	uniform float4		fogSettings,

    uniform float4		LightPosition[2],
    uniform float4		LightAttenuation[2],
	
	// Diffuse color of the light
	uniform float4		LightDiffuse[2],

	// Color of the ambient light
	uniform float4		lightAmbient,
	
	// Diffuse color of the terrain
	uniform float4		materialDiffuse,
	
	// Ambient color of the terrain
	uniform float4		materialAmbient,
	
	// Size of a terrain page
	uniform float		pageSize,
	
	// How many meters is one tiling of the terrain textures
	uniform float		textureTileSize
)
{
	TerrainVSOutput output;

    // Calculate the output position and texture coordinates
	output.position  = mul(worldViewProj,iPosition);
	output.texCoord = float2(iPosition.x, iPosition.z) / pageSize;
    output.scaledTexCoord = output.texCoord * 256.0f / textureTileSize;
    
    float3 lightDirection[2];
    float lightAttenuation[2];

      
    // transform position to world space
    float4 position = mul(worldMat, iPosition);
    
	
	// get the light and eye direction in world space (not normalized)
    for (int lightIndex = 0; lightIndex < 2; ++lightIndex) {
        float4 lightPosition = mul(worldMat, LightPosition[lightIndex]);

        // Account for whether the light is a point source.
        lightDirection[lightIndex] = lightPosition.xyz - (position * lightPosition.w).xyz;
        // set up attenuation params
        float lightDistance = length(lightDirection[lightIndex]);
        float lightDistanceSquared = lightDistance * lightDistance;

        //lightDistance = 1;
        //LightAttenuation[1].x = 0;

        lightAttenuation[lightIndex] = (lightDistance >
                                        LightAttenuation[lightIndex].x) ?
            0 : (1 / (LightAttenuation[lightIndex].y +
                      LightAttenuation[lightIndex].z * lightDistance +
                      LightAttenuation[lightIndex].w * lightDistanceSquared));
    }
    
    // Do lighting calculations
    output.color = saturate(
					max(dot(iNormal, normalize(lightDirection[0])), 0) *		// diffuse lighting
					LightDiffuse[0] * materialDiffuse * lightAttenuation[0] +	// diffuse color
					max(dot(iNormal, normalize(lightDirection[1])), 0) *		// diffuse lighting
					LightDiffuse[1] * materialDiffuse * lightAttenuation[1] +	// diffuse color
					lightAmbient * materialAmbient);							// ambient color

	// compute page relative offset of vertex, for use as a texture coord
	output.pageTexCoord = float2(iPosition.x, iPosition.z) / pageSize;
	
	// compute world world coordinates (just 2d) of vertex, for use as texture coord
	output.worldTexCoord = ( float2(worldMat._m03, worldMat._m23) + float2(iPosition.x, iPosition.z) );
	
	// scale world coords to page size (one unit is one page)
	output.worldPageTexCoord = output.worldTexCoord / pageSize;
	
	// scale world coords to be one unit per meter
	output.worldTexCoord /= 1000;
	
	// compute alpha map texture coords
	// Old line of code ===> dunno what it does: output.alpha0TexCoord = output.pageTexCoord * alpha0TextureCoordAdjust.yw + alpha0TextureCoordAdjust.xz;
	output.alpha0TexCoord = iTexcoord;
	output.alpha1TexCoord = iTexcoord;
	
	// compute fog
	float fog = clamp(( output.position.z - fogSettings[0] ) / (fogSettings[1] - fogSettings[0]),0.0,1.0) * fogSettings[2];
    output.fog = 1.0 - fog;
    
    return output;
}


float4 TerrainFP(
    // output of vertex shader
	TerrainVSOutput In,
	
    uniform float4		alpha0Mask,
    uniform float4		alpha1Mask,
	
    // alpha map 0
    uniform sampler2D   alphaMap0Sampler : register(s0),
    
    // alpha map 1
    uniform sampler2D   alphaMap1Sampler : register(s1),
    
    // layer 0 texture
    uniform sampler2D   layer0Sampler : register(s2),
    
    // layer 1 texture
    uniform sampler2D   layer1Sampler : register(s3),
    
    // layer 2 texture
    uniform sampler2D	layer2Sampler : register(s4),
    
    // layer 3 texture
    uniform sampler2D   layer3Sampler : register(s5),
    
    // layer 4 texture
    uniform sampler2D   layer4Sampler : register(s6),
    
    // layer 5 texture
    uniform sampler2D	layer5Sampler : register(s7),
    
    // layer 6 texture
    uniform sampler2D   layer6Sampler : register(s8),
    
    // layer 7 texture
    uniform sampler2D	layer7Sampler : register(s9),
    
    // detail texture
    uniform sampler2D	detailSampler : register(s10)    
        
) : COLOR
{
	float4 outputColor;
	
	float4 alpha0 = tex2D(alphaMap0Sampler, In.alpha0TexCoord);
	float4 alpha1 = tex2D(alphaMap1Sampler, In.alpha1TexCoord);
	
	alpha0 = alpha0 * alpha0Mask;
	alpha1 = alpha1 * alpha1Mask;
	
	float4 l0 = tex2D(layer0Sampler, In.scaledTexCoord.xy);
	float4 l1 = tex2D(layer1Sampler, In.scaledTexCoord.xy);
	float4 l2 = tex2D(layer2Sampler, In.scaledTexCoord.xy);
	float4 l3 = tex2D(layer3Sampler, In.scaledTexCoord.xy);
	float4 l4 = tex2D(layer4Sampler, In.scaledTexCoord.xy);
	float4 l5 = tex2D(layer5Sampler, In.scaledTexCoord.xy);
	float4 l6 = tex2D(layer6Sampler, In.scaledTexCoord.xy);
	float4 l7 = tex2D(layer7Sampler, In.scaledTexCoord.xy);
	
	outputColor = l0 * alpha0.r + l1 * alpha0.g + l2 * alpha0.b + l3 * alpha0.a	+ 
		l4 * alpha1.r + l5 * alpha1.g + l6 * alpha1.b + l7 * alpha1.a;
	
	// scale output color by the color from the vertex shader, which is the
	// output of the lighting calculations
	outputColor *= In.color;
	
	// add detail map
	outputColor *= tex2D(detailSampler, In.pageTexCoord.xy);
	
	return outputColor;
}
Material file: StartTerrain.material

Code: Select all

vertex_program TerrainAlphaSplat/VP cg
{
	source TerrainAlphaSplat.cg
	entry_point TerrainVP
    //target vs_2_0
	profiles vs_2_0 arbvp1
}

fragment_program TerrainAlphaSplat/FP cg
{
	source TerrainAlphaSplat.cg
	entry_point TerrainFP
    //target ps_2_0
	profiles ps_2_0 arbfp1
}

material TerrainAlphaSplatShaderMaterial
{
    technique
	{
		pass
		{
			vertex_program_ref TerrainAlphaSplat/VP
			{
                param_named_auto worldViewProj      worldviewproj_matrix

                param_named_auto LightDiffuse[0] light_diffuse_colour 0
                param_named_auto LightDiffuse[1] light_diffuse_colour 1
                
                param_named_auto LightPosition[0] light_position_object_space 0
                param_named_auto LightPosition[1] light_position_object_space 1
                
                param_named_auto LightAttenuation[0] light_attenuation 0
                param_named_auto LightAttenuation[1] light_attenuation 1
                
				param_named_auto lightAmbient ambient_light_colour
				param_named materialDiffuse float4 0.4 0.4 0.4 1.0
				param_named materialAmbient float4 0.6 0.6 0.6 1.0
				
				param_named pageSize float 1024
				param_named_auto worldMat world_matrix
				param_named_auto fogSettings fog_params
				param_named textureTileSize float 256
			}


			fragment_program_ref TerrainAlphaSplat/FP
			{
				param_named alpha0Mask float4 1 1 1 1
				param_named alpha1Mask float4 0 0 0 0
			}
			texture_unit
			{
				texture_alias AlphaMap1
				tex_address_mode clamp
			}
			texture_unit
			{
				texture_alias AlphaMap2
				tex_address_mode clamp
			}
			texture_unit
			{
				texture_alias Splat1
				filtering anisotropic
			}
			texture_unit
			{
				texture_alias Splat2
				filtering anisotropic
			}
			texture_unit
			{	
				texture_alias Splat3
				filtering anisotropic
			}
			texture_unit
			{	
				texture_alias Splat4
				tex_address_mode wrap
			}
			texture_unit
			{	
				texture_alias Splat5
				tex_address_mode wrap
			}
			texture_unit
			{	
				texture_alias Splat6
				tex_address_mode wrap
			}
			
			texture_unit
			{	
				texture_alias Splat7
				tex_address_mode wrap
			}
			
			texture_unit
			{	
				texture_alias Splat8
				tex_address_mode wrap
			}
			
			texture_unit
			{
				texture_alias Detail
				tex_address_mode wrap
			}
		}
	}

	// Fallback technique
	technique
	{
		pass
		{
			shading phong

			texture_unit
			{
				texture_alias Fallback
			}
		}
	}
}

material StartTerrain : TerrainAlphaSplatShaderMaterial
{	
	set_texture_alias AlphaMap1		rainbow.png
	set_texture_alias AlphaMap2		round_rainbow.png
	
	// In order:
	// Splat1 == Red   Channel of AlphaMap1 image
	// Splat2 == Green Channel of AlphaMap1 image
	// Splat3 == Blue  Channel of AlphaMap1 image
	// Splat4 == Alpha Channel of AlphaMap1 image  (tricky! Make sure to manually add alpha channel to your AlphaMap1 image)
	set_texture_alias Splat1		Sand.png	
	set_texture_alias Splat2		ice_texture.bmp
	set_texture_alias Splat3		splatting_snow.png
	set_texture_alias Splat4		splatting_rock.png

	// In order:
	// Splat5 == Red   Channel of AlphaMap2 image
	// Splat6 == Green Channel of AlphaMap2 image
	// Splat7 == Blue  Channel of AlphaMap2 image
	// Splat8 == Alpha Channel of AlphaMap2 image  (tricky! Make sure to manually add alpha channel to your AlphaMap2 image)	
	set_texture_alias Splat5		FracturedFlow.png
	set_texture_alias Splat6		FracturedFlow.png
	set_texture_alias Splat7		FracturedFlow.png
	set_texture_alias Splat8		FracturedFlow.png
	
	// Detail image is "merged" with every shown image.  Also serves as a base texture.
	set_texture_alias Detail		splatting_rock.png
	
	// Fallback image is used when the user is too cheap to buy a modern graphics card.
	set_texture_alias Fallback		light_texture.png
}
Terrain Scene Manager Configuration file: StartTerrain.cfg

Code: Select all

#number of times the detail texture will tile in a terrain tile
DetailTile=3

# Heightmap source
PageSource=Heightmap

# Heightmap-source specific settings
Heightmap.image=mission01_heightmap.png

# How large is a page of tiles (in vertices)? Must be (2^n)+1
PageSize=1025

# How large is each tile? Must be (2^n)+1 and be smaller than PageSize
TileSize=129

# The maximum error allowed when determining which LOD to use
MaxPixelError=3

# The size of a terrain page, in world units
PageWorldX=15000
PageWorldZ=15000
# Maximum height of the terrain 
MaxHeight=1000

# Upper LOD limit
MaxMipMapLevel=5

VertexNormals=yes
#VertexColors=yes
#UseTriStrips=yes

# Use vertex program to morph LODs, if available
#VertexProgramMorph=yes

# The proportional distance range at which the LOD morph starts to take effect
# This is as a proportion of the distance between the current LODs effective range,
# and the effective range of the next lower LOD
#LODMorphStart=0.2

# This following section is for if you want to provide your own terrain shading routine
# Note that since you define your textures within the material this makes the 
# WorldTexture and DetailTexture settings redundant

# The name of the vertex program parameter you wish to bind the morph LOD factor to
# this is 0 when there is no adjustment (highest) to 1 when the morph takes it completely
# to the same position as the next lower LOD
# USE THIS IF YOU USE HIGH-LEVEL VERTEX PROGRAMS WITH LOD MORPHING
#MorphLODFactorParamName=morphFactor

# The index of the vertex program parameter you wish to bind the morph LOD factor to
# this is 0 when there is no adjustment (highest) to 1 when the morph takes it completely
# to the same position as the next lower LOD
# USE THIS IF YOU USE ASSEMBLER VERTEX PROGRAMS WITH LOD MORPHING
#MorphLODFactorParamIndex=4

# The name of the material you will define to shade the terrain
CustomMaterialName=StartTerrain
Images/files used, for reference, are linked below:
FracturedFlow.png
Sand.png
ice_texture.bmp
light_texture.png
mission01_heightmap.png
rainbow.png
round_rainbow.png
splatting_grass.png
splatting_rock.png
splatting_snow.png

StartTerrain.cfg
StartTerrain.material
TerrainAlphaSplat.cg

How I changed the original files to make it work (for me):
First hurdle was the Cg script not "working right". I tweaked the tweakable parameters in the material files and changed alpha map images through several dozen logical combinations without proper results. Most of the time it would lead to only one image being shown or complete black map surfaces or complete white, but never what *should* appear. As a last act of desperation before dropping the entire shader script for some other alternatives, I decided to gather enough courage to start grinding through the Cg file itself, having never done Cg before. By looking through the script, this Vertex program segment seems kind of odd (original shader here: http://www.ogre3d.org/wiki/index.php/Te ... lat_Shader):

Code: Select all

	// compute page relative offset of vertex, for use as a texture coord
	output.pageTexCoord = fmod( float2(worldMat._m03, worldMat._m23), float2(pageSize, pageSize) );
	if ( output.pageTexCoord.x < 0 ) {
		output.pageTexCoord.x += pageSize;
	}
	if ( output.pageTexCoord.y < 0 ) {
		output.pageTexCoord.y += pageSize;
	}	
	output.pageTexCoord = float2(iPosition.x, iPosition.z) / pageSize;
I've no idea what all of that voodoo does, except that last line ignores all of the calculations done above it.. so a logical step was to remove all of that segment except the last line.

By looking at my still-incorrectly-rendered map, and by simplifying the Fragment program to a mere:

Code: Select all

float4 TerrainFP(
	TerrainVSOutput In,
	
    uniform float4		alpha0Mask,
    uniform float4		alpha1Mask,
	
    uniform sampler2D   alphaMap0Sampler : register(s0),
    uniform sampler2D   alphaMap1Sampler : register(s1),
    uniform sampler2D   layer0Sampler : register(s2),
    uniform sampler2D   layer1Sampler : register(s3),
    uniform sampler2D	layer2Sampler : register(s4),
    uniform sampler2D   layer3Sampler : register(s5),
    uniform sampler2D   layer4Sampler : register(s6),
    uniform sampler2D	layer5Sampler : register(s7),
    uniform sampler2D   layer6Sampler : register(s8),
    uniform sampler2D	layer7Sampler : register(s9),
    uniform sampler2D	detailSampler : register(s10)           
) : COLOR
// ^^^^=== WUT? This method inherits from COLOR?? WTF?
{
	float4 alpha0 = tex2D(alphaMap0Sampler, In.alpha0TexCoord);

      // Return the contents of only the first alpha map
       return alpha0;
}
It was apparent the texture coordinates over the entire world were not correctly mapping to the alpha map image, and vice versa. This is because the *ENTIRE* assertion, the reason for being, the raison d'etre of the Terrain alpha splatting shader rests upon the idea that an alpha map image should cover the entire world map, and that a point on the alpha image maps exactly to a proportional/size-equivalent point on the world.
Example to make my statement clearer:
Suppose the RGBA alpha map image is of size 512x512 pixels, and world height map is of size 1025x1025, and World size is 10240x10240.
Color of alpha map image at the upper-left most corner (0,0) should correspond to the upper-left most corner of the world height map, which should correspond to roughly region (0,0) of the world.
Color of alpha map image at the center-middle (255,255) should correspond to the center-middle the world height map, which should correspond to roughly region (5120,5120) of the world.

But such was not the case. I was seeing this:
Image

After removing Hydrax, it was verified that the shader registered all RGBA colors on good 'ol rainbow.png that I was using as an alpha map image, except that the texture coordinates were off. Since the texture coordinate get their numbers from the vertex program by means of the TerrainVSOutput struct generated by the Vertex program... more specifically the alpha0TexCoord member of the struct in vertex program.. that was the culprit. After toying with a bunch of possible variables I landed on iTexcoord as the proper variable for alpha0TexCoord to use.. and thus the implementation problem was solved.... Almost.

My next hurdle in implementating the shader was a Photoshop problem. I couldn't figure out how to work with the Alpha channel of a PNG image! Because PNG files by default set Alpha to 1 (fully opague) and do not have an explicit alpha channel upon creation, you must explicitly manually make the alpha channel in the Layers window/tab! After figuring that out, the shader works wonderfully. :mrgreen:
0 x

User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
Contact:

Re: Splatting Shader test

Post by jacmoe » Tue Jul 28, 2009 11:15 am

Thanks for sharing! :)
I'll keep your version in mind when I revisit it for the new Ogre terrain.
0 x
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.

Kenshido
Gremlin
Posts: 153
Joined: Tue Jun 09, 2009 9:31 am
Location: Russia
Contact:

Re: Splatting Shader test

Post by Kenshido » Sat Sep 05, 2009 8:18 pm

How to make SHADOWTYPE_TEXTURE_MODULATIVE shadows to work correctly with this shader. Or it's just my custom problem?
Attachments
screenshot_2.jpg
With shader
screenshot_2.jpg (100.22 KiB) Viewed 7646 times
screenshot_1.jpg
Without shader
screenshot_1.jpg (116.26 KiB) Viewed 7646 times
0 x

Kenshido
Gremlin
Posts: 153
Joined: Tue Jun 09, 2009 9:31 am
Location: Russia
Contact:

Re: Splatting Shader test

Post by Kenshido » Mon Sep 07, 2009 6:02 pm

The answer is found. You should translate shadow texture into pixel shader program, and shadow texture coordinates into vertex shader. Then apply shadow texture information to pixels.
0 x

User avatar
tdev
Silver Sponsor
Silver Sponsor
Posts: 244
Joined: Thu Apr 12, 2007 9:21 pm
Location: Germany

Re: Splatting Shader test

Post by tdev » Tue Nov 17, 2009 1:24 pm

i wonder if it is possible to integrate PSSM into the shader and if it would be worth the hassle.
0 x

User avatar
aguru
Goblin
Posts: 236
Joined: Tue Feb 26, 2008 5:48 pm

Re: Splatting Shader test

Post by aguru » Tue Nov 17, 2009 1:59 pm

I'd personally wait for ogre's new terrain system to mature. It already supports splatting, and pssm shadows are on sinbad's list. :)
0 x

Kenshido
Gremlin
Posts: 153
Joined: Tue Jun 09, 2009 9:31 am
Location: Russia
Contact:

Re: Splatting Shader test

Post by Kenshido » Sun Nov 22, 2009 8:26 am

tdev wrote:i wonder if it is possible to integrate PSSM into the shader and if it would be worth the hassle.
There's no integration problem. For example:

terrain.material

Code: Select all

// declare the vertex shader (CG for the language)
vertex_program PSSM/shadow_caster_vs cg
{
	// source file
	source pssm.cg
	// will run on vertex shader 1.1+
	profiles vs_1_1 arbvp1
	// entry function
	entry_point shadow_caster_vs

	default_params
	{
		param_named_auto wvpMat worldviewproj_matrix
		// this is the scene's depth range
		//param_named_auto depthRange			scene_depth_range
		//param_named_auto optimalAdustFactor	custom 0
	}
}

// declare the fragment shader (CG for the language)
fragment_program PSSM/shadow_caster_ps cg
{
	// source file
	source pssm.cg
	// will run on pixel shader 2.0+
	profiles ps_2_0 arbfp1
	// entry function
	entry_point shadow_caster_ps

	default_params
	{
	}
}

material PSSM/shadow_caster
{
	technique
	{
		// all this will do is write depth and depthІ to red and green
		pass
		{
			vertex_program_ref PSSM/shadow_caster_vs
			{
			}

			fragment_program_ref PSSM/shadow_caster_ps
			{
			}
		}
	}
}



vertex_program PSSM/shadow_receiver_vs cg
{
	source pssm.cg
	profiles vs_1_1 arbvp1
	entry_point shadow_receiver_vs

	default_params
	{
		param_named_auto lightPosition				light_position_object_space 0
		param_named_auto eyePosition				camera_position_object_space
		param_named_auto worldViewProjMatrix		worldviewproj_matrix
		param_named_auto texWorldViewProjMatrix0	texture_worldviewproj_matrix 0
		param_named_auto texWorldViewProjMatrix1	texture_worldviewproj_matrix 1
		param_named_auto texWorldViewProjMatrix2	texture_worldviewproj_matrix 2
		//param_named_auto depthRange0				shadow_scene_depth_range 0
		//param_named_auto depthRange1				shadow_scene_depth_range 1
		//param_named_auto depthRange2				shadow_scene_depth_range 2
	}
}

fragment_program PSSM/shadow_receiver_ps cg
{
	source pssm.cg
	profiles ps_2_x arbfp1
	entry_point shadow_receiver_ps

	default_params
	{
		param_named_auto lightDiffuse		derived_light_diffuse_colour 0
		param_named_auto lightSpecular		derived_light_specular_colour 0
		param_named_auto ambient			derived_ambient_light_colour 
		param_named_auto invShadowMapSize0	inverse_texture_size 0
		param_named_auto invShadowMapSize1	inverse_texture_size 1
		param_named_auto invShadowMapSize2	inverse_texture_size 2
		//param_named pssmSplitPoints MANUAL
	}
}


abstract material PSSM/base_receiver
{
	technique
	{
		pass
		{
			vertex_program_ref PSSM/shadow_receiver_vs 
			{
			}
			fragment_program_ref PSSM/shadow_receiver_ps 
			{
				param_named textureTileSize float 240
			}

			texture_unit shadow_tex0
			{
				content_type shadow
				tex_address_mode clamp
			}
			texture_unit shadow_tex1
			{
				content_type shadow
				tex_address_mode clamp
			}
			texture_unit shadow_tex2
			{
				content_type shadow
				tex_address_mode clamp
			}

			// Splatting
			texture_unit
			{
				// Alpha texture 0
				texture mymap01_d.png
			}
			texture_unit
			{
				// Splatting 1
				texture bigRockFace.png
			}
			texture_unit
			{
				// Splatting 2
				texture hardDirt.png
			}
			texture_unit
			{
				// Splatting 3
				texture packDirt.png
			}
			texture_unit
			{
				// Splatting 4
				texture grass_1024.jpg
			}
			texture_unit
			{
				// Lightmap
				texture mymap01_l.png
			}
		}
	}
}
pssm.cg

Code: Select all

void shadow_caster_vs(
	float4 position			: POSITION,
	float2 uv         : TEXCOORD0,

	out float4 oPosition	: POSITION,
	out float2 oDepth		: TEXCOORD0,
	out float2 ouv	:TEXCOORD1,

	uniform float4x4 wvpMat)
{
	// this is the view space position
	oPosition = mul(wvpMat, position);

	// depth info for the fragment.
	oDepth.x = oPosition.z;
	oDepth.y = oPosition.w;

	// clamp z to zero. seem to do the trick. :-/
	//oPosition.z = max(oPosition.z, 0);

	ouv = uv;
}

void shadow_caster_ps(
	float2 depth		: TEXCOORD0,
	float2 uv : TEXCOORD1,
	uniform sampler2D    pDiffuseMap    : register(s0),

	out float4 oColour	: COLOR,

	uniform float4 pssmSplitPoints)
{
	if (tex2D(pDiffuseMap, uv).a < 0.5)
	{
		discard;
	}

	float finalDepth = depth.x / depth.y;
	oColour = float4(finalDepth, finalDepth, finalDepth, 1);
}



void shadow_receiver_vs(
	float4 position				: POSITION,
	float3 normal				: NORMAL,
	float2 uv				: TEXCOORD0,

	out float4 oPosition		: POSITION,
	out float3 oUv			: TEXCOORD0,
	out float3 oLightDir		: TEXCOORD1,
	out float3 oHalfAngle		: TEXCOORD2,
	out float4 oLightPosition0	: TEXCOORD3,
	out float4 oLightPosition1	: TEXCOORD4,
	out float4 oLightPosition2	: TEXCOORD5,
	out float3 oNormal		: TEXCOORD6,

	uniform float4 lightPosition,				// object space
	uniform float3 eyePosition,					// object space
	uniform float4x4 worldViewProjMatrix,
	uniform float4x4 texWorldViewProjMatrix0,
	uniform float4x4 texWorldViewProjMatrix1,
	uniform float4x4 texWorldViewProjMatrix2)
{
	// calculate output position
	oPosition = mul(worldViewProjMatrix, position);

	// pass the main uvs straight through unchanged
	oUv.xy = uv;
	oUv.z = oPosition.z;

	// calculate tangent space light vector
	// Get object space light direction
	oLightDir = normalize(lightPosition.xyz - (position * lightPosition.w).xyz);

	// Calculate half-angle in tangent space
	float3 eyeDir = normalize(eyePosition - position.xyz);
	oHalfAngle = normalize(eyeDir + oLightDir);	

	// Calculate the position of vertex in light space
	oLightPosition0 = mul(texWorldViewProjMatrix0, position);
	oLightPosition1 = mul(texWorldViewProjMatrix1, position);
	oLightPosition2 = mul(texWorldViewProjMatrix2, position);

	oNormal = normal;
}

float shadowPCF(sampler2D shadowMap, float4 shadowMapPos, float2 offset)
{
	shadowMapPos = shadowMapPos / shadowMapPos.w;
	float2 uv = shadowMapPos.xy;
	float3 o = float3(offset, -offset.x) * 0.3f;

	// Note: We using 2x2 PCF. Good enough and is alot faster.
	float c =	(shadowMapPos.z <= tex2D(shadowMap, uv.xy - o.xy).r) ? 0.5 : 0; // top left
	c +=		(shadowMapPos.z <= tex2D(shadowMap, uv.xy + o.xy).r) ? 0.5 : 0; // bottom right
	c +=		(shadowMapPos.z <= tex2D(shadowMap, uv.xy + o.zy).r) ? 0.5 : 0; // bottom left
	c +=		(shadowMapPos.z <= tex2D(shadowMap, uv.xy - o.zy).r) ? 0.5 : 0; // top right
	//float c =	(shadowMapPos.z <= tex2Dlod(shadowMap, uv.xyyy - o.xyyy).r) ? 1 : 0; // top left
	//c +=		(shadowMapPos.z <= tex2Dlod(shadowMap, uv.xyyy + o.xyyy).r) ? 1 : 0; // bottom right
	//c +=		(shadowMapPos.z <= tex2Dlod(shadowMap, uv.xyyy + o.zyyy).r) ? 1 : 0; // bottom left
	//c +=		(shadowMapPos.z <= tex2Dlod(shadowMap, uv.xyyy - o.zyyy).r) ? 1 : 0; // top right
	return (c / 4) + 0.5;
}

float shadowPCF1(sampler2D shadowMap, float4 shadowMapPos, float2 offset)
{
	shadowMapPos = shadowMapPos / shadowMapPos.w;
	float2 uv = shadowMapPos.xy;
	float3 o = float3(offset, -offset.x) * 0.3f;

	// Note: We using 2x2 PCF. Good enough and is alot faster.
	float c =	(shadowMapPos.z <= tex2D(shadowMap, uv.xy - o.xy).r) ? 1 : 0.5; // top left
	return c;
}

// to put it simply, this does 100% per pixel diffuse lighting
void shadow_receiver_ps(
	float3 uv				: TEXCOORD0,
	float3 OSlightDir			: TEXCOORD1,
	float3 OShalfAngle		: TEXCOORD2,
	float4 LightPosition0	: TEXCOORD3,
	float4 LightPosition1	: TEXCOORD4,
	float4 LightPosition2	: TEXCOORD5,
	float3 normal			: TEXCOORD6,

	out float4 oColour		: COLOR,

	uniform float4 ambient,
	uniform float4 invShadowMapSize0,
	uniform float4 invShadowMapSize1,
	uniform float4 invShadowMapSize2,
	uniform float4 pssmSplitPoints,
	uniform sampler2D shadowMap0,
	uniform sampler2D shadowMap1,
	uniform sampler2D shadowMap2,
	uniform sampler Alpha0Texture,
	uniform sampler Splatting1,
	uniform sampler Splatting2,
	uniform sampler Splatting3,
	uniform sampler Splatting4,
	uniform sampler LightmapTexture,

	uniform float textureTileSize
	)
{
	// calculate shadow
	float shadowing = 1.0f;
	float4 splitColour;
	if (uv.z <= pssmSplitPoints.y)
	{
//		splitColour = float4(0.1, 0, 0, 1);
		shadowing = shadowPCF(shadowMap0, LightPosition0, invShadowMapSize0.xy);
	}
	else if (uv.z <= pssmSplitPoints.z)
	{
//		splitColour = float4(0, 0.1, 0, 1);
		shadowing = shadowPCF1(shadowMap1, LightPosition1, invShadowMapSize1.xy);
	}
	else
	{
//		splitColour = float4(0.1, 0.1, 0, 1);
		shadowing = shadowPCF1(shadowMap2, LightPosition2, invShadowMapSize2.xy);
	}

//	shadowing = (shadowing + 1) / 2;

	float4 Alpha0Tex = tex2D(Alpha0Texture, uv);
	float4 Splatting1Tex = tex2D(Splatting1, uv * textureTileSize);
	float4 Splatting2Tex = tex2D(Splatting2, uv * textureTileSize);
	float4 Splatting3Tex = tex2D(Splatting3, uv * textureTileSize);
	float4 Splatting4Tex = tex2D(Splatting4, uv * textureTileSize);
	float4 LightmapTex = tex2D(LightmapTexture, uv);

	oColour = ((Splatting1Tex * Alpha0Tex.r +
		 Splatting2Tex * Alpha0Tex.g +
		 Splatting3Tex * Alpha0Tex.b +
		 Splatting4Tex * Alpha0Tex.a) * shadowing * LightmapTex * ambient);
//		 Splatting4Tex * Alpha0Tex.a) * shadowing * ambient);
}

Attachments
screenshot_5.jpg
screenshot_5.jpg (92.01 KiB) Viewed 6924 times
0 x

User avatar
Tup4c
Gnoblar
Posts: 5
Joined: Mon Jan 18, 2010 7:45 pm

Re: Splatting Shader test

Post by Tup4c » Mon Jan 18, 2010 8:01 pm

Hi everyone. I did exactly what lansglenn said but i still have a black terrain or (if i define it) the Fallback texture. I tried to modify everything in textures but unsuccessfully.
Is that a textures problem ? (i have an alpha channel in all my masks and i tried 2^+1 & 2^ in all my textures and masks)
Or anything else, shader? (I didn't see any logs for shaders compilation)


ps : can anyone give us the lansglenn's textures (links are broken)


thanks.
0 x

User avatar
aguru
Goblin
Posts: 236
Joined: Tue Feb 26, 2008 5:48 pm

Re: Splatting Shader test

Post by aguru » Mon Jan 18, 2010 8:17 pm

I know I'm repeating myself but did you take a look at the new terrain in ogre 1.7? The new terrain shaders not only support shadows and normal/parallax mapped splatting out of the box, they are also very fast for what they do.

If you still need help with this shader you should really post the ogre log here.
0 x

User avatar
Tup4c
Gnoblar
Posts: 5
Joined: Mon Jan 18, 2010 7:45 pm

Re: Splatting Shader test

Post by Tup4c » Mon Jan 18, 2010 10:46 pm

Ok! thanks god! I was trying since a while to compile addons from svn and didn't take a look to 1.7 changelog.
I'm waiting impatiently for the c:b SDK :D

thx again.
0 x

User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
Contact:

Re: Splatting Shader test

Post by jacmoe » Tue Jan 19, 2010 10:17 am

You have to wait a long, long time for an Ogre Code::Blocks SDK, I'm afraid.
We have no maintainer for it.
Either move to Visual Studio Express, or do it yourself.
0 x
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.

User avatar
tdev
Silver Sponsor
Silver Sponsor
Posts: 244
Joined: Thu Apr 12, 2007 9:21 pm
Location: Germany

Re: Splatting Shader test

Post by tdev » Tue Mar 30, 2010 12:52 am

jacmoe wrote:You have to wait a long, long time for an Ogre Code::Blocks SDK, I'm afraid.
We have no maintainer for it.
Either move to Visual Studio Express, or do it yourself.
CMake can generate Codeblock projects as well IIRC
0 x

User avatar
hebdemnobad
Goblin
Posts: 274
Joined: Wed Feb 09, 2005 5:09 pm
Location: catskill escarpment, new york, usa
Contact:

Re: Splatting Shader test

Post by hebdemnobad » Tue Jan 18, 2011 4:06 pm

jacmoe wrote:It should work on anything. :wink:
It works with a .mesh object. Is there any way to get the following parameters into your verrsion of the shader, specifically:

uv tiling for each texture so you can have multiple maps in specific parts of the main alpha maps
more than two alpha maps
a pass for normal maps along with uv tiling for them

let me know I'm an ignorant otherwise with shader coding.

-h
0 x

User avatar
nirvan
Gnoblar
Posts: 11
Joined: Sat Feb 27, 2010 12:19 pm

Re: Splatting Shader test

Post by nirvan » Sun Jul 17, 2011 11:54 pm

Hi, this is my first shader, what I want to "install" correctly, but i have problems.
There is data files, what i am using to make terrain:
http://www.mediafire.com/?5cyearif6h5v331

When i use other material on terrain i see this but when i want use shader i don't see terrain. Why?

Maybe this is because i using wrapper? (GMogre)
But other shaders working correctly, for example this: http://www.ogre3d.org/tikiwiki/Normal+A ... e=Cookbook
0 x
I using Image gmogre3d.org

Post Reply