Das Problem mit der Erreichbarkeit der HS-Koblenz ist behoben. Es können sich wieder alle anmelden.

Commit eeacc6ae authored by unknown's avatar unknown
Browse files

Fixed issues with BSDF color values and self shadowing

parent b05736a9
......@@ -121,6 +121,8 @@ bool shade(int id, inout vec3 radiance, uint bounce, out uint bsdf_id)
if(bsdf_result.bsdf_id == eEmit)
{
writeColorStore(ray, radiance * bsdf_result.radiance, clamp_color_max);
// if(!isnan(bsdf_result.generated_ray.direction.x))
//writeColorStore(ray, bsdf_result.generated_ray.direction.xyz, clamp_color_max);
b_traces[id].hit.invalidate();
return false;
}
......
......@@ -145,13 +145,14 @@ BSDFResult computeBSDF(const in Material material, const in vec2 random, const i
float m_dot_out = clamp(dot(micro_normal, outgoing_reflected), 0, 1);
float m_dot_out_refract = clamp(dot(micro_normal, outgoing_refracted), -1, 1);
float n_dot_out_refract = clamp(dot(normal, outgoing_refracted), -1, 1);
float m_dot_n = clamp(dot(micro_normal, normal), 0, 1);
// In this implementation, it is defined that the importance sample generated is cos(theta) instead of the usual approach of only theta.
float cos_theta = hemisphere_sample.importance.y;
float cos_theta = cos(hemisphere_sample.importance.y);
// Compute the microsurface normal probability and with that the final probability density function
// Clamp up denominator to not divide by zero.
float jacobian_reflect = 1 / clamp(4 * m_dot_out, 0.001f, 1);
float jacobian_reflect = 1 / clamp(4 * m_dot_out, 0.00001f, 1);
float probability_m = hemisphere_sample.distribution * cos_theta;
float pdf = probability_m * jacobian_reflect;
......@@ -159,25 +160,20 @@ BSDFResult computeBSDF(const in Material material, const in vec2 random, const i
float ior_out_2 = ior_out * ior_out;
float jacobian_refract_denominator = ior_in * m_dot_in + ior_out * m_dot_out_refract;
jacobian_refract_denominator *= jacobian_refract_denominator;
jacobian_refract_denominator = clamp(jacobian_refract_denominator, 0.001f, 1.f);
jacobian_refract_denominator = clamp(jacobian_refract_denominator, 0.00001f, 1.f);
//Take the absolute value as m_dot_out_refract is negative
float jacobian_refract = abs(ior_out_2 * m_dot_out_refract / jacobian_refract_denominator);
float pdf_refract = probability_m * jacobian_refract;
// Same here... clamp up denominator to not divide by zero
float brdf_denominator = clamp((4 * n_dot_in * n_dot_out), 0.001f, 1.f);
float brdf_denominator = clamp((4 * n_dot_in * n_dot_out), 0.0000001f, 1.f);
float btdf_denominator = jacobian_refract_denominator;
// TODO: what exactly is causing the slight offset in color on smooth surfaces?
// This value will prohibit very high reflection values which occur for some reason.
float reflection_correction_factor = mix(1.f, 0.0002f, sampled_material.metallic * (1-sampled_material.roughness));
float transmission_correction_factor = mix(1.f, 0.01f, (1-sampled_material.roughness));
// Finally, build the brdf. As we do russian roulette, we can just tint the brdf instead of multiplying with the fresnel value.
vec3 brdf = mix(vec3(1), sampled_material.diffuse.rgb * reflection_correction_factor, sampled_material.metallic) * geometry * hemisphere_sample.distribution / brdf_denominator;
vec3 brdf = mix(vec3(1), sampled_material.diffuse.rgb, sampled_material.metallic) * geometry * hemisphere_sample.distribution / brdf_denominator;
// Same as above, we don't need the fresnel factor here either.
vec3 btdf = (m_dot_in * m_dot_out_refract / (n_dot_in * n_dot_out_refract)) * ior_out_2 * transmission_correction_factor * sampled_material.diffuse.rgb * geometry_refracted * hemisphere_sample.distribution / btdf_denominator;
vec3 btdf = (m_dot_in * m_dot_out_refract / (n_dot_in * n_dot_out_refract)) * ior_out_2 * sampled_material.diffuse.rgb * geometry_refracted * hemisphere_sample.distribution / btdf_denominator;
// russian roulette Part 2
// Also check whether the refracted ray is valid, as we don't want to sample with NaN rays.
......@@ -185,8 +181,8 @@ BSDFResult computeBSDF(const in Material material, const in vec2 random, const i
{
// Use as brdf sample
result.generated_ray.direction = outgoing_reflected;
result.radiance = brdf;
result.probability_density = pdf;
result.radiance = brdf;
result.evaluation = vec3(0); // No diffuse if reflecting
result.bsdf_id = eReflect;
}
......
......@@ -39,7 +39,7 @@ Ray getRayFromPixel(const in Camera camera, const in vec2 pixel, const in vec2 s
ray.px = final_pixel.x;
ray.py = final_pixel.y;
depthOfFieldTransform(ray, sub_pixel, 66.f, 5.f);
depthOfFieldTransform(ray, sub_pixel, 30.f, 10.f);
return ray;
}
......
......@@ -43,9 +43,9 @@ vec3 fresnelTint(float fresnel, float metallic, const in vec3 material_color)
// Computes an importance sample {phi, theta} from any random sample {(0..1], (0..1]}.
vec2 ggxImportanceSample(const in vec2 random_sample, const in float roughness)
{
float phi = random_sample.y;
float phi = random_sample.y * 2.f * PI;
float rough2 = roughness*roughness;
float theta = sqrt(rough2 * random_sample.x / (1 - random_sample.x));
float theta = atan(sqrt(rough2 * random_sample.x / (1 - random_sample.x)));
return vec2(phi, theta);
}
......@@ -53,9 +53,9 @@ vec2 ggxImportanceSample(const in vec2 random_sample, const in float roughness)
vec3 ggxImportantHemisphereSample(const in vec2 random_sample, const in float roughness, out vec2 importance)
{
importance = ggxImportanceSample(random_sample, roughness);
float phi = importance.x * 2.f * PI;
float phi = importance.x;
float cosTheta = cos(importance.y);
float sinTheta = sqrt(max(0, 1 - cosTheta * cosTheta));
float sinTheta = sin(importance.y);//sqrt(max(0, 1 - cosTheta * cosTheta));
return vec3(sinTheta * cos(phi), sinTheta * sin(phi), cosTheta);
}
......@@ -101,7 +101,7 @@ HemisphereSample ggxSample(const in vec2 random, const in float roughness)
{
HemisphereSample hemisphere_sample;
hemisphere_sample.micro_normal = ggxImportantHemisphereSample(random, roughness, hemisphere_sample.importance);
hemisphere_sample.distribution = ggxDistribution(hemisphere_sample.importance.y, roughness);
hemisphere_sample.distribution = ggxDistribution(cos(hemisphere_sample.importance.y), roughness);
return hemisphere_sample;
}
......
......@@ -12,11 +12,11 @@ bool samplePoint(const in BufferLight light, const in Vertex vertex, const in ve
{
vec3 direction = (light.position.xyz + randUniformSphere(random_sample)*light.data[0]) - vertex.position.xyz;
shadow_ray.origin = vertex.position.xyz + 1e-5*vertex.normal.xyz;
shadow_ray.origin = vertex.position.xyz + 1e-3*vertex.normal.xyz;
shadow_ray.direction = normalize(direction);
light_distance = length(direction);
light_color = light.color.rgb * attenuation(light_distance, light.constant, light.linear, light.quadratic) * angle(shadow_ray, vertex);
light_color = light.color.rgb * attenuation(light_distance, light.constant, light.linear, light.quadratic) * max(0.f, dot(shadow_ray.direction, vertex.normal.xyz));
return length(light_color) > 0.001f;
}
......
......@@ -111,10 +111,10 @@ namespace glare
//Create a skybox from cube map.
m_skybox = std::make_shared<core::Skybox>(core::Skybox::collectFilesFrom(files::asset("/textures/ryfjallet/")));
initializeScene(m_current_scene_root / "TY_Plane.dae", 1.f);
//initializeScene(m_current_scene_root / "TY_Plane.dae", 1.f);
//initializeScene(m_current_scene_root / "dragn.dae", 1.f);
//initializeScene(m_current_scene_root / "benchmark_stfd_bunny_diff.dae", 1.f);
//initializeScene(m_current_scene_root / "banni.dae", 1.f);
initializeScene(m_current_scene_root / "lstest.dae", 1.f);
initializeRenderRequirements();
initializeAdvanced();
......
......@@ -95,8 +95,8 @@ namespace glare
std::string Collada::decodeTextureSampler(const pugi::xml_node& effect_node, const std::string &sampler)
{
const auto surface = effect_node.find_child_by_attribute("newparam", "sid", sampler.c_str()).child("surface").child("init_from").child_value();
return effect_node.find_child_by_attribute("newparam", "sid", surface).child("sampler2D").child("source").child_value();
const auto surface = effect_node.find_child_by_attribute("newparam", "sid", sampler.c_str()).child("sampler2D").child("source").child_value();
return effect_node.find_child_by_attribute("newparam", "sid", surface).child("surface").child("init_from").child_value();
}
glm::vec3 Collada::decodeVec3(const std::string &value)
......
......@@ -28,43 +28,43 @@ namespace glare
mat.map_diffuse = 0;
if (material.map_diffuse) {
mat.flags |= uint32_t(MapFlag::eDiffuse);
mat.map_diffuse = material.map_diffuse->residentTextureAddress();
mat.map_diffuse = material.map_diffuse->makeTextureResident();
}
mat.map_ambient = 0;
if (material.map_ambient) {
mat.flags |= uint32_t(MapFlag::eAmbient);
mat.map_ambient = material.map_ambient->residentTextureAddress();
mat.map_ambient = material.map_ambient->makeTextureResident();
}
mat.map_displacement = 0;
if (material.map_displacement) {
mat.flags |= uint32_t(MapFlag::eDisplacement);
mat.map_displacement = material.map_displacement->residentTextureAddress();
mat.map_displacement = material.map_displacement->makeTextureResident();
}
mat.map_normal = 0;
if (material.map_normal) {
mat.flags |= uint32_t(MapFlag::eNormal);
mat.map_normal = material.map_normal->residentTextureAddress();
mat.map_normal = material.map_normal->makeTextureResident();
}
mat.map_specular = 0;
if (material.map_specular) {
mat.flags |= uint32_t(MapFlag::eSpecular);
mat.map_specular = material.map_specular->residentTextureAddress();
mat.map_specular = material.map_specular->makeTextureResident();
}
mat.map_transparent = 0;
if (material.map_transparent) {
mat.flags |= uint32_t(MapFlag::eTransparent);
mat.map_transparent = material.map_transparent->residentTextureAddress();
mat.map_transparent = material.map_transparent->makeTextureResident();
}
mat.map_emissive = 0;
if (material.map_transparent) {
mat.flags |= uint32_t(MapFlag::eEmissive);
mat.map_emissive = material.map_emissive->residentTextureAddress();
mat.map_emissive = material.map_emissive->makeTextureResident();
}
return mat;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment