initial
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
#version 450
|
||||
|
||||
layout(location = 0) out vec4 fragColor;
|
||||
layout(location = 0) in vec2 inUV;
|
||||
|
||||
layout(set = 1, binding = 0) uniform sampler2D inHdr;
|
||||
|
||||
layout( push_constant ) uniform constants
|
||||
{
|
||||
ivec2 resolution;
|
||||
} PushConstants;
|
||||
|
||||
/* a - ? - b
|
||||
* | | |
|
||||
* ? - c - ?
|
||||
* | | |
|
||||
* d - ? - e
|
||||
*/
|
||||
vec4 downscale() {
|
||||
vec2 srcTexelSize = 1.0f / PushConstants.resolution;
|
||||
float x = srcTexelSize.x;
|
||||
float y = srcTexelSize.y;
|
||||
|
||||
vec3 color = vec3(0.0f);
|
||||
vec3 a = texture(inHdr, vec2(inUV.x - 2*x, inUV.y + 2*y)).rgb;
|
||||
vec3 b = texture(inHdr, vec2(inUV.x + 2*x, inUV.y + 2*y)).rgb;
|
||||
|
||||
vec3 c = texture(inHdr, inUV).rgb;
|
||||
|
||||
vec3 d = texture(inHdr, vec2(inUV.x - 2*x, inUV.y - 2*y)).rgb;
|
||||
vec3 e = texture(inHdr, vec2(inUV.x + 2*x, inUV.y - 2*y)).rgb;
|
||||
|
||||
|
||||
|
||||
return vec4((a + b + c + d) * (1.0f/8.0f) + c * 1.0f/2.0f, 1.0);
|
||||
|
||||
/* vec3 a = texture(inHdr, vec2(inUV.x - 2*x, inUV.y + 2*y)).rgb;
|
||||
vec3 b = texture(inHdr, vec2(inUV.x, inUV.y + 2*y)).rgb;
|
||||
vec3 c = texture(inHdr, vec2(inUV.x + 2*x, inUV.y + 2*y)).rgb;
|
||||
|
||||
vec3 d = texture(inHdr, vec2(inUV.x - 2*x, inUV.y)).rgb;
|
||||
vec3 e = texture(inHdr, vec2(inUV.x, inUV.y)).rgb;
|
||||
vec3 f = texture(inHdr, vec2(inUV.x + 2*x, inUV.y)).rgb;
|
||||
|
||||
vec3 g = texture(inHdr, vec2(inUV.x - 2*x, inUV.y - 2*y)).rgb;
|
||||
vec3 h = texture(inHdr, vec2(inUV.x, inUV.y - 2*y)).rgb;
|
||||
vec3 i = texture(inHdr, vec2(inUV.x + 2*x, inUV.y - 2*y)).rgb;
|
||||
|
||||
vec3 j = texture(inHdr, vec2(inUV.x - x, inUV.y + y)).rgb;
|
||||
vec3 k = texture(inHdr, vec2(inUV.x + x, inUV.y + y)).rgb;
|
||||
vec3 l = texture(inHdr, vec2(inUV.x - x, inUV.y - y)).rgb;
|
||||
vec3 m = texture(inHdr, vec2(inUV.x + x, inUV.y - y)).rgb;
|
||||
|
||||
vec3 color = e * 0.125f;
|
||||
color += (a + c + g + i) * 0.03125;
|
||||
color += (b + d + f + h) * 0.0625;
|
||||
color += (j + k + l + m) * 0.125;
|
||||
return vec4(color, 1.0f); */
|
||||
|
||||
|
||||
}
|
||||
|
||||
void main() {
|
||||
fragColor = downscale();
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,81 @@
|
||||
#version 450
|
||||
|
||||
|
||||
layout(location = 0) out vec4 fragColor;
|
||||
layout(location = 0) in vec2 inUV;
|
||||
|
||||
layout(set = 1, binding = 0) uniform sampler2D inHdr;
|
||||
layout(set = 1, binding = 1) uniform sampler2D inBloom;
|
||||
|
||||
layout( push_constant ) uniform constants
|
||||
{
|
||||
float exposure;
|
||||
float gamma;
|
||||
} PushConstants;
|
||||
|
||||
const mat3x3 ACESInputMat =
|
||||
{
|
||||
{0.59719, 0.35458, 0.04823},
|
||||
{0.07600, 0.90834, 0.01566},
|
||||
{0.02840, 0.13383, 0.83777}
|
||||
};
|
||||
|
||||
// ODT_SAT => XYZ => D60_2_D65 => sRGB
|
||||
const mat3x3 ACESOutputMat =
|
||||
{
|
||||
{ 1.60475, -0.53108, -0.07367},
|
||||
{-0.10208, 1.10813, -0.00605},
|
||||
{-0.00327, -0.07276, 1.07602}
|
||||
};
|
||||
|
||||
vec3 RRTAndODTFit(vec3 v)
|
||||
{
|
||||
vec3 a = v * (v + 0.0245786f) - 0.000090537f;
|
||||
vec3 b = v * (0.983729f * v + 0.4329510f) + 0.238081f;
|
||||
return a / b;
|
||||
}
|
||||
|
||||
vec3 ACESFitted(vec3 color)
|
||||
{
|
||||
color = transpose(ACESInputMat) * color;
|
||||
|
||||
// Apply RRT and ODT
|
||||
color = RRTAndODTFit(color);
|
||||
|
||||
color = transpose(ACESOutputMat) * color;
|
||||
|
||||
// Clamp to [0, 1]
|
||||
color = clamp(color, vec3(0.0f), vec3(1.0f));
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
vec4 upscale() {
|
||||
vec2 srcTexelSize = 1.0f / vec2(1200, 800) * 2.0f;
|
||||
float x = srcTexelSize.x;
|
||||
float y = srcTexelSize.y;
|
||||
|
||||
vec3
|
||||
color = texture(inBloom, vec2(inUV.x + x, inUV.y + y)).rgb;
|
||||
color += texture(inBloom, vec2(inUV.x + x, inUV.y - y)).rgb;
|
||||
color += texture(inBloom, vec2(inUV.x - x, inUV.y + y)).rgb;
|
||||
color += texture(inBloom, vec2(inUV.x - x, inUV.y - y)).rgb;
|
||||
|
||||
color += 2.0f * texture(inBloom, vec2(inUV.x + x, inUV.y)).rgb;
|
||||
color += 2.0f * texture(inBloom, vec2(inUV.x - x, inUV.y)).rgb;
|
||||
color += 2.0f * texture(inBloom, vec2(inUV.x, inUV.y + y)).rgb;
|
||||
color += 2.0f * texture(inBloom, vec2(inUV.x, inUV.y - y)).rgb;
|
||||
|
||||
color += 4.0f * texture(inBloom, inUV).rgb;
|
||||
|
||||
return vec4(color * (1.0f / 16.0f), 1.0f);
|
||||
}
|
||||
|
||||
void main() {
|
||||
|
||||
vec3 color = ACESFitted(texture(inHdr, inUV).rgb * PushConstants.exposure + upscale().rgb);
|
||||
|
||||
color = pow(color.rgb, vec3(1.0/PushConstants.gamma));
|
||||
|
||||
fragColor = vec4(color, 1.0);
|
||||
}
|
||||
Binary file not shown.
+11
@@ -0,0 +1,11 @@
|
||||
FILES=$(wildcard ./*.glsl)
|
||||
|
||||
SPIRV=$(FILES:%.glsl=%.spirv)
|
||||
|
||||
debug: $(SPIRV)
|
||||
|
||||
%.spirv:%.glsl
|
||||
glslangValidator -g -V $^ -o $@
|
||||
|
||||
clean:
|
||||
rm -f ./*.spirv
|
||||
@@ -0,0 +1,11 @@
|
||||
#version 450
|
||||
|
||||
layout(location = 0) out vec2 outUV;
|
||||
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
outUV = vec2((gl_VertexIndex << 1) & 2, gl_VertexIndex & 2);
|
||||
gl_Position = vec4(outUV * 2.0f - 1.0f, 0.0f, 1.0f);
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,56 @@
|
||||
#version 450
|
||||
|
||||
layout(location = 0) out vec4 fragColor;
|
||||
layout(location = 1) out vec4 fragNormal;
|
||||
layout(location = 2) out vec4 fragPosition;
|
||||
layout(location = 3) out vec4 fragPbr;
|
||||
|
||||
layout(location = 0) in vec3 inPos;
|
||||
layout(location = 1) in vec3 inNormal;
|
||||
layout(location = 2) in vec2 inUV;
|
||||
layout(location = 3) in mat3 inTBN;
|
||||
|
||||
layout( push_constant ) uniform constants
|
||||
{
|
||||
uint transformIdx;
|
||||
uint materialIdx;
|
||||
} PushConstants;
|
||||
|
||||
struct Material {
|
||||
vec4 albedo;
|
||||
vec4 bsdf;
|
||||
|
||||
int colorTexture;
|
||||
float colorTextureBlend;
|
||||
|
||||
int normalTexture;
|
||||
float normalTextureBlend;
|
||||
|
||||
int pbrTexture;
|
||||
float pbrTextureBlend;
|
||||
};
|
||||
|
||||
|
||||
layout(set = 2, binding = 0) uniform Materials {
|
||||
Material materials[128];
|
||||
} materials;
|
||||
|
||||
layout(set = 2, binding = 1) uniform sampler2D colorTextures[128];
|
||||
// layout(set = 2, binding = 2) uniform sampler2DArray normalTextures;
|
||||
// layout(set = 2, binding = 3) uniform sampler2DArray pbrTextures;
|
||||
|
||||
|
||||
void main() {
|
||||
Material material = materials.materials[PushConstants.materialIdx];
|
||||
vec2 uv = inUV;
|
||||
|
||||
vec3 color = texture(colorTextures[material.colorTexture], uv).rgb;
|
||||
vec3 normal = texture(colorTextures[material.normalTexture], uv).rgb;
|
||||
normal = normalize(normal * 2.0 - 1.0);
|
||||
vec2 pbr = texture(colorTextures[material.pbrTexture], uv).bg;
|
||||
|
||||
fragColor = vec4(mix(material.albedo.rgb, color, material.colorTextureBlend), 1.0);
|
||||
fragNormal = vec4(mix(inNormal, normalize(inTBN * normalize(normal)), material.normalTextureBlend), 1.0);
|
||||
fragPosition = vec4(inPos, 1.0);
|
||||
fragPbr = vec4(pbr, 0.0, 1.0);
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,43 @@
|
||||
#version 450
|
||||
|
||||
layout(location = 0) in vec3 pos;
|
||||
layout(location = 1) in vec3 norm;
|
||||
layout(location = 2) in vec2 uv;
|
||||
layout(location = 3) in vec4 tangent;
|
||||
|
||||
layout(set = 0, binding = 0) uniform Camera {
|
||||
mat4 proj;
|
||||
mat4 view;
|
||||
} cam;
|
||||
|
||||
|
||||
struct SceneNode {
|
||||
uint transformIdx;
|
||||
uint meshIdx;
|
||||
};
|
||||
|
||||
layout(set = 2, binding = 1) uniform ObjectInfo {
|
||||
SceneNode nodes[];
|
||||
} objectInfo;
|
||||
|
||||
layout(location = 0) out vec3 outPos;
|
||||
layout(location = 1) out vec3 outNormal;
|
||||
layout(location = 2) out vec2 outUV;
|
||||
layout(location = 3) out mat3 outTBN;
|
||||
|
||||
layout( push_constant ) uniform constants
|
||||
{
|
||||
uint transformIdx;
|
||||
uint materialIdx;
|
||||
} PushConstants;
|
||||
|
||||
|
||||
void main() {
|
||||
vec3 bitangent = cross(norm, tangent.xyz) * tangent.w;
|
||||
outTBN = mat3(tangent.xyz, bitangent, norm);
|
||||
|
||||
outPos = pos.xyz * 0.05;
|
||||
outNormal = norm.xyz;
|
||||
outUV = uv;
|
||||
gl_Position = cam.proj * cam.view * vec4(outPos, 1.0);
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,13 @@
|
||||
#version 450
|
||||
|
||||
layout (location = 0) in vec4 inColor;
|
||||
layout (location = 1) in float inGradientPos;
|
||||
|
||||
layout (location = 0) out vec4 outFragColor;
|
||||
|
||||
void main ()
|
||||
{
|
||||
//vec3 color = texture(samplerGradientRamp, vec2(inGradientPos, 0.0)).rgb;
|
||||
//outFragColor.rgb = texture(samplerColorMap, gl_PointCoord).rgb * color;
|
||||
outFragColor = vec4(inColor.rgb, 1.0f);
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,26 @@
|
||||
#version 450
|
||||
|
||||
layout (location = 0) in vec4 inPos;
|
||||
layout (location = 1) in vec4 inGradientPos;
|
||||
|
||||
layout (location = 0) out vec4 outColor;
|
||||
layout (location = 1) out float outGradientPos;
|
||||
|
||||
layout(set = 0, binding = 0) uniform Camera {
|
||||
mat4 proj;
|
||||
mat4 view;
|
||||
} cam;
|
||||
|
||||
out gl_PerVertex
|
||||
{
|
||||
vec4 gl_Position;
|
||||
float gl_PointSize;
|
||||
};
|
||||
|
||||
void main ()
|
||||
{
|
||||
gl_PointSize = 8.0;
|
||||
outColor = vec4(1.0);
|
||||
outGradientPos = inGradientPos.x;
|
||||
gl_Position = cam.proj * cam.view * vec4(inPos.xy * 0.01, 1.0, 1.0);
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,72 @@
|
||||
#version 450
|
||||
|
||||
struct Particle {
|
||||
vec4 position;
|
||||
vec4 velocity;
|
||||
vec4 gradient_pos;
|
||||
};
|
||||
|
||||
layout(std140, binding = 0) buffer ParticleBuffer {
|
||||
Particle particles[];
|
||||
};
|
||||
|
||||
layout (local_size_x = 256) in;
|
||||
|
||||
|
||||
|
||||
vec2 attraction(vec2 pos, vec2 attractPos)
|
||||
{
|
||||
vec2 delta = attractPos - pos;
|
||||
const float damp = 0.5;
|
||||
float dDampedDot = dot(delta, delta) + damp;
|
||||
float invDist = 1.0f / sqrt(dDampedDot);
|
||||
float invDistCubed = invDist*invDist*invDist;
|
||||
return delta * invDistCubed * 0.0035;
|
||||
}
|
||||
|
||||
vec2 repulsion(vec2 pos, vec2 attractPos)
|
||||
{
|
||||
vec2 delta = attractPos - pos;
|
||||
float targetDistance = sqrt(dot(delta, delta));
|
||||
return delta * (1.0 / (targetDistance * targetDistance * targetDistance)) * -0.000035;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
uint particle_count = 1000;
|
||||
float dest_x = 0.0f;
|
||||
float dest_y = 0.0f;
|
||||
float delta_time = 0.001;
|
||||
// Current SSBO index
|
||||
uint index = gl_GlobalInvocationID.x;
|
||||
// Don't try to write beyond particle count
|
||||
if (index >= particle_count)
|
||||
return;
|
||||
|
||||
// Read position and velocity
|
||||
vec2 vVel = particles[index].velocity.xy;
|
||||
vec2 vPos = particles[index].position.xy;
|
||||
|
||||
vec2 destPos = vec2(dest_x, dest_y);
|
||||
|
||||
vec2 delta = destPos - vPos;
|
||||
float targetDistance = sqrt(dot(delta, delta));
|
||||
vVel += repulsion(vPos, destPos.xy) * 0.05;
|
||||
|
||||
// Move by velocity
|
||||
vPos += vVel * delta_time;
|
||||
|
||||
// collide with boundary
|
||||
if ((vPos.x < -1.0) || (vPos.x > 1.0) || (vPos.y < -1.0) || (vPos.y > 1.0))
|
||||
vVel = (-vVel * 0.1) + attraction(vPos, destPos) * 12;
|
||||
else
|
||||
particles[index].position.xy = vPos;
|
||||
|
||||
// Write back
|
||||
particles[index].velocity.xy = vVel;
|
||||
particles[index].gradient_pos.x += 0.02 * delta_time;
|
||||
if (particles[index].gradient_pos.x > 1.0)
|
||||
particles[index].gradient_pos.x -= 1.0;
|
||||
particles[index].position = vec4(0.0, index, index, 1.0f);
|
||||
|
||||
}
|
||||
Binary file not shown.
+192
@@ -0,0 +1,192 @@
|
||||
#version 460
|
||||
|
||||
#define M_PI 3.14159265359
|
||||
|
||||
layout(location = 0) in vec2 inUV;
|
||||
|
||||
layout(location = 0) out vec4 outColor;
|
||||
// layout(location = 1) out vec4 outBloomThreshold;
|
||||
|
||||
layout(set = 1, binding = 1) uniform sampler2D inAlbedo;
|
||||
layout(set = 1, binding = 2) uniform sampler2D inNormal;
|
||||
layout(set = 1, binding = 3) uniform sampler2D inPosition;
|
||||
layout(set = 1, binding = 4) uniform sampler2D inPbr;
|
||||
// layout(set = 1, binding = 5) uniform sampler2D shadowMap;
|
||||
|
||||
float ggx_normal_distr(float NoH, float roughness) {
|
||||
float a = NoH * roughness;
|
||||
float k = roughness / (1.0 - NoH * NoH + a * a);
|
||||
return k * k * (1.0 / M_PI);
|
||||
}
|
||||
|
||||
vec3 schlick(float VoH, vec3 f0) {
|
||||
return f0 + (vec3(1.0) - f0) * pow(1.0 - VoH, 5.0);
|
||||
}
|
||||
|
||||
float ggx_smith_correlated(float NoV, float NoL, float a) {
|
||||
float a2 = a * a;
|
||||
float GGXL = NoV * sqrt((-NoL * a2 + NoL) * NoL + a2);
|
||||
float GGXV = NoL * sqrt((-NoV * a2 + NoV) * NoV + a2);
|
||||
return 0.5 / (GGXV + GGXL + 0.0001);
|
||||
}
|
||||
|
||||
|
||||
vec3 lambert_diffuse(vec3 albedo) {
|
||||
return albedo / M_PI;
|
||||
}
|
||||
|
||||
layout(set = 0, binding = 0) uniform Camera {
|
||||
mat4 proj;
|
||||
mat4 view;
|
||||
vec4 position;
|
||||
} cam;
|
||||
|
||||
struct Light {
|
||||
mat4 view;
|
||||
vec4 color;
|
||||
vec4 position;
|
||||
};
|
||||
|
||||
layout(set = 1, binding = 0) uniform Lights {
|
||||
Light lights[];
|
||||
} lights;
|
||||
|
||||
#define AMBIENT 0.1
|
||||
|
||||
float linearize_depth(float depth) {
|
||||
float n = 1000.0f;
|
||||
float f = 1.0f;
|
||||
float z = depth;
|
||||
return (2.0 * n) / (f + n - z * (f - n));
|
||||
}
|
||||
|
||||
float textureProj(vec4 shadowCoord, vec2 off) {
|
||||
return 0.0f;
|
||||
/* float shadow = 0.0f;
|
||||
|
||||
float dist = texture( shadowMap, shadowCoord.st + off ).r;
|
||||
if ( shadowCoord.w > 0.0 )
|
||||
{
|
||||
shadow = (dist < shadowCoord.z) ? 1.0f : 0.0f;
|
||||
}
|
||||
return shadow; */
|
||||
}
|
||||
|
||||
float filterPCF(vec4 sc) {
|
||||
return 0.0f;
|
||||
/* ivec2 texDim = textureSize(shadowMap, 0);
|
||||
float scale = 6.0f;
|
||||
float dx = scale * 1.0 / float(texDim.x);
|
||||
float dy = scale * 1.0 / float(texDim.y);
|
||||
|
||||
float shadowFactor = 0.0;
|
||||
int count = 0;
|
||||
int range = 12;
|
||||
|
||||
for (int x = -range; x <= range; x++)
|
||||
{
|
||||
for (int y = -range; y <= range; y++)
|
||||
{
|
||||
shadowFactor += textureProj(sc, vec2(dx*x, dy*y));
|
||||
count++;
|
||||
}
|
||||
|
||||
}
|
||||
return shadowFactor / count; */
|
||||
}
|
||||
|
||||
const mat4 biasMat = mat4(
|
||||
0.5, 0.0, 0.0, 0.0,
|
||||
0.0, 0.5, 0.0, 0.0,
|
||||
0.0, 0.0, 1.0, 0.0,
|
||||
0.5, 0.5, 0.0, 1.0
|
||||
);
|
||||
|
||||
|
||||
float get_shadow(int lightIdx, vec4 position) {
|
||||
Light light = lights.lights[0];
|
||||
vec4 relativePosition = light.view * position;
|
||||
vec4 shadowCoords = relativePosition / relativePosition.w;
|
||||
|
||||
float shadow = filterPCF(biasMat * shadowCoords);
|
||||
|
||||
return shadow;
|
||||
}
|
||||
|
||||
vec3 bsdf(vec3 normal, vec3 viewDir, vec3 lightDir, vec3 baseColor, float metallic, float roughness) {
|
||||
vec3 halfway = normalize(viewDir + lightDir);
|
||||
float NoH = max(0.0, dot(normal, halfway));
|
||||
float NoL = max(0.0, dot(normal, lightDir));
|
||||
float NoV = abs(dot(normal, viewDir)) + 1e-5;
|
||||
float VoH = max(0.0, dot(viewDir, halfway));
|
||||
float LoH = max(0.0, dot(lightDir, halfway));
|
||||
|
||||
|
||||
/* color at 0 degree angle */
|
||||
vec3 f0 = 0.16 * (1.0 - roughness) * (1.0 - roughness) * (1.0 - metallic) + baseColor * metallic;
|
||||
vec3 diffuseColor = (1.0 - metallic) * baseColor.rgb;
|
||||
|
||||
/* normal distribution of the dome */
|
||||
float D = ggx_normal_distr(NoH, roughness);
|
||||
/* occlusion of microfacets */
|
||||
float G = ggx_smith_correlated(NoV, NoL, roughness);
|
||||
/* fresnel */
|
||||
vec3 F = schlick(VoH, f0);
|
||||
|
||||
vec3 specular = D * G * F; /// (4.0 * NoV * NoL + 0.0001);
|
||||
/* light emmited back by material (not reflection) */
|
||||
|
||||
vec3 diffuse = lambert_diffuse(diffuseColor);
|
||||
|
||||
return (diffuse + specular) * NoL * 4.0f;
|
||||
}
|
||||
|
||||
vec3 bloom_threshold(vec3 base) {
|
||||
float threshold = 0.8f;
|
||||
float knee = 0.5f;
|
||||
float intensity = 0.4f;
|
||||
vec4 curveThreshold = vec4(threshold - knee, knee * 2.0f, 0.25f / max(1e-5f, knee), threshold);
|
||||
|
||||
// Pixel brightness
|
||||
float br = max((base).x, max((base).y, (base).z));
|
||||
|
||||
// Under-threshold part: quadratic curve
|
||||
float rq = clamp(br - curveThreshold.x, 0.0, curveThreshold.y);
|
||||
rq = curveThreshold.z * rq * rq;
|
||||
|
||||
// Combine and apply the brightness response curve.
|
||||
base *= max(rq, br - curveThreshold.w) / max(1e-5, br);
|
||||
|
||||
// Clamp pixel intensity if clamping enabled
|
||||
if (intensity > 0.0) {
|
||||
br = max(1e-5, max((base).x, max((base).y, (base).z)));
|
||||
base *= 1.0 - max(0.0, br - intensity) / br;
|
||||
}
|
||||
|
||||
return base;
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec3 color = texture(inAlbedo, inUV).rgb;
|
||||
float metallic = texture(inPbr, inUV).r;
|
||||
float roughness = texture(inPbr, inUV).g;
|
||||
roughness *= roughness;
|
||||
vec3 normal = texture(inNormal, inUV).rgb;
|
||||
vec3 position = texture(inPosition, inUV).rgb;
|
||||
|
||||
vec3 viewDir = normalize(-cam.position.xyz - position);
|
||||
|
||||
vec3 lightDir = -normalize(vec3(lights.lights[0].view[0][2], lights.lights[0].view[1][2], lights.lights[0].view[2][2]));
|
||||
|
||||
float occlusion = get_shadow(0, vec4(position, 1.0));
|
||||
|
||||
float lightIntensity = 1.5f;
|
||||
vec3 Lo = bsdf(normal, viewDir, lightDir, color, metallic, roughness);
|
||||
|
||||
vec3 ambient = vec3(0.2) * color;
|
||||
vec3 prd = ambient + Lo * (1.0 - occlusion) * lightIntensity;
|
||||
|
||||
outColor = vec4(prd, 1.0);
|
||||
|
||||
// outBloomThreshold = vec4(bloom_threshold(prd), dot(bloom_threshold(prd), bloom_threshold(prd)));
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,7 @@
|
||||
#version 450
|
||||
|
||||
|
||||
|
||||
void main() {
|
||||
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,14 @@
|
||||
#version 450
|
||||
|
||||
layout(location = 0) in vec3 pos;
|
||||
layout(location = 1) in vec3 norm;
|
||||
layout(location = 2) in vec2 uv;
|
||||
layout(location = 3) in vec3 tangent;
|
||||
|
||||
layout( push_constant ) uniform constants {
|
||||
mat4 view;
|
||||
} Camera;
|
||||
|
||||
void main() {
|
||||
gl_Position = Camera.view * vec4(pos * 0.05, 1.0);
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,53 @@
|
||||
#version 450
|
||||
|
||||
layout(location = 0) out vec4 fragColor;
|
||||
layout(location = 1) out vec4 fragNormal;
|
||||
layout(location = 2) out vec4 fragPosition;
|
||||
layout(location = 3) out vec4 fragPbr;
|
||||
|
||||
layout(location = 0) in vec3 inPos;
|
||||
layout(location = 1) in vec3 inNormal;
|
||||
layout(location = 2) in vec2 inUV;
|
||||
layout(location = 3) in mat3 inTBN;
|
||||
|
||||
layout( push_constant ) uniform constants
|
||||
{
|
||||
uint transformIdx;
|
||||
uint materialIdx;
|
||||
} PushConstants;
|
||||
|
||||
struct Material {
|
||||
vec4 albedo;
|
||||
vec4 bsdf;
|
||||
|
||||
int colorTexture;
|
||||
float colorTextureBlend;
|
||||
|
||||
int normalTexture;
|
||||
float normalTextureBlend;
|
||||
|
||||
int pbrTexture;
|
||||
float pbrTextureBlend;
|
||||
};
|
||||
|
||||
layout(set = 2, binding = 0) uniform Materials {
|
||||
Material materials[128];
|
||||
} materials;
|
||||
|
||||
layout(set = 2, binding = 2) uniform sampler2DArray colorTextures;
|
||||
layout(set = 2, binding = 3) uniform sampler2DArray normalTextures;
|
||||
layout(set = 2, binding = 4) uniform sampler2DArray pbrTextures;
|
||||
|
||||
|
||||
void main() {
|
||||
Material material = materials.materials[PushConstants.materialIdx];
|
||||
vec4 color = texture(colorTextures, vec3(inUV, material.colorTexture)).rgba;
|
||||
vec3 normal = texture(normalTextures, vec3(inUV, materials.materials[PushConstants.materialIdx].normalTexture)).rgb;
|
||||
normal = normalize(normal * 2.0 - 1.0);
|
||||
vec2 pbr = texture(pbrTextures, vec3(inUV, material.pbrTexture)).bg;
|
||||
|
||||
fragColor = vec4(mix(material.albedo.rgb, color.rgb, material.colorTextureBlend), color.a);
|
||||
fragNormal = vec4(mix(inNormal, normalize(inTBN * normalize(normal)), 1.0), color.a);
|
||||
fragPosition = vec4(inPos, color.a);
|
||||
fragPbr = vec4(mix(material.bsdf.xy, pbr, 1.0), 0.0, color.a);
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,58 @@
|
||||
#version 450
|
||||
|
||||
layout(location = 0) out vec4 fragColor;
|
||||
layout(location = 0) in vec2 inUV;
|
||||
|
||||
layout(set = 1, binding = 0) uniform sampler2D source;
|
||||
layout(set = 1, binding = 1) uniform sampler2D upscaled;
|
||||
|
||||
layout( push_constant ) uniform constants
|
||||
{
|
||||
ivec2 resolution;
|
||||
} PushConstants;
|
||||
|
||||
/* ? - e - ?
|
||||
* | a | b |
|
||||
* f - ? - g
|
||||
* | c | d |
|
||||
* ? - h - ?
|
||||
*/
|
||||
vec4 upscale() {
|
||||
vec2 srcTexelSize = 1.0f / PushConstants.resolution * 2.0f;
|
||||
float x = srcTexelSize.x;
|
||||
float y = srcTexelSize.y;
|
||||
|
||||
vec3 color = vec3(0.0f);
|
||||
vec3 a = texture(upscaled, vec2(inUV.x - x, inUV.y + y)).rgb;
|
||||
vec3 b = texture(upscaled, vec2(inUV.x + x, inUV.y + y)).rgb;
|
||||
|
||||
vec3 c = texture(upscaled, vec2(inUV.x - x, inUV.y - y)).rgb;
|
||||
vec3 d = texture(upscaled, vec2(inUV.x + x, inUV.y - y)).rgb;
|
||||
|
||||
vec3 e = texture(upscaled, vec2(inUV.x, inUV.y + 2.0*y)).rgb;
|
||||
vec3 h = texture(upscaled, vec2(inUV.x, inUV.y - 2.0*y)).rgb;
|
||||
|
||||
vec3 f = texture(upscaled, vec2(inUV.x - 2.0*x, inUV.y)).rgb;
|
||||
vec3 g = texture(upscaled, vec2(inUV.x + 2.0*x, inUV.y)).rgb;
|
||||
|
||||
return vec4((a + b + c + d) * (1.0f/6.0f) + (e + f + g + h) * (1.0f/12.0f), 1.0);
|
||||
|
||||
/* vec3
|
||||
color = texture(upscaled, vec2(inUV.x + x, inUV.y + y)).rgb;
|
||||
color += texture(upscaled, vec2(inUV.x + x, inUV.y - y)).rgb;
|
||||
color += texture(upscaled, vec2(inUV.x - x, inUV.y + y)).rgb;
|
||||
color += texture(upscaled, vec2(inUV.x - x, inUV.y - y)).rgb;
|
||||
|
||||
color += 2.0f * texture(upscaled, vec2(inUV.x + x, inUV.y)).rgb;
|
||||
color += 2.0f * texture(upscaled, vec2(inUV.x - x, inUV.y)).rgb;
|
||||
color += 2.0f * texture(upscaled, vec2(inUV.x, inUV.y + y)).rgb;
|
||||
color += 2.0f * texture(upscaled, vec2(inUV.x, inUV.y - y)).rgb;
|
||||
|
||||
color += 4.0f * texture(upscaled, inUV).rgb;
|
||||
|
||||
return vec4(color * (1.0f / 16.0f), 1.0f); */
|
||||
}
|
||||
|
||||
void main() {
|
||||
fragColor = texture(source, inUV) + upscale();
|
||||
}
|
||||
Binary file not shown.
Reference in New Issue
Block a user