-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented stable Poisson filtering demo. Source of inspiration:
- Loading branch information
Showing
13 changed files
with
810 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// https://www.shadertoy.com/view/4sfGzS | ||
float hash(vec3 p) // replace this by something better | ||
{ | ||
p = fract( p*0.3183099+.1 ); | ||
p *= 17.0; | ||
return fract( p.x*p.y*p.z*(p.x+p.y+p.z) ); | ||
} | ||
|
||
float noise( in vec3 x ) | ||
{ | ||
vec3 i = floor(x); | ||
vec3 f = fract(x); | ||
f = f*f*(3.0-2.0*f); | ||
|
||
return mix(mix(mix( hash(i+vec3(0,0,0)), | ||
hash(i+vec3(1,0,0)),f.x), | ||
mix( hash(i+vec3(0,1,0)), | ||
hash(i+vec3(1,1,0)),f.x),f.y), | ||
mix(mix( hash(i+vec3(0,0,1)), | ||
hash(i+vec3(1,0,1)),f.x), | ||
mix( hash(i+vec3(0,1,1)), | ||
hash(i+vec3(1,1,1)),f.x),f.y),f.z); | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include "common/poisson32.h" | ||
|
||
float pcf(sampler2DShadow shadowMap, vec4 clipPos, float bias, mat2 jitter) | ||
{ | ||
clipPos.z += bias; | ||
float sum = 0.; | ||
for (int i = 0; i < 32; ++i) | ||
{ | ||
vec2 offset = jitter * poisson32[i]; | ||
sum += textureProj(shadowMap, vec4(clipPos.xy + offset, clipPos.zw)); | ||
} | ||
return sum/32.; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
#version 450 | ||
#extension GL_GOOGLE_include_directive : enable | ||
#include "common/transforms.h" | ||
#include "common/noise2d.h" | ||
#include "common/noise3d.h" | ||
#include "pcf.h" | ||
|
||
#include "common/linearizeDepth.h" | ||
|
||
layout(constant_id = 0) const bool c_screenSpaceNoise = true; | ||
layout(constant_id = 1) const bool c_showNoise = false; | ||
|
||
layout(binding = 2) uniform Light | ||
{ | ||
vec4 viewPos; | ||
vec4 ambient; | ||
vec4 diffuse; | ||
vec4 specular; | ||
} light; | ||
|
||
layout(binding = 3) uniform Material | ||
{ | ||
vec4 ambient; | ||
vec4 diffuse; | ||
vec4 specular; | ||
float shininess; | ||
} surface; | ||
|
||
layout(binding = 4) uniform Parameters | ||
{ | ||
vec4 screenSize; // x, y, 1/x, 1/y | ||
float radius; | ||
float zbias; | ||
float jitterDensity; | ||
}; | ||
|
||
layout(binding = 5) uniform sampler2DShadow shadowMap; | ||
|
||
layout(location = 0) in vec4 worldPos; | ||
layout(location = 1) in vec3 viewPos; | ||
layout(location = 2) in vec3 viewNormal; | ||
layout(location = 3) in vec2 texCoord; | ||
|
||
layout(location = 0) out vec3 oColor; | ||
|
||
float screenNoise(vec4 fragCoord) | ||
{ | ||
vec2 uv = fragCoord.xy * screenSize.zw; | ||
float aspectRatio = screenSize.x * screenSize.w; | ||
uv.x *= aspectRatio; | ||
return noise(uv * screenSize.x); | ||
} | ||
|
||
float worldNoise(vec3 worldPos, float z, float density) | ||
{ | ||
float w = 1./z; | ||
return noise(worldPos * density * w); | ||
} | ||
|
||
mat2 jitter(float a, float x, float y) | ||
{ | ||
float s = sin(a); | ||
float c = cos(a); | ||
mat2 rot = mat2( | ||
c,-s, | ||
s, c); | ||
mat2 scale = mat2( | ||
x, 0., | ||
0., y); | ||
return rot * scale; | ||
} | ||
|
||
vec3 phong(vec3 n, vec3 l, vec3 v, | ||
vec3 Ka, vec3 Ia, | ||
vec3 Kdiff, vec3 Idiff, | ||
vec3 Kspec, vec3 Ispec, | ||
float shininess, | ||
float shadow) | ||
{ | ||
float NdL = max(dot(n, l), 0.); | ||
vec3 r = reflect(-l, n); | ||
float RdV = max(dot(r, v), 0.); | ||
return Ka * Ia + shadow * (Kdiff * NdL * Idiff) + (Kspec * pow(RdV, shininess) * Ispec); | ||
} | ||
|
||
void main() | ||
{ | ||
vec3 n = normalize(viewNormal); | ||
vec3 l = normalize(light.viewPos.xyz - viewPos); | ||
vec3 v = -normalize(viewPos); | ||
|
||
float theta; | ||
if (c_screenSpaceNoise) | ||
theta = screenNoise(gl_FragCoord); | ||
else | ||
theta = worldNoise(worldPos.xyz, viewPos.z, jitterDensity); | ||
|
||
float shadow; | ||
if (dot(n, l) <= 0.) | ||
shadow = 0.; | ||
else | ||
{ | ||
vec4 shadowPos = shadowProj * worldPos; | ||
vec2 scale = radius/textureSize(shadowMap, 0) * shadowPos.w; | ||
mat2 jitMat = jitter(theta * TWO_PI, scale.x, scale.y); | ||
shadow = pcf(shadowMap, shadowPos, zbias, jitMat); | ||
} | ||
|
||
oColor = phong(n, l, v, | ||
surface.ambient.rgb, light.ambient.rgb, | ||
surface.diffuse.rgb, light.diffuse.rgb, | ||
surface.specular.rgb, light.specular.rgb, | ||
surface.shininess, shadow); | ||
if (c_showNoise) | ||
oColor *= theta; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#version 450 | ||
#extension GL_GOOGLE_include_directive : enable | ||
#include "common/transforms.h" | ||
|
||
layout(location = 0) in vec4 position; | ||
|
||
out gl_PerVertex { | ||
vec4 gl_Position; | ||
}; | ||
|
||
void main() | ||
{ | ||
gl_Position = worldLightProj * position; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#version 450 | ||
#extension GL_GOOGLE_include_directive : enable | ||
#include "common/transforms.h" | ||
|
||
layout(location = 0) in vec4 position; | ||
layout(location = 1) in vec3 normal; | ||
|
||
layout(location = 0) out vec4 oWorldPos; | ||
layout(location = 1) out vec3 oViewPos; | ||
layout(location = 2) out vec3 oViewNormal; | ||
out gl_PerVertex { | ||
vec4 gl_Position; | ||
}; | ||
|
||
void main() | ||
{ | ||
oWorldPos = world * position; | ||
oViewPos = (worldView * position).xyz; | ||
oViewNormal = mat3(normalView) * normal; | ||
gl_Position = worldViewProj * position; | ||
} |
Oops, something went wrong.