• 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
TheResolute

Texture replaced when rendered to

6 posts in this topic

Hello there,

I have a 2D lighting engine that renders the game scene to the back buffer, renders the lighting map to a texture, and then renders the texture to the back buffer with a blend state
The issue I'm encountering is that every time I make a Draw call when rendering a light to be added to the light map, it completely replaces all data in the texture including its width and height
For example, let's say I make Draw call that will fill the entire light map texture with black, when I make another Draw call to render a light sprite to the texture, the entire texture is replaced by that single sprite and it also resizes as well
There is the possibly that this is not actually what is occurring, but all evidence from a fair amount of testing indicates this

What I'd like to do is render my lighting sprites to my light map texture just like I would render my object sprites to the back buffer, in that each successive Draw call only adds the new sprite on top of whatever else was there and only replaces certain pixels
I do not believe this is a blend state issue because I use the same one for rendering to the back buffer and the light map, and the back buffer rendering works just fine
Please provide an explanation as to what is going on and how to make this process function as I've described

Thanks
0

Share this post


Link to post
Share on other sites
Can you show some code perhaps? Like part where you draw your light sprites?

Best regards!
0

Share this post


Link to post
Share on other sites
Here's the setup:
[CODE]
// Lighting
ZeroMemory( &blendDesc, sizeof( blendDesc ) );
blendDesc.RenderTarget[0].BlendEnable = TRUE;
blendDesc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
blendDesc.RenderTarget[0].SrcBlend = D3D11_BLEND_DEST_COLOR;
blendDesc.RenderTarget[0].DestBlend = D3D11_BLEND_ZERO;
blendDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
blendDesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
blendDesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
blendDesc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
d3dDevice_->CreateBlendState( &blendDesc, &lightingBlendState_ );
float blendFactor[4] = { 0.0f, 0.0f, 0.0f, 0.0f };

// Light map and render target view
DXGI_SAMPLE_DESC sampleDesc = {
1,
0
};
D3D11_TEXTURE2D_DESC texDesc = {
1024,
768,
1,
1,
DXGI_FORMAT_R32G32B32A32_FLOAT,
sampleDesc,
D3D11_USAGE_DEFAULT,
D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE,
NULL,
NULL
};
d3dDevice_->CreateTexture2D( &texDesc, NULL, ( ID3D11Texture2D** )&lightMap_ );
D3D11_RENDER_TARGET_VIEW_DESC renderDesc = {
DXGI_FORMAT_R32G32B32A32_FLOAT,
D3D11_RTV_DIMENSION_TEXTURE2D,
{ 0 },
};
d3dDevice_->CreateRenderTargetView( lightMap_, &renderDesc, &lightMapTarget_ );
D3D11_SHADER_RESOURCE_VIEW_DESC resourceDesc = {
DXGI_FORMAT_R32G32B32A32_FLOAT,
D3D11_SRV_DIMENSION_TEXTURE2D,
0,
1
};
d3dDevice_->CreateShaderResourceView( lightMap_, &resourceDesc, &lightMapResource_ );
[/CODE]

And here's the render:
[CODE]
d3dContext_->OMSetRenderTargets( 1, &lightMapTarget_, NULL );

colorMap = dxiSprites_[kBlackSprite].GetShaderResourceView( );
d3dContext_->PSSetShaderResources( 0, 1, &colorMap );
spritePtr = 0;
HRESULT d3dResult = d3dContext_->Map( vertexBufferText_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapResource );
spritePtr = ( VertexPos* )mapResource.pData;
spritePtr[0].pos = XMFLOAT3( 1, -1, 0 );
spritePtr[1].pos = XMFLOAT3( -1, -1, 0 );
spritePtr[2].pos = XMFLOAT3( -1, 1, 0 );
spritePtr[3].pos = XMFLOAT3( -1, 1, 0 );
spritePtr[4].pos = XMFLOAT3( 1, 1, 0 );
spritePtr[5].pos = XMFLOAT3( 1, -1, 0 );
spritePtr[0].tex0 = XMFLOAT2( 1, 0 );
spritePtr[1].tex0 = XMFLOAT2( 0, 0 );
spritePtr[2].tex0 = XMFLOAT2( 0, 1 );
spritePtr[3].tex0 = XMFLOAT2( 0, 1 );
spritePtr[4].tex0 = XMFLOAT2( 1, 1 );
spritePtr[5].tex0 = XMFLOAT2( 1, 0 );
d3dContext_->Unmap( vertexBufferText_, 0 );
d3dContext_->Draw( 6, 0 );


stride = sizeof( VertexPos );
offset = 0;
d3dContext_->IASetInputLayout( inputLayout_ );
d3dContext_->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST );
d3dContext_->VSSetShader( solidColorVS_, 0, 0 );
d3dContext_->PSSetShader( solidColorPS_, 0, 0 );
d3dContext_->PSSetSamplers( 0, 1, &colorMapSampler_ );
for( int i = kNumberOfSprites; i < kNumberOfLights + kNumberOfSprites; i++ )
{
ID3D11Buffer* vertexBuffer = dxiSprites_[i].GetVertexBuffer( );
ID3D11ShaderResourceView* colorMap = dxiSprites_[i].GetShaderResourceView( );
d3dContext_->IASetVertexBuffers( 0, 1, &vertexBuffer, &stride, &offset );
d3dContext_->PSSetShaderResources( 0, 1, &colorMap );
if( i == kDarknessLight )
{
XMFLOAT2 pos = XMFLOAT2( 0.0f, 0.0f );
XMMATRIX world = dxiSprites_[i].CreateAWorldMatrix( pos, ( 360.0f - 0 ) * 0.0174532925f, XMFLOAT2( 1, 1 ) );
XMMATRIX mvp = XMMatrixMultiply( world, vpMatrix_ );
mvp = XMMatrixMultiply( mvp, XMMatrixTranslation( 512 / ( kWindowWidth / 2 ), 384 / ( kWindowHeight / 2 ), 0.0f ) );
mvp = XMMatrixTranspose( mvp );
d3dContext_->UpdateSubresource( mvpCB_, 0, 0, &mvp, 0, 0 );
d3dContext_->VSSetConstantBuffers( 0, 1, &mvpCB_ );
d3dContext_->Draw( 6, 0 );
}
for( int j = 0; j < drawData->spriteDataLength; j++ )
{
if( drawData->spriteData[j].index == kFlagshipSprite )
{
XMFLOAT2 pos = XMFLOAT2( 0.0f, 0.0f );
XMMATRIX world = dxiSprites_[i].CreateAWorldMatrix( pos, ( 360.0f - drawData->spriteData[j].rotation ) * 0.0174532925f, drawData->spriteData[j].scale );
XMMATRIX mvp = XMMatrixMultiply( world, vpMatrix_ );
mvp = XMMatrixMultiply( mvp, XMMatrixTranslation( drawData->spriteData[j].position.x / ( kWindowWidth / 2 ), drawData->spriteData[j].position.y / ( kWindowHeight / 2 ), 0.0f ) );
mvp = XMMatrixTranspose( mvp );
d3dContext_->UpdateSubresource( mvpCB_, 0, 0, &mvp, 0, 0 );
d3dContext_->VSSetConstantBuffers( 0, 1, &mvpCB_ );
d3dContext_->Draw( 6, 0 );
}
}
}

d3dContext_->OMSetRenderTargets( 1, &backBufferTarget_, NULL );
d3dContext_->OMSetBlendState( lightingBlendState_, blendfactor, 0xFFFFFFFF );
d3dContext_->PSSetShaderResources( 0, 1, &lightMapResource_ );
d3dContext_->Draw( 6, 0 );
[/CODE]
The first chunk of that fills the texture with darkness (black)
Then the second bit draws all the lighting sprites (usually white circles), and a darkness sprite
Darkness is drawn twice for debugging reasons, indicating that regardless of what's in the texture, it's replaced when a new Draw call is made
And the last piece draws the texture to the existing rendered frame with the correct blend state

Thanks in advance for any help Edited by TheResolute
0

Share this post


Link to post
Share on other sites
Off the top of my head:

You could be clearing the target before rendering the next iteration.
Your blending operations could be wrong.
If you're using shaders, the shader might not be updated with the new data on the next draw call.
Or there is an issue with your loop that draws.

Use PIX to debug so you can pin point where the issue is happening in code.
1

Share this post


Link to post
Share on other sites
[quote name='DJTN' timestamp='1336077544' post='4937205']
Off the top of my head:

You could be clearing the target before rendering the next iteration.
Your blending operations could be wrong.
If you're using shaders, the shader might not be updated with the new data on the next draw call.
Or there is an issue with your loop that draws.

Use PIX to debug so you can pin point where the issue is happening in code.
[/quote]

That PIX piece is an excellent suggestion
I'll have to figure that out and it might just be awesome so thank you
0

Share this post


Link to post
Share on other sites
[color=#000000][font=Arial,]
Turns out, and you'll notice this with those code samples, that I (in my infinite incompetence) do not set the correct vertex shader or buffer for drawing the entire texture2d to the back buffer[/font][/color][color=#000000][font=Arial,]
So, it used the last set vertex buffer (the one used to to draw the last thing rendered to the texture XD ) when it rendered the texture to the back buffer. This created the effect that I believed to be the texture2d being replaced by whatever was rendered to it[/font][/color][color=#000000][font=Arial,]
There you have it, just some silly little semantic error[/font][/color][color=#000000][font=Arial,]
Thank you all for trying to help[/font][/color]
0

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