mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 18:48:36 +02:00
~ | Refraction change
This commit is contained in:
@ -7,7 +7,7 @@ Pos=1515,93
|
|||||||
Size=368,276
|
Size=368,276
|
||||||
|
|
||||||
[Window][Material]
|
[Window][Material]
|
||||||
Pos=1620,199
|
Pos=1601,205
|
||||||
Size=297,259
|
Size=297,259
|
||||||
|
|
||||||
[Window][Camera]
|
[Window][Camera]
|
||||||
|
@ -21,6 +21,7 @@ typedef struct s_Material
|
|||||||
float emission;
|
float emission;
|
||||||
float roughness;
|
float roughness;
|
||||||
float metallic;
|
float metallic;
|
||||||
|
float refraction;
|
||||||
int type;
|
int type;
|
||||||
} Material;
|
} Material;
|
||||||
|
|
||||||
|
@ -39,6 +39,7 @@ struct GPUMaterial
|
|||||||
float emission;
|
float emission;
|
||||||
float roughness;
|
float roughness;
|
||||||
float metallic;
|
float metallic;
|
||||||
|
float refraction;
|
||||||
int type;
|
int type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -26,8 +26,8 @@ struct GPUMaterial
|
|||||||
float emission; // 4
|
float emission; // 4
|
||||||
float roughness; // 4
|
float roughness; // 4
|
||||||
float metallic; // 4
|
float metallic; // 4
|
||||||
|
float refraction; // 4
|
||||||
int type; // 4
|
int type; // 4
|
||||||
int texture_index; // 4
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct GPUCamera
|
struct GPUCamera
|
||||||
|
@ -17,12 +17,12 @@ Ray dieletricRay(hitInfo hit, Ray ray, GPUMaterial mat)
|
|||||||
float refraction_ratio;
|
float refraction_ratio;
|
||||||
vec3 unit_direction;
|
vec3 unit_direction;
|
||||||
|
|
||||||
refraction_ratio = 1.0f / mat.roughness; //mat.roughness = refraction (saving memory)
|
refraction_ratio = 1.0f / mat.refraction;
|
||||||
|
|
||||||
if (dot(ray.direction, hit.normal) > 0.0f)
|
if (dot(ray.direction, hit.normal) > 0.0f)
|
||||||
{
|
{
|
||||||
hit.normal = -hit.normal;
|
hit.normal = -hit.normal;
|
||||||
refraction_ratio = mat.roughness;
|
refraction_ratio = mat.refraction;
|
||||||
}
|
}
|
||||||
|
|
||||||
unit_direction = normalize(ray.direction);
|
unit_direction = normalize(ray.direction);
|
||||||
|
@ -142,6 +142,7 @@ void Scene::updateGPUData()
|
|||||||
gpu_mat.emission = material->emission;
|
gpu_mat.emission = material->emission;
|
||||||
gpu_mat.roughness = material->roughness;
|
gpu_mat.roughness = material->roughness;
|
||||||
gpu_mat.metallic = material->metallic;
|
gpu_mat.metallic = material->metallic;
|
||||||
|
gpu_mat.refraction = material->refraction;
|
||||||
gpu_mat.type = material->type;
|
gpu_mat.type = material->type;
|
||||||
|
|
||||||
_gpu_materials.push_back(gpu_mat);
|
_gpu_materials.push_back(gpu_mat);
|
||||||
|
@ -61,13 +61,13 @@ void SceneParser::parseMaterial(std::stringstream &line)
|
|||||||
{
|
{
|
||||||
float r,g,b;
|
float r,g,b;
|
||||||
float emission;
|
float emission;
|
||||||
float roughness;
|
float rough_refrac;
|
||||||
float metallic;
|
float metallic;
|
||||||
std::string type;
|
std::string type;
|
||||||
|
|
||||||
Material *mat;
|
Material *mat;
|
||||||
|
|
||||||
if (!(line >> r >> g >> b >> emission >> roughness >> metallic))
|
if (!(line >> r >> g >> b >> emission >> rough_refrac >> metallic))
|
||||||
throw std::runtime_error("Material: Missing material properties");
|
throw std::runtime_error("Material: Missing material properties");
|
||||||
|
|
||||||
if (!(line >> type))
|
if (!(line >> type))
|
||||||
@ -77,8 +77,9 @@ void SceneParser::parseMaterial(std::stringstream &line)
|
|||||||
|
|
||||||
mat->color = glm::vec3(r / 255.0f, g / 255.0f, b / 255.0f);
|
mat->color = glm::vec3(r / 255.0f, g / 255.0f, b / 255.0f);
|
||||||
mat->emission = emission;
|
mat->emission = emission;
|
||||||
mat->roughness = roughness;
|
mat->roughness = rough_refrac;
|
||||||
mat->metallic = metallic;
|
mat->metallic = metallic;
|
||||||
|
mat->refraction = rough_refrac;
|
||||||
|
|
||||||
mat->type = 0;
|
mat->type = 0;
|
||||||
if (type == "LAM")
|
if (type == "LAM")
|
||||||
|
@ -200,11 +200,12 @@ void Window::imGuiRender()
|
|||||||
has_changed |= ImGui::SliderFloat("Emission", &mat.emission, 0.0f, 10.0f);
|
has_changed |= ImGui::SliderFloat("Emission", &mat.emission, 0.0f, 10.0f);
|
||||||
|
|
||||||
if (mat.type == 1)
|
if (mat.type == 1)
|
||||||
has_changed |= ImGui::SliderFloat("Roughness", &mat.roughness, 0.0f, 5.0f);
|
has_changed |= ImGui::SliderFloat("Refraction", &mat.refraction, 1.0f, 5.0f);
|
||||||
else
|
else
|
||||||
|
{
|
||||||
has_changed |= ImGui::SliderFloat("Roughness", &mat.roughness, 0.0f, 1.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::SliderFloat("Metallic", &mat.metallic, 0.0f, 1.0f);
|
}
|
||||||
has_changed |= ImGui::SliderInt("Type", &mat.type, 0, 1);
|
has_changed |= ImGui::SliderInt("Type", &mat.type, 0, 1);
|
||||||
|
|
||||||
ImGui::PopID();
|
ImGui::PopID();
|
||||||
|
Reference in New Issue
Block a user