• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0

Need help with render to texture

3 posts in this topic

Hi all, I was wondering if anyone could help me with a minor render to texture problem:

I'm getting:
D3D11: WARNING: ID3D11DeviceContext::OMSetRenderTargets: Resource being set to OM RenderTarget slot 0 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 ]

When trying to render with the following loop:
void render()
static float theta = 0;
float thetaRads = theta * 3.14159/180.0;
float ClearColor[4] = { 0.0f, 0.0, 0, 0.9f }; // red,green,blue,alpha
float r = 0.1 * cos(2 * 3.14159 * 1 * thetaRads);
//Render the texture
g_pImmediateContext->OMSetRenderTargets(1, &g_baseRTV,NULL);
g_pImmediateContext->ClearRenderTargetView( g_baseRTV, ClearColor );
ConstantBufferType cb;
XMStoreFloat4x4(&cb.worldView, XMMatrixIdentity());
cb.worldView._11 = cos(thetaRads);
cb.worldView._12 = -sin(thetaRads);
cb.worldView._21 = sin(thetaRads);
cb.worldView._22 = cos(thetaRads);
//cb.worldView._14 = r*cos(thetaRads);
//cb.worldView._24 = r*sin(thetaRads);
g_pImmediateContext->UpdateSubresource(g_constantBuffer, 0, NULL, &cb, 0,0);
g_pImmediateContext->VSSetConstantBuffers(0, 1, &g_constantBuffer);
g_pImmediateContext->PSSetConstantBuffers(0, 1, &g_constantBuffer);
g_pImmediateContext->VSSetShader(g_baseVShader, NULL, 0);
g_pImmediateContext->PSSetShader(g_basePShader, NULL, 0);
UINT stride = sizeof(BasicVertex);
UINT offset = 0;
//Render the screen.
g_pImmediateContext->OMSetRenderTargets(1,&g_pRenderTargetView, NULL);
g_pImmediateContext->VSSetShader(g_texVShader, NULL, 0);
g_pImmediateContext->PSSetShader(g_texPShader, NULL, 0);
g_pImmediateContext->PSSetShaderResources(0,1, &g_baseSRV);
g_pSwapChain->Present( 0, 0 );
theta += 0.05;

g_pRenderTargetView is the main screen's render target view, and g_baseRTV is the render target view I'm using for render to texture.
Any pointers on what I'm doing wrong?
It also doesn't seem to be alpha blending properly (I'm expecting a sort of blurred trail like an accumulation buffer effect, but it doesn't seem to be working), and I'm wondering if it has something to do with the errors I'm seeing D3D throw...

Share this post

Link to post
Share on other sites
The error means exactly what it says: you're trying to bind a render target, but the texture for that render target is still bound as a shader resource view for the pixel shader. This is happening because at the end of your frame you bind the SRV for your render target texture to the pixel shader, then at the beginning of the next frame you bind RTV for that texture. You need to set the pixel shader SRV slot to NULL before you bind the RTV, and then you won't get the error.

If you want alpha blending, then you need to bind an appropriate blend state that has blending enabled. Are you attempting to blend into your render target texture, as if it were an accumulation buffer? If so, then you also won't want to clear the target each frame (otherwise it will lose everything you've currently accumulated).

Share this post

Link to post
Share on other sites
Thanks, I didn't realize the shader view had to be unbounded before the texture could be bound as the render target again.

As for the blending, yes, I'm using an alpha blend state. The problem seems to come from blending a quad into the render texture, then blending the render texture into the screen. The quad itself seems to show alpha, but when its alpha gets mixed with the screen quad, either the screen quad seems to become transparent instead of additvely blending into the screen quad, or the trail only shows up within the smaller quad's area. I'm not sure my explanation makes sense, so here are some pics:

Where I don't clear the back buffer, I get the expected trail, but only within the quad:

Where I *do* clear the back buffer, you can see the transparency problem better:

Alpha seems to at least be partially working, as alpha is how i implement the "fuzziness" of the dot (exponential falloff from the center of the quad on the alpha channel), but the quad makes a "hole" in the screen quad, allowing the background to bleed through. I always clear the render target view texture to 0,0,0, 0.9, yet it has no alpha except where I render the smaller quad into it.

Here's how I'm setting up my blending:
D3D11_BLEND_DESC blendDesc;
ZeroMemory( &blendDesc, sizeof(blendDesc) );
ZeroMemory( &rtbd, sizeof(rtbd) );
rtbd.BlendEnable = true;
rtbd.SrcBlend = D3D11_BLEND_SRC_ALPHA;
rtbd.DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
rtbd.BlendOp = D3D11_BLEND_OP_ADD;
rtbd.SrcBlendAlpha = D3D11_BLEND_ONE;
rtbd.DestBlendAlpha = D3D11_BLEND_ZERO;
rtbd.BlendOpAlpha = D3D11_BLEND_OP_ADD;
rtbd.RenderTargetWriteMask = D3D10_COLOR_WRITE_ENABLE_ALL;
blendDesc.AlphaToCoverageEnable = false;
blendDesc.RenderTarget[0] = rtbd;
g_pd3dDevice->CreateBlendState(&blendDesc, &g_pBlendState);
g_pImmediateContext->OMSetBlendState(g_pBlendState, 0, 0xffffffff);

Share this post

Link to post
Share on other sites
Oops, I noticed my DEST_BLEND_ALPHA was set to zero, so I set that to 1, and now the transparency problem is fixed and I'm getting some trails, but they don't seem to properly dissipate over time:

I'm going more for a CRT persistence fall-off effect, like an analog oscilloscope where the trail will eventually fade to black and be brightest the closer you get to the dot.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
Followers 0