79 lines
2.0 KiB
GLSL
79 lines
2.0 KiB
GLSL
#version 460
|
|
|
|
#extension GL_GOOGLE_include_directive : require
|
|
|
|
#include "structures.layout"
|
|
|
|
layout (location = 0) in struct FragDataIn {
|
|
vec3 normal;
|
|
vec2 uv;
|
|
} FragData;
|
|
|
|
layout (location = 0, index = 0) out vec4 FragColor;
|
|
|
|
vec4 CalculateDirectionalLight(vec4 diff_col, vec4 diff_samp, vec4 light_col, vec3 dir, vec3 normal)
|
|
{
|
|
float diffuse_factor = max(dot(normal, -dir), 0.0);
|
|
|
|
vec4 ambient = vec4(vec3(G.ambient_color * diff_col), diff_samp.a);
|
|
vec4 diffuse = vec4(vec3(light_col * diffuse_factor), diff_samp.a);
|
|
|
|
diffuse *= diff_samp;
|
|
ambient *= diff_samp;
|
|
|
|
return (ambient + diffuse);
|
|
}
|
|
|
|
float UnPreMultLinearToSRGB(float col)
|
|
{
|
|
return col < 0.0031308f ? col * 12.92f : (pow(col, 1.0f / 2.4f) * 1.055f) - 0.055f;
|
|
}
|
|
|
|
vec4 UnPreMultLinearToSRGB(vec4 col)
|
|
{
|
|
col.r = UnPreMultLinearToSRGB(col.x);
|
|
col.g = UnPreMultLinearToSRGB(col.x);
|
|
col.b = UnPreMultLinearToSRGB(col.x);
|
|
return col;
|
|
}
|
|
|
|
void main()
|
|
{
|
|
ivec2 coord = ivec2(gl_FragCoord.xy);
|
|
int store_mask = 0;
|
|
int view_size = int(G.res.x) * int(G.res.y);
|
|
int sample_id = 0;
|
|
int list_pos = view_size * OIT_LAYERS * sample_id + coord.y * int(G.res.x) + coord.x;
|
|
|
|
vec4 col = ModelDiffuse;
|
|
vec4 tex_col = texture(sampler2D(AlbedoTex, SamplerNearest), FragData.uv);
|
|
|
|
vec4 out_col = CalculateDirectionalLight(col, tex_col, G.light_color, G.light_direction, FragData.normal);
|
|
out_col.a = 1.0;// Materials[nonuniformEXT(PC.mat_id)].alpha;
|
|
|
|
if(ALPHA_TEX)
|
|
{
|
|
vec4 alpha_col = texture(sampler2D(AlphaTex, SamplerNearest), FragData.uv);
|
|
out_col.a = alpha_col.a;
|
|
}
|
|
|
|
//FragColor = out_col;
|
|
|
|
//TODO: set up OIT again
|
|
vec4 srgb_col = out_col;// UnPreMultLinearToSRGB(out_col);
|
|
|
|
uvec4 store_value = uvec4(packUnorm4x8(srgb_col), floatBitsToUint(gl_FragCoord.z), store_mask, 0);
|
|
|
|
uint old_counter = imageAtomicAdd(ImageAux, coord, 1u);
|
|
if (old_counter < OIT_LAYERS)
|
|
{
|
|
imageStore(ImageABuffer, list_pos + int(old_counter) * view_size, store_value);
|
|
|
|
FragColor = vec4(0.0);
|
|
}
|
|
else
|
|
{
|
|
FragColor = vec4(0.0); //vec4(out_col.rgb * out_col.a, out_col.a); // Change to vec4(0.0) to disable tail blending
|
|
}
|
|
}
|