Jump to content
This Topic

Recommended Posts

Posted

Light cone angles not saves:

1. Create spot light

2. Set 60 : 90 cone angles

3. Open map file or reload in the editor - 60 : 60

 

Brightness does not matches with in game bright in same cases, but can't reproduce it yet

 

Strange stripes from light on surfaces:

image.thumb.png.33bed6b9496c73085dd9e478bec8fcb3.png

Example map:Start.zip

Posted
  On 3/30/2025 at 6:14 AM, Dreikblack said:

Strange stripes from light on surfaces:

Expand  

This is shadow acne, and can always happen with texture-based lighting. Increasing the shadow map size and avoiding lights that are very close to a surface is the easiest way to avoid it.

  • Like 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Posted
  On 3/30/2025 at 8:00 AM, Josh said:

This is shadow acne, and can always happen with texture-based lighting. Increasing the shadow map size and avoiding lights that are very close to a surface is the easiest way to avoid it.

Expand  

Shadow map size increase helped. Also had to set 0 for near range. Working on flashlight for characters so had to be close to surfaces in any case.

Also noticed similar issue from sun light and no option to change shadow map for it in the Editor? Can do it via code ig, but extra field for in world settings would be convenient for people.

  • Like 2
Posted

The image above does not look bad. The artifact is barely visible even without any texture.

My job is to make tools you love, with the features you want, and performance you can't live without.

Posted

I think I created something pretty close to the magic formula that will make shadows close to objects that are casting them, but prevent most shadow acne.

At line 196 of Shaders/PBR/Lighting.glsl, try replacing this:

			shadowCoord.z *= 0.98f;
			shadowCoord.z = PositionToDepth(shadowCoord.z, shadowrange);

With this:

			//shadowCoord.z *= 0.98f;
			float tscale = (512.0f / float(textureSize(sampler2DShadow(shadowmap), 0).x));
			shadowCoord.z -= 0.005f * tscale;
			shadowCoord.z = PositionToDepth(shadowCoord.z, shadowrange);
			shadowCoord.z -= 0.001f * sin((1.0f - dp) * 1.5708f) * tscale;

An initial offset in linear space is used, and then a second offset is added AFTER conversion into non-linear space, and accounts for the angle between the surface normal and the photon direction. Most importantly, it treats the dot product as an angle, not a simple dot product, which I think is crucial for the accuracy. It also scales the offset by the texture resolution, so smaller shadow maps have a greater depth error.

image.thumb.png.764b299c7c8abcaca2c60813716a325f.png

It's a challenge because you want the tighest possible offsets without causing shadow acne, bit the depth values are stored in a strange non-linear way, and there is more precision near the camera than far away. I have made some attempts to store shadow maps in a linear depth value, but so far have been unable to find a way.

It is possible to modify gl_FragDepth in a fragment shader, but this comes at a performance cost because it eliminates the early-z discard. Does this cost apply to shadow rendering in any significant way? I think so but I don't know for sure.

  • Like 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Posted

I don't know, I just invented it ten minutes ago. We should probably test it out a bit more before making any big plans. :D

  • Like 2

My job is to make tools you love, with the features you want, and performance you can't live without.

Posted

For some reason i can rid of from shadow acne in my game only if put 0 for nearest range no matter shadow map size or shader changes, but i have no shadows from flashlight at all then.

Posted

Zero is not a valid number of the near range, for any light that uses perspective projection (spot and point). The value must be greater than zero.

My job is to make tools you love, with the features you want, and performance you can't live without.

Posted

That's shadow acne.

Why are the edges of the light perfectly sharp lines? The spot light is supposed to fade out near the edges.

My job is to make tools you love, with the features you want, and performance you can't live without.

Posted

It doesn't look anything like my spotlight above. The falloff method does not affect the cone angles.

My job is to make tools you love, with the features you want, and performance you can't live without.

Posted

The edges don't even look like a round shape. What are these sharp straight lines?

The cone angles should be defined in the order outer, inner, and a 90 degree angle is impossible because that would form a flat plane.

image.png.3c35d966d34b8f8d99701312ab63c648.png

My job is to make tools you love, with the features you want, and performance you can't live without.

Posted
  On 3/30/2025 at 2:28 PM, Josh said:

The edges don't even look like a round shape. What are these sharp straight lines?

Expand  

idk, it just works this way when created via code:

image.thumb.png.4ff2e9e69c5ee007164da964c6e30cd1.png

#include "Leadwerks.h"

using namespace Leadwerks;

int main(int argc, const char* argv[]) {
    auto displays = GetDisplays();
    auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);
    auto framebuffer = CreateFramebuffer(window);
    auto world = CreateWorld();
    auto camera = CreateCamera(world);
    camera->SetClearColor(0.125);
    camera->SetFov(70);
    camera->Move(0, 2, -2);
    auto ground = CreateBox(world, 20, 1, 20);
    ground->SetPosition(0, -0.5, 0);
    ground->SetColor(0, 1, 0);

    auto light = CreateSpotLight(world);
    light->SetPosition(0, 1, 0);
    light->SetColor(5, 5, 5);
    light->SetConeAngles(60, 90);
    light->SetShadowmapSize(4096);
    light->SetRange(1, 8 * 2);
    light->SetFalloff(LIGHTFALLOFF_INVERSESQUARE);

    while (window->Closed() == false and window->KeyHit(KEY_ESCAPE) == false) {
        world->Update();
        world->Render(framebuffer);
    }
    return 0;
}

 

Posted

Okay, I see.

You need to decrease the near range, and the inner cone angle should be less than the outer cone angle. Use values like maybe 60, 50.

My job is to make tools you love, with the features you want, and performance you can't live without.

Posted

Near range needs to be 1.0f to avoid character shadow from his own flashlight. And i'm fine with that shape anyway.

I will experiment with angles a bit later, thought it's horizontal and vertical. Set 60:30 for now, looks better, but might be not sharp enough for gameplay purposes laterimage.thumb.png.1b68d15af469a5f1e85c1e6eb6a7b295.png

  • Like 1
Posted

When I set the near range to 1.0 I noticed shadow acne appearing, so obviously that equation needs adjustment.

My job is to make tools you love, with the features you want, and performance you can't live without.

Posted

This seems to provide a consistent offset:

			float tscale = (512.0f / float(textureSize(sampler2DShadow(shadowmap), 0).x));
			shadowCoord.z -= 0.005f * tscale;
			shadowCoord.z = PositionToDepth(shadowCoord.z, shadowrange);
			shadowCoord.z -= 0.001f * sin((1.0f - dp) * 1.5708f) * tscale * (shadowrange.x / 0.1f);

 

  • Like 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...