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

Ray: distance travelled between 2 planes

9 posts in this topic

I'm trying to fake cheap-ass ground fog. I made my own version, but it has problems, which I don't understand.

Since math and physical activity are things I'll get to - eventually; I might as well ask for some help.

 

This is my own version:

float foglen = max(0.0, fogTopY - point.y) / max(0.1, pointDir.y);

The double max() was a signal to me that things were not done correctly.

 

pointDir is the direction vector from camera to a point in world.

point is the points world coordinates.

fogTopY is the top of the fog plane, and point.y is the bottom of the fog plane. (when travelling)

 

Both planes' normals can be assumed to be vec3(0, 1, 0)

 

I'm already using math-fu to smooth the top and bottom of the fog.

Still, my equation does work, but I'm wondering if there's anything wrong with it.

Edited by Kaptein
0

Share this post


Link to post
Share on other sites

What distance are you trying to find exactly?  Is it the distance along the camera path from the first plane intersection to the second plane intersection?

Edited by hagerprof
0

Share this post


Link to post
Share on other sites

What distance are you trying to find exactly?  Is it the distance along the camera path from the first plane intersection to the second plane intersection?

 

I'm trying to find the distance travelled in fog, so the distance ray has to travel from cameraPos to point, except only in fog. Fog starts at fogTopY and goes all the way down. The point is a world coordinate belonging to a pixel/fragment. Which is what you guessed.

0

Share this post


Link to post
Share on other sites

is pointDir.y always negative? If it is always negative then max(0.1, pointDir.y) will always be 0.1;

 

Only if I'm looking upwards, which happens. Removing the max() doesn't help much because ray.y can be 0 when looking straight forward into the fog.

The thing is, I know there is a way to calculate this travel distance properly, because my equation is basically just me and a paper - not much.

 

The ideal solution is something that is [0, ZFAR], so that traveldistance / ZFAR => [0, 1].

Edited by Kaptein
0

Share this post


Link to post
Share on other sites

Your basic len calculation looks ok, take a look at Eric's fog document over here, it should help you with your ground fog.

0

Share this post


Link to post
Share on other sites

Every time i read a whitepaper, I ask myself if there is some stigma attached to explaining things clearly with proper names and function descriptions.

Not that it's completely unreadable.

 

Well, it works now, at least with smoothing the top and bottom:

float foglen = max(0.0, fogTopY - point.y) / abs(ray.y);
Edited by Kaptein
0

Share this post


Link to post
Share on other sites

Oops, I forgot to hit post on this and fell behind in the discussion:

 

"I'm probably not totally understanding the context.   If y is positive down, your numerator will always be 0 because the fogTopY - point.y should always be negative. 

 

If y is positive up, and your camera is always facing the ground (from the air), your denominator will always be 0.1, because pointDir.y will always be negative."

 

The article has a nice 3D solution.  However, it looked like it pre-solved the dot products in its code, which I don't think would fit your known data. Your code would have to do this. 

 

Is ray.y equal to pointDir.y? Does ray.y have a fixed length? If so you may have a problem when you have a horizontally facing camera as the equation will approach infinity.  This would be right if your camera is in the fog, but would throw an exception.  If the camera were above the fog, it would give an incorrect answer.

 

Also, I'm assuming that the camera can be above or in the fog.  The article adeptly uses a saturation function to control the distance of non-traversed fog. Since you haven't used one, you'd probably need an "if" statement( especially if you don't have saturation available in your programming language.)

 

If you want we can work through a specific equation for your case(s).

0

Share this post


Link to post
Share on other sites

as the equation will approach infinity

 

Indeed, the entire fog area becomes white. I smoothed it out on the top and bottom, and the results were ok. The reason I posted on this forum was simply to know if there was a way to do this thing that made some beautiful mathematical sense. Typically how you have issues with angles, but not with vectors.

 

What does the saturation() function do?

In GLSL you have min() and max(), step() and other stuff to avoid if () branches.

	// distance in fog is calculated with a simple intercept
	float foglen = max(0.0, fogTopY - point.y) / abs(ray.y);
	foglen = min(1.0, foglen / ZFAR);
	
	// how far are we from center of fog?
	float foglevel = min(1.0, abs(point.y - fogY) / HEIGHT);
	foglevel = 1.0 - foglevel * foglevel;

That's how I calculate the fog now.

foglen is the length the ray traversed into the fog and foglevel is my crossfade top/bottom.

Multiplied together the fog will no longer have hard edges, add some noise on top and its decent.

 

Where fogY is the center of the fog (absolute Y-coordinate) and HEIGHT is how far the fog goes up and down.

Edited by Kaptein
0

Share this post


Link to post
Share on other sites

Before I forget, saturation is explained way better than I can do in this.

 

I think that I might still be not getting it, but your foglen essentailly is driven by the height of your fog itself.  So, if your camera is angled the same at point, but  as both move  (with no relationship change), foglen can change if the fog height grows.  This would work fine if you are approximating the fog thickness with the height of the fog.  I'm not sure that is what you want.

 

Why not use an equation like:

 

foglen = abs((cam.y-point.y)*Math.sqrt(ray.x*ray.x+ray.y*ray.y+ray.z*ray.z)/ ray.y)                              (add your math libs as needed)

 

where cam.y is your camera's y position?  You can apply a max or min if desired.

Edited by hagerprof
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