Commit 109699ab authored by unknown's avatar unknown
Browse files

Not much has changed.

parent e7d17b2d
......@@ -114,11 +114,11 @@ bool shade(int id, inout vec3 radiance, uint bounce, out uint bsdf_id)
//vec3 light_influence;
//Ray out_ray;
//vec3 reflectance =
BSDFResult bsdf_result;
bsdf_result.radiance = material.sampleBSDF(random_sample, vertex, ray, bsdf_result.generated_ray, bsdf_result.irradiance, bsdf_result.distribution, bsdf_result.bsdf_id);
// BSDFResult bsdf_result;
//bsdf_result.radiance = material.sampleBSDF(random_sample, vertex, ray, bsdf_result.generated_ray, bsdf_result.irradiance, bsdf_result.distribution, bsdf_result.bsdf_id);
// reflectance = radiance; light_influence = irradiance; pdf = distribution; out_ray = generated_ray
//BSDFResult bsdf_result = material.computeBSDF(random_sample, vertex, ray);
BSDFResult bsdf_result = material.computeBSDF(random_sample, vertex, ray);
b_traces[id].addBounceAmount(bsdf_result.bsdf_id, 1);
......@@ -143,11 +143,11 @@ bool shade(int id, inout vec3 radiance, uint bounce, out uint bsdf_id)
// Environment shading for the diffuse part
if(length(bsdf_result.irradiance) > 0.01f && !bsdf_result.diffuse_ray.intersectsAny(FLT_MAX, use_bvh)){
writeColorStore(ray, u_environment.sampleColor(bsdf_result.diffuse_ray.direction.xyz).rgb * bsdf_result.irradiance * radiance, clamp_color_max);
}
// if(length(bsdf_result.irradiance) > 0.01f && !bsdf_result.diffuse_ray.intersectsAny(FLT_MAX, use_bvh)){
// writeColorStore(ray, u_environment.sampleColor(bsdf_result.diffuse_ray.direction.xyz).rgb * bsdf_result.irradiance * radiance, clamp_color_max);
// }
if (b_lights.length() > 0) {
if (false && b_lights.length() > 0) {
//Select random light... well... at least if there are any.
BufferLight light = b_lights[int(floor(random_sample.x * b_lights.length()))];
......
......@@ -43,12 +43,12 @@ struct SampledMaterial
float ior; // 0..n
};
vec3 reflectedDirection(vec3 local_hemi_sample, vec3 reflected, float roughness)
vec3 reflectedDirection(vec3 local_hemi_sample, vec3 normal, vec3 reflected, float roughness)
{
return normalize(localToWorldNormal(local_hemi_sample * vec3(roughness, roughness, 1), reflected));
return normalize(localToWorld(local_hemi_sample, normal, reflected));
}
BSDFResult computeBSDFaaa(const in Material material, const in vec2 random, const in Vertex vertex, const in Ray ray_in)
BSDFResult computeBSDFaaaaa(const in Material material, const in vec2 random, const in Vertex vertex, const in Ray ray_in)
{
SampledMaterial sampled_material;
sampled_material.diffuse = material.getDiffuse(vertex.texcoord);
......@@ -69,7 +69,7 @@ BSDFResult computeBSDFaaa(const in Material material, const in vec2 random, cons
BSDFResult result;
result.generated_ray = ray_in;
result.generated_ray.direction = reflectedDirection(hemi, reflected, sampled_material.roughness);
result.generated_ray.direction = reflectedDirection(hemi, vertex.normal.xyz, reflected, sampled_material.roughness);
result.generated_ray.origin = vertex.position.xyz + 1e-5f * result.generated_ray.direction;
result.diffuse_ray.direction = localToWorldNormal(hemi, vertex.normal.xyz).xyz;
......@@ -89,8 +89,8 @@ BSDFResult computeBSDFaaa(const in Material material, const in vec2 random, cons
vec3 k_specular = fresnel;
vec3 one_minus_kspec = (1-k_specular);
result.radiance = fresnel * geometry * sinT / denominator;
result.distribution = cosT * geometry * sinT / denominator;
result.radiance = fresnel * geometry;
result.distribution = denominator;//cosT * geometry * sinT / denominator;
result.irradiance = (1-k_specular)*(1-sampled_material.metallic)*sampled_material.diffuse.rgb * ONE_OVER_PI;
result.bsdf_id = 0;
......@@ -111,44 +111,55 @@ BSDFResult computeBSDF(const in Material material, const in vec2 random, const i
sampled_material.metallic = clamp((sampled_material.specular.r + sampled_material.specular.g + sampled_material.specular.b )/3, 0, 1);
sampled_material.ior = 1.56f;//material.ior;
vec3 backwards_direction = normalize(-ray_in.direction);
vec3 incoming = normalize(-ray_in.direction);
vec3 normal_response = normalResponse(sampled_material.diffuse.rgb, sampled_material.ior, sampled_material.metallic);
bool entering = dot(backwards_direction, vertex.normal.xyz) > 0.f;
vec3 hemi = randCosineHemisphere(random.x, random.y) * (entering ? 1 : -1);
vec3 microsurface_normal = reflectedDirection(hemi, vertex.normal.xyz, sampled_material.roughness);
vec3 outgoing = reflect(-backwards_direction, faceforward(microsurface_normal, -backwards_direction, vertex.normal.xyz));
vec3 fresnel = fresnelSchlick(clamp(dot(backwards_direction, microsurface_normal), 0, 1), normal_response);
//float geometry = ggxPartialGeometry(backwards_direction, vertex.normal.xyz, microsurface_normal, sampled_material.roughness)
// * ggxPartialGeometry(outgoing, vertex.normal.xyz, microsurface_normal, sampled_material.roughness);
//float distribution = ggxDistribution(vertex.normal.xyz, microsurface_normal, sampled_material.roughness);
float i_dot_m = clamp(dot(backwards_direction, microsurface_normal), 0, 1);
float i_dot_n = clamp(dot(backwards_direction, vertex.normal.xyz), 0, 1);
float m_dot_n = clamp(dot(vertex.normal.xyz, microsurface_normal), 0, 1);
float o_dot_m = clamp(dot(microsurface_normal, outgoing), 0, 1);
float o_dot_n = clamp(dot(vertex.normal.xyz, outgoing), 0, 1);
float alphaSqr = sampled_material.roughness * sampled_material.roughness * sampled_material.roughness * sampled_material.roughness;
float denom = m_dot_n * m_dot_n * (alphaSqr - 1.0) + 1.0;
float distribution = alphaSqr / (denom * denom);
float geometry = min(1, min((2*m_dot_n*i_dot_n/i_dot_m), (2*m_dot_n*o_dot_n/i_dot_m)));
float out_probability = distribution * m_dot_n;
float weight = i_dot_m * geometry / (i_dot_n * i_dot_m);
bool entering = dot(incoming, vertex.normal.xyz) > 0.f;
vec3 hemi = randUniformSphere(random.x, random.y);
hemi.z = abs(hemi.z);
hemi *= (entering ? 1 : -1);
float distribution = ggxDistribution(vec3(0,0,1), hemi, sampled_material.roughness);
hemi.xy *= distribution;
vec3 microsurface_normal = reflectedDirection(hemi, incoming, vertex.normal.xyz, 1);
vec3 outgoing = reflect(-incoming, microsurface_normal);
vec3 fresnel = fresnelSchlick(clamp(dot(incoming, microsurface_normal), 0, 1), normal_response);
// m is h
float n_dot_m = clamp(dot(vertex.normal.xyz, microsurface_normal), 0, 1);
float n_dot_i = clamp(dot(vertex.normal.xyz, incoming), 0, 1);
float n_dot_o = clamp(dot(vertex.normal.xyz, outgoing), 0, 1);
float i_dot_m = clamp(dot(incoming, microsurface_normal), 0, 1);
float o_dot_m = clamp(dot(outgoing, microsurface_normal), 0, 1);
float roughness2 = sampled_material.roughness * sampled_material.roughness;
float sin_theta = sqrt(1 - n_dot_o*n_dot_o);
float sin_theta_in = sqrt(1 - n_dot_i*n_dot_i);
float geometric_in = ggxPartialGeometry(incoming, vertex.normal.xyz, microsurface_normal, sampled_material.roughness);
float geometric_out = ggxPartialGeometry(incoming, vertex.normal.xyz, microsurface_normal, sampled_material.roughness);
float geometric = clamp(min(geometric_in, geometric_out), 0, 1);
// float n_dot_m2 = 2.0f * n_dot_m;
// float geom1 = (n_dot_m2 * n_dot_i) / o_dot_m;
// float geom2 = (n_dot_m2 * n_dot_o) / o_dot_m;
// float geometric = min(1.0f, min(geom1, geom2));
float denom_part = (roughness2 - 1) * (n_dot_m*n_dot_m) + 1;
float distribution_part = roughness2 / (denom_part * denom_part);
//float distribution = distribution_part * ONE_OVER_PI;
float probability_half_theta = distribution * 2 * n_dot_m;
// float distribution = ggxDistribution(vertex.normal.xyz, microsurface_normal, sampled_material.roughness);
float denominator = clamp(4 * (n_dot_i * n_dot_o), 0.05f, 1);
vec3 specular = (fresnel * geometric * distribution) / denominator;
vec3 reflection_term = fresnel * geometry * distribution / (4 * i_dot_m * o_dot_m);
BSDFResult result;
result.generated_ray = ray_in;
result.generated_ray.direction = outgoing;
result.generated_ray.origin = vertex.position.xyz + 1e-5 * outgoing;
result.radiance = fresnel * geometry;// * distribution;
result.distribution = geometry;
result.irradiance = (1-fresnel)*(1-sampled_material.metallic)*sampled_material.diffuse.rgb * ONE_OVER_PI;
// result.diffuse_ray.direction = localToWorldNormal(hemi, vertex.normal.xyz).xyz;
//result.diffuse_ray.origin = vertex.position.xyz + 1e-5f*result.diffuse_ray.direction;
result.radiance = specular;// * distribution;
result.distribution = probability_half_theta / denominator;// * mix(1, 0.5f, sampled_material.roughness);//sin_theta * ONE_OVER_PI * n_dot_o;
result.irradiance = vec3(0);//(1-fresnel)*(1-sampled_material.metallic)*sampled_material.diffuse.rgb;
result.bsdf_id = 0;
return result;
}
......
......@@ -11,13 +11,20 @@ vec3 localToWorld(const in vec3 v, const in vec3 ss, const in vec3 ts, const in
return v.x * ss + v.y * ts + v.z * ns;
}
vec3 localToWorld(const in vec3 v, const in vec3 normal, const in vec3 reflected)
{
vec3 ts = normalize(cross(normal, reflected));
vec3 sss = normalize(cross(reflected, ts));
return v.x * sss + v.y * ts + v.z * reflected;
}
vec3 localToWorldNormal(const in vec3 v, const in vec3 normal) {
vec3 perpendicular = normalize(
max(
max(
cross(normal, vec3(0.0, 1.0, 0.0)),
cross(normal, vec3(0.0, 0.0, 1.0))
),
cross(normal, vec3(0.0, 0.0, 1.0)),
cross(normal, vec3(0.0, 1.0, 0.0))
),
cross(normal, vec3(1.0, 0.0, 0.0))
)
);
......@@ -27,4 +34,4 @@ vec3 localToWorldNormal(const in vec3 v, const in vec3 normal) {
return localToWorld(v, perpendicular, secondary_perpendicular, normal); // bring vectors to local shading space
}
#endif // !__RAY_TRANSFORM_GLH
\ No newline at end of file
#endif // !__RAY_TRANSFORM_GLH
......@@ -21,8 +21,7 @@ float ggxDistribution(const in vec3 normal, const in vec3 half_view, float rough
float roughness2 = roughness * roughness;
float normal_dot_half2 = normal_dot_half * normal_dot_half;
float tan2 = (1-normal_dot_half2) / normal_dot_half2;
float denominator = normal_dot_half2 * (roughness2 + tan2);
float denominator = normal_dot_half2 * roughness2 + (1-normal_dot_half2);
return (ggxChi(normal_dot_half) * roughness2) / (GGX_PI * denominator * denominator);
}
......
......@@ -112,6 +112,7 @@ namespace glare
m_skybox = std::make_shared<core::Skybox>(core::Skybox::collectFilesFrom(files::asset("/textures/ryfjallet/")));
initializeScene(m_current_scene_root / "cbox.dae", 1.f);
//initializeScene(m_current_scene_root / "benchmark_stfd_bunny_diff.dae", 1.f);
//initializeScene(m_current_scene_root / "banni.dae", 1.f);
initializeRenderRequirements();
......
......@@ -145,7 +145,7 @@ namespace glare
BufferLight light;
light.data = m_data;
light.attenuation = m_attenuation;
light.color = m_color;
light.color = 8*m_color;
light.direction = transform * glm::vec4(0, 0, -1, 0);
light.position = transform * glm::vec4(0, 0, 0, 1);
return light;
......
......@@ -170,6 +170,7 @@ namespace glare
return *m_render_target;
m_ray_generator->generate(*this);
//return *m_render_target;
m_render_shader->use();
m_render_shader->uniform("u_render_config.current_sample", m_render_config.current_sample);
......
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