mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 18:48:36 +02:00
+ | Backface culling choosing on quad so euclidian map + portal
This commit is contained in:
@ -24,8 +24,6 @@ class Portal : public Object
|
|||||||
float x1, y1, z1;
|
float x1, y1, z1;
|
||||||
float x2, y2, z2;
|
float x2, y2, z2;
|
||||||
|
|
||||||
bool invert_normal;
|
|
||||||
|
|
||||||
int mat_index;
|
int mat_index;
|
||||||
|
|
||||||
if (!(line >> x >> y >> z))
|
if (!(line >> x >> y >> z))
|
||||||
@ -37,7 +35,7 @@ class Portal : public Object
|
|||||||
if (!(line >> x2 >> y2 >> z2))
|
if (!(line >> x2 >> y2 >> z2))
|
||||||
throw std::runtime_error("Missing Portal's second edge");
|
throw std::runtime_error("Missing Portal's second edge");
|
||||||
|
|
||||||
if (!(line >> invert_normal))
|
if (!(line >> _invert_normal))
|
||||||
throw std::runtime_error("Missing invert_normal");
|
throw std::runtime_error("Missing invert_normal");
|
||||||
|
|
||||||
if (!(line >> mat_index))
|
if (!(line >> mat_index))
|
||||||
@ -47,14 +45,18 @@ class Portal : public Object
|
|||||||
_up = glm::vec3(x1, y1, z1);
|
_up = glm::vec3(x1, y1, z1);
|
||||||
_right = glm::vec3(x2, y2, z2);
|
_right = glm::vec3(x2, y2, z2);
|
||||||
|
|
||||||
glm::vec3 up = glm::normalize(_up);
|
// glm::vec3 temp_right = _right;
|
||||||
|
// _right = _invert_normal ? _up : _right;
|
||||||
|
// _up = _invert_normal ? temp_right : _up;
|
||||||
|
|
||||||
glm::vec3 right = glm::normalize(_right);
|
glm::vec3 right = glm::normalize(_right);
|
||||||
|
glm::vec3 up = glm::normalize(_up);
|
||||||
glm::vec3 forward = glm::normalize(glm::cross(right, up));
|
glm::vec3 forward = glm::normalize(glm::cross(right, up));
|
||||||
|
|
||||||
up = normalize(glm::cross(forward, right));
|
// up = normalize(glm::cross(forward, right));
|
||||||
|
|
||||||
_rotation = glm::mat3(right, up, forward);
|
_rotation = glm::mat3(right, up, forward);
|
||||||
_normal = forward * (invert_normal ? -1.0f : 1.0f);
|
_normal = forward * (_invert_normal ? -1.0f : 1.0f);
|
||||||
|
|
||||||
_linked_portal = -1;
|
_linked_portal = -1;
|
||||||
|
|
||||||
@ -67,19 +69,23 @@ class Portal : public Object
|
|||||||
{
|
{
|
||||||
float extension = 0.2f;
|
float extension = 0.2f;
|
||||||
|
|
||||||
glm::vec3 right_dir = glm::normalize(_up);
|
glm::vec3 right_dir = glm::normalize(_right);
|
||||||
glm::vec3 up_dir = glm::normalize(_right);
|
glm::vec3 up_dir = glm::normalize(_up);
|
||||||
|
|
||||||
float right_length = glm::length(_up) + extension;
|
// glm::vec3 temp_right = right_dir;
|
||||||
float up_length = glm::length(_right) + extension;
|
// right_dir = _invert_normal ? right_dir : up_dir;
|
||||||
|
// up_dir = _invert_normal ? up_dir : temp_right;
|
||||||
|
|
||||||
|
float right_length = glm::length(_right) + extension;
|
||||||
|
float up_length = glm::length(_up) + extension;
|
||||||
|
|
||||||
glm::vec3 center_offset = -(right_dir * (extension / 2.0f) + up_dir * (extension / 2.0f));
|
glm::vec3 center_offset = -(right_dir * (extension / 2.0f) + up_dir * (extension / 2.0f));
|
||||||
glm::vec3 position = _position + _normal * -0.001f + center_offset;
|
glm::vec3 position = _position + _normal * 0.001f + center_offset;
|
||||||
|
|
||||||
glm::vec3 right = right_dir * right_length;
|
glm::vec3 right = right_dir * right_length;
|
||||||
glm::vec3 up = up_dir * up_length;
|
glm::vec3 up = up_dir * up_length;
|
||||||
|
// position += 10;
|
||||||
return (new Quad(position, right, up, _mat_index));
|
return (new Quad(position, right, up, _normal, 1, _mat_index));
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 getUp() const { return (_up); }
|
glm::vec3 getUp() const { return (_up); }
|
||||||
@ -101,6 +107,7 @@ class Portal : public Object
|
|||||||
glm::mat3 _rotation;
|
glm::mat3 _rotation;
|
||||||
|
|
||||||
int _linked_portal;
|
int _linked_portal;
|
||||||
|
int _invert_normal;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -23,6 +23,7 @@ class Quad : public Object
|
|||||||
float x, y, z;
|
float x, y, z;
|
||||||
float x1, y1, z1;
|
float x1, y1, z1;
|
||||||
float x2, y2, z2;
|
float x2, y2, z2;
|
||||||
|
bool double_face;
|
||||||
int mat_index;
|
int mat_index;
|
||||||
|
|
||||||
if (!(line >> x >> y >> z))
|
if (!(line >> x >> y >> z))
|
||||||
@ -34,6 +35,9 @@ class Quad : public Object
|
|||||||
if (!(line >> x2 >> y2 >> z2))
|
if (!(line >> x2 >> y2 >> z2))
|
||||||
throw std::runtime_error("Missing quad's second edge");
|
throw std::runtime_error("Missing quad's second edge");
|
||||||
|
|
||||||
|
if (!(line >> _single_sided))
|
||||||
|
throw std::runtime_error("Missing double_face");
|
||||||
|
|
||||||
if (!(line >> mat_index))
|
if (!(line >> mat_index))
|
||||||
throw std::runtime_error("Missing material properties");
|
throw std::runtime_error("Missing material properties");
|
||||||
|
|
||||||
@ -41,18 +45,25 @@ class Quad : public Object
|
|||||||
_up = glm::vec3(x1, y1, z1);
|
_up = glm::vec3(x1, y1, z1);
|
||||||
_right = glm::vec3(x2, y2, z2);
|
_right = glm::vec3(x2, y2, z2);
|
||||||
|
|
||||||
|
_normal = glm::normalize(glm::cross(_up, _right));
|
||||||
|
|
||||||
_mat_index = mat_index;
|
_mat_index = mat_index;
|
||||||
}
|
}
|
||||||
Quad(const glm::vec3 &position, const glm::vec3 &edge1, const glm::vec3 &edge2, const int mat_index)
|
Quad(const glm::vec3 &position, const glm::vec3 &edge1, const glm::vec3 &edge2, const glm::vec3 &normal, const int single_sided, const int mat_index)
|
||||||
: Object(position, mat_index), _up(edge1), _right(edge2) {}
|
: Object(position, mat_index), _up(edge1), _right(edge2), _normal(normal), _single_sided(single_sided) {}
|
||||||
|
|
||||||
glm::vec3 getUp() const { return (_up); }
|
glm::vec3 getUp() const { return (_up); }
|
||||||
glm::vec3 getRight() const { return (_right); }
|
glm::vec3 getRight() const { return (_right); }
|
||||||
|
glm::vec3 getNormal() const { return (_normal); }
|
||||||
|
int getSingleSided() const { return (_single_sided); }
|
||||||
Type getType() const override { return Type::QUAD; }
|
Type getType() const override { return Type::QUAD; }
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
glm::vec3 _up;
|
glm::vec3 _up;
|
||||||
glm::vec3 _right;
|
glm::vec3 _right;
|
||||||
|
glm::vec3 _normal;
|
||||||
|
int _single_sided;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -2,7 +2,7 @@ CAM -2.41462 2.57199 4.09049 -1.80012 -50.2012 0.02 2.973 45.75
|
|||||||
|
|
||||||
MAT 20 20 20 0. 0.9 0.5 // 0 gray
|
MAT 20 20 20 0. 0.9 0.5 // 0 gray
|
||||||
# pl 0 5.2 0 0 -1 0 0 // floor
|
# pl 0 5.2 0 0 -1 0 0 // floor
|
||||||
qu -5 5 -5 10 0 0 0 0 10 0
|
qu -5 5 -5 0 0 10 10 0 0 0
|
||||||
|
|
||||||
|
|
||||||
MAT 255 100 100 1.0 0.0 0.0 //1 red
|
MAT 255 100 100 1.0 0.0 0.0 //1 red
|
||||||
|
20
scenes/noneuclidian.rt
Normal file
20
scenes/noneuclidian.rt
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
CAM 0 2.59881 7 -4.8 -89.9996 0 1 90 5
|
||||||
|
|
||||||
|
MAT 100 200 100 0.0 0.0 0.0 // 0
|
||||||
|
MAT 200 200 200 0.0 0.0 0.0 // 1
|
||||||
|
|
||||||
|
MAT 200 200 200 0 0 0 // 2 portal
|
||||||
|
|
||||||
|
pl 0 0 0 0 1 0 0
|
||||||
|
|
||||||
|
po -1.5 0 4.5 3 0 0 0 3 0 0 2
|
||||||
|
po -1.5 0 -4.5 3 0 0 0 3 0 1 2
|
||||||
|
|
||||||
|
qu -1.5 0 -5 0 3 0 0 0 10 0 1
|
||||||
|
qu 1.5 0 -5 0 3 0 0 0 10 0 1
|
||||||
|
|
||||||
|
qu -1.5 3 -5 3 0 0 0 0 10 0 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
cu 10 1.5 0 3 3 5 1
|
@ -8,7 +8,7 @@ sp +0.000 +17.00 +20.00 4.0 0
|
|||||||
sp +0.000 +17.00 +0.000 4.0 1
|
sp +0.000 +17.00 +0.000 4.0 1
|
||||||
sp +0.000 +17.00 -20.00 4.0 2
|
sp +0.000 +17.00 -20.00 4.0 2
|
||||||
|
|
||||||
MAT 250 250 250 0.0 1.5 0.0 DIE -1 // 3 white 0 0 1
|
MAT 250 250 250 0.0 1.2 0.0 DIE -1 // 3 white 0 0 1
|
||||||
MAT 250 250 250 0.0 1.0 1.0 // 4 white 0 1 0
|
MAT 250 250 250 0.0 1.0 1.0 // 4 white 0 1 0
|
||||||
MAT 200 200 200 0.0 0.0 0.0 // 5 white 1 0 0
|
MAT 200 200 200 0.0 0.0 0.0 // 5 white 1 0 0
|
||||||
|
|
||||||
|
@ -22,8 +22,8 @@ qu -1 4 -1 2 0 0 0 0 2 2
|
|||||||
|
|
||||||
cu 0 2.5 0 5 5 5 1
|
cu 0 2.5 0 5 5 5 1
|
||||||
|
|
||||||
po -1 1 -1.5 0 2 0 2 0 0 0 3
|
po -1 1 -1.5 0 2 0 2 0 0 1 3
|
||||||
po -1 1 1.5 0 2 0 2 0 0 1 4
|
po -1 1 1.5 0 2 0 2 0 0 0 4
|
||||||
|
|
||||||
po -1.5 1 -1 0 2 0 0 0 2 1 5
|
po -1.5 1 -1 0 2 0 0 0 2 0 5
|
||||||
po 1.5 1 -1 0 2 0 0 0 2 0 6
|
po 1.5 1 -1 0 2 0 0 0 2 1 6
|
||||||
|
@ -18,5 +18,5 @@ pl -3 0 0 1 0 0 3
|
|||||||
pl 0 0 -3 0 0 1 4
|
pl 0 0 -3 0 0 1 4
|
||||||
pl 0 0 3 0 0 -1 2
|
pl 0 0 3 0 0 -1 2
|
||||||
|
|
||||||
po -0.33 -0.66 -1 0 1 0 0.5 0.5 -0.5 0 2
|
po -0.5 -0.5 -1 0 1 0 1 0.5 0.5 1 2
|
||||||
po -0.5 -0.5 1 0 1 0 1 0 0 1 4
|
po -0.5 -0.5 1 0 1 0 1 0 0 0 4
|
@ -40,5 +40,5 @@ sp 2.4 1.5 -1 1.5 14
|
|||||||
|
|
||||||
|
|
||||||
// light quad
|
// light quad
|
||||||
qu -1 2.999 -1 2 0 0 0 0 2 0
|
qu -1 2.999 -1 0 0 2 2 0 0 0
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ cu -9 0.98 3 3 3 3 28
|
|||||||
MAT 244 95 28 0.0 0.5 1.0
|
MAT 244 95 28 0.0 0.5 1.0
|
||||||
cu -9 1.23 -6 3 3 3 29
|
cu -9 1.23 -6 3 3 3 29
|
||||||
|
|
||||||
MAT 200 20 20 0.0 1.0 0.05 LAM 0
|
MAT 200 20 20 0.0 1.0 0.05 LAM -1
|
||||||
MAT 255 255 255 0.0 1.8 0.0 DIE -1
|
MAT 255 255 255 0.0 1.8 0.0 DIE -1
|
||||||
MAT 255 255 255 0.0 1.0 1.0
|
MAT 255 255 255 0.0 1.0 1.0
|
||||||
|
|
||||||
|
@ -1,6 +1,18 @@
|
|||||||
CAM -0.181956 1.3733 2.83437 -16 -87.8001 0 1 90 5
|
CAM 0 1.3733 2.83437 -16 -87.8001 0 1 90 5
|
||||||
|
|
||||||
MAT 255 255 255 10.0 1.0 0.0 //white
|
# MAT 255 255 255 0.0 1.5 0.0 DIE -1 // 0
|
||||||
# sp 0 0 0 1 0
|
# sp 0 0 0 12.5 0
|
||||||
|
|
||||||
|
TEX skymap.hdr
|
||||||
|
MAT 255 255 255 1.0 0.0 0.0 LAM 0 // 0
|
||||||
|
|
||||||
|
MAT 255 255 255 0.0 0.0 0.0 // 1
|
||||||
|
|
||||||
|
|
||||||
|
sp 0 2 0 150 0
|
||||||
|
|
||||||
|
OBJ scenes/obj/jinx.obj -10 0 0 1.25 0 0 0
|
||||||
|
# OBJ scenes/obj/Dragon_800K.obj 0 0 0 35 0 0 0 1
|
||||||
|
|
||||||
|
OBJ scenes/obj/whitedragon.obj 0 0 0 1 0 0 0
|
||||||
|
|
||||||
OBJ scenes/obj/jinx.obj 0 0 0 1
|
|
||||||
|
@ -42,10 +42,10 @@ bool intersectPlane(Ray ray, GPUObject obj, out hitInfo hit)
|
|||||||
|
|
||||||
bool intersectQuad(Ray ray, GPUObject obj, out hitInfo hit)
|
bool intersectQuad(Ray ray, GPUObject obj, out hitInfo hit)
|
||||||
{
|
{
|
||||||
vec3 normal = normalize(cross(obj.vertex1, obj.vertex2));
|
vec3 normal = obj.normal;
|
||||||
float d = dot(normal, ray.direction);
|
float d = dot(normal, ray.direction);
|
||||||
|
|
||||||
if (d == 0.0) return (false);
|
if (d == 0.0 || (obj.radius != 0.0 && d <= 0)) return (false); // double sided or not
|
||||||
|
|
||||||
float t = dot(obj.position - ray.origin, normal) / d;
|
float t = dot(obj.position - ray.origin, normal) / d;
|
||||||
|
|
||||||
@ -64,6 +64,7 @@ bool intersectQuad(Ray ray, GPUObject obj, out hitInfo hit)
|
|||||||
hit.t = t;
|
hit.t = t;
|
||||||
hit.position = p + obj.position;
|
hit.position = p + obj.position;
|
||||||
hit.normal = normal * -sign(d);
|
hit.normal = normal * -sign(d);
|
||||||
|
// hit.normal = normal;
|
||||||
|
|
||||||
return (inside);
|
return (inside);
|
||||||
}
|
}
|
||||||
|
@ -171,7 +171,7 @@ hitInfo traceRay(Ray ray)
|
|||||||
hitInfo hitScene;
|
hitInfo hitScene;
|
||||||
hitInfo hit;
|
hitInfo hit;
|
||||||
|
|
||||||
#if 0
|
#if 1
|
||||||
for (int i = 0; i < 10; i++) // portal ray
|
for (int i = 0; i < 10; i++) // portal ray
|
||||||
{
|
{
|
||||||
hitBVH = traverseBVHs(ray);
|
hitBVH = traverseBVHs(ray);
|
||||||
|
@ -91,6 +91,8 @@ void Scene::addObject(Object *obj)
|
|||||||
auto quad = static_cast<Quad *>(obj);
|
auto quad = static_cast<Quad *>(obj);
|
||||||
gpu_obj.vertex1 = quad->getUp();
|
gpu_obj.vertex1 = quad->getUp();
|
||||||
gpu_obj.vertex2 = quad->getRight();
|
gpu_obj.vertex2 = quad->getRight();
|
||||||
|
gpu_obj.normal = quad->getNormal();
|
||||||
|
gpu_obj.radius = quad->getSingleSided();
|
||||||
}
|
}
|
||||||
else if (obj->getType() == Object::Type::CUBE)
|
else if (obj->getType() == Object::Type::CUBE)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user