• 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

Fragments view space from depth in WebGL

3 posts in this topic

Hi there,


I'm currently trying to implement a SSAO in WebGL. My inspiration is this site: Tutorial


But my current problem is to reconstruct the fragments view space position from depth.

If I understood the viewray right it is a vector from the camera to a point on the far plane. I read through all of MJP s articles, but they confused me somehow.

I render a fullscreen quad, so i get the TexCoords and the positions of x and y of the vertex. So my thought was, that only z is needed which I filled with the linearized depth value at the position of the TexCoord.



For visualisation I switched the coordinates from -1,+1 to 0,1; But even with that info I don't really know what the outcome should look like.

vec3 viewRay = vec3(vViewRay.xy * 0.5 + 0.5 , linearDepth);

Here is a fiddle of my 2 shaders I use.




Thanks for your ideas



Share this post

Link to post
Share on other sites

I continued my research and found out that I need to project my vertices of the quad to the corners of the farplane by multiplying

 it with the inverse of my perspective matrix in the vertex shader.

So far so good.

vViewRay = vec3(vec4(VertexPosition, 1.0) * invPerspectiveMatrix).xyz;

Displaying viewray in the fragment shader looks like this:




I think it looks just fine with exception of the missing blue values. This could possible be the result of the z-value of my quad all being 1.0 before the inverseprojection.

So it is gone after that. Putting z of the far clipping plane (z=1000); in, didn't change anything.


Any suggestions?

Edited by Pris0n

Share this post

Link to post
Share on other sites

Normals will also look like that if you pass them out through the color output. 


Try using the following formula to retool all the 3D vectors into the "color quadrant"??? I think I just made that name up???... or color space if you prefer.  Anyways, by this I mean: all positive numbers, between 0.0 and 1.0. as vectors they are -1.0 to 1.0.  Colors with negative numbers in them have peculiarities that are not entirely intuitive.  For example, what you are seeing there.


When a 3D modeling program range compresses normals from 3D space to a color texture it uses this formula ->  


(normal+ 1.0) * 0.5;  


For you it would be:


 (vViewRay + 1.0) * 0.5;  


It squishes all three vectors to half their sizes then pushes everything towards the positive... well... color quadrant.


Your vector should now look like a world space normal map now I'm thinking...


Share this post

Link to post
Share on other sites

Ah ok, maybe I confuse you :)


I want to reconstruct my VertexPosition in view space from depth. So far I read through tons of artictles but wasn't able to get thinks working.


vec3 origin = should be my final VertexPosition in view space


Currently I'll do this, taken from http://mynameismjp.wordpress.com/2010/09/05/position-from-depth-3/

vec3 origin = vec3(screenPos.xy, 1.0) * linearDepth;

screenPos are the ndc of the screen:

vec2 screenPos = vec2(gl_FragCoord.x / 512, gl_FragCoord.y / 512.0);

But I dunno what origin should look like so i can validate the that it worked.


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