1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- #version 430
- layout (location = 0) out vec3 worldPosition;
- layout (location = 1) out vec3 worldNormal;
- layout (location = 2) out vec4 worldColor;
- layout (location = 3) out float worldShadow;
- layout (binding = 0) uniform sampler2D samp;
- //layout (binding = 1) uniform sampler2DShadow shadowSamp;
- layout (binding = 1) uniform sampler2D shadowSamp;
- uniform mat4 proj;
- uniform mat4 view;
- uniform mat4 model;
- uniform mat4 projViewShadow;
- in vec3 varPosition;
- in vec2 varTex;
- in vec3 varNormal;
- in vec4 varShadow;
- uniform float radius;
- uniform float bias;
- const int sampleAmount = 64;
- const vec2 samples[64] = {
- vec2(-0.000, -0.000), vec2(-0.007, 0.004), vec2(0.016, 0.001), vec2(-0.015, -0.018),
- vec2(-0.024, -0.020), vec2(0.036, -0.014), vec2(-0.015, -0.045), vec2(0.037, 0.041),
- vec2(-0.036, -0.051), vec2(-0.069, 0.014), vec2(0.068, -0.039), vec2(0.086, -0.001),
- vec2(0.062, -0.070), vec2(-0.066, -0.077), vec2(-0.010, 0.109), vec2(-0.013, 0.117),
- vec2(-0.086, 0.091), vec2(0.019, 0.131), vec2(-0.051, 0.131), vec2(0.133, 0.067),
- vec2(0.154, -0.024), vec2(0.151, -0.063), vec2(0.124, 0.119), vec2(0.133, -0.121),
- vec2(0.149, 0.113), vec2(-0.188, -0.054), vec2(0.030, 0.201), vec2(0.002, 0.211),
- vec2(-0.063, -0.209), vec2(0.013, 0.226), vec2(-0.052, 0.229), vec2(-0.093, -0.223),
- vec2(0.153, 0.198), vec2(0.258, -0.005), vec2(-0.188, -0.188), vec2(0.267, -0.061),
- vec2(0.150, -0.238), vec2(0.027, 0.288), vec2(-0.293, 0.049), vec2(-0.044, 0.301),
- vec2(-0.018, 0.312), vec2(-0.296, -0.121), vec2(0.026, -0.327), vec2(-0.248, 0.226),
- vec2(-0.344, -0.008), vec2(-0.042, 0.349), vec2(-0.357, -0.038), vec2(-0.156, -0.332),
- vec2(-0.342, 0.154), vec2(0.031, 0.382), vec2(-0.331, 0.207), vec2(0.209, -0.339),
- vec2(-0.068, -0.401), vec2(-0.409, -0.063), vec2(-0.249, 0.340), vec2(-0.041, 0.428),
- vec2(0.326, 0.292), vec2(-0.127, -0.427), vec2(0.226, 0.393), vec2(0.424, 0.180),
- vec2(-0.063, 0.465), vec2(0.446, -0.167), vec2(-0.477, -0.084), vec2(-0.433, -0.234)
- };
- const vec3 light = vec3(-0.280166, -0.573576, -0.769751);
- void main(void) {
- worldPosition = varPosition;
- worldNormal = normalize(varNormal);
- vec3 pos = varShadow.xyz / varShadow.w;
- float fbias = bias * (1.0 - max(dot(worldNormal, -light), 0.0));
- float shadow = 0;
- for(int i = 0; i < sampleAmount; i++) {
- shadow += float(texture(shadowSamp, pos.xy + vec2(samples[i].x, samples[i].y) * radius).r + fbias > pos.z);
- }
- shadow /= sampleAmount;
- /*if(shadow < 0.5) {
- shadow = 4 * pow(shadow, 3);
- } else {
- //shadow = -2 * shadow * shadow + 4 * shadow - 1;
- shadow = 1 - exp(-40 * shadow - 0.693147180559945 + 20);
- }*/
- //shadow = 1 - exp(-40 * shadow - 0.693147180559945 + 20);
- //shadow = float(shadow > 0.05);
- worldShadow = shadow;
- //worldShadow = textureProj(shadowSamp, varShadow);
- //float f = 1.0 - max(dot(worldNormal, -light), 0.0);
- //worldColor = vec4(f, f, f, 1.0);
- worldColor = texture(samp, varTex);
- }
|