From 9441608623a2692263191c254db23765eefa2cef Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Mon, 6 May 2024 10:07:02 -0700 Subject: secondlife/viewer#907: Local PBR terrain texture transforms --- .../shaders/class1/deferred/pbrterrainF.glsl | 93 +++++++++++--- .../shaders/class1/deferred/pbrterrainUtilF.glsl | 19 ++- .../shaders/class1/deferred/pbrterrainV.glsl | 135 ++++++++++++++++----- .../shaders/class1/deferred/textureUtilV.glsl | 39 ++++++ 4 files changed, 228 insertions(+), 58 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl index de4745c1c4..65a6b8613d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl @@ -31,7 +31,7 @@ #define TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS -3 #if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3 -#define TerrainCoord vec4[2] +#define TerrainCoord vec4[3] #elif TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 1 #define TerrainCoord vec2 #endif @@ -131,12 +131,16 @@ uniform vec3[4] emissiveColors; uniform vec4 minimum_alphas; // PBR alphaMode: MASK, See: mAlphaCutoff, setAlphaCutoff() #if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3 +in vec4[10] vary_coords; +#elif TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 1 in vec4[2] vary_coords; #endif in vec3 vary_position; in vec3 vary_normal; -in vec3 vary_tangent; +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL) +in vec3 vary_tangents[4]; flat in float vary_sign; +#endif in vec4 vary_texcoord0; in vec4 vary_texcoord1; @@ -144,17 +148,26 @@ void mirrorClip(vec3 position); float terrain_mix(TerrainMix tm, vec4 tms4); +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL) +// from mikktspace.com +vec3 mikktspace(vec3 vNt, vec3 vT) +{ + vec3 vN = vary_normal; + + vec3 vB = vary_sign * cross(vN, vT); + vec3 tnorm = normalize( vNt.x * vT + vNt.y * vB + vNt.z * vN ); + + tnorm *= gl_FrontFacing ? 1.0 : -1.0; + + return tnorm; +} +#endif + void main() { // Make sure we clip the terrain if we're in a mirror. mirrorClip(vary_position); -#if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3 - TerrainCoord terrain_texcoord = vary_coords; -#elif TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 1 - TerrainCoord terrain_texcoord = vary_texcoord0.xy; -#endif - float alpha1 = texture(alpha_ramp, vary_texcoord0.zw).a; float alpha2 = texture(alpha_ramp,vary_texcoord1.xy).a; float alphaFinal = texture(alpha_ramp, vary_texcoord1.zw).a; @@ -185,6 +198,16 @@ void main() switch (tm.type & MIX_X) { case MIX_X: +#if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3 + TerrainCoord terrain_texcoord; + terrain_texcoord[0].xy = vary_coords[0].xy; + terrain_texcoord[0].zw = vary_coords[0].zw; + terrain_texcoord[1].xy = vary_coords[1].xy; + terrain_texcoord[1].zw = vary_coords[1].zw; + terrain_texcoord[2].xy = vary_coords[2].xy; +#elif TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 1 + TerrainCoord terrain_texcoord = vary_coords[0].xy; +#endif mix2 = terrain_sample_and_multiply_pbr( terrain_texcoord , detail_0_base_color @@ -207,6 +230,9 @@ void main() , emissiveColors[0] #endif ); +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL) + mix2.vNt = mikktspace(mix2.vNt, vary_tangents[0]); +#endif mix = mix_pbr(mix, mix2, tm.weight.x); break; default: @@ -215,6 +241,16 @@ void main() switch (tm.type & MIX_Y) { case MIX_Y: +#if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3 + TerrainCoord terrain_texcoord; + terrain_texcoord[0].xy = vary_coords[2].zw; + terrain_texcoord[0].zw = vary_coords[3].xy; + terrain_texcoord[1].xy = vary_coords[3].zw; + terrain_texcoord[1].zw = vary_coords[4].xy; + terrain_texcoord[2].xy = vary_coords[4].zw; +#elif TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 1 + TerrainCoord terrain_texcoord = vary_coords[0].zw; +#endif mix2 = terrain_sample_and_multiply_pbr( terrain_texcoord , detail_1_base_color @@ -237,6 +273,9 @@ void main() , emissiveColors[1] #endif ); +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL) + mix2.vNt = mikktspace(mix2.vNt, vary_tangents[1]); +#endif mix = mix_pbr(mix, mix2, tm.weight.y); break; default: @@ -245,6 +284,16 @@ void main() switch (tm.type & MIX_Z) { case MIX_Z: +#if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3 + TerrainCoord terrain_texcoord; + terrain_texcoord[0].xy = vary_coords[5].xy; + terrain_texcoord[0].zw = vary_coords[5].zw; + terrain_texcoord[1].xy = vary_coords[6].xy; + terrain_texcoord[1].zw = vary_coords[6].zw; + terrain_texcoord[2].xy = vary_coords[7].xy; +#elif TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 1 + TerrainCoord terrain_texcoord = vary_coords[1].xy; +#endif mix2 = terrain_sample_and_multiply_pbr( terrain_texcoord , detail_2_base_color @@ -267,6 +316,9 @@ void main() , emissiveColors[2] #endif ); +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL) + mix2.vNt = mikktspace(mix2.vNt, vary_tangents[2]); +#endif mix = mix_pbr(mix, mix2, tm.weight.z); break; default: @@ -275,6 +327,16 @@ void main() switch (tm.type & MIX_W) { case MIX_W: +#if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3 + TerrainCoord terrain_texcoord; + terrain_texcoord[0].xy = vary_coords[7].zw; + terrain_texcoord[0].zw = vary_coords[8].xy; + terrain_texcoord[1].xy = vary_coords[8].zw; + terrain_texcoord[1].zw = vary_coords[9].xy; + terrain_texcoord[2].xy = vary_coords[9].zw; +#elif TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 1 + TerrainCoord terrain_texcoord = vary_coords[1].zw; +#endif mix2 = terrain_sample_and_multiply_pbr( terrain_texcoord , detail_3_base_color @@ -297,6 +359,9 @@ void main() , emissiveColors[3] #endif ); +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL) + mix2.vNt = mikktspace(mix2.vNt, vary_tangents[3]); +#endif mix = mix_pbr(mix, mix2, tm.weight.w); break; default: @@ -311,19 +376,11 @@ void main() float base_color_factor_alpha = terrain_mix(tm, vec4(baseColorFactors[0].z, baseColorFactors[1].z, baseColorFactors[2].z, baseColorFactors[3].z)); #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL) - // from mikktspace.com - vec3 vNt = mix.vNt; - vec3 vN = vary_normal; - vec3 vT = vary_tangent.xyz; - - vec3 vB = vary_sign * cross(vN, vT); - vec3 tnorm = normalize( vNt.x * vT + vNt.y * vB + vNt.z * vN ); - - tnorm *= gl_FrontFacing ? 1.0 : -1.0; + vec3 tnorm = normalize(mix.vNt); #else vec3 tnorm = vary_normal; - tnorm *= gl_FrontFacing ? 1.0 : -1.0; #endif + tnorm *= gl_FrontFacing ? 1.0 : -1.0; #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl index 935c3f9301..7a7fd783ec 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl @@ -233,17 +233,12 @@ float terrain_mix(TerrainMix tm, vec4 tms4) // Triplanar mapping // Pre-transformed texture coordinates for each axial uv slice (Packing: xy, yz, (-x)z, unused) -#define TerrainCoord vec4[2] +#define TerrainCoord vec4[3] -vec2 _t_uv(vec2 uv_unflipped, float sign_or_zero) +// If sign_or_zero is positive, use uv_unflippped, otherwise use uv_flipped +vec2 _t_uv(vec2 uv_unflipped, vec2 uv_flipped, float sign_or_zero) { - // Handle case where sign is 0 - float sign = (2.0*sign_or_zero) + 1.0; - sign /= abs(sign); - // If the vertex normal is negative, flip the texture back - // right-side up. - vec2 uv = uv_unflipped * vec2(sign, 1); - return uv; + return mix(uv_flipped, uv_unflipped, max(0.0, sign_or_zero)); } vec3 _t_normal_post_1(vec3 vNt0, float sign_or_zero) @@ -298,9 +293,9 @@ PBRMix terrain_sample_pbr( { PBRMix mix = init_pbr_mix(); -#define get_uv_x() _t_uv(terrain_coord[0].zw, sign(vary_vertex_normal.x)) -#define get_uv_y() _t_uv(terrain_coord[1].xy, sign(vary_vertex_normal.y)) -#define get_uv_z() _t_uv(terrain_coord[0].xy, sign(vary_vertex_normal.z)) +#define get_uv_x() _t_uv(terrain_coord[0].zw, terrain_coord[1].zw, sign(vary_vertex_normal.x)) +#define get_uv_y() _t_uv(terrain_coord[1].xy, terrain_coord[2].xy, sign(vary_vertex_normal.y)) +#define get_uv_z() _t_uv(terrain_coord[0].xy, vec2(0), sign(vary_vertex_normal.z)) switch (tw.type & SAMPLE_X) { case SAMPLE_X: diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl index 489fc26e3f..167d980eb8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl @@ -23,6 +23,11 @@ * $/LicenseInfo$ */ +#define TERRAIN_PBR_DETAIL_EMISSIVE 0 +#define TERRAIN_PBR_DETAIL_OCCLUSION -1 +#define TERRAIN_PBR_DETAIL_NORMAL -2 +#define TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS -3 + uniform mat3 normal_matrix; uniform mat4 texture_matrix0; uniform mat4 modelview_matrix; @@ -34,24 +39,28 @@ in vec4 tangent; in vec4 diffuse_color; in vec2 texcoord1; -#if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3 -out vec4[2] vary_coords; -#endif out vec3 vary_vertex_normal; // Used by pbrterrainUtilF.glsl out vec3 vary_normal; -out vec3 vary_tangent; +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL) +out vec3 vary_tangents[4]; flat out float vary_sign; +#endif out vec4 vary_texcoord0; out vec4 vary_texcoord1; +#if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3 +out vec4[10] vary_coords; +#elif TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 1 +out vec4[2] vary_coords; +#endif out vec3 vary_position; -// *HACK: tangent_space_transform should use texture_normal_transform, or maybe -// we shouldn't use tangent_space_transform at all. See the call to -// tangent_space_transform below. -uniform vec4[2] texture_base_color_transform; +// *HACK: Each material uses only one texture transform, but the KHR texture +// transform spec allows handling texture transforms separately for each +// individual texture info. +uniform vec4[5] terrain_texture_transforms; -vec2 texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform, mat4 sl_animation_transform); -vec3 tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] khr_gltf_transform, mat4 sl_animation_transform); +vec2 terrain_texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform); +vec3 terrain_tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] khr_gltf_transform); void main() { @@ -63,31 +72,101 @@ void main() vary_vertex_normal = normal; vec3 t = normal_matrix * tangent.xyz; - vary_tangent = normalize(t); - // *TODO: Decide if we want this. It may be better to just calculate the - // tangents on-the-fly in the fragment shader, due to the subtleties of the - // effect of triplanar mapping on UVs. - // *HACK: Should be using texture_normal_transform here. The KHR texture - // transform spec requires handling texture transforms separately for each - // individual texture. - vary_tangent = normalize(tangent_space_transform(vec4(t, tangent.w), n, texture_base_color_transform, texture_matrix0)); +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL) + { + vec4[2] ttt; + // material 1 + ttt[0].xyz = terrain_texture_transforms[0].xyz; + ttt[1].x = terrain_texture_transforms[0].w; + ttt[1].y = terrain_texture_transforms[1].x; + vary_tangents[0] = normalize(terrain_tangent_space_transform(vec4(t, tangent.w), n, ttt)); + // material 2 + ttt[0].xyz = terrain_texture_transforms[1].yzw; + ttt[1].xy = terrain_texture_transforms[2].xy; + vary_tangents[1] = normalize(terrain_tangent_space_transform(vec4(t, tangent.w), n, ttt)); + // material 3 + ttt[0].xy = terrain_texture_transforms[2].zw; + ttt[0].z = terrain_texture_transforms[3].x; + ttt[1].xy = terrain_texture_transforms[3].yz; + vary_tangents[2] = normalize(terrain_tangent_space_transform(vec4(t, tangent.w), n, ttt)); + // material 4 + ttt[0].x = terrain_texture_transforms[3].w; + ttt[0].yz = terrain_texture_transforms[4].xy; + ttt[1].xy = terrain_texture_transforms[4].zw; + vary_tangents[3] = normalize(terrain_tangent_space_transform(vec4(t, tangent.w), n, ttt)); + } + vary_sign = tangent.w; +#endif vary_normal = normalize(n); // Transform and pass tex coords - // *HACK: texture_base_color_transform is used for all of these here, but - // the KHR texture transform spec requires handling texture transforms - // separately for each individual texture. + { + vec4[2] ttt; #if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3 - // xy - vary_coords[0].xy = texture_transform(position.xy, texture_base_color_transform, texture_matrix0); - // yz - vary_coords[0].zw = texture_transform(position.yz, texture_base_color_transform, texture_matrix0); - // (-x)z - vary_coords[1].xy = texture_transform(position.xz * vec2(-1, 1), texture_base_color_transform, texture_matrix0); +// Don't care about upside-down (transform_xy_flipped()) +#define transform_xy() terrain_texture_transform(position.xy, ttt) +#define transform_yz() terrain_texture_transform(position.yz, ttt) +#define transform_negx_z() terrain_texture_transform(position.xz * vec2(-1, 1), ttt) +#define transform_yz_flipped() terrain_texture_transform(position.yz * vec2(-1, 1), ttt) +#define transform_negx_z_flipped() terrain_texture_transform(position.xz, ttt) + // material 1 + ttt[0].xyz = terrain_texture_transforms[0].xyz; + ttt[1].x = terrain_texture_transforms[0].w; + ttt[1].y = terrain_texture_transforms[1].x; + vary_coords[0].xy = transform_xy(); + vary_coords[0].zw = transform_yz(); + vary_coords[1].xy = transform_negx_z(); + vary_coords[1].zw = transform_yz_flipped(); + vary_coords[2].xy = transform_negx_z_flipped(); + // material 2 + ttt[0].xyz = terrain_texture_transforms[1].yzw; + ttt[1].xy = terrain_texture_transforms[2].xy; + vary_coords[2].zw = transform_xy(); + vary_coords[3].xy = transform_yz(); + vary_coords[3].zw = transform_negx_z(); + vary_coords[4].xy = transform_yz_flipped(); + vary_coords[4].zw = transform_negx_z_flipped(); + // material 3 + ttt[0].xy = terrain_texture_transforms[2].zw; + ttt[0].z = terrain_texture_transforms[3].x; + ttt[1].xy = terrain_texture_transforms[3].yz; + vary_coords[5].xy = transform_xy(); + vary_coords[5].zw = transform_yz(); + vary_coords[6].xy = transform_negx_z(); + vary_coords[6].zw = transform_yz_flipped(); + vary_coords[7].xy = transform_negx_z_flipped(); + // material 4 + ttt[0].x = terrain_texture_transforms[3].w; + ttt[0].yz = terrain_texture_transforms[4].xy; + ttt[1].xy = terrain_texture_transforms[4].zw; + vary_coords[7].zw = transform_xy(); + vary_coords[8].xy = transform_yz(); + vary_coords[8].zw = transform_negx_z(); + vary_coords[9].xy = transform_yz_flipped(); + vary_coords[9].zw = transform_negx_z_flipped(); #elif TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 1 - vary_texcoord0.xy = texture_transform(position.xy, texture_base_color_transform, texture_matrix0); + // material 1 + ttt[0].xyz = terrain_texture_transforms[0].xyz; + ttt[1].x = terrain_texture_transforms[0].w; + ttt[1].y = terrain_texture_transforms[1].x; + vary_coords[0].xy = terrain_texture_transform(position.xy, ttt); + // material 2 + ttt[0].xyz = terrain_texture_transforms[1].yzw; + ttt[1].xy = terrain_texture_transforms[2].xy; + vary_coords[0].zw = terrain_texture_transform(position.xy, ttt); + // material 3 + ttt[0].xy = terrain_texture_transforms[2].zw; + ttt[0].z = terrain_texture_transforms[3].x; + ttt[1].xy = terrain_texture_transforms[3].yz; + vary_coords[1].xy = terrain_texture_transform(position.xy, ttt); + // material 4 + ttt[0].x = terrain_texture_transforms[3].w; + ttt[0].yz = terrain_texture_transforms[4].xy; + ttt[1].xy = terrain_texture_transforms[4].zw; + vary_coords[1].zw = terrain_texture_transform(position.xy, ttt); #endif + } vec4 tc = vec4(texcoord1,0,1); vary_texcoord0.zw = tc.xy; diff --git a/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl b/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl index 732333311c..baf4010fa7 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl @@ -48,6 +48,7 @@ vec2 khr_texture_transform(vec2 texcoord, vec2 scale, float rotation, vec2 offse return (transform * vec3(texcoord, 1)).xy; } +// A texture transform function for PBR materials applied to shape prims/Collada model prims // vertex_texcoord - The UV texture coordinates sampled from the vertex at // runtime. Per SL convention, this is in a right-handed UV coordinate // system. Collada models also have right-handed UVs. @@ -77,6 +78,21 @@ vec2 texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform, mat4 sl return texcoord; } +// Similar to texture_transform but no offset during coordinate system +// conversion, and no texture animation support. +vec2 terrain_texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform) +{ + vec2 texcoord = vertex_texcoord; + + texcoord.y = 1.0 - texcoord.y; + //texcoord.y = -texcoord.y; + texcoord = khr_texture_transform(texcoord, khr_gltf_transform[0].xy, khr_gltf_transform[0].z, khr_gltf_transform[1].xy); + texcoord.y = 1.0 - texcoord.y; + //texcoord.y = -texcoord.y; + + return texcoord; +} + // Take the rotation only from both transforms and apply to the tangent. This // accounts for the change of the topology of the normal texture when a texture // rotation is applied to it. @@ -120,3 +136,26 @@ vec3 tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] kh return (weights.x * vertex_binormal.xyz) + (weights.y * vertex_tangent.xyz); } + +// Similar to tangent_space_transform but no offset during coordinate system +// conversion, and no texture animation support. +vec3 terrain_tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] khr_gltf_transform) +{ + // Immediately convert to left-handed coordinate system ((0,1) -> (0, -1)) + vec2 weights = vec2(0, -1); + + // Apply KHR_texture_transform (rotation only) + float khr_rotation = khr_gltf_transform[0].z; + mat2 khr_rotation_mat = mat2( + cos(khr_rotation),-sin(khr_rotation), + sin(khr_rotation), cos(khr_rotation) + ); + weights = khr_rotation_mat * weights; + + // Convert back to right-handed coordinate system + weights.y = -weights.y; + + vec3 vertex_binormal = vertex_tangent.w * cross(vertex_normal, vertex_tangent.xyz); + + return (weights.x * vertex_binormal.xyz) + (weights.y * vertex_tangent.xyz); +} -- cgit v1.2.3 From 124c58901ddf9622eba90986336f1eaf15013b06 Mon Sep 17 00:00:00 2001 From: Brad Linden Date: Tue, 14 May 2024 11:59:38 -0700 Subject: Fix shader error on mac: 'Redeclaration of sized array 'terrain_texcoord' not allowed' --- .../app_settings/shaders/class1/deferred/pbrterrainF.glsl | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl index 65a6b8613d..f57d7eb7eb 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl @@ -242,14 +242,13 @@ void main() { case MIX_Y: #if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3 - TerrainCoord terrain_texcoord; terrain_texcoord[0].xy = vary_coords[2].zw; terrain_texcoord[0].zw = vary_coords[3].xy; terrain_texcoord[1].xy = vary_coords[3].zw; terrain_texcoord[1].zw = vary_coords[4].xy; terrain_texcoord[2].xy = vary_coords[4].zw; #elif TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 1 - TerrainCoord terrain_texcoord = vary_coords[0].zw; + terrain_texcoord = vary_coords[0].zw; #endif mix2 = terrain_sample_and_multiply_pbr( terrain_texcoord @@ -285,14 +284,13 @@ void main() { case MIX_Z: #if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3 - TerrainCoord terrain_texcoord; terrain_texcoord[0].xy = vary_coords[5].xy; terrain_texcoord[0].zw = vary_coords[5].zw; terrain_texcoord[1].xy = vary_coords[6].xy; terrain_texcoord[1].zw = vary_coords[6].zw; terrain_texcoord[2].xy = vary_coords[7].xy; #elif TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 1 - TerrainCoord terrain_texcoord = vary_coords[1].xy; + terrain_texcoord = vary_coords[1].xy; #endif mix2 = terrain_sample_and_multiply_pbr( terrain_texcoord @@ -328,14 +326,13 @@ void main() { case MIX_W: #if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3 - TerrainCoord terrain_texcoord; terrain_texcoord[0].xy = vary_coords[7].zw; terrain_texcoord[0].zw = vary_coords[8].xy; terrain_texcoord[1].xy = vary_coords[8].zw; terrain_texcoord[1].zw = vary_coords[9].xy; terrain_texcoord[2].xy = vary_coords[9].zw; #elif TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 1 - TerrainCoord terrain_texcoord = vary_coords[1].zw; + terrain_texcoord = vary_coords[1].zw; #endif mix2 = terrain_sample_and_multiply_pbr( terrain_texcoord -- cgit v1.2.3 From 28563eb8fe76c723aa583f72a34cb5d44998fb3d Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Wed, 15 May 2024 14:52:47 -0700 Subject: secondlife/viewer#1474: Fix broken shader compilation --- indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl index f57d7eb7eb..2efd50a46a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl @@ -195,18 +195,18 @@ void main() PBRMix mix = init_pbr_mix(); PBRMix mix2; + TerrainCoord terrain_texcoord; switch (tm.type & MIX_X) { case MIX_X: #if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3 - TerrainCoord terrain_texcoord; terrain_texcoord[0].xy = vary_coords[0].xy; terrain_texcoord[0].zw = vary_coords[0].zw; terrain_texcoord[1].xy = vary_coords[1].xy; terrain_texcoord[1].zw = vary_coords[1].zw; terrain_texcoord[2].xy = vary_coords[2].xy; #elif TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 1 - TerrainCoord terrain_texcoord = vary_coords[0].xy; + terrain_texcoord = vary_coords[0].xy; #endif mix2 = terrain_sample_and_multiply_pbr( terrain_texcoord -- cgit v1.2.3 From 6e501c5a1ae956e13d3ba3ba05ea8954d25bbc55 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Wed, 15 May 2024 15:15:34 -0700 Subject: secondlife/viewer#1474: Remove small texture offset from PBR terrain --- .../newview/app_settings/shaders/class1/deferred/textureUtilV.glsl | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl b/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl index baf4010fa7..bf5d106dab 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl @@ -84,11 +84,9 @@ vec2 terrain_texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform) { vec2 texcoord = vertex_texcoord; - texcoord.y = 1.0 - texcoord.y; - //texcoord.y = -texcoord.y; + texcoord.y = -texcoord.y; texcoord = khr_texture_transform(texcoord, khr_gltf_transform[0].xy, khr_gltf_transform[0].z, khr_gltf_transform[1].xy); - texcoord.y = 1.0 - texcoord.y; - //texcoord.y = -texcoord.y; + texcoord.y = -texcoord.y; return texcoord; } -- cgit v1.2.3 From e1493a10b46bb53af165e4f23fda0fedd3193269 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Fri, 17 May 2024 15:45:07 +0300 Subject: viewer#1501 Crash initiating screenSpaceReflUtil.glsl Error: Function return is not matching type --- .../app_settings/shaders/class1/deferred/screenSpaceReflUtil.glsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflUtil.glsl index 1a85d70256..6791fe44d9 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflUtil.glsl @@ -27,11 +27,11 @@ float random (vec2 uv) { - return 0; + return 0.f; } float tapScreenSpaceReflection(int totalSamples, vec2 tc, vec3 viewPos, vec3 n, inout vec4 collectedColor, sampler2D source, float glossiness) { collectedColor = vec4(0); - return 0; + return 0.f; } -- cgit v1.2.3 From 2f4120038429c6aff865f153f708ceefb60d67f4 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 28 May 2024 09:45:40 -0500 Subject: Remove tinygltf dependency from LL::GLTF (#1541) * #1535 Image loading/saving support in boost::json driven GLTF parser * #1536 GLB Support in boost::json drvien GLTF parser --- .../shaders/class1/gltf/pbrmetallicroughnessF.glsl | 117 +++++++++++++++++++++ .../shaders/class1/gltf/pbrmetallicroughnessV.glsl | 106 +++++++++++++++++++ 2 files changed, 223 insertions(+) create mode 100644 indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessF.glsl create mode 100644 indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessV.glsl (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessF.glsl b/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessF.glsl new file mode 100644 index 0000000000..dbee58b76a --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessF.glsl @@ -0,0 +1,117 @@ +/** + * @file pbrmetallicroughnessF.glsl + * + * $LicenseInfo:firstyear=2024&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2022, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +/*[EXTRA_CODE_HERE]*/ + + +// GLTF pbrMetallicRoughness implementation + +uniform sampler2D diffuseMap; //always in sRGB space + +uniform float metallicFactor; +uniform float roughnessFactor; +uniform vec3 emissiveColor; +uniform sampler2D bumpMap; +uniform sampler2D emissiveMap; +uniform sampler2D specularMap; // Packed: Occlusion, Metal, Roughness + +out vec4 frag_data[4]; + +in vec3 vary_position; +in vec4 vertex_color; +in vec3 vary_normal; +in vec3 vary_tangent; +flat in float vary_sign; + +in vec2 base_color_texcoord; +in vec2 normal_texcoord; +in vec2 metallic_roughness_texcoord; +in vec2 emissive_texcoord; + +uniform float minimum_alpha; // PBR alphaMode: MASK, See: mAlphaCutoff, setAlphaCutoff() + +vec3 linear_to_srgb(vec3 c); +vec3 srgb_to_linear(vec3 c); + +uniform vec4 clipPlane; +uniform float clipSign; + +void mirrorClip(vec3 pos); + +uniform mat3 normal_matrix; + +void main() +{ + mirrorClip(vary_position); + + vec4 basecolor = texture(diffuseMap, base_color_texcoord.xy).rgba; + basecolor.rgb = srgb_to_linear(basecolor.rgb); + + basecolor *= vertex_color; + + if (basecolor.a < minimum_alpha) + { + discard; + } + + vec3 col = basecolor.rgb; + + // from mikktspace.com + vec3 vNt = texture(bumpMap, normal_texcoord.xy).xyz*2.0-1.0; + float sign = vary_sign; + vec3 vN = vary_normal; + vec3 vT = vary_tangent.xyz; + + vec3 vB = sign * cross(vN, vT); + vec3 tnorm = normalize( vNt.x * vT + vNt.y * vB + vNt.z * vN ); + + // RGB = Occlusion, Roughness, Metal + // default values, see LLViewerTexture::sDefaultPBRORMImagep + // occlusion 1.0 + // roughness 0.0 + // metal 0.0 + vec3 spec = texture(specularMap, metallic_roughness_texcoord.xy).rgb; + + spec.g *= roughnessFactor; + spec.b *= metallicFactor; + + vec3 emissive = emissiveColor; + emissive *= srgb_to_linear(texture(emissiveMap, emissive_texcoord.xy).rgb); + + tnorm *= gl_FrontFacing ? 1.0 : -1.0; + + //spec.rgb = vec3(1,1,0); + //col = vec3(0,0,0); + //emissive = vary_tangent.xyz*0.5+0.5; + //emissive = vec3(sign*0.5+0.5); + //emissive = vNt * 0.5 + 0.5; + //emissive = tnorm*0.5+0.5; + // See: C++: addDeferredAttachments(), GLSL: softenLightF + frag_data[0] = max(vec4(col, 0.0), vec4(0)); // Diffuse + frag_data[1] = max(vec4(spec.rgb,0.0), vec4(0)); // PBR linear packed Occlusion, Roughness, Metal. + frag_data[2] = vec4(tnorm, GBUFFER_FLAG_HAS_PBR); // normal, environment intensity, flags + frag_data[3] = max(vec4(emissive,0), vec4(0)); // PBR sRGB Emissive +} + diff --git a/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessV.glsl b/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessV.glsl new file mode 100644 index 0000000000..0add509002 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessV.glsl @@ -0,0 +1,106 @@ +/** + * @file pbrmetallicroughnessV.glsl + * + * $LicenseInfo:firstyear=2024&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2022, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +// GLTF pbrMetallicRoughness implementation + +uniform mat4 modelview_matrix; + +#ifdef HAS_SKIN +uniform mat4 projection_matrix; +mat4 getObjectSkinnedTransform(); +#else +uniform mat3 normal_matrix; +uniform mat4 modelview_projection_matrix; +#endif +uniform mat4 texture_matrix0; + +uniform vec4[2] texture_base_color_transform; +uniform vec4[2] texture_normal_transform; +uniform vec4[2] texture_metallic_roughness_transform; +uniform vec4[2] texture_emissive_transform; + +in vec3 position; +in vec4 diffuse_color; +in vec3 normal; +in vec4 tangent; +in vec2 texcoord0; + +out vec2 base_color_texcoord; +out vec2 normal_texcoord; +out vec2 metallic_roughness_texcoord; +out vec2 emissive_texcoord; + +out vec4 vertex_color; + +out vec3 vary_tangent; +flat out float vary_sign; +out vec3 vary_normal; +out vec3 vary_position; + +vec2 texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform, mat4 sl_animation_transform); +vec3 tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] khr_gltf_transform, mat4 sl_animation_transform); + +void main() +{ +#ifdef HAS_SKIN + mat4 mat = getObjectSkinnedTransform(); + + mat = modelview_matrix * mat; + + vec3 pos = (mat*vec4(position.xyz,1.0)).xyz; + vary_position = pos; + gl_Position = projection_matrix*vec4(pos,1.0); + +#else + vary_position = (modelview_matrix*vec4(position.xyz, 1.0)).xyz; + //transform vertex + gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); +#endif + + base_color_texcoord = texture_transform(texcoord0, texture_base_color_transform, texture_matrix0); + normal_texcoord = texture_transform(texcoord0, texture_normal_transform, texture_matrix0); + metallic_roughness_texcoord = texture_transform(texcoord0, texture_metallic_roughness_transform, texture_matrix0); + emissive_texcoord = texture_transform(texcoord0, texture_emissive_transform, texture_matrix0); + +#ifdef HAS_SKIN + vec3 n = (mat*vec4(normal.xyz+position.xyz,1.0)).xyz-pos.xyz; + vec3 t = (mat*vec4(tangent.xyz+position.xyz,1.0)).xyz-pos.xyz; +#else //HAS_SKIN + vec3 n = normal_matrix * normal; + vec3 t = normal_matrix * tangent.xyz; +#endif + + n = normalize(n); + + vary_tangent = normalize(tangent_space_transform(vec4(t, tangent.w), n, texture_normal_transform, texture_matrix0)); + vary_sign = tangent.w; + vary_normal = n; + + vertex_color = diffuse_color; +} + + + + -- cgit v1.2.3 From 15fd13f83036ff781160957a21bb2d59771044bc Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 29 May 2024 16:56:39 -0500 Subject: #1530 Increase joint limit for GLTF Assets (#1582) * Migrate GLTF scene rendering to its own shaders * Add support for ambient occlusion map separate from metallic roughness map (or absent) * Use UBO's for GLTF joints * Better error handling of downloading GLTF assets --- .../shaders/class1/deferred/deferredUtil.glsl | 37 +++++ .../shaders/class1/deferred/pbralphaV.glsl | 4 +- .../shaders/class1/gltf/pbrmetallicroughnessF.glsl | 185 ++++++++++++++++++--- .../shaders/class1/gltf/pbrmetallicroughnessV.glsl | 74 ++++++++- .../shaders/class2/deferred/pbralphaF.glsl | 58 ++----- .../shaders/class3/deferred/materialF.glsl | 1 - 6 files changed, 282 insertions(+), 77 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl index 385920f622..8b23037934 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl @@ -496,6 +496,43 @@ vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, return clamp(color, vec3(0), vec3(10)); } +vec3 pbrCalcPointLightOrSpotLight(vec3 diffuseColor, vec3 specularColor, + float perceptualRoughness, + float metallic, + vec3 n, // normal + vec3 p, // pixel position + vec3 v, // view vector (negative normalized pixel position) + vec3 lp, // light position + vec3 ld, // light direction (for spotlights) + vec3 lightColor, + float lightSize, float falloff, float is_pointlight, float ambiance) +{ + vec3 color = vec3(0,0,0); + + vec3 lv = lp.xyz - p; + + float lightDist = length(lv); + + float dist = lightDist / lightSize; + if (dist <= 1.0) + { + lv /= lightDist; + + float dist_atten = calcLegacyDistanceAttenuation(dist, falloff); + + // spotlight coefficient. + float spot = max(dot(-ld, lv), is_pointlight); + // spot*spot => GL_SPOT_EXPONENT=2 + float spot_atten = spot*spot; + + vec3 intensity = spot_atten * dist_atten * lightColor * 3.0; //magic number to balance with legacy materials + + color = intensity*pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, n.xyz, v, lv); + } + + return color; +} + void calcDiffuseSpecular(vec3 baseColor, float metallic, inout vec3 diffuseColor, inout vec3 specularColor) { vec3 f0 = vec3(0.04); diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbralphaV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbralphaV.glsl index d0fc362db9..ae179d3f37 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbralphaV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbralphaV.glsl @@ -51,8 +51,6 @@ uniform vec4[2] texture_emissive_transform; out vec3 vary_fragcoord; -uniform float near_clip; - in vec3 position; in vec4 diffuse_color; in vec3 normal; @@ -88,7 +86,7 @@ void main() #endif gl_Position = vert; - vary_fragcoord.xyz = vert.xyz + vec3(0,0,near_clip); + vary_fragcoord.xyz = vert.xyz; base_color_texcoord = texture_transform(texcoord0, texture_base_color_transform, texture_matrix0); normal_texcoord = texture_transform(texcoord0, texture_normal_transform, texture_matrix0); diff --git a/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessF.glsl b/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessF.glsl index dbee58b76a..a59127ec77 100644 --- a/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessF.glsl +++ b/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessF.glsl @@ -1,24 +1,24 @@ -/** +/** * @file pbrmetallicroughnessF.glsl * * $LicenseInfo:firstyear=2024&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2022, Linden Research, Inc. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License only. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * + * * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ @@ -33,11 +33,82 @@ uniform sampler2D diffuseMap; //always in sRGB space uniform float metallicFactor; uniform float roughnessFactor; uniform vec3 emissiveColor; -uniform sampler2D bumpMap; +uniform sampler2D normalMap; uniform sampler2D emissiveMap; -uniform sampler2D specularMap; // Packed: Occlusion, Metal, Roughness +uniform sampler2D metallicRoughnessMap; +uniform sampler2D occlusionMap; + +#ifdef ALPHA_BLEND +out vec4 frag_color; + +in vec3 vary_fragcoord; + +#ifdef HAS_SUN_SHADOW +uniform sampler2D lightMap; +uniform vec2 screen_res; +#endif + +// Lights +// See: LLRender::syncLightState() +uniform vec4 light_position[8]; +uniform vec3 light_direction[8]; // spot direction +uniform vec4 light_attenuation[8]; // linear, quadratic, is omni, unused, See: LLPipeline::setupHWLights() and syncLightState() +uniform vec3 light_diffuse[8]; +uniform vec2 light_deferred_attenuation[8]; // light size and falloff + +uniform int sun_up_factor; +uniform vec3 sun_dir; +uniform vec3 moon_dir; +vec3 srgb_to_linear(vec3 c); +vec3 linear_to_srgb(vec3 c); + +void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive); +vec4 applySkyAndWaterFog(vec3 pos, vec3 additive, vec3 atten, vec4 color); + +void calcHalfVectors(vec3 lv, vec3 n, vec3 v, out vec3 h, out vec3 l, out float nh, out float nl, out float nv, out float vh, out float lightDist); +float calcLegacyDistanceAttenuation(float distance, float falloff); +float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); +void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, + vec2 tc, vec3 pos, vec3 norm, float glossiness, bool transparent, vec3 amblit_linear); + +void mirrorClip(vec3 pos); +void waterClip(vec3 pos); + +void calcDiffuseSpecular(vec3 baseColor, float metallic, inout vec3 diffuseColor, inout vec3 specularColor); + +vec3 pbrBaseLight(vec3 diffuseColor, + vec3 specularColor, + float metallic, + vec3 pos, + vec3 norm, + float perceptualRoughness, + vec3 light_dir, + vec3 sunlit, + float scol, + vec3 radiance, + vec3 irradiance, + vec3 colorEmissive, + float ao, + vec3 additive, + vec3 atten); + +vec3 pbrCalcPointLightOrSpotLight(vec3 diffuseColor, vec3 specularColor, + float perceptualRoughness, + float metallic, + vec3 n, // normal + vec3 p, // pixel position + vec3 v, // view vector (negative normalized pixel position) + vec3 lp, // light position + vec3 ld, // light direction (for spotlights) + vec3 lightColor, + float lightSize, float falloff, float is_pointlight, float ambiance); + + +#else out vec4 frag_data[4]; +#endif + in vec3 vary_position; in vec4 vertex_color; @@ -50,7 +121,7 @@ in vec2 normal_texcoord; in vec2 metallic_roughness_texcoord; in vec2 emissive_texcoord; -uniform float minimum_alpha; // PBR alphaMode: MASK, See: mAlphaCutoff, setAlphaCutoff() +uniform float minimum_alpha; vec3 linear_to_srgb(vec3 c); vec3 srgb_to_linear(vec3 c); @@ -62,9 +133,11 @@ void mirrorClip(vec3 pos); uniform mat3 normal_matrix; + void main() { - mirrorClip(vary_position); + vec3 pos = vary_position; + mirrorClip(pos); vec4 basecolor = texture(diffuseMap, base_color_texcoord.xy).rgba; basecolor.rgb = srgb_to_linear(basecolor.rgb); @@ -79,39 +152,97 @@ void main() vec3 col = basecolor.rgb; // from mikktspace.com - vec3 vNt = texture(bumpMap, normal_texcoord.xy).xyz*2.0-1.0; + vec3 vNt = texture(normalMap, normal_texcoord.xy).xyz*2.0-1.0; float sign = vary_sign; vec3 vN = vary_normal; vec3 vT = vary_tangent.xyz; - + vec3 vB = sign * cross(vN, vT); - vec3 tnorm = normalize( vNt.x * vT + vNt.y * vB + vNt.z * vN ); + vec3 norm = normalize( vNt.x * vT + vNt.y * vB + vNt.z * vN ); // RGB = Occlusion, Roughness, Metal // default values, see LLViewerTexture::sDefaultPBRORMImagep // occlusion 1.0 // roughness 0.0 // metal 0.0 - vec3 spec = texture(specularMap, metallic_roughness_texcoord.xy).rgb; - - spec.g *= roughnessFactor; - spec.b *= metallicFactor; + vec3 orm = texture(metallicRoughnessMap, metallic_roughness_texcoord.xy).rgb; + orm.r = texture(occlusionMap, metallic_roughness_texcoord.xy).r; + orm.g *= roughnessFactor; + orm.b *= metallicFactor; vec3 emissive = emissiveColor; emissive *= srgb_to_linear(texture(emissiveMap, emissive_texcoord.xy).rgb); - tnorm *= gl_FrontFacing ? 1.0 : -1.0; + norm *= gl_FrontFacing ? 1.0 : -1.0; + +#ifdef ALPHA_BLEND + vec3 color = vec3(0,0,0); + + vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; + + float scol = 1.0; + vec3 sunlit; + vec3 amblit; + vec3 additive; + vec3 atten; + calcAtmosphericVarsLinear(pos.xyz, norm, light_dir, sunlit, amblit, additive, atten); + + vec3 sunlit_linear = srgb_to_linear(sunlit); + + vec2 frag = vary_fragcoord.xy/vary_fragcoord.z*0.5+0.5; + +#ifdef HAS_SUN_SHADOW + scol = sampleDirectionalShadow(pos.xyz, norm.xyz, frag); +#endif + + float perceptualRoughness = orm.g * roughnessFactor; + float metallic = orm.b * metallicFactor; + + // emissiveColor is the emissive color factor from GLTF and is already in linear space + vec3 colorEmissive = emissiveColor; + // emissiveMap here is a vanilla RGB texture encoded as sRGB, manually convert to linear + colorEmissive *= srgb_to_linear(texture(emissiveMap, emissive_texcoord.xy).rgb); + + // PBR IBL + float gloss = 1.0 - perceptualRoughness; + vec3 irradiance = vec3(0); + vec3 radiance = vec3(0); + sampleReflectionProbes(irradiance, radiance, vary_position.xy*0.5+0.5, pos.xyz, norm.xyz, gloss, true, amblit); + + vec3 diffuseColor; + vec3 specularColor; + calcDiffuseSpecular(col.rgb, metallic, diffuseColor, specularColor); + + vec3 v = -normalize(pos.xyz); + + color = pbrBaseLight(diffuseColor, specularColor, metallic, v, norm.xyz, perceptualRoughness, light_dir, sunlit_linear, scol, radiance, irradiance, colorEmissive, orm.r, additive, atten); + + vec3 light = vec3(0); + + // Punctual lights +#define LIGHT_LOOP(i) light += pbrCalcPointLightOrSpotLight(diffuseColor, specularColor, perceptualRoughness, metallic, norm.xyz, pos.xyz, v, light_position[i].xyz, light_direction[i].xyz, light_diffuse[i].rgb, light_deferred_attenuation[i].x, light_deferred_attenuation[i].y, light_attenuation[i].z, light_attenuation[i].w); + + LIGHT_LOOP(1) + LIGHT_LOOP(2) + LIGHT_LOOP(3) + LIGHT_LOOP(4) + LIGHT_LOOP(5) + LIGHT_LOOP(6) + LIGHT_LOOP(7) + + color.rgb += light.rgb; + + color.rgb = applySkyAndWaterFog(pos.xyz, additive, atten, vec4(color, 1.0)).rgb; + + float a = basecolor.a*vertex_color.a; - //spec.rgb = vec3(1,1,0); - //col = vec3(0,0,0); - //emissive = vary_tangent.xyz*0.5+0.5; - //emissive = vec3(sign*0.5+0.5); - //emissive = vNt * 0.5 + 0.5; - //emissive = tnorm*0.5+0.5; + frag_color = max(vec4(color.rgb,a), vec4(0)); +#else // See: C++: addDeferredAttachments(), GLSL: softenLightF - frag_data[0] = max(vec4(col, 0.0), vec4(0)); // Diffuse - frag_data[1] = max(vec4(spec.rgb,0.0), vec4(0)); // PBR linear packed Occlusion, Roughness, Metal. - frag_data[2] = vec4(tnorm, GBUFFER_FLAG_HAS_PBR); // normal, environment intensity, flags - frag_data[3] = max(vec4(emissive,0), vec4(0)); // PBR sRGB Emissive + frag_data[0] = max(vec4(col, 0.0), vec4(0)); + frag_data[1] = max(vec4(orm.rgb,0.0), vec4(0)); + frag_data[2] = vec4(norm, GBUFFER_FLAG_HAS_PBR); + frag_data[3] = max(vec4(emissive,0), vec4(0)); +#endif } diff --git a/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessV.glsl b/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessV.glsl index 0add509002..403ca8b2db 100644 --- a/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessV.glsl +++ b/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessV.glsl @@ -29,7 +29,6 @@ uniform mat4 modelview_matrix; #ifdef HAS_SKIN uniform mat4 projection_matrix; -mat4 getObjectSkinnedTransform(); #else uniform mat3 normal_matrix; uniform mat4 modelview_projection_matrix; @@ -62,21 +61,85 @@ out vec3 vary_position; vec2 texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform, mat4 sl_animation_transform); vec3 tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] khr_gltf_transform, mat4 sl_animation_transform); + +#ifdef ALPHA_BLEND +out vec3 vary_fragcoord; +#endif + + +#ifdef HAS_SKIN +in vec4 weight4; + +layout (std140) uniform GLTFJoints +{ + // list of OBBs for user override probes + mat3x4 gltf_joints[MAX_JOINTS_PER_GLTF_OBJECT]; +}; + +mat4 getGLTFSkinTransform() +{ + int i; + + vec4 w = fract(weight4); + vec4 index = floor(weight4); + + index = min(index, vec4(MAX_JOINTS_PER_GLTF_OBJECT-1)); + index = max(index, vec4( 0.0)); + + w *= 1.0/(w.x+w.y+w.z+w.w); + + int i1 = int(index.x); + int i2 = int(index.y); + int i3 = int(index.z); + int i4 = int(index.w); + + mat3 mat = mat3(gltf_joints[i1])*w.x; + mat += mat3(gltf_joints[i2])*w.y; + mat += mat3(gltf_joints[i3])*w.z; + mat += mat3(gltf_joints[i4])*w.w; + + vec3 trans = vec3(gltf_joints[i1][0].w,gltf_joints[i1][1].w,gltf_joints[i1][2].w)*w.x; + trans += vec3(gltf_joints[i2][0].w,gltf_joints[i2][1].w,gltf_joints[i2][2].w)*w.y; + trans += vec3(gltf_joints[i3][0].w,gltf_joints[i3][1].w,gltf_joints[i3][2].w)*w.z; + trans += vec3(gltf_joints[i4][0].w,gltf_joints[i4][1].w,gltf_joints[i4][2].w)*w.w; + + mat4 ret; + + ret[0] = vec4(mat[0], 0); + ret[1] = vec4(mat[1], 0); + ret[2] = vec4(mat[2], 0); + ret[3] = vec4(trans, 1.0); + + return ret; + +#ifdef IS_AMD_CARD + // If it's AMD make sure the GLSL compiler sees the arrays referenced once by static index. Otherwise it seems to optimise the storage awawy which leads to unfun crashes and artifacts. + mat3x4 dummy1 = gltf_joints[0]; + mat3x4 dummy2 = gltf_joints[MAX_JOINTS_PER_MESH_OBJECT-1]; +#endif + +} + +#endif + void main() { #ifdef HAS_SKIN - mat4 mat = getObjectSkinnedTransform(); + mat4 mat = getGLTFSkinTransform(); mat = modelview_matrix * mat; vec3 pos = (mat*vec4(position.xyz,1.0)).xyz; vary_position = pos; - gl_Position = projection_matrix*vec4(pos,1.0); + + vec4 vert = projection_matrix * vec4(pos, 1.0); + gl_Position = vert; #else vary_position = (modelview_matrix*vec4(position.xyz, 1.0)).xyz; //transform vertex - gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); + vec4 vert = modelview_projection_matrix * vec4(position.xyz, 1.0); + gl_Position = vert; #endif base_color_texcoord = texture_transform(texcoord0, texture_base_color_transform, texture_matrix0); @@ -99,6 +162,9 @@ void main() vary_normal = n; vertex_color = diffuse_color; +#ifdef ALPHA_BLEND + vary_fragcoord = vert.xyz; +#endif } diff --git a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl index 059c2a64ce..f4a8051427 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl @@ -1,24 +1,24 @@ -/** +/** * @file class1\deferred\pbralphaF.glsl * * $LicenseInfo:firstyear=2022&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2022, Linden Research, Inc. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License only. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * + * * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ @@ -87,7 +87,7 @@ vec4 applySkyAndWaterFog(vec3 pos, vec3 additive, vec3 atten, vec4 color); void calcHalfVectors(vec3 lv, vec3 n, vec3 v, out vec3 h, out vec3 l, out float nh, out float nl, out float nv, out float vh, out float lightDist); float calcLegacyDistanceAttenuation(float distance, float falloff); float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); -void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, +void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, vec2 tc, vec3 pos, vec3 norm, float glossiness, bool transparent, vec3 amblit_linear); void mirrorClip(vec3 pos); @@ -111,15 +111,15 @@ vec3 pbrBaseLight(vec3 diffuseColor, vec3 additive, vec3 atten); -vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, - float perceptualRoughness, +vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, + float perceptualRoughness, float metallic, vec3 n, // normal vec3 v, // surface point to camera vec3 l); //surface point to light -vec3 calcPointLightOrSpotLight(vec3 diffuseColor, vec3 specularColor, - float perceptualRoughness, +vec3 pbrCalcPointLightOrSpotLight(vec3 diffuseColor, vec3 specularColor, + float perceptualRoughness, float metallic, vec3 n, // normal vec3 p, // pixel position @@ -127,33 +127,7 @@ vec3 calcPointLightOrSpotLight(vec3 diffuseColor, vec3 specularColor, vec3 lp, // light position vec3 ld, // light direction (for spotlights) vec3 lightColor, - float lightSize, float falloff, float is_pointlight, float ambiance) -{ - vec3 color = vec3(0,0,0); - - vec3 lv = lp.xyz - p; - - float lightDist = length(lv); - - float dist = lightDist / lightSize; - if (dist <= 1.0) - { - lv /= lightDist; - - float dist_atten = calcLegacyDistanceAttenuation(dist, falloff); - - // spotlight coefficient. - float spot = max(dot(-ld, lv), is_pointlight); - // spot*spot => GL_SPOT_EXPONENT=2 - float spot_atten = spot*spot; - - vec3 intensity = spot_atten * dist_atten * lightColor * 3.0; //magic number to balance with legacy materials - - color = intensity*pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, n.xyz, v, lv); - } - - return color; -} + float lightSize, float falloff, float is_pointlight, float ambiance); void main() { @@ -181,7 +155,7 @@ void main() float sign = vary_sign; vec3 vN = vary_normal; vec3 vT = vary_tangent.xyz; - + vec3 vB = sign * cross(vN, vT); vec3 norm = normalize( vNt.x * vT + vNt.y * vB + vNt.z * vN ); @@ -218,7 +192,7 @@ void main() vec3 irradiance = vec3(0); vec3 radiance = vec3(0); sampleReflectionProbes(irradiance, radiance, vary_position.xy*0.5+0.5, pos.xyz, norm.xyz, gloss, true, amblit); - + vec3 diffuseColor; vec3 specularColor; calcDiffuseSpecular(col.rgb, metallic, diffuseColor, specularColor); @@ -230,7 +204,7 @@ void main() vec3 light = vec3(0); // Punctual lights -#define LIGHT_LOOP(i) light += calcPointLightOrSpotLight(diffuseColor, specularColor, perceptualRoughness, metallic, norm.xyz, pos.xyz, v, light_position[i].xyz, light_direction[i].xyz, light_diffuse[i].rgb, light_deferred_attenuation[i].x, light_deferred_attenuation[i].y, light_attenuation[i].z, light_attenuation[i].w); +#define LIGHT_LOOP(i) light += pbrCalcPointLightOrSpotLight(diffuseColor, specularColor, perceptualRoughness, metallic, norm.xyz, pos.xyz, v, light_position[i].xyz, light_direction[i].xyz, light_diffuse[i].rgb, light_deferred_attenuation[i].x, light_deferred_attenuation[i].y, light_attenuation[i].z, light_attenuation[i].w); LIGHT_LOOP(1) LIGHT_LOOP(2) @@ -245,7 +219,7 @@ void main() color.rgb = applySkyAndWaterFog(pos.xyz, additive, atten, vec4(color, 1.0)).rgb; float a = basecolor.a*vertex_color.a; - + frag_color = max(vec4(color.rgb,a), vec4(0)); } @@ -295,7 +269,7 @@ void main() // emissiveMap here is a vanilla RGB texture encoded as sRGB, manually convert to linear colorEmissive *= srgb_to_linear(texture(emissiveMap, emissive_texcoord.xy).rgb); - + float a = basecolor.a*vertex_color.a; color += colorEmissive; diff --git a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl index d3e19cf4a8..26ab0406f6 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl @@ -77,7 +77,6 @@ uniform float is_mirror; uniform vec3 sun_dir; uniform vec3 moon_dir; -in vec2 vary_fragcoord; uniform mat4 proj_mat; uniform mat4 inv_proj; -- cgit v1.2.3 From 0f6ef1643e6149a40aa605ad8f44d89df843bd80 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Geenz\" Goodman" Date: Tue, 4 Jun 2024 09:36:37 -0700 Subject: Fix for AMD not being able to load pbrmetallicroughnessV. (#1620) --- .../newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessV.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessV.glsl b/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessV.glsl index 403ca8b2db..0ed1c5d315 100644 --- a/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessV.glsl +++ b/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessV.glsl @@ -115,7 +115,7 @@ mat4 getGLTFSkinTransform() #ifdef IS_AMD_CARD // If it's AMD make sure the GLSL compiler sees the arrays referenced once by static index. Otherwise it seems to optimise the storage awawy which leads to unfun crashes and artifacts. mat3x4 dummy1 = gltf_joints[0]; - mat3x4 dummy2 = gltf_joints[MAX_JOINTS_PER_MESH_OBJECT-1]; + mat3x4 dummy2 = gltf_joints[MAX_JOINTS_PER_GLTF_OBJECT-1]; #endif } -- cgit v1.2.3 From f4808dbbe1ee7066df5e46ef2fb57aa5353071a1 Mon Sep 17 00:00:00 2001 From: Brad Linden Date: Tue, 4 Jun 2024 17:55:38 -0700 Subject: Fixup mix->pbr_mix after merge. --- .../newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl index c4c1fc6952..abb899a876 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl @@ -233,7 +233,7 @@ void main() #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL) mix2.vNt = mikktspace(mix2.vNt, vary_tangents[0]); #endif - pbr_mix = mix_pbr(mix, mix2, tm.weight.x); + pbr_mix = mix_pbr(pbr_mix, mix2, tm.weight.x); break; default: break; @@ -275,7 +275,7 @@ void main() #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL) mix2.vNt = mikktspace(mix2.vNt, vary_tangents[1]); #endif - pbr_mix = mix_pbr(mix, mix2, tm.weight.y); + pbr_mix = mix_pbr(pbr_mix, mix2, tm.weight.y); break; default: break; @@ -317,7 +317,7 @@ void main() #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL) mix2.vNt = mikktspace(mix2.vNt, vary_tangents[2]); #endif - pbr_mix = mix_pbr(mix, mix2, tm.weight.z); + pbr_mix = mix_pbr(pbr_mix, mix2, tm.weight.z); break; default: break; @@ -359,7 +359,7 @@ void main() #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL) mix2.vNt = mikktspace(mix2.vNt, vary_tangents[3]); #endif - pbr_mix = mix_pbr(mix, mix2, tm.weight.w); + pbr_mix = mix_pbr(pbr_mix, mix2, tm.weight.w); break; default: break; -- cgit v1.2.3 From 24586f810eb7ef8048a55687333d51c53aa2bed8 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 5 Jun 2024 15:14:13 -0500 Subject: #1527 Improve performance on Apple silicon (#1632) --- indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl index 5f598f84a7..5c79fd7315 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl @@ -57,7 +57,7 @@ void main() outColor.a = 0.0; // yes, downstream atmospherics - frag_data[0] = outColor; + frag_data[0] = max(outColor, vec4(0)); frag_data[1] = vec4(0.0,0.0,0.0,-1.0); vec3 nvn = normalize(vary_normal); frag_data[2] = vec4(nvn.xyz, GBUFFER_FLAG_HAS_ATMOS); -- cgit v1.2.3 From 227e9be06832515fd10eb496d4a2a4528d1ebd92 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 10 Jun 2024 10:43:38 -0500 Subject: #1654 generate normals and tangents according to gltf specification (#1662) * Disable unloading of objects in background. * Add unlit GLTF shader variant --- .../shaders/class1/environment/srgbF.glsl | 2 - .../shaders/class1/gltf/pbrmetallicroughnessF.glsl | 176 +++++++++++++-------- .../shaders/class1/gltf/pbrmetallicroughnessV.glsl | 43 +++-- 3 files changed, 135 insertions(+), 86 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/environment/srgbF.glsl b/indra/newview/app_settings/shaders/class1/environment/srgbF.glsl index 7e1d906878..d7f6d20547 100644 --- a/indra/newview/app_settings/shaders/class1/environment/srgbF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/srgbF.glsl @@ -23,8 +23,6 @@ * $/LicenseInfo$ */ - uniform sampler2D exposureMap; - vec3 srgb_to_linear(vec3 cs) { vec3 low_range = cs / vec3(12.92); diff --git a/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessF.glsl b/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessF.glsl index a59127ec77..d71a3fad99 100644 --- a/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessF.glsl +++ b/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessF.glsl @@ -28,20 +28,61 @@ // GLTF pbrMetallicRoughness implementation -uniform sampler2D diffuseMap; //always in sRGB space -uniform float metallicFactor; -uniform float roughnessFactor; +// ================================== +// needed by all variants +// ================================== +uniform sampler2D diffuseMap; //always in sRGB space +uniform sampler2D emissiveMap; uniform vec3 emissiveColor; +in vec3 vary_position; +in vec4 vertex_color; +in vec2 base_color_texcoord; +in vec2 emissive_texcoord; +uniform float minimum_alpha; + +void mirrorClip(vec3 pos); +vec3 linear_to_srgb(vec3 c); +vec3 srgb_to_linear(vec3 c); +// ================================== + + +// ================================== +// needed by all lit variants +// ================================== +#ifndef UNLIT uniform sampler2D normalMap; -uniform sampler2D emissiveMap; uniform sampler2D metallicRoughnessMap; uniform sampler2D occlusionMap; +uniform float metallicFactor; +uniform float roughnessFactor; +in vec3 vary_normal; +in vec3 vary_tangent; +flat in float vary_sign; +in vec2 normal_texcoord; +in vec2 metallic_roughness_texcoord; +#endif +// ================================== -#ifdef ALPHA_BLEND -out vec4 frag_color; +// ================================== +// needed by all alpha variants +// ================================== +#ifdef ALPHA_BLEND in vec3 vary_fragcoord; +uniform vec4 clipPlane; +uniform float clipSign; +void waterClip(vec3 pos); +void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive); +vec4 applySkyAndWaterFog(vec3 pos, vec3 additive, vec3 atten, vec4 color); +#endif +// ================================== + + +// ================================== +// needed by lit alpha +// ================================== +#if defined(ALPHA_BLEND) && !defined(UNLIT) #ifdef HAS_SUN_SHADOW uniform sampler2D lightMap; @@ -60,21 +101,12 @@ uniform int sun_up_factor; uniform vec3 sun_dir; uniform vec3 moon_dir; -vec3 srgb_to_linear(vec3 c); -vec3 linear_to_srgb(vec3 c); - -void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive); -vec4 applySkyAndWaterFog(vec3 pos, vec3 additive, vec3 atten, vec4 color); - void calcHalfVectors(vec3 lv, vec3 n, vec3 v, out vec3 h, out vec3 l, out float nh, out float nl, out float nv, out float vh, out float lightDist); float calcLegacyDistanceAttenuation(float distance, float falloff); float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, vec2 tc, vec3 pos, vec3 norm, float glossiness, bool transparent, vec3 amblit_linear); -void mirrorClip(vec3 pos); -void waterClip(vec3 pos); - void calcDiffuseSpecular(vec3 baseColor, float metallic, inout vec3 diffuseColor, inout vec3 specularColor); vec3 pbrBaseLight(vec3 diffuseColor, @@ -104,44 +136,36 @@ vec3 pbrCalcPointLightOrSpotLight(vec3 diffuseColor, vec3 specularColor, vec3 lightColor, float lightSize, float falloff, float is_pointlight, float ambiance); +#endif +// ================================== + +// ================================== +// output definition +// ================================== +#if defined(ALPHA_BLEND) || defined(UNLIT) +out vec4 frag_color; #else out vec4 frag_data[4]; #endif - - -in vec3 vary_position; -in vec4 vertex_color; -in vec3 vary_normal; -in vec3 vary_tangent; -flat in float vary_sign; - -in vec2 base_color_texcoord; -in vec2 normal_texcoord; -in vec2 metallic_roughness_texcoord; -in vec2 emissive_texcoord; - -uniform float minimum_alpha; - -vec3 linear_to_srgb(vec3 c); -vec3 srgb_to_linear(vec3 c); - -uniform vec4 clipPlane; -uniform float clipSign; - -void mirrorClip(vec3 pos); - -uniform mat3 normal_matrix; +// ================================== void main() { + +// ================================== +// all variants +// mirror clip +// base color +// masking +// emissive +// ================================== vec3 pos = vary_position; mirrorClip(pos); vec4 basecolor = texture(diffuseMap, base_color_texcoord.xy).rgba; basecolor.rgb = srgb_to_linear(basecolor.rgb); - basecolor *= vertex_color; if (basecolor.a < minimum_alpha) @@ -149,8 +173,16 @@ void main() discard; } - vec3 col = basecolor.rgb; - + vec3 emissive = emissiveColor; + emissive *= srgb_to_linear(texture(emissiveMap, emissive_texcoord.xy).rgb); +// ================================== + +// ================================== +// all lit variants +// prepare norm +// prepare orm +// ================================== +#ifndef UNLIT // from mikktspace.com vec3 vNt = texture(normalMap, normal_texcoord.xy).xyz*2.0-1.0; float sign = vary_sign; @@ -159,6 +191,7 @@ void main() vec3 vB = sign * cross(vN, vT); vec3 norm = normalize( vNt.x * vT + vNt.y * vB + vNt.z * vN ); + norm *= gl_FrontFacing ? 1.0 : -1.0; // RGB = Occlusion, Roughness, Metal // default values, see LLViewerTexture::sDefaultPBRORMImagep @@ -169,24 +202,49 @@ void main() orm.r = texture(occlusionMap, metallic_roughness_texcoord.xy).r; orm.g *= roughnessFactor; orm.b *= metallicFactor; +#endif +// ================================== + +// ================================== +// non alpha output +// ================================== +#ifndef ALPHA_BLEND +#ifdef UNLIT + vec4 color = basecolor; + color.rgb += emissive.rgb; + frag_color = color; +#else + frag_data[0] = max(vec4(basecolor.rgb, 0.0), vec4(0)); + frag_data[1] = max(vec4(orm.rgb,0.0), vec4(0)); + frag_data[2] = vec4(norm, GBUFFER_FLAG_HAS_PBR); + frag_data[3] = max(vec4(emissive,0), vec4(0)); +#endif +#endif - vec3 emissive = emissiveColor; - emissive *= srgb_to_linear(texture(emissiveMap, emissive_texcoord.xy).rgb); - - norm *= gl_FrontFacing ? 1.0 : -1.0; +// ================================== +// alpha implementation +// ================================== #ifdef ALPHA_BLEND - vec3 color = vec3(0,0,0); - - vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; float scol = 1.0; vec3 sunlit; vec3 amblit; vec3 additive; vec3 atten; + + vec3 light_dir; + +#ifdef UNLIT + light_dir = vec3(0,0,1); + vec3 norm = vec3(0,0,1); +#else + light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; +#endif + calcAtmosphericVarsLinear(pos.xyz, norm, light_dir, sunlit, amblit, additive, atten); +#ifndef UNLIT vec3 sunlit_linear = srgb_to_linear(sunlit); vec2 frag = vary_fragcoord.xy/vary_fragcoord.z*0.5+0.5; @@ -198,11 +256,6 @@ void main() float perceptualRoughness = orm.g * roughnessFactor; float metallic = orm.b * metallicFactor; - // emissiveColor is the emissive color factor from GLTF and is already in linear space - vec3 colorEmissive = emissiveColor; - // emissiveMap here is a vanilla RGB texture encoded as sRGB, manually convert to linear - colorEmissive *= srgb_to_linear(texture(emissiveMap, emissive_texcoord.xy).rgb); - // PBR IBL float gloss = 1.0 - perceptualRoughness; vec3 irradiance = vec3(0); @@ -211,11 +264,11 @@ void main() vec3 diffuseColor; vec3 specularColor; - calcDiffuseSpecular(col.rgb, metallic, diffuseColor, specularColor); + calcDiffuseSpecular(basecolor.rgb, metallic, diffuseColor, specularColor); vec3 v = -normalize(pos.xyz); - color = pbrBaseLight(diffuseColor, specularColor, metallic, v, norm.xyz, perceptualRoughness, light_dir, sunlit_linear, scol, radiance, irradiance, colorEmissive, orm.r, additive, atten); + vec3 color = pbrBaseLight(diffuseColor, specularColor, metallic, v, norm.xyz, perceptualRoughness, light_dir, sunlit_linear, scol, radiance, irradiance, emissive, orm.r, additive, atten); vec3 light = vec3(0); @@ -237,12 +290,11 @@ void main() float a = basecolor.a*vertex_color.a; frag_color = max(vec4(color.rgb,a), vec4(0)); -#else - // See: C++: addDeferredAttachments(), GLSL: softenLightF - frag_data[0] = max(vec4(col, 0.0), vec4(0)); - frag_data[1] = max(vec4(orm.rgb,0.0), vec4(0)); - frag_data[2] = vec4(norm, GBUFFER_FLAG_HAS_PBR); - frag_data[3] = max(vec4(emissive,0), vec4(0)); +#else // UNLIT + vec4 color = basecolor; + color.rgb += emissive.rgb; + frag_color = color; #endif +#endif // ALPHA_BLEND } diff --git a/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessV.glsl b/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessV.glsl index 0ed1c5d315..f123c29101 100644 --- a/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessV.glsl +++ b/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessV.glsl @@ -42,32 +42,32 @@ uniform vec4[2] texture_emissive_transform; in vec3 position; in vec4 diffuse_color; -in vec3 normal; -in vec4 tangent; in vec2 texcoord0; - out vec2 base_color_texcoord; -out vec2 normal_texcoord; -out vec2 metallic_roughness_texcoord; out vec2 emissive_texcoord; - out vec4 vertex_color; +out vec3 vary_position; +#ifndef UNLIT +in vec3 normal; +in vec4 tangent; +out vec2 normal_texcoord; +out vec2 metallic_roughness_texcoord; out vec3 vary_tangent; flat out float vary_sign; out vec3 vary_normal; -out vec3 vary_position; +vec3 tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] khr_gltf_transform, mat4 sl_animation_transform); +#endif vec2 texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform, mat4 sl_animation_transform); -vec3 tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] khr_gltf_transform, mat4 sl_animation_transform); #ifdef ALPHA_BLEND out vec3 vary_fragcoord; #endif - #ifdef HAS_SKIN +in uvec4 joint; in vec4 weight4; layout (std140) uniform GLTFJoints @@ -80,18 +80,12 @@ mat4 getGLTFSkinTransform() { int i; - vec4 w = fract(weight4); - vec4 index = floor(weight4); - - index = min(index, vec4(MAX_JOINTS_PER_GLTF_OBJECT-1)); - index = max(index, vec4( 0.0)); - - w *= 1.0/(w.x+w.y+w.z+w.w); + vec4 w = weight4; - int i1 = int(index.x); - int i2 = int(index.y); - int i3 = int(index.z); - int i4 = int(index.w); + uint i1 = joint.x; + uint i2 = joint.y; + uint i3 = joint.z; + uint i4 = joint.w; mat3 mat = mat3(gltf_joints[i1])*w.x; mat += mat3(gltf_joints[i2])*w.y; @@ -143,10 +137,15 @@ void main() #endif base_color_texcoord = texture_transform(texcoord0, texture_base_color_transform, texture_matrix0); + emissive_texcoord = texture_transform(texcoord0, texture_emissive_transform, texture_matrix0); + +#ifndef UNLIT normal_texcoord = texture_transform(texcoord0, texture_normal_transform, texture_matrix0); metallic_roughness_texcoord = texture_transform(texcoord0, texture_metallic_roughness_transform, texture_matrix0); - emissive_texcoord = texture_transform(texcoord0, texture_emissive_transform, texture_matrix0); +#endif + +#ifndef UNLIT #ifdef HAS_SKIN vec3 n = (mat*vec4(normal.xyz+position.xyz,1.0)).xyz-pos.xyz; vec3 t = (mat*vec4(tangent.xyz+position.xyz,1.0)).xyz-pos.xyz; @@ -156,10 +155,10 @@ void main() #endif n = normalize(n); - vary_tangent = normalize(tangent_space_transform(vec4(t, tangent.w), n, texture_normal_transform, texture_matrix0)); vary_sign = tangent.w; vary_normal = n; +#endif vertex_color = diffuse_color; #ifdef ALPHA_BLEND -- cgit v1.2.3 From c95b4bf3ea2b681d6d05468b07e60fedb71fa2cf Mon Sep 17 00:00:00 2001 From: Andrey Lihatskiy Date: Mon, 10 Jun 2024 20:42:42 +0300 Subject: Post-merge - trim trailing whitespace --- .../app_settings/shaders/class1/deferred/screenSpaceReflUtil.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflUtil.glsl index 6791fe44d9..e77e972873 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflUtil.glsl @@ -25,7 +25,7 @@ // debug stub -float random (vec2 uv) +float random (vec2 uv) { return 0.f; } -- cgit v1.2.3 From 1ebf62e102cb3f328aa90809f7f5060b8f065db1 Mon Sep 17 00:00:00 2001 From: Ansariel Date: Tue, 11 Jun 2024 15:40:09 +0200 Subject: Clean up line endings that got mangled up during last merge --- .../shaders/class1/deferred/blurLightF.glsl | 28 ++--- .../shaders/class1/deferred/exposureF.glsl | 18 +-- .../shaders/class1/deferred/fullbrightF.glsl | 16 +-- .../shaders/class1/deferred/globalF.glsl | 10 +- .../shaders/class1/deferred/luminanceF.glsl | 18 +-- .../shaders/class1/deferred/moonF.glsl | 14 +-- .../class1/deferred/pbrShadowAlphaMaskF.glsl | 12 +- .../shaders/class1/deferred/pbropaqueF.glsl | 16 +-- .../shaders/class1/deferred/pbrterrainF.glsl | 14 +-- .../shaders/class1/deferred/pbrterrainUtilF.glsl | 12 +- .../app_settings/shaders/class1/deferred/skyF.glsl | 16 +-- .../shaders/class1/deferred/terrainF.glsl | 20 ++-- .../shaders/class1/deferred/terrainV.glsl | 24 ++-- .../shaders/class1/deferred/textureUtilV.glsl | 10 +- .../shaders/class1/interface/normaldebugG.glsl | 10 +- .../class1/windlight/atmosphericsFuncs.glsl | 10 +- .../shaders/class2/deferred/pbralphaF.glsl | 28 ++--- .../shaders/class2/deferred/sunLightF.glsl | 14 +-- .../shaders/class2/deferred/sunLightSSAOF.glsl | 14 +-- .../shaders/class3/deferred/hazeF.glsl | 8 +- .../shaders/class3/deferred/multiPointLightF.glsl | 6 +- .../shaders/class3/deferred/pointLightF.glsl | 22 ++-- .../shaders/class3/deferred/reflectionProbeF.glsl | 132 ++++++++++----------- .../class3/deferred/screenSpaceReflPostF.glsl | 6 +- .../shaders/class3/deferred/softenLightF.glsl | 16 +-- .../shaders/class3/deferred/spotLightF.glsl | 40 +++---- .../shaders/class3/deferred/waterHazeF.glsl | 4 +- 27 files changed, 269 insertions(+), 269 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl index 8627ab1852..d7d98477c0 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl @@ -1,24 +1,24 @@ -/** +/** * @file blurLightF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2007, Linden Research, Inc. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License only. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * + * * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ @@ -42,16 +42,16 @@ in vec2 vary_fragcoord; vec4 getPosition(vec2 pos_screen); vec4 getNorm(vec2 pos_screen); -void main() +void main() { vec2 tc = vary_fragcoord.xy; vec4 norm = getNorm(tc); vec3 pos = getPosition(tc).xyz; vec4 ccol = texture(lightMap, tc).rgba; - + vec2 dlt = kern_scale * delta / (1.0+norm.xy*norm.xy); dlt /= max(-pos.z*dist_factor, 1.0); - + vec2 defined_weight = kern[0].xy; // special case the first (centre) sample's weight in the blur; we have to sample it anyway so we get it for 'free' vec4 col = defined_weight.xyxx * ccol; @@ -75,15 +75,15 @@ void main() k[1] = (k[0]+k[2])*0.5f; k[3] = (k[2]+k[4])*0.5f; k[5] = (k[4]+k[6])*0.5f; - + for (int i = 1; i < 7; i++) { vec2 samptc = tc + k[i].z*dlt*2.0; samptc /= screen_res; - vec3 samppos = getPosition(samptc).xyz; + vec3 samppos = getPosition(samptc).xyz; float d = dot(norm.xyz, samppos.xyz-pos.xyz);// dist from plane - + if (d*d <= pointplanedist_tolerance_pow2) { col += texture(lightMap, samptc)*k[i].xyxx; @@ -95,10 +95,10 @@ void main() { vec2 samptc = tc - k[i].z*dlt*2.0; samptc /= screen_res; - vec3 samppos = getPosition(samptc).xyz; + vec3 samppos = getPosition(samptc).xyz; float d = dot(norm.xyz, samppos.xyz-pos.xyz);// dist from plane - + if (d*d <= pointplanedist_tolerance_pow2) { col += texture(lightMap, samptc)*k[i].xyxx; @@ -108,7 +108,7 @@ void main() col /= defined_weight.xyxx; //col.y *= col.y; - + frag_color = max(col, vec4(0)); #ifdef IS_AMD_CARD diff --git a/indra/newview/app_settings/shaders/class1/deferred/exposureF.glsl b/indra/newview/app_settings/shaders/class1/deferred/exposureF.glsl index eff7221ae7..67890032df 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/exposureF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/exposureF.glsl @@ -1,28 +1,28 @@ -/** +/** * @file exposureF.glsl * * $LicenseInfo:firstyear=2023&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2023, Linden Research, Inc. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License only. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * + * * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ - + /*[EXTRA_CODE_HERE]*/ out vec4 frag_color; @@ -43,7 +43,7 @@ float lum(vec3 col) return dot(l, col); } -void main() +void main() { vec2 tc = vec2(0.5,0.5); @@ -53,13 +53,13 @@ void main() L /= max_L; L = pow(L, 2.0); float s = mix(dynamic_exposure_params.z, dynamic_exposure_params.y, L); - + #ifdef USE_LAST_EXPOSURE float prev = texture(exposureMap, vec2(0.5,0.5)).r; s = mix(prev, s, min(dt*2.0*abs(prev-s), 0.04)); #endif - + frag_color = max(vec4(s, s, s, dt), vec4(0.0)); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index 52dfed06ae..2b9cc6ae5a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -1,28 +1,28 @@ -/** +/** * @file deferred/fullbrightF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2007, Linden Research, Inc. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License only. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * + * * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ - + /*[EXTRA_CODE_HERE]*/ out vec4 frag_color; @@ -52,7 +52,7 @@ vec4 applySkyAndWaterFog(vec3 pos, vec3 additive, vec3 atten, vec4 color); void mirrorClip(vec3 pos); -void main() +void main() { mirrorClip(vary_position); #ifdef IS_ALPHA @@ -90,7 +90,7 @@ void main() calcAtmosphericVars(pos.xyz, vec3(0), 1.0, sunlit, amblit, additive, atten); color.rgb = applySkyAndWaterFog(pos, additive, atten, color).rgb; - + #endif #endif diff --git a/indra/newview/app_settings/shaders/class1/deferred/globalF.glsl b/indra/newview/app_settings/shaders/class1/deferred/globalF.glsl index 7e3e7d9271..a1b7a4b11f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/globalF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/globalF.glsl @@ -1,24 +1,24 @@ -/** +/** * @file class1/deferred/globalF.glsl * * $LicenseInfo:firstyear=2024&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2024, Linden Research, Inc. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License only. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * + * * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ diff --git a/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl b/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl index 95b2f80e06..3432bf07ef 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl @@ -1,32 +1,32 @@ -/** +/** * @file luminanceF.glsl * * $LicenseInfo:firstyear=2023&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2023, Linden Research, Inc. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License only. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * + * * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ - + /*[EXTRA_CODE_HERE]*/ -// take a luminance sample of diffuseRect and emissiveRect +// take a luminance sample of diffuseRect and emissiveRect out vec4 frag_color; @@ -43,12 +43,12 @@ float lum(vec3 col) return dot(l, col); } -void main() +void main() { vec2 tc = vary_fragcoord*0.6+0.2; tc.y -= 0.1; // HACK - nudge exposure sample down a little bit to favor ground over sky vec3 c = texture(diffuseRect, tc).rgb; - + vec4 norm = texture(normalMap, tc); if (!GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_HDRI) && diff --git a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl index 6ef556d7e8..585de99e1d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl @@ -1,28 +1,28 @@ -/** +/** * @file class1\deferred\moonF.glsl * * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2005, 2020 Linden Research, Inc. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License only. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * + * * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ - + /*[EXTRA_CODE_HERE]*/ out vec4 frag_data[4]; @@ -34,7 +34,7 @@ uniform sampler2D diffuseMap; in vec2 vary_texcoord0; -void main() +void main() { // Restore Pre-EEP alpha fade moon near horizon float fade = 1.0; diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrShadowAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrShadowAlphaMaskF.glsl index 35b7602569..07a2218db2 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrShadowAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrShadowAlphaMaskF.glsl @@ -1,24 +1,24 @@ -/** +/** * @file pbrShadowAlphaMaskF.glsl * * $LicenseInfo:firstyear=2023&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2023, Linden Research, Inc. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License only. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * + * * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ @@ -33,7 +33,7 @@ in vec4 vertex_color; in vec2 vary_texcoord0; uniform float minimum_alpha; -void main() +void main() { float alpha = texture(diffuseMap,vary_texcoord0.xy).a * vertex_color.a; diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl index 380d493636..b521081af9 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl @@ -1,24 +1,24 @@ -/** +/** * @file pbropaqueF.glsl * * $LicenseInfo:firstyear=2022&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2022, Linden Research, Inc. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License only. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * + * * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ @@ -28,7 +28,7 @@ #ifndef IS_HUD -// deferred opaque implementation +// deferred opaque implementation uniform sampler2D diffuseMap; //always in sRGB space @@ -85,7 +85,7 @@ void main() float sign = vary_sign; vec3 vN = vary_normal; vec3 vT = vary_tangent.xyz; - + vec3 vB = sign * cross(vN, vT); vec3 tnorm = normalize( vNt.x * vT + vNt.y * vB + vNt.z * vN ); @@ -95,7 +95,7 @@ void main() // roughness 0.0 // metal 0.0 vec3 spec = texture(specularMap, metallic_roughness_texcoord.xy).rgb; - + spec.g *= roughnessFactor; spec.b *= metallicFactor; diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl index 0de2d348c3..71f4a93369 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl @@ -1,24 +1,24 @@ -/** +/** * @file class1\deferred\terrainF.glsl * * $LicenseInfo:firstyear=2023&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2023, Linden Research, Inc. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License only. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * + * * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ @@ -315,7 +315,7 @@ void main() vec3 vNt = pbr_mix.vNt; vec3 vN = vary_normal; vec3 vT = vary_tangent.xyz; - + vec3 vB = vary_sign * cross(vN, vT); vec3 tnorm = normalize( vNt.x * vT + vNt.y * vB + vNt.z * vN ); @@ -324,7 +324,7 @@ void main() vec3 tnorm = vary_normal; tnorm *= gl_FrontFacing ? 1.0 : -1.0; #endif - + #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) #define mix_emissive pbr_mix.emissive diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl index 935c3f9301..c44b60b6e5 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl @@ -1,24 +1,24 @@ -/** +/** * @file class1\deferred\pbrterrainUtilF.glsl * * $LicenseInfo:firstyear=2023&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2023, Linden Research, Inc. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License only. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * + * * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ @@ -379,7 +379,7 @@ PBRMix terrain_sample_pbr( default: break; } - + return mix; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl index 785c748234..41e42b5173 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl @@ -1,24 +1,24 @@ -/** +/** * @file class1/deferred/skyF.glsl * * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2005, Linden Research, Inc. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License only. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * + * * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ @@ -99,9 +99,9 @@ void main() else #endif { - // Potential Fill-rate optimization. Add cloud calculation - // back in and output alpha of 0 (so that alpha culling kills - // the fragment) if the sky wouldn't show up because the clouds + // Potential Fill-rate optimization. Add cloud calculation + // back in and output alpha of 0 (so that alpha culling kills + // the fragment) if the sky wouldn't show up because the clouds // are fully opaque. color = vary_HazeColor; diff --git a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl index 5f598f84a7..d6fe211910 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl @@ -1,28 +1,28 @@ -/** +/** * @file class1\deferred\terrainF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2007, Linden Research, Inc. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License only. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * + * * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ - + /*[EXTRA_CODE_HERE]*/ out vec4 frag_data[4]; @@ -44,7 +44,7 @@ void main() { mirrorClip(pos); /// Note: This should duplicate the blending functionality currently used for the terrain rendering. - + vec4 color0 = texture(detail_0, vary_texcoord0.xy); vec4 color1 = texture(detail_1, vary_texcoord0.xy); vec4 color2 = texture(detail_2, vary_texcoord0.xy); @@ -54,9 +54,9 @@ void main() float alpha2 = texture(alpha_ramp,vary_texcoord1.xy).a; float alphaFinal = texture(alpha_ramp, vary_texcoord1.zw).a; vec4 outColor = mix( mix(color3, color2, alpha2), mix(color1, color0, alpha1), alphaFinal ); - - outColor.a = 0.0; // yes, downstream atmospherics - + + outColor.a = 0.0; // yes, downstream atmospherics + frag_data[0] = outColor; frag_data[1] = vec4(0.0,0.0,0.0,-1.0); vec3 nvn = normalize(vary_normal); diff --git a/indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl b/indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl index b4ab7cd169..7fc0e98513 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl @@ -1,24 +1,24 @@ -/** +/** * @file class1\environment\terrainV.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2007, Linden Research, Inc. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License only. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * + * * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ @@ -44,15 +44,15 @@ uniform vec4 object_plane_t; vec2 texgen_object(vec4 vpos, mat4 mat, vec4 tp0, vec4 tp1) { vec4 tcoord; - + tcoord.x = dot(vpos, tp0); tcoord.y = dot(vpos, tp1); tcoord.z = 0; tcoord.w = 1; - tcoord = mat * tcoord; - - return tcoord.xy; + tcoord = mat * tcoord; + + return tcoord.xy; } void main() @@ -65,12 +65,12 @@ void main() pos = (modelview_matrix*pre_pos).xyz; vary_normal = normalize(normal_matrix * normal); - + // Transform and pass tex coords vary_texcoord0.xy = texgen_object(vec4(position, 1.0), texture_matrix0, object_plane_s, object_plane_t); - + vec4 t = vec4(texcoord1,0,1); - + vary_texcoord0.zw = t.xy; vary_texcoord1.xy = t.xy-vec2(2.0, 0.0); vary_texcoord1.zw = t.xy-vec2(1.0, 0.0); diff --git a/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl b/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl index 7c02cb9d4a..6ba57f7543 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl @@ -1,24 +1,24 @@ -/** +/** * @file class1/deferred/textureUtilV.glsl * * $LicenseInfo:firstyear=2023&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2023, Linden Research, Inc. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License only. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * + * * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ diff --git a/indra/newview/app_settings/shaders/class1/interface/normaldebugG.glsl b/indra/newview/app_settings/shaders/class1/interface/normaldebugG.glsl index 51d05cd507..50737d4742 100644 --- a/indra/newview/app_settings/shaders/class1/interface/normaldebugG.glsl +++ b/indra/newview/app_settings/shaders/class1/interface/normaldebugG.glsl @@ -1,24 +1,24 @@ -/** +/** * @file normaldebugG.glsl * * $LicenseInfo:firstyear=2023&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2023, Linden Research, Inc. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License only. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * + * * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl index d077670c96..55daa83750 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl @@ -57,9 +57,9 @@ void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, ou vec3 rel_pos_norm = normalize(rel_pos); float rel_pos_len = length(rel_pos); - + vec3 sunlight = (sun_up_factor == 1) ? sunlight_color: moonlight_color; - + // sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes vec3 light_atten = (blue_density + vec3(haze_density * 0.25)) * (density_multiplier * max_y); @@ -119,7 +119,7 @@ void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, ou additive = (blue_horizon.rgb * blue_weight.rgb) * (cs + tmpAmbient.rgb) + (haze_horizon * haze_weight.rgb) * (cs * haze_glow + tmpAmbient.rgb); // brightness of surface both sunlight and ambient - + sunlit = sunlight.rgb; amblit = tmpAmbient; @@ -128,7 +128,7 @@ void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, ou vec3 srgb_to_linear(vec3 col); -// provide a touch of lighting in the opposite direction of the sun light +// provide a touch of lighting in the opposite direction of the sun light // so areas in shadow don't lose all detail float ambientLighting(vec3 norm, vec3 light_dir) { @@ -150,7 +150,7 @@ void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, ou // (allows for mixing of light sources other than sunlight e.g. reflection probes) sunlit *= sky_sunlight_scale; amblit *= sky_ambient_scale; - + amblit = srgb_to_linear(amblit); amblit *= ambientLighting(norm, light_dir); } diff --git a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl index 059c2a64ce..17774adbf5 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl @@ -1,24 +1,24 @@ -/** +/** * @file class1\deferred\pbralphaF.glsl * * $LicenseInfo:firstyear=2022&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2022, Linden Research, Inc. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License only. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * + * * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ @@ -87,7 +87,7 @@ vec4 applySkyAndWaterFog(vec3 pos, vec3 additive, vec3 atten, vec4 color); void calcHalfVectors(vec3 lv, vec3 n, vec3 v, out vec3 h, out vec3 l, out float nh, out float nl, out float nv, out float vh, out float lightDist); float calcLegacyDistanceAttenuation(float distance, float falloff); float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); -void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, +void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, vec2 tc, vec3 pos, vec3 norm, float glossiness, bool transparent, vec3 amblit_linear); void mirrorClip(vec3 pos); @@ -111,15 +111,15 @@ vec3 pbrBaseLight(vec3 diffuseColor, vec3 additive, vec3 atten); -vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, - float perceptualRoughness, +vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, + float perceptualRoughness, float metallic, vec3 n, // normal vec3 v, // surface point to camera vec3 l); //surface point to light -vec3 calcPointLightOrSpotLight(vec3 diffuseColor, vec3 specularColor, - float perceptualRoughness, +vec3 calcPointLightOrSpotLight(vec3 diffuseColor, vec3 specularColor, + float perceptualRoughness, float metallic, vec3 n, // normal vec3 p, // pixel position @@ -181,7 +181,7 @@ void main() float sign = vary_sign; vec3 vN = vary_normal; vec3 vT = vary_tangent.xyz; - + vec3 vB = sign * cross(vN, vT); vec3 norm = normalize( vNt.x * vT + vNt.y * vB + vNt.z * vN ); @@ -218,7 +218,7 @@ void main() vec3 irradiance = vec3(0); vec3 radiance = vec3(0); sampleReflectionProbes(irradiance, radiance, vary_position.xy*0.5+0.5, pos.xyz, norm.xyz, gloss, true, amblit); - + vec3 diffuseColor; vec3 specularColor; calcDiffuseSpecular(col.rgb, metallic, diffuseColor, specularColor); @@ -245,7 +245,7 @@ void main() color.rgb = applySkyAndWaterFog(pos.xyz, additive, atten, vec4(color, 1.0)).rgb; float a = basecolor.a*vertex_color.a; - + frag_color = max(vec4(color.rgb,a), vec4(0)); } @@ -295,7 +295,7 @@ void main() // emissiveMap here is a vanilla RGB texture encoded as sRGB, manually convert to linear colorEmissive *= srgb_to_linear(texture(emissiveMap, emissive_texcoord.xy).rgb); - + float a = basecolor.a*vertex_color.a; color += colorEmissive; diff --git a/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl index 1bd5f5a718..f6c75e6a9c 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl @@ -1,24 +1,24 @@ -/** +/** * @file sunLightF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2007, Linden Research, Inc. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License only. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * + * * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ @@ -41,7 +41,7 @@ vec4 getPosition(vec2 pos_screen); float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); float sampleSpotShadow(vec3 pos, vec3 norm, int index, vec2 pos_screen); -void main() +void main() { vec2 pos_screen = vary_fragcoord.xy; vec4 pos = getPosition(pos_screen); @@ -50,7 +50,7 @@ void main() vec4 col; col.r = sampleDirectionalShadow(pos.xyz, norm.xyz, pos_screen); col.g = 1.0f; - col.b = sampleSpotShadow(pos.xyz, norm.xyz, 0, pos_screen); + col.b = sampleSpotShadow(pos.xyz, norm.xyz, 0, pos_screen); col.a = sampleSpotShadow(pos.xyz, norm.xyz, 1, pos_screen); frag_color = clamp(col, vec4(0), vec4(1)); diff --git a/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl index e0333b6044..3437ed4b4c 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl @@ -1,27 +1,27 @@ -/** +/** * @file class2/deferred/sunLightSSAOF.glsl * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2007, Linden Research, Inc. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License only. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * + * * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ - + /*[EXTRA_CODE_HERE]*/ out vec4 frag_color; @@ -38,7 +38,7 @@ float sampleDirectionalShadow(vec3 shadow_pos, vec3 norm, vec2 pos_screen); float sampleSpotShadow(vec3 shadow_pos, vec3 norm, int index, vec2 pos_screen); float calcAmbientOcclusion(vec4 pos, vec3 norm, vec2 pos_screen); -void main() +void main() { vec2 pos_screen = vary_fragcoord.xy; vec4 pos = getPosition(pos_screen); diff --git a/indra/newview/app_settings/shaders/class3/deferred/hazeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/hazeF.glsl index 4af57e3b80..87977eb28c 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/hazeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/hazeF.glsl @@ -67,16 +67,16 @@ void main() calcAtmosphericVarsLinear(pos.xyz, norm.xyz, light_dir, sunlit, amblit, additive, atten); vec3 sunlit_linear = srgb_to_linear(sunlit); - + // mask off atmospherics below water (when camera is under water) bool do_atmospherics = false; - + if (dot(vec3(0), waterPlane.xyz) + waterPlane.w > 0.0 || dot(pos.xyz, waterPlane.xyz) + waterPlane.w > 0.0) { do_atmospherics = true; } - + vec3 irradiance = vec3(0); vec3 radiance = vec3(0); @@ -101,5 +101,5 @@ void main() } frag_color = max(vec4(color.rgb, alpha), vec4(0)); //output linear since local lights will be added to this shader's results - + } diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl index edfd6cbced..ac3fec23f6 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl @@ -56,8 +56,8 @@ vec3 srgb_to_linear(vec3 c); // Util vec3 hue_to_rgb(float hue); -vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, - float perceptualRoughness, +vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, + float perceptualRoughness, float metallic, vec3 n, // normal vec3 v, // surface point to camera @@ -91,7 +91,7 @@ void main() float metallic = orm.b; vec3 f0 = vec3(0.04); vec3 baseColor = diffuse.rgb; - + vec3 diffuseColor = baseColor.rgb*(vec3(1.0)-f0); diffuseColor *= 1.0 - metallic; diff --git a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl index 60be9f4407..e419525bd5 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl @@ -1,28 +1,28 @@ -/** +/** * @file class3\deferred\pointLightF.glsl * * $LicenseInfo:firstyear=2022&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2022, Linden Research, Inc. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License only. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * + * * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ - + /*[EXTRA_CODE_HERE]*/ out vec4 frag_color; @@ -59,8 +59,8 @@ vec2 getScreenCoord(vec4 clip); vec3 srgb_to_linear(vec3 c); float getDepth(vec2 tc); -vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, - float perceptualRoughness, +vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, + float perceptualRoughness, float metallic, vec3 n, // normal vec3 v, // surface point to camera @@ -93,13 +93,13 @@ void main() if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) { - vec3 colorEmissive = texture(emissiveRect, tc).rgb; + vec3 colorEmissive = texture(emissiveRect, tc).rgb; vec3 orm = spec.rgb; float perceptualRoughness = orm.g; float metallic = orm.b; vec3 f0 = vec3(0.04); vec3 baseColor = diffuse.rgb; - + vec3 diffuseColor = baseColor.rgb*(vec3(1.0)-f0); diffuseColor *= 1.0 - metallic; @@ -136,7 +136,7 @@ void main() final_color += lit*scol*color.rgb*spec.rgb; } } - + if (dot(final_color, final_color) <= 0.0) { discard; diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index 90c84cc428..5dfa196cf6 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -51,7 +51,7 @@ layout (std140) uniform ReflectionProbes mat4 heroBox; // list of bounding spheres for reflection probes sorted by distance to camera (closest first) vec4 refSphere[MAX_REFMAP_COUNT]; - // extra parameters + // extra parameters // x - irradiance scale // y - radiance scale // z - fade in @@ -102,7 +102,7 @@ bool shouldSampleProbe(int i, vec3 pos) if (refIndex[i].w < 0) { vec4 v = refBox[i] * vec4(pos, 1.0); - if (abs(v.x) > 1 || + if (abs(v.x) > 1 || abs(v.y) > 1 || abs(v.z) > 1) { @@ -229,7 +229,7 @@ void preProbeSample(vec3 pos) } } count++; - + ++neighborIdx; } @@ -251,56 +251,56 @@ void preProbeSample(vec3 pos) // original reference implementation: /* -bool intersect(const Ray &ray) const -{ - float t0, t1; // solutions for t if the ray intersects -#if 0 +bool intersect(const Ray &ray) const +{ + float t0, t1; // solutions for t if the ray intersects +#if 0 // geometric solution - Vec3f L = center - orig; - float tca = L.dotProduct(dir); + Vec3f L = center - orig; + float tca = L.dotProduct(dir); // if (tca < 0) return false; - float d2 = L.dotProduct(L) - tca * tca; - if (d2 > radius2) return false; - float thc = sqrt(radius2 - d2); - t0 = tca - thc; - t1 = tca + thc; -#else + float d2 = L.dotProduct(L) - tca * tca; + if (d2 > radius2) return false; + float thc = sqrt(radius2 - d2); + t0 = tca - thc; + t1 = tca + thc; +#else // analytic solution - Vec3f L = orig - center; - float a = dir.dotProduct(dir); - float b = 2 * dir.dotProduct(L); - float c = L.dotProduct(L) - radius2; - if (!solveQuadratic(a, b, c, t0, t1)) return false; -#endif - if (t0 > t1) std::swap(t0, t1); - - if (t0 < 0) { - t0 = t1; // if t0 is negative, let's use t1 instead - if (t0 < 0) return false; // both t0 and t1 are negative - } - - t = t0; - - return true; + Vec3f L = orig - center; + float a = dir.dotProduct(dir); + float b = 2 * dir.dotProduct(L); + float c = L.dotProduct(L) - radius2; + if (!solveQuadratic(a, b, c, t0, t1)) return false; +#endif + if (t0 > t1) std::swap(t0, t1); + + if (t0 < 0) { + t0 = t1; // if t0 is negative, let's use t1 instead + if (t0 < 0) return false; // both t0 and t1 are negative + } + + t = t0; + + return true; } */ // adapted -- assume that origin is inside sphere, return intersection of ray with edge of sphere vec3 sphereIntersect(vec3 origin, vec3 dir, vec3 center, float radius2) -{ - float t0, t1; // solutions for t if the ray intersects +{ + float t0, t1; // solutions for t if the ray intersects - vec3 L = center - origin; + vec3 L = center - origin; float tca = dot(L,dir); - float d2 = dot(L,L) - tca * tca; + float d2 = dot(L,L) - tca * tca; + + float thc = sqrt(radius2 - d2); + t0 = tca - thc; + t1 = tca + thc; - float thc = sqrt(radius2 - d2); - t0 = tca - thc; - t1 = tca + thc; - vec3 v = origin + dir * t1; - return v; -} + return v; +} void swap(inout float a, inout float b) { @@ -312,17 +312,17 @@ void swap(inout float a, inout float b) // debug implementation, make no assumptions about origin void sphereIntersectDebug(vec3 origin, vec3 dir, vec3 center, float radius2, float depth, inout vec4 col) { - float t[2]; // solutions for t if the ray intersects + float t[2]; // solutions for t if the ray intersects // geometric solution - vec3 L = center - origin; + vec3 L = center - origin; float tca = dot(L, dir); // if (tca < 0) return false; - float d2 = dot(L, L) - tca * tca; - if (d2 > radius2) return; - float thc = sqrt(radius2 - d2); - t[0] = tca - thc; - t[1] = tca + thc; + float d2 = dot(L, L) - tca * tca; + if (d2 > radius2) return; + float thc = sqrt(radius2 - d2); + t[0] = tca - thc; + t[1] = tca + thc; for (int i = 0; i < 2; ++i) { @@ -411,8 +411,8 @@ void debugBoxCol(vec3 ro, vec3 rd, float t, vec3 p, inout vec4 col) bool behind = dot(v,v) > dot(pos,pos); float w = 0.25; - - if (behind) + + if (behind) { w *= 0.5; w /= (length(v)-length(pos))*0.5+1.0; @@ -426,7 +426,7 @@ void debugBoxCol(vec3 ro, vec3 rd, float t, vec3 p, inout vec4 col) // cribbed from https://iquilezles.org/articles/intersectors/ // axis aligned box centered at the origin, with size boxSize -void boxIntersectionDebug( in vec3 ro, in vec3 p, vec3 boxSize, inout vec4 col) +void boxIntersectionDebug( in vec3 ro, in vec3 p, vec3 boxSize, inout vec4 col) { vec3 rd = normalize(p-ro); @@ -453,7 +453,7 @@ void boxIntersectionDebug( in vec3 ro, in vec3 p, vec3 boxSize, inout vec4 col) void boxIntersectDebug(vec3 origin, vec3 pos, mat4 i, inout vec4 col) { mat4 clipToLocal = i; - + // transform into unit cube space origin = (clipToLocal * vec4(origin, 1.0)).xyz; pos = (clipToLocal * vec4(pos, 1.0)).xyz; @@ -471,7 +471,7 @@ void boxIntersectDebug(vec3 origin, vec3 pos, mat4 i, inout vec4 col) // dw - distance weight float sphereWeight(vec3 pos, vec3 dir, vec3 origin, float r, vec4 i, out float dw) { - float r1 = r * 0.5; // 50% of radius (outer sphere to start interpolating down) + float r1 = r * 0.5; // 50% of radius (outer sphere to start interpolating down) vec3 delta = pos.xyz - origin; float d2 = max(length(delta), 0.001); @@ -495,7 +495,7 @@ float sphereWeight(vec3 pos, vec3 dir, vec3 origin, float r, vec4 i, out float d // lod - which mip to sample (lower is higher res, sharper reflections) // c - center of probe // r2 - radius of probe squared -// i - index of probe +// i - index of probe vec3 tapRefMap(vec3 pos, vec3 dir, out float w, out float dw, float lod, vec3 c, int i) { // parallax adjustment @@ -514,7 +514,7 @@ vec3 tapRefMap(vec3 pos, vec3 dir, out float w, out float dw, float lod, vec3 c, float rr = r * r; - v = sphereIntersect(pos, dir, c, + v = sphereIntersect(pos, dir, c, refIndex[i].w < 1 ? 4096.0*4096.0 : // <== effectively disable parallax correction for automatically placed probes to keep from bombing the world with obvious spheres rr); @@ -525,7 +525,7 @@ vec3 tapRefMap(vec3 pos, vec3 dir, out float w, out float dw, float lod, vec3 c, vec3 d = normalize(v); v = env_mat * v; - + vec4 ret = textureLod(reflectionProbes, vec4(v.xyz, refIndex[i].x), lod) * refParams[i].y; return ret.rgb; @@ -536,7 +536,7 @@ vec3 tapRefMap(vec3 pos, vec3 dir, out float w, out float dw, float lod, vec3 c, // dir - pixel normal // w - weight of sample (distance and angular attenuation) // dw - weight of sample (distance only) -// i - index of probe +// i - index of probe vec3 tapIrradianceMap(vec3 pos, vec3 dir, out float w, out float dw, vec3 c, int i, vec3 amblit) { // parallax adjustment @@ -554,7 +554,7 @@ vec3 tapIrradianceMap(vec3 pos, vec3 dir, out float w, out float dw, vec3 c, int // pad sphere for manual probe extending into automatic probe space float rr = r * r; - v = sphereIntersect(pos, dir, c, + v = sphereIntersect(pos, dir, c, refIndex[i].w < 1 ? 4096.0*4096.0 : // <== effectively disable parallax correction for automatically placed probes to keep from bombing the world with obvious spheres rr); @@ -563,7 +563,7 @@ vec3 tapIrradianceMap(vec3 pos, vec3 dir, out float w, out float dw, vec3 c, int v -= c; v = env_mat * v; - + vec3 col = textureLod(irradianceProbes, vec4(v.xyz, refIndex[i].x), 0).rgb * refParams[i].x; col = mix(amblit, col, min(refParams[i].x, 1.0)); @@ -625,7 +625,7 @@ vec3 sampleProbes(vec3 pos, vec3 dir, float lod) col[1] *= 1.0/wsum[1]; col[0] = vec3(0); } - + return col[1]+col[0]; } @@ -654,7 +654,7 @@ vec3 sampleProbeAmbient(vec3 pos, vec3 dir, vec3 amblit) { continue; } - + { float w = 0; float dw = 0; @@ -684,7 +684,7 @@ vec3 sampleProbeAmbient(vec3 pos, vec3 dir, vec3 amblit) col[1] *= 1.0/wsum[1]; col[0] = vec3(0); } - + return col[1]+col[0]; } @@ -704,13 +704,13 @@ void tapHeroProbe(inout vec3 glossenv, vec3 pos, vec3 norm, float glossiness) { float d = 0; boxIntersect(pos, norm, heroBox, d, 1.0); - + w = max(d, 0); } else { float r = heroSphere.w; - + w = sphereWeight(pos, refnormpersp, heroSphere.xyz, r, vec4(1), dw); } @@ -851,9 +851,9 @@ void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout { float lod = (1.0-glossiness)*reflection_lods; glossenv = sampleProbes(pos, normalize(refnormpersp), lod); - + } - + if (envIntensity > 0.0) { legacyenv = sampleProbes(pos, normalize(refnormpersp), 0.0); diff --git a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostF.glsl b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostF.glsl index deb276ef9d..9ac389f926 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostF.glsl @@ -52,7 +52,7 @@ float random (vec2 uv); float tapScreenSpaceReflection(int totalSamples, vec2 tc, vec3 viewPos, vec3 n, inout vec4 collectedColor, sampler2D source, float glossiness); -void main() +void main() { vec2 tc = vary_fragcoord.xy; float depth = linearDepth01(getDepth(tc), zNear, zFar); @@ -60,13 +60,13 @@ void main() vec3 pos = getPositionWithDepth(tc, getDepth(tc)).xyz; vec4 spec = texture(specularRect, tc); vec2 hitpixel; - + vec4 diffuse = texture(diffuseRect, tc); vec3 specCol = spec.rgb; vec4 fcol = texture(diffuseMap, tc); - if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) + if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) { vec3 orm = specCol.rgb; float perceptualRoughness = orm.g; diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 96c32734e4..529d1cba6b 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -105,8 +105,8 @@ vec3 pbrBaseLight(vec3 diffuseColor, vec3 additive, vec3 atten); -vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, - float perceptualRoughness, +vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, + float perceptualRoughness, float metallic, vec3 n, // normal vec3 v, // surface point to camera @@ -169,15 +169,15 @@ void main() if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) { - vec3 orm = spec.rgb; + vec3 orm = spec.rgb; float perceptualRoughness = orm.g; float metallic = orm.b; float ao = orm.r; - + // PBR IBL float gloss = 1.0 - perceptualRoughness; - + sampleReflectionProbes(irradiance, radiance, tc, pos.xyz, norm.xyz, gloss, false, amblit_linear); adjustIrradiance(irradiance, ambocc); @@ -205,7 +205,7 @@ void main() { // legacy shaders are still writng sRGB to gbuffer baseColor.rgb = srgb_to_linear(baseColor.rgb); - + spec.rgb = srgb_to_linear(spec.rgb); float da = clamp(dot(norm.xyz, light_dir.xyz), 0.0, 1.0); @@ -224,7 +224,7 @@ void main() vec3 sun_contrib = min(da, scol) * sunlit_linear; color.rgb += sun_contrib; color.rgb *= baseColor.rgb; - + vec3 refnormpersp = reflect(pos.xyz, norm.xyz); if (spec.a > 0.0) @@ -254,7 +254,7 @@ void main() } color.rgb = mix(color.rgb, baseColor.rgb, baseColor.a); - + if (envIntensity > 0.0) { // add environment map applyLegacyEnv(color, legacyenv, spec, pos.xyz, norm.xyz, envIntensity); diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl index 319fa86148..092b0c3c08 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -1,28 +1,28 @@ -/** +/** * @file class3\deferred\spotLightF.glsl * * $LicenseInfo:firstyear=2022&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2022, Linden Research, Inc. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License only. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * + * * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ - + /*[EXTRA_CODE_HERE]*/ out vec4 frag_color; @@ -83,8 +83,8 @@ vec4 getPosition(vec2 pos_screen); const float M_PI = 3.14159265; -vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, - float perceptualRoughness, +vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, + float perceptualRoughness, float metallic, vec3 n, // normal vec3 v, // surface point to camera @@ -112,13 +112,13 @@ void main() } float shadow = 1.0; - + if (proj_shadow_idx >= 0) { vec4 shd = texture(lightMap, tc); shadow = (proj_shadow_idx==0)?shd.b:shd.a; shadow += shadow_fade; - shadow = clamp(shadow, 0.0, 1.0); + shadow = clamp(shadow, 0.0, 1.0); } vec4 norm = getNorm(tc); @@ -149,7 +149,7 @@ void main() float metallic = orm.b; vec3 f0 = vec3(0.04); vec3 baseColor = diffuse.rgb; - + vec3 diffuseColor = baseColor.rgb*(vec3(1.0)-f0); diffuseColor *= 1.0 - metallic; @@ -167,7 +167,7 @@ void main() if (nl > 0.0) { amb_da += (nl*0.5 + 0.5) * proj_ambiance; - + dlit = getProjectedLightDiffuseColor( l_dist, proj_tc.xy ); vec3 intensity = dist_atten * dlit * 3.25 * shadow; // Legacy attenuation, magic number to balance with legacy materials @@ -205,11 +205,11 @@ void main() // unshadowed for consistency between forward and deferred? amb_da += (nl*0.5+0.5) /* * (1.0-shadow) */ * proj_ambiance; } - + amb_rgb = getProjectedLightAmbiance( amb_da, dist_atten, lit, nl, 1.0, proj_tc.xy ); final_color += diffuse.rgb * amb_rgb * max(dot(-normalize(lv), n), 0.0); } - + if (spec.a > 0.0) { dlit *= min(nl*6.0, 1.0) * dist_atten; @@ -218,7 +218,7 @@ void main() float gtdenom = 2 * nh; float gt = max(0, min(gtdenom * nv / vh, gtdenom * nl / vh)); - + if (nh > 0.0) { float scol = fres*texture(lightFunc, vec2(nh, spec.a)).r*gt/(nh*nl); @@ -226,26 +226,26 @@ void main() speccol = clamp(speccol, vec3(0), vec3(1)); final_color += speccol; } - } + } if (envIntensity > 0.0) { vec3 ref = reflect(normalize(pos), n); - + //project from point pos in direction ref to plane proj_p, proj_n vec3 pdelta = proj_p-pos; float ds = dot(ref, proj_n); - + if (ds < 0.0) { vec3 pfinal = pos + ref * dot(pdelta, proj_n)/ds; - + vec4 stc = (proj_mat * vec4(pfinal.xyz, 1.0)); if (stc.z > 0.0) { stc /= stc.w; - + if (stc.x < 1.0 && stc.y < 1.0 && stc.x > 0.0 && diff --git a/indra/newview/app_settings/shaders/class3/deferred/waterHazeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/waterHazeF.glsl index f6bef1e498..a5a37d80dd 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/waterHazeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/waterHazeF.glsl @@ -43,7 +43,7 @@ void main() float depth = getDepth(tc.xy); if (above_water > 0) - { + { // we want to depth test when the camera is above water, but some GPUs have a hard time // with depth testing against render targets that are bound for sampling in the same shader // so we do it manually here @@ -60,5 +60,5 @@ void main() vec4 fogged = getWaterFogView(pos.xyz); frag_color = max(fogged, vec4(0)); //output linear since local lights will be added to this shader's results - + } -- cgit v1.2.3 From 3d4bc98f6be51ebb8ac43af395e54bb6b608c9ae Mon Sep 17 00:00:00 2001 From: Andrey Lihatskiy Date: Tue, 11 Jun 2024 17:38:48 +0300 Subject: Trim remaining trailing whitespaces after #1695 --- indra/newview/app_settings/shaders/class1/deferred/skyV.glsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl index 24d2db2183..ea00d240df 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl @@ -102,7 +102,7 @@ void main() // Initialize temp variables vec3 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color * 0.7; //magic 0.7 to match legacy color - + // Sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes vec3 light_atten = (blue_density + vec3(haze_density * 0.25)) * (density_multiplier * max_y); @@ -152,7 +152,7 @@ void main() sunlight *= max(0.0, (1. - cloud_shadow)); // Haze color below cloud - vec3 add_below_cloud = (blue_horizon * blue_weight * (sunlight + ambient) + vec3 add_below_cloud = (blue_horizon * blue_weight * (sunlight + ambient) + (haze_horizon * haze_weight) * (sunlight * haze_glow + ambient)); // Attenuate cloud color by atmosphere -- cgit v1.2.3 From 429c92ad75fd3b3f7b9dfc52ed034b25004a3b9c Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 11 Jun 2024 13:27:54 -0500 Subject: #1687 Add support for KHR_texture_transform (#1717) --- .../shaders/class1/gltf/pbrmetallicroughnessF.glsl | 3 +- .../shaders/class1/gltf/pbrmetallicroughnessV.glsl | 37 ++++++++++++++++++---- 2 files changed, 33 insertions(+), 7 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessF.glsl b/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessF.glsl index d71a3fad99..99bfcf70fa 100644 --- a/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessF.glsl +++ b/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessF.glsl @@ -61,6 +61,7 @@ in vec3 vary_tangent; flat in float vary_sign; in vec2 normal_texcoord; in vec2 metallic_roughness_texcoord; +in vec2 occlusion_texcoord; #endif // ================================== @@ -199,7 +200,7 @@ void main() // roughness 0.0 // metal 0.0 vec3 orm = texture(metallicRoughnessMap, metallic_roughness_texcoord.xy).rgb; - orm.r = texture(occlusionMap, metallic_roughness_texcoord.xy).r; + orm.r = texture(occlusionMap, occlusion_texcoord.xy).r; orm.g *= roughnessFactor; orm.b *= metallicFactor; #endif diff --git a/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessV.glsl b/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessV.glsl index f123c29101..bc9a47d41e 100644 --- a/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessV.glsl +++ b/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessV.glsl @@ -39,6 +39,7 @@ uniform vec4[2] texture_base_color_transform; uniform vec4[2] texture_normal_transform; uniform vec4[2] texture_metallic_roughness_transform; uniform vec4[2] texture_emissive_transform; +uniform vec4[2] texture_occlusion_transform; in vec3 position; in vec4 diffuse_color; @@ -53,13 +54,37 @@ in vec3 normal; in vec4 tangent; out vec2 normal_texcoord; out vec2 metallic_roughness_texcoord; +out vec2 occlusion_texcoord; out vec3 vary_tangent; flat out float vary_sign; out vec3 vary_normal; vec3 tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] khr_gltf_transform, mat4 sl_animation_transform); #endif -vec2 texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform, mat4 sl_animation_transform); +vec2 gltf_texture_transform(vec2 texcoord, vec4[2] p) +{ + texcoord.y = 1.0 - texcoord.y; + + vec2 Scale = p[0].xy; + float Rotation = -p[0].z; + vec2 Offset = vec2(p[0].w, p[1].x); + + mat3 translation = mat3(1,0,0, 0,1,0, Offset.x, Offset.y, 1); + mat3 rotation = mat3( + cos(Rotation), sin(Rotation), 0, + -sin(Rotation), cos(Rotation), 0, + 0, 0, 1); + + mat3 scale = mat3(Scale.x,0,0, 0,Scale.y,0, 0,0,1); + + mat3 matrix = translation * rotation * scale; + + vec2 uvTransformed = ( matrix * vec3(texcoord.xy, 1) ).xy; + + uvTransformed.y = 1.0 - uvTransformed.y; + + return uvTransformed; +} #ifdef ALPHA_BLEND @@ -136,14 +161,14 @@ void main() gl_Position = vert; #endif - base_color_texcoord = texture_transform(texcoord0, texture_base_color_transform, texture_matrix0); - emissive_texcoord = texture_transform(texcoord0, texture_emissive_transform, texture_matrix0); + base_color_texcoord = gltf_texture_transform(texcoord0, texture_base_color_transform); + emissive_texcoord = gltf_texture_transform(texcoord0, texture_emissive_transform); #ifndef UNLIT - normal_texcoord = texture_transform(texcoord0, texture_normal_transform, texture_matrix0); - metallic_roughness_texcoord = texture_transform(texcoord0, texture_metallic_roughness_transform, texture_matrix0); + normal_texcoord = gltf_texture_transform(texcoord0, texture_normal_transform); + metallic_roughness_texcoord = gltf_texture_transform(texcoord0, texture_metallic_roughness_transform); + occlusion_texcoord = gltf_texture_transform(texcoord0, texture_occlusion_transform); #endif - #ifndef UNLIT #ifdef HAS_SKIN -- cgit v1.2.3 From f40fbdf4ad27a547e30781cd44cd6847d68d3300 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 11 Jun 2024 17:10:13 -0500 Subject: #1718 Add GLTF support for multiple texcoords (#1720) * Fix for GLTF MeshPrimitiveModes test --- .../shaders/class1/gltf/pbrmetallicroughnessF.glsl | 20 ++--- .../shaders/class1/gltf/pbrmetallicroughnessV.glsl | 92 +++++++++++++++++++--- 2 files changed, 89 insertions(+), 23 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessF.glsl b/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessF.glsl index 99bfcf70fa..789c00259b 100644 --- a/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessF.glsl +++ b/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessF.glsl @@ -37,8 +37,8 @@ uniform sampler2D emissiveMap; uniform vec3 emissiveColor; in vec3 vary_position; in vec4 vertex_color; -in vec2 base_color_texcoord; -in vec2 emissive_texcoord; +in vec2 base_color_uv; +in vec2 emissive_uv; uniform float minimum_alpha; void mirrorClip(vec3 pos); @@ -59,9 +59,9 @@ uniform float roughnessFactor; in vec3 vary_normal; in vec3 vary_tangent; flat in float vary_sign; -in vec2 normal_texcoord; -in vec2 metallic_roughness_texcoord; -in vec2 occlusion_texcoord; +in vec2 normal_uv; +in vec2 metallic_roughness_uv; +in vec2 occlusion_uv; #endif // ================================== @@ -165,7 +165,7 @@ void main() vec3 pos = vary_position; mirrorClip(pos); - vec4 basecolor = texture(diffuseMap, base_color_texcoord.xy).rgba; + vec4 basecolor = texture(diffuseMap, base_color_uv.xy).rgba; basecolor.rgb = srgb_to_linear(basecolor.rgb); basecolor *= vertex_color; @@ -175,7 +175,7 @@ void main() } vec3 emissive = emissiveColor; - emissive *= srgb_to_linear(texture(emissiveMap, emissive_texcoord.xy).rgb); + emissive *= srgb_to_linear(texture(emissiveMap, emissive_uv.xy).rgb); // ================================== // ================================== @@ -185,7 +185,7 @@ void main() // ================================== #ifndef UNLIT // from mikktspace.com - vec3 vNt = texture(normalMap, normal_texcoord.xy).xyz*2.0-1.0; + vec3 vNt = texture(normalMap, normal_uv.xy).xyz*2.0-1.0; float sign = vary_sign; vec3 vN = vary_normal; vec3 vT = vary_tangent.xyz; @@ -199,8 +199,8 @@ void main() // occlusion 1.0 // roughness 0.0 // metal 0.0 - vec3 orm = texture(metallicRoughnessMap, metallic_roughness_texcoord.xy).rgb; - orm.r = texture(occlusionMap, occlusion_texcoord.xy).r; + vec3 orm = texture(metallicRoughnessMap, metallic_roughness_uv.xy).rgb; + orm.r = texture(occlusionMap, occlusion_uv.xy).r; orm.g *= roughnessFactor; orm.b *= metallicFactor; #endif diff --git a/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessV.glsl b/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessV.glsl index bc9a47d41e..aac3dc917f 100644 --- a/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessV.glsl +++ b/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessV.glsl @@ -33,7 +33,6 @@ uniform mat4 projection_matrix; uniform mat3 normal_matrix; uniform mat4 modelview_projection_matrix; #endif -uniform mat4 texture_matrix0; uniform vec4[2] texture_base_color_transform; uniform vec4[2] texture_normal_transform; @@ -44,21 +43,31 @@ uniform vec4[2] texture_occlusion_transform; in vec3 position; in vec4 diffuse_color; in vec2 texcoord0; -out vec2 base_color_texcoord; -out vec2 emissive_texcoord; +out vec2 base_color_uv; +out vec2 emissive_uv; out vec4 vertex_color; out vec3 vary_position; #ifndef UNLIT in vec3 normal; in vec4 tangent; -out vec2 normal_texcoord; -out vec2 metallic_roughness_texcoord; -out vec2 occlusion_texcoord; +out vec2 normal_uv; +out vec2 metallic_roughness_uv; +out vec2 occlusion_uv; out vec3 vary_tangent; flat out float vary_sign; out vec3 vary_normal; -vec3 tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] khr_gltf_transform, mat4 sl_animation_transform); +#endif + +#ifdef MULTI_UV +in vec2 texcoord1; +uniform int base_color_texcoord; +uniform int emissive_texcoord; +#ifndef UNLIT +uniform int normal_texcoord; +uniform int metallic_roughness_texcoord; +uniform int occlusion_texcoord; +#endif #endif vec2 gltf_texture_transform(vec2 texcoord, vec4[2] p) @@ -86,6 +95,36 @@ vec2 gltf_texture_transform(vec2 texcoord, vec4[2] p) return uvTransformed; } +#ifndef UNLIT +vec3 gltf_tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] khr_gltf_transform) +{ //derived from tangent_space_transform in textureUtilV.glsl + vec2 weights = vec2(0, 1); + + // Convert to left-handed coordinate system + weights.y = -weights.y; + + // Apply KHR_texture_transform (rotation only) + float khr_rotation = khr_gltf_transform[0].z; + mat2 khr_rotation_mat = mat2( + cos(khr_rotation),-sin(khr_rotation), + sin(khr_rotation), cos(khr_rotation) + ); + weights = khr_rotation_mat * weights; + + // Convert back to right-handed coordinate system + weights.y = -weights.y; + + // Similar to the MikkTSpace-compatible method of extracting the binormal + // from the normal and tangent, as seen in the fragment shader + vec3 vertex_binormal = vertex_tangent.w * cross(vertex_normal, vertex_tangent.xyz); + + return (weights.x * vertex_binormal.xyz) + (weights.y * vertex_tangent.xyz); + + return vertex_tangent.xyz; +} +#endif + + #ifdef ALPHA_BLEND out vec3 vary_fragcoord; @@ -161,13 +200,40 @@ void main() gl_Position = vert; #endif - base_color_texcoord = gltf_texture_transform(texcoord0, texture_base_color_transform); - emissive_texcoord = gltf_texture_transform(texcoord0, texture_emissive_transform); + vec2 bcuv; + vec2 emuv; + +#ifdef MULTI_UV + vec2 uv[2]; + uv[0] = texcoord0; + uv[1] = texcoord1; + + bcuv = uv[base_color_texcoord]; + emuv = uv[emissive_texcoord]; +#else + bcuv = texcoord0; + emuv = texcoord0; +#endif + + base_color_uv = gltf_texture_transform(bcuv, texture_base_color_transform); + emissive_uv = gltf_texture_transform(emuv, texture_emissive_transform); #ifndef UNLIT - normal_texcoord = gltf_texture_transform(texcoord0, texture_normal_transform); - metallic_roughness_texcoord = gltf_texture_transform(texcoord0, texture_metallic_roughness_transform); - occlusion_texcoord = gltf_texture_transform(texcoord0, texture_occlusion_transform); + vec2 normuv; + vec2 rmuv; + vec2 ouv; +#ifdef MULTI_UV + normuv = uv[normal_texcoord]; + rmuv = uv[metallic_roughness_texcoord]; + ouv = uv[occlusion_texcoord]; +#else + normuv = texcoord0; + rmuv = texcoord0; + ouv = texcoord0; +#endif + normal_uv = gltf_texture_transform(normuv, texture_normal_transform); + metallic_roughness_uv = gltf_texture_transform(rmuv, texture_metallic_roughness_transform); + occlusion_uv = gltf_texture_transform(ouv, texture_occlusion_transform); #endif #ifndef UNLIT @@ -180,7 +246,7 @@ void main() #endif n = normalize(n); - vary_tangent = normalize(tangent_space_transform(vec4(t, tangent.w), n, texture_normal_transform, texture_matrix0)); + vary_tangent = normalize(gltf_tangent_space_transform(vec4(t, tangent.w), n, texture_normal_transform)); vary_sign = tangent.w; vary_normal = n; #endif -- cgit v1.2.3 From 8444cd9562a6a7b755fcb075864e205122354192 Mon Sep 17 00:00:00 2001 From: Brad Linden Date: Wed, 12 Jun 2024 13:51:21 -0700 Subject: Fix whitespace pre-commit hook failures --- .../shaders/class1/deferred/pbrterrainF.glsl | 14 +++++++------- .../shaders/class1/deferred/pbrterrainUtilF.glsl | 12 ++++++------ .../shaders/class1/deferred/terrainF.glsl | 20 ++++++++++---------- .../shaders/class1/deferred/textureUtilV.glsl | 10 +++++----- 4 files changed, 28 insertions(+), 28 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl index abb899a876..2cb7ff196b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl @@ -1,24 +1,24 @@ -/** +/** * @file class1\deferred\terrainF.glsl * * $LicenseInfo:firstyear=2023&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2023, Linden Research, Inc. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License only. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * + * * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ @@ -153,7 +153,7 @@ float terrain_mix(TerrainMix tm, vec4 tms4); vec3 mikktspace(vec3 vNt, vec3 vT) { vec3 vN = vary_normal; - + vec3 vB = vary_sign * cross(vN, vT); vec3 tnorm = normalize( vNt.x * vT + vNt.y * vB + vNt.z * vN ); @@ -378,7 +378,7 @@ void main() vec3 tnorm = vary_normal; #endif tnorm *= gl_FrontFacing ? 1.0 : -1.0; - + #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) #define mix_emissive pbr_mix.emissive diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl index 7a7fd783ec..1ae9efe544 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl @@ -1,24 +1,24 @@ -/** +/** * @file class1\deferred\pbrterrainUtilF.glsl * * $LicenseInfo:firstyear=2023&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2023, Linden Research, Inc. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License only. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * + * * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ @@ -374,7 +374,7 @@ PBRMix terrain_sample_pbr( default: break; } - + return mix; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl index 5c79fd7315..1fd31e0546 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl @@ -1,28 +1,28 @@ -/** +/** * @file class1\deferred\terrainF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2007, Linden Research, Inc. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License only. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * + * * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ - + /*[EXTRA_CODE_HERE]*/ out vec4 frag_data[4]; @@ -44,7 +44,7 @@ void main() { mirrorClip(pos); /// Note: This should duplicate the blending functionality currently used for the terrain rendering. - + vec4 color0 = texture(detail_0, vary_texcoord0.xy); vec4 color1 = texture(detail_1, vary_texcoord0.xy); vec4 color2 = texture(detail_2, vary_texcoord0.xy); @@ -54,9 +54,9 @@ void main() float alpha2 = texture(alpha_ramp,vary_texcoord1.xy).a; float alphaFinal = texture(alpha_ramp, vary_texcoord1.zw).a; vec4 outColor = mix( mix(color3, color2, alpha2), mix(color1, color0, alpha1), alphaFinal ); - - outColor.a = 0.0; // yes, downstream atmospherics - + + outColor.a = 0.0; // yes, downstream atmospherics + frag_data[0] = max(outColor, vec4(0)); frag_data[1] = vec4(0.0,0.0,0.0,-1.0); vec3 nvn = normalize(vary_normal); diff --git a/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl b/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl index bf5d106dab..a70180c1b5 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl @@ -1,24 +1,24 @@ -/** +/** * @file class1/deferred/textureUtilV.glsl * * $LicenseInfo:firstyear=2023&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2023, Linden Research, Inc. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License only. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * + * * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ -- cgit v1.2.3 From fcf9af42fa51567957a924fbfda8c3be948d3a25 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Wed, 12 Jun 2024 16:21:58 -0700 Subject: secondlife/viewer#907: Review feedback --- indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl b/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl index a70180c1b5..767416d564 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl @@ -135,8 +135,7 @@ vec3 tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] kh return (weights.x * vertex_binormal.xyz) + (weights.y * vertex_tangent.xyz); } -// Similar to tangent_space_transform but no offset during coordinate system -// conversion, and no texture animation support. +// Similar to tangent_space_transform but no texture animation support. vec3 terrain_tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] khr_gltf_transform) { // Immediately convert to left-handed coordinate system ((0,1) -> (0, -1)) -- cgit v1.2.3 From 375555012f92c1b836f2d122754f9facd050be62 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 14 Jun 2024 17:06:07 -0500 Subject: 1736 audit texture image unit usage on os x (#1739) * #1736 Remove some unused samplers from glsl files and refactor shader manager to assume 16 texture image units and 4 indexed texture units all the time. --- indra/newview/app_settings/shaders/class1/deferred/aoUtil.glsl | 3 +-- indra/newview/app_settings/shaders/class1/deferred/avatarShadowF.glsl | 2 -- indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl | 1 - indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl | 1 - .../newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl | 2 -- indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl | 1 - indra/newview/app_settings/shaders/class1/interface/copyF.glsl | 3 +++ indra/newview/app_settings/shaders/class3/deferred/hazeF.glsl | 2 -- .../newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl | 1 - indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl | 2 -- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 2 -- indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl | 3 --- indra/newview/app_settings/shaders/class3/deferred/waterHazeF.glsl | 2 -- indra/newview/app_settings/shaders/class3/environment/underWaterF.glsl | 1 - 14 files changed, 4 insertions(+), 22 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/aoUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/aoUtil.glsl index 49470f0e39..ce018623a8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/aoUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/aoUtil.glsl @@ -23,8 +23,7 @@ * $/LicenseInfo$ */ -uniform sampler2D noiseMap; -uniform sampler2D normalMap; +uniform sampler2D noiseMap; uniform sampler2D depthMap; uniform float ssao_radius; diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarShadowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarShadowF.glsl index 438e1d1b33..37dcbbd328 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarShadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarShadowF.glsl @@ -27,8 +27,6 @@ out vec4 frag_color; -uniform sampler2D diffuseMap; - void main() { frag_color = vec4(1,1,1,1); diff --git a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl index d7d98477c0..23a3ca4911 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl @@ -27,7 +27,6 @@ out vec4 frag_color; -uniform sampler2D normalMap; uniform sampler2D lightMap; uniform float dist_factor; diff --git a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl index 3ea2248bec..ab0e4fd4d8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl @@ -50,7 +50,6 @@ SOFTWARE. uniform sampler2D normalMap; uniform sampler2D depthMap; -uniform sampler2D emissiveRect; uniform sampler2D projectionMap; // rgba uniform sampler2D brdfLut; diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl index 9db8f461dd..f208ac746b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl @@ -27,8 +27,6 @@ out vec4 frag_color; -uniform sampler2D diffuseMap; - in vec4 post_pos; in float target_pos_x; in vec4 vertex_color; diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl index 16cc7cfbbc..6f7bd2bf3c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl @@ -24,7 +24,6 @@ */ uniform sampler2D normalMap; -uniform sampler2D depthMap; #if defined(SUN_SHADOW) uniform sampler2DShadow shadowMap0; diff --git a/indra/newview/app_settings/shaders/class1/interface/copyF.glsl b/indra/newview/app_settings/shaders/class1/interface/copyF.glsl index edaa2488f0..094d147e86 100644 --- a/indra/newview/app_settings/shaders/class1/interface/copyF.glsl +++ b/indra/newview/app_settings/shaders/class1/interface/copyF.glsl @@ -25,7 +25,10 @@ in vec2 tc; +#if defined(COPY_DEPTH) uniform sampler2D depthMap; +#endif + uniform sampler2D diffuseMap; out vec4 frag_color; diff --git a/indra/newview/app_settings/shaders/class3/deferred/hazeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/hazeF.glsl index 87977eb28c..7b82aa1a0d 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/hazeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/hazeF.glsl @@ -25,8 +25,6 @@ out vec4 frag_color; -uniform sampler2D normalMap; - // Inputs uniform vec3 sun_dir; uniform vec3 moon_dir; diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl index ac3fec23f6..4ed778371f 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl @@ -27,7 +27,6 @@ out vec4 frag_color; -uniform sampler2D depthMap; uniform sampler2D diffuseRect; uniform sampler2D specularRect; uniform sampler2D emissiveRect; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl diff --git a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl index e419525bd5..6c13757149 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl @@ -29,10 +29,8 @@ out vec4 frag_color; uniform sampler2D diffuseRect; uniform sampler2D specularRect; -uniform sampler2D normalMap; uniform sampler2D emissiveRect; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl uniform sampler2D lightFunc; -uniform sampler2D depthMap; uniform vec3 env_mat[3]; uniform float sun_wash; diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 529d1cba6b..ca88fe7482 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -29,7 +29,6 @@ out vec4 frag_color; uniform sampler2D diffuseRect; uniform sampler2D specularRect; -uniform sampler2D normalMap; uniform sampler2D emissiveRect; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl const float M_PI = 3.14159265; @@ -38,7 +37,6 @@ const float M_PI = 3.14159265; uniform sampler2D lightMap; #endif -uniform sampler2D depthMap; uniform sampler2D lightFunc; uniform float blur_size; diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl index 092b0c3c08..bc4d36d10d 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -29,12 +29,9 @@ out vec4 frag_color; uniform sampler2D diffuseRect; uniform sampler2D specularRect; -uniform sampler2D depthMap; -uniform sampler2D normalMap; uniform sampler2D emissiveRect; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl uniform samplerCube environmentMap; uniform sampler2D lightMap; -uniform sampler2D projectionMap; // rgba uniform sampler2D lightFunc; uniform mat4 proj_mat; //screen space to light space diff --git a/indra/newview/app_settings/shaders/class3/deferred/waterHazeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/waterHazeF.glsl index a5a37d80dd..2bf785e773 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/waterHazeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/waterHazeF.glsl @@ -28,8 +28,6 @@ out vec4 frag_color; // Inputs in vec4 vary_fragcoord; -uniform sampler2D normalMap; - vec4 getPositionWithDepth(vec2 pos_screen, float depth); float getDepth(vec2 pos_screen); diff --git a/indra/newview/app_settings/shaders/class3/environment/underWaterF.glsl b/indra/newview/app_settings/shaders/class3/environment/underWaterF.glsl index 728d70ebb2..1c02dc764d 100644 --- a/indra/newview/app_settings/shaders/class3/environment/underWaterF.glsl +++ b/indra/newview/app_settings/shaders/class3/environment/underWaterF.glsl @@ -25,7 +25,6 @@ out vec4 frag_color; -uniform sampler2D diffuseMap; uniform sampler2D bumpMap; #ifdef TRANSPARENT_WATER -- cgit v1.2.3 From 80ea30af1a8b38360f71c29cc45872c4399dab0d Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 21 Jun 2024 13:13:08 -0500 Subject: #1769 gltf optimization pass (#1816) #1814 and #1517 Fix mirror update rate and occlusion culling --- .../shaders/class1/gltf/pbrmetallicroughnessF.glsl | 34 ++++- .../shaders/class1/gltf/pbrmetallicroughnessV.glsl | 162 +++++++++++++++------ 2 files changed, 144 insertions(+), 52 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessF.glsl b/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessF.glsl index 789c00259b..ac4ff50552 100644 --- a/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessF.glsl +++ b/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessF.glsl @@ -28,18 +28,40 @@ // GLTF pbrMetallicRoughness implementation +uniform int gltf_material_id; + +vec3 emissiveColor = vec3(0,0,0); +float metallicFactor = 1.0; +float roughnessFactor = 1.0; +float minimum_alpha = -1.0; + +layout (std140) uniform GLTFMaterials +{ + // see pbrmetallicroughnessV.glsl for packing + vec4 gltf_material_data[MAX_UBO_VEC4S]; +}; + +void unpackMaterial() +{ + if (gltf_material_id > -1) + { + int idx = gltf_material_id*12; + emissiveColor = gltf_material_data[idx+10].rgb; + roughnessFactor = gltf_material_data[idx+11].g; + metallicFactor = gltf_material_data[idx+11].b; + minimum_alpha -= gltf_material_data[idx+11].a; + } +} // ================================== // needed by all variants // ================================== uniform sampler2D diffuseMap; //always in sRGB space uniform sampler2D emissiveMap; -uniform vec3 emissiveColor; in vec3 vary_position; in vec4 vertex_color; in vec2 base_color_uv; in vec2 emissive_uv; -uniform float minimum_alpha; void mirrorClip(vec3 pos); vec3 linear_to_srgb(vec3 c); @@ -54,8 +76,6 @@ vec3 srgb_to_linear(vec3 c); uniform sampler2D normalMap; uniform sampler2D metallicRoughnessMap; uniform sampler2D occlusionMap; -uniform float metallicFactor; -uniform float roughnessFactor; in vec3 vary_normal; in vec3 vary_tangent; flat in float vary_sign; @@ -154,7 +174,7 @@ out vec4 frag_data[4]; void main() { - + unpackMaterial(); // ================================== // all variants // mirror clip @@ -165,6 +185,10 @@ void main() vec3 pos = vary_position; mirrorClip(pos); +#ifdef ALPHA_BLEND + //waterClip(pos); +#endif + vec4 basecolor = texture(diffuseMap, base_color_uv.xy).rgba; basecolor.rgb = srgb_to_linear(basecolor.rgb); basecolor *= vertex_color; diff --git a/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessV.glsl b/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessV.glsl index aac3dc917f..6a628bc852 100644 --- a/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessV.glsl +++ b/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessV.glsl @@ -26,19 +26,95 @@ // GLTF pbrMetallicRoughness implementation uniform mat4 modelview_matrix; - -#ifdef HAS_SKIN uniform mat4 projection_matrix; -#else -uniform mat3 normal_matrix; -uniform mat4 modelview_projection_matrix; + +#ifdef MULTI_UV +in vec2 texcoord1; +int base_color_texcoord = 0; +int emissive_texcoord = 0; +#ifndef UNLIT +int normal_texcoord = 0; +int metallic_roughness_texcoord = 0; +int occlusion_texcoord = 0; +#endif +#endif + +uniform int gltf_material_id; + +layout (std140) uniform GLTFMaterials +{ + // index by gltf_material_id*12 + + // [gltf_material_id + [0-1]] - base color transform + // [gltf_material_id + [2-3]] - normal transform + // [gltf_material_id + [4-5]] - metallic roughness transform + // [gltf_material_id + [6-7]] - emissive transform + // [gltf_material_id + [8-9]] - occlusion transform + // [gltf_material_id + 10] - emissive factor + // [gltf_material_id + 11] - .r unused, .g roughness, .b metalness, .a minimum alpha + + // Transforms are packed as follows + // packed[0] = vec4(scale.x, scale.y, rotation, offset.x) + // packed[1] = vec4(mScale.y, texcoord, 0, 0) + vec4 gltf_material_data[MAX_UBO_VEC4S]; +}; + +vec4[2] texture_base_color_transform; +vec4[2] texture_normal_transform; +vec4[2] texture_metallic_roughness_transform; +vec4[2] texture_emissive_transform; +vec4[2] texture_occlusion_transform; + +void unpackTextureTransforms() +{ + if (gltf_material_id != -1) + { + int idx = gltf_material_id*12; + + texture_base_color_transform[0] = gltf_material_data[idx+0]; + texture_base_color_transform[1] = gltf_material_data[idx+1]; + + texture_normal_transform[0] = gltf_material_data[idx+2]; + texture_normal_transform[1] = gltf_material_data[idx+3]; + + texture_metallic_roughness_transform[0] = gltf_material_data[idx+4]; + texture_metallic_roughness_transform[1] = gltf_material_data[idx+5]; + + texture_emissive_transform[0] = gltf_material_data[idx+6]; + texture_emissive_transform[1] = gltf_material_data[idx+7]; + + texture_occlusion_transform[0] = gltf_material_data[idx+8]; + texture_occlusion_transform[1] = gltf_material_data[idx+9]; + +#ifdef MULTI_UV + base_color_texcoord = int(gltf_material_data[idx+1].g); + emissive_texcoord = int(gltf_material_data[idx+7].g); +#ifndef UNLIT + normal_texcoord = int(gltf_material_data[idx+3].g); + metallic_roughness_texcoord = int(gltf_material_data[idx+5].g); + occlusion_texcoord = int(gltf_material_data[idx+9].g); #endif +#endif + } + else + { + texture_base_color_transform[0] = vec4(1.0, 1.0, 0.0, 0.0); + texture_base_color_transform[1] = vec4(0.0, 0.0, 0.0, 0.0); + + texture_normal_transform[0] = vec4(1.0, 1.0, 0.0, 0.0); + texture_normal_transform[1] = vec4(0.0, 0.0, 0.0, 0.0); + + texture_metallic_roughness_transform[0] = vec4(1.0, 1.0, 0.0, 0.0); + texture_metallic_roughness_transform[1] = vec4(0.0, 0.0, 0.0, 0.0); + + texture_emissive_transform[0] = vec4(1.0, 1.0, 0.0, 0.0); + texture_emissive_transform[1] = vec4(0.0, 0.0, 0.0, 0.0); + + texture_occlusion_transform[0] = vec4(1.0, 1.0, 0.0, 0.0); + texture_occlusion_transform[1] = vec4(0.0, 0.0, 0.0, 0.0); + } +} -uniform vec4[2] texture_base_color_transform; -uniform vec4[2] texture_normal_transform; -uniform vec4[2] texture_metallic_roughness_transform; -uniform vec4[2] texture_emissive_transform; -uniform vec4[2] texture_occlusion_transform; in vec3 position; in vec4 diffuse_color; @@ -59,17 +135,6 @@ flat out float vary_sign; out vec3 vary_normal; #endif -#ifdef MULTI_UV -in vec2 texcoord1; -uniform int base_color_texcoord; -uniform int emissive_texcoord; -#ifndef UNLIT -uniform int normal_texcoord; -uniform int metallic_roughness_texcoord; -uniform int occlusion_texcoord; -#endif -#endif - vec2 gltf_texture_transform(vec2 texcoord, vec4[2] p) { texcoord.y = 1.0 - texcoord.y; @@ -124,23 +189,22 @@ vec3 gltf_tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[ } #endif - - #ifdef ALPHA_BLEND out vec3 vary_fragcoord; #endif #ifdef HAS_SKIN -in uvec4 joint; -in vec4 weight4; layout (std140) uniform GLTFJoints { - // list of OBBs for user override probes - mat3x4 gltf_joints[MAX_JOINTS_PER_GLTF_OBJECT]; + mat3x4 gltf_joints[MAX_NODES_PER_GLTF_OBJECT]; }; -mat4 getGLTFSkinTransform() + +in uvec4 joint; +in vec4 weight4; + +mat4 getGLTFTransform() { int i; @@ -169,21 +233,37 @@ mat4 getGLTFSkinTransform() ret[3] = vec4(trans, 1.0); return ret; +} -#ifdef IS_AMD_CARD - // If it's AMD make sure the GLSL compiler sees the arrays referenced once by static index. Otherwise it seems to optimise the storage awawy which leads to unfun crashes and artifacts. - mat3x4 dummy1 = gltf_joints[0]; - mat3x4 dummy2 = gltf_joints[MAX_JOINTS_PER_GLTF_OBJECT-1]; -#endif +#else + +layout (std140) uniform GLTFNodes +{ + mat3x4 gltf_nodes[MAX_NODES_PER_GLTF_OBJECT]; +}; + +uniform int gltf_node_id = 0; + +mat4 getGLTFTransform() +{ + mat4 ret; + mat3x4 src = gltf_nodes[gltf_node_id]; + + ret[0] = vec4(src[0].xyz, 0); + ret[1] = vec4(src[1].xyz, 0); + ret[2] = vec4(src[2].xyz, 0); + + ret[3] = vec4(src[0].w, src[1].w, src[2].w, 1); + return ret; } #endif void main() { -#ifdef HAS_SKIN - mat4 mat = getGLTFSkinTransform(); + unpackTextureTransforms(); + mat4 mat = getGLTFTransform(); mat = modelview_matrix * mat; @@ -193,13 +273,6 @@ void main() vec4 vert = projection_matrix * vec4(pos, 1.0); gl_Position = vert; -#else - vary_position = (modelview_matrix*vec4(position.xyz, 1.0)).xyz; - //transform vertex - vec4 vert = modelview_projection_matrix * vec4(position.xyz, 1.0); - gl_Position = vert; -#endif - vec2 bcuv; vec2 emuv; @@ -237,13 +310,8 @@ void main() #endif #ifndef UNLIT -#ifdef HAS_SKIN vec3 n = (mat*vec4(normal.xyz+position.xyz,1.0)).xyz-pos.xyz; vec3 t = (mat*vec4(tangent.xyz+position.xyz,1.0)).xyz-pos.xyz; -#else //HAS_SKIN - vec3 n = normal_matrix * normal; - vec3 t = normal_matrix * tangent.xyz; -#endif n = normalize(n); vary_tangent = normalize(gltf_tangent_space_transform(vec4(t, tangent.w), n, texture_normal_transform)); -- cgit v1.2.3