post process

This commit is contained in:
2024-05-29 20:58:47 +03:00
parent 579a7693ed
commit 1b95e62d9e

View File

@ -575,6 +575,11 @@ float fOpTongue(float a, float b, float ra, float rb) {
//#endSection End of library
// https://stackoverflow.com/questions/4200224/random-noise-functions-for-glsl
// golden_noise
float noise(in vec2 xy, in float seed){
return fract(tan(distance(xy*PHI, xy)*seed)*xy.x);
}
mat2 Rot(float a) {
float s=sin(a), c=cos(a);
@ -684,17 +689,17 @@ vec3 shading(vec3 v, vec3 n, vec3 dir, float material) {
vec3 outMaterial = vec3(0.1686, 0.1686, 0.1686);
if (material == 0.) {
outMaterial = vec3(0.1412, 0.1412, 0.1412);
shininess = 11.1;
outMaterial = vec3(0.1608, 0.1255, 0.1255);
shininess = 1.;
} else if (material == 1.) {
outMaterial = vec3(0.1765, 1.1961, 0.2275);
shininess = 31.;
outMaterial = vec3(0.2039, 0.2431, 0.3137);
shininess = 16.;
} else if (material == 2.) {
outMaterial = vec3(1.1765, 0.1961, 0.2275);
shininess = 21.;
outMaterial = vec3(0.0941, 0.102, 0.1137);
shininess = 16.;
} else if (material == 3.) {
outMaterial = vec3(0.1765, 0.1961, 1.2275);
shininess = 21.;
outMaterial = vec3(0.1569, 0.1922, 0.2549);
shininess = 16.;
}
// light 0
@ -746,11 +751,18 @@ vec3 shading(vec3 v, vec3 n, vec3 dir, float material) {
return final;
}
vec3 postProcess(vec3 pos, vec3 col) {
float random = noise(gl_FragCoord.xy, 0.01+u_time);
float random2 = noise(gl_FragCoord.xy, .2+u_time);
col += clamp(vec3(0.5*random, 0.5*random2, 0.*random), 0.02, 1.)*0.05; // dither / noise
col = pow( col, vec3(1.0/1.3) ); // gamma
return col;
}
void main()
{
vec2 p = (2.0 * gl_FragCoord.xy - u_resolution.xy) / u_resolution.y;
float angle = u_time*0.4;
float angle = -0.4 +u_time*0.4;
// camera
vec3 ta = vec3(0.0, 0., 1.0);
vec3 ro = ta + vec3(4.*sin(angle), cos(angle), 4.*cos(angle)); // *cos(angle))
@ -758,19 +770,20 @@ void main()
vec3 ww = normalize(ta-ro);
vec3 uu = normalize(cross(ww, vec3(0.,1.0, 0.))); // vec3 = pitch, yaw, pan
vec3 vv = normalize(cross(uu,ww));
vec3 rd = normalize(p.x * uu + p.y*vv + ww * 2.0); // camera
vec3 rd = normalize(p.x * uu + p.y*vv + ww * 1.8); // camera
// global light
vec3 col = vec3(0.1451, 0.1098, 0.1608) - vec3(0.9725, 0.5176, 0.0) *rd.y;
vec2 t = castRay(ro, rd);
if (t.x > 0.) {
vec3 pos = ro + rd * t.x;
vec3 pos = ro + rd * t.x;
if (t.x > 0.) {
vec3 nor = calcNormal(pos);
col = shading(pos, nor, rd , t.y);
// apply fog
col = applyFog(col, t.x);
}
gl_FragColor = vec4( pow( col, vec3(1.0/1.3) ), 1.0 );
col = applyFog(col, t.x);
}
col = postProcess(pos, col);
gl_FragColor = vec4( col , 1.0 );
}