shader cleanup initial
This commit is contained in:
@@ -29,7 +29,7 @@ uniform float earthRadius;
|
||||
*/
|
||||
void main()
|
||||
{
|
||||
vPos = vec4(vPosition.x, vPosition.y, vPosition.z, vPosition.w); // This is so it can be passed to the fragment shader
|
||||
vPos = vPosition.x; // This is so it can be passed to the fragment shader
|
||||
|
||||
vertexWorldPos = vPosition.xyz + modelOffset;
|
||||
|
||||
@@ -52,36 +52,35 @@ void main()
|
||||
vertexWorldPos.y += my;
|
||||
vertexWorldPos.z += mz;
|
||||
|
||||
// Old (disabled) vertex transformation logic - Leetom
|
||||
#if 0
|
||||
// Old (disabled) vertex transformation logic - Leetom
|
||||
|
||||
// Calculate the vertex pos due to curvature of the earth
|
||||
// We use spherical coordinates to calculate the vertex position
|
||||
if(vertexWorldPos.x == 0.0 && vertexWorldPos.z == 0.0)
|
||||
{
|
||||
// In the center. No curvature needed
|
||||
}
|
||||
else
|
||||
{
|
||||
float theta = atan(vertexWorldPos.z, vertexWorldPos.x); // in radians (-pi, pi)
|
||||
float trueY = earthRadius + vertexWorldPos.y; // true Y position, or height
|
||||
float phi = sqrt(vertexWorldPos.z * vertexWorldPos.z + vertexWorldPos.x * vertexWorldPos.x) / trueY;
|
||||
// Convert spherical coordinates to cartesian coordinates
|
||||
vertexWorldPos.x = trueY * sin(phi) * cos(theta);
|
||||
vertexWorldPos.z = trueY * sin(phi) * sin(theta);
|
||||
vertexWorldPos.y = trueY * cos(phi) - earthRadius;
|
||||
}
|
||||
// Calculate the vertex pos due to curvature of the earth
|
||||
// We use spherical coordinates to calculate the vertex position
|
||||
//if (vertexWorldPos.x == 0.0 && vertexWorldPos.z == 0.0)
|
||||
//{
|
||||
// // In the center. No curvature needed
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
float theta = atan(vertexWorldPos.z, vertexWorldPos.x); // in radians (-pi, pi)
|
||||
float trueY = earthRadius + vertexWorldPos.y; // true Y position, or height
|
||||
float phi = sqrt(vertexWorldPos.z * vertexWorldPos.z + vertexWorldPos.x * vertexWorldPos.x) / trueY;
|
||||
// Convert spherical coordinates to cartesian coordinates
|
||||
vertexWorldPos.x = trueY * sin(phi) * cos(theta);
|
||||
vertexWorldPos.z = trueY * sin(phi) * sin(theta);
|
||||
vertexWorldPos.y = trueY * cos(phi) - earthRadius;
|
||||
//}
|
||||
|
||||
#else
|
||||
// new vertex transformation logic - stduhpf
|
||||
// new vertex transformation logic - stduhpf
|
||||
|
||||
float localRadius = earthRadius + vertexYPos;// vertexWorldPos.y + cameraPosition.y - Center_Y;
|
||||
float localRadius = earthRadius + vertexYPos;// vertexWorldPos.y + cameraPosition.y - Center_Y;
|
||||
|
||||
float phi = length(vertexWorldPos.xz) / localRadius;
|
||||
|
||||
vertexWorldPos.y += (cos(phi) - 1.) * localRadius;
|
||||
vertexWorldPos.xz = vertexWorldPos.xz * sin(phi) / phi;
|
||||
float phi = length(vertexWorldPos.xz) / localRadius;
|
||||
|
||||
vertexWorldPos.y += (cos(phi) - 1.0) * localRadius;
|
||||
vertexWorldPos.xz = vertexWorldPos.xz * sin(phi) / phi;
|
||||
#endif
|
||||
|
||||
uint lights = meta & 0xFFu;
|
||||
|
||||
@@ -18,8 +18,9 @@ uniform int noiseDropoff;
|
||||
// method definitions
|
||||
|
||||
float fade(float value, float start, float end) {
|
||||
return (clamp(value,start,end)-start)/(end-start);
|
||||
return (clamp(value, start, end) - start) / (end - start);
|
||||
}
|
||||
|
||||
// The random functions for diffrent dimentions
|
||||
float rand(float co) { return fract(sin(co*(91.3458)) * 47453.5453); }
|
||||
float rand(vec2 co){ return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); }
|
||||
@@ -50,6 +51,7 @@ vec3 RGB2HSV(vec3 c) {
|
||||
float e = 1.0e-10;
|
||||
return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
|
||||
}
|
||||
|
||||
vec3 HSV2RGB(vec3 c) {
|
||||
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
|
||||
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
|
||||
@@ -74,15 +76,10 @@ void main()
|
||||
if (noiseEnabled) {
|
||||
vec3 vertexNormal = normalize(cross(dFdx(vPos.xyz), dFdy(vPos.xyz)));
|
||||
// This bit of code is required to fix the vertex position problem cus of floats in the verted world position varuable
|
||||
vec3 fixedVPos = vec3(
|
||||
vPos.x - vertexNormal.x * 0.001,
|
||||
vPos.y - vertexNormal.y * 0.001,
|
||||
vPos.z - vertexNormal.z * 0.001
|
||||
);
|
||||
vec3 fixedVPos = vPos.xyz - vertexNormal * 0.001;
|
||||
|
||||
|
||||
float noiseAmplification = noiseIntensity / 100;
|
||||
noiseAmplification = (-1 * pow(2*((fragColor.x + fragColor.y + fragColor.z) / 3) - 1, 2) + 1) * noiseAmplification; // Lessen the effect on depending on how dark the object is, equasion for this is -(2x-1)^{2}+1
|
||||
float noiseAmplification = noiseIntensity * 0.01;
|
||||
noiseAmplification = (-1.0 * pow(2.0*((fragColor.x + fragColor.y + fragColor.z) / 3.0) - 1.0, 2.0) + 1.0) * noiseAmplification; // Lessen the effect on depending on how dark the object is, equasion for this is -(2x-1)^{2}+1
|
||||
noiseAmplification *= fragColor.w; // The effect would lessen on transparent objects
|
||||
|
||||
// Random value for each position
|
||||
@@ -91,30 +88,20 @@ void main()
|
||||
quantize(fixedVPos.y, noiseSteps),
|
||||
quantize(fixedVPos.z, noiseSteps)
|
||||
))
|
||||
* 2. * noiseAmplification - noiseAmplification;
|
||||
* 2.0 * noiseAmplification - noiseAmplification;
|
||||
|
||||
|
||||
// Modifies the color
|
||||
// A value of 0 on the randomValue will result in the original color, while a value of 1 will result in a fully bright color
|
||||
vec3 newCol = fragColor.rgb + (vec3(1.0) - fragColor.rgb) * randomValue;
|
||||
vec3 newCol = fragColor.rgb + (1.0 - fragColor.rgb) * randomValue;
|
||||
|
||||
// Clamps it and turns it back into a vec4
|
||||
if (noiseDropoff == 0)
|
||||
fragColor = vec4(
|
||||
clamp(newCol.r, 0., 1.),
|
||||
clamp(newCol.g, 0., 1.),
|
||||
clamp(newCol.b, 0., 1.),
|
||||
fragColor.w
|
||||
);
|
||||
fragColor = vec4(clamp(newCol.rgb, 0.0, 1.0), fragColor.w);
|
||||
else
|
||||
fragColor = mix(
|
||||
vec4(
|
||||
clamp(newCol.r, 0., 1.),
|
||||
clamp(newCol.g, 0., 1.),
|
||||
clamp(newCol.b, 0., 1.),
|
||||
fragColor.w
|
||||
), fragColor,
|
||||
clamp(length(vertexWorldPos) / noiseDropoff, 0., 1.) // The further away it gets, the less noise gets applied
|
||||
vec4(clamp(newCol.rgb, 0.0, 1.0), fragColor.w), fragColor,
|
||||
min(length(vertexWorldPos) / noiseDropoff, 1.0) // The further away it gets, the less noise gets applied
|
||||
);
|
||||
|
||||
// For testing
|
||||
|
||||
@@ -59,16 +59,12 @@ float mod(float x, int y) {
|
||||
|
||||
vec3 calcViewPosition(float fragmentDepth)
|
||||
{
|
||||
vec4 ndc = vec4(
|
||||
TexCoord.x * 2.0 - 1.0,
|
||||
TexCoord.y * 2.0 - 1.0,
|
||||
fragmentDepth * 2.0 - 1.0,
|
||||
1.0
|
||||
);
|
||||
vec4 ndc = vec4(TexCoord.xy, fragmentDepth, 1.0);
|
||||
ndc.xyz = ndc.xyz * 2.0 - 1.0;
|
||||
|
||||
// TODO: This inverse() should be moved CPU side
|
||||
vec4 eyeCoord = inverse(gMvmProj) * ndc;
|
||||
vec3 cameraPos = eyeCoord.xyz / eyeCoord.w;
|
||||
return cameraPos;
|
||||
return eyeCoord.xyz / eyeCoord.w;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,7 +81,7 @@ void main()
|
||||
// a fragment depth of "1" means the fragment wasn't drawn to,
|
||||
// we only want to apply Fog to LODs, not to the sky outside the LODs
|
||||
// FIXME: This bit of code causes problems on intel integrated graphics
|
||||
if (fragmentDepth != -420.0) // Should be `1.0`, but set to `-420.0` both so that the compiler doesnt mess with rest of the code, and it always returns true
|
||||
if (fragmentDepth < 0.99999)
|
||||
{
|
||||
if (fullFogMode == 0)
|
||||
{
|
||||
@@ -99,17 +95,15 @@ void main()
|
||||
float nearFogThickness = getNearFogThickness(horizontalDist);
|
||||
float farFogThickness = getFarFogThickness(farDist);
|
||||
float heightFogThickness = getHeightFogThickness(heightDist);
|
||||
float mixedFogThickness =
|
||||
clamp(
|
||||
mixFogThickness(nearFogThickness, farFogThickness, heightFogThickness)
|
||||
, 0.0, 1.0);
|
||||
float mixedFogThickness = mixFogThickness(nearFogThickness, farFogThickness, heightFogThickness)
|
||||
mixedFogThickness = clamp(mixedFogThickness, 0.0, 1.0);
|
||||
|
||||
fragColor = vec4(fogColor.r, fogColor.g, fogColor.b, mixedFogThickness);
|
||||
fragColor = vec4(fogColor.rgb, mixedFogThickness);
|
||||
}
|
||||
else if (fullFogMode == 1)
|
||||
{
|
||||
// render everything with the fog color
|
||||
fragColor = vec4(fogColor.r, fogColor.g, fogColor.b, 1.0);
|
||||
fragColor = vec4(fogColor.rgb, 1.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -26,6 +26,10 @@ float quantize(float val, int stepSize) {
|
||||
return floor(val*stepSize)/stepSize;
|
||||
}
|
||||
|
||||
vec3 quantize(vec3 val, int stepSize) {
|
||||
return floor(val*stepSize)/stepSize;
|
||||
}
|
||||
|
||||
// The modulus function dosnt exist in GLSL so I made my own
|
||||
// To speed up the mod function, this only accepts full numbers for y
|
||||
float mod(float x, int y) {
|
||||
@@ -44,11 +48,7 @@ float mod(float x, int y) {
|
||||
void main() {
|
||||
// This bit of code is required to fix the vertex position problem cus of floats in the verted world position varuable
|
||||
vec3 vertexNormal = normalize(cross(dFdx(vPos.xyz), dFdy(vPos.xyz)));
|
||||
vec3 fixedVPos = vec3(
|
||||
vPos.x - vertexNormal.x * 0.001,
|
||||
vPos.y - vertexNormal.y * 0.001,
|
||||
vPos.z - vertexNormal.z * 0.001
|
||||
);
|
||||
vec3 fixedVPos = vPos.xyz - vertexNormal * 0.001;
|
||||
|
||||
|
||||
float noiseAmplification = noiseIntensity / 100;
|
||||
@@ -56,29 +56,20 @@ void main() {
|
||||
noiseAmplification *= vertexColor.w; // The effect would lessen on transparent objects
|
||||
|
||||
// Random value for each position
|
||||
float randomValue = rand(vec3(
|
||||
quantize(fixedVPos.x, noiseSteps),
|
||||
quantize(fixedVPos.y, noiseSteps),
|
||||
quantize(fixedVPos.z, noiseSteps)
|
||||
))
|
||||
* 2. * noiseAmplification - noiseAmplification;
|
||||
float randomValue = rand(quantize(fixedVPos.xyz, noiseSteps))
|
||||
* 2.0 * noiseAmplification - noiseAmplification;
|
||||
|
||||
|
||||
// Modifies the color
|
||||
// A value of 0 on the randomValue will result in the original color, while a value of 1 will result in a fully bright color
|
||||
vec3 newCol = (vec3(1.0) - vertexColor.rgb) * randomValue;
|
||||
vec3 newCol = (1.0 - vertexColor.rgb) * randomValue;
|
||||
|
||||
// Clamps it and turns it back into a vec4
|
||||
fragColor = vec4(
|
||||
clamp(newCol.r, 0., 1.),
|
||||
clamp(newCol.g, 0., 1.),
|
||||
clamp(newCol.b, 0., 1.),
|
||||
clamp(length(vertexWorldPos) * distanceScale * noiseDropoff, 0., 1.) // The further away it gets, the less noise gets applied
|
||||
);
|
||||
fragColor = vec4(
|
||||
0f, 0f, 0f,
|
||||
randomValue // The further away it gets, the less noise gets applied
|
||||
);
|
||||
float distA = length(vertexWorldPos) * distanceScale * noiseDropoff;
|
||||
fragColor = clamp(vec4(newCol.rgb, distA), 0.0, 1.0); // The further away it gets, the less noise gets applied
|
||||
|
||||
// The further away it gets, the less noise gets applied
|
||||
fragColor = vec4(0.0, 0.0, 0.0, randomValue);
|
||||
|
||||
// For testing
|
||||
// if (vertexColor.r != 69420.) {
|
||||
|
||||
@@ -17,40 +17,30 @@ uniform vec3 gKernel[MAX_KERNEL_SIZE];
|
||||
|
||||
vec3 calcViewPosition(vec2 coords) {
|
||||
float fragmentDepth = texture(gDepthMap, coords).r;
|
||||
vec4 ndc = vec4(coords.xy, fragmentDepth, 1.0);
|
||||
ndc.xyz = ndc.xyz * 2.0 - 1.0;
|
||||
|
||||
vec4 ndc = vec4(
|
||||
coords.x * 2.0 - 1.0,
|
||||
coords.y * 2.0 - 1.0,
|
||||
fragmentDepth * 2.0 - 1.0,
|
||||
1.0
|
||||
);
|
||||
|
||||
// TODO: This inverse() call should be moved CPU side
|
||||
vec4 vs_pos = inverse(gProj) * ndc;
|
||||
vs_pos.xyz = vs_pos.xyz / vs_pos.w;
|
||||
return vs_pos.xyz;
|
||||
return vs_pos.xyz / vs_pos.w;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 viewPos = calcViewPosition(TexCoord);
|
||||
vec3 viewNormal = normalize(cross(dFdy(viewPos.xyz), dFdx(viewPos.xyz)) * -1.0);
|
||||
vec3 viewNormal = normalize(cross(dFdx(viewPos.xyz), dFdy(viewPos.xyz)));
|
||||
|
||||
vec3 randomVec = vec3(
|
||||
0.0,
|
||||
-1.0,
|
||||
0.0
|
||||
);
|
||||
vec3 randomVec = vec3(0.0, -1.0, 0.0);
|
||||
|
||||
vec3 tangent = normalize(randomVec - viewNormal * dot(randomVec, viewNormal));
|
||||
vec3 bitangent = cross(viewNormal, tangent);
|
||||
mat3 TBN = mat3(tangent, bitangent, viewNormal);
|
||||
|
||||
float occlusion_factor = 0.0;
|
||||
for (int i = 0; i < MAX_KERNEL_SIZE; i++) {
|
||||
vec3 samplePos = vec3(0.0) + (TBN * gKernel[i]);
|
||||
samplePos = viewPos + samplePos * gSampleRad;
|
||||
vec3 samplePos = TBN * gKernel[i] * gSampleRad;
|
||||
|
||||
vec4 offset = vec4(samplePos, 1.0);
|
||||
offset = gProj * offset;
|
||||
vec4 offset = gProj * vec4(samplePos + viewPos, 1.0);
|
||||
offset.xy /= offset.w;
|
||||
offset.xy = offset.xy * HALF_2 + HALF_2;
|
||||
|
||||
|
||||
@@ -13,9 +13,9 @@ void main()
|
||||
float fragmentDepth = texture(gDepthMap, TexCoord).r;
|
||||
// a fragment depth of "1" means the fragment wasn't drawn to,
|
||||
// we only want to apply SSAO to LODs, not to the sky outside the LODs
|
||||
// FIXME: This bit of code causes problems on intel integrated graphics
|
||||
if (fragmentDepth != -420.0) // Should be `1.0`, but set to `-420.0` both so that the compiler doesnt mess with rest of the code, and it always returns true
|
||||
if (fragmentDepth < 0.99999)
|
||||
{
|
||||
fragColor = vec4(0.0, 0.0, 0.0, 1-texture(gSSAOMap, TexCoord).r);
|
||||
fragColor = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
fragColor.a -= textureLod(gSSAOMap, TexCoord, 0).r;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ uniform float mircoOffset;
|
||||
*/
|
||||
void main()
|
||||
{
|
||||
vPos = vec4(vPosition.x, vPosition.y, vPosition.z, vPosition.w); // This is so it can be passed to the fragment shader
|
||||
vPos = vPosition; // This is so it can be passed to the fragment shader
|
||||
|
||||
vertexWorldPos = vPosition.xyz + modelOffset;
|
||||
|
||||
@@ -54,6 +54,7 @@ void main()
|
||||
float light2 = (mod(float(lights), 16.0)+0.5) / 16.0;
|
||||
float light = (float(lights/16u)+0.5) / 16.0;
|
||||
vertexColor = vec4(texture(lightMap, vec2(light, light2)).xyz, 1.0);
|
||||
|
||||
if (!whiteWorld)
|
||||
{
|
||||
vertexColor *= color;
|
||||
|
||||
Reference in New Issue
Block a user