You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-07 12:30:27 +00:00
New lightmapper
-Added LocalVector (needed it) -Added stb_rect_pack (It's pretty cool, we could probably use it for other stuff too) -Fixes and changes all around the place -Added library for 128 bits fixed point (required for Delaunay3D)
This commit is contained in:
@@ -39,7 +39,13 @@ layout(push_constant, binding = 1, std430) uniform Params {
|
||||
}
|
||||
params;
|
||||
|
||||
#ifdef MODE_CUBEMAP_ARRAY_TO_PANORAMA
|
||||
layout(set = 0, binding = 0) uniform samplerCubeArray source_color;
|
||||
#elif defined(MODE_CUBEMAP_TO_PANORAMA)
|
||||
layout(set = 0, binding = 0) uniform samplerCube source_color;
|
||||
#else
|
||||
layout(set = 0, binding = 0) uniform sampler2D source_color;
|
||||
#endif
|
||||
|
||||
#ifdef GLOW_USE_AUTO_EXPOSURE
|
||||
layout(set = 1, binding = 0) uniform sampler2D source_auto_exposure;
|
||||
@@ -57,7 +63,7 @@ void main() {
|
||||
|
||||
// Pixel being shaded
|
||||
ivec2 pos = ivec2(gl_GlobalInvocationID.xy);
|
||||
if (any(greaterThan(pos, params.section.zw))) { //too large, do nothing
|
||||
if (any(greaterThanEqual(pos, params.section.zw))) { //too large, do nothing
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -217,4 +223,25 @@ void main() {
|
||||
|
||||
imageStore(dest_buffer, pos + params.target, color);
|
||||
#endif
|
||||
|
||||
#if defined(MODE_CUBEMAP_TO_PANORAMA) || defined(MODE_CUBEMAP_ARRAY_TO_PANORAMA)
|
||||
|
||||
const float PI = 3.14159265359;
|
||||
vec2 uv = vec2(pos) / vec2(params.section.zw);
|
||||
uv.y = 1.0 - uv.y;
|
||||
float phi = uv.x * 2.0 * PI;
|
||||
float theta = uv.y * PI;
|
||||
|
||||
vec3 normal;
|
||||
normal.x = sin(phi) * sin(theta) * -1.0;
|
||||
normal.y = cos(theta);
|
||||
normal.z = cos(phi) * sin(theta) * -1.0;
|
||||
|
||||
#ifdef MODE_CUBEMAP_TO_PANORAMA
|
||||
vec4 color = textureLod(source_color, normal, params.camera_z_far); //the biggest the lod the least the acne
|
||||
#else
|
||||
vec4 color = textureLod(source_color, vec4(normal, params.camera_z_far), 0.0); //the biggest the lod the least the acne
|
||||
#endif
|
||||
imageStore(dest_buffer, pos + params.target, color);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ layout(location = 3) in vec4 color_attrib;
|
||||
|
||||
layout(location = 4) in vec2 uv_attrib;
|
||||
|
||||
#if defined(UV2_USED) || defined(USE_LIGHTMAP)
|
||||
#if defined(UV2_USED) || defined(USE_LIGHTMAP) || defined(MODE_RENDER_MATERIAL)
|
||||
layout(location = 5) in vec2 uv2_attrib;
|
||||
#endif
|
||||
|
||||
@@ -49,7 +49,7 @@ layout(location = 6) out vec3 binormal_interp;
|
||||
#endif
|
||||
|
||||
#ifdef USE_MATERIAL_UNIFORMS
|
||||
layout(set = 5, binding = 0, std140) uniform MaterialUniforms{
|
||||
layout(set = MATERIAL_UNIFORM_SET, binding = 0, std140) uniform MaterialUniforms{
|
||||
/* clang-format off */
|
||||
MATERIAL_UNIFORMS
|
||||
/* clang-format on */
|
||||
@@ -263,6 +263,14 @@ VERTEX_SHADER_CODE
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef MODE_RENDER_MATERIAL
|
||||
if (scene_data.material_uv2_mode) {
|
||||
gl_Position.xy = (uv2_attrib.xy + draw_call.bake_uv2_offset) * 2.0 - 1.0;
|
||||
gl_Position.z = 0.00001;
|
||||
gl_Position.w = 1.0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* clang-format off */
|
||||
@@ -315,7 +323,7 @@ layout(location = 8) in float dp_clip;
|
||||
#endif
|
||||
|
||||
#ifdef USE_MATERIAL_UNIFORMS
|
||||
layout(set = 5, binding = 0, std140) uniform MaterialUniforms{
|
||||
layout(set = MATERIAL_UNIFORM_SET, binding = 0, std140) uniform MaterialUniforms{
|
||||
/* clang-format off */
|
||||
MATERIAL_UNIFORMS
|
||||
/* clang-format on */
|
||||
@@ -1917,42 +1925,96 @@ FRAGMENT_SHADER_CODE
|
||||
#if !defined(MODE_RENDER_DEPTH) && !defined(MODE_UNSHADED)
|
||||
//gi probes
|
||||
|
||||
//lightmap
|
||||
#ifdef USE_LIGHTMAP
|
||||
|
||||
//lightmap
|
||||
if (bool(instances.data[instance_index].flags & INSTANCE_FLAGS_USE_LIGHTMAP_CAPTURE)) { //has lightmap capture
|
||||
uint index = instances.data[instance_index].gi_offset;
|
||||
|
||||
vec3 wnormal = mat3(scene_data.camera_matrix) * normal;
|
||||
const float c1 = 0.429043;
|
||||
const float c2 = 0.511664;
|
||||
const float c3 = 0.743125;
|
||||
const float c4 = 0.886227;
|
||||
const float c5 = 0.247708;
|
||||
ambient_light += (c1 * lightmap_captures.data[index].sh[8].rgb * (wnormal.x * wnormal.x - wnormal.y * wnormal.y) +
|
||||
c3 * lightmap_captures.data[index].sh[6].rgb * wnormal.z * wnormal.z +
|
||||
c4 * lightmap_captures.data[index].sh[0].rgb -
|
||||
c5 * lightmap_captures.data[index].sh[6].rgb +
|
||||
2.0 * c1 * lightmap_captures.data[index].sh[4].rgb * wnormal.x * wnormal.y +
|
||||
2.0 * c1 * lightmap_captures.data[index].sh[7].rgb * wnormal.x * wnormal.z +
|
||||
2.0 * c1 * lightmap_captures.data[index].sh[5].rgb * wnormal.y * wnormal.z +
|
||||
2.0 * c2 * lightmap_captures.data[index].sh[3].rgb * wnormal.x +
|
||||
2.0 * c2 * lightmap_captures.data[index].sh[1].rgb * wnormal.y +
|
||||
2.0 * c2 * lightmap_captures.data[index].sh[2].rgb * wnormal.z);
|
||||
|
||||
} else if (bool(instances.data[instance_index].flags & INSTANCE_FLAGS_USE_LIGHTMAP)) { // has actual lightmap
|
||||
bool uses_sh = bool(instances.data[instance_index].flags & INSTANCE_FLAGS_USE_SH_LIGHTMAP);
|
||||
uint ofs = instances.data[instance_index].gi_offset & 0xFFF;
|
||||
vec3 uvw;
|
||||
uvw.xy = uv2 * instances.data[instance_index].lightmap_uv_scale.zw + instances.data[instance_index].lightmap_uv_scale.xy;
|
||||
uvw.z = float((instances.data[instance_index].gi_offset >> 12) & 0xFF);
|
||||
|
||||
if (uses_sh) {
|
||||
uvw.z *= 4.0; //SH textures use 4 times more data
|
||||
vec3 lm_light_l0 = textureLod(sampler2DArray(lightmap_textures[ofs], material_samplers[SAMPLER_LINEAR_CLAMP]), uvw + vec3(0.0, 0.0, 0.0), 0.0).rgb;
|
||||
vec3 lm_light_l1n1 = textureLod(sampler2DArray(lightmap_textures[ofs], material_samplers[SAMPLER_LINEAR_CLAMP]), uvw + vec3(0.0, 0.0, 1.0), 0.0).rgb;
|
||||
vec3 lm_light_l1_0 = textureLod(sampler2DArray(lightmap_textures[ofs], material_samplers[SAMPLER_LINEAR_CLAMP]), uvw + vec3(0.0, 0.0, 2.0), 0.0).rgb;
|
||||
vec3 lm_light_l1p1 = textureLod(sampler2DArray(lightmap_textures[ofs], material_samplers[SAMPLER_LINEAR_CLAMP]), uvw + vec3(0.0, 0.0, 3.0), 0.0).rgb;
|
||||
|
||||
uint idx = instances.data[instance_index].gi_offset >> 20;
|
||||
vec3 n = normalize(lightmaps.data[idx].normal_xform * normal);
|
||||
|
||||
ambient_light += lm_light_l0 * 0.282095f;
|
||||
ambient_light += lm_light_l1n1 * 0.32573 * n.y;
|
||||
ambient_light += lm_light_l1_0 * 0.32573 * n.z;
|
||||
ambient_light += lm_light_l1p1 * 0.32573 * n.x;
|
||||
if (metallic > 0.01) { // since the more direct bounced light is lost, we can kind of fake it with this trick
|
||||
vec3 r = reflect(normalize(-vertex), normal);
|
||||
specular_light += lm_light_l1n1 * 0.32573 * r.y;
|
||||
specular_light += lm_light_l1_0 * 0.32573 * r.z;
|
||||
specular_light += lm_light_l1p1 * 0.32573 * r.x;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
ambient_light += textureLod(sampler2DArray(lightmap_textures[ofs], material_samplers[SAMPLER_LINEAR_CLAMP]), uvw, 0.0).rgb;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
//lightmap capture
|
||||
|
||||
#ifdef USE_VOXEL_CONE_TRACING
|
||||
{ // process giprobes
|
||||
if (bool(instances.data[instance_index].flags & INSTANCE_FLAGS_USE_GIPROBE)) { // process giprobes
|
||||
|
||||
uint index1 = instances.data[instance_index].gi_offset & 0xFFFF;
|
||||
if (index1 != 0xFFFF) {
|
||||
vec3 ref_vec = normalize(reflect(normalize(vertex), normal));
|
||||
//find arbitrary tangent and bitangent, then build a matrix
|
||||
vec3 v0 = abs(normal.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(0.0, 1.0, 0.0);
|
||||
vec3 tangent = normalize(cross(v0, normal));
|
||||
vec3 bitangent = normalize(cross(tangent, normal));
|
||||
mat3 normal_mat = mat3(tangent, bitangent, normal);
|
||||
vec3 ref_vec = normalize(reflect(normalize(vertex), normal));
|
||||
//find arbitrary tangent and bitangent, then build a matrix
|
||||
vec3 v0 = abs(normal.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(0.0, 1.0, 0.0);
|
||||
vec3 tangent = normalize(cross(v0, normal));
|
||||
vec3 bitangent = normalize(cross(tangent, normal));
|
||||
mat3 normal_mat = mat3(tangent, bitangent, normal);
|
||||
|
||||
vec4 amb_accum = vec4(0.0);
|
||||
vec4 spec_accum = vec4(0.0);
|
||||
gi_probe_compute(index1, vertex, normal, ref_vec, normal_mat, roughness * roughness, ambient_light, specular_light, spec_accum, amb_accum);
|
||||
vec4 amb_accum = vec4(0.0);
|
||||
vec4 spec_accum = vec4(0.0);
|
||||
gi_probe_compute(index1, vertex, normal, ref_vec, normal_mat, roughness * roughness, ambient_light, specular_light, spec_accum, amb_accum);
|
||||
|
||||
uint index2 = instances.data[instance_index].gi_offset >> 16;
|
||||
uint index2 = instances.data[instance_index].gi_offset >> 16;
|
||||
|
||||
if (index2 != 0xFFFF) {
|
||||
gi_probe_compute(index2, vertex, normal, ref_vec, normal_mat, roughness * roughness, ambient_light, specular_light, spec_accum, amb_accum);
|
||||
}
|
||||
|
||||
if (amb_accum.a > 0.0) {
|
||||
amb_accum.rgb /= amb_accum.a;
|
||||
}
|
||||
|
||||
if (spec_accum.a > 0.0) {
|
||||
spec_accum.rgb /= spec_accum.a;
|
||||
}
|
||||
|
||||
specular_light = spec_accum.rgb;
|
||||
ambient_light = amb_accum.rgb;
|
||||
if (index2 != 0xFFFF) {
|
||||
gi_probe_compute(index2, vertex, normal, ref_vec, normal_mat, roughness * roughness, ambient_light, specular_light, spec_accum, amb_accum);
|
||||
}
|
||||
|
||||
if (amb_accum.a > 0.0) {
|
||||
amb_accum.rgb /= amb_accum.a;
|
||||
}
|
||||
|
||||
if (spec_accum.a > 0.0) {
|
||||
spec_accum.rgb /= spec_accum.a;
|
||||
}
|
||||
|
||||
specular_light = spec_accum.rgb;
|
||||
ambient_light = amb_accum.rgb;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -2424,7 +2486,6 @@ FRAGMENT_SHADER_CODE
|
||||
ao_light_affect = mix(1.0, ao, ao_light_affect);
|
||||
specular_light = mix(scene_data.ao_color.rgb, specular_light, ao_light_affect);
|
||||
diffuse_light = mix(scene_data.ao_color.rgb, diffuse_light, ao_light_affect);
|
||||
|
||||
#else
|
||||
|
||||
if (scene_data.ssao_enabled) {
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
|
||||
layout(push_constant, binding = 0, std430) uniform DrawCall {
|
||||
uint instance_index;
|
||||
uint pad[3]; //16 bits minimum size
|
||||
uint pad; //16 bits minimum size
|
||||
vec2 bake_uv2_offset; //used for bake to uv2, ignored otherwise
|
||||
}
|
||||
draw_call;
|
||||
|
||||
@@ -77,6 +78,10 @@ layout(set = 0, binding = 3, std140) uniform SceneData {
|
||||
bool roughness_limiter_enabled;
|
||||
|
||||
vec4 ao_color;
|
||||
bool material_uv2_mode;
|
||||
uint pad_material0;
|
||||
uint pad_material1;
|
||||
uint pad_material2;
|
||||
|
||||
#if 0
|
||||
vec4 ambient_light_color;
|
||||
@@ -115,11 +120,10 @@ layout(set = 0, binding = 3, std140) uniform SceneData {
|
||||
}
|
||||
scene_data;
|
||||
|
||||
#define INSTANCE_FLAGS_FORWARD_MASK 0x7
|
||||
#define INSTANCE_FLAGS_FORWARD_OMNI_LIGHT_SHIFT 3
|
||||
#define INSTANCE_FLAGS_FORWARD_SPOT_LIGHT_SHIFT 6
|
||||
#define INSTANCE_FLAGS_FORWARD_DECAL_SHIFT 9
|
||||
|
||||
#define INSTANCE_FLAGS_USE_LIGHTMAP_CAPTURE (1 << 8)
|
||||
#define INSTANCE_FLAGS_USE_LIGHTMAP (1 << 9)
|
||||
#define INSTANCE_FLAGS_USE_SH_LIGHTMAP (1 << 10)
|
||||
#define INSTANCE_FLAGS_USE_GIPROBE (1 << 11)
|
||||
#define INSTANCE_FLAGS_MULTIMESH (1 << 12)
|
||||
#define INSTANCE_FLAGS_MULTIMESH_FORMAT_2D (1 << 13)
|
||||
#define INSTANCE_FLAGS_MULTIMESH_HAS_COLOR (1 << 14)
|
||||
@@ -135,8 +139,9 @@ struct InstanceData {
|
||||
mat4 normal_transform;
|
||||
uint flags;
|
||||
uint instance_uniforms_ofs; //base offset in global buffer for instance variables
|
||||
uint gi_offset; //GI information when using lightmapping (VCT or lightmap)
|
||||
uint gi_offset; //GI information when using lightmapping (VCT or lightmap index)
|
||||
uint layer_mask;
|
||||
vec4 lightmap_uv_scale;
|
||||
};
|
||||
|
||||
layout(set = 0, binding = 4, std430) restrict readonly buffer Instances {
|
||||
@@ -248,12 +253,35 @@ gi_probes;
|
||||
|
||||
layout(set = 0, binding = 9) uniform texture3D gi_probe_textures[MAX_GI_PROBE_TEXTURES];
|
||||
|
||||
#define LIGHTMAP_FLAG_USE_DIRECTION 1
|
||||
#define LIGHTMAP_FLAG_USE_SPECULAR_DIRECTION 2
|
||||
|
||||
struct Lightmap {
|
||||
mat3 normal_xform;
|
||||
};
|
||||
|
||||
layout(set = 0, binding = 10, std140) restrict readonly buffer Lightmaps {
|
||||
Lightmap data[];
|
||||
}
|
||||
lightmaps;
|
||||
|
||||
layout(set = 0, binding = 11) uniform texture2DArray lightmap_textures[MAX_LIGHTMAP_TEXTURES];
|
||||
|
||||
struct LightmapCapture {
|
||||
vec4 sh[9];
|
||||
};
|
||||
|
||||
layout(set = 0, binding = 12, std140) restrict readonly buffer LightmapCaptures {
|
||||
LightmapCapture data[];
|
||||
}
|
||||
lightmap_captures;
|
||||
|
||||
#define CLUSTER_COUNTER_SHIFT 20
|
||||
#define CLUSTER_POINTER_MASK ((1 << CLUSTER_COUNTER_SHIFT) - 1)
|
||||
#define CLUSTER_COUNTER_MASK 0xfff
|
||||
|
||||
layout(set = 0, binding = 10) uniform texture2D decal_atlas;
|
||||
layout(set = 0, binding = 11) uniform texture2D decal_atlas_srgb;
|
||||
layout(set = 0, binding = 13) uniform texture2D decal_atlas;
|
||||
layout(set = 0, binding = 14) uniform texture2D decal_atlas_srgb;
|
||||
|
||||
struct DecalData {
|
||||
mat4 xform; //to decal transform
|
||||
@@ -273,21 +301,21 @@ struct DecalData {
|
||||
float normal_fade;
|
||||
};
|
||||
|
||||
layout(set = 0, binding = 12, std430) restrict readonly buffer Decals {
|
||||
layout(set = 0, binding = 15, std430) restrict readonly buffer Decals {
|
||||
DecalData data[];
|
||||
}
|
||||
decals;
|
||||
|
||||
layout(set = 0, binding = 13) uniform utexture3D cluster_texture;
|
||||
layout(set = 0, binding = 16) uniform utexture3D cluster_texture;
|
||||
|
||||
layout(set = 0, binding = 14, std430) restrict readonly buffer ClusterData {
|
||||
layout(set = 0, binding = 17, std430) restrict readonly buffer ClusterData {
|
||||
uint indices[];
|
||||
}
|
||||
cluster_data;
|
||||
|
||||
layout(set = 0, binding = 15) uniform texture2D directional_shadow_atlas;
|
||||
layout(set = 0, binding = 18) uniform texture2D directional_shadow_atlas;
|
||||
|
||||
layout(set = 0, binding = 16, std430) restrict readonly buffer GlobalVariableData {
|
||||
layout(set = 0, binding = 19, std430) restrict readonly buffer GlobalVariableData {
|
||||
vec4 data[];
|
||||
}
|
||||
global_variables;
|
||||
@@ -312,7 +340,7 @@ layout(set = 2, binding = 0) uniform textureCubeArray reflection_atlas;
|
||||
|
||||
layout(set = 2, binding = 1) uniform texture2D shadow_atlas;
|
||||
|
||||
/* Set 1, Render Buffers */
|
||||
/* Set 3, Render Buffers */
|
||||
|
||||
layout(set = 3, binding = 0) uniform texture2D depth_buffer;
|
||||
layout(set = 3, binding = 1) uniform texture2D color_buffer;
|
||||
|
||||
@@ -68,7 +68,7 @@ void main() {
|
||||
// Pixel being shaded
|
||||
ivec2 ssC = ivec2(gl_GlobalInvocationID.xy);
|
||||
|
||||
if (any(greaterThan(ssC, params.screen_size))) { //too large, do nothing
|
||||
if (any(greaterThanEqual(ssC, params.screen_size))) { //too large, do nothing
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -120,7 +120,7 @@ void main() {
|
||||
// Pixel being shaded
|
||||
ivec2 ssC = ivec2(gl_GlobalInvocationID.xy);
|
||||
|
||||
if (any(greaterThan(ssC, params.screen_size))) { //too large, do nothing
|
||||
if (any(greaterThanEqual(ssC, params.screen_size))) { //too large, do nothing
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ void main() {
|
||||
// Pixel being shaded
|
||||
ivec2 ssC = ivec2(gl_GlobalInvocationID.xy);
|
||||
|
||||
if (any(greaterThan(ssC, params.screen_size))) { //too large, do nothing
|
||||
if (any(greaterThanEqual(ssC, params.screen_size))) { //too large, do nothing
|
||||
return;
|
||||
}
|
||||
//do not filter, SSR will generate arctifacts if this is done
|
||||
|
||||
@@ -212,7 +212,7 @@ float sampleAO(in ivec2 ssC, in vec3 C, in vec3 n_C, in float ssDiskRadius, in f
|
||||
void main() {
|
||||
// Pixel being shaded
|
||||
ivec2 ssC = ivec2(gl_GlobalInvocationID.xy);
|
||||
if (any(greaterThan(ssC, params.screen_size))) { //too large, do nothing
|
||||
if (any(greaterThanEqual(ssC, params.screen_size))) { //too large, do nothing
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ void main() {
|
||||
|
||||
// Pixel being shaded
|
||||
ivec2 ssC = ivec2(gl_GlobalInvocationID.xy);
|
||||
if (any(greaterThan(ssC, params.screen_size))) { //too large, do nothing
|
||||
if (any(greaterThanEqual(ssC, params.screen_size))) { //too large, do nothing
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -142,7 +142,7 @@ void main() {
|
||||
// Pixel being shaded
|
||||
ivec2 ssC = ivec2(gl_GlobalInvocationID.xy);
|
||||
|
||||
if (any(greaterThan(ssC, params.screen_size))) { //too large, do nothing
|
||||
if (any(greaterThanEqual(ssC, params.screen_size))) { //too large, do nothing
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user