First commit
This commit is contained in:
225
shaders/old/ambientOcclusion.shader
Executable file
225
shaders/old/ambientOcclusion.shader
Executable file
@@ -0,0 +1,225 @@
|
||||
/**
|
||||
* Kepler - Core
|
||||
* STUDIOS
|
||||
* All rights reserved.
|
||||
* Obfuscated by Shader closure (A product of kaj dijkstra)
|
||||
*/
|
||||
|
||||
/**
|
||||
* Author: Kaj Dijksta
|
||||
*/
|
||||
|
||||
|
||||
|
||||
attribute vec2 uv;
|
||||
attribute vec3 position;
|
||||
uniform mat4 viewProjection;
|
||||
varying vec2 v_uv;
|
||||
void main ( void ) {
|
||||
v_uv = uv;
|
||||
gl_Position = viewProjection *vec4 ( position , 1.0 );
|
||||
}
|
||||
// #keplerEngine - Split
|
||||
|
||||
#ifndef AMBIANT_ONLY
|
||||
#define AMBIANT_ONLY 0
|
||||
#endif
|
||||
|
||||
precision highp float;
|
||||
varying vec2 v_uv;
|
||||
uniform sampler2D infoSampler;
|
||||
uniform sampler2D randomSampler;
|
||||
|
||||
uniform float screenWidth;
|
||||
uniform float screenHeight;
|
||||
uniform vec3 cameraPosition;
|
||||
uniform float far;
|
||||
|
||||
uniform vec3 scale[ 32 ];
|
||||
uniform vec4 kernelRad[ 8 ];
|
||||
|
||||
|
||||
struct fragmentPass { highp vec2 uv; mediump vec4 diffuse; mediump vec3 normal; mediump vec3 positionWorld; mediump float ambiantOcclusion; highp float far; highp float depth; highp float depthNorm; };
|
||||
float function_0 ( vec3 var_0 , vec3 var_1 , vec3 var_2 , float var_3 )
|
||||
{
|
||||
mediump vec3 var_4 = reflect ( -var_2 , var_0 );
|
||||
return pow ( clamp ( dot ( var_1 , var_4 ) , 0.0 , 1.0 ) , var_3 );
|
||||
}
|
||||
|
||||
float function_1 ( vec2 var_0 ) {
|
||||
mediump vec4 var_1 = vec4 (.6 , 0.075 , 1.0 , 1.0 );
|
||||
const mediump float var_2 = 1.0 -1.0 /8.0;
|
||||
const mediump float var_3 = 0.025;
|
||||
mediump float var_4 = 0.0;
|
||||
mediump vec3 var_5[8];
|
||||
var_5[0] = normalize ( vec3 ( 1.0 , 1.0 , 1.0 ) ) *var_3 *( var_4 += var_2 );
|
||||
var_5[1] = normalize ( vec3 ( -1.0 , -1.0 , -1.0 ) ) *var_3 *( var_4 += var_2 );
|
||||
var_5[2] = normalize ( vec3 ( -1.0 , -1.0 , 1.0 ) ) *var_3 *( var_4 += var_2 );
|
||||
var_5[3] = normalize ( vec3 ( -1.0 , 1.0 , -1.0 ) ) *var_3 *( var_4 += var_2 );
|
||||
var_5[4] = normalize ( vec3 ( -1.0 , 1.0 , 1.0 ) ) *var_3 *( var_4 += var_2 );
|
||||
var_5[5] = normalize ( vec3 ( 1.0 , -1.0 , -1.0 ) ) *var_3 *( var_4 += var_2 );
|
||||
var_5[6] = normalize ( vec3 ( 1.0 , -1.0 , 1.0 ) ) *var_3 *( var_4 += var_2 );
|
||||
var_5[7] = normalize ( vec3 ( 1.0 , 1.0 , -1.0 ) ) *var_3 *( var_4 += var_2 );
|
||||
mediump vec3 var_6 = texture2D ( randomSampler , vec2 ( screenWidth , screenHeight ) *var_0 /4.0 ).xyz *2.0 -1.0;
|
||||
mediump float var_7 = texture2D ( infoSampler , var_0 ).w;
|
||||
mediump float var_8 = var_7 *far;
|
||||
mediump vec3 var_9 = var_1.zzw *clamp ( var_8 /5.3 , 0.0 , 1.0 ) *( 1.0 +var_8 /8.0 );
|
||||
mediump float var_10 = far /var_9.z *0.75;
|
||||
var_9.xy *= 1.0 /var_8;
|
||||
var_9.z *= 2.0 /far;
|
||||
float var_11 = 64.0 /var_9.z;
|
||||
mediump vec4 var_12[2];
|
||||
mediump vec4 var_13 = vec4 ( 0.0 );
|
||||
mediump vec3 var_14;
|
||||
mediump vec4 var_15;
|
||||
highp vec4 var_16 = vec4 ( 0.0 );
|
||||
const float var_17 = 0.2;
|
||||
vec4 var_18;
|
||||
var_14 = reflect ( var_5[0] , var_6 ) *var_9;
|
||||
var_12[0].x = texture2D ( infoSampler , var_0.xy +var_14.xy ).w +var_14.z;
|
||||
var_14.xyz *= var_17;
|
||||
var_12[1].x = texture2D ( infoSampler , var_0.xy +var_14.xy ).w +var_14.z;
|
||||
var_14 = reflect ( var_5[1] , var_6 ) *var_9;
|
||||
var_12[0].y = texture2D ( infoSampler , var_0.xy +var_14.xy ).w +var_14.z;
|
||||
var_14.xyz *= var_17;
|
||||
var_12[1].y = texture2D ( infoSampler , var_0.xy +var_14.xy ).w +var_14.z;
|
||||
var_14 = reflect ( var_5[2] , var_6 ) *var_9;
|
||||
var_12[0].z = texture2D ( infoSampler , var_0.xy +var_14.xy ).w +var_14.z;
|
||||
var_14.xyz *= var_17;
|
||||
var_12[1].z = texture2D ( infoSampler , var_0.xy +var_14.xy ).w +var_14.z;
|
||||
var_14 = reflect ( var_5[3] , var_6 ) *var_9;
|
||||
var_12[0].w = texture2D ( infoSampler , var_0.xy +var_14.xy ).w +var_14.z;
|
||||
var_14.xyz *= var_17;
|
||||
var_12[1].w = texture2D ( infoSampler , var_0.xy +var_14.xy ).w +var_14.z;
|
||||
const float var_19 = 0.001;
|
||||
var_15 = var_7 -var_12[0];
|
||||
var_18 = var_15 *var_10;
|
||||
var_16 = ( clamp ( abs ( var_18 ) , 0.0 , 1.0 ) +clamp ( var_18 , 0.0 , 1.0 ) ) /2.0;
|
||||
var_13 += mix ( clamp ( ( -var_15 ) *var_11 , 0.0 , 1.0 ) , vec4 ( var_19 ) , var_16 );
|
||||
var_15 = var_7 -var_12[1];
|
||||
var_18 = var_15 *var_10;
|
||||
var_16 = ( clamp ( abs ( var_18 ) , 0.0 , 1.0 ) +clamp ( var_18 , 0.0 , 1.0 ) ) /2.0;
|
||||
var_13 += mix ( clamp ( ( -var_15 ) *var_11 , 0.0 , 1.0 ) , vec4 ( var_19 ) , var_16 );
|
||||
float var_20 = dot ( var_13 , vec4 ( ( 1.0 /16.0 ) *2.0 ) ) -var_1.y;
|
||||
var_20 = clamp ( mix ( 0.9 , var_20 , var_1.x ) , 0.0 , 1.0 );
|
||||
return var_20;
|
||||
}
|
||||
|
||||
float function_2 ( vec2 var_0 , float var_1 , vec3 var_2 )
|
||||
{
|
||||
const mediump float var_3 = 0.4;
|
||||
const mediump int var_4 = 16;
|
||||
const mediump float var_5 = 0.05;
|
||||
const mediump float var_6 = var_3 /( float ( var_4 ) /2.0 );
|
||||
const mediump float var_7 = 1000.0;
|
||||
mediump float var_8 = 2.8 *( 1.0 +sqrt ( var_5 ) ) /var_7;
|
||||
const mediump float var_9 = 1.0 -2.8;
|
||||
mediump vec3 var_10 = texture2D ( randomSampler , vec2 ( screenWidth , screenHeight ) *var_0 /4.0 ).xyz *2.0 -1.0;
|
||||
mediump vec4 var_11 = vec4 ( var_7 /var_1 );
|
||||
mediump vec4 var_12 = vec4 ( 0.0 );
|
||||
for ( int var_13 = 0; var_13 < var_4 /4; var_13 ++)
|
||||
{
|
||||
mediump vec4 var_14 = vec4 ( 0.0 );
|
||||
mediump vec4 var_15 = vec4 ( 0.0 );
|
||||
mediump vec4 var_16 = vec4 ( 0.0 );
|
||||
for ( int var_17 = 0; var_17 < 4; ++var_17 )
|
||||
{
|
||||
mediump vec3 var_18 = reflect ( scale[4 *var_13 +var_17] , var_10 );
|
||||
var_16[var_17] = dot ( var_18 , var_2 );
|
||||
var_18 = ( var_16[var_17] >= 0.0 ) ? var_18 : -var_18;
|
||||
var_14[var_17] = texture2D ( infoSampler , var_0.xy +var_18.xy ).w;
|
||||
var_15[var_17] = var_18.z;
|
||||
}
|
||||
var_14 = var_14 *var_11;
|
||||
mediump vec4 var_19 = clamp ( var_7 +var_15 *( 2.0 *var_7 ) -var_14 , 0.0 , 1.0 );
|
||||
var_19 *= clamp ( var_8 *var_14 +var_9 , 0.0 , 1.0 );
|
||||
var_19 *= ( abs ( var_16 ) *kernelRad[var_13] );
|
||||
var_12 += var_19;
|
||||
}
|
||||
var_12 *= var_6;
|
||||
lowp float var_20 = 1.0 -dot ( vec4 ( 1.0 ) , var_12 );
|
||||
return var_20;
|
||||
}
|
||||
|
||||
float function_3 ( vec2 var_0 , float var_1 , vec3 var_2 )
|
||||
{
|
||||
const mediump vec4 var_3 = vec4 ( 1. , 0.075 , 1.0 , 2.0 );
|
||||
const int var_4 = 8;
|
||||
const mediump float var_5 = 0.6;
|
||||
const mediump float var_6 = 1.0 /var_5;
|
||||
const mediump float var_7 = 2.5;
|
||||
const mediump float var_8 = var_3.x;
|
||||
vec3 var_9[16];
|
||||
var_9[0] = vec3 ( -0.055664 , -0.00371090 , -0.0654297 );
|
||||
var_9[1] = vec3 ( 0.0173828 , 0.0111328 , 0.0064453 );
|
||||
var_9[2] = vec3 ( 0.0001953 , 0.008203100000000001 , -0.0060547 );
|
||||
var_9[3] = vec3 ( 0.0220703 , -0.035937500000000004 , -0.00625 );
|
||||
var_9[4] = vec3 ( 0.0242188 , 0.012695300000000001 , -0.025 );
|
||||
var_9[5] = vec3 ( 0.0070313 , -0.0025391000000000003 , 0.014843799999999999 );
|
||||
var_9[6] = vec3 ( -0.007812 , 0.0013672 , -0.0314453 );
|
||||
var_9[7] = vec3 ( 0.0117188 , -0.0140625 , -0.019921900000000003 );
|
||||
var_9[8] = vec3 ( -0.025195 , -0.055859400000000003 , 0.008203100000000001 );
|
||||
var_9[9] = vec3 ( 0.0308594 , 0.019335900000000003 , 0.0324219 );
|
||||
var_9[10] = vec3 ( 0.0173828 , -0.0140625 , 0.003125 );
|
||||
var_9[11] = vec3 ( 0.0179688 , -0.0044922 , 0.004687500000000001 );
|
||||
var_9[12] = vec3 ( -0.014648 , -0.020117200000000002 , -0.0029297000000000004 );
|
||||
var_9[13] = vec3 ( -0.030078 , 0.0234375 , 0.0539063 );
|
||||
var_9[14] = vec3 ( 0.0228516 , 0.0154297 , -0.0119141 );
|
||||
var_9[15] = vec3 ( -0.011914 , -0.00039060000000000006 , -0.006640600000000001 );
|
||||
mediump vec3 var_10 = texture2D ( randomSampler , vec2 ( screenWidth , screenHeight ) *var_0 /4.0 ).xyz *2.0 -1.0;
|
||||
mediump vec4 var_11 = vec4 ( 1.0 /var_1 );
|
||||
mediump vec4 var_12 = vec4 ( 0.0 );
|
||||
for ( int var_13 = 0; var_13 < var_4; var_13 += 4 )
|
||||
{
|
||||
mediump vec4 var_14 = vec4 ( 0.0 );
|
||||
mediump vec4 var_15 = vec4 ( 0.0 );
|
||||
mediump vec4 var_16;
|
||||
mediump vec4 var_17;
|
||||
for ( int var_18 = 0; var_18 < 4; ++var_18 )
|
||||
{
|
||||
mediump vec3 var_19 = reflect ( var_9[var_13 +var_18] , var_10 );
|
||||
float var_20 = dot ( var_19 , var_2 );
|
||||
var_19 = ( var_20 >= 0.0 ) ? var_19 : -var_19;
|
||||
var_14[var_18] = texture2D ( infoSampler , ( var_0 +var_19.xy ) ).w;
|
||||
var_15[var_18] = var_19.z;
|
||||
}
|
||||
var_14 = var_14 *var_11;
|
||||
mediump vec4 var_21 = ( 1.0 +var_15 *2. -var_14 ) *var_6;
|
||||
var_16 = clamp ( var_7 *var_21 , 0.0 , 1.0 );
|
||||
var_17 = clamp ( 1.0 /var_21 , 0.0 , 1.0 );
|
||||
var_12 += var_16 *var_17;
|
||||
}
|
||||
var_12 *= var_8 /float ( var_4 );
|
||||
mediump float var_22 = dot ( vec4 ( 1.0 ) , var_12 );
|
||||
return 1.0 -var_22;
|
||||
}
|
||||
|
||||
mediump vec3 function_4 ( mediump vec2 var_0 ) {
|
||||
mediump vec2 var_1 = var_0 *4.0 -2.0;
|
||||
|
||||
mediump float var_2 = dot ( var_1 , var_1 );
|
||||
mediump float var_3 = sqrt ( 1.0 -var_2 /4.0 );
|
||||
mediump vec3 var_4;
|
||||
var_4.xy = var_1 *var_3;
|
||||
var_4.z = 1.0 -var_2 /2.0;
|
||||
return var_4;
|
||||
}
|
||||
|
||||
void main ( void ) {
|
||||
vec4 var_0 = texture2D ( infoSampler , v_uv );
|
||||
float var_1 = var_0.w ;
|
||||
//vec3 var_3 = function_4 ( var_0.yz );
|
||||
vec3 var_3 = var_0.xyz;
|
||||
|
||||
float var_4;
|
||||
|
||||
// var_4 = function_1 ( v_uv );
|
||||
var_4 = function_3 ( v_uv , var_1 , var_3 );
|
||||
gl_FragColor = vec4 ( var_4 , var_4 , var_4 , 1.0 );
|
||||
//gl_FragColor = vec4(v_uv, 0.0, 1.0);
|
||||
|
||||
//gl_FragColor = vec4(vec3(texture2D ( infoSampler , v_uv).w/10.),1.0);//werkt
|
||||
// gl_FragColor = vec4(vec3(texture2D ( infoSampler , v_uv).xyz),1.0);//werkt
|
||||
|
||||
//gl_FragColor = vec4(texture2D ( randomSampler, v_uv).xyz , 1.0);//werkt
|
||||
}
|
||||
1058
shaders/old/color.shader
Executable file
1058
shaders/old/color.shader
Executable file
File diff suppressed because it is too large
Load Diff
83
shaders/old/convolution.shader
Executable file
83
shaders/old/convolution.shader
Executable file
@@ -0,0 +1,83 @@
|
||||
/**
|
||||
* Kepler - Core
|
||||
* Copyright (c) 2010 kaj dijkstra STUDIOS
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Author: Kaj Dijksta
|
||||
*/
|
||||
|
||||
attribute vec3 position;
|
||||
attribute vec2 uv;
|
||||
|
||||
uniform mat4 viewProjection;
|
||||
|
||||
varying vec2 v_textureCoord;
|
||||
|
||||
void main(void) {
|
||||
v_textureCoord = uv;
|
||||
gl_Position = viewProjection * vec4(position, 1.0);
|
||||
}
|
||||
|
||||
// #keplerEngine - Split
|
||||
|
||||
precision highp float;
|
||||
|
||||
uniform sampler2D image;
|
||||
uniform vec2 imageIncrement;
|
||||
uniform sampler2D random;
|
||||
|
||||
uniform float merge;
|
||||
|
||||
uniform float far;
|
||||
|
||||
|
||||
varying vec2 v_textureCoord;
|
||||
|
||||
void main() {
|
||||
|
||||
float MSAA1X[13];
|
||||
//MSAA1X[0] = 0.004433048175243747;
|
||||
//MSAA1X[1] = 0.054005582622414484;
|
||||
//MSAA1X[2] = 0.2420362293761143;
|
||||
//MSAA1X[3] = 0.3990502796524549;
|
||||
//MSAA1X[4] = 0.2420362293761143;
|
||||
//MSAA1X[5] = 0.054005582622414484;
|
||||
//MSAA1X[6] = 0.004433048175243747;
|
||||
|
||||
|
||||
MSAA1X[0] = 0.0022181958546457665;
|
||||
MSAA1X[1] = 0.008773134791588384;
|
||||
MSAA1X[2] = 0.027023157602879527;
|
||||
MSAA1X[3] = 0.06482518513852684;
|
||||
MSAA1X[4] = 0.12110939007484814;
|
||||
MSAA1X[5] = 0.17621312278855084;
|
||||
MSAA1X[6] = 0.19967562749792112;
|
||||
MSAA1X[7] = 0.17621312278855084;
|
||||
MSAA1X[8] = 0.12110939007484814;
|
||||
MSAA1X[9] = 0.06482518513852684;
|
||||
MSAA1X[10] = 0.027023157602879527;
|
||||
MSAA1X[11] = 0.008773134791588384;
|
||||
MSAA1X[12] = 0.0022181958546457665;
|
||||
|
||||
|
||||
|
||||
vec2 imageCoordTmp = v_textureCoord + (vec2(imageIncrement) * 6.0);
|
||||
|
||||
vec4 sum = vec4(0.0);
|
||||
|
||||
|
||||
for (int i = 0; i < 12; ++i) {
|
||||
sum += texture2D(image, imageCoordTmp) * MSAA1X[i];
|
||||
|
||||
|
||||
imageCoordTmp -= imageIncrement;
|
||||
}
|
||||
|
||||
|
||||
|
||||
gl_FragColor = vec4(sum);
|
||||
}
|
||||
|
||||
|
||||
432
shaders/old/deferred.shader
Executable file
432
shaders/old/deferred.shader
Executable file
@@ -0,0 +1,432 @@
|
||||
#version 300 es
|
||||
|
||||
precision highp float;
|
||||
|
||||
in vec2 uv;
|
||||
in vec3 position;
|
||||
|
||||
out vec2 v_uv;
|
||||
|
||||
uniform mat4 viewProjection;
|
||||
|
||||
|
||||
|
||||
void main(void) {
|
||||
v_uv = uv;
|
||||
|
||||
gl_Position = viewProjection * vec4(position, 1.0);
|
||||
}
|
||||
|
||||
// #keplerEngine - Split
|
||||
|
||||
#version 300 es
|
||||
|
||||
precision highp float;
|
||||
|
||||
#define PI 3.14159265358979323846
|
||||
#define ANISOTROPY 0
|
||||
#define USE_IES_PROFILE 0
|
||||
#define TRANSPARENT_MATERIAL 0
|
||||
#define TRANSLUCENT_MATERIAL 0
|
||||
#define CUBEMAP_EDGE_FIXUP 0
|
||||
|
||||
|
||||
uniform float lightType;
|
||||
uniform vec3 lightGeometry;
|
||||
uniform samplerCube reflectionSampler;
|
||||
uniform float clearCoat;
|
||||
uniform vec3 clearCoatColor;
|
||||
uniform float clearCoatThickness;
|
||||
uniform float clearCoatRoughness;
|
||||
uniform vec3 lightDirection;
|
||||
uniform float attenuation;
|
||||
uniform float SourceRadius;
|
||||
uniform float SourceLength;
|
||||
uniform float environmentLuminance;
|
||||
uniform vec3 lightPosition;
|
||||
uniform vec3 lightColor;
|
||||
uniform float lightIntensity;
|
||||
uniform float clearCoatIOR;
|
||||
uniform vec3 cameraPosition;
|
||||
|
||||
|
||||
uniform float metallic;
|
||||
|
||||
|
||||
#include "physically_based_shading.shader"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define TEXTURED_MATERIAL 1
|
||||
|
||||
out vec4 fragmentColor;
|
||||
|
||||
in vec2 v_uv;
|
||||
|
||||
|
||||
|
||||
|
||||
uniform float reflectance;
|
||||
|
||||
|
||||
|
||||
uniform float anisotropy;
|
||||
|
||||
|
||||
|
||||
uniform float roughness;
|
||||
|
||||
|
||||
|
||||
uniform sampler2D diffuseSampler;
|
||||
uniform sampler2D normalSampler;
|
||||
uniform sampler2D tangentSampler;
|
||||
uniform sampler2D infoSampler;
|
||||
|
||||
uniform sampler2D ambientOcclusionSampler;
|
||||
uniform sampler2D materialSampler;
|
||||
uniform sampler2D shadowNoiseSampler;
|
||||
uniform sampler2D shadowDepthSampler;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
uniform float luma_z;
|
||||
uniform float far;
|
||||
|
||||
|
||||
uniform mat4 InvProjection;
|
||||
uniform mat4 lightViewProjection;
|
||||
uniform vec2 screenSize;
|
||||
uniform float shadowBias;
|
||||
|
||||
const float PackUpscale = 256. / 255.; // fraction -> 0..1 (including 1)
|
||||
const float UnpackDownscale = 255. / 256.; // 0..1 -> fraction (excluding 1)
|
||||
|
||||
const vec3 PackFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );
|
||||
const vec4 UnpackFactors = UnpackDownscale / vec4( PackFactors, 1. );
|
||||
|
||||
const float ShiftRight8 = 1. / 256.;
|
||||
|
||||
vec4 packDepthToRGBA( const in float v ) {
|
||||
vec4 r = vec4( fract( v * PackFactors ), v );
|
||||
r.yzw -= r.xyz * ShiftRight8; // tidy overflow
|
||||
return r * PackUpscale;
|
||||
}
|
||||
|
||||
float unpackRGBAToDepth( const in vec4 v ) {
|
||||
return dot( v, UnpackFactors );
|
||||
}
|
||||
|
||||
|
||||
|
||||
float shadow_sample(sampler2D depthMap, vec2 coord)
|
||||
{
|
||||
return ( texture(depthMap, coord.xy).x );//DecodeFloatRGBA() ;
|
||||
}
|
||||
|
||||
vec2 DoubleSampleRotated(sampler2D depthMap, vec4 p, vec4 rotMatr, vec4 kernel) {
|
||||
|
||||
vec4 rotatedOff;
|
||||
|
||||
rotatedOff = rotMatr.xyzw * kernel.xxww +
|
||||
rotMatr.zwxy * kernel.yyzz;
|
||||
|
||||
vec4 fetchPos = p.xyxy + rotatedOff;// + rotatedOff
|
||||
|
||||
vec2 result;
|
||||
|
||||
result.x = shadow_sample(depthMap, fetchPos.xy);
|
||||
result.y = shadow_sample(depthMap, fetchPos.zw);
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
float PCF(sampler2D depthMap, vec4 p, vec2 randDirTC, float depth)
|
||||
{
|
||||
|
||||
vec2 kernelRadius = vec2(4.0);
|
||||
|
||||
vec4 irreg_kernel_2d[8];
|
||||
irreg_kernel_2d[0] = vec4(-0.556641,-0.037109,-0.654297, 0.111328);
|
||||
irreg_kernel_2d[1] = vec4(0.173828,0.111328,0.064453, -0.359375);
|
||||
irreg_kernel_2d[2] = vec4(0.001953,0.082031,-0.060547, 0.078125);
|
||||
irreg_kernel_2d[3] = vec4(0.220703,-0.359375,-0.062500, 0.001953);
|
||||
irreg_kernel_2d[4] = vec4(0.242188,0.126953,-0.250000, -0.140625);
|
||||
irreg_kernel_2d[5] = vec4(0.070313,-0.025391,0.148438, 0.082031);
|
||||
irreg_kernel_2d[6] = vec4(-0.078125,0.013672,-0.314453, 0.013672);
|
||||
irreg_kernel_2d[7] = vec4(0.117188,-0.140625,-0.199219, 0.117188);
|
||||
|
||||
vec2 vInvShadowMapWH = vec2(1.0 / 2048.0);
|
||||
|
||||
const int kernelSize = 8;
|
||||
|
||||
mediump float P_Z = depth; // p.z;
|
||||
|
||||
vec4 p0 = vec4(p.xyz, 1.0);
|
||||
|
||||
|
||||
mediump vec2 rotScale = vec2(kernelRadius.y * 2.0);
|
||||
|
||||
float shadowTest = 0.0;
|
||||
|
||||
#define KERNEL_STEP_SIZE 2
|
||||
|
||||
vec2 rotSample = 2.0 * texture(shadowDepthSampler, randDirTC.xy).xy - 1.0;
|
||||
rotSample.xy = normalize(rotSample.xy);
|
||||
rotSample.xy *= (kernelRadius.xy * vInvShadowMapWH.xy);
|
||||
|
||||
vec4 rot = vec4(rotSample.x, -rotSample.y, rotSample.y, rotSample.x);
|
||||
|
||||
const int kernelOffset = 0;
|
||||
|
||||
for(int i=kernelOffset; i<kernelSize; i+=KERNEL_STEP_SIZE) // Loop over taps
|
||||
{
|
||||
|
||||
mediump vec4 sampleDepth = vec4(0.0);
|
||||
vec4 irr = irreg_kernel_2d[i+0];
|
||||
sampleDepth.xy = DoubleSampleRotated(depthMap, p0, rot, irr);
|
||||
sampleDepth.zw = DoubleSampleRotated(depthMap, p0, rot, irreg_kernel_2d[i+1]);
|
||||
|
||||
mediump vec4 InShadow;
|
||||
InShadow.x = ( P_Z < sampleDepth.x + shadowBias ) ? 1. : 0.0;
|
||||
InShadow.y = ( P_Z < sampleDepth.y + shadowBias ) ? 1. : 0.0;
|
||||
InShadow.z = ( P_Z < sampleDepth.z + shadowBias ) ? 1. : 0.0;
|
||||
InShadow.w = ( P_Z < sampleDepth.w + shadowBias ) ? 1. : 0.0;
|
||||
|
||||
|
||||
const mediump float quality = 8.0; // 8 == high
|
||||
const mediump float fInvSamplNum = (1.0 / quality);
|
||||
|
||||
shadowTest += dot(InShadow, vec4(fInvSamplNum));
|
||||
}
|
||||
|
||||
return shadowTest;
|
||||
}
|
||||
|
||||
float DecodeFloatRGBA( vec4 rgba ) {
|
||||
return (rgba).x;
|
||||
|
||||
//return dot( rgba, vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 160581375.0) );
|
||||
}
|
||||
|
||||
float poissonPCFmultitap(vec4 projCoords, float shadowDepth, vec2 uv)
|
||||
{
|
||||
const mediump float step = 1.0 - 1.0 / 8.0;
|
||||
const mediump float fScale = 0.025; // 0.025
|
||||
|
||||
mediump float n = 0.0;
|
||||
|
||||
mediump vec3 directions[8];
|
||||
float vSampleScale = 1.0 / 2048.0;
|
||||
|
||||
|
||||
directions[0] = normalize(vec3( 1.0, 1.0, 1.0))*fScale*(n+=step);
|
||||
directions[1] = normalize(vec3(-1.0,-1.0,-1.0))*fScale*(n+=step);
|
||||
directions[2] = normalize(vec3(-1.0,-1.0, 1.0))*fScale*(n+=step);
|
||||
directions[3] = normalize(vec3(-1.0, 1.0,-1.0))*fScale*(n+=step);
|
||||
directions[4] = normalize(vec3(-1.0, 1.0 ,1.0))*fScale*(n+=step);
|
||||
directions[5] = normalize(vec3( 1.0,-1.0,-1.0))*fScale*(n+=step);
|
||||
directions[6] = normalize(vec3( 1.0,-1.0, 1.0))*fScale*(n+=step);
|
||||
directions[7] = normalize(vec3( 1.0, 1.0,-1.0))*fScale*(n+=step);
|
||||
|
||||
mediump vec3 randomSample = texture(shadowNoiseSampler, vec2(64.0, 64.0) * uv.xy / 4.0).xyz * 2.0 - 1.0;
|
||||
|
||||
|
||||
|
||||
float sum = 0.0;
|
||||
|
||||
for( int i = 0; i < 4; i++ ) {
|
||||
vec3 sampler = reflect(directions[0], randomSample) * vSampleScale;
|
||||
|
||||
float pixelDepth = DecodeFloatRGBA( texture(shadowDepthSampler, projCoords.xy+ sampler.xy ) ) ; // + sampler.xy + sampler.z
|
||||
|
||||
if( pixelDepth + shadowBias > shadowDepth) {
|
||||
sum += 1.0;
|
||||
} else {
|
||||
sum += 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
float linestep(float min, float max, float value) {
|
||||
return clamp((value - min) / (max - min), 0., 1.);
|
||||
}
|
||||
|
||||
float reduceBleeding(float p_max, float amount) {
|
||||
return linestep(amount, 1.0, p_max);
|
||||
}
|
||||
|
||||
float ChebyshevUpperBound(vec2 moments, float distance) {
|
||||
if (distance <= moments.x)
|
||||
return 1.0;
|
||||
|
||||
float g_minVariance = .0007;
|
||||
|
||||
float variance = moments.y - (moments.x*moments.x);
|
||||
variance = max(variance,g_minVariance);
|
||||
|
||||
float d = distance - moments.x;
|
||||
float p_max = variance / (variance + d*d);
|
||||
|
||||
return reduceBleeding(p_max, shadowBias);
|
||||
}
|
||||
|
||||
float calculateShadowOcclusion( vec3 worldPosition, vec2 uv ) {
|
||||
|
||||
vec4 projCoords = lightViewProjection * vec4(worldPosition, 1.0) ;
|
||||
|
||||
float shadowDepth = length( lightPosition - worldPosition ) / 99.0;
|
||||
|
||||
projCoords.xy /= projCoords.w;
|
||||
projCoords = 0.51 * projCoords + 0.5;
|
||||
|
||||
vec4 moments = texture( shadowDepthSampler, projCoords.xy );
|
||||
mediump vec2 randomSample = texture(shadowNoiseSampler, vec2(1024.) * uv / 64.0).xy * 2.0 - 1.0;
|
||||
|
||||
float outFrustum = 0.0;
|
||||
|
||||
if(projCoords.x < 0.0 || projCoords.x > 1.0) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
if(projCoords.y < 0.0 || projCoords.y > 1.0) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
if(projCoords.z < 1.0) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
return ChebyshevUpperBound(moments.xy, shadowDepth);
|
||||
return poissonPCFmultitap(projCoords, shadowDepth, uv);
|
||||
//return PCF( shadowDepthSampler, projCoords, randomSample, shadowDepth );
|
||||
|
||||
|
||||
}
|
||||
|
||||
vec3 sampleReflection( vec3 r ) {
|
||||
|
||||
return texture(reflectionSampler, r).xyz;
|
||||
|
||||
}
|
||||
|
||||
vec3 cubemapReflection( deferredMaterialData materialData ) {
|
||||
|
||||
vec3 viewDir = ( cameraPosition - materialData.position );
|
||||
vec3 reflectionVector = reflect(-viewDir, normalize( materialData.normal ));
|
||||
vec3 reflectionSample = sampleReflection( reflectionVector );
|
||||
|
||||
return reflectionSample;
|
||||
}
|
||||
|
||||
|
||||
const float gamma = 2.2;
|
||||
|
||||
float toLinear(float v) {
|
||||
return pow(v, gamma);
|
||||
}
|
||||
|
||||
vec2 toLinear(vec2 v) {
|
||||
return pow(v, vec2(gamma));
|
||||
}
|
||||
|
||||
vec3 toLinear(vec3 v) {
|
||||
return pow(v, vec3(gamma));
|
||||
}
|
||||
|
||||
vec4 toLinear(vec4 v) {
|
||||
return vec4(toLinear(v.rgb), v.a);
|
||||
}
|
||||
|
||||
|
||||
vec3 HDR_ACES(const vec3 x) {
|
||||
// Narkowicz 2015, "ACES Filmic Tone Mapping Curve"
|
||||
const float a = 2.51;
|
||||
const float b = 0.03;
|
||||
const float c = 2.43;
|
||||
const float d = 0.59;
|
||||
const float e = 0.14;
|
||||
return (x * (a * x + b)) / (x * (c * x + d) + e);
|
||||
}
|
||||
|
||||
vec3 tonemap(const vec3 x) {
|
||||
return HDR_ACES(x);
|
||||
}
|
||||
|
||||
float linearToSRGB(float c) {
|
||||
return (c <= 0.0031308) ? c * 12.92 : (pow(abs(c), 1.0 / 2.4) * 1.055) - 0.055;
|
||||
}
|
||||
|
||||
vec3 linearToSRGB(vec3 c) {
|
||||
return vec3(linearToSRGB(c.r), linearToSRGB(c.g), linearToSRGB(c.b));
|
||||
}
|
||||
|
||||
|
||||
void main() {
|
||||
|
||||
deferredMaterialData materialData;
|
||||
|
||||
float gamma = 2.2;
|
||||
|
||||
vec4 normalDepth = texture(normalSampler, v_uv);
|
||||
vec4 diffuseRoughness = texture(diffuseSampler, v_uv);
|
||||
vec4 positionMaterialIndex = texture(infoSampler, v_uv);
|
||||
vec4 depthNormal = texture(normalSampler, v_uv);
|
||||
vec4 shadowAmbientOcclusion = texture(ambientOcclusionSampler, v_uv);
|
||||
|
||||
materialData.ambientOcclusion = shadowAmbientOcclusion.x;
|
||||
materialData.normal = normalize( depthNormal.xyz );
|
||||
materialData.baseColor = sRGBtoLinear(diffuseRoughness.rgb);
|
||||
materialData.position = positionMaterialIndex.xyz;
|
||||
materialData.index = positionMaterialIndex.w;
|
||||
materialData.roughness = diffuseRoughness.w;
|
||||
materialData.alpha = 1.0;
|
||||
materialData.shadowOcclusion = shadowAmbientOcclusion.y; //calculateShadowOcclusion( materialData.position, v_uv );
|
||||
materialData.metallic = metallic;
|
||||
materialData.reflectance = reflectance;
|
||||
//materialData.tangent = tangent;
|
||||
|
||||
//materialData.shadowOcclusion = 1.0;
|
||||
//materialData.baseColor = vec3(1.0);
|
||||
|
||||
vec4 color = physically_based_shading( materialData );
|
||||
|
||||
float exposure = 1.7;
|
||||
|
||||
color.rgb *= exposure;
|
||||
|
||||
vec3 finalRender = color.rgb;// + diffuse * .2
|
||||
|
||||
|
||||
|
||||
// For fxaa
|
||||
float luma = sqrt( dot(color.rgb, vec3(0.299, 0.587, 0.114)) );
|
||||
|
||||
if(luma_z == 1.0)
|
||||
|
||||
//if(v_uv.x < 0.5)
|
||||
fragmentColor = vec4(linearToSRGB(tonemap(color.rgb)), luma);
|
||||
//else
|
||||
// fragmentColor = vec4(vec3(materialData.ambientOcclusion), 1.0);
|
||||
|
||||
//fragmentColor = vec4(linearToSRGB(tonemap(color.rgb)), 1.0);
|
||||
|
||||
if(materialData.index == 100.0) {
|
||||
|
||||
vec3 cubeReflectionSample = cubemapReflection( materialData );
|
||||
fragmentColor = vec4( cubeReflectionSample, 1.0 );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
142
shaders/old/depth.shader
Executable file
142
shaders/old/depth.shader
Executable file
@@ -0,0 +1,142 @@
|
||||
#version 300 es
|
||||
|
||||
in vec3 position;
|
||||
|
||||
out vec4 v_position;
|
||||
out float v_depth;
|
||||
|
||||
uniform mat4 view;
|
||||
uniform mat4 viewProjection;
|
||||
uniform mat4 world;
|
||||
|
||||
void main(void) {
|
||||
vec4 worldPosition = world * vec4(position.xyz, 1.0);
|
||||
|
||||
v_position = viewProjection * worldPosition;
|
||||
|
||||
v_depth = v_position.z;
|
||||
|
||||
gl_Position = viewProjection * vec4(position.xyz, 1.0);
|
||||
}
|
||||
|
||||
// #keplerEngine - Split
|
||||
|
||||
#version 300 es
|
||||
|
||||
precision highp float;
|
||||
|
||||
in vec4 v_position;
|
||||
in float v_depth;
|
||||
|
||||
out vec4 pixelColor;
|
||||
|
||||
uniform float far;
|
||||
uniform float near;
|
||||
uniform vec3 diffuseColor;
|
||||
|
||||
|
||||
|
||||
|
||||
vec4 pack (float depth)
|
||||
{
|
||||
const vec4 bias = vec4(1.0 / 255.0,
|
||||
1.0 / 255.0,
|
||||
1.0 / 255.0,
|
||||
0.0);
|
||||
|
||||
float r = depth;
|
||||
float g = fract(r * 255.0);
|
||||
float b = fract(g * 255.0);
|
||||
float a = fract(b * 255.0);
|
||||
vec4 color = vec4(r, g, b, a);
|
||||
|
||||
return color - (color.yzww * bias);
|
||||
}
|
||||
|
||||
|
||||
|
||||
vec4 EncodeFloatRGBA( float v ) {
|
||||
vec4 enc = vec4(1.0, 255.0, 65025.0, 160581375.0) * v;
|
||||
enc = fract(enc);
|
||||
enc -= enc.yzww * vec4(1.0/255.0,1.0/255.0,1.0/255.0,0.0);
|
||||
return enc;
|
||||
}
|
||||
|
||||
vec2 packHalf (float depth)
|
||||
{
|
||||
const vec2 bias = vec2(1.0 / 255.0,
|
||||
0.0);
|
||||
|
||||
vec2 colour = vec2(depth, fract(depth * 255.0));
|
||||
return colour - (colour.yy * bias);
|
||||
}
|
||||
|
||||
vec2 ComputeMoments(float depth) {
|
||||
vec2 moments;
|
||||
|
||||
moments.x = depth;
|
||||
|
||||
float dx = dFdx(depth);
|
||||
float dy = dFdy(depth);
|
||||
|
||||
moments.y = depth*depth + 0.25 * (dx*dx + dy*dy);
|
||||
|
||||
return moments;
|
||||
}
|
||||
|
||||
float normalizeDepth(float depth, float realFar) {
|
||||
return (depth) / (realFar);
|
||||
}
|
||||
|
||||
const float PackUpscale = 256. / 255.; // fraction -> 0..1 (including 1)
|
||||
const float UnpackDownscale = 255. / 256.; // 0..1 -> fraction (excluding 1)
|
||||
|
||||
const vec3 PackFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );
|
||||
const vec4 UnpackFactors = UnpackDownscale / vec4( PackFactors, 1. );
|
||||
|
||||
const float ShiftRight8 = 1. / 256.;
|
||||
|
||||
vec4 packDepthToRGBA( const in float v ) {
|
||||
vec4 r = vec4( fract( v * PackFactors ), v );
|
||||
r.yzw -= r.xyz * ShiftRight8; // tidy overflow
|
||||
return r * PackUpscale;
|
||||
}
|
||||
|
||||
float unpackRGBAToDepth( const in vec4 v ) {
|
||||
return dot( v, UnpackFactors );
|
||||
}
|
||||
|
||||
|
||||
vec4 DistributePrecision(vec2 Moments)
|
||||
{
|
||||
float g_DistributeFactor = 256.0;
|
||||
float FactorInv = 1.0 / g_DistributeFactor;
|
||||
// Split precision
|
||||
vec2 IntPart;
|
||||
vec2 FracPart = mod(Moments * g_DistributeFactor, IntPart);
|
||||
// Compose outputs to make reconstruction cheap.
|
||||
return vec4(IntPart * FactorInv, FracPart);
|
||||
}
|
||||
float DecodeFloatRGBA( vec4 rgba ) {
|
||||
return dot( rgba, vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 160581375.0) );
|
||||
}
|
||||
|
||||
|
||||
void main() {
|
||||
float depth = v_position.z ;
|
||||
|
||||
depth = depth;
|
||||
|
||||
float moment1 = depth;
|
||||
float moment2 = depth * depth;
|
||||
|
||||
float dx = dFdx(depth);
|
||||
float dy = dFdy(depth);
|
||||
|
||||
moment2 += 0.25 * (dx * dx + dy * dy);
|
||||
|
||||
pixelColor = vec4(depth, moment2, 0.0, 1.0);
|
||||
//pixelColor = vec4(diffuseColor, 1.0);
|
||||
gl_FragDepth = clamp(depth / far, 0.0, 1.0);
|
||||
|
||||
}
|
||||
137
shaders/old/fxaa.shader
Executable file
137
shaders/old/fxaa.shader
Executable file
@@ -0,0 +1,137 @@
|
||||
#version 300 es
|
||||
|
||||
in vec3 position;
|
||||
in vec2 uv;
|
||||
|
||||
|
||||
uniform vec2 res;
|
||||
uniform mat4 viewProjection;
|
||||
|
||||
out vec2 textureCoord;
|
||||
out vec2 v_rgbNW;
|
||||
out vec2 v_rgbNE;
|
||||
out vec2 v_rgbSW;
|
||||
out vec2 v_rgbSE;
|
||||
out vec2 v_rgbM;
|
||||
|
||||
void main(void) {
|
||||
textureCoord = uv;
|
||||
|
||||
mediump vec2 fragCoord = textureCoord * res;
|
||||
|
||||
vec2 inverseVP = 1.0 / res.xy;
|
||||
mediump vec2 v_rgbNW = (fragCoord + vec2(-1.0, -1.0)) * inverseVP;
|
||||
mediump vec2 v_rgbNE = (fragCoord + vec2(1.0, -1.0)) * inverseVP;
|
||||
mediump vec2 v_rgbSW = (fragCoord + vec2(-1.0, 1.0)) * inverseVP;
|
||||
mediump vec2 v_rgbSE = (fragCoord + vec2(1.0, 1.0)) * inverseVP;
|
||||
mediump vec2 v_rgbM = vec2(fragCoord * inverseVP);
|
||||
|
||||
gl_Position = viewProjection * vec4(position, 1.0);
|
||||
}
|
||||
|
||||
// #keplerEngine - Split
|
||||
|
||||
#version 300 es
|
||||
|
||||
precision highp float;
|
||||
|
||||
uniform sampler2D deferredSampler;
|
||||
|
||||
uniform vec2 res;
|
||||
uniform vec2 inverseScreenSize;
|
||||
|
||||
|
||||
in vec2 textureCoord;
|
||||
in vec2 v_rgbNW;
|
||||
in vec2 v_rgbNE;
|
||||
in vec2 v_rgbSW;
|
||||
in vec2 v_rgbSE;
|
||||
in vec2 v_rgbM;
|
||||
|
||||
|
||||
out vec4 fragmentColor;
|
||||
|
||||
#ifndef FXAA_REDUCE_MIN
|
||||
#define FXAA_REDUCE_MIN (1.0/ 128.0)
|
||||
#endif
|
||||
#ifndef FXAA_REDUCE_MUL
|
||||
#define FXAA_REDUCE_MUL (1.0 / 8.0)
|
||||
#endif
|
||||
#ifndef FXAA_SPAN_MAX
|
||||
#define FXAA_SPAN_MAX 8.0
|
||||
#endif
|
||||
|
||||
//optimized version for mobile, where dependent
|
||||
//texture reads can be a bottleneck
|
||||
vec4 fxaa(sampler2D tex, vec2 fragCoord, vec2 resolution,
|
||||
vec2 v_rgbNW, vec2 v_rgbNE,
|
||||
vec2 v_rgbSW, vec2 v_rgbSE,
|
||||
vec2 v_rgbM) {
|
||||
vec4 color;
|
||||
mediump vec2 inverseVP = vec2(1.0 / resolution.x, 1.0 / resolution.y);
|
||||
vec3 rgbNW = texture(tex, v_rgbNW).xyz;
|
||||
vec3 rgbNE = texture(tex, v_rgbNE).xyz;
|
||||
vec3 rgbSW = texture(tex, v_rgbSW).xyz;
|
||||
vec3 rgbSE = texture(tex, v_rgbSE).xyz;
|
||||
vec4 texColor = texture(tex, v_rgbM);
|
||||
vec3 rgbM = texColor.xyz;
|
||||
vec3 luma = vec3(0.299, 0.587, 0.114);
|
||||
float lumaNW = dot(rgbNW, luma);
|
||||
float lumaNE = dot(rgbNE, luma);
|
||||
float lumaSW = dot(rgbSW, luma);
|
||||
float lumaSE = dot(rgbSE, luma);
|
||||
float lumaM = dot(rgbM, luma);
|
||||
float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));
|
||||
float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));
|
||||
|
||||
mediump vec2 dir;
|
||||
dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));
|
||||
dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));
|
||||
|
||||
float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) *
|
||||
(0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN);
|
||||
|
||||
float rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);
|
||||
dir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX),
|
||||
max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),
|
||||
dir * rcpDirMin)) * inverseVP;
|
||||
|
||||
vec3 rgbA = 0.5 * (
|
||||
texture(tex, fragCoord * inverseVP + dir * (1.0 / 3.0 - 0.5)).xyz +
|
||||
texture(tex, fragCoord * inverseVP + dir * (2.0 / 3.0 - 0.5)).xyz);
|
||||
vec3 rgbB = rgbA * 0.5 + 0.25 * (
|
||||
texture(tex, fragCoord * inverseVP + dir * -0.5).xyz +
|
||||
texture(tex, fragCoord * inverseVP + dir * 0.5).xyz);
|
||||
|
||||
float lumaB = dot(rgbB, luma);
|
||||
if ((lumaB < lumaMin) || (lumaB > lumaMax))
|
||||
color = vec4(rgbA, texColor.a);
|
||||
else
|
||||
color = vec4(rgbB, texColor.a);
|
||||
return color;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//compute FXAA
|
||||
|
||||
//
|
||||
mediump vec2 fragCoord = textureCoord * res;
|
||||
|
||||
fragmentColor = fxaa(deferredSampler, fragCoord, res, v_rgbNW, v_rgbNE, v_rgbSW, v_rgbSE, v_rgbM);
|
||||
//fragmentColor = texture(deferredSampler, textureCoord);
|
||||
|
||||
fragmentColor.w = 1.0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
1173
shaders/old/fxaa4.shader
Executable file
1173
shaders/old/fxaa4.shader
Executable file
File diff suppressed because it is too large
Load Diff
387
shaders/old/physically_based_shading.shader
Executable file
387
shaders/old/physically_based_shading.shader
Executable file
@@ -0,0 +1,387 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
struct deferredMaterialData {
|
||||
vec3 normal;
|
||||
vec3 baseColor;
|
||||
vec3 diffuse;
|
||||
vec3 position;
|
||||
vec3 vertex;
|
||||
vec3 specularReflectance;
|
||||
|
||||
|
||||
float reflectance;
|
||||
float metallic;
|
||||
float roughness;
|
||||
float clearCoatRoughness;
|
||||
float geometricRoughness;
|
||||
float ambientOcclusion;
|
||||
float shadowOcclusion;
|
||||
float eta;
|
||||
float refracted_NoV;
|
||||
float index;
|
||||
|
||||
float alpha;
|
||||
};
|
||||
|
||||
|
||||
|
||||
float D_GGX(float NoH, float a) {
|
||||
float a2 = a * a;
|
||||
float f = (NoH * a2 - NoH) * NoH + 1.0;
|
||||
return a2 / (PI * f * f);
|
||||
}
|
||||
|
||||
float D_GGX_Anisotropy(float NoH, vec3 h, vec3 x, vec3 y, float ax, float ay) {
|
||||
float XoH = dot(x, h);
|
||||
float YoH = dot(y, h);
|
||||
float d = XoH * XoH * (ax * ax) + YoH * YoH * (ay * ay) + NoH * NoH;
|
||||
return (ax * ay) / (PI * d * d);
|
||||
}
|
||||
|
||||
vec3 F_Schlick(float VoH, vec3 specularReflectance, float f90) {
|
||||
return specularReflectance + (vec3(f90) - specularReflectance) * pow(1.0 - VoH, 5.0);
|
||||
}
|
||||
|
||||
float V_SmithGGXCorrelated(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);
|
||||
}
|
||||
|
||||
float Fd_Lambert() {
|
||||
return 1.0 / PI;
|
||||
}
|
||||
|
||||
float F_Schlick_Scalar(float VoH, float specularReflectance, float f90) {
|
||||
return specularReflectance + (f90 - specularReflectance) * pow(1.0 - VoH, 5.0);
|
||||
}
|
||||
|
||||
float square(float v) {
|
||||
return v * v;
|
||||
}
|
||||
|
||||
vec3 irradianceSH(vec3 n) {
|
||||
return
|
||||
vec3(0.754553530212464, 0.748541695286661, 0.790922541330174)
|
||||
+ vec3(-0.083855089181764, 0.092536341322488, 0.322767327275582) * (n.y)
|
||||
+ vec3(0.308154551673257, 0.366799355358085, 0.466705760819624) * (n.z)
|
||||
+ vec3(-0.188887618191928, -0.277403749518126, -0.377844811540716) * (n.x)
|
||||
|
||||
+ vec3(-0.252782448589491, -0.316051613736677, -0.396141020484574) * (n.y * n.x)
|
||||
+ vec3(0.071362454444021, 0.159789075773366, 0.29059362717571) * (n.y * n.z)
|
||||
+ vec3(-0.031040420617065, -0.031141089772695, -0.031044001883204) * (3.0 * n.z * n.z - 1.0)
|
||||
+ vec3(-0.161001896026477, -0.203649521035777, -0.246641086569566) * (n.z * n.x)
|
||||
+ vec3(0.045710934605387, 0.048121779682969, 0.046326375668417) * (n.x * n.x - n.y * n.y);
|
||||
}
|
||||
|
||||
vec2 prefilteredDFGKaris(float NoV, float roughness) {
|
||||
// see https://www.unrealengine.com/blog/physically-based-shading-on-mobile
|
||||
const vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022);
|
||||
const vec4 c1 = vec4( 1.0, 0.0425, 1.040, -0.040);
|
||||
vec4 r = roughness * c0 + c1;
|
||||
float a004 = min(r.x * r.x, exp2(-9.28 * NoV)) * r.x + r.y;
|
||||
return vec2(-1.04, 1.04) * a004 + r.zw;
|
||||
}
|
||||
|
||||
|
||||
float sRGBtoLinear(float c) {
|
||||
return (c <= 0.04045) ? c / 12.92 : pow((c + 0.055) / 1.055, 2.4);
|
||||
}
|
||||
|
||||
vec3 sRGBtoLinear(vec3 c) {
|
||||
return vec3(sRGBtoLinear(c.r), sRGBtoLinear(c.g), sRGBtoLinear(c.b));
|
||||
}
|
||||
|
||||
vec3 decodeEnvironmentMap(vec4 c) {
|
||||
return c.rgb;//;sRGBtoLinear(c.rgb) ;
|
||||
}
|
||||
|
||||
float getSquareFalloffAttenuation(float distanceSquare) {
|
||||
float factor = distanceSquare * lightGeometry.x;
|
||||
float smoothFactor = max(1.0 - factor * factor, 0.0);
|
||||
return smoothFactor * smoothFactor;
|
||||
}
|
||||
|
||||
|
||||
float getPhotometricAttenuation(vec3 lightToPos, vec3 lightDir) {
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
float getAngleAttenuation(vec3 l, vec3 lightDir) {
|
||||
float cd = dot(lightDir, l);
|
||||
float attenuation = clamp(cd * lightGeometry.y + lightGeometry.z, 0.0, 1.0);
|
||||
return attenuation * attenuation;
|
||||
}
|
||||
|
||||
vec3 beerLambert(float NoV, float NoL, vec3 alpha, float d) {
|
||||
return exp(alpha * -(d * ((NoL + NoV) / max(NoL * NoV, 1e-3))));
|
||||
}
|
||||
|
||||
vec3 fixCubemapLookup(vec3 v, float lod) {
|
||||
vec3 r = abs(v);
|
||||
float M = max(max(v.x, v.y), v.z);
|
||||
float scale = 1.0 - exp2(lod) * (1.0 / 256.0);
|
||||
if (v.x != M) v.x *= scale;
|
||||
if (v.y != M) v.y *= scale;
|
||||
if (v.z != M) v.z *= scale;
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
vec3 evaluateSpecularIBL(vec3 r, float roughness) {
|
||||
float lod = 5.0 * roughness;
|
||||
|
||||
r = fixCubemapLookup(r, lod);
|
||||
|
||||
return decodeEnvironmentMap( texture(reflectionSampler, r, lod) ); //, lod * 3.
|
||||
}
|
||||
|
||||
float computeSpecularambientOcclusion(float NoV, float ambientOcclusion, float roughness) {
|
||||
return clamp(pow(NoV + ambientOcclusion, exp2(-16.0 * roughness - 1.0)) - 1.0 + ambientOcclusion, 0.0, 1.0);
|
||||
}
|
||||
|
||||
vec3 getSpecularDominantDirection(vec3 n, vec3 r, float roughness) {
|
||||
float s = 1.0 - roughness;
|
||||
return mix(n, r, s * (sqrt(s) + roughness));
|
||||
}
|
||||
|
||||
|
||||
vec3 evaluateIBL( deferredMaterialData materialData ) { //, deferredLightData params
|
||||
|
||||
vec3 normal = materialData.normal;
|
||||
vec3 vertex = materialData.vertex;
|
||||
|
||||
|
||||
float roughness = materialData.roughness;
|
||||
|
||||
float NoV = max( dot(normal, vertex), 0.0 );
|
||||
|
||||
#if ANISOTROPY == 1
|
||||
vec3 t = normalize( materialData.tangent );
|
||||
vec3 b = normalize( cross(t, normal));
|
||||
|
||||
vec3 anisotropicTangent = cross(-vertex, b);
|
||||
vec3 anisotropicNormal = cross(anisotropicTangent, b);
|
||||
vec3 bentNormal = normalize(mix(normal, anisotropicNormal, anisotropy));
|
||||
|
||||
vec3 r = reflect( vertex, bentNormal );
|
||||
#else
|
||||
vec3 r = reflect( -vertex, normal );
|
||||
r = getSpecularDominantDirection(normal, r, roughness * roughness);
|
||||
#endif
|
||||
|
||||
float NoR = max( dot(r, normal), 0.0);
|
||||
|
||||
// specular indirect
|
||||
vec3 indirectSpecular = evaluateSpecularIBL( reflect(vertex, normal), roughness);
|
||||
|
||||
// horizon occlusion, can be removed for performance
|
||||
//float horizon = min(1.0 + NoR, 1.0);
|
||||
//indirectSpecular *= horizon * horizon;
|
||||
|
||||
vec2 env = prefilteredDFGKaris( NoV, materialData.roughness );
|
||||
// we should multiply env.y by f90 for more accurate results
|
||||
vec3 specularColor = materialData.specularReflectance * env.x + env.y * (1.0 - clearCoat) *
|
||||
clamp(dot(materialData.specularReflectance, vec3(50.0 * 0.33)), 0.0, 1.0);
|
||||
|
||||
// diffuse indirect
|
||||
vec3 indirectDiffuse = max(irradianceSH(normal), 0.0) * Fd_Lambert();
|
||||
// ambient occlusion
|
||||
float ambientOcclusionFade = clamp(dot(normalize(normal), vertex), 0.0, 1.0);
|
||||
float ambientOcclusion = mix(1.0, materialData.ambientOcclusion, ambientOcclusionFade);
|
||||
indirectDiffuse *= ambientOcclusion;
|
||||
//indirectDiffuse *= 4.0;
|
||||
// TODO: Not really useful without SSambientOcclusion/HBambientOcclusion/etc.
|
||||
indirectSpecular *= computeSpecularambientOcclusion(NoV, ambientOcclusion, materialData.roughness);
|
||||
|
||||
// clear coat
|
||||
float Fcc = F_Schlick_Scalar(NoV, 0.04, 1.0) * 0.2;
|
||||
#if ANISOTROPY == 1
|
||||
// We used the bent normal for the base layer
|
||||
r = reflect(-vertex, normal);
|
||||
#endif
|
||||
|
||||
|
||||
vec3 indirectClearCoatSpecular = evaluateSpecularIBL(reflect(vertex, normal), materialData.clearCoatRoughness);
|
||||
|
||||
|
||||
vec3 clearCoatAbsorption = mix(vec3(1.0),
|
||||
beerLambert(materialData.refracted_NoV, materialData.refracted_NoV, clearCoatColor, clearCoatThickness),
|
||||
clearCoat);
|
||||
|
||||
// indirect contribution
|
||||
vec3 color =
|
||||
(materialData.diffuse * indirectDiffuse + indirectSpecular * specularColor)//kaj materialData.diffuse * indirectDiffuse
|
||||
* (1.0 - Fcc) * clearCoatAbsorption +
|
||||
indirectClearCoatSpecular * Fcc;
|
||||
|
||||
#if TRANSLUCENT_MATERIAL == 1
|
||||
indirectDiffuse = max(irradianceSH(-vertex), 0.0) * Fd_Lambert();
|
||||
vec3 tL = -vertex + normal * translucencyDistortion;
|
||||
float tD = pow(clamp(dot(vertex, -tL), 0.0, 1.0), translucencyPower) * translucencyScale;
|
||||
vec3 tT = (tD + translucencyAmbient) * texture(translucencyThicknessMap, outUV).r;
|
||||
color.rgb += materialData.diffuse * indirectDiffuse * tT;
|
||||
#endif
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
|
||||
vec3 getNormal(vec3 n) {
|
||||
|
||||
return normalize(n);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
vec3 evaluateLight( deferredMaterialData params ) {
|
||||
|
||||
vec3 n = params.normal;
|
||||
vec3 v = params.vertex;
|
||||
|
||||
vec3 l;
|
||||
float NoL;
|
||||
float energy;
|
||||
float attenuation;
|
||||
|
||||
vec3 lightDir = normalize(lightDirection);
|
||||
float linearRoughness = params.roughness * params.roughness;
|
||||
|
||||
vec3 r = reflect(-v, n);
|
||||
|
||||
if (lightType == 1.0) {
|
||||
|
||||
l = -lightDir;
|
||||
|
||||
// Disc area light
|
||||
vec3 sunDir = -lightDir;
|
||||
float e = sin(radians(0.53));
|
||||
float d = cos(radians(0.53));
|
||||
float DoR = dot(sunDir, r);
|
||||
vec3 s = r - DoR * sunDir;
|
||||
l = DoR < d ? normalize(d * sunDir + normalize(s) * e) : r;
|
||||
|
||||
NoL = dot(n, l);
|
||||
energy = 1.0;
|
||||
attenuation = 1.0;
|
||||
|
||||
|
||||
} else if (lightType == 0.0) {
|
||||
|
||||
vec3 posToLight = lightPosition - params.position;
|
||||
float distanceSquare = dot(posToLight, posToLight);
|
||||
l = normalize(posToLight);
|
||||
NoL = dot(n, l);
|
||||
energy = 50.0;
|
||||
attenuation = getSquareFalloffAttenuation(distanceSquare);
|
||||
attenuation *= 1.0 / max(distanceSquare, 1e-4);
|
||||
attenuation *= getPhotometricAttenuation(-l, lightDir);
|
||||
// if (lightGeometry.w >= 1.0) {
|
||||
// attenuation *= getAngleAttenuation(l, -lightDir);
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
vec3 h = normalize(v + l);
|
||||
|
||||
NoL = clamp(NoL, 0.0, 1.0);
|
||||
float NoV = abs(dot(n, v)) + 1e-5;
|
||||
float NoH = clamp(dot(n, h), 0.0, 1.0);
|
||||
float LoH = clamp(dot(l, h), 0.0, 1.0);
|
||||
|
||||
// specular BRDF
|
||||
#if ANISOTROPY == 1
|
||||
vec3 t = normalize(v_tangent.xyz);
|
||||
vec3 b = normalize(cross(t, n));
|
||||
|
||||
float aspect = inversesqrt(1.0 - anisotropy * 0.9);
|
||||
float ax = 1.0 / (linearRoughness * aspect);
|
||||
float ay = aspect / linearRoughness;
|
||||
|
||||
float D = D_GGX_Anisotropy(NoH, h, t, b, ax, ay);
|
||||
#else
|
||||
float D = D_GGX(NoH, linearRoughness);
|
||||
#endif
|
||||
vec3 F = F_Schlick(LoH, params.specularReflectance, clamp(dot(params.specularReflectance, vec3(50.0 * 0.33)), 0.0, 1.0));
|
||||
float V = V_SmithGGXCorrelated(NoV, NoL, linearRoughness);
|
||||
vec3 Fr = (D * V) * F;
|
||||
|
||||
// diffuse BRDF
|
||||
vec3 Fd = params.diffuse * Fd_Lambert();// * 3.6
|
||||
|
||||
// clear coat
|
||||
float linearClearCoatRoughness = params.clearCoatRoughness * params.clearCoatRoughness;
|
||||
float Dcc = D_GGX(NoH, linearClearCoatRoughness);
|
||||
float Fcc = F_Schlick_Scalar(LoH, 0.04, 1.0) * clearCoat;
|
||||
float Vcc = V_SmithGGXCorrelated(NoV, NoL, linearClearCoatRoughness);
|
||||
float FrCC = Dcc * Vcc * Fcc;
|
||||
|
||||
vec3 refracted_l = -refract(l, n, params.eta);
|
||||
float refracted_NoL = clamp(dot(n, refracted_l), 0.0, 1.0);
|
||||
vec3 clearCoatAbsorption = mix(vec3(1.0),
|
||||
beerLambert(params.refracted_NoV, refracted_NoL, clearCoatColor, clearCoatThickness),
|
||||
clearCoat);
|
||||
|
||||
// direct contribution
|
||||
vec3 color = (attenuation * NoL) * lightColor * lightIntensity * energy *
|
||||
((Fd + Fr) * (1.0 - Fcc) * clearCoatAbsorption + FrCC);
|
||||
|
||||
#if TRANSLUCENT_MATERIAL == 1
|
||||
vec3 tL = l + n * translucencyDistortion;
|
||||
float tD = exp2(clamp(dot(v, -tL), 0.0, 1.0) * translucencyPower - translucencyPower) * translucencyScale;
|
||||
vec3 tT = attenuation * lightIntensity * (tD + translucencyAmbient) * texture(translucencyThicknessMap, outUV).r;
|
||||
color.rgb += Fd * lightColor * tT;
|
||||
#endif
|
||||
|
||||
// micro-shadowing
|
||||
float aperture = 2.0 * params.ambientOcclusion * params.ambientOcclusion * params.shadowOcclusion;
|
||||
float microShadow = clamp(abs(dot(l, n)) + aperture - 1.0, 0.0, 1.0);
|
||||
color.rgb *= microShadow;
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
|
||||
vec4 physically_based_shading( deferredMaterialData materialData ) {
|
||||
|
||||
//deferredLightData lightData;
|
||||
materialData.diffuse = (1.0 - metallic) * materialData.baseColor;
|
||||
|
||||
// Geometric AA
|
||||
vec3 ndFdx = dFdx( materialData.normal );
|
||||
vec3 ndFdy = dFdy( materialData.normal );
|
||||
|
||||
materialData.geometricRoughness = pow( max( dot(ndFdx, ndFdx), dot(ndFdy, ndFdy) ), 0.333);
|
||||
materialData.roughness = max(materialData.roughness, materialData.geometricRoughness);
|
||||
|
||||
materialData.specularReflectance = 0.16 *
|
||||
materialData.reflectance * materialData.reflectance * (1.0 - metallic) +
|
||||
materialData.baseColor * materialData.metallic;
|
||||
|
||||
|
||||
materialData.clearCoatRoughness = max( mix(0.089, 0.6, clearCoatRoughness), materialData.geometricRoughness);
|
||||
materialData.eta = 1.0 / clearCoatIOR;
|
||||
|
||||
materialData.vertex = normalize( cameraPosition - materialData.position ); // v
|
||||
|
||||
vec3 refracted_vertex = -refract(materialData.vertex, materialData.normal, materialData.eta);
|
||||
|
||||
materialData.refracted_NoV = clamp(dot(materialData.normal, refracted_vertex), 0.0, 1.0);
|
||||
|
||||
|
||||
float alpha = 1.0;
|
||||
|
||||
// indirect lighting
|
||||
vec3 color = evaluateIBL( materialData );
|
||||
|
||||
color *= environmentLuminance;
|
||||
|
||||
|
||||
color += evaluateLight(materialData);
|
||||
return vec4(color, alpha);
|
||||
}
|
||||
234
shaders/old/shadow.shader
Executable file
234
shaders/old/shadow.shader
Executable file
@@ -0,0 +1,234 @@
|
||||
|
||||
|
||||
/**
|
||||
* Author: Kaj Dijksta
|
||||
*/
|
||||
|
||||
attribute vec3 position;
|
||||
attribute vec2 uv;
|
||||
|
||||
uniform mat4 viewProjection;
|
||||
|
||||
varying vec2 v_textureCoord;
|
||||
|
||||
void main(void) {
|
||||
|
||||
v_textureCoord = uv;
|
||||
gl_Position = viewProjection * vec4(position, 1.0);
|
||||
|
||||
}
|
||||
|
||||
// #keplerEngine - Split
|
||||
|
||||
|
||||
precision highp float;
|
||||
|
||||
uniform sampler2D positionSampler;
|
||||
uniform sampler2D shadowDepthSampler;
|
||||
uniform sampler2D shadowNoiseSampler;
|
||||
uniform sampler2D ambientOcclusionSampler;
|
||||
|
||||
uniform float bias;
|
||||
uniform float minVariance;
|
||||
|
||||
uniform vec3 lightPosition;
|
||||
uniform mat4 lightViewProjection;
|
||||
|
||||
varying vec2 v_textureCoord;
|
||||
float DecodeFloatRGBA( vec4 rgba ) {
|
||||
return (rgba).x;
|
||||
|
||||
//return dot( rgba, vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 160581375.0) );
|
||||
}
|
||||
|
||||
float poissonPCFmultitap(vec4 projCoords, float shadowDepth, vec2 uv)
|
||||
{
|
||||
const mediump float step = 1.0 - 1.0 / 8.0;
|
||||
const mediump float fScale = 0.025; // 0.025
|
||||
|
||||
mediump float n = 0.0;
|
||||
|
||||
mediump vec3 directions[8];
|
||||
float vSampleScale = 1.0 / 2048.0;
|
||||
|
||||
|
||||
directions[0] = normalize(vec3( 1.0, 1.0, 1.0))*fScale*(n+=step);
|
||||
directions[1] = normalize(vec3(-1.0,-1.0,-1.0))*fScale*(n+=step);
|
||||
directions[2] = normalize(vec3(-1.0,-1.0, 1.0))*fScale*(n+=step);
|
||||
directions[3] = normalize(vec3(-1.0, 1.0,-1.0))*fScale*(n+=step);
|
||||
directions[4] = normalize(vec3(-1.0, 1.0 ,1.0))*fScale*(n+=step);
|
||||
directions[5] = normalize(vec3( 1.0,-1.0,-1.0))*fScale*(n+=step);
|
||||
directions[6] = normalize(vec3( 1.0,-1.0, 1.0))*fScale*(n+=step);
|
||||
directions[7] = normalize(vec3( 1.0, 1.0,-1.0))*fScale*(n+=step);
|
||||
|
||||
mediump vec3 randomSample = texture2D(shadowNoiseSampler, vec2(64.0, 64.0) * uv.xy / 4.0).xyz * 2.0 - 1.0;
|
||||
|
||||
|
||||
|
||||
float sum = 0.0;
|
||||
|
||||
// for( int i = 0; i < 4; i++ ) {
|
||||
// vec3 sampler = reflect(directions[0], randomSample) * vSampleScale;
|
||||
|
||||
float pixelDepth = DecodeFloatRGBA( texture2D(shadowDepthSampler, projCoords.xy ) ) ; // + sampler.xy + sampler.z
|
||||
|
||||
if( pixelDepth + bias > shadowDepth) {
|
||||
sum += 1.0;
|
||||
} else {
|
||||
sum += 0.5;
|
||||
}
|
||||
// }
|
||||
|
||||
return sum;
|
||||
}
|
||||
float shadow_sample(sampler2D depthMap, vec2 coord)
|
||||
{
|
||||
return ( texture2D(depthMap, coord.xy).x );
|
||||
}
|
||||
|
||||
vec2 DoubleSampleRotated(sampler2D depthMap, vec4 p, vec4 rotMatr, vec4 kernel) {
|
||||
|
||||
vec4 rotatedOff;
|
||||
|
||||
rotatedOff = rotMatr.xyzw * kernel.xxww +
|
||||
rotMatr.zwxy * kernel.yyzz;
|
||||
|
||||
vec4 fetchPos = p.xyxy + rotatedOff;// + rotatedOff
|
||||
|
||||
vec2 result;
|
||||
|
||||
result.x = shadow_sample(depthMap, fetchPos.xy);
|
||||
result.y = shadow_sample(depthMap, fetchPos.zw);
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
float PCF(sampler2D depthMap, vec4 p, vec2 randDirTC, float depth)
|
||||
{
|
||||
|
||||
vec2 kernelRadius = vec2(4.0);
|
||||
|
||||
vec4 irreg_kernel_2d[8];
|
||||
irreg_kernel_2d[0] = vec4(-0.556641,-0.037109,-0.654297, 0.111328);
|
||||
irreg_kernel_2d[1] = vec4(0.173828,0.111328,0.064453, -0.359375);
|
||||
irreg_kernel_2d[2] = vec4(0.001953,0.082031,-0.060547, 0.078125);
|
||||
irreg_kernel_2d[3] = vec4(0.220703,-0.359375,-0.062500, 0.001953);
|
||||
irreg_kernel_2d[4] = vec4(0.242188,0.126953,-0.250000, -0.140625);
|
||||
irreg_kernel_2d[5] = vec4(0.070313,-0.025391,0.148438, 0.082031);
|
||||
irreg_kernel_2d[6] = vec4(-0.078125,0.013672,-0.314453, 0.013672);
|
||||
irreg_kernel_2d[7] = vec4(0.117188,-0.140625,-0.199219, 0.117188);
|
||||
|
||||
vec2 vInvShadowMapWH = vec2(1.0 / 2048.0);
|
||||
|
||||
const int kernelSize = 8;
|
||||
|
||||
mediump float P_Z = depth; // p.z;
|
||||
|
||||
vec4 p0 = vec4(p.xyz, 1.0);
|
||||
|
||||
|
||||
mediump vec2 rotScale = vec2(kernelRadius.y * 2.0);
|
||||
|
||||
float shadowTest = 0.0;
|
||||
|
||||
#define KERNEL_STEP_SIZE 2
|
||||
|
||||
vec2 rotSample = 2.0 * texture2D(shadowDepthSampler, randDirTC.xy).xy - 1.0;
|
||||
rotSample.xy = normalize(rotSample.xy);
|
||||
rotSample.xy *= (kernelRadius.xy * vInvShadowMapWH.xy);
|
||||
|
||||
vec4 rot = vec4(rotSample.x, -rotSample.y, rotSample.y, rotSample.x);
|
||||
|
||||
const int kernelOffset = 0;
|
||||
|
||||
for(int i=kernelOffset; i<kernelSize; i+=KERNEL_STEP_SIZE) // Loop over taps
|
||||
{
|
||||
|
||||
mediump vec4 sampleDepth = vec4(0.0);
|
||||
vec4 irr = irreg_kernel_2d[i+0];
|
||||
sampleDepth.xy = DoubleSampleRotated(depthMap, p0, rot, irr);
|
||||
sampleDepth.zw = DoubleSampleRotated(depthMap, p0, rot, irreg_kernel_2d[i+1]);
|
||||
|
||||
mediump vec4 InShadow;
|
||||
InShadow.x = ( P_Z < sampleDepth.x + bias ) ? 1. : 0.0;
|
||||
InShadow.y = ( P_Z < sampleDepth.y + bias ) ? 1. : 0.0;
|
||||
InShadow.z = ( P_Z < sampleDepth.z + bias ) ? 1. : 0.0;
|
||||
InShadow.w = ( P_Z < sampleDepth.w + bias ) ? 1. : 0.0;
|
||||
|
||||
|
||||
const mediump float quality = 8.0; // 8 == high
|
||||
const mediump float fInvSamplNum = (1.0 / quality);
|
||||
|
||||
shadowTest += dot(InShadow, vec4(fInvSamplNum));
|
||||
}
|
||||
|
||||
return shadowTest;
|
||||
}
|
||||
float linestep(float min, float max, float value) {
|
||||
return clamp((value - min) / (max - min), 0., 1.);
|
||||
}
|
||||
|
||||
float reduceBleeding(float p_max, float amount) {
|
||||
return linestep(amount, 1.0, p_max);
|
||||
}
|
||||
|
||||
float ChebyshevUpperBound(vec2 moments, float distance) {
|
||||
if (distance <= moments.x)
|
||||
return 1.0;
|
||||
|
||||
|
||||
float variance = moments.y - (moments.x*moments.x);
|
||||
variance = max(variance, minVariance);
|
||||
|
||||
float d = distance - moments.x;
|
||||
float p_max = variance / (variance + d*d);
|
||||
|
||||
return reduceBleeding(p_max, bias);
|
||||
}
|
||||
|
||||
float calculateShadowOcclusion( vec3 worldPosition, vec2 uv ) {
|
||||
|
||||
vec4 projCoords = lightViewProjection * vec4(worldPosition, 1.0) ;
|
||||
|
||||
float shadowDepth = length( lightPosition - worldPosition ) ;
|
||||
|
||||
projCoords.xy /= projCoords.w;
|
||||
projCoords = 0.5 * projCoords + 0.5;
|
||||
|
||||
vec4 moments = texture2D( shadowDepthSampler, projCoords.xy );
|
||||
mediump vec2 randomSample = texture2D(shadowNoiseSampler, vec2(1024.) * uv / 64.0).xy * 2.0 - 1.0;
|
||||
|
||||
float outFrustum = 0.0;
|
||||
|
||||
if(projCoords.x < 0.0 || projCoords.x > 1.0) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
if(projCoords.y < 0.0 || projCoords.y > 1.0) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
//if(projCoords.z < 1.0) {
|
||||
// return 0.0;
|
||||
//}
|
||||
|
||||
//return ChebyshevUpperBound(moments.xy, shadowDepth);
|
||||
//return poissonPCFmultitap(projCoords, shadowDepth, uv);
|
||||
return PCF( shadowDepthSampler, projCoords, randomSample, shadowDepth );
|
||||
}
|
||||
|
||||
|
||||
void main() {
|
||||
|
||||
vec3 position = texture2D( positionSampler, v_textureCoord ).xyz;
|
||||
|
||||
float shadow = calculateShadowOcclusion( position, v_textureCoord );
|
||||
float ambientOcclusion = texture2D( ambientOcclusionSampler, v_textureCoord ).x;
|
||||
|
||||
|
||||
gl_FragColor = vec4(ambientOcclusion, shadow, 0.0, 1.0);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
70
shaders/old/tonemap.shader
Executable file
70
shaders/old/tonemap.shader
Executable file
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* Kepler - Core
|
||||
* Copyright (c) 2010 kaj dijkstra STUDIOS
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Author: Kaj Dijksta
|
||||
*/
|
||||
|
||||
attribute vec3 position;
|
||||
attribute vec2 uv;
|
||||
|
||||
uniform mat4 viewProjection;
|
||||
|
||||
varying vec2 v_textureCoord;
|
||||
|
||||
void main(void) {
|
||||
|
||||
v_textureCoord = uv;
|
||||
gl_Position = viewProjection * vec4(position, 1.0);
|
||||
|
||||
}
|
||||
|
||||
// #keplerEngine - Split
|
||||
|
||||
precision highp float;
|
||||
|
||||
uniform sampler2D colorSampler;
|
||||
uniform float exposure;
|
||||
|
||||
varying vec2 v_textureCoord;
|
||||
|
||||
vec3 HDR_ACES(const vec3 x) {
|
||||
// Narkowicz 2015, "ACES Filmic Tone Mapping Curve"
|
||||
const float a = 2.51;
|
||||
const float b = 0.03;
|
||||
const float c = 2.43;
|
||||
const float d = 0.59;
|
||||
const float e = 0.14;
|
||||
return (x * (a * x + b)) / (x * (c * x + d) + e);
|
||||
}
|
||||
|
||||
vec3 tonemap(const vec3 x) {
|
||||
return HDR_ACES(x);
|
||||
}
|
||||
|
||||
float linearToSRGB(float c) {
|
||||
return (c <= 0.0031308) ? c * 12.92 : (pow(abs(c), 1.0 / 2.4) * 1.055) - 0.055;
|
||||
}
|
||||
|
||||
vec3 linearToSRGB(vec3 c) {
|
||||
return vec3(linearToSRGB(c.r), linearToSRGB(c.g), linearToSRGB(c.b));
|
||||
}
|
||||
|
||||
void main() {
|
||||
|
||||
vec3 pbr = texture2D( colorSampler, v_textureCoord ).rgb;
|
||||
gl_FragColor = vec4( pbr , 1.0 );
|
||||
//pbr.rgb *= exposure;
|
||||
|
||||
//if(v_textureCoord.x < 0.5) {
|
||||
// gl_FragColor = vec4( linearToSRGB( tonemap(pbr) ), 1.0 );
|
||||
//} else {
|
||||
// gl_FragColor = vec4(
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user