mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 10:48:34 +02:00
+ | Texture working finally !
This commit is contained in:
BIN
scenes/obj/Cat_diffuse.jpg
Normal file
BIN
scenes/obj/Cat_diffuse.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 39 KiB |
15
scenes/obj/cat.mtl
Normal file
15
scenes/obj/cat.mtl
Normal file
@ -0,0 +1,15 @@
|
||||
# 3ds Max Wavefront OBJ Exporter v0.97b - (c)2007 guruware
|
||||
# File Created: 20.12.2011 11:12:50
|
||||
|
||||
newmtl Cat
|
||||
Ns 10.0000
|
||||
Ni 1.5000
|
||||
d 1.0000
|
||||
Tr 0.0000
|
||||
Tf 1.0000 1.0000 1.0000
|
||||
illum 2
|
||||
Ka 1.0000 1.0000 1.0000
|
||||
Kd 1.0000 1.0000 1.0000
|
||||
Ks 0.0000 0.0000 0.0000
|
||||
Ke 0.0000 0.0000 0.0000
|
||||
map_Kd Cat_diffuse.jpg
|
142137
scenes/obj/cat.obj
Normal file
142137
scenes/obj/cat.obj
Normal file
File diff suppressed because it is too large
Load Diff
@ -11,174 +11,3 @@ newmtl Material
|
||||
d 1
|
||||
Tr 0
|
||||
map_Kd Material_baseColor.png
|
||||
newmtl Material
|
||||
illum 2
|
||||
Kd 1 1 1
|
||||
Ke 0 0 0
|
||||
Pr 0.80404085
|
||||
Pm 0
|
||||
d 1
|
||||
Tr 0
|
||||
map_Kd Material_baseColor.png
|
||||
newmtl Material
|
||||
illum 2
|
||||
Kd 1 1 1
|
||||
Ke 0 0 0
|
||||
Pr 0.80404085
|
||||
Pm 0
|
||||
d 1
|
||||
Tr 0
|
||||
map_Kd Material_baseColor.png
|
||||
newmtl Material
|
||||
illum 2
|
||||
Kd 1 1 1
|
||||
Ke 0 0 0
|
||||
Pr 0.80404085
|
||||
Pm 0
|
||||
d 1
|
||||
Tr 0
|
||||
map_Kd Material_baseColor.png
|
||||
newmtl Material
|
||||
illum 2
|
||||
Kd 1 1 1
|
||||
Ke 0 0 0
|
||||
Pr 0.80404085
|
||||
Pm 0
|
||||
d 1
|
||||
Tr 0
|
||||
map_Kd Material_baseColor.png
|
||||
newmtl Material
|
||||
illum 2
|
||||
Kd 1 1 1
|
||||
Ke 0 0 0
|
||||
Pr 0.80404085
|
||||
Pm 0
|
||||
d 1
|
||||
Tr 0
|
||||
map_Kd Material_baseColor.png
|
||||
newmtl Material
|
||||
illum 2
|
||||
Kd 1 1 1
|
||||
Ke 0 0 0
|
||||
Pr 0.80404085
|
||||
Pm 0
|
||||
d 1
|
||||
Tr 0
|
||||
map_Kd Material_baseColor.png
|
||||
newmtl Material
|
||||
illum 2
|
||||
Kd 1 1 1
|
||||
Ke 0 0 0
|
||||
Pr 0.80404085
|
||||
Pm 0
|
||||
d 1
|
||||
Tr 0
|
||||
map_Kd Material_baseColor.png
|
||||
newmtl Material
|
||||
illum 2
|
||||
Kd 1 1 1
|
||||
Ke 0 0 0
|
||||
Pr 0.80404085
|
||||
Pm 0
|
||||
d 1
|
||||
Tr 0
|
||||
map_Kd Material_baseColor.png
|
||||
newmtl Material
|
||||
illum 2
|
||||
Kd 1 1 1
|
||||
Ke 0 0 0
|
||||
Pr 0.80404085
|
||||
Pm 0
|
||||
d 1
|
||||
Tr 0
|
||||
map_Kd Material_baseColor.png
|
||||
newmtl Material
|
||||
illum 2
|
||||
Kd 1 1 1
|
||||
Ke 0 0 0
|
||||
Pr 0.80404085
|
||||
Pm 0
|
||||
d 1
|
||||
Tr 0
|
||||
map_Kd Material_baseColor.png
|
||||
newmtl Material
|
||||
illum 2
|
||||
Kd 1 1 1
|
||||
Ke 0 0 0
|
||||
Pr 0.80404085
|
||||
Pm 0
|
||||
d 1
|
||||
Tr 0
|
||||
map_Kd Material_baseColor.png
|
||||
newmtl Material
|
||||
illum 2
|
||||
Kd 1 1 1
|
||||
Ke 0 0 0
|
||||
Pr 0.80404085
|
||||
Pm 0
|
||||
d 1
|
||||
Tr 0
|
||||
map_Kd Material_baseColor.png
|
||||
newmtl Material
|
||||
illum 2
|
||||
Kd 1 1 1
|
||||
Ke 0 0 0
|
||||
Pr 0.80404085
|
||||
Pm 0
|
||||
d 1
|
||||
Tr 0
|
||||
map_Kd Material_baseColor.png
|
||||
newmtl Material
|
||||
illum 2
|
||||
Kd 1 1 1
|
||||
Ke 0 0 0
|
||||
Pr 0.80404085
|
||||
Pm 0
|
||||
d 1
|
||||
Tr 0
|
||||
map_Kd Material_baseColor.png
|
||||
newmtl Material
|
||||
illum 2
|
||||
Kd 1 1 1
|
||||
Ke 0 0 0
|
||||
Pr 0.80404085
|
||||
Pm 0
|
||||
d 1
|
||||
Tr 0
|
||||
map_Kd Material_baseColor.png
|
||||
newmtl Material
|
||||
illum 2
|
||||
Kd 1 1 1
|
||||
Ke 0 0 0
|
||||
Pr 0.80404085
|
||||
Pm 0
|
||||
d 1
|
||||
Tr 0
|
||||
map_Kd Material_baseColor.png
|
||||
newmtl Material
|
||||
illum 2
|
||||
Kd 1 1 1
|
||||
Ke 0 0 0
|
||||
Pr 0.80404085
|
||||
Pm 0
|
||||
d 1
|
||||
Tr 0
|
||||
map_Kd Material_baseColor.png
|
||||
newmtl Material
|
||||
illum 2
|
||||
Kd 1 1 1
|
||||
Ke 0 0 0
|
||||
Pr 0.80404085
|
||||
Pm 0
|
||||
d 1
|
||||
Tr 0
|
||||
map_Kd Material_baseColor.png
|
||||
newmtl Material
|
||||
illum 2
|
||||
Kd 1 1 1
|
||||
Ke 0 0 0
|
||||
Pr 0.80404085
|
||||
Pm 0
|
||||
d 1
|
||||
Tr 0
|
||||
map_Kd Material_baseColor.png
|
||||
|
1131
scenes/test.rt
1131
scenes/test.rt
File diff suppressed because it is too large
Load Diff
@ -150,8 +150,10 @@ struct hitInfo
|
||||
float last_t;
|
||||
vec3 normal;
|
||||
vec3 position;
|
||||
|
||||
int obj_index;
|
||||
int mat_index;
|
||||
int obj_type;
|
||||
|
||||
float u;
|
||||
float v;
|
||||
|
@ -105,8 +105,15 @@ 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;
|
||||
vec2 uv = vec2(0.0);
|
||||
|
||||
if (hit.obj_type == 0)
|
||||
uv = getSphereUV(hit.normal);
|
||||
else if (hit.obj_type == 3)
|
||||
{
|
||||
GPUTriangle tri = triangles[hit.obj_index];
|
||||
uv = hit.u * tri.texture_vertex2 + hit.v * tri.texture_vertex3 + (1 - (hit.u + hit.v)) * tri.texture_vertex1;
|
||||
}
|
||||
|
||||
return (texture(textures[texture_index], uv).rgb);
|
||||
}
|
||||
|
@ -45,6 +45,7 @@ hitInfo traceScene(Ray ray)
|
||||
hit.t = temp_hit.t;
|
||||
hit.last_t = temp_hit.last_t;
|
||||
hit.obj_index = i;
|
||||
hit.obj_type = obj.type;
|
||||
hit.mat_index = obj.mat_index;
|
||||
hit.position = temp_hit.position;
|
||||
hit.normal = temp_hit.normal;
|
||||
@ -152,6 +153,7 @@ hitInfo traverseBVHs(Ray ray)
|
||||
hit.last_t = temp_hit.last_t / bvh_data.scale;
|
||||
hit.obj_index = temp_hit.obj_index;
|
||||
hit.mat_index = temp_hit.mat_index;
|
||||
hit.obj_type = 3;
|
||||
hit.position = inverseTransformMatrix * temp_hit.position + bvh_data.offset;
|
||||
hit.normal = normalize(inverseTransformMatrix * temp_hit.normal);
|
||||
}
|
||||
|
@ -228,7 +228,7 @@ void Scene::loadTextures()
|
||||
unsigned char* image = stbi_load(path.c_str(), &width, &height, &channels, STBI_rgb_alpha);
|
||||
|
||||
if (!image)
|
||||
throw std::runtime_error("Failed to load texture");
|
||||
throw std::runtime_error("Failed to load texture " + path);
|
||||
|
||||
std::cout << "Loaded texture: " << path << " (" << width << "x" << height << ")" << std::endl;
|
||||
|
||||
|
@ -67,7 +67,7 @@ Shader::Shader(std::string vertexPath, std::string fragmentPath, std::string com
|
||||
const char *fragmentCode = loadFileWithIncludes(fragmentPath);
|
||||
const char *computeCode = loadFileWithIncludes(computePath);
|
||||
|
||||
printWithLineNumbers(computeCode);
|
||||
// printWithLineNumbers(computeCode);
|
||||
|
||||
_vertex = glCreateShader(GL_VERTEX_SHADER);
|
||||
|
||||
|
Reference in New Issue
Block a user