changed brick texture from being 32x32x32 1D to 32x32x32 2D (smaller indexes)

This commit is contained in:
Piotrek
2021-04-26 14:01:13 +02:00
parent 1bb45ec31b
commit 6206800df9
7 changed files with 44 additions and 27 deletions
Binary file not shown.
+8 -4
View File
@@ -20,7 +20,11 @@ HitResult castBricks(vec3 origin, vec3 start, vec3 dir, vec3 incAxis, uint addr)
vec3 rayInv = 1.0/dir;
vec3 raySign = sign(dir);
vec3 dist = (pos-origin+0.5 + raySign*0.5) * rayInv;
ivec3 offset = ivec3(0, 0, (addr-1)*32);
// Calculate offset
uint y = (addr-1) % BLOCK_TEX_SIZE * BLOCK_SIZE;
uint z = (addr-1) / BLOCK_TEX_SIZE * BLOCK_SIZE;
ivec3 offset = ivec3(0, y, z);
for(int i=0;i<110;i++)
{
@@ -45,7 +49,7 @@ HitResult castBricks(vec3 origin, vec3 start, vec3 dir, vec3 incAxis, uint addr)
// Check for bounds
if(pos.x < 0 || pos.y < 0 || pos.z < 0) { break; }
if(pos.x > 31 || pos.y > 31 || pos.z > 31) { break; }
if(pos.x >= BLOCK_SIZE || pos.y >= BLOCK_SIZE || pos.z >= BLOCK_SIZE) { break; }
}
return HitResult(0, vec3(0,0,0), vec3(0,0,0));
@@ -92,8 +96,8 @@ HitResult castNodes(Ray ray, uint maxSteps)
pos += incAxis * raySign;
// Outside bounds
//if(pos.x < 0 || pos.y < 0 || pos.z < 0) { break; }
// if(pos.x > 1 || pos.y > 1 || pos.z > 1) { break; }
if(pos.x < 0 || pos.y < 0 || pos.z < 0) { break; }
if(pos.x >= BLOCK_TEX_SIZE || pos.y > BLOCK_TEX_SIZE || pos.z >= NODE_TEX_SIZE) { break; }
}
// Not found
+6 -4
View File
@@ -24,9 +24,11 @@ layout(set=3, binding=0) uniform Materials {
};
// Defines
// #define PI 3.141592
// #define EPSILON 0.01
// #define NEAR 0.01
#define EPSILON 0.00000001
#define NODE_TEX_SIZE 32
#define BLOCK_TEX_SIZE 64
#define BLOCK_SIZE 32
// Include
#include "structs.cginc"
@@ -66,7 +68,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.00000001;
vec3 hitPos = primary.pos-primary.normal*EPSILON;
// Shadow ray
Ray shadowRay = Ray(hitPos, _SunDir);