Commit 24753245 authored by Johannes Braun's avatar Johannes Braun
Browse files

Some more fixing around. Still shows weirdness.

parent fff8906b
......@@ -82,7 +82,7 @@ BSDFResult computeBSDF(const in Material material, const in vec2 random, const i
HemisphereSample hemisphere_sample = ggxSample(random, sampled_material.roughness);
// Turn around normal if looking at it from the backside
vec3 normal = faceforward(vertex.normal.xyz, -incoming, vertex.normal.xyz);
vec3 normal = vertex.normal.xyz;//faceforward(vertex.normal.xyz, -incoming, vertex.normal.xyz);
// Compute needed refraction values
bool enters = dot(incoming, vertex.normal.xyz) > 0;
......@@ -91,7 +91,8 @@ BSDFResult computeBSDF(const in Material material, const in vec2 random, const i
float eta = ior_in / ior_out;
// Transform the computed local microsurface normal to world space along the hit normal
vec3 micro_normal = normalize(localToWorld(hemisphere_sample.micro_normal, incoming, normal));
vec3 micro_normal = normalize(localToWorld(hemisphere_sample.micro_normal, normal));
micro_normal = dot(micro_normal, incoming) < 0 ? reflect(-micro_normal, normal) : micro_normal;
// Schlick's fresnel approximation with the material's normal response
float normal_response = normalResponse(sampled_material.ior, sampled_material.metallic);
......@@ -110,12 +111,12 @@ BSDFResult computeBSDF(const in Material material, const in vec2 random, const i
{
// Sample lambertian diffuse
result.evaluation = (1-sampled_material.metallic)*sampled_material.base * ONE_OVER_PI;
result.generated_ray.direction = normalize(localToWorld(randCosineHemisphere(random.x, random.y), incoming, normal));
result.generated_ray.direction = normalize(localToWorld(randCosineHemisphere(random.x, random.y), normal));
result.probability_density = abs(dot(vec4(result.generated_ray.direction, 0), vertex.normal)) * ONE_OVER_PI;
result.radiance = (1-sampled_material.metallic)*sampled_material.base * ONE_OVER_PI;
result.bsdf_id = eDiffuse;
// offset by newly generated direction
result.generated_ray.origin = vertex.position.xyz + 1e-5f * result.generated_ray.direction;
result.generated_ray.origin = vertex.position.xyz + 1e-3f * result.generated_ray.direction;
return result;
}
......@@ -142,22 +143,22 @@ BSDFResult computeBSDF(const in Material material, const in vec2 random, const i
// 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 / (4 * m_dot_out);
float jacobian_reflect = 1 / max(abs(4 * m_dot_out), 0.00001f);
float probability_m = hemisphere_sample.distribution * cos_theta;
float pdf = probability_m * jacobian_reflect;
// Same as above but for refractions
float ior_out_2 = ior_out * ior_out;
float jacobian_refract_denominator = ior_in * m_dot_in + ior_out * m_dot_out_refract;
float jacobian_refract_denominator = ior_in * m_dot_in + ior_out * abs(m_dot_out_refract);
jacobian_refract_denominator *= jacobian_refract_denominator;
jacobian_refract_denominator = clamp(jacobian_refract_denominator, 0.0000000001f, 1.f);
jacobian_refract_denominator = max(jacobian_refract_denominator, 0.00001f);
//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 = 4 * m_dot_in * m_dot_out;
float brdf_denominator = 4 * abs(m_dot_in) * abs(m_dot_out);
float btdf_denominator = jacobian_refract_denominator;
// Finally, build the brdf. As we do russian roulette, we can just tint the brdf instead of multiplying with the fresnel value.
......
......@@ -81,7 +81,7 @@ vec4 phong(const in Material material, const in LightShadow light_and_map, sampl
float k_t = (1-k_s) * material.transmission.value;
float k_d = 1 - k_s - k_t;
return vec4(k_d * (phong_diffuse + material.base.value * textureLod(environment, normal, 8).rgb) + k_t * environment_refract + k_s * (environment_reflect + phong_specular), 1);
return vec4(k_d * (phong_diffuse + material.base.value * textureLod(environment, normal, 16).rgb) + k_t * environment_refract + k_s * (environment_reflect + phong_specular), 1);
}
#endif // !__GBUFFER_LIGHTS_GLH
......@@ -9,4 +9,23 @@ const float UINT_MAX = 4294967295.0;
const float PI = 3.1415926535897932384626433832795;
const float ONE_OVER_PI = 1/PI;
const vec2 poissonDisk[16] = vec2[](
vec2(0.1505688f, 0.9006551f),
vec2(-0.01351117f, 0.3535984f),
vec2(0.4001779f, 0.5178972f),
vec2(-0.440886f, 0.4302851f),
vec2(-0.4160731f, 0.8641366f),
vec2(0.9662936f, 0.02506917f),
vec2(0.4277292f, -0.007689635f),
vec2(0.794787f, 0.5989406f),
vec2(-0.7394559f, -0.1354285f),
vec2(-0.6448742f, -0.7343334f),
vec2(-0.2089914f, -0.6586035f),
vec2(-0.3510948f, 0.04614406f),
vec2(0.3864633f, -0.696366f),
vec2(0.6720468f, -0.3266357f),
vec2(-0.8208213f, 0.4652553f),
vec2(0.111697f, -0.2986286f)
);
#endif //!INCLUDE_UTIL_CONSTANTS_GLSL
......@@ -66,17 +66,17 @@ void expand(inout Bounds bounds, const in vec3 include)
bounds.max = max(bounds.max, vec4(include, 0));
}
vec3 localToWorld(const in vec3 vector, const in vec3 view, const in vec3 n) {
vec3 localToWorld(const in vec3 vector, const in vec3 normal) {
// Find an axis that is not parallel to normal
vec3 normal = faceforward(n, -view, n);
vec3 majorAxis = mix(vec3(0, 0, 1), vec3(1, 0, 0), dot(normal, vec3(0, 0, 1)));
vec3 majorAxis;
majorAxis = normalize(mix(vec3(0, 1, 0), vec3(0, 0, 1), abs(dot(normal, vec3(0, 1, 0)))));
// Use majorAxis to create a coordinate system relative to world space
vec3 u = normalize(cross(normal, majorAxis));
vec3 v = cross(normal, u);
vec3 w = normal;
// return vector;// u+v+w;
// Transform from local coordinates to world coordinates
return normalize(u * vector.x +
v * vector.y +
......
......@@ -78,8 +78,8 @@ float ggxDistribution(float cosT, float roughness)
// Half of the full ggx geometry attenuation term
float ggxPartialGeometry(const in vec3 vector, const in vec3 normal, const in vec3 half_view, float roughness)
{
float eye_dot_half2 = clamp(dot(vector, half_view), -1, 1);
float chi = ggxChi(eye_dot_half2 / clamp(dot(vector, normal), -1, 1));
float eye_dot_half2 = dot(vector, half_view);
float chi = ggxChi(eye_dot_half2 / dot(vector, normal));
eye_dot_half2 = eye_dot_half2 * eye_dot_half2;
float tan2 = (1 - eye_dot_half2) / eye_dot_half2;
......@@ -91,7 +91,7 @@ float ggxGeometry(const in vec3 vector_in, const in vec3 vector_out, const in ve
{
float geom_in = ggxPartialGeometry(vector_in, normal, half_view, roughness);
float geom_out = ggxPartialGeometry(vector_out, normal, half_view, roughness);
return clamp(geom_in * geom_out, 0, 1);
return geom_in * geom_out;
}
// Samples an importance sample, a z-up local microsurface normal and the fitting normal distribution
......
......@@ -115,7 +115,7 @@ float rand(int seed)
}
vec2 rand2D(int seed, int samples){
return hammersley2d(uint(rand(seed) * samples), 1/float(samples));
return hammersley2d(uint(clamp(rand(seed), 0.f, 1.f) * samples), 1/float(samples));
}
#endif //!INCLUDE_UTIL_RANDOM_GLSL
#ifndef INCLUDE_UTIL_LIGHT_GLSL
#define INCLUDE_UTIL_LIGHT_GLSL
#include <util/math/constants.glsl>
#include <util/math/random.glsl>
const float DIRECTIONAL_DISTANCE = 1000000.f;
......@@ -90,25 +91,6 @@ struct LightShadow
ShadowMap shadow_map;
};
const vec2 poissonDisk[16] = vec2[](
vec2(0.1505688f, 0.9006551f),
vec2(-0.01351117f, 0.3535984f),
vec2(0.4001779f, 0.5178972f),
vec2(-0.440886f, 0.4302851f),
vec2(-0.4160731f, 0.8641366f),
vec2(0.9662936f, 0.02506917f),
vec2(0.4277292f, -0.007689635f),
vec2(0.794787f, 0.5989406f),
vec2(-0.7394559f, -0.1354285f),
vec2(-0.6448742f, -0.7343334f),
vec2(-0.2089914f, -0.6586035f),
vec2(-0.3510948f, 0.04614406f),
vec2(0.3864633f, -0.696366f),
vec2(0.6720468f, -0.3266357f),
vec2(-0.8208213f, 0.4652553f),
vec2(0.111697f, -0.2986286f)
);
////////////////////////////////////////////////////////////////////
////
//// UTILITY FUNCTIONS
......
......@@ -98,11 +98,6 @@ namespace glare
float getDistanceThreshold() const;
void setDistanceThreshold(float distance_threshold);
private:
uint32_t m_last_width = 0;
uint32_t m_last_height = 0;
struct {
unsigned current_sample = 0;
unsigned max_samples = 80000;
......@@ -112,6 +107,11 @@ namespace glare
float clamp_indirect = 10.f;
} m_render_config;
private:
uint32_t m_last_width = 0;
uint32_t m_last_height = 0;
struct {
float accuracy_threshold;
float shadow_threshold;
......
Supports Markdown
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