|
@@ -178,6 +178,13 @@ vec3 double_add_vec3(vec3 base_a, vec3 prec_a, vec3 base_b, vec3 prec_b, out vec
|
|
|
}
|
|
|
#endif
|
|
|
|
|
|
+uint multimesh_stride() {
|
|
|
+ uint stride = sc_multimesh_format_2d() ? 2 : 3;
|
|
|
+ stride += sc_multimesh_has_color() ? 1 : 0;
|
|
|
+ stride += sc_multimesh_has_custom_data() ? 1 : 0;
|
|
|
+ return stride;
|
|
|
+}
|
|
|
+
|
|
|
void main() {
|
|
|
vec4 instance_custom = vec4(0.0);
|
|
|
#if defined(COLOR_USED)
|
|
@@ -208,7 +215,7 @@ void main() {
|
|
|
mat4 matrix;
|
|
|
mat4 read_model_matrix = model_matrix;
|
|
|
|
|
|
- if (sc_is_multimesh()) {
|
|
|
+ if (sc_multimesh()) {
|
|
|
//multimesh, instances are for it
|
|
|
|
|
|
#ifdef USE_PARTICLE_TRAILS
|
|
@@ -256,25 +263,10 @@ void main() {
|
|
|
#endif
|
|
|
|
|
|
#else
|
|
|
- uint stride = 0;
|
|
|
- {
|
|
|
- //TODO implement a small lookup table for the stride
|
|
|
- if (bool(instances.data[draw_call.instance_index].flags & INSTANCE_FLAGS_MULTIMESH_FORMAT_2D)) {
|
|
|
- stride += 2;
|
|
|
- } else {
|
|
|
- stride += 3;
|
|
|
- }
|
|
|
- if (bool(instances.data[draw_call.instance_index].flags & INSTANCE_FLAGS_MULTIMESH_HAS_COLOR)) {
|
|
|
- stride += 1;
|
|
|
- }
|
|
|
- if (bool(instances.data[draw_call.instance_index].flags & INSTANCE_FLAGS_MULTIMESH_HAS_CUSTOM_DATA)) {
|
|
|
- stride += 1;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
+ uint stride = multimesh_stride();
|
|
|
uint offset = stride * gl_InstanceIndex;
|
|
|
|
|
|
- if (bool(instances.data[draw_call.instance_index].flags & INSTANCE_FLAGS_MULTIMESH_FORMAT_2D)) {
|
|
|
+ if (sc_multimesh_format_2d()) {
|
|
|
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 {
|
|
@@ -282,14 +274,14 @@ void main() {
|
|
|
offset += 3;
|
|
|
}
|
|
|
|
|
|
- if (bool(instances.data[draw_call.instance_index].flags & INSTANCE_FLAGS_MULTIMESH_HAS_COLOR)) {
|
|
|
+ if (sc_multimesh_has_color()) {
|
|
|
#ifdef COLOR_USED
|
|
|
color_interp *= transforms.data[offset];
|
|
|
#endif
|
|
|
offset += 1;
|
|
|
}
|
|
|
|
|
|
- if (bool(instances.data[draw_call.instance_index].flags & INSTANCE_FLAGS_MULTIMESH_HAS_CUSTOM_DATA)) {
|
|
|
+ if (sc_multimesh_has_custom_data()) {
|
|
|
instance_custom = transforms.data[offset];
|
|
|
}
|
|
|
|
|
@@ -404,7 +396,7 @@ void main() {
|
|
|
// Then we combine the translations from the model matrix and the view matrix using emulated doubles.
|
|
|
// We add the result to the vertex and ignore the final lost precision.
|
|
|
vec3 model_origin = model_matrix[3].xyz;
|
|
|
- if (sc_is_multimesh()) {
|
|
|
+ if (sc_multimesh()) {
|
|
|
vertex = mat3(matrix) * vertex;
|
|
|
model_origin = double_add_vec3(model_origin, model_precision, matrix[3].xyz, vec3(0.0), model_precision);
|
|
|
}
|
|
@@ -461,50 +453,24 @@ void main() {
|
|
|
diffuse_light_interp = vec4(0.0);
|
|
|
specular_light_interp = vec4(0.0);
|
|
|
|
|
|
- if (!sc_disable_omni_lights()) {
|
|
|
- uint light_indices = instances.data[draw_call.instance_index].omni_lights.x;
|
|
|
- for (uint i = 0; i < 8; i++) {
|
|
|
- uint light_index = light_indices & 0xFF;
|
|
|
- if (i == 3) {
|
|
|
- light_indices = instances.data[draw_call.instance_index].omni_lights.y;
|
|
|
- } else {
|
|
|
- light_indices = light_indices >> 8;
|
|
|
- }
|
|
|
-
|
|
|
- if (light_index == 0xFF) {
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- light_process_omni_vertex(light_index, vertex, view, normal, roughness,
|
|
|
- diffuse_light_interp.rgb, specular_light_interp.rgb);
|
|
|
- }
|
|
|
+ uvec2 omni_light_indices = instances.data[draw_call.instance_index].omni_lights;
|
|
|
+ for (uint i = 0; i < sc_omni_lights(); i++) {
|
|
|
+ uint light_index = (i > 3) ? ((omni_light_indices.y >> ((i - 4) * 8)) & 0xFF) : ((omni_light_indices.x >> (i * 8)) & 0xFF);
|
|
|
+ light_process_omni_vertex(light_index, vertex, view, normal, roughness, diffuse_light_interp.rgb, specular_light_interp.rgb);
|
|
|
}
|
|
|
|
|
|
- if (!sc_disable_spot_lights()) {
|
|
|
- uint light_indices = instances.data[draw_call.instance_index].spot_lights.x;
|
|
|
- for (uint i = 0; i < 8; i++) {
|
|
|
- uint light_index = light_indices & 0xFF;
|
|
|
- if (i == 3) {
|
|
|
- light_indices = instances.data[draw_call.instance_index].spot_lights.y;
|
|
|
- } else {
|
|
|
- light_indices = light_indices >> 8;
|
|
|
- }
|
|
|
-
|
|
|
- if (light_index == 0xFF) {
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- light_process_spot_vertex(light_index, vertex, view, normal, roughness,
|
|
|
- diffuse_light_interp.rgb, specular_light_interp.rgb);
|
|
|
- }
|
|
|
+ uvec2 spot_light_indices = instances.data[draw_call.instance_index].spot_lights;
|
|
|
+ for (uint i = 0; i < sc_spot_lights(); i++) {
|
|
|
+ uint light_index = (i > 3) ? ((spot_light_indices.y >> ((i - 4) * 8)) & 0xFF) : ((spot_light_indices.x >> (i * 8)) & 0xFF);
|
|
|
+ light_process_spot_vertex(light_index, vertex, view, normal, roughness, diffuse_light_interp.rgb, specular_light_interp.rgb);
|
|
|
}
|
|
|
|
|
|
- if (!sc_disable_directional_lights()) {
|
|
|
+ if (sc_directional_lights() > 0) {
|
|
|
// We process the first directional light separately as it may have shadows.
|
|
|
vec3 directional_diffuse = vec3(0.0);
|
|
|
vec3 directional_specular = vec3(0.0);
|
|
|
|
|
|
- for (uint i = 0; i < scene_data.directional_light_count; i++) {
|
|
|
+ for (uint i = 0; i < sc_directional_lights(); i++) {
|
|
|
if (!bool(directional_lights.data[i].mask & instances.data[draw_call.instance_index].layer_mask)) {
|
|
|
continue; // Not masked, skip.
|
|
|
}
|
|
@@ -823,7 +789,7 @@ vec4 fog_process(vec3 vertex) {
|
|
|
float sun_total = 0.0;
|
|
|
vec3 view = normalize(vertex);
|
|
|
|
|
|
- for (uint i = 0; i < scene_data_block.data.directional_light_count; i++) {
|
|
|
+ for (uint i = 0; i < sc_directional_lights(); i++) {
|
|
|
vec3 light_color = directional_lights.data[i].color * directional_lights.data[i].energy;
|
|
|
float light_amount = pow(max(dot(view, directional_lights.data[i].direction), 0.0), 8.0);
|
|
|
fog_color += light_color * light_amount * scene_data_block.data.fog_sun_scatter;
|
|
@@ -1110,97 +1076,83 @@ void main() {
|
|
|
vec3 vertex_ddx = dFdx(vertex);
|
|
|
vec3 vertex_ddy = dFdy(vertex);
|
|
|
|
|
|
- if (!sc_disable_decals()) { //Decals
|
|
|
- // must implement
|
|
|
-
|
|
|
- uint decal_indices = instances.data[draw_call.instance_index].decals.x;
|
|
|
- for (uint i = 0; i < 8; i++) {
|
|
|
- uint decal_index = decal_indices & 0xFF;
|
|
|
- if (i == 3) {
|
|
|
- decal_indices = instances.data[draw_call.instance_index].decals.y;
|
|
|
- } else {
|
|
|
- decal_indices = decal_indices >> 8;
|
|
|
- }
|
|
|
+ uvec2 decal_indices = instances.data[draw_call.instance_index].decals;
|
|
|
+ for (uint i = 0; i < sc_decals(); i++) {
|
|
|
+ uint decal_index = (i > 3) ? ((decal_indices.y >> ((i - 4) * 8)) & 0xFF) : ((decal_indices.x >> (i * 8)) & 0xFF);
|
|
|
+ if (!bool(decals.data[decal_index].mask & instances.data[draw_call.instance_index].layer_mask)) {
|
|
|
+ continue; //not masked
|
|
|
+ }
|
|
|
|
|
|
- if (decal_index == 0xFF) {
|
|
|
- break;
|
|
|
- }
|
|
|
+ vec3 uv_local = (decals.data[decal_index].xform * vec4(vertex, 1.0)).xyz;
|
|
|
+ if (any(lessThan(uv_local, vec3(0.0, -1.0, 0.0))) || any(greaterThan(uv_local, vec3(1.0)))) {
|
|
|
+ continue; //out of decal
|
|
|
+ }
|
|
|
|
|
|
- if (!bool(decals.data[decal_index].mask & instances.data[draw_call.instance_index].layer_mask)) {
|
|
|
- continue; //not masked
|
|
|
- }
|
|
|
+ float fade = pow(1.0 - (uv_local.y > 0.0 ? uv_local.y : -uv_local.y), uv_local.y > 0.0 ? decals.data[decal_index].upper_fade : decals.data[decal_index].lower_fade);
|
|
|
|
|
|
- vec3 uv_local = (decals.data[decal_index].xform * vec4(vertex, 1.0)).xyz;
|
|
|
- if (any(lessThan(uv_local, vec3(0.0, -1.0, 0.0))) || any(greaterThan(uv_local, vec3(1.0)))) {
|
|
|
- continue; //out of decal
|
|
|
- }
|
|
|
+ if (decals.data[decal_index].normal_fade > 0.0) {
|
|
|
+ fade *= smoothstep(decals.data[decal_index].normal_fade, 1.0, dot(normal_interp, decals.data[decal_index].normal) * 0.5 + 0.5);
|
|
|
+ }
|
|
|
|
|
|
- float fade = pow(1.0 - (uv_local.y > 0.0 ? uv_local.y : -uv_local.y), uv_local.y > 0.0 ? decals.data[decal_index].upper_fade : decals.data[decal_index].lower_fade);
|
|
|
+ //we need ddx/ddy for mipmaps, so simulate them
|
|
|
+ vec2 ddx = (decals.data[decal_index].xform * vec4(vertex_ddx, 0.0)).xz;
|
|
|
+ vec2 ddy = (decals.data[decal_index].xform * vec4(vertex_ddy, 0.0)).xz;
|
|
|
|
|
|
- if (decals.data[decal_index].normal_fade > 0.0) {
|
|
|
- fade *= smoothstep(decals.data[decal_index].normal_fade, 1.0, dot(normal_interp, decals.data[decal_index].normal) * 0.5 + 0.5);
|
|
|
+ if (decals.data[decal_index].albedo_rect != vec4(0.0)) {
|
|
|
+ //has albedo
|
|
|
+ vec4 decal_albedo;
|
|
|
+ if (sc_decal_use_mipmaps()) {
|
|
|
+ decal_albedo = textureGrad(sampler2D(decal_atlas_srgb, decal_sampler), uv_local.xz * decals.data[decal_index].albedo_rect.zw + decals.data[decal_index].albedo_rect.xy, ddx * decals.data[decal_index].albedo_rect.zw, ddy * decals.data[decal_index].albedo_rect.zw);
|
|
|
+ } else {
|
|
|
+ decal_albedo = textureLod(sampler2D(decal_atlas_srgb, decal_sampler), uv_local.xz * decals.data[decal_index].albedo_rect.zw + decals.data[decal_index].albedo_rect.xy, 0.0);
|
|
|
}
|
|
|
+ decal_albedo *= decals.data[decal_index].modulate;
|
|
|
+ decal_albedo.a *= fade;
|
|
|
+ albedo = mix(albedo, decal_albedo.rgb, decal_albedo.a * decals.data[decal_index].albedo_mix);
|
|
|
|
|
|
- //we need ddx/ddy for mipmaps, so simulate them
|
|
|
- vec2 ddx = (decals.data[decal_index].xform * vec4(vertex_ddx, 0.0)).xz;
|
|
|
- vec2 ddy = (decals.data[decal_index].xform * vec4(vertex_ddy, 0.0)).xz;
|
|
|
-
|
|
|
- if (decals.data[decal_index].albedo_rect != vec4(0.0)) {
|
|
|
- //has albedo
|
|
|
- vec4 decal_albedo;
|
|
|
+ if (decals.data[decal_index].normal_rect != vec4(0.0)) {
|
|
|
+ vec3 decal_normal;
|
|
|
if (sc_decal_use_mipmaps()) {
|
|
|
- decal_albedo = textureGrad(sampler2D(decal_atlas_srgb, decal_sampler), uv_local.xz * decals.data[decal_index].albedo_rect.zw + decals.data[decal_index].albedo_rect.xy, ddx * decals.data[decal_index].albedo_rect.zw, ddy * decals.data[decal_index].albedo_rect.zw);
|
|
|
+ decal_normal = textureGrad(sampler2D(decal_atlas, decal_sampler), uv_local.xz * decals.data[decal_index].normal_rect.zw + decals.data[decal_index].normal_rect.xy, ddx * decals.data[decal_index].normal_rect.zw, ddy * decals.data[decal_index].normal_rect.zw).xyz;
|
|
|
} else {
|
|
|
- decal_albedo = textureLod(sampler2D(decal_atlas_srgb, decal_sampler), uv_local.xz * decals.data[decal_index].albedo_rect.zw + decals.data[decal_index].albedo_rect.xy, 0.0);
|
|
|
- }
|
|
|
- decal_albedo *= decals.data[decal_index].modulate;
|
|
|
- decal_albedo.a *= fade;
|
|
|
- albedo = mix(albedo, decal_albedo.rgb, decal_albedo.a * decals.data[decal_index].albedo_mix);
|
|
|
-
|
|
|
- if (decals.data[decal_index].normal_rect != vec4(0.0)) {
|
|
|
- vec3 decal_normal;
|
|
|
- if (sc_decal_use_mipmaps()) {
|
|
|
- decal_normal = textureGrad(sampler2D(decal_atlas, decal_sampler), uv_local.xz * decals.data[decal_index].normal_rect.zw + decals.data[decal_index].normal_rect.xy, ddx * decals.data[decal_index].normal_rect.zw, ddy * decals.data[decal_index].normal_rect.zw).xyz;
|
|
|
- } else {
|
|
|
- decal_normal = textureLod(sampler2D(decal_atlas, decal_sampler), uv_local.xz * decals.data[decal_index].normal_rect.zw + decals.data[decal_index].normal_rect.xy, 0.0).xyz;
|
|
|
- }
|
|
|
- decal_normal.xy = decal_normal.xy * vec2(2.0, -2.0) - vec2(1.0, -1.0); //users prefer flipped y normal maps in most authoring software
|
|
|
- decal_normal.z = sqrt(max(0.0, 1.0 - dot(decal_normal.xy, decal_normal.xy)));
|
|
|
- //convert to view space, use xzy because y is up
|
|
|
- decal_normal = (decals.data[decal_index].normal_xform * decal_normal.xzy).xyz;
|
|
|
-
|
|
|
- normal = normalize(mix(normal, decal_normal, decal_albedo.a));
|
|
|
+ decal_normal = textureLod(sampler2D(decal_atlas, decal_sampler), uv_local.xz * decals.data[decal_index].normal_rect.zw + decals.data[decal_index].normal_rect.xy, 0.0).xyz;
|
|
|
}
|
|
|
+ decal_normal.xy = decal_normal.xy * vec2(2.0, -2.0) - vec2(1.0, -1.0); //users prefer flipped y normal maps in most authoring software
|
|
|
+ decal_normal.z = sqrt(max(0.0, 1.0 - dot(decal_normal.xy, decal_normal.xy)));
|
|
|
+ //convert to view space, use xzy because y is up
|
|
|
+ decal_normal = (decals.data[decal_index].normal_xform * decal_normal.xzy).xyz;
|
|
|
|
|
|
- if (decals.data[decal_index].orm_rect != vec4(0.0)) {
|
|
|
- vec3 decal_orm;
|
|
|
- if (sc_decal_use_mipmaps()) {
|
|
|
- decal_orm = textureGrad(sampler2D(decal_atlas, decal_sampler), uv_local.xz * decals.data[decal_index].orm_rect.zw + decals.data[decal_index].orm_rect.xy, ddx * decals.data[decal_index].orm_rect.zw, ddy * decals.data[decal_index].orm_rect.zw).xyz;
|
|
|
- } else {
|
|
|
- decal_orm = textureLod(sampler2D(decal_atlas, decal_sampler), uv_local.xz * decals.data[decal_index].orm_rect.zw + decals.data[decal_index].orm_rect.xy, 0.0).xyz;
|
|
|
- }
|
|
|
- ao = mix(ao, decal_orm.r, decal_albedo.a);
|
|
|
- roughness = mix(roughness, decal_orm.g, decal_albedo.a);
|
|
|
- metallic = mix(metallic, decal_orm.b, decal_albedo.a);
|
|
|
- }
|
|
|
+ normal = normalize(mix(normal, decal_normal, decal_albedo.a));
|
|
|
}
|
|
|
|
|
|
- if (decals.data[decal_index].emission_rect != vec4(0.0)) {
|
|
|
- //emission is additive, so its independent from albedo
|
|
|
+ if (decals.data[decal_index].orm_rect != vec4(0.0)) {
|
|
|
+ vec3 decal_orm;
|
|
|
if (sc_decal_use_mipmaps()) {
|
|
|
- emission += textureGrad(sampler2D(decal_atlas_srgb, decal_sampler), uv_local.xz * decals.data[decal_index].emission_rect.zw + decals.data[decal_index].emission_rect.xy, ddx * decals.data[decal_index].emission_rect.zw, ddy * decals.data[decal_index].emission_rect.zw).xyz * decals.data[decal_index].emission_energy * fade;
|
|
|
+ decal_orm = textureGrad(sampler2D(decal_atlas, decal_sampler), uv_local.xz * decals.data[decal_index].orm_rect.zw + decals.data[decal_index].orm_rect.xy, ddx * decals.data[decal_index].orm_rect.zw, ddy * decals.data[decal_index].orm_rect.zw).xyz;
|
|
|
} else {
|
|
|
- emission += textureLod(sampler2D(decal_atlas_srgb, decal_sampler), uv_local.xz * decals.data[decal_index].emission_rect.zw + decals.data[decal_index].emission_rect.xy, 0.0).xyz * decals.data[decal_index].emission_energy * fade;
|
|
|
+ decal_orm = textureLod(sampler2D(decal_atlas, decal_sampler), uv_local.xz * decals.data[decal_index].orm_rect.zw + decals.data[decal_index].orm_rect.xy, 0.0).xyz;
|
|
|
}
|
|
|
+ ao = mix(ao, decal_orm.r, decal_albedo.a);
|
|
|
+ roughness = mix(roughness, decal_orm.g, decal_albedo.a);
|
|
|
+ metallic = mix(metallic, decal_orm.b, decal_albedo.a);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (decals.data[decal_index].emission_rect != vec4(0.0)) {
|
|
|
+ //emission is additive, so its independent from albedo
|
|
|
+ if (sc_decal_use_mipmaps()) {
|
|
|
+ emission += textureGrad(sampler2D(decal_atlas_srgb, decal_sampler), uv_local.xz * decals.data[decal_index].emission_rect.zw + decals.data[decal_index].emission_rect.xy, ddx * decals.data[decal_index].emission_rect.zw, ddy * decals.data[decal_index].emission_rect.zw).xyz * decals.data[decal_index].emission_energy * fade;
|
|
|
+ } else {
|
|
|
+ emission += textureLod(sampler2D(decal_atlas_srgb, decal_sampler), uv_local.xz * decals.data[decal_index].emission_rect.zw + decals.data[decal_index].emission_rect.xy, 0.0).xyz * decals.data[decal_index].emission_energy * fade;
|
|
|
}
|
|
|
}
|
|
|
- } //Decals
|
|
|
+ }
|
|
|
#endif //!MODE_RENDER_DEPTH
|
|
|
|
|
|
/////////////////////// LIGHTING //////////////////////////////
|
|
|
|
|
|
#ifdef NORMAL_USED
|
|
|
- if (scene_data.roughness_limiter_enabled) {
|
|
|
+ if (sc_scene_roughness_limiter_enabled()) {
|
|
|
//https://www.jp.square-enix.com/tech/library/pdf/ImprovedGeometricSpecularAA.pdf
|
|
|
float roughness2 = roughness * roughness;
|
|
|
vec3 dndu = dFdx(normal), dndv = dFdy(normal);
|
|
@@ -1225,7 +1177,7 @@ void main() {
|
|
|
|
|
|
#ifndef AMBIENT_LIGHT_DISABLED
|
|
|
|
|
|
- if (scene_data.use_reflection_cubemap) {
|
|
|
+ if (sc_scene_use_reflection_cubemap()) {
|
|
|
#ifdef LIGHT_ANISOTROPY_USED
|
|
|
// https://google.github.io/filament/Filament.html#lighting/imagebasedlights/anisotropy
|
|
|
vec3 anisotropic_direction = anisotropy >= 0.0 ? binormal : tangent;
|
|
@@ -1266,7 +1218,7 @@ void main() {
|
|
|
if (scene_data.use_ambient_light) {
|
|
|
ambient_light = scene_data.ambient_light_color_energy.rgb;
|
|
|
|
|
|
- if (scene_data.use_ambient_cubemap) {
|
|
|
+ if (sc_scene_use_ambient_cubemap()) {
|
|
|
vec3 ambient_dir = scene_data.radiance_inverse_xform * normal;
|
|
|
#ifdef USE_RADIANCE_CUBEMAP_ARRAY
|
|
|
vec3 cubemap_ambient = texture(samplerCubeArray(radiance_cubemap, DEFAULT_SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP), vec4(ambient_dir, MAX_ROUGHNESS_LOD)).rgb;
|
|
@@ -1285,7 +1237,7 @@ void main() {
|
|
|
#endif // CUSTOM_IRRADIANCE_USED
|
|
|
#ifdef LIGHT_CLEARCOAT_USED
|
|
|
|
|
|
- if (scene_data.use_reflection_cubemap) {
|
|
|
+ if (sc_scene_use_reflection_cubemap()) {
|
|
|
vec3 n = normalize(normal_interp); // We want to use geometric normal, not normal_map
|
|
|
float NoV = max(dot(n, view), 0.0001);
|
|
|
vec3 ref_vec = reflect(-view, n);
|
|
@@ -1393,12 +1345,10 @@ void main() {
|
|
|
|
|
|
// skipping ssao, do we remove ssao totally?
|
|
|
|
|
|
- if (!sc_disable_reflection_probes()) { //Reflection probes
|
|
|
+ if (sc_reflection_probes() > 0) {
|
|
|
vec4 reflection_accum = vec4(0.0, 0.0, 0.0, 0.0);
|
|
|
vec4 ambient_accum = vec4(0.0, 0.0, 0.0, 0.0);
|
|
|
|
|
|
- uint reflection_indices = instances.data[draw_call.instance_index].reflection_probes.x;
|
|
|
-
|
|
|
#ifdef LIGHT_ANISOTROPY_USED
|
|
|
// https://google.github.io/filament/Filament.html#lighting/imagebasedlights/anisotropy
|
|
|
vec3 anisotropic_direction = anisotropy >= 0.0 ? binormal : tangent;
|
|
@@ -1411,18 +1361,9 @@ void main() {
|
|
|
vec3 ref_vec = normalize(reflect(-view, bent_normal));
|
|
|
ref_vec = mix(ref_vec, bent_normal, roughness * roughness);
|
|
|
|
|
|
- for (uint i = 0; i < 8; i++) {
|
|
|
- uint reflection_index = reflection_indices & 0xFF;
|
|
|
- if (i == 3) {
|
|
|
- reflection_indices = instances.data[draw_call.instance_index].reflection_probes.y;
|
|
|
- } else {
|
|
|
- reflection_indices = reflection_indices >> 8;
|
|
|
- }
|
|
|
-
|
|
|
- if (reflection_index == 0xFF) {
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
+ uvec2 reflection_indices = instances.data[draw_call.instance_index].reflection_probes;
|
|
|
+ for (uint i = 0; i < sc_reflection_probes(); i++) {
|
|
|
+ uint reflection_index = (i > 3) ? ((reflection_indices.y >> ((i - 4) * 8)) & 0xFF) : ((reflection_indices.x >> (i * 8)) & 0xFF);
|
|
|
reflection_process(reflection_index, vertex, ref_vec, bent_normal, roughness, ambient_light, specular_light, ambient_accum, reflection_accum);
|
|
|
}
|
|
|
|
|
@@ -1487,7 +1428,7 @@ void main() {
|
|
|
specular_light += specular_light_interp.rgb * f0;
|
|
|
#endif
|
|
|
|
|
|
- if (!sc_disable_directional_lights()) { //directional light
|
|
|
+ if (sc_directional_lights() > 0) {
|
|
|
#ifndef SHADOWS_DISABLED
|
|
|
// Do shadow and lighting in two passes to reduce register pressure
|
|
|
uint shadow0 = 0;
|
|
@@ -1497,7 +1438,7 @@ void main() {
|
|
|
// Only process the first light's shadow for vertex lighting.
|
|
|
for (uint i = 0; i < 1; i++) {
|
|
|
#else
|
|
|
- for (uint i = 0; i < scene_data.directional_light_count; i++) {
|
|
|
+ for (uint i = 0; i < sc_directional_lights(); i++) {
|
|
|
#endif
|
|
|
|
|
|
if (!bool(directional_lights.data[i].mask & instances.data[draw_call.instance_index].layer_mask)) {
|
|
@@ -1612,7 +1553,7 @@ void main() {
|
|
|
#endif // SHADOWS_DISABLED
|
|
|
|
|
|
#ifndef USE_VERTEX_LIGHTING
|
|
|
- for (uint i = 0; i < scene_data.directional_light_count; i++) {
|
|
|
+ for (uint i = 0; i < sc_directional_lights(); i++) {
|
|
|
if (!bool(directional_lights.data[i].mask & instances.data[draw_call.instance_index].layer_mask)) {
|
|
|
continue; //not masked
|
|
|
}
|
|
@@ -1678,95 +1619,72 @@ void main() {
|
|
|
} //directional light
|
|
|
|
|
|
#ifndef USE_VERTEX_LIGHTING
|
|
|
- if (!sc_disable_omni_lights()) { //omni lights
|
|
|
- uint light_indices = instances.data[draw_call.instance_index].omni_lights.x;
|
|
|
- for (uint i = 0; i < 8; i++) {
|
|
|
- uint light_index = light_indices & 0xFF;
|
|
|
- if (i == 3) {
|
|
|
- light_indices = instances.data[draw_call.instance_index].omni_lights.y;
|
|
|
- } else {
|
|
|
- light_indices = light_indices >> 8;
|
|
|
- }
|
|
|
-
|
|
|
- if (light_index == 0xFF) {
|
|
|
- break;
|
|
|
- }
|
|
|
+ uvec2 omni_indices = instances.data[draw_call.instance_index].omni_lights;
|
|
|
+ for (uint i = 0; i < sc_omni_lights(); i++) {
|
|
|
+ uint light_index = (i > 3) ? ((omni_indices.y >> ((i - 4) * 8)) & 0xFF) : ((omni_indices.x >> (i * 8)) & 0xFF);
|
|
|
|
|
|
- float shadow = light_process_omni_shadow(light_index, vertex, normal, scene_data.taa_frame_count);
|
|
|
+ float shadow = light_process_omni_shadow(light_index, vertex, normal, scene_data.taa_frame_count);
|
|
|
|
|
|
- shadow = blur_shadow(shadow);
|
|
|
+ shadow = blur_shadow(shadow);
|
|
|
|
|
|
- // Fragment lighting
|
|
|
- light_process_omni(light_index, vertex, view, normal, vertex_ddx, vertex_ddy, f0, orms, shadow, albedo, alpha,
|
|
|
+ // Fragment lighting
|
|
|
+ light_process_omni(light_index, vertex, view, normal, vertex_ddx, vertex_ddy, f0, orms, shadow, albedo, alpha,
|
|
|
#ifdef LIGHT_BACKLIGHT_USED
|
|
|
- backlight,
|
|
|
+ backlight,
|
|
|
#endif
|
|
|
/*
|
|
|
#ifdef LIGHT_TRANSMITTANCE_USED
|
|
|
- transmittance_color,
|
|
|
- transmittance_depth,
|
|
|
- transmittance_boost,
|
|
|
+ transmittance_color,
|
|
|
+ transmittance_depth,
|
|
|
+ transmittance_boost,
|
|
|
#endif
|
|
|
*/
|
|
|
#ifdef LIGHT_RIM_USED
|
|
|
- rim,
|
|
|
- rim_tint,
|
|
|
+ rim,
|
|
|
+ rim_tint,
|
|
|
#endif
|
|
|
#ifdef LIGHT_CLEARCOAT_USED
|
|
|
- clearcoat, clearcoat_roughness, normalize(normal_interp),
|
|
|
+ clearcoat, clearcoat_roughness, normalize(normal_interp),
|
|
|
#endif
|
|
|
#ifdef LIGHT_ANISOTROPY_USED
|
|
|
- tangent,
|
|
|
- binormal, anisotropy,
|
|
|
+ tangent,
|
|
|
+ binormal, anisotropy,
|
|
|
#endif
|
|
|
- diffuse_light, specular_light);
|
|
|
- }
|
|
|
- } //omni lights
|
|
|
-
|
|
|
- if (!sc_disable_spot_lights()) { //spot lights
|
|
|
-
|
|
|
- uint light_indices = instances.data[draw_call.instance_index].spot_lights.x;
|
|
|
- for (uint i = 0; i < 8; i++) {
|
|
|
- uint light_index = light_indices & 0xFF;
|
|
|
- if (i == 3) {
|
|
|
- light_indices = instances.data[draw_call.instance_index].spot_lights.y;
|
|
|
- } else {
|
|
|
- light_indices = light_indices >> 8;
|
|
|
- }
|
|
|
+ diffuse_light, specular_light);
|
|
|
+ }
|
|
|
|
|
|
- if (light_index == 0xFF) {
|
|
|
- break;
|
|
|
- }
|
|
|
+ uvec2 spot_indices = instances.data[draw_call.instance_index].spot_lights;
|
|
|
+ for (uint i = 0; i < sc_spot_lights(); i++) {
|
|
|
+ uint light_index = (i > 3) ? ((spot_indices.y >> ((i - 4) * 8)) & 0xFF) : ((spot_indices.x >> (i * 8)) & 0xFF);
|
|
|
|
|
|
- float shadow = light_process_spot_shadow(light_index, vertex, normal, scene_data.taa_frame_count);
|
|
|
+ float shadow = light_process_spot_shadow(light_index, vertex, normal, scene_data.taa_frame_count);
|
|
|
|
|
|
- shadow = blur_shadow(shadow);
|
|
|
+ shadow = blur_shadow(shadow);
|
|
|
|
|
|
- light_process_spot(light_index, vertex, view, normal, vertex_ddx, vertex_ddy, f0, orms, shadow, albedo, alpha,
|
|
|
+ light_process_spot(light_index, vertex, view, normal, vertex_ddx, vertex_ddy, f0, orms, shadow, albedo, alpha,
|
|
|
#ifdef LIGHT_BACKLIGHT_USED
|
|
|
- backlight,
|
|
|
+ backlight,
|
|
|
#endif
|
|
|
/*
|
|
|
#ifdef LIGHT_TRANSMITTANCE_USED
|
|
|
- transmittance_color,
|
|
|
- transmittance_depth,
|
|
|
- transmittance_boost,
|
|
|
+ transmittance_color,
|
|
|
+ transmittance_depth,
|
|
|
+ transmittance_boost,
|
|
|
#endif
|
|
|
*/
|
|
|
#ifdef LIGHT_RIM_USED
|
|
|
- rim,
|
|
|
- rim_tint,
|
|
|
+ rim,
|
|
|
+ rim_tint,
|
|
|
#endif
|
|
|
#ifdef LIGHT_CLEARCOAT_USED
|
|
|
- clearcoat, clearcoat_roughness, normalize(normal_interp),
|
|
|
+ clearcoat, clearcoat_roughness, normalize(normal_interp),
|
|
|
#endif
|
|
|
#ifdef LIGHT_ANISOTROPY_USED
|
|
|
- tangent,
|
|
|
- binormal, anisotropy,
|
|
|
+ tangent,
|
|
|
+ binormal, anisotropy,
|
|
|
#endif
|
|
|
- diffuse_light, specular_light);
|
|
|
- }
|
|
|
- } //spot lights
|
|
|
+ diffuse_light, specular_light);
|
|
|
+ }
|
|
|
#endif // !VERTEX_LIGHTING
|
|
|
|
|
|
#endif //!defined(MODE_RENDER_DEPTH) && !defined(MODE_UNSHADED)
|