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

Trouble combining two projection spaces?

4 posts in this topic

Hi all,

Here's the setup:
I have a deferred rendering chain that renders all world-space items to several targets, then does screen-space calculations on those targets to get my final result, which is then rendered onto a screen-facing quad in an orthographic projection that is drawn to the backbuffer and presented.

Shorthand:

World content -> World-View-PerspectiveProjection matrix -> gbuffer -> textured to quad -> orthographic projection matrix -> screen.

This is all for a level editor, which lets you paint directly on the terrain and manipulate terrain structure, etc. One thing I'm trying to do is draw the "border" of the paintbrush on the terrain, and I already have reverse projection in place for picking, so I know (in world-space coordinates) where the mouse is pointing at all times. My brush border is a linestrip that is drawn relative to that world-space point.

[b]Here's the specific question:[/b]

I want to draw the brush border as it lays on the terrain. I get its normalized coordinates (in the -1,1 range on all three axes) by applying the same worldViewProjection matrix that I use to draw the rest of the world content. I'm trying to draw the resulting linestrip on TOP of the ortho view of the textured quad that shows my deferred results (so that the color of the linestrip isn't affected by any of the pixel shaders that combine my deferred buffers). [b]If both an ortho projection and a perspective projection translate coordinates into the same normalized space, why doesn't the brush circle [/b](technically an ellipse in all but a straight-down view)[b] show up correctly in the view?[/b]

A few extra notes:

-My ortho view is built with the viewport width and height of the WinForm it's built into, depth range .1 - 10, with the textured quad at z=10 just to put it as far back as possible.
-The normalized z-depth of the brush radius is usually around +.7 - +.9 given the perspective projection is given a depth range of 4-1000.

-The brush verts are drawn to the backbuffer via a shader that only uses the world-view-projection matrix, AFTER the textured quad is drawn to the backbuffer using the ortho matrix.

-My expectation is that I would get an ellipse (my brush circle from the camera perspective) overlayed on the ortho view of the textured quad. Instead, I get the attached image. This has to be a stupid Linear algebra mistake, but I'm not sharp enough to see it right now.
[attachment=11139:exampleView.jpg]
The green line is my problem. That [i]should [/i]be a circle drawn onto the terrain at the mouse point. What am I forgetting or incorrectly assuming?
0

Share this post


Link to post
Share on other sites
Is your brush border strip correct? I.e. if you render it as "normal" object in deferred pass, does it appear as ellipse (as it should) or line (as it does now)?
Try hardcoding linestrip coordinates (so it lies on the ground plane) - what happens?
1

Share this post


Link to post
Share on other sites
You're on to something here, I finally went in and rearranged my draw code to add the border to the diffuse target, and I get the same result. Here's the code that builds my linestrip:

[code]
borderVerts = new VertexPositionColor[16];
lineIndices = new short[17];
double angle = MathUtil.PiOverTwo/4;
for (int i = 0; i < 16; i++)
{
Vector3 temp = new Vector3((float)Math.Sin(angle * i) * radius,
0f,
(float)(Math.Cos(angle * i) * radius));
borderVerts[i] = new VertexPositionColor(temp, new Vector4(0f,1f,0f,1f));
originalBorderVerts[i] = borderVerts[i]; //stores them for an "expand" method if I change radius (not using right now)
lineIndices[i] = (short)(i);
}
lineIndices[16] = 0;

[/code]

This gave me what I was looking for in XNA, so I'm not sure what's missing...
0

Share this post


Link to post
Share on other sites
Followup: this all has to do with how I'm applying a World matrix multiplication, as when I swapped that out with an identity matrix, the circle is showing up perfectly (in either g-buffers or the main backbuffer). So initial question answered: my assumption on normalized spaces is correct. Now I just need to figure out how I'm messing things up with a Translation matrix...
0

Share this post


Link to post
Share on other sites
Resolution: always remember when writing your matrix multiplications in the shader code to pass the matrix as the SECOND argument in a mul() call. *sigh*
Thankfully, after a weekend not looking at the problem, 5 minutes reading the code found the obvious mistake.
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