Original Post
Hey there,
first of all i have to say that i am fairly new to the whole shader programing or 3D programming in general, so this problem might seem pretty obvious to you.
I want to texture my terrain based on slope and on height. The slope part is working fine but i am having trouble getting the height part working. What i am wanting to accomplish is texturing the terrain near ground level (height <= 10) with a rock texture.
So im using the pixel shader like this:
But if i do it like this only a small area at the top of my screen is getting textured with the rock texture. not based on the terrain. If i rotate my camera around i can see the texture of my terrain changing in this little part of my screen.
This seems kinda odd to me, because i am pretty sure that i am transforming the position coordinates to 3D space like this:
What am i doing wrong?`Thanks to anyone willing to help!
first of all i have to say that i am fairly new to the whole shader programing or 3D programming in general, so this problem might seem pretty obvious to you.
I want to texture my terrain based on slope and on height. The slope part is working fine but i am having trouble getting the height part working. What i am wanting to accomplish is texturing the terrain near ground level (height <= 10) with a rock texture.
So im using the pixel shader like this:
grassColor = grassTexture.Sample(SampleType, input.tex);
// Sample the slope color from the texture using the sampler at this texture coordinate location.
slopeColor = slopeTexture.Sample(SampleType, input.tex);
// Sample the rock color from the texture using the sampler at this texture coordinate location.
rockColor = rockTexture.Sample(SampleType, input.tex);
// Calculate the slope of this point.
slope = 1.0f - input.normal.y;
// Determine which texture to use based on height.
if(slope < 0.2)
{
blendAmount = slope / 0.2f;
textureColor = lerp(grassColor, slopeColor, blendAmount);
}
if((slope < 0.7) && (slope >= 0.2f))
{
blendAmount = (slope - 0.2f) * (1.0f / (0.7f - 0.2f));
textureColor = lerp(slopeColor, rockColor, blendAmount);
}
if((slope >= 0.7) || (input.position.y <= 10))
{
textureColor = rockColor;
}
But if i do it like this only a small area at the top of my screen is getting textured with the rock texture. not based on the terrain. If i rotate my camera around i can see the texture of my terrain changing in this little part of my screen.
This seems kinda odd to me, because i am pretty sure that i am transforming the position coordinates to 3D space like this:
input.position.w = 1.0f;
// Calculate the position of the vertex against the world, view, and projection matrices.
output.position = mul(input.position, worldMatrix);
output.position = mul(output.position, viewMatrix);
output.position = mul(output.position, projectionMatrix);
What am i doing wrong?`Thanks to anyone willing to help!