Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Johannes Braun
glare
Commits
24753245
Commit
24753245
authored
Aug 09, 2017
by
Johannes Braun
Browse files
Some more fixing around. Still shows weirdness.
parent
fff8906b
Changes
8
Hide whitespace changes
Inline
Side-by-side
assets/shaders/pathtracer/bsdf.glsl
View file @
24753245
...
...
@@ -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-
5
f
*
result
.
generated_ray
.
direction
;
result
.
generated_ray
.
origin
=
vertex
.
position
.
xyz
+
1e-
3
f
*
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
.
00001
f
)
;
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
.
0000
000001
f
,
1
.
f
);
jacobian_refract_denominator
=
max
(
jacobian_refract_denominator
,
0
.
0000
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
=
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.
...
...
assets/shaders/screenshader/gbuffer/gbuffer_lights.glsl
View file @
24753245
...
...
@@ -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
assets/shaders/util/math/constants.glsl
View file @
24753245
...
...
@@ -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
.
1505688
f
,
0
.
9006551
f
),
vec2
(
-
0
.
01351117
f
,
0
.
3535984
f
),
vec2
(
0
.
4001779
f
,
0
.
5178972
f
),
vec2
(
-
0
.
440886
f
,
0
.
4302851
f
),
vec2
(
-
0
.
4160731
f
,
0
.
8641366
f
),
vec2
(
0
.
9662936
f
,
0
.
02506
917
f
),
vec2
(
0
.
4277292
f
,
-
0
.
0076
89635
f
),
vec2
(
0
.
794787
f
,
0
.
5989406
f
),
vec2
(
-
0
.
7394559
f
,
-
0
.
1354285
f
),
vec2
(
-
0
.
6448742
f
,
-
0
.
7343334
f
),
vec2
(
-
0
.
2089914
f
,
-
0
.
6586035
f
),
vec2
(
-
0
.
3510948
f
,
0
.
04614406
f
),
vec2
(
0
.
3864633
f
,
-
0
.
696366
f
),
vec2
(
0
.
6720468
f
,
-
0
.
3266357
f
),
vec2
(
-
0
.
8208213
f
,
0
.
4652553
f
),
vec2
(
0
.
111697
f
,
-
0
.
2986286
f
)
);
#endif //!INCLUDE_UTIL_CONSTANTS_GLSL
assets/shaders/util/math/geometry.glsl
View file @
24753245
...
...
@@ -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
+
...
...
assets/shaders/util/math/ggx.glsl
View file @
24753245
...
...
@@ -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
...
...
assets/shaders/util/math/random.glsl
View file @
24753245
...
...
@@ -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
assets/shaders/util/scene/light.glsl
View file @
24753245
#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
.
1505688
f
,
0
.
9006551
f
),
vec2
(
-
0
.
01351117
f
,
0
.
3535984
f
),
vec2
(
0
.
4001779
f
,
0
.
5178972
f
),
vec2
(
-
0
.
440886
f
,
0
.
4302851
f
),
vec2
(
-
0
.
4160731
f
,
0
.
8641366
f
),
vec2
(
0
.
9662936
f
,
0
.
02506
917
f
),
vec2
(
0
.
4277292
f
,
-
0
.
0076
89635
f
),
vec2
(
0
.
794787
f
,
0
.
5989406
f
),
vec2
(
-
0
.
7394559
f
,
-
0
.
1354285
f
),
vec2
(
-
0
.
6448742
f
,
-
0
.
7343334
f
),
vec2
(
-
0
.
2089914
f
,
-
0
.
6586035
f
),
vec2
(
-
0
.
3510948
f
,
0
.
04614406
f
),
vec2
(
0
.
3864633
f
,
-
0
.
696366
f
),
vec2
(
0
.
6720468
f
,
-
0
.
3266357
f
),
vec2
(
-
0
.
8208213
f
,
0
.
4652553
f
),
vec2
(
0
.
111697
f
,
-
0
.
2986286
f
)
);
////////////////////////////////////////////////////////////////////
////
//// UTILITY FUNCTIONS
...
...
src/libraries/raytrace/tracer/pathtracer.h
View file @
24753245
...
...
@@ -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
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment