1
0
mirror of https://github.com/godotengine/godot.git synced 2025-12-06 17:25:19 +00:00

Several fixes to 3D rendering, and multimesh implementation.

This commit is contained in:
Juan Linietsky
2019-09-14 00:37:42 -03:00
parent 9d7b7f931b
commit 6deffa62fb
36 changed files with 1212 additions and 222 deletions

View File

@@ -86,16 +86,50 @@ layout(location =8) out float dp_clip;
void main() {
instance_index = draw_call.instance_index;
/*if (draw_call.instance_increment) {
instance_index += gl_InstanceIndex;
}*/
vec3 vertex = vertex_attrib;
vec4 instance_custom = vec4(0.0);
#if defined(COLOR_USED)
color_interp = color_attrib;
#endif
mat4 world_matrix = instances.data[instance_index].transform;
mat3 world_normal_matrix= mat3(instances.data[instance_index].normal_transform);
if (bool(instances.data[instance_index].flags & INSTANCE_FLAGS_MULTIMESH)) {
//multimesh, instances are for it
uint offset = (instances.data[instance_index].flags>>INSTANCE_FLAGS_MULTIMESH_STRIDE_SHIFT)&INSTANCE_FLAGS_MULTIMESH_STRIDE_MASK;
offset*=gl_InstanceIndex;
mat4 matrix;
if (bool(instances.data[instance_index].flags & INSTANCE_FLAGS_MULTIMESH_FORMAT_2D)) {
mat4 matrix = mat4(transforms.data[offset+0],transforms.data[offset+1],vec4(0.0,0.0,1.0,0.0),vec4(0.0,0.0,0.0,1.0));
offset+=2;
} else {
mat4 matrix = mat4(transforms.data[offset+0],transforms.data[offset+1],transforms.data[offset+2],vec4(0.0,0.0,0.0,1.0));
offset+=3;
}
if (bool(instances.data[instance_index].flags & INSTANCE_FLAGS_MULTIMESH_HAS_COLOR)) {
#ifdef COLOR_USED
color_interp *= transforms.data[offset];
#endif
offset+=1;
}
if (bool(instances.data[instance_index].flags & INSTANCE_FLAGS_MULTIMESH_HAS_CUSTOM_DATA)) {
instance_custom = transforms.data[offset];
}
//transposed, so multiply in opposite order
world_matrix = matrix * world_matrix;
world_normal_matrix = mat3(matrix) * world_normal_matrix;
} else {
//not a multimesh, instances are for multiple draw calls
instance_index += gl_InstanceIndex;
}
vec3 vertex = vertex_attrib;
vec3 normal = normal_attrib;
#if defined(TANGENT_USED) || defined(NORMALMAP_USED) || defined(LIGHT_ANISOTROPY_USED)
@@ -103,10 +137,6 @@ void main() {
float binormalf = tangent_attrib.a;
#endif
#if defined(COLOR_USED)
color_interp = color_attrib;
#endif
#if defined(TANGENT_USED) || defined(NORMALMAP_USED) || defined(LIGHT_ANISOTROPY_USED)
vec3 binormal = normalize(cross(normal, tangent) * binormalf);
@@ -124,7 +154,7 @@ void main() {
vec4 position;
#endif
vec4 instance_custom = vec4(0.0);
mat4 projection_matrix = scene_data.projection_matrix;
@@ -768,7 +798,7 @@ void light_process_spot(uint idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 a
transmission,
#endif
#ifdef LIGHT_RIM_USED
rim * omni_attenuation, rim_tint,
rim * spot_attenuation, rim_tint,
#endif
#ifdef LIGHT_CLEARCOAT_USED
clearcoat, clearcoat_gloss,
@@ -932,7 +962,7 @@ void main() {
float normaldepth = 1.0;
#if defined(SCREEN_UV_USED)
vec2 screen_uv = gl_FragCoord.xy * screen_pixel_size;
vec2 screen_uv = gl_FragCoord.xy * scene_data.screen_pixel_size;
#endif
float sss_strength = 0.0;
@@ -1182,7 +1212,7 @@ FRAGMENT_SHADER_CODE
transmission,
#endif
#ifdef LIGHT_RIM_USED
rim * omni_attenuation, rim_tint,
rim, rim_tint,
#endif
#ifdef LIGHT_CLEARCOAT_USED
clearcoat, clearcoat_gloss,

View File

@@ -118,11 +118,20 @@ layout(set=0,binding=8,std140) uniform SceneData {
#endif
} scene_data;
#define INSTANCE_FLAGS_FORWARD_MASK 3
#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_MULTIMESH (1 << 12)
#define INSTANCE_FLAGS_MULTIMESH_FORMAT_2D (1 << 13)
#define INSTANCE_FLAGS_MULTIMESH_HAS_COLOR (1 << 14)
#define INSTANCE_FLAGS_MULTIMESH_HAS_CUSTOM_DATA (1 << 15)
#define INSTANCE_FLAGS_MULTIMESH_STRIDE_SHIFT 16
//3 bits of stride
#define INSTANCE_FLAGS_MULTIMESH_STRIDE_MASK 0x7
struct InstanceData {
mat4 transform;
@@ -217,6 +226,11 @@ layout(set=0,binding=15,std430) buffer Skeletons {
//layout(set = 1, binding = 0) uniform textureBuffer multimesh_transforms;
layout(set=1,binding=0,std430) buffer Transforms {
vec4 data[];
} transforms;
/* Set 2 Instancing (Multimesh) data */
#if 0

View File

@@ -145,7 +145,7 @@ vec3 tonemap_filmic(vec3 color, float white) {
vec3 color_tonemapped = ((color * (A * color + C * B) + D * E) / (color * (A * color + B) + D * F)) - E / F;
float white_tonemapped = ((white * (A * white + C * B) + D * E) / (white * (A * white + B) + D * F)) - E / F;
return color_tonemapped / white_tonemapped, vec3(0.0f), vec3(1.0f);
return color_tonemapped / white_tonemapped;
}
vec3 tonemap_aces(vec3 color, float white) {
@@ -159,7 +159,7 @@ vec3 tonemap_aces(vec3 color, float white) {
vec3 color_tonemapped = (color * (A * color + B)) / (color * (C * color + D) + E);
float white_tonemapped = (white * (A * white + B)) / (white * (C * white + D) + E);
return color_tonemapped / white_tonemapped, vec3(0.0f), vec3(1.0f);
return color_tonemapped / white_tonemapped;
}
vec3 tonemap_reinhard(vec3 color, float white) {