-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
1,010 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright 2023 Matthieu Bouron <[email protected]> | ||
* Copyright 2023 Nope Forge | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
const vec2 positions[] = vec2[](vec2(0.0, 0.0), vec2(2.0, 0.0), vec2(0.0, 2.0)); | ||
|
||
void main() | ||
{ | ||
vec2 uv = positions[ngl_vertex_index]; | ||
ngl_out_pos = vec4(uv * 2.0 - 1.0, 0.0, 1.0); | ||
tex_coord = uv; | ||
map_coord = uv; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright 2023-2024 Matthieu Bouron <[email protected]> | ||
* Copyright 2023-2024 Nope Forge | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
#include helper_srgb.glsl | ||
#include helper_blur.glsl | ||
|
||
const vec2 up = vec2(0.0, 1.0); // cos(PI/2), sin(PI/2) | ||
const vec2 down_left = vec2(0.8660254037844387, -0.5); // cos(-PI/6), sin(-PI/6) | ||
|
||
void main() | ||
{ | ||
float coc = texture(map, map_coord).r; | ||
int radius = int(float(blur.radius) * coc); | ||
|
||
float lod = 0.0; | ||
float scale = 1.0; | ||
int nb_samples = max(radius, 1); | ||
if (radius > blur.nb_samples) { | ||
scale = float(radius) / float(blur.nb_samples); | ||
nb_samples = blur.nb_samples; | ||
lod = log(scale); | ||
} | ||
|
||
vec4 color = ngli_blur_hexagonal(tex, tex_coord, map, map_coord, up, scale, lod, nb_samples); | ||
vec4 color2 = ngli_blur_hexagonal(tex, tex_coord, map, map_coord, down_left, scale, lod, nb_samples); | ||
|
||
ngl_out_color[0] = vec4(ngli_linear2srgb(color.rgb), color.a); | ||
ngl_out_color[1] = vec4(ngli_linear2srgb(color.rgb + color2.rgb), color.a + color2.a); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright 2023-2024 Matthieu Bouron <[email protected]> | ||
* Copyright 2023-2024 Nope Forge | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
#include helper_srgb.glsl | ||
#include helper_blur.glsl | ||
|
||
const vec2 down_left = vec2(0.8660254037844387, -0.5); // cos(-PI/6), sin(-PI/6) | ||
const vec2 down_right = vec2(-0.8660254037844387, -0.5); // cos(-5*PI/6), sin(-5*PI/6) | ||
|
||
/* | ||
* Hexagonal blur pass 2 (down-left, down-right + combine) | ||
* Adapted from WHITE, John, and BARRÉ-BRISEBOIS, Colin. More Performance! Five | ||
* Rendering Ideas From Battlefield 3 and Need For Speed: The Run, Advances in | ||
* Real-Time Rendering in Games, SIGGRAPH 2011: | ||
* https://www.slideshare.net/DICEStudio/five-rendering-ideas-from-battlefield-3-need-for-speed-the-run | ||
*/ | ||
void main() | ||
{ | ||
float coc = texture(map, map_coord).r; | ||
int radius = int(float(blur.radius) * coc); | ||
|
||
float lod = 0.0; | ||
float scale = 1.0; | ||
int nb_samples = max(radius, 1); | ||
if (radius > blur.nb_samples) { | ||
scale = float(radius) / float(blur.nb_samples); | ||
nb_samples = blur.nb_samples; | ||
lod = log(scale); | ||
} | ||
|
||
vec4 color = ngli_blur_hexagonal(tex0, tex_coord, map, map_coord, down_left, scale, lod, nb_samples); | ||
vec4 color2 = ngli_blur_hexagonal(tex1, tex_coord, map, map_coord, down_right, scale, lod, nb_samples); | ||
|
||
vec4 out_color = mix(color, color2, 0.5); | ||
ngl_out_color = vec4(ngli_linear2srgb(out_color.rgb), out_color.a); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright 2024 Matthieu Bouron <[email protected]> | ||
* Copyright 2024 Nope Forge | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
vec4 ngli_blur_hexagonal(sampler2D tex, vec2 tex_coord, sampler2D map, vec2 map_coord, vec2 direction, float scale, float lod, int nb_samples) | ||
{ | ||
nb_samples = max(nb_samples, 1); | ||
|
||
float use_coc = nb_samples > 1 ? 1.0 : 0.0; | ||
float offset = 0.5 * use_coc; | ||
|
||
vec2 tex_step = 1.0 / vec2(textureSize(tex, 0).xy); | ||
vec2 tex_direction = tex_step * direction; | ||
|
||
tex_coord += tex_direction * offset; | ||
tex_direction *= scale; | ||
|
||
vec4 color = vec4(0.0); | ||
float amount = 0.0; | ||
for (int i = 0; i < nb_samples; i++) { | ||
vec2 coord_offset = float(i) * tex_direction; | ||
vec4 value = textureLod(tex, tex_coord + coord_offset, lod); | ||
float coc = texture(map, map_coord + coord_offset).r; | ||
coc = mix(1.0, coc, use_coc); | ||
color += vec4(ngli_srgb2linear(value.rgb), value.a) * coc; | ||
amount += coc; | ||
} | ||
return color / amount; | ||
} |
Oops, something went wrong.