fix: changes inf ray behaviour for better sky rendering
This commit is contained in:
21
sdf.glsl
21
sdf.glsl
@@ -28,7 +28,7 @@ struct Ray {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Ray createRay(vec3 dir, vec3 pos){
|
Ray createRay(vec3 dir, vec3 pos){
|
||||||
return Ray(dir, pos, .0, .0, SmallHit(80.,0.,false), vec3(.0));
|
return Ray(dir, pos, .0, .0, SmallHit(80.,0.,false), vec3(1.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ray applyMin(Ray ray, float min) {
|
Ray applyMin(Ray ray, float min) {
|
||||||
@@ -52,11 +52,11 @@ Ray applyMin(Ray ray, float min) {
|
|||||||
|
|
||||||
|
|
||||||
float planeMin(vec3 pos){
|
float planeMin(vec3 pos){
|
||||||
return pos.y - planeHeight;
|
return pos.y - planeHeight+ 0.2*sin(5*pos.x+t)*sin(5*pos.y+t)*sin(5*pos.z+t);
|
||||||
}
|
}
|
||||||
|
|
||||||
float sphereMin(vec3 pos){
|
float sphereMin(vec3 pos){
|
||||||
return length(pos - center) - radius + 0.2*sin(5*pos.x+t)*sin(5*pos.y+t)*sin(5*pos.z+t);
|
return length(pos - center) - radius;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ray minFn(Ray ray){
|
Ray minFn(Ray ray){
|
||||||
@@ -88,11 +88,13 @@ Ray march(Ray ray){
|
|||||||
//ray.min = minFn(ray.pos);
|
//ray.min = minFn(ray.pos);
|
||||||
ray = minFn(ray);
|
ray = minFn(ray);
|
||||||
int c = 0;
|
int c = 0;
|
||||||
while(( c < 200) && (ray.min < 100.0f) && (ray.min > 0.01f) ) {
|
while(( c < 1000) && (ray.min < 100.0f) && (ray.min > 0.01f) ) {
|
||||||
ray = minFn(ray);
|
ray = minFn(ray);
|
||||||
c++;
|
c++;
|
||||||
}
|
}
|
||||||
|
if(ray.min > 0.01){
|
||||||
|
ray.color = vec3(1.0);
|
||||||
|
}
|
||||||
return ray;
|
return ray;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,11 +144,14 @@ void main()
|
|||||||
|
|
||||||
light *= shLeve;
|
light *= shLeve;
|
||||||
|
|
||||||
|
Ray reflectR = createRay(reflect(ray.dir,normal),ray.pos + 0.1* normal);
|
||||||
|
reflectR = march(reflectR);
|
||||||
|
|
||||||
if(ray.min <= 0.2){
|
if(ray.min <= 0.2){
|
||||||
//FragColor = vec4(vec3(shRay.small.min)*0.1,1.0);
|
//FragColor = vec4(0,1,0,1.0);
|
||||||
FragColor = vec4(ray.color * (light+0.3), 1.0);
|
FragColor = vec4(mix(ray.color,reflectR.color,0.3) * (light+0.3), 1.0);
|
||||||
} else {
|
} else {
|
||||||
FragColor = vec4(.0,0.0,0.0,1.0);
|
FragColor = vec4(ray.color,1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user