Jump to content
  • Advertisement
Sign in to follow this  
Brejlounek

Render targets don't work...

This topic is 2639 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there,

I ran into problems in my new project where I want to apply a gaussian blur shader. I've already done it before and it worked perfectly, so I just pretty much copied/pasted it, but it doesn't work, but in a very strange way...

It is simple - shader "white" takes care of classic 3d space transformations and lighting, "blurh" blurs image horizontally and "blurv" blurs it vertically, so I just want to
1) render 3D scene to a viewport-sized texture,
2) render this texture to a quad and blur it horizontally,
3) blur this texture to a quad and blur it vertically.

I am assigning trender target to the device by calling Dev->SetRenderTarget(0,surface) and I am properly setting the chain of textures. But even if I am in step 3 assigning texture of the quad to the texture in which I rendered in step 2, it seems like it always sets itself to the texture in which I was rendering in step 1 (the result is same if I paste there t0.tex or t1.tex). I have compared this code to the code of project where it is working. It does exactly the same thing, aet it doesn't assign the texture correctly.

If I comment out the rendering in step two, framerate incereses rapidly, so it actually is rendering somewhere. I tried switching textures or shaders, few different ways - it stills ignore everything in the second step. I don't have a clue, what is causing it. There's no logic in it, every texture or its surface looks right - and if it didn't, it would call an error and not set some other random texture. I even debugged the textures, they have different pointers, so they are not the same.

Here is the code (without tranformations settings and rendering):
Dev->SetRenderTarget(0,t0.surf); //t0.surf = t0.tex surface level
Dev->BeginScene();

//transformations+testures...

eff_white->SetMatrix("worldViewProj",&transf);
eff_white->SetTechnique("white");
eff_white->Begin(0,0);
eff_white->BeginPass(0);
//rendering mesh...
eff_white->End();

Dev->EndScene();
Dev->SetRenderTarget(0,t1.surf); //t1.surf = t1.tex surface level
Dev->BeginScene();

eff_quad->SetTechnique("blurh");
eff_quad->Begin(0,0);
eff_quad->BeginPass(0);
eff_quad->SetTexture(tex0,t0.tex);
//rendering screen quad...
eff_quad->End();

Dev->EndScene();
Dev->SetRenderTarget(0,backbuf); //backbuf = back buffer surface
Dev->BeginScene();

eff_quad->SetTechnique("blurv");
eff_quad->Begin(0,0);
eff_quad->BeginPass(0);


Could you please take a look at it and tell me, what could be wrong? I am done with ideas here... :( And sorry for my English, if it is too crappy...

Share this post


Link to post
Share on other sites
Advertisement
What you mean it doesnt work? Do you get a black screen or what?

Have you enabled D3D debug layer? if yes, does it write any errors/warnings?

Also, I'm guessing you forgot to post some code because you dont call the rendering functions are you set the backbuffer as render target (in the end of your code...

Have you debugged your program using PIX? What do the render targets look like after the draw calls?

Share this post


Link to post
Share on other sites

What you mean it doesnt work? Do you get a black screen or what?

Have you enabled D3D debug layer? if yes, does it write any errors/warnings?


"But even if I am in step 3 assigning texture of the quad to the texture in which I rendered in step 2, it seems like it always sets itself to the texture in which I was rendering in step 1 (the result is same if I paste there t0.tex or t1.tex)."

That means that if I am rendering horizontal blur in the 2nd step and verical blur in the 3rd step, image is only blurred vertically and if I turn off the rendering in the 2nd step, 3rd step renders the same thing again - it shouldn't render anything. It really looks like t0.tex and t1.tex is the same texture, but the pointer is different.

There are no DirectX errors, everything goes fine.


Also, I'm guessing you forgot to post some code because you dont call the rendering functions are you set the backbuffer as render target (in the end of your code...
Have you debugged your program using PIX? What do the render targets look like after the draw calls?


I deleted the rendering code from this snippet, it is very oop and I am sure it works.

I'll try the debugging with PIX, thx.

Just for fun, actual code (won't say much):

void d3d_main::render(void)
{
//cam.setup(Dev);
input.Step(delta,cam.x,cam.y,cam.z,cam.rh,cam.rv);

t0.set(Dev,0);
Dev->BeginScene();

eff_white.transform(cam.setup(Dev,asp));
D3DXVECTOR4 li(10,10,10,0);
D3DXVec4Normalize(&li,&li);
eff_white.SetLi("li0",-li);
eff_white.SetFloat("amb",0.33333333);

eff_white.megabegin("text_dir");
model.render(eff_white,false);
eff_white.end();

Dev->EndScene();
t1.set(Dev,0);
Dev->BeginScene();

eff_quad.megabegin("blurv");
eff_quad.SetText("tex0",t0.tex);
plane.render(eff_quad,true);
eff_quad.end();

Dev->EndScene();
Dev->SetRenderTarget(0,backbuf);
Dev->BeginScene();

eff_quad.megabegin("blurh");
eff_quad.SetText("tex1",t1.tex);
plane.render(eff_quad,true);
eff_quad.end();

Dev->EndScene();
Dev->Present(NULL, NULL, NULL, NULL);

delta=(double)(clock()-lasttime)/CLOCKS_PER_SEC;
lasttime=clock();
}

Share this post


Link to post
Share on other sites
Hurraay, I accidentaly figured it out! It looks like the shader texture doesn't cleanup when the eff_quad->End(); is called and stays there. I had to do two texture slots in the shader, one for the vertical blur and one for the horizontal and use different one in each step.

Anyways, than you very much, TiagoCosta for your PIX advicement. It is really useful debug utility. So many things are going in the background! :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!