djalexd

Member
  • Content count

    4
  • Joined

  • Last visited

Community Reputation

127 Neutral

About djalexd

  • Rank
    Newbie
  1. I've moved that code before the rendering, so now I only have one BeginScene / EndScene, but I still encounter that problem. Can anybody help me?
  2. I'm working on the terrain rendering technique which involves displacement mapping. I have a couple of textures that are, logically, the mip-map of the terrain. Now, I have to update them all, from the biggest to the smallest, and to do so I do the following: device->GetRenderTarget(0, &oldRT); device->GetDepthStencilSurface(&oldDSS); device->BeginScene(); for (i = 0; i < levels - 1; i++) { // // Set the current texture as displacement map device->SetTexture(D3DVERTEXSAMPLER0, level[i].displacement); // // Set the next texture as render target and the depth surface as NULL device->SetRenderTarget(0, level[i + 1].displacement); device->SetDepthStencilSurface(NULL); // // Render a 2D quad that updates the texture (no Clear) } device->EndScene(); device->SetRenderTarget(0, oldRT); device->SetDepthStencilSurface(oldDSS); This is achieved in the Update function that is called before Render function. However, when I move through the world (so the Update is called), the terrain disappears until I stop moving; then the terrain appears again, like nothing had happened. I don't know why this happens, can anyone help me? My updating textures are 32bit floating point if this is of any importance.
  3. Copy pixels

    Unfortunately I can't use the StrechRect method. The pixel shader add some noise to the resulting texture so I can't get rid of it. Only the vertex shader solution is viable to what I want. I don't need the application / vertex shader to be debugged; I got the application to run but the results were wrong. I just need someone to tell me what the code is missing (like matrix setup) or what is wrong (like what is "float2(position.x,-position.y) + float2(-1.0, 1.0)/Viewport" - i just don't understand this, maybe it's a transform from world space to texture space), if that is possible. The reply was very helpful, thanks
  4. Copy pixels

    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?