diff options
author | Ptolemy <ptolemy@lindenlab.com> | 2022-06-23 15:16:24 -0700 |
---|---|---|
committer | Ptolemy <ptolemy@lindenlab.com> | 2022-06-23 15:16:24 -0700 |
commit | 29533c345443f127fa0ef2f9499ccfd59a971842 (patch) | |
tree | 0206e21fd5e16b9e9136ac11f44219652be3d343 /indra/newview | |
parent | c68e469d88f2817ee49bbf23ffe5207c432e3c45 (diff) |
SL-17274: Fix shaders to use normal and spec maps
Diffstat (limited to 'indra/newview')
-rw-r--r-- | indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl | 85 | ||||
-rw-r--r-- | indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl | 27 |
2 files changed, 73 insertions, 39 deletions
diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl index cb9cc4958a..15e02c9551 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl @@ -25,69 +25,81 @@ /*[EXTRA_CODE_HERE]*/ -#define DEBUG_BASIC 1 -#define DEBUG_COLOR 0 +#define DEBUG_BASIC 0 +#define DEBUG_VERTEX 0 #define DEBUG_NORMAL 0 #define DEBUG_POSITION 0 -#define DEBUG_REFLECT_VEC 0 -#define DEBUG_REFLECT_COLOR 0 + +uniform sampler2D diffuseMap; //always in sRGB space + +#ifdef HAS_NORMAL_MAP + uniform sampler2D bumpMap; +#endif #ifdef HAS_SPECULAR_MAP -uniform sampler2D specularMap; + uniform sampler2D specularMap; // Packed: Occlusion, Metal, Roughness #endif + uniform samplerCube environmentMap; uniform mat3 env_mat; #ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_data[3]; +out vec4 frag_data[4]; #else #define frag_data gl_FragData #endif VARYING vec3 vary_position; -VARYING vec3 vary_normal; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; +#ifdef HAS_NORMAL_MAP + VARYING vec3 vary_normal; + VARYING vec2 vary_texcoord1; +#endif + #ifdef HAS_SPECULAR_MAP -VARYING vec2 vary_texcoord2; + VARYING vec2 vary_texcoord2; #endif vec2 encode_normal(vec3 n); vec3 linear_to_srgb(vec3 c); -struct PBR -{ - float LdotH; // Light and Half - float NdotL; // Normal and Light - float NdotH; // Normal and Half - float VdotH; // View and Half -}; - const float M_PI = 3.141592653589793; void main() { - vec3 col = vertex_color.rgb * diffuseLookup(vary_texcoord0.xy).rgb; +// IF .mFeatures.mIndexedTextureChannels = LLGLSLShader::sIndexedTextureChannels; +// vec3 col = vertex_color.rgb * diffuseLookup(vary_texcoord0.xy).rgb; +// else + vec3 col = vertex_color.rgb * texture2D(diffuseMap, vary_texcoord0.xy).rgb; -//#ifdef HAS_SPECULAR_MAP -//#else - vec4 norm = vec4(0,0,0,1.0); - vec3 tnorm = vary_normal; -//#endif - norm.xyz = normalize(tnorm.xyz); + vec3 emissive = vec3(0); - vec3 spec; - spec.rgb = vec3(vertex_color.a); +#ifdef HAS_NORMAL_MAP + vec4 norm = texture2D(bumpMap, vary_texcoord1.xy); + vec3 tnorm = norm.xyz * 2 - 1; +#else + vec4 norm = vec4(0,0,0,1.0); +// vec3 tnorm = vary_normal; + vec3 tnorm = vec3(0,0,1); +#endif - vec3 pos = vary_position; - vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); - vec3 env_vec = env_mat * refnormpersp; - vec3 reflected_color = textureCube(environmentMap, env_vec).rgb; + // RGB = Occlusion, Roughness, Metal + // default values + // occlusion ? + // roughness 1.0 + // metal 1.0 +#ifdef HAS_SPECULAR_MAP + vec3 spec = texture2D(specularMap, vary_texcoord0.xy).rgb; // TODO: FIXME: vary_texcoord2 +#else + vec3 spec = vec3(0,1,1); +#endif + norm.xyz = normalize(tnorm.xyz); #if DEBUG_BASIC - col.rgb = vec3( 1, 0, 1 ); // DEBUG + col.rgb = vec3( 1, 0, 1 ); #endif -#if DEBUG_COLOR +#if DEBUG_VERTEX col.rgb = vertex_color.rgb; #endif #if DEBUG_NORMAL @@ -96,14 +108,9 @@ void main() #if DEBUG_POSITION col.rgb = vary_position.xyz; #endif -#if DEBUG_REFLECT_VEC - col.rgb = refnormpersp; -#endif -#if DEBUG_REFLECT_COLOR - col.rgb = reflected_color; -#endif frag_data[0] = vec4(col, 0.0); - frag_data[1] = vec4(spec, vertex_color.a); // spec - frag_data[2] = vec4(encode_normal(norm.xyz), vertex_color.a, 0.0); + frag_data[1] = vec4(spec.rgb, vertex_color.a); // Occlusion, Roughness, Metal + frag_data[2] = vec4(encode_normal(norm.xyz), vertex_color.a, GBUFFER_FLAG_HAS_PBR); // + frag_data[3] = vec4(emissive,0); // Emissive } diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl index 72bae808e0..58048687a5 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl @@ -33,10 +33,24 @@ ATTRIBUTE vec4 diffuse_color; ATTRIBUTE vec3 normal; ATTRIBUTE vec2 texcoord0; +#ifdef HAS_NORMAL_MAP + ATTRIBUTE vec4 tangent; + ATTRIBUTE vec2 texcoord1; + VARYING vec3 vary_mat0; + VARYING vec3 vary_mat1; + VARYING vec3 vary_mat2; +#endif + +#if HAS_SPECULAR_MAP + ATTRIBUTE vec2 texcoord2; +#endif + VARYING vec3 vary_position; VARYING vec3 vary_normal; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; +VARYING vec2 vary_texcoord1; // normal map +VARYING vec2 vary_texcoord2; // specular map void passTextureIndex(); @@ -50,5 +64,18 @@ void main() passTextureIndex(); vary_normal = normalize(normal_matrix * normal); +#ifdef HAS_NORMAL_MAP + //vary_texcoord1 = (texture_matrix0 * vec4(texcoord1,0,1)).xy; + vary_texcoord1 = texcoord1; +// vary_mat0 = vec3(t.x, b.x, n.x); +// vary_mat1 = vec3(t.y, b.y, n.y); +// vary_mat2 = vec3(t.z, b.z, n.z); +#endif + +#ifdef HAS_SPECULAR_MAP + //vary_texcoord2 = (texture_matrix0 * vec4(texcoord2,0,1)).xy; + vary_texcoord2 = texcoord2; +#endif + vertex_color = diffuse_color; } |