renamed brick to block, world gen stuff in separate file

This commit is contained in:
Piotrek
2021-04-25 16:22:24 +02:00
parent 9718ea68dd
commit 1bb45ec31b
15 changed files with 223 additions and 220 deletions
Binary file not shown.
+6 -5
View File
@@ -2,7 +2,8 @@
#version 450
struct Material {
vec4 albedo;
vec3 albedo;
float specular;
};
// Variables
@@ -65,7 +66,7 @@ vec3 solve()
if(primary.data > 0)
{
vec3 color = applyLighting(primary.pos, primaryRay.dir, primary.normal, primary.data);
vec3 hitPos = primary.pos-primaryRay.dir*0.000001;
vec3 hitPos = primary.pos-primaryRay.dir*0.00000001;
// Shadow ray
Ray shadowRay = Ray(hitPos, _SunDir);
@@ -73,9 +74,9 @@ vec3 solve()
if(shadow.data > 0) color *= 0.1;
// Secondary ray
Ray secondRay = Ray(hitPos, randomHemisphere(primary.normal));
HitResult second = castNodes(secondRay, 25);
if(second.data > 0) color += getAlbedo(second.data) * 0.8;
// Ray secondRay = Ray(hitPos, randomHemisphere(primary.normal));
// HitResult second = castNodes(secondRay, 25);
// if(second.data > 0) color += getAlbedo(second.data) * 0.8;
return color;
}
+9 -9
View File
@@ -1,10 +1,8 @@
/*
* Returns material albedo for given voxel
*/
vec3 getAlbedo(uint data)
{
return _Materials[data-1].albedo.rgb;
}
vec3 getAlbedo(uint data) { return _Materials[data-1].albedo.rgb; }
float getSpecular(uint data) { return _Materials[data-1].specular; }
/*
point: Hit point
@@ -14,12 +12,14 @@ vec3 getAlbedo(uint data)
vec3 applyLighting(vec3 hitPoint, vec3 view, vec3 normal, uint data)
{
// Lighting
vec3 light_color = vec3(1);
vec3 ambientColor = vec3(0.9, 0.9, 1.0);
vec3 ambient = ambientColor * 0.05;
vec3 sky = ambientColor * 0.1 * max(normal.y, 0);
vec3 ambient = light_color * 0.1;
vec3 diffuse = light_color * max(1.0-dot(normal, _SunDir), 0.0);
vec3 specular = light_color * pow(max(dot(view, reflect(_SunDir, normal)), 0.0), 32);
vec3 sunColor = vec3(1.0, 1.0, 0.9);
vec3 diffuse = sunColor * max(1.0-dot(normal, _SunDir), 0.0);
vec3 specular = sunColor * getSpecular(data) * pow(max(dot(view, reflect(_SunDir, normal)), 0.0), 32);
// Combine colors
return (ambient + diffuse + specular) * getAlbedo(data);
return (ambient + sky + diffuse + specular) * getAlbedo(data);
}
-14
View File
@@ -1,14 +0,0 @@
float sdSphere(in vec3 pos)
{
return length(pos) - 1.0;
}
float sdPlane(in vec3 pos)
{
return pos.y;
}
vec2 sdUnion(vec2 a, vec2 b)
{
return (a.x < b.x) ? a : b;
}