SL-17274: Add debug rendering to pbr shader

meow-7.2.2
Ptolemy 2022-05-06 09:48:49 -07:00
parent 415380b140
commit 663e121f2f
1 changed files with 65 additions and 9 deletions

View File

@ -25,6 +25,19 @@
/*[EXTRA_CODE_HERE]*/
#define DEBUG_BASIC 1
#define DEBUG_COLOR 0
#define DEBUG_NORMAL 0
#define DEBUG_POSITION 0
#define DEBUG_REFLECT_VEC 0
#define DEBUG_REFLECT_COLOR 0
#ifdef HAS_SPECULAR_MAP
uniform sampler2D specularMap;
#endif
uniform samplerCube environmentMap;
uniform mat3 env_mat;
#ifdef DEFINE_GL_FRAGCOLOR
out vec4 frag_data[3];
#else
@ -35,19 +48,62 @@ VARYING vec3 vary_position;
VARYING vec3 vary_normal;
VARYING vec4 vertex_color;
VARYING vec2 vary_texcoord0;
#ifdef HAS_SPECULAR_MAP
VARYING vec2 vary_texcoord2;
#endif
vec2 encode_normal(vec3 n);
vec3 linear_to_srgb(vec3 c);
void main()
struct PBR
{
vec3 col = vertex_color.rgb * diffuseLookup(vary_texcoord0.xy).rgb;
float LdotH; // Light and Half
float NdotL; // Normal and Light
float NdotH; // Normal and Half
float VdotH; // View and Half
};
vec3 spec;
spec.rgb = vec3(vertex_color.a);
col.rgb = vec3( 1, 0, 1 ); // DEBUG
frag_data[0] = vec4(col, 0.0);
frag_data[1] = vec4(spec, vertex_color.a); // spec
vec3 nvn = normalize(vary_normal);
frag_data[2] = vec4(encode_normal(nvn.xyz), vertex_color.a, 0.0);
const float M_PI = 3.141592653589793;
void main()
{
vec3 col = vertex_color.rgb * diffuseLookup(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 spec;
spec.rgb = vec3(vertex_color.a);
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;
#if DEBUG_BASIC
col.rgb = vec3( 1, 0, 1 ); // DEBUG
#endif
#if DEBUG_COLOR
col.rgb = vertex_color.rgb;
#endif
#if DEBUG_NORMAL
col.rgb = vary_normal;
#endif
#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);
}