Giter Site home page Giter Site logo

Noisy lightmaps about lightmapper HOT 8 CLOSED

ands avatar ands commented on June 20, 2024
Noisy lightmaps

from lightmapper.

Comments (8)

jpcy avatar jpcy commented on June 20, 2024 1

You could ray trace the directional sun light using Embree. Use the lightmapper rasterizer to get the worldspace position of each luxel, then trace a ray in the direction of the sun to see if it's occluded. For smoother shadows, take multiple samples with jittered sampling positions and average them. Then run the lightmapper to get bounce lighting.

from lightmapper.

braddabug avatar braddabug commented on June 20, 2024 1

I think that will work. I modified my code to do a initial pass where I shoot a ray from each texel to the light, and that calculates pretty nice direct lighting. Then I feed that in to the emissive texture and start the indirect lighting passes. It looks quite a bit nicer. Practically no noise!

I did have to modify lightmapper.h to get things like the lightmap texel position (world coords and texel coords) and normal since the contents of lm_context are hidden. I just added this function:

void lmTexelInfo(lm_context* ctx, float* outWorldPos, float* outDirection, int* outTexelCoord, int* hemisphereSideIndex)
{
	if (outWorldPos)
	{
		outWorldPos[0] = ctx->meshPosition.sample.position.x;
		outWorldPos[1] = ctx->meshPosition.sample.position.y;
		outWorldPos[2] = ctx->meshPosition.sample.position.z;
	}

	if (outDirection)
	{
		outDirection[0] = ctx->meshPosition.sample.direction.x;
		outDirection[1] = ctx->meshPosition.sample.direction.y;
		outDirection[2] = ctx->meshPosition.sample.direction.z;
	}

	if (outTexelCoord)
	{
		outTexelCoord[0] = ctx->meshPosition.rasterizer.x;
		outTexelCoord[1] = ctx->meshPosition.rasterizer.y;
	}

	if (hemisphereSideIndex)
	{
		hemisphereSideIndex[0] = ctx->meshPosition.hemisphere.side;
	}
}

EDIT: I tweaked the code a little bit. I wanted the hemisphere side index, but I guess I was getting the hemisphere index instead.

from lightmapper.

ands avatar ands commented on June 20, 2024

Hi,

What do you write into the alpha channels in your own surface fragment shaders? (should be 1.0 for front faces)
Do you maybe clear the framebuffer on your own? Or change the target framebuffer/viewport/scissor rect?
Do you modify the matrices before multiplying them with the vertex positions?
What are your lmCreate parameters and api call order?

Cheers :),
Andreas

from lightmapper.

braddabug avatar braddabug commented on June 20, 2024

My code is based on the example, so the shaders are the same. And I can't find anywhere that I'm clearing the framebuffer or changing anything before drawing.

My call to lmCreate() looks like this:

lm_context *ctx = lmCreate(
		64,               // hemisphere resolution (power of two, max=512)
		0.01f, 200.0f,   // zNear, zFar of hemisphere cameras
		0, 0, 0, // background color (white for ambient occlusion)
		0, 0.00f);        // lightmap interpolation threshold (small differences are interpolated rather than sampled)
						  // check debug_interpolation.tga for an overview of sampled (red) vs interpolated (green) pixels.

Then I'm calling lmSetTargetLightmap(), then lmSetGeometry(), then the lmBegin()/lmEnd() loop.

The full source is here: https://github.com/braddabug/thegame/tree/master/Tools/LightmapTool

It's got to be some little thing I'm doing wrong. I checked with Valgrind on Linux and it didn't report anything. OpenGL doesn't complain about anything either.

from lightmapper.

ands avatar ands commented on June 20, 2024

from lightmapper.

ands avatar ands commented on June 20, 2024

Hey :)
First I thought that the noise looked very random, but after building and running your tool I quickly realized that you are using a very tiny light source. So, the noise is just a very severe undersampling artifact.
I actually got ok-ish results when increasing the hemisphere rendering resolution. Try these parameters:

lm_context *ctx = lmCreate(
512, // hemisphere resolution (power of two, max=512)
0.01f, 200.0f, // zNear, zFar of hemisphere cameras
ambientRed, ambientGreen, ambientBlue, // background color (white for ambient occlusion)
3, 0.01f);

It will be slower and there's still some minor noise on some wall parts.
You can easily get rid of noise artifacts (and thus improve performance, because you don't need such a high hemisphere rendering resolution) by using larger light sources, if applicable.

Here's a shot with two bounces:
Indirect Light

from lightmapper.

braddabug avatar braddabug commented on June 20, 2024

Thanks! Now that I think about it that makes perfect sense.

The tiny point light will eventually become a directional "sun" light. Maybe it'd be best to investigate representing the entire sky as an HDR floating-point cubemap, that way aliasing becomes less of an issue since the cubemap can easily be filtered/smoothed. I think.

from lightmapper.

ands avatar ands commented on June 20, 2024

If you want to use this lib for indirect lighting, you could also render your scene with the usual direct scene lighting during baking (a static shadow map, materials, point/directional/spotlights, etc.)

from lightmapper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.