Jump to content

  • Log In with Google      Sign In   
  • Create Account

Render To Texture To Texture in Directx


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
No replies to this topic

#1 ggeasy   Members   -  Reputation: 103

Like
0Likes
Like

Posted 23 April 2014 - 11:46 AM

He everyone,

 

For a school project I am working on a old engine we once made in directx9 and the challenge is to implement the oculus rift in it. Now I am having a issue with rendering of the eyes. As the SDK of oculus says that I need to render my scene twice (in 2 viewports) and then pass the result to a distortion shader for the distortion correction. 

 

But the distortion shader (pixel shader) distorts only one side of the screen, atleast the one I am using. I use the one from this forum post one with will work with DX9: 

https://developer.oculusvr.com/forums/viewtopic.php?f=33&t=497

 

This means I have to distort for each eye. I want to do this by rendering the full scene to a texture. Then apply the shader to this texture twice for left and right. The result of this is also a texture and then put this two textures to my quad. 

 

Now the full scene is rendering perfectly and when I apply this directly to my quad you see the scene rendered twice. However when I apply the pixelshader to my full scene texture and apply the resulting texture to my quad I won't see a thing... The HRESULTS of all SetTextures are S_OK. And I cant find the problem anywhere.

 

Here is some code:

Here I create all textures and surfaces:

pd3dDevice->CreateTexture(backBufferWidth,
		backBufferHeight,
		1,
		D3DUSAGE_RENDERTARGET,
		D3DFMT_A16B16G16R16,
		D3DPOOL_DEFAULT,
		&fullSceneTexture,
		NULL);
	fullSceneTexture->GetSurfaceLevel(0, &fullSceneSurface);

	pd3dDevice->CreateTexture(backBufferWidth,
		backBufferHeight,
		1,
		D3DUSAGE_RENDERTARGET,
		D3DFMT_A16B16G16R16,
		D3DPOOL_DEFAULT,
		&leftEyeTexture,
		NULL);
	leftEyeTexture->GetSurfaceLevel(0, &leftEyeSurface);

	pd3dDevice->CreateTexture(backBufferWidth,
		backBufferHeight,
		1,
		D3DUSAGE_RENDERTARGET,
		D3DFMT_A16B16G16R16,
		D3DPOOL_DEFAULT,
		&rightEyeTexture,
		NULL);
	rightEyeTexture->GetSurfaceLevel(0, &rightEyeSurface);

Here is my main render loop (the renderScene() parameters are still to be decided):

void Scene::renderScene()
{
	rnd->setupRenderToTexture();
	render(SConfig.GetEyeRenderParams(OVR::Util::Render::StereoEye_Left));
	render(SConfig.GetEyeRenderParams(OVR::Util::Render::StereoEye_Right));
	rnd->endRenderToTexture();
	rnd->renderEye(SConfig.GetEyeRenderParams(OVR::Util::Render::StereoEye_Left), SConfig);
	rnd->renderEye(SConfig.GetEyeRenderParams(OVR::Util::Render::StereoEye_Right), SConfig);
	rnd->renderScene(SConfig.GetEyeRenderParams(OVR::Util::Render::StereoEye_Right), SConfig);
	rnd->present(window->getHandle());
};

void Scene::render(const OVR::Util::Render::StereoEyeParams& stereo){
	rnd->setViewport(stereo);
	for (unsigned int i = 0; i < entities.size(); ++i)
	{
		entities[i]->drawSelf(rnd);
	}
	camera->drawSelf(rnd, stereo, SConfig);
	skybox->drawSelf(rnd);
	terrain->drawSelf(rnd);
}

Here are my render methods in my Renderer. In the RenderScene() method I call for now setTexture once, but even this texture is not showing up:

void RendererDX9::renderEye(const OVR::Util::Render::StereoEyeParams& params, OVR::Util::Render::StereoConfig SConfig)
{
	if (params.Eye == OVR::Util::Render::StereoEye_Right){
		pd3dDevice->SetRenderTarget(0, rightEyeSurface);
	}
	else{
		pd3dDevice->SetRenderTarget(0, leftEyeSurface);
	}
	pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL, D3DCOLOR_XRGB(0, 0, 255), 1.0f, 0);
	pd3dDevice->BeginScene();
	//apply shader
	pd3dDevice->SetPixelShader(lpPixelShader);
	setPixelShaderConstants(params, SConfig);	
	pd3dDevice->SetTexture(0, fullSceneTexture);
	pd3dDevice->SetPixelShader(NULL);

	pd3dDevice->EndScene();
};

void RendererDX9::renderScene(const OVR::Util::Render::StereoEyeParams& params, OVR::Util::Render::StereoConfig SConfig){
	pd3dDevice->SetRenderTarget(0, backBuffer);
	pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL, D3DCOLOR_XRGB(0, 0, 255), 1.0f, 0);
	pd3dDevice->BeginScene();
	//apply shader
	//render to aligned quad
	fillVertexBuffer("screenVertex", screenQuad, sizeof(CustomVertex)* 4);
	setZWriteEnable(false);
	setStreamSource("screenVertex", sizeof(CustomVertex));
	pd3dDevice->SetTexture(0, leftEyeTexture);
	//reset matrixes
	//resetWorldMatrix();
	pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
	setZWriteEnable(true);
	pd3dDevice->EndScene();
}

void RendererDX9::setupRenderToTexture(){
	pd3dDevice->SetRenderTarget(0, fullSceneSurface);
	pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL, D3DCOLOR_XRGB(0, 0, 255), 1.0f, 0);
	pd3dDevice->BeginScene();

};

void RendererDX9::endRenderToTexture(){
	pd3dDevice->EndScene();
};

Thanks in advance!



Sponsor:



Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS