Only use envmap for lighting
This commit is contained in:
@@ -59,14 +59,3 @@ function const_data_create_skydome_data() {
|
||||
}
|
||||
g4_index_buffer_unlock(const_data_skydome_ib);
|
||||
}
|
||||
|
||||
let const_data_ltc_mat_tex: image_t = null;
|
||||
let const_data_ltc_mag_tex: image_t = null;
|
||||
function const_data_init_ltc() {
|
||||
// Real-Time Polygonal-Light Shading with Linearly Transformed Cosines
|
||||
// https://eheitzresearch.wordpress.com/415-2/
|
||||
let ltc_mat: buffer_t = data_get_blob("ltc_mat.arm");
|
||||
let ltc_mag: buffer_t = data_get_blob("ltc_mag.arm");
|
||||
const_data_ltc_mat_tex = image_from_bytes(armpack_decode(ltc_mat), 64, 64, tex_format_t.RGBA128);
|
||||
const_data_ltc_mag_tex = image_from_bytes(armpack_decode(ltc_mag), 64, 64, tex_format_t.R32);
|
||||
}
|
||||
|
||||
@@ -17,28 +17,6 @@ let uniforms_i32_links: (o: object_t, md: material_data_t, s: string)=>i32 = nul
|
||||
let uniforms_pos_unpack: f32 = 1.0;
|
||||
let uniforms_tex_unpack: f32 = 1.0;
|
||||
|
||||
let uniforms_light_size_x: f32 = 3.0;
|
||||
let uniforms_light_size_y: f32 = 0.005;
|
||||
let uniforms_light_strength: f32 = 1.0;
|
||||
let uniforms_light_world: mat4_t = mat4_create(
|
||||
0.9502051472663879,
|
||||
-0.19612328708171844,
|
||||
0.24216893315315247,
|
||||
0.7578424215316772,
|
||||
0.3094223141670227,
|
||||
0.6860249638557434,
|
||||
-0.658504068851471,
|
||||
-2.0724263191223145,
|
||||
-0.03698595613241196,
|
||||
0.7006464004516602,
|
||||
0.7125493884086609,
|
||||
1.9363592863082886,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1
|
||||
);
|
||||
|
||||
function uniforms_set_context_consts(context: shader_context_t, bind_params: string[]) {
|
||||
if (context.constants != null) {
|
||||
for (let i: i32 = 0; i < context.constants.length; ++i) {
|
||||
@@ -234,31 +212,7 @@ function uniforms_set_context_const(location: kinc_const_loc_t, c: shader_const_
|
||||
else if (c.type == "vec3") {
|
||||
let v: vec4_t = vec4_nan();
|
||||
|
||||
if (c.link == "_light_area0") {
|
||||
let sx: f32 = uniforms_light_size_x * uniforms_light_strength * 0.25;
|
||||
let sy: f32 = uniforms_light_size_y * uniforms_light_strength * 0.25;
|
||||
v = vec4_create(-sx, sy, 0.0);
|
||||
v = vec4_apply_mat(v, uniforms_light_world);
|
||||
}
|
||||
else if (c.link == "_light_area1") {
|
||||
let sx: f32 = uniforms_light_size_x * uniforms_light_strength * 0.25;
|
||||
let sy: f32 = uniforms_light_size_y * uniforms_light_strength * 0.25;
|
||||
v = vec4_create(sx, sy, 0.0);
|
||||
v = vec4_apply_mat(v, uniforms_light_world);
|
||||
}
|
||||
else if (c.link == "_light_area2") {
|
||||
let sx: f32 = uniforms_light_size_x * uniforms_light_strength * 0.25;
|
||||
let sy: f32 = uniforms_light_size_y * uniforms_light_strength * 0.25;
|
||||
v = vec4_create(sx, -sy, 0.0);
|
||||
v = vec4_apply_mat(v, uniforms_light_world);
|
||||
}
|
||||
else if (c.link == "_light_area3") {
|
||||
let sx: f32 = uniforms_light_size_x * uniforms_light_strength * 0.25;
|
||||
let sy: f32 = uniforms_light_size_y * uniforms_light_strength * 0.25;
|
||||
v = vec4_create(-sx, -sy, 0.0);
|
||||
v = vec4_apply_mat(v, uniforms_light_world);
|
||||
}
|
||||
else if (c.link == "_camera_pos") {
|
||||
if (c.link == "_camera_pos") {
|
||||
v = vec4_create(transform_world_x(camera.base.transform), transform_world_y(camera.base.transform), transform_world_z(camera.base.transform));
|
||||
}
|
||||
else if (c.link == "_camera_look") {
|
||||
|
||||
@@ -98,8 +98,6 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte
|
||||
if (context_raw.viewport_mode == viewport_mode_t.LIT && context_raw.render_mode == render_mode_t.FORWARD) {
|
||||
node_shader_add_uniform(frag, "sampler2D senvmap_brdf", "$brdf.k");
|
||||
node_shader_add_uniform(frag, "sampler2D senvmap_radiance", "_envmap_radiance");
|
||||
node_shader_add_uniform(frag, "sampler2D sltc_mat", "_ltc_mat");
|
||||
node_shader_add_uniform(frag, "sampler2D sltc_mag", "_ltc_mag");
|
||||
}
|
||||
|
||||
node_shader_add_shared_sampler(frag, "sampler2D texpaint");
|
||||
@@ -176,31 +174,12 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte
|
||||
node_shader_write(frag, "float envlod = roughness * float(envmap_num_mipmaps);");
|
||||
node_shader_add_function(frag, str_envmap_equirect);
|
||||
node_shader_write(frag, "vec3 prefiltered_color = textureLod(senvmap_radiance, envmap_equirect(wreflect, envmap_data.x), envlod).rgb;");
|
||||
node_shader_add_uniform(frag, "vec3 light_area0", "_light_area0");
|
||||
node_shader_add_uniform(frag, "vec3 light_area1", "_light_area1");
|
||||
node_shader_add_uniform(frag, "vec3 light_area2", "_light_area2");
|
||||
node_shader_add_uniform(frag, "vec3 light_area3", "_light_area3");
|
||||
node_shader_add_function(frag, str_ltc_evaluate);
|
||||
node_shader_write(frag, "const float LUT_SIZE = 64.0;");
|
||||
node_shader_write(frag, "const float LUT_SCALE = (LUT_SIZE - 1.0) / LUT_SIZE;");
|
||||
node_shader_write(frag, "const float LUT_BIAS = 0.5 / LUT_SIZE;");
|
||||
node_shader_write(frag, "float theta = acos(dotnv);");
|
||||
node_shader_write(frag, "vec2 tuv = vec2(roughness, theta / (0.5 * 3.14159265));");
|
||||
node_shader_write(frag, "tuv = tuv * LUT_SCALE + LUT_BIAS;");
|
||||
node_shader_write(frag, "vec4 t = textureLod(sltc_mat, tuv, 0.0);");
|
||||
node_shader_write(frag, "mat3 minv = mat3(vec3(1.0, 0.0, t.y), vec3(0.0, t.z, 0.0), vec3(t.w, 0.0, t.x));");
|
||||
node_shader_write(frag, "float ltcspec = ltc_evaluate(n, vvec, dotnv, wposition, minv, light_area0, light_area1, light_area2, light_area3);");
|
||||
node_shader_write(frag, "ltcspec *= textureLod(sltc_mag, tuv, 0.0).a;");
|
||||
node_shader_write(frag, "mat3 mident = mat3(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0);");
|
||||
node_shader_write(frag, "float ltcdiff = ltc_evaluate(n, vvec, dotnv, wposition, mident, light_area0, light_area1, light_area2, light_area3);");
|
||||
node_shader_write(frag, "vec3 direct = albedo * ltcdiff + ltcspec * 0.05;");
|
||||
|
||||
node_shader_add_uniform(frag, "vec4 shirr[7]", "_envmap_irradiance");
|
||||
node_shader_add_function(frag, str_sh_irradiance());
|
||||
node_shader_write(frag, "vec3 indirect = albedo * (sh_irradiance(vec3(n.x * envmap_data.z - n.y * envmap_data.y, n.x * envmap_data.y + n.y * envmap_data.z, n.z), shirr) / 3.14159265);");
|
||||
node_shader_write(frag, "indirect += prefiltered_color * (f0 * env_brdf.x + env_brdf.y) * 1.5;");
|
||||
node_shader_write(frag, "indirect *= envmap_data.w * occlusion;");
|
||||
node_shader_write(frag, "frag_color[1] = vec4(direct + indirect, 1.0);");
|
||||
node_shader_write(frag, "frag_color[1] = vec4(indirect, 1.0);");
|
||||
}
|
||||
else { // Deferred, Pathtraced
|
||||
node_shader_write(frag, "frag_color[1] = vec4(basecol, occlusion);");
|
||||
|
||||
@@ -3,6 +3,5 @@
|
||||
"action_rotate": "middle",
|
||||
"action_pan": "shift+middle",
|
||||
"action_zoom": "ctrl+middle",
|
||||
"rotate_light": "shift+right",
|
||||
"rotate_envmap": "ctrl+right"
|
||||
}
|
||||
|
||||
@@ -161,8 +161,6 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte
|
||||
texture_count += 4;
|
||||
node_shader_add_uniform(frag, "sampler2D senvmap_brdf", "$brdf.k");
|
||||
node_shader_add_uniform(frag, "sampler2D senvmap_radiance", "_envmap_radiance");
|
||||
node_shader_add_uniform(frag, "sampler2D sltc_mat", "_ltc_mat");
|
||||
node_shader_add_uniform(frag, "sampler2D sltc_mag", "_ltc_mag");
|
||||
}
|
||||
|
||||
// Get layers for this pass
|
||||
@@ -393,31 +391,12 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte
|
||||
node_shader_write(frag, "float envlod = roughness * float(envmap_num_mipmaps);");
|
||||
node_shader_add_function(frag, str_envmap_equirect);
|
||||
node_shader_write(frag, "vec3 prefiltered_color = textureLod(senvmap_radiance, envmap_equirect(wreflect, envmap_data.x), envlod).rgb;");
|
||||
node_shader_add_uniform(frag, "vec3 light_area0", "_light_area0");
|
||||
node_shader_add_uniform(frag, "vec3 light_area1", "_light_area1");
|
||||
node_shader_add_uniform(frag, "vec3 light_area2", "_light_area2");
|
||||
node_shader_add_uniform(frag, "vec3 light_area3", "_light_area3");
|
||||
node_shader_add_function(frag, str_ltc_evaluate);
|
||||
node_shader_write(frag, "const float LUT_SIZE = 64.0;");
|
||||
node_shader_write(frag, "const float LUT_SCALE = (LUT_SIZE - 1.0) / LUT_SIZE;");
|
||||
node_shader_write(frag, "const float LUT_BIAS = 0.5 / LUT_SIZE;");
|
||||
node_shader_write(frag, "float theta = acos(dotnv);");
|
||||
node_shader_write(frag, "vec2 tuv = vec2(roughness, theta / (0.5 * 3.14159265));");
|
||||
node_shader_write(frag, "tuv = tuv * LUT_SCALE + LUT_BIAS;");
|
||||
node_shader_write(frag, "vec4 t = textureLod(sltc_mat, tuv, 0.0);");
|
||||
node_shader_write(frag, "mat3 minv = mat3(vec3(1.0, 0.0, t.y), vec3(0.0, t.z, 0.0), vec3(t.w, 0.0, t.x));");
|
||||
node_shader_write(frag, "float ltcspec = ltc_evaluate(n, vvec, dotnv, wposition, minv, light_area0, light_area1, light_area2, light_area3);");
|
||||
node_shader_write(frag, "ltcspec *= textureLod(sltc_mag, tuv, 0.0).a;");
|
||||
node_shader_write(frag, "mat3 mident = mat3(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0);");
|
||||
node_shader_write(frag, "float ltcdiff = ltc_evaluate(n, vvec, dotnv, wposition, mident, light_area0, light_area1, light_area2, light_area3);");
|
||||
node_shader_write(frag, "vec3 direct = albedo * ltcdiff + ltcspec * 0.05;");
|
||||
|
||||
node_shader_add_uniform(frag, "vec4 shirr[7]", "_envmap_irradiance");
|
||||
node_shader_add_function(frag, str_sh_irradiance());
|
||||
node_shader_write(frag, "vec3 indirect = albedo * (sh_irradiance(vec3(n.x * envmap_data.z - n.y * envmap_data.y, n.x * envmap_data.y + n.y * envmap_data.z, n.z), shirr) / 3.14159265);");
|
||||
node_shader_write(frag, "indirect += prefiltered_color * (f0 * env_brdf.x + env_brdf.y) * 1.5;");
|
||||
node_shader_write(frag, "indirect *= envmap_data.w * occlusion;");
|
||||
node_shader_write(frag, "frag_color[1] = vec4(direct + indirect, 1.0);");
|
||||
node_shader_write(frag, "frag_color[1] = vec4(indirect, 1.0);");
|
||||
}
|
||||
else { // Deferred, Pathtraced
|
||||
if (make_material_emis_used) {
|
||||
|
||||
@@ -119,8 +119,6 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte
|
||||
texture_count += 4;
|
||||
node_shader_add_uniform(frag, "sampler2D senvmap_brdf", "$brdf.k");
|
||||
node_shader_add_uniform(frag, "sampler2D senvmap_radiance", "_envmap_radiance");
|
||||
node_shader_add_uniform(frag, "sampler2D sltc_mat", "_ltc_mat");
|
||||
node_shader_add_uniform(frag, "sampler2D sltc_mag", "_ltc_mag");
|
||||
}
|
||||
|
||||
// Get layers for this pass
|
||||
@@ -278,31 +276,12 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte
|
||||
node_shader_write(frag, "float envlod = roughness * float(envmap_num_mipmaps);");
|
||||
node_shader_add_function(frag, str_envmap_equirect);
|
||||
node_shader_write(frag, "vec3 prefiltered_color = textureLod(senvmap_radiance, envmap_equirect(wreflect, envmap_data.x), envlod).rgb;");
|
||||
node_shader_add_uniform(frag, "vec3 light_area0", "_light_area0");
|
||||
node_shader_add_uniform(frag, "vec3 light_area1", "_light_area1");
|
||||
node_shader_add_uniform(frag, "vec3 light_area2", "_light_area2");
|
||||
node_shader_add_uniform(frag, "vec3 light_area3", "_light_area3");
|
||||
node_shader_add_function(frag, str_ltc_evaluate);
|
||||
node_shader_write(frag, "const float LUT_SIZE = 64.0;");
|
||||
node_shader_write(frag, "const float LUT_SCALE = (LUT_SIZE - 1.0) / LUT_SIZE;");
|
||||
node_shader_write(frag, "const float LUT_BIAS = 0.5 / LUT_SIZE;");
|
||||
node_shader_write(frag, "float theta = acos(dotnv);");
|
||||
node_shader_write(frag, "vec2 tuv = vec2(roughness, theta / (0.5 * 3.14159265));");
|
||||
node_shader_write(frag, "tuv = tuv * LUT_SCALE + LUT_BIAS;");
|
||||
node_shader_write(frag, "vec4 t = textureLod(sltc_mat, tuv, 0.0);");
|
||||
node_shader_write(frag, "mat3 minv = mat3(vec3(1.0, 0.0, t.y), vec3(0.0, t.z, 0.0), vec3(t.w, 0.0, t.x));");
|
||||
node_shader_write(frag, "float ltcspec = ltc_evaluate(n, vvec, dotnv, wposition, minv, light_area0, light_area1, light_area2, light_area3);");
|
||||
node_shader_write(frag, "ltcspec *= textureLod(sltc_mag, tuv, 0.0).a;");
|
||||
node_shader_write(frag, "mat3 mident = mat3(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0);");
|
||||
node_shader_write(frag, "float ltcdiff = ltc_evaluate(n, vvec, dotnv, wposition, mident, light_area0, light_area1, light_area2, light_area3);");
|
||||
node_shader_write(frag, "vec3 direct = albedo * ltcdiff + ltcspec * 0.05;");
|
||||
|
||||
node_shader_add_uniform(frag, "vec4 shirr[7]", "_envmap_irradiance");
|
||||
node_shader_add_function(frag, str_sh_irradiance());
|
||||
node_shader_write(frag, "vec3 indirect = albedo * (sh_irradiance(vec3(n.x * envmap_data.z - n.y * envmap_data.y, n.x * envmap_data.y + n.y * envmap_data.z, n.z), shirr) / 3.14159265);");
|
||||
node_shader_write(frag, "indirect += prefiltered_color * (f0 * env_brdf.x + env_brdf.y) * 1.5;");
|
||||
node_shader_write(frag, "indirect *= envmap_data.w * occlusion;");
|
||||
node_shader_write(frag, "frag_color[1] = vec4(direct + indirect, 1.0);");
|
||||
node_shader_write(frag, "frag_color[1] = vec4(indirect, 1.0);");
|
||||
}
|
||||
else { // Deferred, Pathtraced
|
||||
if (make_material_emis_used) {
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -16,12 +16,6 @@ uniform sampler2D ssaotex;
|
||||
uniform vec2 camera_proj;
|
||||
uniform vec3 eye;
|
||||
uniform vec3 eye_look;
|
||||
uniform vec3 light_area0;
|
||||
uniform vec3 light_area1;
|
||||
uniform vec3 light_area2;
|
||||
uniform vec3 light_area3;
|
||||
uniform sampler2D sltc_mat;
|
||||
uniform sampler2D sltc_mag;
|
||||
|
||||
#include "std/gbuffer.glsl"
|
||||
#include "std/brdf.glsl"
|
||||
@@ -32,167 +26,6 @@ in vec2 tex_coord;
|
||||
in vec3 view_ray;
|
||||
out vec4 frag_color;
|
||||
|
||||
const float LUT_SIZE = 64.0;
|
||||
const float LUT_SCALE = (LUT_SIZE - 1.0) / LUT_SIZE;
|
||||
const float LUT_BIAS = 0.5 / LUT_SIZE;
|
||||
|
||||
float integrate_edge(vec3 v1, vec3 v2) {
|
||||
float cos_theta = dot(v1, v2);
|
||||
float theta = acos(cos_theta);
|
||||
float res = cross(v1, v2).z * ((theta > 0.001) ? theta / sin(theta) : 1.0);
|
||||
return res;
|
||||
}
|
||||
|
||||
float ltc_evaluate(vec3 N, vec3 V, float dotnv, vec3 P, mat3 Minv, vec3 points0, vec3 points1, vec3 points2, vec3 points3) {
|
||||
// Construct orthonormal basis around N
|
||||
vec3 T1, T2;
|
||||
T1 = normalize(V - N * dotnv);
|
||||
T2 = cross(N, T1);
|
||||
|
||||
// Rotate area light in (T1, T2, R) basis
|
||||
Minv = mul(transpose(mat3(T1, T2, N)), Minv);
|
||||
|
||||
// Polygon (allocate 5 vertices for clipping)
|
||||
vec3 L0 = mul((points0 - P), Minv);
|
||||
vec3 L1 = mul((points1 - P), Minv);
|
||||
vec3 L2 = mul((points2 - P), Minv);
|
||||
vec3 L3 = mul((points3 - P), Minv);
|
||||
vec3 L4 = vec3(0.0, 0.0, 0.0);
|
||||
|
||||
int n = 0;
|
||||
// Detect clipping config
|
||||
int config = 0;
|
||||
if (L0.z > 0.0) config += 1;
|
||||
if (L1.z > 0.0) config += 2;
|
||||
if (L2.z > 0.0) config += 4;
|
||||
if (L3.z > 0.0) config += 8;
|
||||
|
||||
// Clip
|
||||
if (config == 0) {
|
||||
// Clip all
|
||||
}
|
||||
else if (config == 1) { // V1 clip V2 V3 V4
|
||||
n = 3;
|
||||
L1 = -L1.z * L0 + L0.z * L1;
|
||||
L2 = -L3.z * L0 + L0.z * L3;
|
||||
}
|
||||
else if (config == 2) { // V2 clip V1 V3 V4
|
||||
n = 3;
|
||||
L0 = -L0.z * L1 + L1.z * L0;
|
||||
L2 = -L2.z * L1 + L1.z * L2;
|
||||
}
|
||||
else if (config == 3) { // V1 V2 clip V3 V4
|
||||
n = 4;
|
||||
L2 = -L2.z * L1 + L1.z * L2;
|
||||
L3 = -L3.z * L0 + L0.z * L3;
|
||||
}
|
||||
else if (config == 4) { // V3 clip V1 V2 V4
|
||||
n = 3;
|
||||
L0 = -L3.z * L2 + L2.z * L3;
|
||||
L1 = -L1.z * L2 + L2.z * L1;
|
||||
}
|
||||
else if (config == 5) { // V1 V3 clip V2 V4) impossible
|
||||
n = 0;
|
||||
}
|
||||
else if (config == 6) { // V2 V3 clip V1 V4
|
||||
n = 4;
|
||||
L0 = -L0.z * L1 + L1.z * L0;
|
||||
L3 = -L3.z * L2 + L2.z * L3;
|
||||
}
|
||||
else if (config == 7) { // V1 V2 V3 clip V4
|
||||
n = 5;
|
||||
L4 = -L3.z * L0 + L0.z * L3;
|
||||
L3 = -L3.z * L2 + L2.z * L3;
|
||||
}
|
||||
else if (config == 8) { // V4 clip V1 V2 V3
|
||||
n = 3;
|
||||
L0 = -L0.z * L3 + L3.z * L0;
|
||||
L1 = -L2.z * L3 + L3.z * L2;
|
||||
L2 = L3;
|
||||
}
|
||||
else if (config == 9) { // V1 V4 clip V2 V3
|
||||
n = 4;
|
||||
L1 = -L1.z * L0 + L0.z * L1;
|
||||
L2 = -L2.z * L3 + L3.z * L2;
|
||||
}
|
||||
else if (config == 10) { // V2 V4 clip V1 V3) impossible
|
||||
n = 0;
|
||||
}
|
||||
else if (config == 11) { // V1 V2 V4 clip V3
|
||||
n = 5;
|
||||
L4 = L3;
|
||||
L3 = -L2.z * L3 + L3.z * L2;
|
||||
L2 = -L2.z * L1 + L1.z * L2;
|
||||
}
|
||||
else if (config == 12) { // V3 V4 clip V1 V2
|
||||
n = 4;
|
||||
L1 = -L1.z * L2 + L2.z * L1;
|
||||
L0 = -L0.z * L3 + L3.z * L0;
|
||||
}
|
||||
else if (config == 13) { // V1 V3 V4 clip V2
|
||||
n = 5;
|
||||
L4 = L3;
|
||||
L3 = L2;
|
||||
L2 = -L1.z * L2 + L2.z * L1;
|
||||
L1 = -L1.z * L0 + L0.z * L1;
|
||||
}
|
||||
else if (config == 14) { // V2 V3 V4 clip V1
|
||||
n = 5;
|
||||
L4 = -L0.z * L3 + L3.z * L0;
|
||||
L0 = -L0.z * L1 + L1.z * L0;
|
||||
}
|
||||
else if (config == 15) { // V1 V2 V3 V4
|
||||
n = 4;
|
||||
}
|
||||
|
||||
if (n == 0) return 0.0;
|
||||
if (n == 3) L3 = L0;
|
||||
if (n == 4) L4 = L0;
|
||||
|
||||
// Project onto sphere
|
||||
L0 = normalize(L0);
|
||||
L1 = normalize(L1);
|
||||
L2 = normalize(L2);
|
||||
L3 = normalize(L3);
|
||||
L4 = normalize(L4);
|
||||
|
||||
// Integrate
|
||||
float sum = 0.0;
|
||||
|
||||
sum += integrate_edge(L0, L1);
|
||||
sum += integrate_edge(L1, L2);
|
||||
sum += integrate_edge(L2, L3);
|
||||
|
||||
if (n >= 4) sum += integrate_edge(L3, L4);
|
||||
if (n == 5) sum += integrate_edge(L4, L0);
|
||||
|
||||
return max(0.0, -sum);
|
||||
}
|
||||
|
||||
vec3 sample_light(const vec3 p, const vec3 n, const vec3 v, const float dotnv,
|
||||
const vec3 albedo, const float rough, const vec3 f0, const float occ
|
||||
) {
|
||||
float theta = acos(dotnv);
|
||||
vec2 tuv = vec2(rough, theta / (0.5 * PI));
|
||||
tuv = tuv * LUT_SCALE + LUT_BIAS;
|
||||
vec4 t = textureLod(sltc_mat, tuv, 0.0);
|
||||
mat3 inv = mat3(
|
||||
vec3(1.0, 0.0, t.y),
|
||||
vec3(0.0, t.z, 0.0),
|
||||
vec3(t.w, 0.0, t.x));
|
||||
float ltcspec = ltc_evaluate(n, v, dotnv, p, inv, light_area0, light_area1, light_area2, light_area3);
|
||||
ltcspec *= textureLod(sltc_mag, tuv, 0.0).a;
|
||||
|
||||
mat3 m1 = mat3(
|
||||
vec3(1.0, 0.0, 0.0),
|
||||
vec3(0.0, 1.0, 0.0),
|
||||
vec3(0.0, 0.0, 1.0));
|
||||
float ltcdiff = ltc_evaluate(n, v, dotnv, p, m1, light_area0, light_area1, light_area2, light_area3);
|
||||
vec3 direct = albedo * ltcdiff + ltcspec * 0.05;
|
||||
direct *= vec3(1000.0, 1000.0, 1000.0);
|
||||
return direct;
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec4 g0 = textureLod(gbuffer0, tex_coord, 0.0); // Normal.xy, roughness, metallic/matid
|
||||
|
||||
@@ -242,6 +75,5 @@ void main() {
|
||||
albedo = vec3(0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
frag_color.rgb += sample_light(p, n, v, dotnv, albedo, roughness, f0, occ);
|
||||
frag_color.a = 1.0; // Mark as opaque
|
||||
}
|
||||
|
||||
@@ -49,7 +49,6 @@ function camera_update() {
|
||||
operator_shortcut(map_get(config_keymap, "action_zoom"), shortcut_type_t.STARTED) ||
|
||||
operator_shortcut(map_get(config_keymap, "action_pan"), shortcut_type_t.STARTED) ||
|
||||
operator_shortcut(map_get(config_keymap, "rotate_envmap"), shortcut_type_t.STARTED) ||
|
||||
operator_shortcut(map_get(config_keymap, "rotate_light"), shortcut_type_t.STARTED) ||
|
||||
(mouse_started("right") && !modif) ||
|
||||
(mouse_started("middle") && !modif) ||
|
||||
(mouse_wheel_delta != 0 && !modif_key)) {
|
||||
@@ -59,7 +58,6 @@ function camera_update() {
|
||||
!operator_shortcut(map_get(config_keymap, "action_zoom"), shortcut_type_t.DOWN) &&
|
||||
!operator_shortcut(map_get(config_keymap, "action_pan"), shortcut_type_t.DOWN) &&
|
||||
!operator_shortcut(map_get(config_keymap, "rotate_envmap"), shortcut_type_t.DOWN) &&
|
||||
!operator_shortcut(map_get(config_keymap, "rotate_light"), shortcut_type_t.DOWN) &&
|
||||
!(mouse_down("right") && !modif) &&
|
||||
!(mouse_down("middle") && !modif) &&
|
||||
(mouse_wheel_delta == 0 && !modif_key)) {
|
||||
@@ -174,15 +172,6 @@ function camera_update() {
|
||||
transform_rotate(camera.base.transform, camera_object_right(camera), -mouse_movement_y / 200 * config_raw.camera_rotation_speed);
|
||||
}
|
||||
|
||||
if (operator_shortcut(map_get(config_keymap, "rotate_light"), shortcut_type_t.DOWN)) {
|
||||
camera_redraws = 2;
|
||||
let pi2: f32 = math_pi() * 2.0;
|
||||
let mx: f32 = mouse_movement_x / 100;
|
||||
context_raw.light_angle = math_fmod(context_raw.light_angle + math_fmod(mx, pi2) + pi2, pi2);
|
||||
let m: mat4_t = mat4_rot_z(mx);
|
||||
uniforms_light_world = mat4_mult_mat(uniforms_light_world, m);
|
||||
}
|
||||
|
||||
if (operator_shortcut(map_get(config_keymap, "rotate_envmap"), shortcut_type_t.DOWN)) {
|
||||
camera_redraws = 2;
|
||||
context_raw.envmap_angle -= mouse_movement_x / 100;
|
||||
|
||||
@@ -33,7 +33,6 @@ function keymap_get_default(): map_t<string, string> {
|
||||
map_set(keymap, "action_rotate", "alt+left");
|
||||
map_set(keymap, "action_pan", "alt+middle");
|
||||
map_set(keymap, "action_zoom", "alt+right");
|
||||
map_set(keymap, "rotate_light", "shift+middle");
|
||||
map_set(keymap, "rotate_envmap", "ctrl+middle");
|
||||
map_set(keymap, "set_clone_source", "alt");
|
||||
map_set(keymap, "stencil_transform", "ctrl");
|
||||
|
||||
@@ -367,116 +367,6 @@ vec2 envmap_equirect(const vec3 normal, const float angle) { \
|
||||
} \
|
||||
";
|
||||
|
||||
// Linearly Transformed Cosines
|
||||
// https://eheitzresearch.wordpress.com/415-2/
|
||||
let str_ltc_evaluate: string = " \
|
||||
float integrate_edge(vec3 v1, vec3 v2) { \
|
||||
float cos_theta = dot(v1, v2); \
|
||||
float theta = acos(cos_theta); \
|
||||
float res = cross(v1, v2).z * ((theta > 0.001) ? theta / sin(theta) : 1.0); \
|
||||
return res; \
|
||||
} \
|
||||
float ltc_evaluate(vec3 N, vec3 V, float dotnv, vec3 P, mat3 Minv, vec3 points0, vec3 points1, vec3 points2, vec3 points3) { \
|
||||
vec3 T1 = normalize(V - N * dotnv); \
|
||||
vec3 T2 = cross(N, T1); \
|
||||
Minv = mul(transpose(mat3(T1, T2, N)), Minv); \
|
||||
vec3 L0 = mul((points0 - P), Minv); \
|
||||
vec3 L1 = mul((points1 - P), Minv); \
|
||||
vec3 L2 = mul((points2 - P), Minv); \
|
||||
vec3 L3 = mul((points3 - P), Minv); \
|
||||
vec3 L4 = vec3(0.0, 0.0, 0.0); \
|
||||
int n = 0; \
|
||||
int config = 0; \
|
||||
if (L0.z > 0.0) config += 1; \
|
||||
if (L1.z > 0.0) config += 2; \
|
||||
if (L2.z > 0.0) config += 4; \
|
||||
if (L3.z > 0.0) config += 8; \
|
||||
if (config == 0) {} \
|
||||
else if (config == 1) { \
|
||||
n = 3; \
|
||||
L1 = -L1.z * L0 + L0.z * L1; \
|
||||
L2 = -L3.z * L0 + L0.z * L3; \
|
||||
} \
|
||||
else if (config == 2) { \
|
||||
n = 3; \
|
||||
L0 = -L0.z * L1 + L1.z * L0; \
|
||||
L2 = -L2.z * L1 + L1.z * L2; \
|
||||
} \
|
||||
else if (config == 3) { \
|
||||
n = 4; \
|
||||
L2 = -L2.z * L1 + L1.z * L2; \
|
||||
L3 = -L3.z * L0 + L0.z * L3; \
|
||||
} \
|
||||
else if (config == 4) { \
|
||||
n = 3; \
|
||||
L0 = -L3.z * L2 + L2.z * L3; \
|
||||
L1 = -L1.z * L2 + L2.z * L1; \
|
||||
} \
|
||||
else if (config == 5) { n = 0; } \
|
||||
else if (config == 6) { \
|
||||
n = 4; \
|
||||
L0 = -L0.z * L1 + L1.z * L0; \
|
||||
L3 = -L3.z * L2 + L2.z * L3; \
|
||||
} \
|
||||
else if (config == 7) { \
|
||||
n = 5; \
|
||||
L4 = -L3.z * L0 + L0.z * L3; \
|
||||
L3 = -L3.z * L2 + L2.z * L3; \
|
||||
} \
|
||||
else if (config == 8) { \
|
||||
n = 3; \
|
||||
L0 = -L0.z * L3 + L3.z * L0; \
|
||||
L1 = -L2.z * L3 + L3.z * L2; \
|
||||
L2 = L3; \
|
||||
} \
|
||||
else if (config == 9) { \
|
||||
n = 4; \
|
||||
L1 = -L1.z * L0 + L0.z * L1; \
|
||||
L2 = -L2.z * L3 + L3.z * L2; \
|
||||
} \
|
||||
else if (config == 10) { n = 0; } \
|
||||
else if (config == 11) { \
|
||||
n = 5; \
|
||||
L4 = L3; \
|
||||
L3 = -L2.z * L3 + L3.z * L2; \
|
||||
L2 = -L2.z * L1 + L1.z * L2; \
|
||||
} \
|
||||
else if (config == 12) { \
|
||||
n = 4; \
|
||||
L1 = -L1.z * L2 + L2.z * L1; \
|
||||
L0 = -L0.z * L3 + L3.z * L0; \
|
||||
} \
|
||||
else if (config == 13) { \
|
||||
n = 5; \
|
||||
L4 = L3; \
|
||||
L3 = L2; \
|
||||
L2 = -L1.z * L2 + L2.z * L1; \
|
||||
L1 = -L1.z * L0 + L0.z * L1; \
|
||||
} \
|
||||
else if (config == 14) { \
|
||||
n = 5; \
|
||||
L4 = -L0.z * L3 + L3.z * L0; \
|
||||
L0 = -L0.z * L1 + L1.z * L0; \
|
||||
} \
|
||||
else if (config == 15) { n = 4; } \
|
||||
if (n == 0) return 0.0; \
|
||||
if (n == 3) L3 = L0; \
|
||||
if (n == 4) L4 = L0; \
|
||||
L0 = normalize(L0); \
|
||||
L1 = normalize(L1); \
|
||||
L2 = normalize(L2); \
|
||||
L3 = normalize(L3); \
|
||||
L4 = normalize(L4); \
|
||||
float sum = 0.0; \
|
||||
sum += integrate_edge(L0, L1); \
|
||||
sum += integrate_edge(L1, L2); \
|
||||
sum += integrate_edge(L2, L3); \
|
||||
if (n >= 4) sum += integrate_edge(L3, L4); \
|
||||
if (n == 5) sum += integrate_edge(L4, L0); \
|
||||
return max(0.0, -sum); \
|
||||
} \
|
||||
";
|
||||
|
||||
let str_get_pos_nor_from_depth: string = " \
|
||||
vec3 get_pos_from_depth(vec2 uv, mat4 invVP, textureArg(gbufferD)) { \n\
|
||||
#ifdef GLSL \n\
|
||||
|
||||
@@ -196,46 +196,6 @@ function ui_menu_render() {
|
||||
context_raw.ddirty = 2;
|
||||
}
|
||||
|
||||
let lhandle: ui_handle_t = ui_handle(__ID__);
|
||||
lhandle.value = uniforms_light_strength;
|
||||
lhandle.value = math_floor(lhandle.value * 100) / 100;
|
||||
ui_menu_align(ui);
|
||||
uniforms_light_strength = ui_slider(lhandle, tr("Light"), 0.0, 4.0, true);
|
||||
if (lhandle.changed) {
|
||||
context_raw.ddirty = 2;
|
||||
}
|
||||
|
||||
let lahandle: ui_handle_t = ui_handle(__ID__);
|
||||
lahandle.value = context_raw.light_angle / math_pi() * 180;
|
||||
ui_menu_align(ui);
|
||||
let new_angle: f32 = ui_slider(lahandle, tr("Light Angle"), 0.0, 360.0, true, 1) / 180 * math_pi();
|
||||
if (ui.is_hovered) {
|
||||
let vars: map_t<string, string> = map_create();
|
||||
map_set(vars, "shortcut", map_get(config_keymap, "rotate_light"));
|
||||
ui_tooltip(tr("{shortcut} and move mouse", vars));
|
||||
}
|
||||
let ldiff: f32 = new_angle - context_raw.light_angle;
|
||||
if (math_abs(ldiff) > 0.005) {
|
||||
if (new_angle < 0) {
|
||||
new_angle += (math_floor(-new_angle / (2 * math_pi())) + 1) * 2 * math_pi();
|
||||
}
|
||||
else if (new_angle > 2 * math_pi()) {
|
||||
new_angle -= math_floor(new_angle / (2 * math_pi())) * 2 * math_pi();
|
||||
}
|
||||
context_raw.light_angle = new_angle;
|
||||
let m: mat4_t = mat4_rot_z(ldiff);
|
||||
uniforms_light_world = mat4_mult_mat(uniforms_light_world, m);
|
||||
context_raw.ddirty = 2;
|
||||
}
|
||||
|
||||
let sxhandle: ui_handle_t = ui_handle(__ID__);
|
||||
sxhandle.value = uniforms_light_size_x;
|
||||
ui_menu_align(ui);
|
||||
uniforms_light_size_x = ui_slider(sxhandle, tr("Light Size"), 0.0, 4.0, true);
|
||||
if (sxhandle.changed) {
|
||||
context_raw.ddirty = 2;
|
||||
}
|
||||
|
||||
///if (is_paint || is_sculpt)
|
||||
let split_view_handle: ui_handle_t = ui_handle(__ID__);
|
||||
if (split_view_handle.init) {
|
||||
|
||||
@@ -329,18 +329,6 @@ function uniforms_ext_tex_link(object: object_t, mat: material_data_t, link: str
|
||||
let rt: render_target_t = map_get(render_path_render_targets, "texpaint_pack_undo" + i);
|
||||
return rt._image;
|
||||
}
|
||||
else if (link == "_ltc_mat") {
|
||||
if (const_data_ltc_mat_tex == null) {
|
||||
const_data_init_ltc();
|
||||
}
|
||||
return const_data_ltc_mat_tex;
|
||||
}
|
||||
else if (link == "_ltc_mag") {
|
||||
if (const_data_ltc_mag_tex == null) {
|
||||
const_data_init_ltc();
|
||||
}
|
||||
return const_data_ltc_mag_tex;
|
||||
}
|
||||
else if (link == "_texcolorid") {
|
||||
if (project_assets.length == 0) {
|
||||
let rt: render_target_t = map_get(render_path_render_targets, "empty_white");
|
||||
|
||||
@@ -31,10 +31,6 @@ function util_render_make_material_preview() {
|
||||
scene_camera.data.fov = 0.92;
|
||||
viewport_update_camera_type(camera_type_t.PERSPECTIVE);
|
||||
|
||||
|
||||
let _light_strength: f32 = uniforms_light_strength;
|
||||
uniforms_light_strength = 0;
|
||||
|
||||
let probe: world_data_t = scene_world;
|
||||
let _probe_strength: f32 = probe.strength;
|
||||
probe.strength = 7;
|
||||
@@ -73,7 +69,6 @@ function util_render_make_material_preview() {
|
||||
camera_object_build_proj(scene_camera);
|
||||
camera_object_build_mat(scene_camera);
|
||||
|
||||
uniforms_light_strength = _light_strength;
|
||||
probe.strength = _probe_strength;
|
||||
context_raw.envmap_angle = _envmap_angle;
|
||||
context_raw.brush_scale = _brush_scale;
|
||||
@@ -110,8 +105,6 @@ function util_render_make_decal_preview() {
|
||||
let saved_fov: f32 = scene_camera.data.fov;
|
||||
scene_camera.data.fov = 0.92;
|
||||
viewport_update_camera_type(camera_type_t.PERSPECTIVE);
|
||||
let _light_strength: f32 = uniforms_light_strength;
|
||||
uniforms_light_strength = 0.0;
|
||||
scene_world._.envmap = context_raw.preview_envmap;
|
||||
|
||||
// No resize
|
||||
@@ -141,8 +134,6 @@ function util_render_make_decal_preview() {
|
||||
camera_object_build_proj(scene_camera);
|
||||
camera_object_build_mat(scene_camera);
|
||||
|
||||
uniforms_light_strength = _light_strength;
|
||||
|
||||
scene_world._.envmap = context_raw.show_envmap ? context_raw.saved_envmap : context_raw.empty_envmap;
|
||||
|
||||
make_material_parse_mesh_material();
|
||||
|
||||
@@ -79,7 +79,6 @@ function viewport_update_camera_type(camera_type: i32) {
|
||||
let cam: camera_object_t = scene_cameras[0];
|
||||
if (camera_type == camera_type_t.PERSPECTIVE) {
|
||||
cam.data.ortho = null;
|
||||
uniforms_light_strength = 1.0;
|
||||
}
|
||||
else {
|
||||
let f32a: f32_array_t = f32_array_create(4);
|
||||
@@ -89,7 +88,6 @@ function viewport_update_camera_type(camera_type: i32) {
|
||||
f32a[2] = -2 * f * (app_h() / app_w());
|
||||
f32a[3] = 2 * f * (app_h() / app_w());
|
||||
cam.data.ortho = f32a;
|
||||
uniforms_light_strength = 0.0;
|
||||
}
|
||||
camera_object_build_proj(cam);
|
||||
context_raw.ddirty = 2;
|
||||
|
||||
Reference in New Issue
Block a user