Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your feedback on a survey! Each completed response supports our community and gives you a chance to win a $25 Amazon gift card!


Render rendertargets.


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
13 replies to this topic

#1 korvax   Members   -  Reputation: 306

Like
0Likes
Like

Posted 28 March 2013 - 02:24 PM

Hi,

im currently exprementing and trying to learn about buffers/gbuffers and using diffrent rendering targets.

So my question is how do i texture that quad with render target 1 as a texture. All the help i verry much appreacheated.

 

struct PSOutput
{
	float4 Color : SV_Target0;
	float3 Normal : SV_Target1;
};


PSOutput main(PS_INPUT input) 
{
	PSOutput output;
	output.Color = diffuse*txDiffuse.Sample(samLinear, input.texcoord);;
	output.Normal = input.normal;
	return output;
}

 

 



Sponsor:

#2 Juliean   GDNet+   -  Reputation: 2755

Like
2Likes
Like

Posted 28 March 2013 - 02:46 PM

You can simply assign the rendertarget as an input texture, like you would do with any other texture. I suppose you have some issue with that...?



#3 korvax   Members   -  Reputation: 306

Like
0Likes
Like

Posted 28 March 2013 - 03:04 PM

To be honest, im not even sure where to start. I use ShaderResourceViews as for more "normal" texture.. Im quiet green to DX.



#4 Juliean   GDNet+   -  Reputation: 2755

Like
0Likes
Like

Posted 28 March 2013 - 03:10 PM

Oh, didn't read you was DX11, thats not quite my buisness, sorry! But can't you create a ShaderResourceView from your rendertarget? Unless D3D11 changed handling of rendertarget dramatically they should qualify here as well. If thats not the case, I'd have to pass :/



#5 NightCreature83   Crossbones+   -  Reputation: 3038

Like
1Likes
Like

Posted 28 March 2013 - 05:26 PM

In D3D11 you create the texture you want to use as a render target and CreateRenderTargetView. If you then want to use it as a normal texture as well you create a normal CreateShaderResourceView with the same texture. Just make sure you don't use the views at the same time in one present loop.
Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, Mad Max

#6 korvax   Members   -  Reputation: 306

Like
0Likes
Like

Posted 29 March 2013 - 11:17 PM

Thx NightCreature83 that make seens actually. Will see if i can get it to work next week.

What do you men dont use the views at the same time in one present loop?



#7 unbird   Crossbones+   -  Reputation: 6023

Like
1Likes
Like

Posted 30 March 2013 - 03:03 AM

"Present loop" sounds like you couldn't use the same resource as input and output in the same frame. This is of course wrong. What he meant is: You can't bind the same resource as input and output at the same time. (E.g. you can't sample from a texture you're also using as a render target).

The pipeline will automatically nullify such attempts, so make sure you detach a resource before you attach it elsewhere. The debug layer will also report this very clearly (if enabled at device creation).



#8 korvax   Members   -  Reputation: 306

Like
0Likes
Like

Posted 31 March 2013 - 04:59 AM

Ok, i think i manged to create a rendertarget and and a shaderview based on the same texture.  

But im no getting the error msg that you guys described "Resource being set to PS shader resource slot 0 is still bound on output! Forcing to NULL".. So my question now is obviously what im doing wrong now? :)

 

im using OMSetRenderTargets to set all my render targets to the device and in my shader it looks like this. 

 

struct PSOutput
{
    float4 Color : SV_Target0;
    float3 Normal : SV_Target1;
};


PSOutput main(PS_INPUT input)
{
    PSOutput output;
    output.Color = diffuse*txDiffuse.Sample(samLinear, input.texcoord);;
    output.Normal = input.normal;
    return output;
}

 

 



#9 NightCreature83   Crossbones+   -  Reputation: 3038

Like
1Likes
Like

Posted 31 March 2013 - 05:24 AM

If you bind either the color or normal buffer to samLinear it will not work. The problem you are now getting is probably that you forgot to reset the render target to the backbuffer when you want to read from these textures.
Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, Mad Max

#10 korvax   Members   -  Reputation: 306

Like
0Likes
Like

Posted 31 March 2013 - 05:37 AM

If you bind either the color or normal buffer to samLinear it will not work. The problem you are now getting is probably that you forgot to reset the render target to the backbuffer when you want to read from these textures.

Sorry not quiet following you (quiet green indeed). rest the render target to the backbuffer  when you want to read form these textures, can you elaborate more pls?

 

Complete Warning:

ID3D11DeviceContext::PSSetShaderResources: Resource being set to PS shader resource slot 0 is still bound on output! Forcing to NULL. [ STATE_SETTING WARNING #7: DEVICE_PSSETSHADERRESOURCES_HAZARD]



#11 NightCreature83   Crossbones+   -  Reputation: 3038

Like
1Likes
Like

Posted 31 March 2013 - 05:42 AM

When you want to use the rendertargets as a texture to read from you need to unbind the rendertargetviews for them and reset this to the actual backbuffer the one you want to show on screen.

Before you set your render targets you want to call this function http://msdn.microsoft.com/en-us/library/windows/desktop/ff476460%28v=vs.85%29.aspx and once you are done rendering to these targets you call OMSetRenderTargets again and pass it the information the function call in the link gives you.
Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, Mad Max

#12 korvax   Members   -  Reputation: 306

Like
0Likes
Like

Posted 31 March 2013 - 01:13 PM

When you want to use the rendertargets as a texture to read from you need to unbind the rendertargetviews for them and reset this to the actual backbuffer the one you want to show on screen.

Before you set your render targets you want to call this function http://msdn.microsoft.com/en-us/library/windows/desktop/ff476460%28v=vs.85%29.aspx and once you are done rendering to these targets you call OMSetRenderTargets again and pass it the information the function call in the link gives you.

 

I manged to get it work and but even better i full understand it want im doing as well   Thx so much for you help NightCreature83.

 

I havent got the GetRenderTargets -> SetRenderTargets to work, think i need to do some reading about ** to * i guess.  But thx again for you help!



#13 NightCreature83   Crossbones+   -  Reputation: 3038

Like
0Likes
Like

Posted 01 April 2013 - 05:05 AM

Thats an easy fix just put a & in front of the variable you are passing to getRenderTargets, as like this (pseudo code for your problem)
void function(int** var);

//This is then called as this
int* anotherVar;
function(&anotherVar);


Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, Mad Max

#14 korvax   Members   -  Reputation: 306

Like
0Likes
Like

Posted 01 April 2013 - 10:01 AM

HI again, sorry for this NightCreateure83 (or anyone else :) just one more thing. 

I got it to work as i wrote before, but im getting some warnings that i would like to get ride off. I gueesing im not resting the them correctly or that im doing it in the wrong order.

 

 * D3D11 WARNING: ID3D11DeviceContext::DrawIndexed: The Pixel Shader expects a Render Target View bound to slot 1, but none is bound. This is OK, as writes of an unbound Render Target View are discarded. It is also possible the developer knows the data will not be used anyway. This is only a problem if the developer actually intended to bind a Render Target View here. [ EXECUTION WARNING #3146081: DEVICE_DRAW_RENDERTARGETVIEW_NOT_SET]
 
* D3D11 WARNING: ID3D11DeviceContext::OMSetRenderTargets: Resource being set to OM RenderTarget slot 1 is still bound on input! [ STATE_SETTING WARNING #9: DEVICE_OMSETRENDERTARGETS_HAZARD]
 
* D3D11 WARNING: ID3D11DeviceContext::OMSetRenderTargets[AndUnorderedAccessViews]: Forcing PS shader resource slot 0 to NULL. [ STATE_SETTING WARNING #7: DEVICE_PSSETSHADERRESOURCES_HAZARD]
 
 
My order.
 
1) Setting all rendertargets, there are two off them the main output and one with normals that Im rendering to a Quad.

void PipelineManagerDX11::SetRenderTargetView(TArray<ID3D11RenderTargetView*> renderTargets,ID3D11DepthStencilView* pDepthStencilView)
{
	m_RenderTargets = renderTargets;	
	m_pDepthStencilView = pDepthStencilView;
	UINT nViews = m_RenderTargets.count();
	ID3D11RenderTargetView*	rtvs[2];	
	for (UINT i= 0; i<nViews;++i){	
		rtvs[i] = m_RenderTargets[i];
	}
	m_pContext->OMSetRenderTargets(nViews,rtvs,m_pDepthStencilView);	
}
 

 

2) Render the scene 

 

3) Resting the Rendertarget, setting Rendertarget 2 to null so i can use the the texture and Setting render target 1 to the device.

 

ID3D11RenderTargetView* rTargets[2] = {m_RenderTargets[0], NULL };
m_pContext->OMSetRenderTargets(2, rTargets, NULL);

 

4) rendering the quad with Shaderview bound to the texture that Rendertarget 2 is using.

 

m_pContext->PSSetShaderResources(0, 1, &m_pShaderResourceView);		
m_pContext->VSSetShader(m_pVertexShader, NULL, 0 );
m_pContext->PSSetShader(m_pPixelShader, NULL, 0);
m_pContext->DrawIndexed(m_QuadIB->m_numIndices,0,0);


 

5) Setting all the rendertargets as i did in step one.

 

SetRenderTargetView(m_RenderTargets,m_pDepthStencilView);

 

6) Ending the pipeline with the usual stuff, clearing all the renderingtargets, swaping the backbufffer, present etc.

 

 

 

 
 
Stupied me, this I already knew :), thx anyway!

 

Thats an easy fix just put a & in front of the variable you are passing to getRenderTargets, as like this (pseudo code for your problem)

void function(int** var);

//This is then called as this
int* anotherVar;
function(&anotherVar);

 






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