-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Included Experimental Shading system
- Loading branch information
Showing
9 changed files
with
308 additions
and
24 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#if (GLSL_VERSION >= 150) | ||
#define DeclareFragOutput(locationNumber, type) out type outputLocation##locationNumber | ||
#define SetFragOutput(locationNumber, val) outputLocation##locationNumber = val | ||
|
||
#define texture2D(tex, coord) texture(tex, coord) | ||
|
||
#if defined(VS_BUILD) | ||
#define varying out | ||
#elif defined(FS_BUILD) | ||
#define varying in | ||
#endif | ||
#else | ||
#define DeclareFragOutput(locationNumber) | ||
#define SetFragOutput(locationNumber, val) gl_FragData[locationNumber] = val | ||
#endif | ||
|
||
#if (GLSL_VERSION >= 400) | ||
#define mad(a, b, c) fma(a, b, c) | ||
#else | ||
#define mad(a, b, c) (a * b + c) | ||
#endif | ||
|
||
#define float2 vec2 | ||
#define float3 vec3 | ||
#define float4 vec4 | ||
#define int2 ivec2 | ||
#define int3 ivec3 | ||
#define int4 ivec4 | ||
#define bool2 bvec2 | ||
#define bool3 bvec3 | ||
#define bool4 bvec4 | ||
|
||
#define lerp(a, b, t) mix(a, b, t) | ||
#define saturate(a) clamp(a, 0.0, 1.0) |
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,76 @@ | ||
#include "common.glh" | ||
// FXAA shader, GLSL code adapted from: | ||
// http://horde3d.org/wiki/index.php5?title=Shading_Technique_-_FXAA | ||
// Whitepaper describing the technique: | ||
// http://developer.download.nvidia.com/assets/gamedev/files/sdk/11/FXAA_WhitePaper.pdf | ||
|
||
varying vec2 texCoord0; | ||
|
||
#if defined(VS_BUILD) | ||
attribute vec3 position; | ||
attribute vec2 texCoord; | ||
|
||
uniform mat4 T_MVP; | ||
|
||
void main() | ||
{ | ||
texCoord0 = texCoord; | ||
gl_Position = T_MVP * vec4(position, 1.0); | ||
} | ||
|
||
#elif defined(FS_BUILD) | ||
uniform sampler2D R_filterTexture; | ||
uniform vec3 R_inverseFilterTextureSize; | ||
uniform float R_fxaaSpanMax; | ||
uniform float R_fxaaReduceMin; | ||
uniform float R_fxaaReduceMul; | ||
|
||
DeclareFragOutput(0, vec4); | ||
void main() | ||
{ | ||
vec2 texCoordOffset = R_inverseFilterTextureSize.xy; | ||
|
||
vec3 luma = vec3(0.299, 0.587, 0.114); | ||
float lumaTL = dot(luma, texture2D(R_filterTexture, texCoord0.xy + (vec2(-1.0, -1.0) * texCoordOffset)).xyz); | ||
float lumaTR = dot(luma, texture2D(R_filterTexture, texCoord0.xy + (vec2(1.0, -1.0) * texCoordOffset)).xyz); | ||
float lumaBL = dot(luma, texture2D(R_filterTexture, texCoord0.xy + (vec2(-1.0, 1.0) * texCoordOffset)).xyz); | ||
float lumaBR = dot(luma, texture2D(R_filterTexture, texCoord0.xy + (vec2(1.0, 1.0) * texCoordOffset)).xyz); | ||
float lumaM = dot(luma, texture2D(R_filterTexture, texCoord0.xy).xyz); | ||
|
||
vec2 dir; | ||
dir.x = -((lumaTL + lumaTR) - (lumaBL + lumaBR)); | ||
dir.y = ((lumaTL + lumaBL) - (lumaTR + lumaBR)); | ||
|
||
float dirReduce = max((lumaTL + lumaTR + lumaBL + lumaBR) * (R_fxaaReduceMul * 0.25), R_fxaaReduceMin); | ||
float inverseDirAdjustment = 1.0/(min(abs(dir.x), abs(dir.y)) + dirReduce); | ||
|
||
dir = min(vec2(R_fxaaSpanMax, R_fxaaSpanMax), | ||
max(vec2(-R_fxaaSpanMax, -R_fxaaSpanMax), dir * inverseDirAdjustment)); | ||
|
||
dir.x = dir.x * step(1.0, abs(dir.x)); | ||
dir.y = dir.y * step(1.0, abs(dir.y)); | ||
|
||
//float dirStep = max(step(1.0, abs(dir.x)), step(1.0, abs(dir.y))); | ||
//dir.x = dir.x * dirStep; | ||
//dir.y = dir.y * dirStep; | ||
|
||
dir = dir * texCoordOffset; | ||
|
||
vec3 result1 = (1.0/2.0) * ( | ||
texture2D(R_filterTexture, texCoord0.xy + (dir * vec2(1.0/3.0 - 0.5))).xyz + | ||
texture2D(R_filterTexture, texCoord0.xy + (dir * vec2(2.0/3.0 - 0.5))).xyz); | ||
|
||
vec3 result2 = result1 * (1.0/2.0) + (1.0/4.0) * ( | ||
texture2D(R_filterTexture, texCoord0.xy + (dir * vec2(0.0/3.0 - 0.5))).xyz + | ||
texture2D(R_filterTexture, texCoord0.xy + (dir * vec2(3.0/3.0 - 0.5))).xyz); | ||
|
||
float lumaMin = min(lumaM, min(min(lumaTL, lumaTR), min(lumaBL, lumaBR))); | ||
float lumaMax = max(lumaM, max(max(lumaTL, lumaTR), max(lumaBL, lumaBR))); | ||
float lumaResult2 = dot(luma, result2); | ||
|
||
if(lumaResult2 < lumaMin || lumaResult2 > lumaMax) | ||
SetFragOutput(0, vec4(result1, 1.0)); | ||
else | ||
SetFragOutput(0, vec4(result2, 1.0)); | ||
} | ||
#endif |
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,36 @@ | ||
#include "common.glh" | ||
|
||
varying vec2 texCoord0; | ||
|
||
#if defined(VS_BUILD) | ||
attribute vec3 position; | ||
attribute vec2 texCoord; | ||
|
||
uniform mat4 T_MVP; | ||
|
||
void main() | ||
{ | ||
gl_Position = T_MVP * vec4(position, 1.0); | ||
texCoord0 = texCoord; | ||
} | ||
|
||
#elif defined(FS_BUILD) | ||
uniform vec3 R_blurScale; | ||
uniform sampler2D R_filterTexture; | ||
|
||
DeclareFragOutput(0, vec4); | ||
void main() | ||
{ | ||
vec4 color = vec4(0.0); | ||
|
||
color += texture2D(R_filterTexture, texCoord0 + (vec2(-3.0) * R_blurScale.xy)) * (1.0/64.0); | ||
color += texture2D(R_filterTexture, texCoord0 + (vec2(-2.0) * R_blurScale.xy)) * (6.0/64.0); | ||
color += texture2D(R_filterTexture, texCoord0 + (vec2(-1.0) * R_blurScale.xy)) * (15.0/64.0); | ||
color += texture2D(R_filterTexture, texCoord0 + (vec2(0.0) * R_blurScale.xy)) * (20.0/64.0); | ||
color += texture2D(R_filterTexture, texCoord0 + (vec2(1.0) * R_blurScale.xy)) * (15.0/64.0); | ||
color += texture2D(R_filterTexture, texCoord0 + (vec2(2.0) * R_blurScale.xy)) * (6.0/64.0); | ||
color += texture2D(R_filterTexture, texCoord0 + (vec2(3.0) * R_blurScale.xy)) * (1.0/64.0); | ||
|
||
SetFragOutput(0, color); | ||
} | ||
#endif |
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,24 @@ | ||
#include "common.glh" | ||
|
||
varying vec2 texCoord0; | ||
|
||
#if defined(VS_BUILD) | ||
attribute vec3 position; | ||
attribute vec2 texCoord; | ||
|
||
uniform mat4 T_MVP; | ||
|
||
void main() | ||
{ | ||
gl_Position = T_MVP * vec4(position, 1.0); | ||
texCoord0 = texCoord; | ||
} | ||
#elif defined(FS_BUILD) | ||
uniform sampler2D R_filterTexture; | ||
|
||
DeclareFragOutput(0, vec4); | ||
void main() | ||
{ | ||
SetFragOutput(0, texture2D(R_filterTexture, texCoord0)); | ||
} | ||
#endif |
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,47 @@ | ||
#include "common.glh" | ||
|
||
varying vec2 texCoord0; | ||
varying vec3 worldPos0; | ||
varying mat3 tbnMatrix; | ||
|
||
#if defined(VS_BUILD) | ||
attribute vec3 position; | ||
attribute vec2 texCoord; | ||
attribute vec3 normal; | ||
attribute vec3 tangent; | ||
|
||
uniform mat4 T_model; | ||
uniform mat4 T_MVP; | ||
|
||
void main() | ||
{ | ||
gl_Position = T_MVP * vec4(position, 1.0); | ||
texCoord0 = texCoord; | ||
worldPos0 = (T_model * vec4(position, 1.0)).xyz; | ||
|
||
vec3 n = normalize((T_model * vec4(normal, 0.0)).xyz); | ||
vec3 t = normalize((T_model * vec4(tangent, 0.0)).xyz); | ||
t = normalize(t - dot(t, n) * n); | ||
|
||
vec3 biTangent = cross(t, n); | ||
tbnMatrix = mat3(t, biTangent, n); | ||
} | ||
#elif defined(FS_BUILD) | ||
#include "sampling.glh" | ||
|
||
uniform vec3 R_ambient; | ||
uniform vec3 C_eyePos; | ||
uniform sampler2D diffuse; | ||
uniform sampler2D dispMap; | ||
|
||
uniform float dispMapScale; | ||
uniform float dispMapBias; | ||
|
||
DeclareFragOutput(0, vec4); | ||
void main() | ||
{ | ||
vec3 directionToEye = normalize(C_eyePos - worldPos0); | ||
vec2 texCoords = CalcParallaxTexCoords(dispMap, tbnMatrix, directionToEye, texCoord0, dispMapScale, dispMapBias); | ||
SetFragOutput(0, texture2D(diffuse, texCoords) * vec4(R_ambient, 1)); | ||
} | ||
#endif |
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,24 @@ | ||
#include "common.glh" | ||
|
||
#if defined(VS_BUILD) | ||
attribute vec3 position; | ||
|
||
uniform mat4 T_MVP; | ||
|
||
void main() | ||
{ | ||
gl_Position = T_MVP * vec4(position, 1.0); | ||
} | ||
#elif defined(FS_BUILD) | ||
DeclareFragOutput(0, vec4); | ||
void main() | ||
{ | ||
float depth = gl_FragCoord.z; | ||
|
||
float dx = dFdx(depth); | ||
float dy = dFdy(depth); | ||
float moment2 = depth * depth + 0.25 * (dx * dx + dy * dy); | ||
|
||
SetFragOutput(0, vec4(depth, moment2, 0.0, 0.0)); | ||
} | ||
#endif |
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
Oops, something went wrong.
0ddfb86
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dear Benny, After using this new system, I get this error (error C0107: Too many arguments to macro DeclareFragOutput) when trying to load the shadowMapShader. I am using Java/LWJGL with an Nvidea GTX640 graphics card. Thanks.