   Render Target problems
  Hey all,I'm trying to get variance shadow mapping up and running.  I have that part written, but i'm having a problem with render targets.  What I do is set a shader to render the depth (and depth^2) to texture. I set a second shader to do Gaussian Blur.  I then set it as the texture for a screen aligned quad, and set another texture as the render target to render the blurred values to.  Then the scene gets rendered, with the blurred depth map as the shadowmap texture.The problem is that nothing is getting written to the second texture, regardless of what I do.  On top of that (or perhaps related), I get "Can not render to a render target that is also used as a texture. A render target was detected as bound, but couldn't detect if texture was actually used in rendering."when I start over trying to render to the shadowmap again.  I have settexture( name, NULL ) for every texture that I set but that doesn't seem to change anything (and that's the solution that I've found most often for this problem).  Any ideas?Thanks in advance,C   
  Can probably help if you post the code you refer to   ;  This is the main loop for this project.This is my own interface to D3D, and I've tried to comment what each of my calls equate to (if it's not obvious)data->renderer->ClearBuffer( CVector3f( 0.0f, 0.4f, 0.5f ) );data->renderer->ClearMatrixStack();data->renderer->ClearRenderTarget( data->shadowTexID, 0xFF000000 );data->renderer->ClearRenderTarget( data->shadowTexID2, 0xFF000000 );data->renderer->StartRender();/////////////////////////////////////////////////////////////////////////////////////////shadow map pass///////////////////////////////////////////////////////////////////////////////////////CMatrixf worldToLight;CMatrixf lightProj = data->renderer->GetProjectionMatrix(); data->renderer->LookAt( CVector3f( data->light.x, data->light.y, data->light.z ), CVector3f( 0.0f, 0.0f, 0.0f ), CVector3f( 0.0f, 1.0f, 0.0f ) );CMatrixf lightView = data->renderer->GetViewMatrix();worldToLight = lightView * lightProj;//this is just to set the shader for the model classdata->model->SetSurfaceShader( "GenerateShadowMapsNonAnim", false );//SetShader calls setTechniquedata->renderer->SetShader( "GenerateShadowMapsNonAnim" );data->renderer->SetShaderLocalParameter( VERTEX_SHADER, WORLD, 230, NULL );data->renderer->SetShaderLocalParameter( VERTEX_SHADER, VECTOR, 203, (void *)&(data->light), "lightPos");data->renderer->SetRenderTarget( 0, data->shadowTexID );//this renders the modeldata->model->Render();data->renderer->Push();data->renderer->SetVertexAttributes( data->vertAttrID, data->vertBuffID );//this calls Begin on the technique, setIndices, and then beginPass, draw, endpassdata->renderer->DrawIndexedGeometry( TRIANGLE_LIST, 0, 4, 2, data->indxBuffID );data->renderer->Pop();data->renderer->ResetRenderTarget( 0 );///////////////////////////////////////////////////////////////////////////////////////////Gaussian Blur/////////////////////////////////////////////////////////////////////////////////////////data->renderer->SetShader( "BlurTexture", false );data->renderer->SetRenderTarget( 0, data->shadowTexID2 );//this sets the texture samplerstate in the Gaussian blur shaderdata->renderer->SetTexture( data->shadowTexID, 0, "tex" );data->renderer->Push();data->renderer->SetVertexAttributes( data->vertAttrID, data->vertBuffID2 );data->renderer->DrawIndexedGeometry( TRIANGLE_LIST, 0, 4, 2, data->indxBuffID );data->renderer->Pop();//calls SetTexture( "tex", NULL )data->renderer->ResetTexture( data->shadowTexID, "tex" );//resets the rendertarget to the backbufferdata->renderer->ResetRenderTarget( 0 ); ///////////////////////////////////////////////////////////////////////////////////////////Render Scene/////////////////////////////////////////////////////////////////////////////////////////data->camera->Update();CRenderer::GetInstance().LookAt( data->camera->m_position,  data->camera->m_view,  data->camera->m_up );data->renderer->SetCullMode( CW );data->renderer->SetShader( "ShadowMapPerPixelNA" );data->model->SetSurfaceShader( "ShadowMapPerPixelNA", false );data->renderer->SetShaderLocalParameter( PIXEL_SHADER, VECTOR, 1, &(data->light), "lightPos" );data->renderer->SetShaderLocalParameter( VERTEX_SHADER, MATRIX, 209, (void*)&worldToLight, "viewToLight");data->renderer->SetShaderLocalParameter( VERTEX_SHADER, WORLD, 230, NULL );data->renderer->SetTexture( data->shadowTexID, 0, "shadowMap" ); //modeldata->model->Render();//floordata->renderer->Push();data->renderer->SetVertexAttributes( data->vertAttrID, data->vertBuffID );data->renderer->SetTexture( data->shadowTexID2, 0, "tex" );data->renderer->DrawIndexedGeometry( TRIANGLE_LIST, 0, 4, 2, data->indxBuffID );data->renderer->Pop();data->renderer->ResetTexture( data->shadowTexID, "shadowMap" );data->renderer->ResetTexture( data->shadowTexID2, "tex" );data->renderer->EndRender();data->renderer->SwapBuffers();If you need more (specific shader code, or the D3D underbelly of all this) please let me know.Thanks,C   ;  It looks like your blur texture is still bound as a texture from the previous pass when you set it as a render target for the gaussian blur.  I think you are using the same texture variable in the shader for both the blur and regular shadow map, so try setting the regular shadow map to the texture before you set the blur as the render target like so:///////////////////////////////////////////////////////////////////////////////////////////Gaussian Blur/////////////////////////////////////////////////////////////////////////////////////////data->renderer->SetShader( "BlurTexture", false );//this sets the texture samplerstate in the Gaussian blur shaderdata->renderer->SetTexture( data->shadowTexID, 0, "tex" );data->renderer->SetRenderTarget( 0, data->shadowTexID2 );If that doesn't work, you should check out NvPerfHUD or the ATI equivalent depending on your video card.  They are incredibly useful for debugging things like this.[Edited by - Leafteaner on June 3, 2008 2:56:10 AM];  Thanks, I'll give that a try and check out PerfHUD.  I'll post here when i've found a solution (or have had more problems hehe...).  Anyway, thanks again,C   ;  Make sure you set your textures back to NULL if you're going to be rendering to them in the future (this includes the next frame).  Otherwise they remain bound to a device sampler, and it will complain when you render to it.   ;  That's my problem...I am setting them to NULL lol.  That's what's confusing me so much   ;  I've got a stupid question.  When you call ID3DXEffect::SetTexture( name, NULL ) to reset a texture, when does that actually get applied?  The next Begin or BeginPass?  I'm calling it and the next thing that gets calls is a settechnique (after the endScene and Present).  Does this matter?I'm calling this function, but it doesn't seem to do anything.  It doesn't complain when I set a rendertarget, render to it, set it as a texture, set another rendertarget, and render to that.  It only complains when I try to render to the back buffer.  More accurately, it complains the next time it tries to set the rendertarget.  The other problem is that while it doesn't complain about the rendertarget setting and rendering, the second rendertarget is blank(i.e. the clear color).This is really annoying me.  Any ideas?  I'll post whatever code is needed.   ;  shameless bump...Seriously though, does anyone have an answer?  I got it to stop complaining about the render target set as a texture by having a Begin, beginPass, Endpass, End after every call to reset the textures.  This solution doesn't seem to fix my problem of it not rendering to the second render target, and it's a very expensive solution.  Anyone have a better one?   