Compositor fixes

This commit is contained in:
luboslenco
2025-09-23 12:24:43 +02:00
parent a7ed646de6
commit 8bdbe10de7
8 changed files with 24 additions and 28 deletions
Binary file not shown.
+4 -1
View File
@@ -3,6 +3,7 @@
const constants: {
vignette_strength: float;
grain_strength: float;
tonemap_strength: float; // 0.0 or 1.0
};
#[set(everything)]
@@ -49,6 +50,7 @@ fun compositor_pass_frag(input: vert_out): float4 {
var g: float = (((x % 13.0) + 1.0) * ((x % 123.0) + 1.0) % 0.01) - 0.005;
color.rgb = color.rgb + (float3(g, g, g) * constants.grain_strength);
// Vignette
color.rgb = color.rgb * ((1.0 - constants.vignette_strength) + constants.vignette_strength * pow(16.0 * input.tex.x * input.tex.y * (1.0 - input.tex.x) * (1.0 - input.tex.y), 0.2));
// Auto exposure
@@ -56,7 +58,8 @@ fun compositor_pass_frag(input: vert_out): float4 {
// var expo: float = 2.0 - clamp(length(sample_lod(histogram, sampler_linear, float2(0.5, 0.5), 0.0).rgb), 0.0, 1.0);
// color.rgb *= pow(expo, auto_exposure_strength * 2.0);
color.rgb = tonemap_filmic(color.rgb); // With gamma
// Tonemap with gamma
color.rgb = lerp3(color.rgb, tonemap_filmic(color.rgb), constants.tonemap_strength);
return color;
}
+15 -1
View File
@@ -2,7 +2,7 @@
#[set(everything)]
const constants: {
SMVP: float4x4;
envmap_data_world: float4; // angle, empty, empty, strength
envmap_data_world: float4; // angle, tonemap_strength, empty, strength
};
#[set(everything)]
@@ -37,10 +37,24 @@ fun envmap_equirect(normal: float3, angle: float): float2 {
return float2(theta / PI2, phi / PI);
}
fun tonemap_filmic(color: float3): float3 {
// Based on Filmic Tonemapping Operators http://filmicgames.com/archives/75
// var x: float3 = max(float3(0.0, 0.0, 0.0), color - 0.004);
var x: float3;
x.x = max(0.0, color.x - 0.004);
x.y = max(0.0, color.y - 0.004);
x.z = max(0.0, color.z - 0.004);
return (x * (x * 6.2 + 0.5)) / (x * (x * 6.2 + 1.7) + 0.06);
}
fun world_pass_frag(input: vert_out): float4 {
var n: float3 = normalize(input.nor);
var color: float4;
color.rgb = sample(envmap, sampler_linear, envmap_equirect(-n, constants.envmap_data_world.x)).rgb * constants.envmap_data_world.w;
// Tonemap with gamma
color.rgb = lerp3(color.rgb, tonemap_filmic(color.rgb), constants.envmap_data_world.y);
color.a = 0.0; // Mark as non-opaque
return color;
}
-5
View File
@@ -526,11 +526,6 @@ function box_preferences_show() {
context_raw.hsupersample.position = config_get_super_sample_quality(config_raw.rp_supersample);
}
context_raw.hvxao = ui_handle(__ID__);
if (context_raw.hvxao.init) {
context_raw.hvxao.selected = config_raw.rp_gi;
}
if (ui_tab(box_preferences_htab, tr("Viewport"), true)) {
let mode_handle: ui_handle_t = ui_handle(__ID__);
-4
View File
@@ -55,7 +55,6 @@ function config_save() {
json_encode_f32("rp_supersample", config_raw.rp_supersample);
json_encode_bool("rp_ssao", config_raw.rp_ssao);
json_encode_bool("rp_bloom", config_raw.rp_bloom);
json_encode_bool("rp_gi", config_raw.rp_gi);
json_encode_f32("rp_vignette", config_raw.rp_vignette);
json_encode_f32("rp_grain", config_raw.rp_grain);
json_encode_string("version", config_raw.version);
@@ -135,7 +134,6 @@ function config_init() {
config_raw.window_vsync = true;
config_raw.window_frequency = sys_display_frequency();
config_raw.rp_bloom = false;
config_raw.rp_gi = false;
config_raw.rp_vignette = 0.2;
config_raw.rp_grain = 0.09;
///if (arm_android || arm_ios)
@@ -299,7 +297,6 @@ function config_import_from(from: config_t) {
function config_apply() {
config_raw.rp_ssao = context_raw.hssao.selected;
config_raw.rp_bloom = context_raw.hbloom.selected;
config_raw.rp_gi = context_raw.hvxao.selected;
config_raw.rp_supersample = config_get_super_sample_size(context_raw.hsupersample.position);
config_save();
context_raw.ddirty = 2;
@@ -443,7 +440,6 @@ type config_t = {
rp_supersample?: f32;
rp_ssao?: bool;
rp_bloom?: bool;
rp_gi?: bool;
rp_vignette?: f32;
rp_grain?: f32;
// Application
-7
View File
@@ -83,10 +83,6 @@ type context_t = {
hssao?: ui_handle_t;
hbloom?: ui_handle_t;
hsupersample?: ui_handle_t;
hvxao?: ui_handle_t;
vxao_ext?: f32;
vxao_offset?: f32;
vxao_aperture?: f32;
texture_export_path?: string;
last_status_position?: i32;
camera_controls?: camera_controls_t;
@@ -321,9 +317,6 @@ function context_create(): context_t {
c.brush_locked = false;
c.camera_type = camera_type_t.PERSPECTIVE;
c.cam_handle = ui_handle_create();
c.vxao_ext = 1.0;
c.vxao_offset = 1.5;
c.vxao_aperture = 1.2;
c.texture_export_path = "";
c.last_status_position = 0;
c.camera_controls = camera_controls_t.ORBIT;
-4
View File
@@ -513,10 +513,6 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte
node_shader_write_frag(kong, "output[1] = float4(1.0, 0.0, 1.0, 1.0);"); // Pink
}
if (context_raw.viewport_mode != viewport_mode_t.LIT && context_raw.viewport_mode != viewport_mode_t.PATH_TRACE) {
node_shader_write_frag(kong, "output[1].rgb = pow3(output[1].rgb, float3(2.2, 2.2, 2.2));"); ////
}
node_shader_write_frag(kong, "n = n / (abs(n.x) + abs(n.y) + abs(n.z));");
// node_shader_write_frag(kong, "n.xy = n.z >= 0.0 ? n.xy : octahedron_wrap(n.xy);");
node_shader_write_frag(kong, "if (n.z < 0.0) { n.xy = octahedron_wrap(n.xy); }");
+5 -6
View File
@@ -46,11 +46,9 @@ function uniforms_ext_f32_link(object: object_t, mat: material_data_t, link: str
else if (link == "_grain_strength") {
return config_raw.rp_grain;
}
else if (link == "_cone_offset") {
return context_raw.vxao_offset;
}
else if (link == "_cone_aperture") {
return context_raw.vxao_aperture;
else if (link == "_tonemap_strength") {
let tonemap: bool = context_raw.viewport_mode == viewport_mode_t.LIT || context_raw.viewport_mode == viewport_mode_t.PATH_TRACE;
return tonemap ? 1.0 : 0.0;
}
else if (link == "_bloom_sample_scale") {
return render_path_base_bloom_sample_scale;
@@ -271,7 +269,8 @@ function uniforms_ext_vec4_link(object: object_t, mat: material_data_t, link: st
return vec4_create(context_raw.envmap_angle, math_sin(-context_raw.envmap_angle), math_cos(-context_raw.envmap_angle), scene_world.strength * 1.5);
}
else if (link == "_envmap_data_world") {
return vec4_create(context_raw.envmap_angle, 0.0, 0.0, context_raw.show_envmap ? scene_world.strength : 1.0);
let tonemap: bool = context_raw.viewport_mode == viewport_mode_t.LIT || context_raw.viewport_mode == viewport_mode_t.PATH_TRACE;
return vec4_create(context_raw.envmap_angle, tonemap ? 0.0 : 1.0, 0.0, context_raw.show_envmap ? scene_world.strength : 1.0);
}
else if (link == "_stencil_transform") {
let v: vec4_t = vec4_create(context_raw.brush_stencil_x, context_raw.brush_stencil_y, context_raw.brush_stencil_scale, context_raw.brush_stencil_angle);