Texture Splatting [OpenGL]
-
- Posts: 226
- Joined: Fri Aug 22, 2008 8:50 pm
- Contact:
HLSL shader:
Code: Select all
float4x4 matViewProjection : ViewProjection;
sampler2D splatMap = sampler_state
{
ADDRESSU = WRAP;
ADDRESSV = WRAP;
ADDRESSW = WRAP;
};
sampler2D layer_red = sampler_state
{
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
ADDRESSU = WRAP;
ADDRESSV = WRAP;
ADDRESSW = WRAP;
};
sampler2D layer_green = sampler_state
{
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
ADDRESSU = WRAP;
ADDRESSV = WRAP;
ADDRESSW = WRAP;
};
sampler2D layer_blue = sampler_state
{
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
ADDRESSU = WRAP;
ADDRESSV = WRAP;
ADDRESSW = WRAP;
};
struct VS_INPUT
{
float4 Position : POSITION0;
float2 alphamap : TEXCOORD0;
float2 tex : TEXCOORD1;
};
struct VS_OUTPUT
{
float4 Position : POSITION0;
float2 alphamap : TEXCOORD0;
float2 tex : TEXCOORD1;
};
struct PS_OUTPUT
{
float4 diffuse : COLOR0;
};
VS_OUTPUT vs_main(in VS_INPUT Input)
{
VS_OUTPUT Output;
Output.Position = mul( Input.Position, matViewProjection );
Output.alphamap = Input.alphamap;
Output.tex = Input.tex;
return( Output );
}
PS_OUTPUT ps_main(in VS_OUTPUT input)
{
float texScale = 10.0f;
PS_OUTPUT output = (PS_OUTPUT)0;
float4 a = tex2D(splatMap, input.alphamap);
float4 i = tex2D(layer_red, input.tex*texScale);
float4 j = tex2D(layer_green, input.tex*texScale);
float4 k = tex2D(layer_blue, input.tex*texScale);
output.diffuse = float4(a.r*i+a.g*j+a.b*k)*float4(1,1,1,a.a);
return output;
}
technique Default_DirectX_Effect
{
pass Pass_0
{
VertexShader = compile vs_2_0 vs_main();
PixelShader = compile ps_2_0 ps_main();
}
-
- Posts: 1638
- Joined: Mon Apr 30, 2007 3:24 am
- Location: Montreal, CANADA
- Contact:
-
- Posts: 226
- Joined: Fri Aug 22, 2008 8:50 pm
- Contact:
Hi,
Buck1000: The shader takes the first uv layer(0) for the splatting map and the second(1) for the other textures. Simply add two uv layers to your model and scale the first one so that the splatmap fits correctly and the second so that the other materials are tiled.
If you only want one uv layer, you can adjust the shader. Remove the "gl_TexCoord[1] = gl_MultiTexCoord1;" in the vertex shader and replace all gl_TexCoord[1] with gl_TexCoord[0] in the fragment shader. The shader then only takes the first uv layer for all textures.
Additionally you could scale the texturecoordinates within the fragment shader "gl_TexCoord[0].xy*20" or something like that to tile the color textures.
greetings
Buck1000: The shader takes the first uv layer(0) for the splatting map and the second(1) for the other textures. Simply add two uv layers to your model and scale the first one so that the splatmap fits correctly and the second so that the other materials are tiled.
If you only want one uv layer, you can adjust the shader. Remove the "gl_TexCoord[1] = gl_MultiTexCoord1;" in the vertex shader and replace all gl_TexCoord[1] with gl_TexCoord[0] in the fragment shader. The shader then only takes the first uv layer for all textures.
Additionally you could scale the texturecoordinates within the fragment shader "gl_TexCoord[0].xy*20" or something like that to tile the color textures.
greetings
-
- Posts: 226
- Joined: Fri Aug 22, 2008 8:50 pm
- Contact:
Hi,
if you can't find a way, you can use this modfied shader:
To set a different scale for the color textures change the "float factor" to any value you want. However, that would change the value globally for all nodes with this shader.
greetings
if you can't find a way, you can use this modfied shader:
Code: Select all
const c8 *vertShader = "void main()\
{\
gl_TexCoord[0] = gl_MultiTexCoord0;\
gl_Position = ftransform();\
}\
";
//Fragment Shader
const c8 *fragShader = "uniform sampler2D splatMap;\
uniform sampler2D layer_red;\
uniform sampler2D layer_green;\
uniform sampler2D layer_blue;\
\
void main(){\
float factor = 20;\
vec4 SplatCol=texture2D(splatMap,gl_TexCoord[0].xy);\
vec4 RedCol=texture2D(layer_red,gl_TexCoord[0].xy*factor);\
vec4 GreenCol=texture2D(layer_green,gl_TexCoord[0].xy*factor);\
vec4 BlueCol=texture2D(layer_blue,gl_TexCoord[0].xy*factor);\
gl_FragColor=(vec4(SplatCol.r*RedCol+SplatCol.g*GreenCol+SplatCol.b*BlueCol))*vec4(1,1,1,SplatCol.a);\
}\
";
greetings
Re: Texture Splatting [OpenGL]
Hey i just compiled this on a MacBook Pro 13' with NVIDIA GeForce 320M. Pretty easy, just add CMultiTexturingManager.h, CMultiTexturingManager.cpp (rename it to CMultiTexturingManager.mm) and main.cpp (rename to main.mm) and compile!
It works really well, i added a 513 terrain, the fps is unstable but it is around 34 to 156, as for the standard terrain it is about 300.
Only problem is:
It works really well, i added a 513 terrain, the fps is unstable but it is around 34 to 156, as for the standard terrain it is about 300.
Only problem is:
Thank youby roelor » Tue Jun 08, 2010 12:05 am
this doesnt work well on my intel gma 4500. framerate is low, (thats to be expected) but the terrain is transparant in the distance. (you can look through the terrain).
by freetimecoder » Wed Jun 09, 2010 9:03 am
Hi,
Is it transparent only in the distance or everywhere? Only in the distance. Does it look like on the screenshot, ecxept the transparency? Looks like on the screenshots. What OpenGL/GLSL version do you have? OpenGL 2.1 Does it give any errors in the console? Dont think so.
greetings
Re: Texture Splatting [OpenGL]
Totally neglected my post :/ Glad you could answer, I can always pick the laptop up again to retest if neccesairy.
Re: Texture Splatting [OpenGL]
Hi, again.
I just got my new iMac 27'
RAM: 12GB
Processor: 3.4 i7
SSD
2gb display card
Error is still there, even on such hardware...
Seems like there is some error with mac osx
I just got my new iMac 27'
RAM: 12GB
Processor: 3.4 i7
SSD
2gb display card
Error is still there, even on such hardware...
Seems like there is some error with mac osx