You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-05 12:10:55 +00:00
Merge pull request #72075 from Maran23/extents-to-size
Replace Extents with Size in VoxelGI, ReflectionProbe, FogVolume, Decal and GPUParticles*3D
This commit is contained in:
@@ -37,7 +37,7 @@ layout(push_constant, std430) uniform Params {
|
||||
vec3 position;
|
||||
float pad;
|
||||
|
||||
vec3 extents;
|
||||
vec3 size;
|
||||
float pad2;
|
||||
|
||||
ivec3 corner;
|
||||
@@ -184,36 +184,37 @@ void main() {
|
||||
vec4 local_pos = params.transform * world;
|
||||
local_pos.xyz /= local_pos.w;
|
||||
|
||||
vec3 half_size = params.size / 2.0;
|
||||
float sdf = -1.0;
|
||||
if (params.shape == 0) {
|
||||
// Ellipsoid
|
||||
// https://www.shadertoy.com/view/tdS3DG
|
||||
float k0 = length(local_pos.xyz / params.extents);
|
||||
float k1 = length(local_pos.xyz / (params.extents * params.extents));
|
||||
float k0 = length(local_pos.xyz / half_size);
|
||||
float k1 = length(local_pos.xyz / (half_size * half_size));
|
||||
sdf = k0 * (k0 - 1.0) / k1;
|
||||
} else if (params.shape == 1) {
|
||||
// Cone
|
||||
// https://iquilezles.org/www/articles/distfunctions/distfunctions.htm
|
||||
|
||||
// Compute the cone angle automatically to fit within the volume's extents.
|
||||
float inv_height = 1.0 / max(0.001, params.extents.y);
|
||||
float radius = 1.0 / max(0.001, (min(params.extents.x, params.extents.z) * 0.5));
|
||||
// Compute the cone angle automatically to fit within the volume's size.
|
||||
float inv_height = 1.0 / max(0.001, half_size.y);
|
||||
float radius = 1.0 / max(0.001, (min(half_size.x, half_size.z) * 0.5));
|
||||
float hypotenuse = sqrt(radius * radius + inv_height * inv_height);
|
||||
float rsin = radius / hypotenuse;
|
||||
float rcos = inv_height / hypotenuse;
|
||||
vec2 c = vec2(rsin, rcos);
|
||||
|
||||
float q = length(local_pos.xz);
|
||||
sdf = max(dot(c, vec2(q, local_pos.y - params.extents.y)), -params.extents.y - local_pos.y);
|
||||
sdf = max(dot(c, vec2(q, local_pos.y - half_size.y)), -half_size.y - local_pos.y);
|
||||
} else if (params.shape == 2) {
|
||||
// Cylinder
|
||||
// https://iquilezles.org/www/articles/distfunctions/distfunctions.htm
|
||||
vec2 d = abs(vec2(length(local_pos.xz), local_pos.y)) - vec2(min(params.extents.x, params.extents.z), params.extents.y);
|
||||
vec2 d = abs(vec2(length(local_pos.xz), local_pos.y)) - vec2(min(half_size.x, half_size.z), half_size.y);
|
||||
sdf = min(max(d.x, d.y), 0.0) + length(max(d, 0.0));
|
||||
} else if (params.shape == 3) {
|
||||
// Box
|
||||
// https://iquilezles.org/www/articles/distfunctions/distfunctions.htm
|
||||
vec3 q = abs(local_pos.xyz) - params.extents;
|
||||
vec3 q = abs(local_pos.xyz) - half_size;
|
||||
sdf = length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0);
|
||||
}
|
||||
|
||||
@@ -222,7 +223,7 @@ void main() {
|
||||
#ifndef SDF_USED
|
||||
cull_mask = 1.0 - smoothstep(-0.1, 0.0, sdf);
|
||||
#endif
|
||||
uvw = clamp((local_pos.xyz + params.extents) / (2.0 * params.extents), 0.0, 1.0);
|
||||
uvw = clamp((local_pos.xyz + half_size) / params.size, 0.0, 1.0);
|
||||
}
|
||||
|
||||
if (cull_mask > 0.0) {
|
||||
|
||||
Reference in New Issue
Block a user