Skip to content

Commit

Permalink
feat(architecture): add shader
Browse files Browse the repository at this point in the history
  • Loading branch information
yyc-git committed Oct 31, 2020
1 parent c8378ec commit 4f1ce41
Show file tree
Hide file tree
Showing 19 changed files with 1,351 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/run/domain_layer/domain/shader/accumulation/accumulation.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#version 450
#pragma shader_stage(fragment)

#include "../common/utils.glsl"

layout(location = 0) in vec2 uv;
layout(location = 0) out vec4 outColor;

layout(std140, set = 0, binding = 0) buffer PixelBuffer { vec4 pixels[]; }
pixelBuffer;

layout(std140, set = 0, binding = 1) buffer AccumulationPixelBuffer {
vec4 pixels[];
}
accumulationPixelBuffer;

layout(set = 0, binding = 2) uniform ScreenDimension { vec2 resolution; }
screenDimension;

layout(std140, set = 0, binding = 3) uniform CommonData {
uint sampleCount;
uint totalSampleCount;
uint pad_0;
uint pad_1;
}
pushC;

void main() {
uint pixelIndex = getPixelIndex(uv, screenDimension.resolution);

vec4 accumulationColor = accumulationPixelBuffer.pixels[pixelIndex] +
pixelBuffer.pixels[pixelIndex];

accumulationPixelBuffer.pixels[pixelIndex] = accumulationColor;

vec4 finalColor = accumulationColor / pushC.totalSampleCount;

finalColor = vec4(gammaCorrection(vec3(finalColor)), finalColor.w);

outColor = finalColor;
}
10 changes: 10 additions & 0 deletions src/run/domain_layer/domain/shader/accumulation/accumulation.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#version 450
#pragma shader_stage(vertex)

layout(location = 0) out vec2 uv;

void main() {
uv = vec2((gl_VertexIndex << 1) & 2, gl_VertexIndex & 2);
gl_Position = vec4(uv * 2.0 - 1.0, 0.0, 1.0);
// uv = vec2(uv.x, 1.0 - uv.y);
}
9 changes: 9 additions & 0 deletions src/run/domain_layer/domain/shader/common/camera.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
layout(std140, set = 1, binding = 0) uniform Camera {
mat4 viewInverse;
mat4 projectionInverse;
float near;
float far;
float pad_0;
float pad_1;
}
uCamera;
40 changes: 40 additions & 0 deletions src/run/domain_layer/domain/shader/common/utils.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

// float saturateFloat(float v) {
// if (v < 0.0) {
// return 0.0;
// }

// if (v > 1.0) {
// return 1.0;
// }

// return v;
// }

// vec2 saturateVec2(vec2 v) {
// return vec2(saturateFloat(v.x), saturateFloat(v.y));
// }

float max(float f1, float f2, float f3) { return max(max(f1, f2), f3); }

uint getPixelIndex(vec2 uv, vec2 resolution) {
const ivec2 bufferCoord = ivec2(floor(uv * resolution));

return bufferCoord.y * uint(resolution.x) + bufferCoord.x;
}

vec2 gammaCorrection(vec2 colorInLinearSpace) {
return pow(colorInLinearSpace, vec2(1.0 / 2.2));
}

vec3 gammaCorrection(vec3 colorInLinearSpace) {
return pow(colorInLinearSpace, vec3(1.0 / 2.2));
}

vec3 convertSRGBToLinear(vec3 specificColorDefinedInShader) {
return pow(specificColorDefinedInShader, vec3(2.2));
}

vec3 getVFromRayDirection(vec3 rayDirection) { return -rayDirection; }

vec3 getRayDirectionFromV(vec3 V) { return -V; }
Loading

0 comments on commit 4f1ce41

Please sign in to comment.