mirror of
https://github.com/raysan5/raylib.git
synced 2026-03-29 03:42:04 +00:00
Remove trailing spaces on shaders
This commit is contained in:
@@ -23,15 +23,15 @@ void main()
|
||||
float localX = mod(fragCoord.x, cellWidth);
|
||||
float barWidth = cellWidth - 1.0;
|
||||
vec4 color = WHITE;
|
||||
|
||||
|
||||
if (localX <= barWidth)
|
||||
{
|
||||
float sampleX = (binIndex + 0.5)/NUM_OF_BINS;
|
||||
vec2 sampleCoord = vec2(sampleX, FFT_ROW);
|
||||
float amplitude = texture2D(iChannel0, sampleCoord).r; // Only filled the red channel, all channels left open for alternative use
|
||||
|
||||
|
||||
if (fragTexCoord.y < amplitude) color = BLACK;
|
||||
}
|
||||
|
||||
|
||||
gl_FragColor = color;
|
||||
}
|
||||
|
||||
@@ -21,15 +21,15 @@ void main()
|
||||
float localX = mod(fragCoord.x, cellWidth);
|
||||
float barWidth = cellWidth - 1.0;
|
||||
vec4 color = WHITE;
|
||||
|
||||
|
||||
if (localX <= barWidth)
|
||||
{
|
||||
float sampleX = (binIndex + 0.5)/NUM_OF_BINS;
|
||||
vec2 sampleCoord = vec2(sampleX, FFT_ROW);
|
||||
float amplitude = texture2D(iChannel0, sampleCoord).r; // Only filled the red channel, all channels left open for alternative use
|
||||
|
||||
|
||||
if (fragTexCoord.y < amplitude) color = BLACK;
|
||||
}
|
||||
|
||||
|
||||
gl_FragColor = color;
|
||||
}
|
||||
|
||||
@@ -21,15 +21,15 @@ void main()
|
||||
float localX = mod(fragCoord.x, cellWidth);
|
||||
float barWidth = cellWidth - 1.0;
|
||||
vec4 color = WHITE;
|
||||
|
||||
|
||||
if (localX <= barWidth)
|
||||
{
|
||||
float sampleX = (binIndex + 0.5)/NUM_OF_BINS;
|
||||
vec2 sampleCoord = vec2(sampleX, FFT_ROW);
|
||||
float amplitude = texture(iChannel0, sampleCoord).r; // Only filled the red channel, all channels left open for alternative use
|
||||
|
||||
|
||||
if (fragTexCoord.y < amplitude) color = BLACK;
|
||||
}
|
||||
|
||||
|
||||
finalColor = color;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ void main()
|
||||
{
|
||||
// Fetch color from texture sampler
|
||||
vec4 texelColor = texture2D(texture0, fragTexCoord);
|
||||
|
||||
|
||||
// Calculate final fragment color
|
||||
gl_FragColor = texelColor*colDiffuse*fragColor;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ void main()
|
||||
int boneIndex1 = int(vertexBoneIndices.y);
|
||||
int boneIndex2 = int(vertexBoneIndices.z);
|
||||
int boneIndex3 = int(vertexBoneIndices.w);
|
||||
|
||||
|
||||
// WARNING: OpenGL ES 2.0 does not support automatic matrix transposing, neither transpose() function
|
||||
mat4 boneMatrixTransposed0 = mat4(
|
||||
vec4(boneMatrices[boneIndex0][0].x, boneMatrices[boneIndex0][1].x, boneMatrices[boneIndex0][2].x, boneMatrices[boneIndex0][3].x),
|
||||
@@ -45,13 +45,13 @@ void main()
|
||||
vec4(boneMatrices[boneIndex3][0].y, boneMatrices[boneIndex3][1].y, boneMatrices[boneIndex3][2].y, boneMatrices[boneIndex3][3].y),
|
||||
vec4(boneMatrices[boneIndex3][0].z, boneMatrices[boneIndex3][1].z, boneMatrices[boneIndex3][2].z, boneMatrices[boneIndex3][3].z),
|
||||
vec4(boneMatrices[boneIndex3][0].w, boneMatrices[boneIndex3][1].w, boneMatrices[boneIndex3][2].w, boneMatrices[boneIndex3][3].w));
|
||||
|
||||
|
||||
vec4 skinnedPosition =
|
||||
vertexBoneWeights.x*(boneMatrixTransposed0*vec4(vertexPosition, 1.0)) +
|
||||
vertexBoneWeights.y*(boneMatrixTransposed1*vec4(vertexPosition, 1.0)) +
|
||||
vertexBoneWeights.z*(boneMatrixTransposed2*vec4(vertexPosition, 1.0)) +
|
||||
vertexBoneWeights.y*(boneMatrixTransposed1*vec4(vertexPosition, 1.0)) +
|
||||
vertexBoneWeights.z*(boneMatrixTransposed2*vec4(vertexPosition, 1.0)) +
|
||||
vertexBoneWeights.w*(boneMatrixTransposed3*vec4(vertexPosition, 1.0));
|
||||
|
||||
|
||||
fragTexCoord = vertexTexCoord;
|
||||
fragColor = vertexColor;
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ void main()
|
||||
{
|
||||
// Fetch color from texture sampler
|
||||
vec4 texelColor = texture2D(texture0, fragTexCoord);
|
||||
|
||||
|
||||
// Calculate final fragment color
|
||||
gl_FragColor = texelColor*colDiffuse*fragColor;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ void main()
|
||||
int boneIndex1 = int(vertexBoneIndices.y);
|
||||
int boneIndex2 = int(vertexBoneIndices.z);
|
||||
int boneIndex3 = int(vertexBoneIndices.w);
|
||||
|
||||
|
||||
// WARNING: OpenGL ES 2.0 does not support automatic matrix transposing, neither transpose() function
|
||||
mat4 boneMatrixTransposed0 = mat4(
|
||||
vec4(boneMatrices[boneIndex0][0].x, boneMatrices[boneIndex0][1].x, boneMatrices[boneIndex0][2].x, boneMatrices[boneIndex0][3].x),
|
||||
@@ -45,13 +45,13 @@ void main()
|
||||
vec4(boneMatrices[boneIndex3][0].y, boneMatrices[boneIndex3][1].y, boneMatrices[boneIndex3][2].y, boneMatrices[boneIndex3][3].y),
|
||||
vec4(boneMatrices[boneIndex3][0].z, boneMatrices[boneIndex3][1].z, boneMatrices[boneIndex3][2].z, boneMatrices[boneIndex3][3].z),
|
||||
vec4(boneMatrices[boneIndex3][0].w, boneMatrices[boneIndex3][1].w, boneMatrices[boneIndex3][2].w, boneMatrices[boneIndex3][3].w));
|
||||
|
||||
|
||||
vec4 skinnedPosition =
|
||||
vertexBoneWeights.x*(boneMatrixTransposed0*vec4(vertexPosition, 1.0)) +
|
||||
vertexBoneWeights.y*(boneMatrixTransposed1*vec4(vertexPosition, 1.0)) +
|
||||
vertexBoneWeights.z*(boneMatrixTransposed2*vec4(vertexPosition, 1.0)) +
|
||||
vertexBoneWeights.y*(boneMatrixTransposed1*vec4(vertexPosition, 1.0)) +
|
||||
vertexBoneWeights.z*(boneMatrixTransposed2*vec4(vertexPosition, 1.0)) +
|
||||
vertexBoneWeights.w*(boneMatrixTransposed3*vec4(vertexPosition, 1.0));
|
||||
|
||||
|
||||
fragTexCoord = vertexTexCoord;
|
||||
fragColor = vertexColor;
|
||||
|
||||
|
||||
@@ -26,17 +26,17 @@ void main()
|
||||
int boneIndex1 = int(vertexBoneIndices.y);
|
||||
int boneIndex2 = int(vertexBoneIndices.z);
|
||||
int boneIndex3 = int(vertexBoneIndices.w);
|
||||
|
||||
|
||||
vec4 skinnedPosition =
|
||||
vertexBoneWeights.x*(boneMatrices[boneIndex0]*vec4(vertexPosition, 1.0)) +
|
||||
vertexBoneWeights.y*(boneMatrices[boneIndex1]*vec4(vertexPosition, 1.0)) +
|
||||
vertexBoneWeights.z*(boneMatrices[boneIndex2]*vec4(vertexPosition, 1.0)) +
|
||||
vertexBoneWeights.y*(boneMatrices[boneIndex1]*vec4(vertexPosition, 1.0)) +
|
||||
vertexBoneWeights.z*(boneMatrices[boneIndex2]*vec4(vertexPosition, 1.0)) +
|
||||
vertexBoneWeights.w*(boneMatrices[boneIndex3]*vec4(vertexPosition, 1.0));
|
||||
|
||||
vec4 skinnedNormal =
|
||||
vertexBoneWeights.x*(boneMatrices[boneIndex0]*vec4(vertexNormal, 0.0)) +
|
||||
vertexBoneWeights.y*(boneMatrices[boneIndex1]*vec4(vertexNormal, 0.0)) +
|
||||
vertexBoneWeights.z*(boneMatrices[boneIndex2]*vec4(vertexNormal, 0.0)) +
|
||||
vertexBoneWeights.y*(boneMatrices[boneIndex1]*vec4(vertexNormal, 0.0)) +
|
||||
vertexBoneWeights.z*(boneMatrices[boneIndex2]*vec4(vertexNormal, 0.0)) +
|
||||
vertexBoneWeights.w*(boneMatrices[boneIndex3]*vec4(vertexNormal, 0.0));
|
||||
skinnedNormal.w = 0.0;
|
||||
|
||||
|
||||
@@ -58,12 +58,12 @@ void main()
|
||||
float gray = GreyScale(cellColor);
|
||||
|
||||
float n = 4096.0;
|
||||
|
||||
|
||||
// Character set from https://www.shadertoy.com/view/lssGDj
|
||||
// Create new bitmaps https://thrill-project.com/archiv/coding/bitmap/
|
||||
if (gray > 0.2) n = 65600.0; // :
|
||||
if (gray > 0.3) n = 18725316.0; // v
|
||||
if (gray > 0.4) n = 15255086.0; // o
|
||||
if (gray > 0.4) n = 15255086.0; // o
|
||||
if (gray > 0.5) n = 13121101.0; // &
|
||||
if (gray > 0.6) n = 15252014.0; // 8
|
||||
if (gray > 0.7) n = 13195790.0; // @
|
||||
|
||||
@@ -12,5 +12,5 @@ void main()
|
||||
fragTexCoord = vertexTexCoord;
|
||||
|
||||
// Calculate final vertex position
|
||||
gl_Position = vec4(vertexPosition, 1.0);
|
||||
gl_Position = vec4(vertexPosition, 1.0);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#version 100
|
||||
#extension GL_EXT_frag_depth : enable
|
||||
#extension GL_EXT_frag_depth : enable
|
||||
|
||||
precision mediump float;
|
||||
|
||||
@@ -14,7 +14,7 @@ uniform vec4 colDiffuse;
|
||||
void main()
|
||||
{
|
||||
vec4 texelColor = texture2D(texture0, fragTexCoord);
|
||||
|
||||
|
||||
gl_FragColor = texelColor*colDiffuse*fragColor;
|
||||
gl_FragDepthEXT = 1.0 - gl_FragCoord.z;
|
||||
}
|
||||
|
||||
@@ -24,13 +24,13 @@ void main()
|
||||
{
|
||||
// Store the fragment position vector in the first gbuffer texture
|
||||
//gPosition = fragPosition;
|
||||
|
||||
|
||||
// Store the per-fragment normals into the gbuffer
|
||||
//gNormal = normalize(fragNormal);
|
||||
|
||||
|
||||
// Store the diffuse per-fragment color
|
||||
gl_FragColor.rgb = texture2D(texture0, fragTexCoord).rgb;
|
||||
|
||||
|
||||
// Store specular intensity in gAlbedoSpec's alpha component
|
||||
gl_FragColor.a = texture2D(specularTexture, fragTexCoord).r;
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ void main()
|
||||
{
|
||||
// Calculate vertex attributes for fragment shader
|
||||
vec4 worldPos = matModel*vec4(vertexPosition, 1.0);
|
||||
fragPosition = worldPos.xyz;
|
||||
fragPosition = worldPos.xyz;
|
||||
fragTexCoord = vertexTexCoord;
|
||||
fragColor = vertexColor;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#version 100
|
||||
|
||||
#extension GL_EXT_frag_depth : enable // Extension required for writing depth
|
||||
|
||||
|
||||
precision mediump float; // Precision required for OpenGL ES2 (WebGL)
|
||||
|
||||
varying vec2 fragTexCoord;
|
||||
|
||||
@@ -32,12 +32,12 @@ float sdHorseshoe(in vec3 p, in vec2 c, in float r, in float le, vec2 w)
|
||||
{
|
||||
p.x = abs(p.x);
|
||||
float l = length(p.xy);
|
||||
p.xy = mat2(-c.x, c.y,
|
||||
p.xy = mat2(-c.x, c.y,
|
||||
c.y, c.x)*p.xy;
|
||||
p.xy = vec2((p.y>0.0 || p.x>0.0)?p.x:l*sign(-c.x),
|
||||
(p.x>0.0)?p.y:l);
|
||||
p.xy = vec2(p.x,abs(p.y-r))-vec2(le,0.0);
|
||||
|
||||
|
||||
vec2 q = vec2(length(max(p.xy,0.0)) + min(0.0,max(p.x,p.y)),p.z);
|
||||
vec2 d = abs(q) - w;
|
||||
return min(max(d.x,d.y),0.0) + length(max(d,0.0));
|
||||
@@ -56,9 +56,9 @@ float sdSixWayCutHollowSphere(vec3 p, float r, float h, float t)
|
||||
}
|
||||
|
||||
vec2 q = vec2(length(ap.yz), ap.x);
|
||||
|
||||
|
||||
float w = sqrt(r*r-h*h);
|
||||
|
||||
|
||||
return ((h*q.x<w*q.y) ? length(q-vec2(w,h)) : abs(length(q)-r)) - t;
|
||||
}
|
||||
|
||||
@@ -110,8 +110,8 @@ vec2 raycast(in vec3 ro, in vec3 rd)
|
||||
if (t>tmax) break;
|
||||
vec2 h = map(ro+rd*t);
|
||||
if (abs(h.x) < (0.0001*t))
|
||||
{
|
||||
res = vec2(t,h.y);
|
||||
{
|
||||
res = vec2(t,h.y);
|
||||
break;
|
||||
}
|
||||
t += h.x;
|
||||
@@ -146,9 +146,9 @@ float calcSoftshadow(in vec3 ro, in vec3 rd, in float mint, in float tmax)
|
||||
vec3 calcNormal(in vec3 pos)
|
||||
{
|
||||
vec2 e = vec2(1.0,-1.0)*0.5773*0.0005;
|
||||
return normalize(e.xyy*map(pos + e.xyy).x +
|
||||
e.yyx*map(pos + e.yyx).x +
|
||||
e.yxy*map(pos + e.yxy).x +
|
||||
return normalize(e.xyy*map(pos + e.xyy).x +
|
||||
e.yyx*map(pos + e.yyx).x +
|
||||
e.yxy*map(pos + e.yxy).x +
|
||||
e.xxx*map(pos + e.xxx).x);
|
||||
}
|
||||
|
||||
@@ -176,15 +176,15 @@ float checkersGradBox(in vec2 p)
|
||||
// analytical integral (box filter)
|
||||
vec2 i = 2.0*(abs(fract((p-0.5*w)*0.5)-0.5)-abs(fract((p+0.5*w)*0.5)-0.5))/w;
|
||||
// xor pattern
|
||||
return 0.5 - 0.5*i.x*i.y;
|
||||
return 0.5 - 0.5*i.x*i.y;
|
||||
}
|
||||
|
||||
// https://www.shadertoy.com/view/tdS3DG
|
||||
vec4 render(in vec3 ro, in vec3 rd)
|
||||
{
|
||||
{
|
||||
// background
|
||||
vec3 col = vec3(0.7, 0.7, 0.9) - max(rd.y,0.0)*0.3;
|
||||
|
||||
|
||||
// raycast scene
|
||||
vec2 res = raycast(ro,rd);
|
||||
float t = res.x;
|
||||
@@ -194,11 +194,11 @@ vec4 render(in vec3 ro, in vec3 rd)
|
||||
vec3 pos = ro + t*rd;
|
||||
vec3 nor = (m<1.5) ? vec3(0.0,1.0,0.0) : calcNormal(pos);
|
||||
vec3 ref = reflect(rd, nor);
|
||||
|
||||
// material
|
||||
|
||||
// material
|
||||
col = 0.2 + 0.2*sin(m*2.0 + vec3(0.0,1.0,2.0));
|
||||
float ks = 1.0;
|
||||
|
||||
|
||||
if (m<1.5)
|
||||
{
|
||||
float f = checkersGradBox(3.0*pos.xz);
|
||||
@@ -208,7 +208,7 @@ vec4 render(in vec3 ro, in vec3 rd)
|
||||
|
||||
// lighting
|
||||
float occ = calcAO(pos, nor);
|
||||
|
||||
|
||||
vec3 lin = vec3(0.0);
|
||||
|
||||
// sun
|
||||
@@ -249,7 +249,7 @@ vec4 render(in vec3 ro, in vec3 rd)
|
||||
dif *= occ;
|
||||
lin += col*0.25*dif*vec3(1.00,1.00,1.00);
|
||||
}
|
||||
|
||||
|
||||
col = lin;
|
||||
|
||||
col = mix(col, vec3(0.7,0.7,0.9), 1.0-exp(-0.0001*t*t*t));
|
||||
@@ -289,7 +289,7 @@ void main()
|
||||
color = res.xyz;
|
||||
depth = CalcDepth(rd,res.w);
|
||||
}
|
||||
|
||||
|
||||
gl_FragColor = vec4(color , 1.0);
|
||||
gl_FragDepthEXT = depth;
|
||||
}
|
||||
@@ -48,7 +48,7 @@ void main()
|
||||
float normR = float(iter - (iter/55)*55)/55.0;
|
||||
float normG = float(iter - (iter/69)*69)/69.0;
|
||||
float normB = float(iter - (iter/40)*40)/40.0;
|
||||
|
||||
|
||||
gl_FragColor = vec4(sin(normR*PI), sin(normG*PI), sin(normB*PI), 1.0);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ void main()
|
||||
// Convert the (normalized) texel color RED component (GB would work, too)
|
||||
// to the palette index by scaling up from [0..1] to [0..255]
|
||||
int index = int(texelColor.r*255.0);
|
||||
|
||||
|
||||
ivec3 color = ivec3(0);
|
||||
|
||||
// NOTE: On GLSL 100 we are not allowed to index a uniform array by a variable value,
|
||||
@@ -34,7 +34,7 @@ void main()
|
||||
else if (index == 5) color = palette[5];
|
||||
else if (index == 6) color = palette[6];
|
||||
else if (index == 7) color = palette[7];
|
||||
|
||||
|
||||
//gl_FragColor = texture2D(palette, texelColor.xy); // Alternative to ivec3
|
||||
|
||||
// Calculate final fragment color. Note that the palette color components
|
||||
|
||||
@@ -83,11 +83,11 @@ vec3 ComputePBR()
|
||||
{
|
||||
vec3 albedo = texture2D(albedoMap, vec2(fragTexCoord.x*tiling.x + offset.x, fragTexCoord.y*tiling.y + offset.y)).rgb;
|
||||
albedo = vec3(albedoColor.x*albedo.x, albedoColor.y*albedo.y, albedoColor.z*albedo.z);
|
||||
|
||||
|
||||
float metallic = clamp(metallicValue, 0.0, 1.0);
|
||||
float roughness = clamp(roughnessValue, 0.0, 1.0);
|
||||
float ao = clamp(aoValue, 0.0, 1.0);
|
||||
|
||||
|
||||
if (useTexMRA == 1)
|
||||
{
|
||||
vec4 mra = texture2D(mraMap, vec2(fragTexCoord.x*tiling.x + offset.x, fragTexCoord.y*tiling.y + offset.y));
|
||||
@@ -132,18 +132,18 @@ vec3 ComputePBR()
|
||||
vec3 F = SchlickFresnel(hDotV, baseRefl); // Fresnel proportion of specular reflectance
|
||||
|
||||
vec3 spec = (D*G*F)/(4.0*nDotV*nDotL);
|
||||
|
||||
|
||||
// Difuse and spec light can't be above 1.0
|
||||
// kD = 1.0 - kS diffuse component is equal 1.0 - spec comonent
|
||||
vec3 kD = vec3(1.0) - F;
|
||||
|
||||
|
||||
// Mult kD by the inverse of metallnes, only non-metals should have diffuse light
|
||||
kD *= 1.0 - metallic;
|
||||
lightAccum += ((kD*albedo.rgb/PI + spec)*radiance*nDotL)*float(lights[i].enabled); // Angle of light has impact on result
|
||||
}
|
||||
|
||||
|
||||
vec3 ambientFinal = (ambientColor + albedo)*ambient*0.5;
|
||||
|
||||
|
||||
return (ambientFinal + lightAccum*ao + emissive);
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ void main()
|
||||
|
||||
// HDR tonemapping
|
||||
color = pow(color, color + vec3(1.0));
|
||||
|
||||
|
||||
// Gamma correction
|
||||
color = pow(color, vec3(1.0/2.2));
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ void main()
|
||||
float bias = max(0.0008*(1.0 - dot(normal, l)), 0.00008);
|
||||
int shadowCounter = 0;
|
||||
const int numSamples = 9;
|
||||
|
||||
|
||||
// PCF (percentage-closer filtering) algorithm:
|
||||
// Instead of testing if just one point is closer to the current point,
|
||||
// we test the surrounding points as well
|
||||
@@ -74,7 +74,7 @@ void main()
|
||||
if (curDepth - bias > sampleDepth) shadowCounter++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
finalColor = mix(finalColor, vec4(0, 0, 0, 1), float(shadowCounter)/float(numSamples));
|
||||
|
||||
// Add ambient lighting whether in shadow or not
|
||||
|
||||
@@ -56,12 +56,12 @@ void main()
|
||||
float gray = GreyScale(cellColor);
|
||||
|
||||
float n = 4096.0;
|
||||
|
||||
|
||||
// Character set from https://www.shadertoy.com/view/lssGDj
|
||||
// Create new bitmaps https://thrill-project.com/archiv/coding/bitmap/
|
||||
if (gray > 0.2) n = 65600.0; // :
|
||||
if (gray > 0.3) n = 18725316.0; // v
|
||||
if (gray > 0.4) n = 15255086.0; // o
|
||||
if (gray > 0.4) n = 15255086.0; // o
|
||||
if (gray > 0.5) n = 13121101.0; // &
|
||||
if (gray > 0.6) n = 15252014.0; // 8
|
||||
if (gray > 0.7) n = 13195790.0; // @
|
||||
|
||||
@@ -12,5 +12,5 @@ void main()
|
||||
fragTexCoord = vertexTexCoord;
|
||||
|
||||
// Calculate final vertex position
|
||||
gl_Position = vec4(vertexPosition, 1.0);
|
||||
gl_Position = vec4(vertexPosition, 1.0);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#version 120
|
||||
|
||||
#extension GL_EXT_frag_depth : enable
|
||||
#extension GL_EXT_frag_depth : enable
|
||||
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
@@ -11,7 +11,7 @@ uniform vec4 colDiffuse;
|
||||
void main()
|
||||
{
|
||||
vec4 texelColor = texture2D(texture0, fragTexCoord);
|
||||
|
||||
|
||||
gl_FragColor = texelColor*colDiffuse*fragColor;
|
||||
gl_FragDepthEXT = 1.0 - gl_FragCoord.z;
|
||||
}
|
||||
@@ -22,13 +22,13 @@ void main()
|
||||
{
|
||||
// Store the fragment position vector in the first gbuffer texture
|
||||
//gPosition = fragPosition;
|
||||
|
||||
|
||||
// Store the per-fragment normals into the gbuffer
|
||||
//gNormal = normalize(fragNormal);
|
||||
|
||||
|
||||
// Store the diffuse per-fragment color
|
||||
gl_FragColor.rgb = texture2D(texture0, fragTexCoord).rgb;
|
||||
|
||||
|
||||
// Store specular intensity in gAlbedoSpec's alpha component
|
||||
gl_FragColor.a = texture2D(specularTexture, fragTexCoord).r;
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ void main()
|
||||
{
|
||||
// Calculate vertex attributes for fragment shader
|
||||
vec4 worldPos = matModel*vec4(vertexPosition, 1.0);
|
||||
fragPosition = worldPos.xyz;
|
||||
fragPosition = worldPos.xyz;
|
||||
fragTexCoord = vertexTexCoord;
|
||||
fragColor = vertexColor;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#version 120
|
||||
|
||||
#extension GL_EXT_frag_depth : enable // Extension required for writing depth
|
||||
#extension GL_EXT_frag_depth : enable // Extension required for writing depth
|
||||
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
@@ -30,12 +30,12 @@ float sdHorseshoe(in vec3 p, in vec2 c, in float r, in float le, vec2 w)
|
||||
{
|
||||
p.x = abs(p.x);
|
||||
float l = length(p.xy);
|
||||
p.xy = mat2(-c.x, c.y,
|
||||
p.xy = mat2(-c.x, c.y,
|
||||
c.y, c.x)*p.xy;
|
||||
p.xy = vec2((p.y>0.0 || p.x>0.0)?p.x:l*sign(-c.x),
|
||||
(p.x>0.0)?p.y:l);
|
||||
p.xy = vec2(p.x,abs(p.y-r))-vec2(le,0.0);
|
||||
|
||||
|
||||
vec2 q = vec2(length(max(p.xy,0.0)) + min(0.0,max(p.x,p.y)),p.z);
|
||||
vec2 d = abs(q) - w;
|
||||
return min(max(d.x,d.y),0.0) + length(max(d,0.0));
|
||||
@@ -54,9 +54,9 @@ float sdSixWayCutHollowSphere(vec3 p, float r, float h, float t)
|
||||
}
|
||||
|
||||
vec2 q = vec2(length(ap.yz), ap.x);
|
||||
|
||||
|
||||
float w = sqrt(r*r-h*h);
|
||||
|
||||
|
||||
return ((h*q.x<w*q.y) ? length(q-vec2(w,h)) : abs(length(q)-r)) - t;
|
||||
}
|
||||
|
||||
@@ -108,8 +108,8 @@ vec2 raycast(in vec3 ro, in vec3 rd)
|
||||
if (t>tmax) break;
|
||||
vec2 h = map(ro+rd*t);
|
||||
if (abs(h.x) < (0.0001*t))
|
||||
{
|
||||
res = vec2(t,h.y);
|
||||
{
|
||||
res = vec2(t,h.y);
|
||||
break;
|
||||
}
|
||||
t += h.x;
|
||||
@@ -144,9 +144,9 @@ float calcSoftshadow(in vec3 ro, in vec3 rd, in float mint, in float tmax)
|
||||
vec3 calcNormal(in vec3 pos)
|
||||
{
|
||||
vec2 e = vec2(1.0, -1.0)*0.5773*0.0005;
|
||||
return normalize(e.xyy*map(pos + e.xyy).x +
|
||||
e.yyx*map(pos + e.yyx).x +
|
||||
e.yxy*map(pos + e.yxy).x +
|
||||
return normalize(e.xyy*map(pos + e.xyy).x +
|
||||
e.yyx*map(pos + e.yyx).x +
|
||||
e.yxy*map(pos + e.yxy).x +
|
||||
e.xxx*map(pos + e.xxx).x);
|
||||
}
|
||||
|
||||
@@ -174,15 +174,15 @@ float checkersGradBox(in vec2 p)
|
||||
// analytical integral (box filter)
|
||||
vec2 i = 2.0*(abs(fract((p-0.5*w)*0.5)-0.5)-abs(fract((p+0.5*w)*0.5)-0.5))/w;
|
||||
// xor pattern
|
||||
return 0.5 - 0.5*i.x*i.y;
|
||||
return 0.5 - 0.5*i.x*i.y;
|
||||
}
|
||||
|
||||
// https://www.shadertoy.com/view/tdS3DG
|
||||
vec4 render(in vec3 ro, in vec3 rd)
|
||||
{
|
||||
{
|
||||
// background
|
||||
vec3 col = vec3(0.7, 0.7, 0.9) - max(rd.y,0.0)*0.3;
|
||||
|
||||
|
||||
// raycast scene
|
||||
vec2 res = raycast(ro,rd);
|
||||
float t = res.x;
|
||||
@@ -192,11 +192,11 @@ vec4 render(in vec3 ro, in vec3 rd)
|
||||
vec3 pos = ro + t*rd;
|
||||
vec3 nor = (m<1.5) ? vec3(0.0,1.0,0.0) : calcNormal(pos);
|
||||
vec3 ref = reflect(rd, nor);
|
||||
|
||||
// material
|
||||
|
||||
// material
|
||||
col = 0.2 + 0.2*sin(m*2.0 + vec3(0.0,1.0,2.0));
|
||||
float ks = 1.0;
|
||||
|
||||
|
||||
if (m<1.5)
|
||||
{
|
||||
float f = checkersGradBox(3.0*pos.xz);
|
||||
@@ -206,7 +206,7 @@ vec4 render(in vec3 ro, in vec3 rd)
|
||||
|
||||
// lighting
|
||||
float occ = calcAO(pos, nor);
|
||||
|
||||
|
||||
vec3 lin = vec3(0.0);
|
||||
|
||||
// sun
|
||||
@@ -247,7 +247,7 @@ vec4 render(in vec3 ro, in vec3 rd)
|
||||
dif *= occ;
|
||||
lin += col*0.25*dif*vec3(1.00,1.00,1.00);
|
||||
}
|
||||
|
||||
|
||||
col = lin;
|
||||
|
||||
col = mix(col, vec3(0.7,0.7,0.9), 1.0-exp(-0.0001*t*t*t));
|
||||
|
||||
@@ -81,11 +81,11 @@ vec3 ComputePBR()
|
||||
{
|
||||
vec3 albedo = texture2D(albedoMap, vec2(fragTexCoord.x*tiling.x + offset.x, fragTexCoord.y*tiling.y + offset.y)).rgb;
|
||||
albedo = vec3(albedoColor.x*albedo.x, albedoColor.y*albedo.y, albedoColor.z*albedo.z);
|
||||
|
||||
|
||||
float metallic = clamp(metallicValue, 0.0, 1.0);
|
||||
float roughness = clamp(roughnessValue, 0.0, 1.0);
|
||||
float ao = clamp(aoValue, 0.0, 1.0);
|
||||
|
||||
|
||||
if (useTexMRA == 1)
|
||||
{
|
||||
vec4 mra = texture2D(mraMap, vec2(fragTexCoord.x*tiling.x + offset.x, fragTexCoord.y*tiling.y + offset.y));
|
||||
@@ -130,18 +130,18 @@ vec3 ComputePBR()
|
||||
vec3 F = SchlickFresnel(hDotV, baseRefl); // Fresnel proportion of specular reflectance
|
||||
|
||||
vec3 spec = (D*G*F)/(4.0*nDotV*nDotL);
|
||||
|
||||
|
||||
// Difuse and spec light can't be above 1.0
|
||||
// kD = 1.0 - kS diffuse component is equal 1.0 - spec comonent
|
||||
vec3 kD = vec3(1.0) - F;
|
||||
|
||||
|
||||
// Mult kD by the inverse of metallnes, only non-metals should have diffuse light
|
||||
kD *= 1.0 - metallic;
|
||||
lightAccum += ((kD*albedo.rgb/PI + spec)*radiance*nDotL)*float(lights[i].enabled); // Angle of light has impact on result
|
||||
}
|
||||
|
||||
|
||||
vec3 ambientFinal = (ambientColor + albedo)*ambient*0.5;
|
||||
|
||||
|
||||
return (ambientFinal + lightAccum*ao + emissive);
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ void main()
|
||||
|
||||
// HDR tonemapping
|
||||
color = pow(color, color + vec3(1.0));
|
||||
|
||||
|
||||
// Gamma correction
|
||||
color = pow(color, vec3(1.0/2.2));
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ void main()
|
||||
float bias = max(0.0008*(1.0 - dot(normal, l)), 0.00008);
|
||||
int shadowCounter = 0;
|
||||
const int numSamples = 9;
|
||||
|
||||
|
||||
// PCF (percentage-closer filtering) algorithm:
|
||||
// Instead of testing if just one point is closer to the current point,
|
||||
// we test the surrounding points as well
|
||||
@@ -72,7 +72,7 @@ void main()
|
||||
if (curDepth - bias > sampleDepth) shadowCounter++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
finalColor = mix(finalColor, vec4(0, 0, 0, 1), float(shadowCounter)/float(numSamples));
|
||||
|
||||
// Add ambient lighting whether in shadow or not
|
||||
|
||||
@@ -52,12 +52,12 @@ void main()
|
||||
float gray = GreyScale(cellColor);
|
||||
|
||||
int n = 4096;
|
||||
|
||||
|
||||
// Character set from https://www.shadertoy.com/view/lssGDj
|
||||
// Create new bitmaps https://thrill-project.com/archiv/coding/bitmap/
|
||||
if (gray > 0.2) n = 65600; // :
|
||||
if (gray > 0.3) n = 18725316; // v
|
||||
if (gray > 0.4) n = 15255086; // o
|
||||
if (gray > 0.4) n = 15255086; // o
|
||||
if (gray > 0.5) n = 13121101; // &
|
||||
if (gray > 0.6) n = 15252014; // 8
|
||||
if (gray > 0.7) n = 13195790; // @
|
||||
|
||||
@@ -20,7 +20,7 @@ void main()
|
||||
|
||||
// NOTE: Implement here your fragment shader code
|
||||
|
||||
// final color is the color from the texture
|
||||
// final color is the color from the texture
|
||||
// times the tint color (colDiffuse)
|
||||
// times the fragment color (interpolated vertex color)
|
||||
finalColor = texelColor*colDiffuse*fragColor;
|
||||
|
||||
@@ -14,7 +14,7 @@ out vec4 finalColor;
|
||||
void main()
|
||||
{
|
||||
vec4 texelColor = texture(texture0, fragTexCoord);
|
||||
|
||||
|
||||
finalColor = texelColor*colDiffuse*fragColor;
|
||||
gl_FragDepth = 1.0 - finalColor.z;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ uniform mat4 matProjection;
|
||||
void main()
|
||||
{
|
||||
vec4 worldPos = matModel*vec4(vertexPosition, 1.0);
|
||||
fragPosition = worldPos.xyz;
|
||||
fragPosition = worldPos.xyz;
|
||||
fragTexCoord = vertexTexCoord;
|
||||
|
||||
mat3 normalMatrix = transpose(inverse(mat3(matModel)));
|
||||
|
||||
@@ -16,7 +16,7 @@ out vec4 finalColor;
|
||||
void main()
|
||||
{
|
||||
vec4 texelColor = texture(texture0, fragTexCoord);
|
||||
|
||||
|
||||
finalColor = texelColor*colDiffuse*fragColor;
|
||||
gl_FragDepth = finalColor.z;
|
||||
}
|
||||
@@ -33,7 +33,7 @@ float sdHorseshoe(in vec3 p, in vec2 c, in float r, in float le, vec2 w)
|
||||
p.xy = mat2(-c.x, c.y, c.y, c.x)*p.xy;
|
||||
p.xy = vec2(((p.y > 0.0) || (p.x > 0.0))? p.x : l*sign(-c.x), (p.x>0.0)? p.y : l);
|
||||
p.xy = vec2(p.x, abs(p.y - r)) - vec2(le, 0.0);
|
||||
|
||||
|
||||
vec2 q = vec2(length(max(p.xy, 0.0)) + min(0.0, max(p.x, p.y)), p.z);
|
||||
vec2 d = abs(q) - w;
|
||||
return min(max(d.x, d.y), 0.0) + length(max(d, 0.0));
|
||||
@@ -54,7 +54,7 @@ float sdSixWayCutHollowSphere(vec3 p, float r, float h, float t)
|
||||
|
||||
vec2 q = vec2(length(ap.yz), ap.x);
|
||||
float w = sqrt(r*r-h*h);
|
||||
|
||||
|
||||
return ((h*q.x < w*q.y)? length(q - vec2(w, h)) : abs(length(q) - r)) - t;
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ vec2 map(in vec3 pos)
|
||||
{
|
||||
vec2 res = vec2(sdHorseshoe(pos - vec3(-1.0, 0.08, 1.0), vec2(cos(1.3), sin(1.3)), 0.2, 0.3, vec2(0.03,0.5)), 11.5);
|
||||
res = opU(res, vec2(sdSixWayCutHollowSphere(pos-vec3(0.0, 1.0, 0.0), 4.0, 3.5, 0.5), 4.5));
|
||||
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -105,8 +105,8 @@ vec2 raycast(in vec3 ro, in vec3 rd)
|
||||
if (t > tmax) break;
|
||||
vec2 h = map(ro + rd*t);
|
||||
if (abs(h.x )< (0.0001*t))
|
||||
{
|
||||
res = vec2(t, h.y);
|
||||
{
|
||||
res = vec2(t, h.y);
|
||||
break;
|
||||
}
|
||||
t += h.x;
|
||||
@@ -131,9 +131,9 @@ float calcSoftshadow(in vec3 ro, in vec3 rd, in float mint, in float tmax)
|
||||
t += clamp(h, 0.01, 0.2);
|
||||
if ((res < 0.004) || (t > tmax)) break;
|
||||
}
|
||||
|
||||
|
||||
res = clamp(res, 0.0, 1.0);
|
||||
|
||||
|
||||
return res*res*(3.0-2.0*res);
|
||||
}
|
||||
|
||||
@@ -141,9 +141,9 @@ float calcSoftshadow(in vec3 ro, in vec3 rd, in float mint, in float tmax)
|
||||
vec3 calcNormal(in vec3 pos)
|
||||
{
|
||||
vec2 e = vec2(1.0, -1.0)*0.5773*0.0005;
|
||||
return normalize(e.xyy*map(pos + e.xyy).x +
|
||||
e.yyx*map(pos + e.yyx).x +
|
||||
e.yxy*map(pos + e.yxy).x +
|
||||
return normalize(e.xyy*map(pos + e.xyy).x +
|
||||
e.yyx*map(pos + e.yyx).x +
|
||||
e.yxy*map(pos + e.yxy).x +
|
||||
e.xxx*map(pos + e.xxx).x);
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ float calcAO(in vec3 pos, in vec3 nor)
|
||||
sca *= 0.95;
|
||||
if (occ>0.35) break;
|
||||
}
|
||||
|
||||
|
||||
return clamp(1.0 - 3.0*occ, 0.0, 1.0)*(0.5+0.5*nor.y);
|
||||
}
|
||||
|
||||
@@ -172,15 +172,15 @@ float checkersGradBox(in vec2 p)
|
||||
// analytical integral (box filter)
|
||||
vec2 i = 2.0*(abs(fract((p - 0.5*w)*0.5)-0.5) - abs(fract((p + 0.5*w)*0.5) - 0.5))/w;
|
||||
// xor pattern
|
||||
return (0.5 - 0.5*i.x*i.y);
|
||||
return (0.5 - 0.5*i.x*i.y);
|
||||
}
|
||||
|
||||
// https://www.shadertoy.com/view/tdS3DG
|
||||
vec4 render(in vec3 ro, in vec3 rd)
|
||||
{
|
||||
{
|
||||
// background
|
||||
vec3 col = vec3(0.7, 0.7, 0.9) - max(rd.y,0.0)*0.3;
|
||||
|
||||
|
||||
// raycast scene
|
||||
vec2 res = raycast(ro,rd);
|
||||
float t = res.x;
|
||||
@@ -190,11 +190,11 @@ vec4 render(in vec3 ro, in vec3 rd)
|
||||
vec3 pos = ro + t*rd;
|
||||
vec3 nor = (m<1.5) ? vec3(0.0,1.0,0.0) : calcNormal(pos);
|
||||
vec3 ref = reflect(rd, nor);
|
||||
|
||||
// material
|
||||
|
||||
// material
|
||||
col = 0.2 + 0.2*sin(m*2.0 + vec3(0.0,1.0,2.0));
|
||||
float ks = 1.0;
|
||||
|
||||
|
||||
if (m < 1.5)
|
||||
{
|
||||
float f = checkersGradBox(3.0*pos.xz);
|
||||
@@ -204,7 +204,7 @@ vec4 render(in vec3 ro, in vec3 rd)
|
||||
|
||||
// lighting
|
||||
float occ = calcAO(pos, nor);
|
||||
|
||||
|
||||
vec3 lin = vec3(0.0);
|
||||
|
||||
// sun
|
||||
@@ -245,7 +245,7 @@ vec4 render(in vec3 ro, in vec3 rd)
|
||||
dif *= occ;
|
||||
lin += col*0.25*dif*vec3(1.00,1.00,1.00);
|
||||
}
|
||||
|
||||
|
||||
col = lin;
|
||||
|
||||
col = mix(col, vec3(0.7,0.7,0.9), 1.0-exp(-0.0001*t*t*t));
|
||||
@@ -285,7 +285,7 @@ void main()
|
||||
color = res.xyz;
|
||||
depth = CalcDepth(rd,res.w);
|
||||
}
|
||||
|
||||
|
||||
finalColor = vec4(color , 1.0);
|
||||
gl_FragDepth = depth;
|
||||
}
|
||||
@@ -24,7 +24,7 @@ void main()
|
||||
// to the palette index by scaling up from [0..1] to [0..255]
|
||||
int index = int(texelColor.r*255.0);
|
||||
ivec3 color = palette[index];
|
||||
|
||||
|
||||
//finalColor = texture(palette, texelColor.xy); // Alternative to ivec3
|
||||
|
||||
// Calculate final fragment color. Note that the palette color components
|
||||
|
||||
@@ -84,11 +84,11 @@ vec3 ComputePBR()
|
||||
{
|
||||
vec3 albedo = texture(albedoMap,vec2(fragTexCoord.x*tiling.x + offset.x, fragTexCoord.y*tiling.y + offset.y)).rgb;
|
||||
albedo = vec3(albedoColor.x*albedo.x, albedoColor.y*albedo.y, albedoColor.z*albedo.z);
|
||||
|
||||
|
||||
float metallic = clamp(metallicValue, 0.0, 1.0);
|
||||
float roughness = clamp(roughnessValue, 0.0, 1.0);
|
||||
float ao = clamp(aoValue, 0.0, 1.0);
|
||||
|
||||
|
||||
if (useTexMRA == 1)
|
||||
{
|
||||
vec4 mra = texture(mraMap, vec2(fragTexCoord.x*tiling.x + offset.x, fragTexCoord.y*tiling.y + offset.y));
|
||||
@@ -133,18 +133,18 @@ vec3 ComputePBR()
|
||||
vec3 F = SchlickFresnel(hDotV, baseRefl); // Fresnel proportion of specular reflectance
|
||||
|
||||
vec3 spec = (D*G*F)/(4.0*nDotV*nDotL);
|
||||
|
||||
|
||||
// Difuse and spec light can't be above 1.0
|
||||
// kD = 1.0 - kS diffuse component is equal 1.0 - spec comonent
|
||||
vec3 kD = vec3(1.0) - F;
|
||||
|
||||
|
||||
// Mult kD by the inverse of metallnes, only non-metals should have diffuse light
|
||||
kD *= 1.0 - metallic;
|
||||
lightAccum += ((kD*albedo.rgb/PI + spec)*radiance*nDotL)*lights[i].enabled; // Angle of light has impact on result
|
||||
}
|
||||
|
||||
|
||||
vec3 ambientFinal = (ambientColor + albedo)*ambient*0.5;
|
||||
|
||||
|
||||
return (ambientFinal + lightAccum*ao + emissive);
|
||||
}
|
||||
|
||||
@@ -154,7 +154,7 @@ void main()
|
||||
|
||||
// HDR tonemapping
|
||||
color = pow(color, color + vec3(1.0));
|
||||
|
||||
|
||||
// Gamma correction
|
||||
color = pow(color, vec3(1.0/2.2));
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ uniform mat4 mvp;
|
||||
uniform mat4 matModel;
|
||||
uniform mat4 matNormal;
|
||||
|
||||
uniform float time;
|
||||
uniform float time;
|
||||
|
||||
uniform sampler2D perlinNoiseMap;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user