-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GenerateEnvironmentMapLight #9414
Changes from all commits
cd3e90f
f682078
186283b
a6ad58d
5608501
fd955e9
212ec68
22573cf
fe75bba
cf9b330
3ebbbdb
368272d
53feb96
a92ab3c
b0b23b3
676c207
2572f1c
71c15b1
d07c6ee
71fcf74
848e92e
bb74bce
00237ae
2015a60
8ce8ee6
3592760
331a020
34664dd
d3606d7
30c7805
24750c6
7dcd68f
dd8dac6
162bc35
eee005d
7574c51
d9c03cf
0521fee
39138fa
c516896
e2bc48d
9ed1dcb
0695579
74ab5ce
14ef095
08de4f9
98d92c1
8bb1b30
dcd03c8
e8ae28a
0b607e9
2dc5475
2ffeec6
9fe7a9d
4676948
82fe775
eaf17d3
719402d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,68 @@ | ||||||||
// Importance samples (Lambertian distribution) a skybox to produce a diffuse lighting cubemap | ||||||||
// Based on https://github.com/KhronosGroup/glTF-IBL-Sampler/blob/master/lib/source/shaders/filter.frag | ||||||||
|
||||||||
#import bevy_pbr::utils::PI | ||||||||
|
||||||||
@group(0) @binding(0) var skybox: texture_cube<f32>; | ||||||||
#ifdef RG11B10FLOAT | ||||||||
@group(0) @binding(1) var diffuse_map: texture_storage_2d_array<rg11b10float, write>; | ||||||||
#else | ||||||||
@group(0) @binding(1) var diffuse_map: texture_storage_2d_array<rgba16float, write>; | ||||||||
#endif | ||||||||
@group(0) @binding(2) var bilinear: sampler; | ||||||||
|
||||||||
fn get_dir(u: f32, v: f32, face: u32) -> vec3<f32> { | ||||||||
switch face { | ||||||||
case 0u: { return vec3(1.0, v, -u); } | ||||||||
case 1u: { return vec3(-1.0, v, u); } | ||||||||
case 2u: { return vec3(u, 1.0, -v); } | ||||||||
case 3u: { return vec3(u, -1.0, v); } | ||||||||
case 4u: { return vec3(u, v, 1.0); } | ||||||||
default { return vec3(-u, v, -1.0); } | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
fn generate_tbn(normal: vec3<f32>) -> mat3x3<f32> { | ||||||||
var bitangent = vec3(0.0, 1.0, 0.0); | ||||||||
|
||||||||
let n_dot_up = dot(normal, bitangent); | ||||||||
if abs(n_dot_up) >= 0.9999999 { | ||||||||
bitangent = vec3(0.0, 0.0, sign(n_dot_up)); | ||||||||
} | ||||||||
|
||||||||
let tangent = normalize(cross(bitangent, normal)); | ||||||||
bitangent = cross(normal, tangent); | ||||||||
|
||||||||
return mat3x3(tangent, bitangent, normal); | ||||||||
} | ||||||||
|
||||||||
@compute | ||||||||
@workgroup_size(8, 8, 1) | ||||||||
fn main(@builtin(global_invocation_id) id: vec3<u32>) { | ||||||||
let u = (f32(id.x) * 2.0 + 1.0) / 64.0 - 1.0; | ||||||||
let v = -(f32(id.y) * 2.0 + 1.0) / 64.0 + 1.0; | ||||||||
|
||||||||
let normal = normalize(get_dir(u, v, id.z)); | ||||||||
|
||||||||
var color = vec3(0.0); | ||||||||
for (var sample_i = 0u; sample_i < 32u; sample_i++) { | ||||||||
// R2 sequence - http://extremelearning.com.au/unreasonable-effectiveness-of-quasirandom-sequences | ||||||||
let r = fract(0.5 + f32(sample_i) * vec2<f32>(0.75487766624669276005, 0.5698402909980532659114)); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Factor this out into a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's 1 line, I'm inclined not to 😅 |
||||||||
|
||||||||
let cos_theta = sqrt(1.0 - f32(r.y)); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
let sin_theta = sqrt(r.y); | ||||||||
let phi = 2.0 * PI * r.x; | ||||||||
|
||||||||
let local_space_direction = normalize(vec3( | ||||||||
sin_theta * cos(phi), | ||||||||
sin_theta * sin(phi), | ||||||||
cos_theta, | ||||||||
)); | ||||||||
let direction = generate_tbn(normal) * local_space_direction; | ||||||||
|
||||||||
color += textureSampleLevel(skybox, bilinear, direction, 0.0).rgb; | ||||||||
} | ||||||||
color /= 32.0; | ||||||||
|
||||||||
textureStore(diffuse_map, id.xy, id.z, vec4(color, 1.0)); | ||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Step 1/2 in generating a specular lighting cubemap from a skybox: Downsamples a skybox into multiple mips | ||
// Original source: https://www.activision.com/cdn/research/downsample_cubemap.txt | ||
|
||
// Copyright 2016 Activision Publishing, Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining | ||
// a copy of this software and associated documentation files (the "Software"), | ||
// to deal in the Software without restriction, including without limitation | ||
// the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
// and/or sell copies of the Software, and to permit persons to whom the Software | ||
// is furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
|
||
@group(0) @binding(0) var tex_hi_res: texture_cube<f32>; | ||
#ifdef RG11B10FLOAT | ||
@group(0) @binding(1) var tex_los_res: texture_storage_2d_array<rg11b10float, write>; | ||
#else | ||
@group(0) @binding(1) var tex_los_res: texture_storage_2d_array<rgba16float, write>; | ||
#endif | ||
@group(0) @binding(2) var bilinear: sampler; | ||
|
||
fn get_dir(u: f32, v: f32, face: u32) -> vec3<f32> { | ||
switch face { | ||
case 0u: { return vec3(1.0, v, -u); } | ||
case 1u: { return vec3(-1.0, v, u); } | ||
case 2u: { return vec3(u, 1.0, -v); } | ||
case 3u: { return vec3(u, -1.0, v); } | ||
case 4u: { return vec3(u, v, 1.0); } | ||
default { return vec3(-u, v, -1.0); } | ||
} | ||
} | ||
|
||
fn calc_weight(u: f32, v: f32) -> f32 { | ||
let val = u * u + v * v + 1.0; | ||
return val * sqrt(val); | ||
} | ||
|
||
@compute | ||
@workgroup_size(8, 8, 1) | ||
fn main(@builtin(global_invocation_id) id: vec3<u32>) { | ||
let res_lo = textureDimensions(tex_los_res).x; | ||
|
||
if all(vec2u(id.xy) < vec2u(res_lo)) { | ||
let inv_res_lo = 1.0 / f32(res_lo); | ||
|
||
let u0 = (f32(id.x) * 2.0 + 1.0 - 0.75) * inv_res_lo - 1.0; | ||
let u1 = (f32(id.x) * 2.0 + 1.0 + 0.75) * inv_res_lo - 1.0; | ||
|
||
let v0 = (f32(id.y) * 2.0 + 1.0 - 0.75) * -inv_res_lo + 1.0; | ||
let v1 = (f32(id.y) * 2.0 + 1.0 + 0.75) * -inv_res_lo + 1.0; | ||
|
||
var weights = vec4(calc_weight(u0, v0), calc_weight(u1, v0), calc_weight(u0, v1), calc_weight(u1, v1)); | ||
let wsum = 0.5 / dot(vec4(1.0), weights); | ||
weights = weights * wsum + 0.125; | ||
|
||
var color = textureSampleLevel(tex_hi_res, bilinear, get_dir(u0, v0, id.z), 0.0) * weights.x; | ||
color += textureSampleLevel(tex_hi_res, bilinear, get_dir(u1, v0, id.z), 0.0) * weights.y; | ||
color += textureSampleLevel(tex_hi_res, bilinear, get_dir(u0, v1, id.z), 0.0) * weights.z; | ||
color += textureSampleLevel(tex_hi_res, bilinear, get_dir(u1, v1, id.z), 0.0) * weights.w; | ||
|
||
textureStore(tex_los_res, id.xy, id.z, color); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,183 @@ | ||||||||
// Step 2/2 in generating a specular lighting cubemap from a skybox: Importance sample the GGX distribution based on the downsampled cubemap | ||||||||
// Original source: https://www.activision.com/cdn/research/filter_using_table_128.txt | ||||||||
|
||||||||
// Copyright 2016 Activision Publishing, Inc. | ||||||||
// | ||||||||
// Permission is hereby granted, free of charge, to any person obtaining | ||||||||
// a copy of this software and associated documentation files (the "Software"), | ||||||||
// to deal in the Software without restriction, including without limitation | ||||||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||||||||
// and/or sell copies of the Software, and to permit persons to whom the Software | ||||||||
// is furnished to do so, subject to the following conditions: | ||||||||
// | ||||||||
// The above copyright notice and this permission notice shall be included in all | ||||||||
// copies or substantial portions of the Software. | ||||||||
// | ||||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||||||||
// SOFTWARE. | ||||||||
|
||||||||
@group(0) @binding(0) var tex_in: texture_cube<f32>; | ||||||||
#ifdef RG11B10FLOAT | ||||||||
@group(0) @binding(1) var text_out0: texture_storage_2d_array<rg11b10float, write>; | ||||||||
@group(0) @binding(2) var text_out1: texture_storage_2d_array<rg11b10float, write>; | ||||||||
@group(0) @binding(3) var text_out2: texture_storage_2d_array<rg11b10float, write>; | ||||||||
@group(0) @binding(4) var text_out3: texture_storage_2d_array<rg11b10float, write>; | ||||||||
@group(0) @binding(5) var text_out4: texture_storage_2d_array<rg11b10float, write>; | ||||||||
@group(0) @binding(6) var text_out5: texture_storage_2d_array<rg11b10float, write>; | ||||||||
@group(0) @binding(7) var text_out6: texture_storage_2d_array<rg11b10float, write>; | ||||||||
#else | ||||||||
@group(0) @binding(1) var text_out0: texture_storage_2d_array<rgba16float, write>; | ||||||||
@group(0) @binding(2) var text_out1: texture_storage_2d_array<rgba16float, write>; | ||||||||
@group(0) @binding(3) var text_out2: texture_storage_2d_array<rgba16float, write>; | ||||||||
@group(0) @binding(4) var text_out3: texture_storage_2d_array<rgba16float, write>; | ||||||||
@group(0) @binding(5) var text_out4: texture_storage_2d_array<rgba16float, write>; | ||||||||
@group(0) @binding(6) var text_out5: texture_storage_2d_array<rgba16float, write>; | ||||||||
@group(0) @binding(7) var text_out6: texture_storage_2d_array<rgba16float, write>; | ||||||||
#endif | ||||||||
@group(0) @binding(8) var trilinear: sampler; | ||||||||
@group(0) @binding(9) var<uniform> coeffs: array<array<array<array<vec4<f32>, 24>, 3>, 5>, 7>; | ||||||||
|
||||||||
fn get_dir(u: f32, v: f32, face: u32) -> vec3<f32> { | ||||||||
switch face { | ||||||||
case 0u: { return vec3(1.0, v, -u); } | ||||||||
case 1u: { return vec3(-1.0, v, u); } | ||||||||
case 2u: { return vec3(u, 1.0, -v); } | ||||||||
case 3u: { return vec3(u, -1.0, v); } | ||||||||
case 4u: { return vec3(u, v, 1.0); } | ||||||||
default { return vec3(-u, v, -1.0); } | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
@compute | ||||||||
@workgroup_size(64, 1, 1) | ||||||||
fn main(@builtin(global_invocation_id) global_id: vec3<u32>) { | ||||||||
var id = global_id; | ||||||||
var level = 0u; | ||||||||
if id.x < 128u * 128u { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So if you went the other way (starting at the smallest mip level, which we will call level 0 in the below formula and going up) then you can calculate the minimum ID value for a level with Going the other way would also let you avoid hardcoding 128 in a few places. I did find a branchless way to calculate the level and texel within that level given the ID (with tricky use of leading zero count), but I think it's probably slower than linear/binary search given that branch divergence is likely to be low. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it has to do the biggest mip first for other reasons, maybe because all the mips after it depend on it. but wgsl workgroups are not guaranteed to run in any particular order so idk |
||||||||
level = 0u; | ||||||||
} else if id.x < 128u * 128u + 64u * 64u { | ||||||||
level = 1u; | ||||||||
id.x -= 128u * 128u; | ||||||||
} else if id.x < 128u * 128u + 64u * 64u + 32u * 32u { | ||||||||
level = 2u; | ||||||||
id.x -= 128u * 128u + 64u * 64u; | ||||||||
} else if id.x < 128u * 128u + 64u * 64u + 32u * 32u + 16u * 16u { | ||||||||
level = 3u; | ||||||||
id.x -= 128u * 128u + 64u * 64u + 32u * 32u; | ||||||||
} else if id.x < 128u * 128u + 64u * 64u + 32u * 32u + 16u * 16u + 8u * 8u { | ||||||||
level = 4u; | ||||||||
id.x -= 128u * 128u + 64u * 64u + 32u * 32u + 16u * 16u; | ||||||||
} else if id.x < 128u * 128u + 64u * 64u + 32u * 32u + 16u * 16u + 8u * 8u + 4u * 4u { | ||||||||
level = 5u; | ||||||||
id.x -= 128u * 128u + 64u * 64u + 32u * 32u + 16u * 16u + 8u * 8u; | ||||||||
} else if id.x < 128u * 128u + 64u * 64u + 32u * 32u + 16u * 16u + 8u * 8u + 4u * 4u + 2u * 2u { | ||||||||
level = 6u; | ||||||||
id.x -= 128u * 128u + 64u * 64u + 32u * 32u + 16u * 16u + 8u * 8u + 4u * 4u; | ||||||||
} else { | ||||||||
return; | ||||||||
} | ||||||||
|
||||||||
id.z = id.y; | ||||||||
let res = 128u >> level; | ||||||||
id.y = id.x / res; | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could save an integer division here with
Suggested change
|
||||||||
id.x -= id.y * res; | ||||||||
|
||||||||
let u = (f32(id.x) * 2.0 + 1.0) / f32(res) - 1.0; | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
let v = -(f32(id.y) * 2.0 + 1.0) / f32(res) + 1.0; | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you explain the intended mapping between There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure, it's what the original shader does though There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it maps to the centers of every other 2x2 texel patch, because the lower mip level must represent those texels as one larger one that covers the area of all 4 original ones. |
||||||||
|
||||||||
let dir = get_dir(u, v, id.z); | ||||||||
let frame_z = normalize(dir); | ||||||||
let adir = abs(dir); | ||||||||
|
||||||||
var color = vec4(0.0); | ||||||||
for (var axis = 0u; axis < 3u; axis++) { | ||||||||
let other_axis0 = 1u - (axis & 1u) - (axis >> 1u); | ||||||||
let other_axis1 = 2u - (axis >> 1u); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like if you're switching over |
||||||||
|
||||||||
let frame_weight = (max(adir[other_axis0], adir[other_axis1]) - 0.75) / 0.25; | ||||||||
if frame_weight > 0.0 { | ||||||||
var up_vector = vec3(0.0); | ||||||||
switch axis { | ||||||||
case 0u: { up_vector = vec3(1.0, 0.0, 0.0); } | ||||||||
case 1u: { up_vector = vec3(0.0, 1.0, 0.0); } | ||||||||
default { up_vector = vec3(0.0, 0.0, 1.0); } | ||||||||
} | ||||||||
let frame_x = normalize(cross(up_vector, frame_z)); | ||||||||
let frame_y = cross(frame_z, frame_x); | ||||||||
|
||||||||
var nx = dir[other_axis0]; | ||||||||
var ny = dir[other_axis1]; | ||||||||
let nz = adir[axis]; | ||||||||
|
||||||||
let nmax_xy = max(abs(ny), abs(nx)); | ||||||||
nx /= nmax_xy; | ||||||||
ny /= nmax_xy; | ||||||||
|
||||||||
var theta = 0.0; | ||||||||
if ny < nx { | ||||||||
if ny <= -0.999 { theta = nx; } else { theta = ny; } | ||||||||
} else { | ||||||||
if ny >= 0.999 { theta = -nx; } else { theta = -ny; } | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kind of wonder if 0.999 should be factored out into an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Eh, I'm just keeping it to match the original shader code |
||||||||
} | ||||||||
|
||||||||
var phi = 0.0; | ||||||||
if nz <= -0.999 { | ||||||||
phi = -nmax_xy; | ||||||||
} else if nz >= 0.999 { | ||||||||
phi = nmax_xy; | ||||||||
} else { | ||||||||
phi = nz; | ||||||||
} | ||||||||
let theta2 = theta * theta; | ||||||||
let phi2 = phi * phi; | ||||||||
|
||||||||
for (var i_super_tap = 0u; i_super_tap < 8u; i_super_tap++) { | ||||||||
let index = 8u * axis + i_super_tap; | ||||||||
var coeffs_dir0 = array(vec4(0.0), vec4(0.0), vec4(0.0)); | ||||||||
var coeffs_dir1 = array(vec4(0.0), vec4(0.0), vec4(0.0)); | ||||||||
var coeffs_dir2 = array(vec4(0.0), vec4(0.0), vec4(0.0)); | ||||||||
var coeffs_level = array(vec4(0.0), vec4(0.0), vec4(0.0)); | ||||||||
var coeffs_weight = array(vec4(0.0), vec4(0.0), vec4(0.0)); | ||||||||
|
||||||||
for (var i_coeff = 0u; i_coeff < 3u; i_coeff++) { | ||||||||
coeffs_dir0[i_coeff] = coeffs[level][0u][i_coeff][index]; | ||||||||
coeffs_dir1[i_coeff] = coeffs[level][1u][i_coeff][index]; | ||||||||
coeffs_dir2[i_coeff] = coeffs[level][2u][i_coeff][index]; | ||||||||
coeffs_level[i_coeff] = coeffs[level][3u][i_coeff][index]; | ||||||||
coeffs_weight[i_coeff] = coeffs[level][4u][i_coeff][index]; | ||||||||
} | ||||||||
|
||||||||
for (var i_sub_tap = 0u; i_sub_tap < 4u; i_sub_tap++) { | ||||||||
var sample_dir = frame_x * (coeffs_dir0[0u][i_sub_tap] + coeffs_dir0[1u][i_sub_tap] * theta2 + coeffs_dir0[2u][i_sub_tap] * phi2) + frame_y * (coeffs_dir1[0u][i_sub_tap] + coeffs_dir1[1u][i_sub_tap] * theta2 + coeffs_dir1[2u][i_sub_tap] * phi2) + frame_z * (coeffs_dir2[0u][i_sub_tap] + coeffs_dir2[1u][i_sub_tap] * theta2 + coeffs_dir2[2u][i_sub_tap] * phi2); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I know that would be a lot of refactoring so feel free to leave this to a followup. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might've been faster to not use the matrix ops, I'm inclined to leave it to match the original shader. |
||||||||
|
||||||||
var sample_level = coeffs_level[0u][i_sub_tap] + coeffs_level[1u][i_sub_tap] * theta2 + coeffs_level[2u][i_sub_tap] * phi2; | ||||||||
|
||||||||
var sample_weight = coeffs_weight[0u][i_sub_tap] + coeffs_weight[1u][i_sub_tap] * theta2 + coeffs_weight[2u][i_sub_tap] * phi2; | ||||||||
sample_weight *= frame_weight; | ||||||||
|
||||||||
sample_dir /= max(abs(sample_dir[0u]), max(abs(sample_dir[1u]), abs(sample_dir[2u]))); | ||||||||
JMS55 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
sample_level += 0.75 * log2(dot(sample_dir, sample_dir)); | ||||||||
JMS55 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
|
||||||||
color += vec4(textureSampleLevel(tex_in, trilinear, sample_dir, sample_level).rgb * sample_weight, sample_weight); | ||||||||
} | ||||||||
} | ||||||||
} | ||||||||
} | ||||||||
color /= color.a; | ||||||||
color = vec4(max(color.rgb, vec3(0.0)), 1.0); | ||||||||
|
||||||||
switch level { | ||||||||
case 0u: { textureStore(text_out0, id.xy, id.z, color); } | ||||||||
case 1u: { textureStore(text_out1, id.xy, id.z, color); } | ||||||||
case 2u: { textureStore(text_out2, id.xy, id.z, color); } | ||||||||
case 3u: { textureStore(text_out3, id.xy, id.z, color); } | ||||||||
case 4u: { textureStore(text_out4, id.xy, id.z, color); } | ||||||||
case 5u: { textureStore(text_out5, id.xy, id.z, color); } | ||||||||
default { textureStore(text_out6, id.xy, id.z, color); } | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you use a local texture variable and then factor out the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that's any cleaner, really |
||||||||
} | ||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two are flipped compared to https://github.com/KhronosGroup/glTF-IBL-Sampler/blob/master/lib/source/shaders/filter.frag, is that intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used the same get_dir function from https://www.activision.com/cdn/research/filter_using_table_128.txt that I used in the other shaders