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

MRT & Z Pre-Pass manually ?

5 posts in this topic

Hi, I am about to pull the trigger with my first attempt to render to multiple targets, because I want to do SSAO,
the implementation with normals, that's why I am using MRT, the first one is for depth (D3DFMT_D24X8) the
second one is for normals (D3DFMT_A8R8G8B8).

Now, I heard about Z Pre-Pass, and right now I have the depth stored, can I use it as depth stencil and let the
comparison made it automatically with D3DCMP_LESSOREQUAL? or I have to do it in the pixel frament,
and discard every pixel if not pass my depth comparison manually?

I know how to use the depth stencil directly writting black, but I don't know if it is possible with MRT AND
I need the depth as texture to be able to reconstruct position from it.

thanks and please sorry my bad grammar, you can spot my errors, that will help too.
0

Share this post


Link to post
Share on other sites
What hardware/API are you targetting? In D3D11 with FEATURE_LEVEL_11, you can create a read-only depth stencil view for your depth buffer. That lets you keep the buffer bound for depth/stencil testing (you can't enable depth or stencil writes), while simultaneously sampling it in the pixel shader. For FEATURE_LEVEL_10_1 (DX10.1), your next-best option is to copy the contents of the depth buffer to another texture and use that for depth testing. For FEATURE_LEVEL_10 you don't even have that option, so you're pretty much stuck.
1

Share this post


Link to post
Share on other sites
The target is D3D9 shader model 3.0, now I don't know what would be the best choice to do, because, I inevitably will draw the geometry twice because of the SSAO,
I thought that is possible to perform a depth test using the depth texture (thinking in shadow map), and discard pixels beyond the depth, but there will be z-fighting for
sure.
0

Share this post


Link to post
Share on other sites
For dx9 you have to create an extra render target of Float32 and then you should output the depth in what ever space you need --like world space depth -- so that you can simply read it in later without reconstructing anything. In dx9 you cannot read from the depth buffer in the pixel shader. In dx10, you can create a depth buffer with the ability to sample it in the pixel shader.

Also, most early-z passes do not cause an increase in speed. You must have an extremely heavy pixel shader to get any benefit out of it.
1

Share this post


Link to post
Share on other sites
[quote name='_Camus_' timestamp='1295347548' post='4760642']
Hi, I am about to pull the trigger with my first attempt to render to multiple targets, because I want to do SSAO,
the implementation with normals, that's why I am using MRT, the first one is for depth (D3DFMT_D24X8) the
second one is for normals (D3DFMT_A8R8G8B8).[/quote]D3DFMT_D24X8 is for use as a depth-stencil target, not as an MRT target. As mentioned above, you should use a floating-point, or ARGB8 texture here instead of a D24 one.

Or, if your card supports reading from depth-buffers, then you don't need MRT - just use the depth-stencil target.[quote name='_Camus_' timestamp='1295387980' post='4760914']I thought that is possible to perform a depth test using the depth texture (thinking in shadow map), and discard pixels beyond the depth, but there will be z-fighting for sure.[/quote]If the exact same geo is drawn with the exact same matrices, there won't be z-fighting.[quote name='smasherprog' timestamp='1295413040' post='4761055']
In dx9 you cannot read from the depth buffer in the pixel shader. In dx10, you can create a depth buffer with the ability to sample it in the pixel shader.[/quote]You can read from the depth buffer in DX9 if the end-user has a DX10-level graphics card.

To do this, you make a texture with D3DFMT_INTZ instead of D3DFMT_D24X8. To check if this is supported you can use:[code]const static D3DFORMAT D3DFMT_INTZ = (D3DFORMAT) MAKEFOURCC('I','N','T','Z');
bool supportsIntZ = d3d->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, displayMode.Format, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE, D3DFMT_INTZ);[/code]
2

Share this post


Link to post
Share on other sites
Hi, Thanks

@Hodgman that DX9 secret capability is awesome, and yes, was my mistake is D3DFMT_R32F, I was thinking in depth stencil too much :rolleyes:

Now I can read it directly, in fact the Z Pre-Pass is working now:

1 - Render to depth
2 - Clear only target, disabling Z Writting and ZFunc to LessEqual

Using 3 point lights, Z Pre Pass saves me about .1 ms on the second pass. Now that I also can read directly from depth, I was curious to make the
depth test by myself on the fragment program, first to ensure that I was using the right projective texture coordinates I did the follow specting to have
z fighting:

[code]
float2 Texcoords = 0.5 * In.Other.xy / In.Other.w + float2( 0.5, 0.5 );
Texcoords.y = 1.0f - Texcoords.y;
float dist = In.Other.z/ In.Other.w;

if(dist == tex2D( nolerpsampler, Texcoords ).r)
return float4(1.0f,0.0f,0.0f,1.0f);
[/code]

And I was right:

[img]http://img233.imageshack.us/img233/7857/zfighting.png[/img]

Well, I thought it would be a matter of adding bias to the distance and do the test:

[code]
...
float dist = (In.Other.z + 0.001f) / In.Other.w;

if(dist > tex2D( nolerpsampler, Texcoords ).r)
return float4(1.0f,0.0f,0.0f,1.0f);

[/code]

And, I was wrong:

[img]http://img717.imageshack.us/img717/2075/bias.png[/img]


Why? It is supposed to be (dist + bias), and not (dist - bias), why it works inverse to what I spected?

Thanks Again
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