+ | Texture working

This commit is contained in:
TheRedShip
2025-01-28 22:09:27 +01:00
parent 8466e672f6
commit ae83d7d9f1
8 changed files with 10 additions and 17 deletions

View File

@ -118,7 +118,6 @@ layout(std430, binding = 6) buffer LightsBuffer
layout(std140, binding = 0) uniform CameraData
{
GPUCamera camera;

View File

@ -101,19 +101,18 @@ vec2 getSphereUV(vec3 surfacePoint)
return vec2(u, v);
}
uniform sampler2D textures[16];
uniform sampler2D textures[32];
vec3 getTextureColor(int texture_index, hitInfo hit)
{
GPUTriangle tri = triangles[hit.obj_index];
vec2 uv = hit.u * tri.texture_vertex2 + hit.v * tri.texture_vertex3 + (1 - (hit.u + hit.v)) * tri.texture_vertex1;
return vec3(uv, 0.);
return (texture(textures[texture_index], uv).rgb);
}
void calculateLightColor(GPUMaterial mat, hitInfo hit, inout vec3 color, inout vec3 light, inout uint rng_state)
{
color *= mat.texture_index;
if (mat.texture_index != -1)
color *= getTextureColor(mat.texture_index, hit);

View File

@ -146,6 +146,8 @@ hitInfo traverseBVHs(Ray ray)
if (temp_hit.t < hit.t)
{
hit.u = temp_hit.u;
hit.v = temp_hit.v;
hit.t = temp_hit.t;
hit.last_t = temp_hit.last_t / bvh_data.scale;
hit.obj_index = temp_hit.obj_index;