• 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
~Helgon

Additive Blending

4 posts in this topic

Hi,

i have a problem with one of the exersises in "introduction to gameprogramming with directx 11" (for the ones who have the book, its chapter 10, exercise 7).

the task ist to draw an animation with additive blending. after trying some logic thinks i started "brute forcing" all possible variations but what ever i tried i never got the desired result.

i attached an img so u can see what is requested and what is my "best" result yet.

i hope that someone can give me a hint.. really tryed to solve it by my own for hours :(

(thats the blend desc which gives me the best result like on the screenshot (right))

[CODE]
D3D11_BLEND_DESC noBlack = {0};
noBlack.AlphaToCoverageEnable = false;
noBlack.IndependentBlendEnable = false;
noBlack.RenderTarget[0].BlendEnable = true;
noBlack.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
noBlack.RenderTarget[0].DestBlend = D3D11_BLEND_SRC_ALPHA;
noBlack.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
noBlack.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
noBlack.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ONE;
noBlack.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
noBlack.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
HR(device->CreateBlendState(&noBlack, &NoBlack));
[/CODE]

[CODE]
boxTech->GetDesc( &techDesc );
for(UINT p = 0; p < techDesc.Passes; ++p)
{
md3dImmediateContext->IASetVertexBuffers(0, 1, &amp;mBoxVB, &amp;stride, &amp;offset);
md3dImmediateContext->IASetIndexBuffer(mBoxIB, DXGI_FORMAT_R32_UINT, 0);
// Draw the Cylinder
XMMATRIX world = XMLoadFloat4x4(&amp;mCylWorld);
XMMATRIX worldInvTranspose = MathHelper::InverseTranspose(world);
XMMATRIX worldViewProj = world*view*proj;

Effects::BasicFX->SetWorld(world);
Effects::BasicFX->SetWorldInvTranspose(worldInvTranspose);
Effects::BasicFX->SetWorldViewProj(worldViewProj);
Effects::BasicFX->SetTexTransform(XMMatrixIdentity());
Effects::BasicFX->SetMaterial(mBoltMat);
Effects::BasicFX->SetDiffuseMap(bolts[currentBolt]);
md3dImmediateContext->RSSetState(RenderStates::NoCullRS);
md3dImmediateContext->OMSetBlendState(RenderStates::NoBlack, blendFactor, 0xffffffff);
landAndWavesTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext);
md3dImmediateContext->DrawIndexed(mCylIndexCount, mCylIndexOffset, mCylVertexOffset);
// Set per object constants.
world = XMLoadFloat4x4(&amp;mBoxWorld);
worldInvTranspose = MathHelper::InverseTranspose(world);
worldViewProj = world*view*proj;

Effects::BasicFX->SetWorld(world);
Effects::BasicFX->SetWorldInvTranspose(worldInvTranspose);
Effects::BasicFX->SetWorldViewProj(worldViewProj);
Effects::BasicFX->SetTexTransform(XMMatrixIdentity());
Effects::BasicFX->SetMaterial(mBoxMat);
Effects::BasicFX->SetDiffuseMap(mBoxMapSRV);
md3dImmediateContext->OMSetBlendState(0, blendFactor, 0xffffffff);
boxTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext);
md3dImmediateContext->DrawIndexed(36, 0, 0);

}
[/CODE]

i really hope that someone can help me because i get crazy

regards helgon Edited by ~Helgon
0

Share this post


Link to post
Share on other sites
Change your blend state a few bits:
[CODE]
noBlack.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
noBlack.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
[/CODE]
This means the interpolation will be "finalOutput = colour1 * a + colour2 * (1-a);"

By looking at the screenshot, you're rendering your thunder effect before the terrain, but you have to do it [b]after[/b] in order to get correct transparency (otherwise it will interpolate the colours with the sky).

Ordering front to back is a very good performance optimization due to something called Early Z. However when dealing with transparent objects (alpha blended objects) you have to sacrifice that performance and sort them back to front.
0

Share this post


Link to post
Share on other sites
Hey, thank you very much for the awnser.

I changed the draw order. Now first terrain , then waves and then the bolt animation.
Then i changed the Blend values as u suggested but it still doesnt give the desired result

and an other question. i just get rid of the black parts of the texture if i clip them in hlsl. is it possible to do this through the blend state?
my solution for now is clip(texture.rgb - 0.1f); and it works but im not sure if this was the desired way of solving the problem.

and an other question. how should the material be for the bolt texture? i tried it with opaque 0 and 50% but both doesnt looked good :(

Hope that u can give me another hint :D

regards helgon
0

Share this post


Link to post
Share on other sites
If the black is true black and you really are doing an additive blend, you don't need to worry about eliminating the black. Black is (R=0, G=0, B=0) and adding 0 to anything, of course, has no effect. If the black areas do cause an effect with an additive blend, it means the black isn't fully black. Your clipping trick leads me to believe that this might be the case. If the texture you are loading is .JPG format, there could be compression artifacts that are making the black not a true black. Or the texture could have been created incorrectly. In any case, make sure your black is really black, then if you do just a simple addition of the source against the destination (however this is done in DirectX; I'm an OpenGL guy) the black should have no effect but the blue/white areas should increase the brightness of the background.
0

Share this post


Link to post
Share on other sites
Damn guys. I love u *nohomo*

I dont know what sh*t i tryed yesterday and the last minutes but now it works with this simple solution

[CODE]
noBlack.RenderTarget[0].BlendEnable = true;
noBlack.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
noBlack.RenderTarget[0].DestBlend = D3D11_BLEND_ONE;
noBlack.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
noBlack.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
noBlack.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ONE;
noBlack.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
[/CODE]

how could i be so stupid not try to set all to add if its called "additive" blending.. damn im retarded.
and ur totally right jtippets. now that it is correct additive blending the black disappears without cliping

thank you both very much

p.s: for someone else if he has this problem. preventing the artefacts which comes up with additive blending solution: before drawing the object which uses the additive blending set depth stencil which is like:

[CODE]
D3D11_DEPTH_STENCIL_DESC mirrorDesc;
mirrorDesc.DepthEnable = true;
mirrorDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
mirrorDesc.DepthFunc = D3D11_COMPARISON_LESS;
mirrorDesc.StencilEnable = true;
mirrorDesc.StencilReadMask = 0xff;
mirrorDesc.StencilWriteMask = 0xff;
mirrorDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
mirrorDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
mirrorDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_REPLACE;
mirrorDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
[/CODE]

and after drawing reset it Edited by ~Helgon
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