split render pipelines
This commit is contained in:
@@ -7,7 +7,7 @@ uniform samplerCube u_cubemap;
|
||||
|
||||
void main(){
|
||||
vec3 dir = normalize(v_coord);
|
||||
f_position = vec4(100000.0);
|
||||
f_position = vec4(0.0, 0.0, 0.0, 1e9);
|
||||
f_normal = vec4(0.0);
|
||||
f_color = texture(u_cubemap, dir);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ uniform sampler2D u_shadows;
|
||||
uniform ivec2 u_screenSize;
|
||||
uniform float u_intensity;
|
||||
uniform float u_timer;
|
||||
uniform bool u_enableShadows;
|
||||
uniform mat4 u_projection;
|
||||
|
||||
#include <__effect__>
|
||||
|
||||
@@ -1,50 +1,3 @@
|
||||
uniform vec3 samples[64];
|
||||
|
||||
int kernelSize = 32;
|
||||
float radius = 0.25;
|
||||
float bias = 0.025;
|
||||
|
||||
float near_plane = 0.5f;
|
||||
float far_plane = 200.0f;
|
||||
|
||||
// required when using a perspective projection matrix
|
||||
float linearize_depth(float depth) {
|
||||
float z = depth * 2.0 - 1.0; // Back to NDC
|
||||
return (2.0 * near_plane * far_plane) / (far_plane + near_plane - z * (far_plane - near_plane));
|
||||
}
|
||||
|
||||
float fmod(float x, float y) {
|
||||
return x - y * floor(x/y);
|
||||
}
|
||||
|
||||
vec4 effect() {
|
||||
vec2 noiseScale = u_screenSize / 4.0;
|
||||
|
||||
vec3 position = texture(u_position, v_uv).xyz;
|
||||
vec3 color = texture(u_screen, v_uv).rgb;
|
||||
vec3 normal = texture(u_normal, v_uv).xyz;
|
||||
vec3 randomVec = normalize(texture(u_noise, v_uv * noiseScale).xyz);
|
||||
|
||||
vec3 tangent = normalize(randomVec - normal * dot(randomVec, normal));
|
||||
vec3 bitangent = cross(normal, tangent);
|
||||
mat3 TBN = mat3(tangent, bitangent, normal);
|
||||
|
||||
float occlusion = 0.0;
|
||||
for(int i = 0; i < kernelSize; ++i)
|
||||
{
|
||||
vec3 samplePos = TBN * samples[i];
|
||||
samplePos = position + samplePos * radius;
|
||||
|
||||
vec4 offset = vec4(samplePos, 1.0);
|
||||
offset = u_projection * offset;
|
||||
offset.xyz /= offset.w;
|
||||
offset.xyz = offset.xyz * 0.5 + 0.5;
|
||||
|
||||
float sampleDepth = texture(u_position, offset.xy).z;
|
||||
float rangeCheck = smoothstep(0.0, 1.0, radius / abs(position.z - sampleDepth));
|
||||
occlusion += (sampleDepth >= samplePos.z + bias ? 1.0 : 0.0) * rangeCheck;
|
||||
}
|
||||
occlusion = 1.1 - (occlusion / kernelSize);
|
||||
float d = texture(u_shadows, v_uv).r;
|
||||
return vec4(color * occlusion, 1.0);
|
||||
return texture(u_screen, v_uv);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,39 @@
|
||||
uniform vec3 samples[64];
|
||||
uniform vec3 u_ssaoSamples[64];
|
||||
|
||||
int kernelSize = 32;
|
||||
float radius = 0.25;
|
||||
float bias = 0.025;
|
||||
|
||||
vec4 effect() {
|
||||
vec2 noiseScale = u_screenSize / 4.0;
|
||||
vec2 noiseScale = u_screenSize / 4.0;
|
||||
|
||||
vec3 position = texture(u_position, v_uv).xyz;
|
||||
vec3 color = texture(u_screen, v_uv).rgb;
|
||||
vec3 normal = texture(u_normal, v_uv).xyz;
|
||||
vec3 randomVec = texture(u_noise, v_uv * noiseScale).xyz;
|
||||
return vec4(randomVec, 1.0);
|
||||
vec3 randomVec = normalize(texture(u_noise, v_uv * noiseScale).xyz);
|
||||
|
||||
vec3 tangent = normalize(randomVec - normal * dot(randomVec, normal));
|
||||
vec3 bitangent = cross(normal, tangent);
|
||||
mat3 tbn = mat3(tangent, bitangent, normal);
|
||||
|
||||
float occlusion = 1.0;
|
||||
if (u_enableShadows) {
|
||||
occlusion = 0.0;
|
||||
for (int i = 0; i < kernelSize; i++) {
|
||||
vec3 samplePos = tbn * u_ssaoSamples[i];
|
||||
samplePos = position + samplePos * radius;
|
||||
|
||||
vec4 offset = vec4(samplePos, 1.0);
|
||||
offset = u_projection * offset;
|
||||
offset.xyz /= offset.w;
|
||||
offset.xyz = offset.xyz * 0.5 + 0.5;
|
||||
|
||||
float sampleDepth = texture(u_position, offset.xy).z;
|
||||
float rangeCheck = smoothstep(0.0, 1.0, radius / abs(position.z - sampleDepth));
|
||||
occlusion += (sampleDepth >= samplePos.z + bias ? 1.0 : 0.0) * rangeCheck;
|
||||
}
|
||||
occlusion = 1.1 - (occlusion / kernelSize);
|
||||
}
|
||||
|
||||
return vec4(color * occlusion, 1.0);
|
||||
}
|
||||
|
||||
@@ -37,18 +37,17 @@ void main() {
|
||||
|
||||
for (int i = 0; i < BLUR_SAMPLES; i++) {
|
||||
shadow += texture(u_shadows, projCoords.xyz + vec3(
|
||||
-0.002*(i%2==0?1:0)*i/BLUR_SAMPLES,
|
||||
-0.002*(i%2==0?0:1)*i/BLUR_SAMPLES,
|
||||
-0.002*(i%2==0?1:0)*i/BLUR_SAMPLES / 4.0,
|
||||
-0.002*(i%2==0?0:1)*i/BLUR_SAMPLES / 4.0,
|
||||
-0.0005 * i/BLUR_SAMPLES));
|
||||
}
|
||||
shadow /= BLUR_SAMPLES;
|
||||
shadow += 0.5;
|
||||
shadow = shadow * 0.7 + 0.3;
|
||||
shadow = shadow * 0.5 + 0.5;
|
||||
}
|
||||
|
||||
vec3 fogColor = texture(u_cubemap, a_dir).rgb;
|
||||
vec4 tex_color = texture(u_texture0, a_texCoord);
|
||||
float alpha = a_color.a * tex_color.a;
|
||||
vec4 texColor = texture(u_texture0, a_texCoord);
|
||||
float alpha = a_color.a * texColor.a;
|
||||
if (u_alphaClip) {
|
||||
if (alpha < 0.2f)
|
||||
discard;
|
||||
@@ -58,12 +57,13 @@ void main() {
|
||||
discard;
|
||||
}
|
||||
if (u_debugLights)
|
||||
tex_color.rgb = u_debugNormals ? (a_normal * 0.5 + 0.5) : vec3(1.0);
|
||||
texColor.rgb = u_debugNormals ? (a_normal * 0.5 + 0.5) : vec3(1.0);
|
||||
else if (u_debugNormals) {
|
||||
tex_color.rgb *= a_normal * 0.5 + 0.5;
|
||||
texColor.rgb *= a_normal * 0.5 + 0.5;
|
||||
}
|
||||
f_color = mix(a_color * tex_color, vec4(fogColor,1.0), a_fog);
|
||||
f_color = a_color * texColor;
|
||||
f_color.rgb *= shadow;
|
||||
f_color = mix(f_color, vec4(fogColor,1.0), a_fog);
|
||||
f_color.a = alpha;
|
||||
f_position = vec4(a_position, 1.0);
|
||||
f_normal = vec4(a_normal, 1.0);
|
||||
|
||||
Reference in New Issue
Block a user