Multiple Render Target and Shader
by Arnaud Hubert · in Torque 3D Professional · 04/18/2013 (7:03 pm) · 4 replies
Hi everyone,
I'm actually working on a way to enhance transition between LOD. I find an interesting article which talks about Frame Sequential for Discrete Level of Detail rendering. In this article, there is a explanation of how it works and I'm trying to implement it into my project.
But the problem is that I need an offscreen buffer to store the ID and the depth of the pixel printed to the screen. I've seen that you can do this with Multiple Render Target and Shader. So when my Shader is executed, i'd like to store my informations in this offscreen buffer.
Here is an example of what i want to do:
//Vertex Shader structure
struct VS_IN
{
float3 texCoord : TEXCOORD0;
float id : POSITION0;
float depth : POSITION1;
};
// Pixel Shader Structure
struct PS_OUT
{
float4 color : COLOR0;
float2 idDepth : COLOR1;
};
PS_OUT main( VS_IN VIN): COLOR
{
PS_OUT PSOUT;
PSOUT.color = // color
PSOUT.idDepth.x = VIN.id;
PSOUT.idDepth.y = VIN.depth;
return PSOUT;
};
But I don't have any idea on how to create and use the buffer relied to COLOR1.
I know I have to use setRenderTarget but i'm lost.
Thanks.
I'm actually working on a way to enhance transition between LOD. I find an interesting article which talks about Frame Sequential for Discrete Level of Detail rendering. In this article, there is a explanation of how it works and I'm trying to implement it into my project.
But the problem is that I need an offscreen buffer to store the ID and the depth of the pixel printed to the screen. I've seen that you can do this with Multiple Render Target and Shader. So when my Shader is executed, i'd like to store my informations in this offscreen buffer.
Here is an example of what i want to do:
//Vertex Shader structure
struct VS_IN
{
float3 texCoord : TEXCOORD0;
float id : POSITION0;
float depth : POSITION1;
};
// Pixel Shader Structure
struct PS_OUT
{
float4 color : COLOR0;
float2 idDepth : COLOR1;
};
PS_OUT main( VS_IN VIN): COLOR
{
PS_OUT PSOUT;
PSOUT.color = // color
PSOUT.idDepth.x = VIN.id;
PSOUT.idDepth.y = VIN.depth;
return PSOUT;
};
But I don't have any idea on how to create and use the buffer relied to COLOR1.
I know I have to use setRenderTarget but i'm lost.
Thanks.
#2
Now, I can draw the elements that I want in it.
But a problem remains, elements are drawn with the COLOR0 and I would like to draw them with my COLOR1.
PS : I'm working with a CustomMaterial and Shader, like in the example above.
04/19/2013 (4:52 pm)
Thank you Lukas, I managed to write in a Texture.Now, I can draw the elements that I want in it.
But a problem remains, elements are drawn with the COLOR0 and I would like to draw them with my COLOR1.
PS : I'm working with a CustomMaterial and Shader, like in the example above.
#3
What elements are drawn with color0?
04/21/2013 (1:47 pm)
Oh just had a look at your shader, are you using a vertex shader input for a pixel shader? Shouldn't you be using a pixelshader input? Are you sure that is working?What elements are drawn with color0?
// Pixel Shader Structure
struct PS_OUT
{
float4 color : COLOR0;
float2 idDepth : COLOR1;
};
PS_OUT main( VS_IN VIN): COLOR
{
PS_OUT PSOUT;
// Shouldn't this be set to something?
PSOUT.color = // color
PSOUT.idDepth.x = VIN.id; // Here you are writing to COLOR1
PSOUT.idDepth.y = VIN.depth; // And here
return PSOUT;
};you set PSOUT.color to PSOUT.idDepth.x which is VIN.id
#4
it was just an example of what i want to do.
I use a customMaterial so I use the Alfio's work in this thread www.garagegames.com/community/forums/viewthread/125562.
I haven't got an error in teh console when I compile my shader and run the game.
For now, I'm setting a float4 color1 : COLOR1 declared in struct PS_OUT to color1 = 1.0 in the pixel shader. But I haven't got access to it in C++.
I think I'll try to do it through the RenderPrePass but it's a shame that I have to add a pass to do it.
04/22/2013 (5:56 am)
Hi,it was just an example of what i want to do.
I use a customMaterial so I use the Alfio's work in this thread www.garagegames.com/community/forums/viewthread/125562.
I haven't got an error in teh console when I compile my shader and run the game.
For now, I'm setting a float4 color1 : COLOR1 declared in struct PS_OUT to color1 = 1.0 in the pixel shader. But I haven't got access to it in C++.
I think I'll try to do it through the RenderPrePass but it's a shame that I have to add a pass to do it.
Torque Owner Lukas Joergensen
WinterLeaf Entertainment
Oh and this thread may be worth taking a look at aswell.