mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 10:48:34 +02:00
+ | New map portal and checkerboard
This commit is contained in:
@ -37,17 +37,23 @@ bool intersectPlane(Ray ray, GPUObject obj, out hitInfo hit)
|
||||
hit.position = ray.origin + ray.direction * t;
|
||||
hit.normal = d < 0.0 ? obj.normal : -obj.normal;
|
||||
|
||||
vec3 U = normalize((abs(obj.normal.x) > abs(obj.normal.z)) ? vec3(-obj.normal.y, obj.normal.x, 0.0) : vec3(0.0, -obj.normal.z, obj.normal.y));
|
||||
vec3 V = normalize(cross(obj.normal, U));
|
||||
|
||||
vec3 localPos = hit.position - obj.position;
|
||||
hit.u = dot(localPos, U) * 1.0;
|
||||
hit.v = dot(localPos, V) * 1.0;
|
||||
|
||||
return (valid);
|
||||
}
|
||||
|
||||
bool intersectQuad(Ray ray, GPUObject obj, out hitInfo hit)
|
||||
{
|
||||
vec3 normal = obj.normal;
|
||||
float d = dot(normal, ray.direction);
|
||||
float d = dot(obj.normal, ray.direction);
|
||||
|
||||
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, obj.normal) / d;
|
||||
|
||||
if (t <= 0.0) return (false);
|
||||
|
||||
@ -59,13 +65,17 @@ bool intersectQuad(Ray ray, GPUObject obj, out hitInfo hit)
|
||||
float l1 = dot(obj.vertex1, obj.vertex1);
|
||||
float l2 = dot(obj.vertex2, obj.vertex2);
|
||||
|
||||
|
||||
bool inside = e1 >= 0.0 && e1 <= l1 && e2 >= 0.0 && e2 <= l2;
|
||||
|
||||
hit.t = t;
|
||||
hit.position = p + obj.position;
|
||||
hit.normal = normal * -sign(d);
|
||||
hit.normal = obj.normal * -sign(d);
|
||||
// hit.normal = normal;
|
||||
|
||||
hit.u = e1 / l1;
|
||||
hit.v = e2 / l2;
|
||||
|
||||
return (inside);
|
||||
}
|
||||
|
||||
|
@ -115,6 +115,17 @@ vec2 getTextureColor(hitInfo hit)
|
||||
return (vec2(uv.x, 1 - uv.y));
|
||||
}
|
||||
|
||||
vec3 getCheckerboardColor(GPUMaterial mat, hitInfo hit)
|
||||
{
|
||||
float scale = mat.refraction; //scale
|
||||
int check = int(floor(hit.u * scale) + floor(hit.v * scale)) % 2;
|
||||
|
||||
vec3 color1 = mat.color;
|
||||
vec3 color2 = vec3(0.0);
|
||||
|
||||
return check == 0 ? color1 : color2;
|
||||
}
|
||||
|
||||
void calculateLightColor(GPUMaterial mat, hitInfo hit, inout vec3 color, inout vec3 light, inout uint rng_state)
|
||||
{
|
||||
if (mat.texture_index != -1)
|
||||
@ -131,8 +142,9 @@ void calculateLightColor(GPUMaterial mat, hitInfo hit, inout vec3 color, inou
|
||||
}
|
||||
else
|
||||
{
|
||||
color *= mat.color;
|
||||
light += mat.emission * mat.color;
|
||||
vec3 mat_color = (mat.type == 3) ? getCheckerboardColor(mat, hit) : mat.color;
|
||||
color *= mat_color;
|
||||
light += mat.emission * mat_color;
|
||||
// if (mat.emission == 0.0)
|
||||
// light += sampleLights(hit.position, rng_state);
|
||||
}
|
||||
|
@ -202,10 +202,10 @@ vec3[2] pathtrace(Ray ray, inout uint rng_state)
|
||||
|
||||
if (i == 0)
|
||||
{
|
||||
// imageStore(normal_texture, ivec2(gl_GlobalInvocationID.xy), vec4(normalize(hit.normal), 1.0));
|
||||
// imageStore(position_texture, ivec2(gl_GlobalInvocationID.xy), vec4(normalize(hit.position), 1.0));
|
||||
vec4 accum_normal = accumulate(normal_texture, accum_normal, normalize(hit.normal));
|
||||
vec4 accum_position = accumulate(position_texture, accum_position, normalize(hit.position));
|
||||
imageStore(normal_texture, ivec2(gl_GlobalInvocationID.xy), vec4(normalize(hit.normal), 1.0));
|
||||
imageStore(position_texture, ivec2(gl_GlobalInvocationID.xy), vec4(normalize(hit.position), 1.0));
|
||||
// vec4 accum_normal = accumulate(normal_texture, accum_normal, normalize(hit.normal));
|
||||
// vec4 accum_position = accumulate(position_texture, accum_position, normalize(hit.position));
|
||||
}
|
||||
|
||||
float p = max(color.r, max(color.g, color.b));
|
||||
|
@ -84,7 +84,7 @@ Ray newRay(hitInfo hit, Ray ray, inout uint rng_state)
|
||||
|
||||
mat = materials[hit.mat_index];
|
||||
|
||||
if (mat.type == 0)
|
||||
if (mat.type == 0 || mat.type == 3)
|
||||
return (lambertRay(hit, ray, mat, rng_state));
|
||||
else if (mat.type == 1)
|
||||
return (dieletricRay(hit, ray, mat));
|
||||
|
@ -48,6 +48,8 @@ hitInfo traceScene(Ray ray)
|
||||
hit.mat_index = obj.mat_index;
|
||||
hit.position = temp_hit.position;
|
||||
hit.normal = temp_hit.normal;
|
||||
hit.u = temp_hit.u;
|
||||
hit.v = temp_hit.v;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ void SceneParser::parseMaterial(std::stringstream &line)
|
||||
float rough_refrac;
|
||||
float metallic;
|
||||
std::string type;
|
||||
int texture_index;
|
||||
float texture_index;
|
||||
|
||||
Material *mat;
|
||||
|
||||
@ -54,6 +54,8 @@ void SceneParser::parseMaterial(std::stringstream &line)
|
||||
mat->type = 1;
|
||||
else if (type == "TRN")
|
||||
mat->type = 2;
|
||||
else if (type == "CHK")
|
||||
mat->type = 3;
|
||||
|
||||
texture_index = -1;
|
||||
if (mat->type != -1)
|
||||
@ -61,7 +63,13 @@ void SceneParser::parseMaterial(std::stringstream &line)
|
||||
else
|
||||
mat->type = 0;
|
||||
|
||||
mat->texture_index = texture_index;
|
||||
if (mat->type == 3) // i know it's ugly
|
||||
{
|
||||
mat->refraction = texture_index;
|
||||
texture_index = -1;
|
||||
}
|
||||
|
||||
mat->texture_index = (int)texture_index;
|
||||
mat->emission_texture_index = -1;
|
||||
_scene->addMaterial(mat);
|
||||
}
|
||||
|
@ -248,7 +248,13 @@ void Window::imGuiRender(ShaderProgram &raytracing_program)
|
||||
has_changed |= ImGui::SliderFloat("Refraction", &mat.refraction, 1.0f, 2.0f);
|
||||
has_changed |= ImGui::SliderFloat("Proba", &mat.metallic, 0., 1.);
|
||||
}
|
||||
has_changed |= ImGui::SliderInt("Type", &mat.type, 0, 2);
|
||||
else if (mat.type == 3)
|
||||
{
|
||||
has_changed |= ImGui::SliderFloat("Checker Scale", &mat.refraction, 0.0f, 40.0f);
|
||||
has_changed |= ImGui::SliderFloat("Roughness", &mat.roughness, 0.0f, 1.0f);
|
||||
has_changed |= ImGui::SliderFloat("Metallic", &mat.metallic, 0.0f, 1.0f);
|
||||
}
|
||||
has_changed |= ImGui::SliderInt("Type", &mat.type, 0, 3);
|
||||
|
||||
ImGui::PopID();
|
||||
|
||||
|
Reference in New Issue
Block a user