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

O'Neil atmospheric scattering.

9 posts in this topic

Hello once again.

 

I've been adding the atmosphere model explained by Sean O'Neil (http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter16.html) and I have it 70% working. I'm thinking how is the best way to implement it in a scenario where I won't be using a planet. I'll just render a terrain (lets say 20x20km) and a few other elements.

My first idea was to render a 3d sphere for the sky with a radius of 4Km, then on the shader I'll specify the outer and inner radius accordingly. This is not a really good idea as I have to hack a few values to move up all the elements of my scene (so they will placed at the "earth" surface). 

The other idea is to make it as a postprocessing effect, define a sphere and raycast it using the scattering shader. I think it will work but I'm not sure how well it will fit in my scene (water,terrain,clouds) forward rendering with some transparent objects.

 

Any ideas?

See you!

 

Edit:

Here are the vertex and fragment shader I've been using. They are used with the 3D sphere:

Vert:http://pastebin.com/p00jTSSy

Frag:http://pastebin.com/KmcXcGc7

 

In those shaders i've been rendering the sky sphere like a skybox(depth mask disabled, rendered before the scene). The sphere in those shaders have 1m radius and I'm harcoding the camera position.

 

Update

Alright, I've been working on the solution using the sphere as a skybox and I'm having some problems with the algorithm itself. The sun gets black when its position is not laying on the x axis (0.0f,0.0f,1.0f) or (0.0f,0.0f,-1.0f) this is how it looks: https://i.gyazo.com/47778fc56b41eeccef798ff79a8a7379.png

Lets see an example if I set the sun position (sun position in the shader = sun direction) (0.0f,0.5f,1.0f): https://i.gyazo.com/22c556be20360b32e2f4431dc22816a0.png.

 

I updated the vertex and fragment codes: 

Vert:http://pastebin.com/shuL2iL5

Frag:http://pastebin.com/V7Pdi3Lq

I would like to mention that I'm ignoring the alpha value in the fragment shader.

Edited by piluve
0

Share this post


Link to post
Share on other sites

Update 2

I've updated all the variables in the shader that were harcoded and now I'm ussing uniforms to set them. I found a problem with the SunDirection that I send from the vertex to the fragment shader, I must normalize it, now the sun is no longer black but it has a strange shape.

0

Share this post


Link to post
Share on other sites

Update 3

I started working again on the atmosphere scattering shader and I'm still figuring out the best way to use it without having to render a sphere with the size of the atmosphere.

I've been using a sphere with radius 1 on top of the camera (like you would do with a skybox) but I have to hack some values. For example, I have to displace down the sphere, if I dont do that, the atmosphere apears on the North pole of the sphere...

Maybe the best way, would be to implement it on a postprocess but I'm not sure how it will fit with other elements (with alpha).

Any ideas?

Thanks!

0

Share this post


Link to post
Share on other sites

Maybe the best way, would be to implement it on a postprocess but I'm not sure how it will fit with other elements (with alpha).

I implemented O'Neil's scattering as a post-process a long time ago. It works.

 

Planets are pretty big, so broadly sorting rendered elements into [ground, ocean, clouds, atmosphere, space] makes it pretty easy to ensure the atmosphere is rendered in the right order such that alpha blending is resolved beforehand.

0

Share this post


Link to post
Share on other sites

 

Maybe the best way, would be to implement it on a postprocess but I'm not sure how it will fit with other elements (with alpha).

I implemented O'Neil's scattering as a post-process a long time ago. It works.

 

Planets are pretty big, so broadly sorting rendered elements into [ground, ocean, clouds, atmosphere, space] makes it pretty easy to ensure the atmosphere is rendered in the right order such that alpha blending is resolved beforehand.

 

 

Did you use raycasting to fake the atmosphere? 

0

Share this post


Link to post
Share on other sites

 

Did you use raycasting to fake the atmosphere?

Yep. Standard ray/sphere intersection.

Mine implementation is buried somewhere, but it looks like someone wrote the same thing on shadertoy.

 

 

Hey!

I found this project: https://github.com/wwwtyro/glsl-atmosphere and it's basically what I wanted. I implemented it in shadertoy (https://www.shadertoy.com/view/4sXcRS) so I can test with it first.

The doubt I have right now, is how to translate the directions:

vec3 rayDir = normalize(vec3(uv,-1.0));

So the effect is in camera space. Should I multiply it by the view matrix? I'm not sure about that.

See you!

0

Share this post


Link to post
Share on other sites

Okey I found a way  to get a ray and also to use the current view matrix. I would try to figure how to mix both the postprocess and the scene. 

0

Share this post


Link to post
Share on other sites

Posted (edited)

Alright, I found a way to mix it with my scene, I render the effect first with depth mask disabled and then render everything else. That part is working!

I have a problem tho with how I calculate the ray you can see the problem here: https://i.gyazo.com/745305ef1e04aab74b3c4cffaf0812f1.mp4.

As you can see its moving up and down...

I calculate the ray using:

vec3 GetRayDir(vec2 uv)
{
    mat4 rotMatrix = mat4(uView);
    rotMatrix[3] = vec4(0.0f,0.0f,0.0f,1.0f);
    mat4 iView = inverse(rotMatrix);
    mat4 iProj = inverse(uProjection);
 
    mat4 iVp = iProj * iView;
    vec3 rd;
    rd = (iVp * vec4(uv.x * uAspect,uv.y,-1.0f,1.0f)).xyz;
    return normalize(rd);
}
vec3 rayDir = GetRayDir(iPos.xy);

iPos is the attribute position of the fullscreen quad.

Any ideas?

Thanks!

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