+ | 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

@ -7,7 +7,7 @@ Pos=1645,8
Size=259,200
[Window][Material]
Pos=1638,215
Pos=1648,211
Size=262,299
[Window][Fog settings]

View File

@ -40,10 +40,9 @@ struct GPUTriangle
alignas(16) glm::vec3 vertex2;
alignas(16) glm::vec3 normal;
glm::vec2 texture_vertex1;
glm::vec2 texture_vertex2;
glm::vec2 texture_vertex3;
alignas(8) glm::vec2 texture_vertex1;
alignas(8) glm::vec2 texture_vertex2;
alignas(8) glm::vec2 texture_vertex3;
int mat_index;
};

View File

@ -83,7 +83,6 @@ class Triangle : public Object
glm::vec2 _texture_vertex2;
glm::vec2 _texture_vertex3;
glm::vec3 _normal;
glm::vec3 _centroid;

View File

@ -17,9 +17,8 @@ MAT 255 255 255 0.0 0.0 0.0 TRN // glass 8
pl 0 0 0 0 1 0 2 // floor
# pl 0 5 0 0 -1 0 5
OBJ obj/tails.obj 0 0 0 1
# OBJ obj/Lowpoly_tree_sample.obj 10 0 0
OBJ scenes/obj/tails.obj 0 0 0 1
OBJ scenes/obj/Lowpoly_tree_sample.obj 10 0 0
# OBJ obj/Dragon_8K.obj 0 0.38 1 1
# OBJ obj/Dragon_8K.obj 0 0.38 2 1

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;

View File

@ -116,10 +116,6 @@ void Scene::addObject(Object *obj)
gpu_triangle.vertex2 = triangle->getVertex3();
gpu_triangle.normal = triangle->getNormal();
gpu_triangle.texture_vertex1 = triangle->getTextureVertex1();
gpu_triangle.texture_vertex2 = triangle->getTextureVertex1();
gpu_triangle.texture_vertex3 = triangle->getTextureVertex1();
_gpu_triangles.push_back(gpu_triangle);
gpu_obj.vertex1 = triangle->getVertex2();