Original Post
Hello and sorry if there were some discussions about this topic, I just couldn't find it. What I'm trying to do is copy a region from a texture to a smaller texture. For this I'm using vertex and pixel shaders. This is the code, where the small texture's dimensions are (128.0f, 128.0f): LPDIRECT3DSURFACE9 m_oldRenderT, m_oldDepthSt, m_renderSurf; UpdateVertex quad[4]; quad[0].x = 0; quad[0].y = 0; quad[0].z = 0; quad[1].x = 0; quad[1].y = 128.0f; quad[1].z = 0; quad[2].x = 128.0f; quad[2].y = 0; quad[2].z = 0; quad[3].x = 128.0f; quad[3].y = 128.0f; quad[3].z = 0; quad[0].u = 0; quad[0].v = 0; quad[1].u = 0; quad[1].v = 1; quad[2].u = 1; quad[2].v = 0; quad[3].u = 1; quad[3].v = 1; m_pDevice->SetVertexDeclaration(m_pUpdateDecl); m_pDevice->SetVertexShader(m_pUnsampleVS); m_pDevice->SetPixelShader(m_pUnsamplePS); m_pDevice->GetRenderTarget(0, &m_oldRenderT); m_pDevice->GetDepthStencilSurface(&m_oldDepthSt); b_pSmallTexture->GetSurfaceLevel(0, &m_renderSurf); m_pDevice->SetRenderTarget(0, m_renderSurf); m_pDevice->BeginScene(); m_pDevice->SetTexture(0, m_pBigTexture); m_pDevice->SetTexture(1, 0); m_pDevice->SetTexture(2, 0); m_pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, &quad[0], sizeof(UpdateVertex)); m_pDevice->EndScene(); Ok let me explain: 1. I set all the quads that are rendered with the positions at (0, 0), (128, 0), (0, 128), (128, 128), those being the corners of the small texture that needs to be updated. 2. I save the old render target and depth surface and set the new one as being the surface of m_SmallTexture's. 3. I just render. Next is the vertex shader used: uniform float Size; uniform float2 Viewport; struct OUTPUT { vector position : POSITION; float2 texcoords : TEXCOORD0; }; OUTPUT Update(float3 pos : POSITION, float2 texcoords : TEXCOORD0) { OUTPUT output; output.position = float4(float2(pos.x,-pos.y) + float2(-1.0, 1.0)/Viewport,0.0,1.0); output.texcoords = texcoords * Size; return output; } Viewport is set to (128.0f, 128.0f). Is that OK? The pixel shader generates the output color given the offset of the small texture within the big one. I'm sure the pixel shader acts correctly, but my questions were: 1. Did I do something wrong? Aren't those the steps to render to a texture? 2. Did I map the vertices correctly? I think I may have to set some matrices; right? 3. Is Viewport parameter from the vertex shader mapping the vertices to texture space? Thanks for any answers, I really would appreciate if someone would help me. One last thing: When I move the camera, I get a blank screen for a few dozens of miliseconds; I believe it's because of the render target being changed. HAs anyone encoutered this? What is the solution?