fixes
This commit is contained in:
39
shader.glsl
39
shader.glsl
@ -3,16 +3,6 @@ uniform vec2 resolution;
|
||||
uniform sampler2D texture_sampler;
|
||||
uniform sampler2D texts;
|
||||
|
||||
#define MAX_STEPS 100
|
||||
#define MAX_DIST 20.
|
||||
#define SURF_DIST .001
|
||||
#define TAU 6.283185
|
||||
#define PI 3.141592
|
||||
|
||||
#define FOG_DENSITY 0.01
|
||||
|
||||
|
||||
|
||||
struct Obj {
|
||||
float distance; // distance map
|
||||
int material; // material Id
|
||||
@ -25,8 +15,7 @@ mat2 Rot(float a) {
|
||||
}
|
||||
|
||||
vec3 applyFog(in vec3 color, in float distance) {
|
||||
|
||||
float fogAmount = 1.0 - exp(-distance*FOG_DENSITY);
|
||||
float fogAmount = 1.0 - exp(-distance *0.01);
|
||||
vec3 fogColor = vec3(0.17, 0.16, 0.24);
|
||||
return mix( color, fogColor, fogAmount );
|
||||
}
|
||||
@ -95,13 +84,13 @@ Obj castRay(vec3 ro, vec3 rd) {
|
||||
float t = 0.0;
|
||||
|
||||
Obj res = Obj(-1., -1);
|
||||
for(int i=0; i<MAX_STEPS; i++) {
|
||||
for(int i=0; i<100; i++) {
|
||||
vec3 p = ro + rd * t;
|
||||
res = mapScene(p);
|
||||
t += res.distance;
|
||||
if (t > MAX_DIST || res.distance < abs(SURF_DIST*t) ) break;
|
||||
if (t > 20.0 || res.distance < abs(0.001*t) ) break;
|
||||
}
|
||||
if (t > MAX_DIST) t = -1.0;
|
||||
if (t > 20.0) t = -1.0;
|
||||
res.distance = t;
|
||||
return res;
|
||||
}
|
||||
@ -109,7 +98,7 @@ Obj castRay(vec3 ro, vec3 rd) {
|
||||
float castShadow(vec3 ro, vec3 rd) {
|
||||
float res = 1.0;
|
||||
float t = 0.001;
|
||||
for(int i = 0; i < MAX_STEPS; i++) {
|
||||
for(int i = 0; i < 100; i++) {
|
||||
vec3 pos = ro + t* rd;
|
||||
float h = mapScene(pos).distance;
|
||||
res = min(res, 10.0*h/t);
|
||||
@ -191,23 +180,16 @@ vec3 shading(vec3 v, vec3 n, vec3 dir, int material) {
|
||||
float sun_dif = clamp(dot(n, SUN_DIR), 0., 1.);
|
||||
final += outMaterial * vec3(0.0353, 0.2667, 0.4784) * sun_dif;
|
||||
}
|
||||
// final += texture( iChannel0, ref ).rgb * fresnel( Ks, n, -dir );
|
||||
// vec3 col = vec3(0.4)* ref.x;
|
||||
//vec3 col = vec3(0.0588, 0.0588, 0.1216);// - vec3(0.149, 0.0863, 0.2314) * v.x;
|
||||
//final += col * fresnel( vec3(.5), ref, -dir );
|
||||
|
||||
return final;
|
||||
return final;
|
||||
}
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 p = (2.0 * gl_FragCoord.xy - resolution.xy) / resolution.y;
|
||||
vec2 p = (gl_FragCoord.xy * 2. - resolution.xy) / min(resolution.x, resolution.y);
|
||||
// vec2 p = (2.0 * gl_FragCoord.xy - resolution.xy) / resolution.y;
|
||||
float angle = time*0.4;
|
||||
// angle = 2.0; // comment to rotate
|
||||
// gl_FragColor = vec4(vec3(sdCog2d(p)), 1.);
|
||||
// return;
|
||||
// camera
|
||||
vec3 ta = vec3(0.0, 0., 0.0);
|
||||
vec3 ro = ta + vec3(4.*sin(angle), cos(angle), 4.*cos(angle)); // *cos(angle))
|
||||
|
||||
@ -227,7 +209,6 @@ void main()
|
||||
col = shading(pos, nor, rd , t.material);
|
||||
// apply fog
|
||||
col = applyFog(col, t.distance);
|
||||
}
|
||||
|
||||
gl_FragColor = vec4( pow( col, vec3(1.0/1.3) ), 1.0 );
|
||||
}
|
||||
gl_FragColor = vec4( pow(col, vec3(1.0/1.3) ), 1.0 );
|
||||
}
|
||||
Reference in New Issue
Block a user