• 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

Raymarching Soft Shadows

5 posts in this topic

I have been able to simulate soft shadows using raymarching in my test scene, as shown below:




However, these artifacts occur when I move the light too close to the occluder:




Can anyone who has experience with raymarching help provide any clues as to why these artifacts occur and how they can be removed?


Share this post

Link to post
Share on other sites

it looks like your light source is intersecting the sphere, and that the light itself has an actual size (and isn't an infinitely small point) which is good, but you're not handling the intersection case properly - or aren't preventing intersections from occuring in the first place.


Share this post

Link to post
Share on other sites

Okay, so I've figured out the cause. Here's my code for reference:

bool raymarch_shadows(vec3 ro, vec3 rd, float maxDist, vec3 lightPos, out float t, out vec3 p, out float light_intensity)
	t = 0.0;
	float minStep = 0.001;
	light_intensity = 1.0;
	for(int i = 0; i< 10; i++) {
		p = ro + rd*t;
		float mDist = rm_obj(p);

		if(mDist < 0.0015) {
			return true;

		light_intensity = min(light_intensity, 5.0*mDist/clamp(t,0.0,5.0));

		if(mDist < minStep) { mDist = minStep;}
		t += mDist;
		if(t >= maxDist) {break;}			

	return false;

Its to do with this function: if(t >= maxDist) {break;}

where maxDist is length of ray (t) from each surface point to the light. The reason why I have to stop the ray when it reaches the light is because if the ray is coming from behind the light, and the occluder is on the other side of the light, if I don't stop the ray, it will overshoot and still capture the occluder. Here is what happens when I remove the "break":




So the break function prevents this from happening; however, it creates another artifact, which is the sudden changes in lighting, like so:



I have now figured out what causes this. It only occurs at locations where the distance from the surface point to the occluder is equal to the distance from the surface point to the light (maxDist). On one side of these points, t < maxDist, thus this side is darker. On the other side, t >= maxDist so this side is lighter.


Now I just wish I could figure out how to get it to gradually fade between lighting intensities. Please provide any advice or thoughts if you have any.

Edited by gboxentertainment

Share this post

Link to post
Share on other sites

I've seemed to have minimized the problem by reducing the softness of the penumbras via changing this formula:






The issue still exists but only when the light is right on the surface of an object.


Now what I'm trying to do is to attach the raymarched shadows to the rasterized objects in the scene. At the moment I'm just testing with a simple box and a sphere, later on I will raymarch more complex objects like the buddha through use of a volume texture.


Right now though, my problem is that the shadow-casting objects themselves are also occluded by their own shadows - i.e. incorrect self-shadowing:




Notice how both the sphere and box are both much darker when they should be lit directly by the light.


Any ideas on how to resolve this?


Share this post

Link to post
Share on other sites

Problem solved smile.png




I've had to cheat a little bit though:


I had to slightly reduce the size of the signed distance version of the models so that the light-facing surface of the rasterized models were not shadowed by the signed distance objects.


Now all I have to do is to figure out a fast way of shadowing more complex objects like the buddha. I have heard that you can voxelize that model into a 3D texture and then raymarch. I have previously cone-traced this model to produce shadows but they were ugly due to the low-res 3d texture. If I increase the resolution then it becomes too expensive.


Alternatively, a volume rendering approach involves taking the difference between the front and back faces to get the ray-march directions, but for shadow ray-marching the direction is known because it is always in the direction of the light.


Can anyone suggest any other methods?


Share this post

Link to post
Share on other sites

So I've tried to raymarch an sdf texture of the stanford bunny from this website:



This is what it comes out as (I haven't rendered the bunny itself, just the shadow effect from it - its actually near the centre):



float sdf(vec3 p) {
	float res = 32;
	float zFrame = floor(p.z*res);
	float v1 = texture2D(volTex, vec2(p.x, (p.y*0.5+zFrame)/res)).r;
	return v1;

float rm_bunny(in vec3 p)
	vec3 p2 = p;
	p2 += vec3(0,0,0); p2.z = -p2.z + 1.0;
	p2.x = min(1.0,max(0.0,p2.x));
	p2.y = min(1.0,max(0.0,p2.y));
	p2.z = min(1.0,max(0.0,p2.z));
	bunny = (0.5-sdf(p2))*0.3;

	return bunny;

I admit that most of this code was copied from that website and modified slightly without my complete understanding of it.

I just want to figure out how to minimize the noise adjacent to the shadow - it is a symptom of the softness of the penumbra.


Also, I don't know what's causing the gap between the bunny shadow and the other object shadows - I'm using min(rm_bunny(p),min(cube, sphere));

Its not to do with the raymarching steps because the gaps are still there even when using 500 steps.

Edited by gboxentertainment

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