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

Multiple draw calls unable to use different OMSetBlendState?

9 posts in this topic

Hi!

I have a situation that boggles my mind. If i have two meshes, and i use OMSetBlendState before drawing each one (with DrawIndexed), both of them seem to be using whatever the most recent blend state that was set. EIther that, or the map/unmap of the lighting properties buffer is only using the most recent settings. Using PIX seems unreliable here but if it's not bugging out, it would seem to be the latter.

Basically, the first mesh is drawn with an alpha blending blend state, the second mesh is drawn with blending disabled (opaque). If i draw only the first mesh, it's correctly rendered - a plant texture with alpha blending around the branches. If i draw the second mesh after the first mesh, which disables alpha blending (for the 2nd mesh draw only), the first mesh that was working fine is also drawing opaquely.

Can anybody give me any ideas of things to try? OMSetBlendState should only be per draw call right?

I'm out of ideas... I'm not sure what other info would be relevant but feel free to ask..

Thanks
0

Share this post


Link to post
Share on other sites
try drawing transparent objects last. You should always draw the transparent objects last anyway so that they have something to blend with on the back buffer. if they are drawn first, they will only blend with whatever is drawn before them, which in this case, it sounds like nothing is drawn before the transparent object, so it probably doesn't appear transparent if it happens to be in front of the opaque object, since the opaque object is drawn last, hope that makes sense

Otherwise, try just adding the line "clip(diffuse.a - 0.25f);" in your pixel shader. this will "clip" or just not draw any pixels with an alpha value of less than .25.
1

Share this post


Link to post
Share on other sites
all state changes and or new resources sent to the GPU will affect everything after. so if you want to use the SAME blendstate for both, just se it befor drawing both.

And chaning to correct states per drawcall is insane, sort them and draw them in batches rahter than per state.
And for alpha, you need to draw alpha after all the other drawing. and you have to sort then so that the object farest away is drawn first, and the closest is drawn last.

EA, the gpu dont know what to do if you dont sort your alpha draws.

hope this make sense.
0

Share this post


Link to post
Share on other sites
[quote name='iedoc' timestamp='1333356231' post='4927405']
try drawing transparent objects last. You should always draw the transparent objects last anyway so that they have something to blend with on the back buffer. if they are drawn first, they will only blend with whatever is drawn before them, which in this case, it sounds like nothing is drawn before the transparent object, so it probably doesn't appear transparent if it happens to be in front of the opaque object, since the opaque object is drawn last, hope that makes sense

Otherwise, try just adding the line "clip(diffuse.a - 0.25f);" in your pixel shader. this will "clip" or just not draw any pixels with an alpha value of less than .25.
[/quote]

Hmm let me try to be more clear.. i'm drawing 2 meshes

1) uses a transparent blend state, imagine a model of a plant where you want to not render the parts of the texture that have 0 alpha
2) drawn opaquely - blending turned off. this is just a regular basic textured model mesh

the two meshes are not the same object, the geometry is in different areas.

i do the following

1) set blend state to the alpha enabled state (your basic alpha, inv alpha blend)
2) draw mesh #1 (needs this transparency)
3) set blend state to the blend disabled state
4) draw mesh #2 (needs to be opaque)

The result on the backbuffer is that mesh #1 is drawn opaquely, not just mesh #2.

If i change the code to draw mesh #1 only, it is drawn correctly with transparency.

This seems to indicate that the first blend state I set is not used for the first draw call.

Regardless of best practices for rendering order, doesn't this seem wrong?
0

Share this post


Link to post
Share on other sites
OMSetBlendState isn't so much 'per draw call' as it is 'set until it is changed again'.

Based on what you are seeing it sounds like on the 2nd run of the rendering loop the blend state isn't being set correctly, which I personally would attribute to a bug in your code rather than any sort of DX/driver issues.

The best advice I can give is to look at the device state at each draw call in PIX to see what is going on; you'll probably want to capture a couple of frames and certainly will want to grab the first frame to see if your state is even being set correctly.
0

Share this post


Link to post
Share on other sites
[quote name='phantom' timestamp='1333401123' post='4927635']
OMSetBlendState isn't so much 'per draw call' as it is 'set until it is changed again'.

Based on what you are seeing it sounds like on the 2nd run of the rendering loop the blend state isn't being set correctly, which I personally would attribute to a bug in your code rather than any sort of DX/driver issues.

The best advice I can give is to look at the device state at each draw call in PIX to see what is going on; you'll probably want to capture a couple of frames and certainly will want to grab the first frame to see if your state is even being set correctly.
[/quote]

Speaking of PIX this kind of relates to the other issue -- if i use PIX, the values in the lighting params constant buffer seem to be wrong as if they're using the values from the most recent map/unmap to the cbuffer. The same deal as the above, im updating the lighting cbuffer inbetween draw calls but in PIX when i debug that first draw call, the registers show the values of what would be the cbuffer state used for the 2nd draw call.

I thought maybe these two items were both related to some setup/config error, where all the draw calls are actually deferred to the end and only use the 'last' states set in the frame.

If i debug the copy to cbuffer, or the OMSetBlendState and look at the values they're 100% correct. It is however wrong in practice and in PIX.

Again, PIX shows cbuffer values set inbewteen 1st and 2nd draw call, even when looking at the device state during the first draw call.
0

Share this post


Link to post
Share on other sites
Assuming you aren't using deferred contexts then all draw calls are executed when the draw functions are called' nothing is deferred until 'later' and all state during execution would be as it is when that call is made.
0

Share this post


Link to post
Share on other sites
[quote name='phantom' timestamp='1333402560' post='4927648']
Assuming you aren't using deferred contexts then all draw calls are executed when the draw functions are called' nothing is deferred until 'later' and all state during execution would be as it is when that call is made.
[/quote]

I am using deferred contexts but only to prepare buffers and stuff, not when drawing...

Everyone always tells me it's just a PIX bug if it shows wrong values in registers and that it's not reliable.. I guess i can't really be sure until i get a machine with 2 videcoards and can debug shaders with nsight?

This is flat out insane that it seems to be doing this..
0

Share this post


Link to post
Share on other sites
I finally figured out the issue.

Apparently, you can't bind a cbuffer to to register cb1 and set it in code to slot 1, if there's nothing in slot 0. If you do, the shader will just use garbage data for the values in your cbuffer structure (well, seemed to be 0's in this case).

I don't know if this is a driver bug or just a quirk, but there you go.
0

Share this post


Link to post
Share on other sites
It may be a driver bug. You can always try with the REF device to see if it produces the correct behavior.
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