Multipass Texture Splatting
Hi,
I need texture samplers for blendmap, normalmaps, base terrain texture and the other textures. However, only 16 texture samplers are available in Shader Model 3.0
So I'm trying to implement terrain texturing so that patches with more textures will be rendered in a second pass.
I'm beginner in writing shaders and don't know how to implement Multipass Texture Splatting. Let's say I want to render 7 textures.(Just an example)
I can render 4 textures with a blendmap. In fact these are 5 textures blended together. Because I'm doing this:
float3 temp1 = lerp(tex0, tex1, blend.r);
float3 temp2 = lerp(temp1, tex2, blend.g);
float3 temp3 = lerp(temp2, tex3, blend.b);
float3 result = lerp(temp3, tex4, blend.a);
So, how do I implement the second pass. Do I need to write a second pixel shader. I can simply set the blendmap and textures to be blended and render. But I can't use the same pixelshader??
Have you considered packing more than one texture into a single, um, texture? As in arranged in a grid? You could fit four 512x512 textures into a single 1024x1024 texture, and use a lookup table to determine the uv offsets.
Of course, texture atlases can be used to minimize the number of the texture samplers.
But this is not the topic. I'm wondering how do I implement blending in more than one, um, passes.("7 textures" was just an example)
But this is not the topic. I'm wondering how do I implement blending in more than one, um, passes.("7 textures" was just an example)
There's a few ways you could do it (if I understand your problem correctly):
1) just have the components of the blendmap zeroed for textures you are not using e.g. on second pass for 7 textures the last two components of the blend map should be 0, assuming 5 textures per pass.
2) use different pixel shaders, would be more efficient.
3) if you are using Cg (or maybe HLSL will do this aswell) you could use interfaces to handle different numbers of input textures through a single pixel shader.
4) also if you are using Cg you could use unsized arrays to procedurally generate the required shaders for different numbers of input textures.
In the end though the pixel shader is going to be short regardless, so using seperate ones wouldn't be too much of a burden (I would imagine).
1) just have the components of the blendmap zeroed for textures you are not using e.g. on second pass for 7 textures the last two components of the blend map should be 0, assuming 5 textures per pass.
2) use different pixel shaders, would be more efficient.
3) if you are using Cg (or maybe HLSL will do this aswell) you could use interfaces to handle different numbers of input textures through a single pixel shader.
4) also if you are using Cg you could use unsized arrays to procedurally generate the required shaders for different numbers of input textures.
In the end though the pixel shader is going to be short regardless, so using seperate ones wouldn't be too much of a burden (I would imagine).
This is maybe a silly question but I need to ask. If I reuse the pixel shader (as suggested)
How do I set the Textures correctly for blending? (I'm getting weird results.)
Thanks in advance
How do I set the Textures correctly for blending? (I'm getting weird results.)
Thanks in advance
Well in the code you are using tex0 in the second pass would be the result of the first pass. You might be better off using the blend values as coefficients (weights) for each texture rather than interpolation factors:
float3 result = tex0 * blend.r + tex1 * blend.g + tex2 * blend.b + tex3 + blend.a;
float3 result = tex0 * blend.r + tex1 * blend.g + tex2 * blend.b + tex3 + blend.a;
Okay, thanks...
Maybe it is a blending state problem. If I render the second pass blending doesn't work correctly, the result of the first pass is a weird color.
What blending state should I set? (for multi pass maybe more then two passes)
Maybe it is a blending state problem. If I render the second pass blending doesn't work correctly, the result of the first pass is a weird color.
What blending state should I set? (for multi pass maybe more then two passes)
Well I would probably use (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) in OpenGL terminology.
Maybe screen shots of first and second pass, and the blend result might help...
What I said before about using weights instead of interpolation depends on how you have your weights set up and the type of results you want:
Using interpolation will work regardless of the sum of the layer weight values, but each new layer with a weight of 1.0 will completely over-write the preceeding layers, and layer order is important.
Using blending and weights will only work correctly if the weights sum to 1.0, but the order of layers is not important, and several layers can be blended together easily.
Maybe screen shots of first and second pass, and the blend result might help...
What I said before about using weights instead of interpolation depends on how you have your weights set up and the type of results you want:
Using interpolation will work regardless of the sum of the layer weight values, but each new layer with a weight of 1.0 will completely over-write the preceeding layers, and layer order is important.
Using blending and weights will only work correctly if the weights sum to 1.0, but the order of layers is not important, and several layers can be blended together easily.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement