DarioSamo / sm64rt-legacy-renderer

MIT License
73 stars 7 forks source link

Post processing #20

Open erherhh4herh opened 3 years ago

erherhh4herh commented 3 years ago

It would be great to have post processing support (bloom, tonemapping, motion blur, etc). This is a proof-of-concept implementation ComposePS.hlsl, it is not meant for final production.

Before: image

Tonemapping is especially important here as the before is extremely blown out.

After: image

The after is not nearly as blown out, while also being more "natural".

The tonemapper is ripped from Unity, it is the same tonemapper Unreal Engine and Blender uses. It's called ACES, the code is here:

float3 ACES(float3 col, float exp) { //const float a = 0.88; //const float b = 0.0; //const float c = 0.7; //const float d = 0.66; //const float e = 0.04;

// unity engine defaults
const float a = 278.5085;
const float b = 10.7772;
const float c = 293.6045;
const float d = 88.7122;
const float e = 80.6889;

// REC709 D65
//const float a = 2.51f;
//const float b = 0.03f;
//const float c = 2.43f;
//const float d = 0.59f;
//const float e = 0.14f;

return saturate(((col * (a * col + b)) / (col * (c * col + d) + e)) * exp);

}

This is where that code snippet came from: Unity's ACES Implementation

Thank you for your time!

DarioSamo commented 3 years ago

HDR tonemapping is definitely one of the things I would like to add to solve how overexposed or underexposed some areas look, but I feel just ACES tonemapping might not be enough to solve that without taking into account the average luminance calculation of the scene.

I guess we need to determine which scenes should be checked before and after applying something like this to make sure it doesn't have unintended effects. Probably HMC and BBH are good scenes with very dark colors to check.