Dreikblack Posted March 30 Posted March 30 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: Example map:Start.zip Quote
Josh Posted March 30 Posted March 30 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. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without.
Dreikblack Posted March 30 Author Posted March 30 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. 2 Quote
Josh Posted March 30 Posted March 30 The image above does not look bad. The artifact is barely visible even without any texture. Quote My job is to make tools you love, with the features you want, and performance you can't live without.
Dreikblack Posted March 30 Author Posted March 30 It was way worse on practice before i fixed it: Quote
Josh Posted March 30 Posted March 30 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. 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. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without.
Alienhead Posted March 30 Posted March 30 Will this shader hack make it to live updates? or is this something we need to do on a per-project-basis? I too have had horrible shadow banding on most surfaces. Quote Alienhead Components and Software
Josh Posted March 30 Posted March 30 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. 2 Quote My job is to make tools you love, with the features you want, and performance you can't live without.
Alienhead Posted March 30 Posted March 30 I can already tell it's working better. Quote Alienhead Components and Software
Dreikblack Posted March 30 Author Posted March 30 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. Quote
Josh Posted March 30 Posted March 30 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. Quote My job is to make tools you love, with the features you want, and performance you can't live without.
Dreikblack Posted March 30 Author Posted March 30 Tried 4096 - works, but without shader changes. With changes new visual artefact appears: Quote
Josh Posted March 30 Posted March 30 I can't tell what I am looking at there. Quote My job is to make tools you love, with the features you want, and performance you can't live without.
Josh Posted March 30 Posted March 30 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. Quote My job is to make tools you love, with the features you want, and performance you can't live without.
Dreikblack Posted March 30 Author Posted March 30 On 3/30/2025 at 2:16 PM, Josh said: Why are the edges of the light perfectly sharp lines? Expand Because i do SetFalloff(LIGHTFALLOFF_INVERSESQUARE); Need it to be sharp for flashlight which will affect gameplay. Quote
Josh Posted March 30 Posted March 30 It doesn't look anything like my spotlight above. The falloff method does not affect the cone angles. Quote My job is to make tools you love, with the features you want, and performance you can't live without.
Josh Posted March 30 Posted March 30 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. Quote My job is to make tools you love, with the features you want, and performance you can't live without.
Dreikblack Posted March 30 Author Posted March 30 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: #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; } Quote
Josh Posted March 30 Posted March 30 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. Quote My job is to make tools you love, with the features you want, and performance you can't live without.
Dreikblack Posted March 30 Author Posted March 30 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 later 1 Quote
Josh Posted March 30 Posted March 30 When I set the near range to 1.0 I noticed shadow acne appearing, so obviously that equation needs adjustment. Quote My job is to make tools you love, with the features you want, and performance you can't live without.
Josh Posted March 30 Posted March 30 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); 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without.
Dreikblack Posted March 30 Author Posted March 30 On 3/30/2025 at 4:12 PM, Josh said: This seems to provide a consistent offset: Expand Now i have no shadow acne with default shadow map size Quote
Recommended Posts
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.