mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 10:48:34 +02:00
+ | Texture working
This commit is contained in:
@ -7,7 +7,7 @@ Pos=1645,8
|
|||||||
Size=259,200
|
Size=259,200
|
||||||
|
|
||||||
[Window][Material]
|
[Window][Material]
|
||||||
Pos=1638,215
|
Pos=1648,211
|
||||||
Size=262,299
|
Size=262,299
|
||||||
|
|
||||||
[Window][Fog settings]
|
[Window][Fog settings]
|
||||||
|
@ -40,10 +40,9 @@ struct GPUTriangle
|
|||||||
alignas(16) glm::vec3 vertex2;
|
alignas(16) glm::vec3 vertex2;
|
||||||
alignas(16) glm::vec3 normal;
|
alignas(16) glm::vec3 normal;
|
||||||
|
|
||||||
glm::vec2 texture_vertex1;
|
alignas(8) glm::vec2 texture_vertex1;
|
||||||
glm::vec2 texture_vertex2;
|
alignas(8) glm::vec2 texture_vertex2;
|
||||||
glm::vec2 texture_vertex3;
|
alignas(8) glm::vec2 texture_vertex3;
|
||||||
|
|
||||||
|
|
||||||
int mat_index;
|
int mat_index;
|
||||||
};
|
};
|
||||||
|
@ -83,7 +83,6 @@ class Triangle : public Object
|
|||||||
glm::vec2 _texture_vertex2;
|
glm::vec2 _texture_vertex2;
|
||||||
glm::vec2 _texture_vertex3;
|
glm::vec2 _texture_vertex3;
|
||||||
|
|
||||||
|
|
||||||
glm::vec3 _normal;
|
glm::vec3 _normal;
|
||||||
|
|
||||||
glm::vec3 _centroid;
|
glm::vec3 _centroid;
|
||||||
|
@ -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 0 0 0 1 0 2 // floor
|
||||||
# pl 0 5 0 0 -1 0 5
|
# pl 0 5 0 0 -1 0 5
|
||||||
|
|
||||||
|
OBJ scenes/obj/tails.obj 0 0 0 1
|
||||||
OBJ obj/tails.obj 0 0 0 1
|
OBJ scenes/obj/Lowpoly_tree_sample.obj 10 0 0
|
||||||
# OBJ 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 1 1
|
||||||
# OBJ obj/Dragon_8K.obj 0 0.38 2 1
|
# OBJ obj/Dragon_8K.obj 0 0.38 2 1
|
||||||
|
@ -118,7 +118,6 @@ layout(std430, binding = 6) buffer LightsBuffer
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
layout(std140, binding = 0) uniform CameraData
|
layout(std140, binding = 0) uniform CameraData
|
||||||
{
|
{
|
||||||
GPUCamera camera;
|
GPUCamera camera;
|
||||||
|
@ -101,19 +101,18 @@ vec2 getSphereUV(vec3 surfacePoint)
|
|||||||
return vec2(u, v);
|
return vec2(u, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
uniform sampler2D textures[16];
|
uniform sampler2D textures[32];
|
||||||
|
|
||||||
vec3 getTextureColor(int texture_index, hitInfo hit)
|
vec3 getTextureColor(int texture_index, hitInfo hit)
|
||||||
{
|
{
|
||||||
GPUTriangle tri = triangles[hit.obj_index];
|
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;
|
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);
|
return (texture(textures[texture_index], uv).rgb);
|
||||||
}
|
}
|
||||||
|
|
||||||
void calculateLightColor(GPUMaterial mat, hitInfo hit, inout vec3 color, inout vec3 light, inout uint rng_state)
|
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)
|
if (mat.texture_index != -1)
|
||||||
color *= getTextureColor(mat.texture_index, hit);
|
color *= getTextureColor(mat.texture_index, hit);
|
||||||
|
|
||||||
|
@ -146,6 +146,8 @@ hitInfo traverseBVHs(Ray ray)
|
|||||||
|
|
||||||
if (temp_hit.t < hit.t)
|
if (temp_hit.t < hit.t)
|
||||||
{
|
{
|
||||||
|
hit.u = temp_hit.u;
|
||||||
|
hit.v = temp_hit.v;
|
||||||
hit.t = temp_hit.t;
|
hit.t = temp_hit.t;
|
||||||
hit.last_t = temp_hit.last_t / bvh_data.scale;
|
hit.last_t = temp_hit.last_t / bvh_data.scale;
|
||||||
hit.obj_index = temp_hit.obj_index;
|
hit.obj_index = temp_hit.obj_index;
|
||||||
|
@ -116,10 +116,6 @@ void Scene::addObject(Object *obj)
|
|||||||
gpu_triangle.vertex2 = triangle->getVertex3();
|
gpu_triangle.vertex2 = triangle->getVertex3();
|
||||||
gpu_triangle.normal = triangle->getNormal();
|
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_triangles.push_back(gpu_triangle);
|
||||||
|
|
||||||
gpu_obj.vertex1 = triangle->getVertex2();
|
gpu_obj.vertex1 = triangle->getVertex2();
|
||||||
|
Reference in New Issue
Block a user