Quote: "you need two intermediate rendertargets for the whole scene, one for the position map and one for the normal map"
That's right, so because what I'm trying to do will happen in screen space, I need the same view of the scene three times: one which shows every scene objects positions in view space, one with the normals in view space, and the final should be just the quad. The quad then has a technique to combine the to views (and the data they show) to the final rendering.
I hope that makes sense to you. To illustrate my problem better, I've writen a little test application and attached it to this post.
It contains the scene objects shader and the post processing shader, which is applied to the quad (the quad is textured with its own camera image as usual). If you switch the quad shaders technique (return key), you'll see that the output is just corrupted mess. This technique should display the contents of the render target sampler!
So think I'm doing something wrong with feeding the render target image with content. What could I be doing wrong?
Edit:
Here is the program code (C++ & DarkGDK):
// Shader Test Project
// includes
#include "DarkGDK.h"
#include "Util.h"
// main entry point
void DarkGDK ( void )
{
// screen setup
dbSetWindowTitle( "Shader Test" );
dbSetDisplayModeAntialias( 800, 600, 32, 0, 0, 0 );
dbSetWindowPosition( 0, 0 );
dbSyncOn();
dbSyncRate( 0 );
dbBackdropOn();
dbSetDir( "Media" );
// text setup
dbInk( dbRGB( 255, 0, 0 ), 0 );
dbSetTextFont( "Arial" );
dbSetTextSize( 18 );
dbSetTextToBold();
// camera setup
dbAutoCamOff();
int CAM_USER = 0;
dbPositionCamera( CAM_USER, -50, 50, -50 );
dbPointCamera( CAM_USER, 0, 0, 0 );
int CAM_QUAD = 1;
dbMakeCamera( CAM_QUAD );
int QuadImage = GetFreeImageID();
dbSetCameraToImage( CAM_QUAD, QuadImage, dbScreenWidth(), dbScreenHeight() );
// shader setup
int SceneShader = GetFreeEffectID();
dbLoadEffect( "scene.fx", SceneShader, 0 );
int PostShader = GetFreeEffectID();
dbLoadEffect( "post.fx", PostShader, 0 );
int Vector4 = 1;
dbMakeVector4( Vector4 );
dbSetVector4( Vector4, 1.0f / dbScreenWidth(), 1.0f / dbScreenHeight(), 0, 0 );
dbSetEffectConstantVector( PostShader, "InvViewSize", Vector4 );
// shader errors
dbPerformChecklistForEffectErrors();
if ( dbChecklistQuantity() > 0 ) ReportError( "Shader Error:\n" + string( dbChecklistString( 1 ) ), 0 );
// screen quad
int Quad = GetFreeObjectID();
dbMakeObjectPlane( Quad, 4, 3 );
dbTextureObject( Quad, 0, QuadImage );
dbLockObjectOn( Quad );
dbSetObjectEffect( Quad, PostShader );
SetObjectMask( Quad, CAM( CAM_USER ) );
// scene setup
int Floor = GetFreeObjectID();
dbMakeObjectBox( Floor, 100, 2, 100 );
dbPositionObject( Floor, 0, -10, 0 );
int Sphere = GetFreeObjectID();
dbMakeObjectSphere( Sphere, 18 );
dbPositionObject( Sphere, 0, 10, 0 );
int Box = GetFreeObjectID();
dbMakeObjectBox( Box, 20, 10, 20 );
dbPositionObject( Box, 0, -4, 0 );
// apply scene shader
dbSetObjectEffect( Floor, SceneShader );
dbSetObjectEffect( Sphere, SceneShader );
dbSetObjectEffect( Box, SceneShader );
// main loop
while ( LoopGDK() )
{
// camera control
dbPrint( "WASD: Move" );
dbPrint( "Right Mouse: Rotate" );
float CamSpeed = 0.3f;
if ( dbKeyState( DIK_W ) ) dbMoveCamera( CAM_USER, CamSpeed );
if ( dbKeyState( DIK_S ) ) dbMoveCamera( CAM_USER, -CamSpeed );
if ( dbKeyState( DIK_A ) ) dbMoveCameraLeft( CAM_USER, CamSpeed );
if ( dbKeyState( DIK_D ) ) dbMoveCameraRight( CAM_USER, CamSpeed );
int MouseMoveX = dbMouseMoveX(),
MouseMoveY = dbMouseMoveY();
if ( dbMouseClick() == 2 )
{
dbYRotateCamera( CAM_USER, dbWrapValue( dbCameraAngleY( CAM_USER ) + ( MouseMoveX * CamSpeed ) ) );
dbXRotateCamera( CAM_USER, dbWrapValue( dbCameraAngleX( CAM_USER ) + ( MouseMoveY * CamSpeed ) ) );
}
// shader input
dbPrint( "Space: Change Scene Technique" );
if ( dbSpaceKey() )
{
dbSetEffectTechnique( SceneShader, "ScenePos" );
}
else
{
dbSetEffectTechnique( SceneShader, "SceneNormals" );
}
// update quad cam
dbPrint( "Shift: Hide Quad" );
if ( dbShiftKey() )
{
dbHideObject( Quad );
}
else
{
dbShowObject( Quad );
dbPositionCamera( CAM_QUAD, dbCameraPositionX( CAM_USER ), dbCameraPositionY( CAM_USER ), dbCameraPositionZ( CAM_USER ) );
dbRotateCamera( CAM_QUAD, dbCameraAngleX( CAM_USER ), dbCameraAngleY( CAM_USER ), dbCameraAngleZ( CAM_USER ) );
}
// update quad
dbPrint( "Return: Change Quad Technique" );
if ( dbReturnKey() )
{
dbSetEffectTechnique( PostShader, "Normals" );
}
else
{
dbSetEffectTechnique( PostShader, "Quad" );
}
// output
dbSetCursor( 0, 32 );
string fps = "FPS: " + Str( dbScreenFPS() );
dbPrint( (char*)fps.c_str() );
// update screen
dbSync();
}
// return to windows
return;
}
Now the plot thickens, the fps decreases, and the awesomeness goes through the roof.