Exposure and tonemapping.

This commit is contained in:
Lubos Lenco 2016-04-08 21:55:07 +02:00
parent 837711c783
commit d33d10313c
3 changed files with 60 additions and 15 deletions

View file

@ -113,20 +113,15 @@ class Object:
return json.dumps(self, default=lambda o: o.__dict__, sort_keys=True, indent=4)
def get_export_scene_override(scene):
for window in bpy.context.window_manager.windows:
screen = window.screen
for area in screen.areas:
if area.type == 'VIEW_3D':
for region in area.regions:
if region.type == 'WINDOW':
override = {
'window': window,
'screen': screen,
'area': area,
'region': region,
'edit_object': bpy.context.edit_object,
'scene': scene}
return override
# None for now
override = {
'window': None,
'screen': None,
'area': None,
'region': None,
'edit_object': None,
'scene': scene}
return override
# Transform Blender data into game data
def exportGameData():

View file

@ -193,7 +193,8 @@ void main() {
// outColor.rgb *= occlusion;
// outColor.rgb *= ao;
gl_FragColor = vec4(pow(outColor.rgb, vec3(1.0 / 2.2)), outColor.a);
gl_FragColor = vec4(outColor.rgb, outColor.a);
// vec4 aocol = texture(ssaotex, texCoord);
// gl_FragColor = aocol;
}

View file

@ -97,6 +97,42 @@ vec3 lensflare(vec2 uv, vec2 pos) {
return c;
}
const float MIDDLE_GREY = 0.18;
float getExposure(float aperture,
float shutterSpeed,
float iso) {
float q = 0.65;
//float l_avg = (1000.0f / 65.0f) * sqrt(aperture) / (iso * shutterSpeed);
float l_avg = (1.0 / q) * sqrt(aperture) / (iso * shutterSpeed);
//float l_avg = sqrt(aperture) / (iso * shutterSpeed);
return MIDDLE_GREY / l_avg;
}
//Based on Filmic Tonemapping Operators http://filmicgames.com/archives/75
vec3 tonemapFilmic(vec3 color) {
vec3 x = max(vec3(0.0), color - 0.004);
return (x * (6.2 * x + 0.5)) / (x * (6.2 * x + 1.7) + 0.06);
}
vec3 tonemapReinhard(vec3 color) {
return color / (color + vec3(1.0));
}
const float A = 0.15;
const float B = 0.50;
const float C = 0.10;
const float D = 0.20;
const float E = 0.02;
const float F = 0.30;
const float W = 11.2;
vec3 uncharted2Tonemap(vec3 x) {
return ((x * (A * x + C * B) + D * E) / (x * (A * x + B) + D * F)) - E / F;
}
vec3 tonemapUncharted2(vec3 color) {
float exposureBias = 2.0;
vec3 curr = uncharted2Tonemap(exposureBias * color);
vec3 whiteScale = 1.0 / uncharted2Tonemap(vec3(W));
return curr * whiteScale;
}
void main() {
// Blur
float depth = texture(gbuffer0, texCoord).a;
@ -137,5 +173,18 @@ void main() {
// Vignetting
col *= vignette();
// Exposure
const float aperture = 16;
const float shutterSpeed = 0.5;
const float iso = 100;
// col.rgb *= getExposure(aperture, shutterSpeed, iso);
// Tonemapping
// col.rgb = tonemapUncharted2(col.rgb);
// col.rgb = tonemapFilmic(col.rgb); // With gamma
// To gamma
col = vec4(pow(col.rgb, vec3(1.0 / 2.2)), col.a);
gl_FragColor = col;
}