Skip to content

Instantly share code, notes, and snippets.

@galek
Created January 26, 2017 21:47
Show Gist options
  • Save galek/aa5e35e1d89d36116f866a320e95e628 to your computer and use it in GitHub Desktop.
Save galek/aa5e35e1d89d36116f866a320e95e628 to your computer and use it in GitHub Desktop.
#include "shared/glslversion.h"
#include "glslcommon.inc"
#include "uniforms.inc"
in
#include "VertexData.h"
#include "LightData.h"
layout(location = 0) out vec4 my_FragColor0;
/*GBuffer*/
layout(binding = 0) uniform sampler2D gPosition;
layout(binding = 1) uniform usampler2D gAlbedoSpec;
layout(binding = 2) uniform usampler2D gSpecular;
layout(binding = 3) uniform sampler2D gDepth;
/*ENVPROBE*/
layout(binding = 4) uniform samplerCube envprobe_diffuse_rad;
layout(binding = 5) uniform samplerCube envprobe_specular_rad;
layout(binding = 6) uniform sampler2D envprobe_f0_scale_bias;
#ifndef DNR_LIGHTS
#define DNR_LIGHTS 0
#endif
const int NR_LIGHTS = DNR_LIGHTS + 1;
uniform LightData lights[NR_LIGHTS];
#include "Lighting.inc"
/*Normals packing/unpacking*/
#include "Normals.inc"
#include "depth.inc"
#if GLSL_VERSION > GLSLVERSION_150
layout(early_fragment_tests) in;
#endif
#include "uniforms.inc"
#include "GBuffer.inc"
#include "depth.inc"
#include "tonemapping.inc"
void main()
{
vec2 uv = VERTEXDATA.v_tex_coord;
/*GBuffer*/
GBufferInfo gbuffer;
UnPackGBuffer
(
gAlbedoSpec,
gSpecular,
gPosition,
ivec2(gl_FragCoord.xy),
uv,
gbuffer
);
vec4 lighting = vec4(0);
for (int i = 0;i < lights.length(); ++i)
{
lighting += ComputeLighting
(i, uv,
unpack_normal(gbuffer.normals),
gbuffer.worldPos,
vec4(gbuffer.albedo, gbuffer.specularPower),
gbuffer.specular, gbuffer.roughness
);
}
// Ambient Lighting
lighting.xyz += auto_globalAmbient*gbuffer.albedo;
GammaCorrection(u_gammaMode, lighting.xyz);
/*DEBUG*/
int draw_mode = debug_drawmode;
if (draw_mode == 1)
my_FragColor0 = vec4(toRGB(gbuffer.albedo), 1.0);
else if (draw_mode == 2)
my_FragColor0 = vec4(unpack_normal(gbuffer.normals), 1.0);
else if (draw_mode == 3)
my_FragColor0 = vec4(gbuffer.worldPos, 1.0);
else if (draw_mode == 4)
my_FragColor0 = vec4(vec3(gbuffer.roughness), 1.0);
else if (draw_mode == 5)
my_FragColor0 = vec4(toRGB(gbuffer.specular), 1.0);
else if (draw_mode == 6)
my_FragColor0 = vec4(vec3(gbuffer.specularPower), 1.0);
else if (draw_mode == 7)
my_FragColor0 = vec4(vec3(gbuffer.depth), 1.0);
else
my_FragColor0 = lighting;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment