Commit 27d47ca9 authored by Johannes Braun's avatar Johannes Braun
Browse files

Reduced struct sizes; parallelized LS generation.

parent d7c31bb2
......@@ -13,14 +13,14 @@ vec3 bsdf__sampleDiffuse(const in Material material, const in vec2 random, const
vec3 hemi = randCosineHemisphere(random.x, random.y);
ray_out.direction.xyz = normalize(localToWorldNormal(entering ? hemi : -hemi, vertex.normal.xyz));
pdf = abs(dot(ray_out.direction, vertex.normal)) * ONE_OVER_PI;
pdf = abs(dot(vec4(ray_out.direction, 0), vertex.normal)) * ONE_OVER_PI;
if (pdf == 0.f)
{
return vec3(0.f);
}
ray_out.origin = vertex.position + 1e-5 * -ray_in.direction;
ray_out.origin = vertex.position.xyz + 1e-5 * -ray_in.direction;
vec3 diffuse = material__getDiffuse(material, vertex.texcoord).xyz;
......@@ -31,7 +31,7 @@ vec3 bsdf__sampleDiffuse(const in Material material, const in vec2 random, const
vec3 bsdf__sampleTranslucent(const in Material material, const in vec2 random, const in Vertex vertex, const in Ray ray_in, inout Ray ray_out, out vec3 light_influence, out float pdf)
{
bool entering = dot(-ray_in.direction, vertex.normal) > 0.f;
bool entering = dot(-ray_in.direction, vertex.normal.xyz) > 0.f;
vec3 hemi = randCosineHemisphere(random.x, random.y);
/*if (entering) {
......@@ -39,9 +39,9 @@ vec3 bsdf__sampleTranslucent(const in Material material, const in vec2 random, c
}*/
ray_out.direction.xyz =localToWorldNormal(hemi, (entering ? -1 : 1) * vertex.normal.xyz);
pdf = abs(dot(ray_out.direction, vertex.normal)) * ONE_OVER_PI;
pdf = abs(dot(ray_out.direction, vertex.normal.xyz)) * ONE_OVER_PI;
ray_out.origin = vertex.position + 1e-5f * ray_in.direction;
ray_out.origin = vertex.position.xyz + 1e-5f * ray_in.direction;
if (pdf == 0.f)
{
......@@ -58,37 +58,37 @@ vec3 bsdf__sampleTranslucent(const in Material material, const in vec2 random, c
vec3 bsdf__sampleGlass(const in Material material, const in vec2 random, const in Vertex vertex, const in Ray ray_in, inout Ray ray_out, out vec3 light_influence, out float pdf)
{
//Needed parameters for refraction and reflection
bool entering = dot(-ray_in.direction, vertex.normal) > 0.f;
bool entering = dot(-ray_in.direction, vertex.normal.xyz) > 0.f;
float eta_i = entering ? 1.f : material.ior;
float eta_t = entering ? material.ior : 1.f;
float fresnel = dialectricFresnel(abs(dot(-ray_in.direction, vertex.normal)), eta_i, eta_t);
float fresnel = dialectricFresnel(abs(dot(-ray_in.direction, vertex.normal.xyz)), eta_i, eta_t);
//refract ray.
ray_out.direction = refract(ray_in.direction, faceforward(vertex.normal, ray_in.direction, vertex.normal), eta_i / eta_t);
ray_out.direction = refract(ray_in.direction, faceforward(vertex.normal.xyz, ray_in.direction, vertex.normal.xyz), eta_i / eta_t);
light_influence = vec3(0);
// Choose whether to sample refractive or reflective BSDF
if ((ray_out.direction.xyz != vec3(0)) && (random.x > fresnel) && (!isnan(ray_out.direction.x)))
{
ray_out.origin = vertex.position + 1e-5 * ray_out.direction;
ray_out.origin = vertex.position.xyz + 1e-5 * ray_out.direction;
pdf = 1.0f - fresnel;
vec3 ft = material__getTransparent(material, vertex.texcoord).xyz * (1.0f - fresnel);
return ft / abs(dot(ray_out.direction, vertex.normal));
return ft / abs(dot(ray_out.direction, vertex.normal.xyz));
}
ray_out.direction = reflect(ray_in.direction, faceforward(vertex.normal, ray_in.direction, vertex.normal));
ray_out.origin = vertex.position + 1e-5 * ray_out.direction;
ray_out.direction = reflect(ray_in.direction, faceforward(vertex.normal.xyz, ray_in.direction, vertex.normal.xyz));
ray_out.origin = vertex.position.xyz + 1e-5 * ray_out.direction;
pdf = fresnel;
return fresnel * material__getSpecular(material, vertex.texcoord).xyz / abs(dot(ray_out.direction, vertex.normal));
return fresnel * material__getSpecular(material, vertex.texcoord).xyz / abs(dot(ray_out.direction, vertex.normal.xyz));
}
vec3 bsdf__sampleRoughGlass(const in Material material, const in vec2 random, const in Vertex vertex, const in Ray ray_in, inout Ray ray_out, out vec3 light_influence, out float pdf)
{
//Needed parameters for refraction and reflection
bool entering = dot(-ray_in.direction, vertex.normal) > 0.f;
bool entering = dot(-ray_in.direction, vertex.normal.xyz) > 0.f;
float eta_i = entering ? 1.f : material.ior;
float eta_t = entering ? material.ior : 1.f;
float fresnel = dialectricFresnel(abs(dot(-ray_in.direction, vertex.normal)), eta_i, eta_t);
float fresnel = dialectricFresnel(abs(dot(-ray_in.direction, vertex.normal.xyz)), eta_i, eta_t);
float roughness = clamp(1.f - (sqrt(material.specular_exponent) / 10.f), 0, 1);
vec3 diffuse = material__getDiffuse(material, vertex.texcoord).xyz;
......@@ -96,7 +96,7 @@ vec3 bsdf__sampleRoughGlass(const in Material material, const in vec2 random, co
light_influence = mix(vec3(0), diffuse * ONE_OVER_PI, roughness);
//refract ray.
vec3 refracted = refract(ray_in.direction, faceforward(vertex.normal, ray_in.direction, vertex.normal), eta_i / eta_t).xyz;
vec3 refracted = refract(ray_in.direction, faceforward(vertex.normal.xyz, ray_in.direction, vertex.normal.xyz), eta_i / eta_t).xyz;
// Choose whether to sample refractive or reflective BSDF
if ((refracted != vec3(0)) && (random.x > fresnel) && (!isnan(refracted.x)))
......@@ -106,57 +106,57 @@ vec3 bsdf__sampleRoughGlass(const in Material material, const in vec2 random, co
ray_out.direction.xyz = localToWorldNormal(sampledPoint, refracted);
if (dot(ray_out.direction, faceforward(vertex.normal, ray_in.direction, vertex.normal)) > 0.0f)
if (dot(ray_out.direction, faceforward(vertex.normal.xyz, ray_in.direction, vertex.normal.xyz)) > 0.0f)
{
ray_out.direction.xyz = localToWorldNormal(sampledPoint * vec3(-1, -1, 1), refracted);
}
pdf = mix(1.0f - fresnel, abs(dot(ray_out.direction, vertex.normal)) * ONE_OVER_PI, roughness);
pdf = mix(1.0f - fresnel, abs(dot(ray_out.direction, vertex.normal.xyz)) * ONE_OVER_PI, roughness);
vec3 ft = material__getTransparent(material, vertex.texcoord).xyz * (1.0f - fresnel);
ray_out.origin = vertex.position + 1e-5 * ray_out.direction;
return mix(ft / abs(dot(ray_out.direction, vertex.normal)), diffuse * ONE_OVER_PI, roughness);
ray_out.origin = vertex.position.xyz + 1e-5 * ray_out.direction;
return mix(ft / abs(dot(ray_out.direction, vertex.normal.xyz)), diffuse * ONE_OVER_PI, roughness);
}
float rad = radians(180.0f - (1.0f - roughness) * 180.0f);
vec3 reflected = reflect(ray_in.direction, faceforward(vertex.normal, ray_in.direction, vertex.normal)).xyz;
vec3 reflected = reflect(ray_in.direction, faceforward(vertex.normal.xyz, ray_in.direction, vertex.normal.xyz)).xyz;
vec3 sampledPoint = randAngle(random.x, random.y, rad);
ray_out.direction.xyz = localToWorldNormal(sampledPoint, reflected);
if (dot(ray_out.direction, faceforward(vertex.normal, ray_in.direction, vertex.normal)) < 0.0f)
if (dot(ray_out.direction, faceforward(vertex.normal.xyz, ray_in.direction, vertex.normal.xyz)) < 0.0f)
{
ray_out.direction.xyz = localToWorldNormal(sampledPoint * vec3(-1, -1, 1), reflected);
}
pdf = mix(fresnel, abs(dot(ray_out.direction, vertex.normal)) * ONE_OVER_PI, roughness);
ray_out.origin = vertex.position + 1e-5 * ray_out.direction;
return mix(fresnel * material__getSpecular(material, vertex.texcoord).xyz / abs(dot(ray_out.direction, vertex.normal)), diffuse * ONE_OVER_PI, roughness);
pdf = mix(fresnel, abs(dot(ray_out.direction, vertex.normal.xyz)) * ONE_OVER_PI, roughness);
ray_out.origin = vertex.position.xyz + 1e-5 * ray_out.direction;
return mix(fresnel * material__getSpecular(material, vertex.texcoord).xyz / abs(dot(ray_out.direction, vertex.normal.xyz)), diffuse * ONE_OVER_PI, roughness);
}
vec3 bsdf__sampleTransparent(const in Material material, const in vec2 random, const in Vertex vertex, const in Ray ray_in, inout Ray ray_out, out vec3 light_influence, out float pdf)
{
//refract ray.
ray_out.direction = ray_in.direction;
ray_out.origin = vertex.position + 1e-5 * ray_out.direction;
ray_out.origin = vertex.position.xyz + 1e-5 * ray_out.direction;
pdf = 1;
light_influence = vec3(0);
return material__getTransparent(material, vertex.texcoord).xyz / abs(dot(ray_out.direction, vertex.normal));
return material__getTransparent(material, vertex.texcoord).xyz / abs(dot(ray_out.direction, vertex.normal.xyz));
}
vec3 bsdf__sampleMirror(const in Material material, const in vec2 random, const in Vertex vertex, const in Ray ray_in, inout Ray ray_out, out vec3 light_influence, out float pdf)
{
pdf = 1.f;
ray_out.direction = reflect(ray_in.direction, faceforward(vertex.normal, ray_in.direction, vertex.normal));
ray_out.direction = reflect(ray_in.direction, faceforward(vertex.normal.xyz, ray_in.direction, vertex.normal.xyz));
light_influence = vec3(0);
ray_out.origin = vertex.position + 1e-5 * ray_out.direction;
return material__getSpecular(material, vertex.texcoord).xyz / abs(dot(ray_out.direction, vertex.normal));
ray_out.origin = vertex.position.xyz + 1e-5 * ray_out.direction;
return material__getSpecular(material, vertex.texcoord).xyz / abs(dot(ray_out.direction, vertex.normal.xyz));
}
vec3 bsdf__sampleGlossy(const in Material material, const in vec2 random, const in Vertex vertex, const in Ray ray_in, inout Ray ray_out, out vec3 light_influence, out float pdf)
{
float roughness = clamp(1.f - (sqrt(material.specular_exponent) / 10.f), 0, 1);
float rad = radians(180.0f - (1.0f - roughness) * 180.0f);
vec3 reflected = normalize(reflect(ray_in.direction, faceforward(vertex.normal, ray_in.direction, vertex.normal)).xyz);
vec3 reflected = normalize(reflect(ray_in.direction, faceforward(vertex.normal.xyz, ray_in.direction, vertex.normal.xyz)).xyz);
vec3 sampledPoint = normalize(randAngle(random.x, random.y, rad));
vec3 diffuse = material__getDiffuse(material, vertex.texcoord).xyz;
......@@ -164,23 +164,23 @@ vec3 bsdf__sampleGlossy(const in Material material, const in vec2 random, const
ray_out.direction.xyz = normalize(localToWorldNormal(sampledPoint, reflected));
if (dot(ray_out.direction, faceforward(vertex.normal, ray_in.direction, vertex.normal)) < 0.0f)
if (dot(ray_out.direction, faceforward(vertex.normal.xyz, ray_in.direction, vertex.normal.xyz)) < 0.0f)
{
ray_out.direction.xyz = normalize(localToWorldNormal(sampledPoint * vec3(-1, -1, 1), reflected));
}
ray_out.origin = vertex.position + 1e-5 * ray_out.direction;
ray_out.origin = vertex.position.xyz + 1e-5 * ray_out.direction;
pdf = 1.f - roughness * abs(dot(ray_out.direction, vertex.normal)) * ONE_OVER_PI;
pdf = 1.f - roughness * abs(dot(ray_out.direction, vertex.normal.xyz)) * ONE_OVER_PI;
return mix(material__getSpecular(material, vertex.texcoord).xyz / abs(dot(ray_out.direction, vertex.normal)), diffuse * ONE_OVER_PI, roughness);
return mix(material__getSpecular(material, vertex.texcoord).xyz / abs(dot(ray_out.direction, vertex.normal.xyz)), diffuse * ONE_OVER_PI, roughness);
}
vec3 bsdf__sampleEmissive(const in Material material, const in vec2 random, const in Vertex vertex, const in Ray ray_in, inout Ray ray_out, out vec3 light_influence, out float pdf)
{
pdf = 1.f;
ray_out.direction = vec4(0);
ray_out.direction = vec3(0);
light_influence = material__getEmissive(material, vertex.texcoord).xyz;
ray_out.origin = vertex.position + 1e-5 * ray_out.direction;
ray_out.origin = vertex.position.xyz + 1e-5 * ray_out.direction;
return vec3(0);
}
......@@ -196,7 +196,8 @@ const uint eEmissive = 1 << 16;
vec3 bsdf__sample(const in Material material, const in vec2 random, const in Vertex vertex, const in Ray ray_in, inout Ray ray_out, out vec3 light_influence, out float pdf)
{
//Kind of crude but also kind of well functional bsdf selector.
ray_out.pixel = ray_in.pixel;
ray_out.px = ray_in.px;
ray_out.py = ray_in.py;
bool rough = material.specular_exponent < 100;
uint bitset = 1; //Glossy by default.
......
......@@ -16,14 +16,11 @@ struct Patch
struct Line
{
vec4 center_begin;
vec4 center_end;
//vec4 center_begin;
//vec4 center_end;
Hit nearest;
Hit farthest;
Patch begin;
Patch end;
};
STD_BUFFER line_buffer
......@@ -49,7 +46,7 @@ void main()
Line line = b_lines[tbi_id];
vec4 last_position;
if (u_full_ls) {
/*if (u_full_ls) {
gl_Position = u_view_projection * line.center_begin;
color = vec4(0, 1, 0, 1);
EmitVertex();
......@@ -60,8 +57,8 @@ void main()
EndPrimitive();
}
else {
if (line.nearest.triangle < u_triangle_count && line.farthest.triangle < u_triangle_count) {
else {*/
if (line.nearest.barycentric.x != -1 && line.farthest.barycentric.x != -1) {
Mesh mesh = b_meshes[u_mesh];
Triangle triangle = mesh.triangles[line.nearest.triangle];
Vertex v1 = mesh.vertices[triangle.indices[1]];
......@@ -74,19 +71,16 @@ void main()
last_position = position;
color = vec4(0, 1, 0, 1);
color.b = (line.begin.face) / 6.f;
EmitVertex();
}
if (line.farthest.triangle < u_triangle_count) {
Mesh mesh = b_meshes[u_mesh];
Triangle triangle = mesh.triangles[line.farthest.triangle];
Vertex v1 = mesh.vertices[triangle.indices[1]];
Vertex v2 = mesh.vertices[triangle.indices[2]];
Vertex v3 = mesh.vertices[triangle.indices[0]];
mesh = b_meshes[u_mesh];
triangle = mesh.triangles[line.farthest.triangle];
v1 = mesh.vertices[triangle.indices[1]];
v2 = mesh.vertices[triangle.indices[2]];
v3 = mesh.vertices[triangle.indices[0]];
vec4 position = hit__getFromBarycentric(line.farthest.barycentric, triangle, position);
position = hit__getFromBarycentric(line.farthest.barycentric, triangle, position);
if (position == last_position)
{
......@@ -95,9 +89,8 @@ void main()
gl_Position = u_view_projection * position;
color = vec4(1, 0, 0, 1);
color.b = (line.end.face) / 6.f;
EmitVertex();
}
EndPrimitive();
}
//}
}
\ No newline at end of file
......@@ -113,20 +113,17 @@ struct Mesh
struct Ray
{
vec4 direction;
vec4 origin;
vec2 pixel;
vec2 padding;
vec3 direction;
float px;
vec3 origin;
float py;
};
struct Hit
{
vec3 barycentric;
vec2 barycentric;
uint triangle;
uint mesh;
uint padding[2];
};
struct Trace
......
......@@ -14,12 +14,14 @@ uniform struct
Ray camera__getRayFromPixel(const in vec2 pixel, const in vec2 sub_pixel)
{
Ray ray;
ray.origin = vec4(u_camera.position, 1);
ray.direction = vec4(u_camera.bottom_left +
ray.origin = u_camera.position;
ray.direction = u_camera.bottom_left +
(pixel.x + sub_pixel.x) * u_camera.axis_x_scaled +
(pixel.y + sub_pixel.y) * u_camera.axis_y_scaled -
u_camera.position, 0);
ray.pixel = pixel + sub_pixel;
u_camera.position;
vec2 final_pixel = pixel + sub_pixel;
ray.px = final_pixel.x;
ray.py = final_pixel.y;
return ray;
}
......
......@@ -10,7 +10,6 @@
#include <raytracer/camera.glh>
layout(rgba32f) uniform readonly image2D u_gbuffer_texture_01;
layout(rgba32f) uniform readonly image2D u_gbuffer_texture_02;
layout(local_size_variable) in;
......@@ -23,16 +22,15 @@ void main()
ivec2 target_size = camera__renderTargetSize();
vec2 pixel = vec2(id%target_size.x, id/target_size.x);
vec4 texel_01 = imageLoad(u_gbuffer_texture_01, ivec2(pixel));
vec4 texel_02 = imageLoad(u_gbuffer_texture_02, ivec2(pixel));
b_traces[id].ray = camera__getRayFromPixel(pixel, rand2D(random_seed + int(id)));
hit__invalidate(b_traces[id].hit);
if (length(texel_01) != 0) {
b_traces[id].hit.barycentric = texel_01.xyz;
b_traces[id].hit.triangle = uint(texel_01.w);
b_traces[id].hit.mesh = uint(texel_02.x);
b_traces[id].hit.barycentric = texel_01.xy;
b_traces[id].hit.triangle = uint(texel_01.z);
b_traces[id].hit.mesh = uint(texel_01.w);
}
}
}
\ No newline at end of file
......@@ -6,10 +6,8 @@ in flat uint triangle_id;
uniform uint u_mesh_id;
layout(location = 0) out vec4 out_data_01; // contains the barycentric coordinate and the triangle id
layout(location = 1) out vec4 out_data_02; // contains the mesh id and.... well... nothing else yet.
void main()
{
out_data_01 = vec4(barycentric, triangle_id);
out_data_02 = vec4(u_mesh_id, 0, 0, 0);
out_data_01 = vec4(barycentric.xy, triangle_id, u_mesh_id);
}
......@@ -21,8 +21,8 @@ bool traverse(const in uint mesh_id, const in Ray ray, inout Hit hit, const in b
//For ease of use, substitute Ray<->OBB for Ray<->AABB by transforming the ray into object space.
Ray ray_in = ray;
ray_in.direction = vec4(normalize(mat3(mesh.inverse_transformation) * ray_in.direction.xyz), 0);
ray_in.origin = mesh.inverse_transformation * vec4(ray_in.origin.xyz, 1);
ray_in.direction = normalize(mat3(mesh.inverse_transformation) * ray_in.direction.xyz);
ray_in.origin = (mesh.inverse_transformation * vec4(ray_in.origin.xyz, 1)).xyz;
// Check once the AABB for the whole scene
bool hit_scene = intersectsRayBounds(ray_in, getNodeBounds(0, mesh), max_distance);
......@@ -93,7 +93,7 @@ bool traverse(const in uint mesh_id, const in Ray ray, inout Hit hit, const in b
return true;
}
hit.barycentric = vec3(u, v, 1 - u - v);
hit.barycentric = vec2(u, v);
hit.triangle = i;
hit.mesh = mesh_id;
}
......
......@@ -38,7 +38,7 @@ bool shade(int id, inout vec3 weight)
//Sample environment when not hitting anything.
if(hit__isNotValid(hit))
{
imageAdd(u_color_store, ivec2(ray.pixel), vec4(c_inv_color_scale_factor * environment__sample(ray.direction.xyz).xyz * weight, 1));
imageAdd(u_color_store, ivec2(ray.px, ray.py), vec4(c_inv_color_scale_factor * environment__sample(ray.direction.xyz).xyz * weight, 1));
return false;
}
......@@ -46,7 +46,7 @@ bool shade(int id, inout vec3 weight)
Material material;
Vertex vertex = hit__getVertex(hit, material);
vec4 diffuse = material__getDiffuse(material, vertex.texcoord);
vec2 random_sample = ray.pixel - ivec2(ray.pixel);
vec2 random_sample = vec2(ray.px, ray.py) - ivec2(ray.px, ray.py);
//Sample BSDF
float pdf;
......@@ -54,16 +54,16 @@ bool shade(int id, inout vec3 weight)
Ray out_ray;
vec3 reflectance = bsdf__sample(material, random_sample, vertex, ray, out_ray, light_influence, pdf);
if(out_ray.direction == vec4(0))
if(out_ray.direction == vec3(0))
{
// Treat as emissive material.
imageAdd(u_color_store, ivec2(ray.pixel), vec4(c_inv_color_scale_factor * weight * light_influence, 1.f));
imageAdd(u_color_store, ivec2(ray.px, ray.py), vec4(c_inv_color_scale_factor * weight * light_influence, 1.f));
hit__invalidate(b_traces[id].hit);
return false;
}
//Add ambient color
imageAdd(u_color_store, ivec2(ray.pixel), vec4(c_inv_color_scale_factor * vec3(0.0f) * light_influence * weight * ONE_OVER_PI, 1));
imageAdd(u_color_store, ivec2(ray.px, ray.py), vec4(c_inv_color_scale_factor * vec3(0.0f) * light_influence * weight * ONE_OVER_PI, 1));
if (b_lights.length() > 0) {
//Select random light... well... at least if there are any.
......@@ -71,15 +71,15 @@ bool shade(int id, inout vec3 weight)
//Shadow test
Ray shadow_test;
shadow_test.origin = vertex.position + 1e-5*vertex.normal;
shadow_test.direction = normalize((light.position + vec4(randUniformSphere(random_sample), 0)*light.data[0]) - vertex.position);
shadow_test.origin = vertex.position.xyz + 1e-5*vertex.normal.xyz;
shadow_test.direction = normalize((light.position.xyz + randUniformSphere(random_sample)*light.data[0]) - vertex.position.xyz);
if (!bvh__intersectsAny(shadow_test, distance(light.position, vertex.position + 1e-5*vertex.normal)))
{
//TODO: only point light for now.
float angle = abs(dot(shadow_test.direction, vertex.normal));
float angle = abs(dot(shadow_test.direction, vertex.normal.xyz));
float dist = distance(light.position, vertex.position);
float attenuation = 1 / (light.constant + dist*light.linear + pow(dist, 2)*light.quadratic);
imageAdd(u_color_store, ivec2(ray.pixel), vec4(c_inv_color_scale_factor * weight * light.color.rgb * light_influence * angle * attenuation, 1.f));
imageAdd(u_color_store, ivec2(ray.px, ray.py), vec4(c_inv_color_scale_factor * weight * light.color.rgb * light_influence * angle * attenuation, 1.f));
}
}
......@@ -91,7 +91,7 @@ bool shade(int id, inout vec3 weight)
}
b_traces[id].ray = out_ray;
weight *= reflectance * abs(dot(out_ray.direction, vertex.normal)) / pdf;
weight *= reflectance * abs(dot(out_ray.direction, vertex.normal.xyz)) / pdf;
return true;
}
......@@ -128,7 +128,7 @@ void main()
//Divide color storage by sample count to retrieve the final color.
imageStore(
u_render_target,
ivec2(b_traces[id].ray.pixel),
c_color_scale_factor * imageLoad(u_color_store, ivec2(b_traces[id].ray.pixel)) / (u_render_config.current_sample+1)
ivec2(b_traces[id].ray.px, b_traces[id].ray.py),
c_color_scale_factor * imageLoad(u_color_store, ivec2(b_traces[id].ray.px, b_traces[id].ray.py)) / (u_render_config.current_sample+1)
);
}
\ No newline at end of file
......@@ -34,7 +34,7 @@ vec4 material__getEmissive(const in Material material, const in vec2 texcoord)
#define hit__invalidate(hit) (hit.barycentric.x = -1)
#define hit__getFromBarycentric(barycentric, triangle, param) (barycentric.x * v1.param + \
barycentric.y * v2.param + \
barycentric.z * v3.param)
(1-barycentric.x-barycentric.y) * v3.param)
#define photon__isNotValid(photon) (photon.ray_direction.w == -1)
#define photon__invalidate(photon) (photon.ray_direction.w = -1)
......
......@@ -47,7 +47,7 @@ namespace glare
//Create a skybox from cube map.
m_skybox = std::make_shared<core::Skybox>(core::Skybox::collectFilesFrom(core::asset("/textures/ryfjallet/")));
initializeScene(core::asset("/meshes/scenery/floored_bunny.dae"), 1.f);
initializeScene(core::asset("/meshes/scenery/cube.dae"), 1.f);
initializeRenderRequirements();
initializeAdvanced();
initializeGUI();
......@@ -70,7 +70,7 @@ namespace glare
unsigned line_mesh_id = 0;
const auto &mesh_collector = m_collector->meshCollectors().at(line_mesh_id);
int ls_resolution = 5;
int ls_resolution = 6;
ls::LineSpace linespace(*mesh_collector, ls_resolution);
std::vector<std::shared_ptr<core::Shader>> shaders = {
......@@ -119,21 +119,11 @@ namespace glare
{
m_collector->collect();
static bool u_full_ls = true;
ImGui::Begin("LineSpace");
ImGui::Checkbox("Show full LS", &u_full_ls);
ImGui::DragInt("Max. Subdivision", &ls_resolution);
if (ImGui::Button("Rebuild with Settings")) {
linespace.generate(*mesh_collector, ls_resolution);
}
ImGui::End();
lines_program->use();
lines_program->updateStorageBuffer("mesh_buffer", m_collector->meshBuffer());
lines_program->updateStorageBuffer("line_buffer", linespace.lineBuffer());
lines_program->updateUniformInt("u_full_ls", int(u_full_ls));
//lines_program->updateUniformInt("u_full_ls", int(u_full_ls));
lines_program->updateUniformUInt("u_mesh", line_mesh_id);
lines_program->updateUniformUInt("u_triangle_count", unsigned(mesh_collector->triangles().size()));
......@@ -155,6 +145,18 @@ namespace glare
ImGui::End();
drawSceneSelector();
//static bool u_full_ls = true;
ImGui::Begin("LineSpace");
//ImGui::Checkbox("Show full LS", &u_full_ls);
ImGui::DragInt("Max. Subdivision", &ls_resolution);
if (ImGui::Button("Rebuild with Settings")) {
linespace.generate(*mesh_collector, ls_resolution);
}
ImGui::End();
ImGui::Render();
core::LightManager::getInstance().clear();
......
......@@ -493,7 +493,7 @@ namespace glare
return true;
}
hit.barycentric = glm::vec3(u, v, 1 - u - v);
hit.barycentric = glm::vec2(u, v);
hit.triangle = i;
hit.mesh = 0;
}
......@@ -501,7 +501,7 @@ namespace glare
if (also_farthest && t > t_max) {
t_max = t;
hit_farthest.barycentric = glm::vec3(u, v, 1 - u - v);
hit_farthest.barycentric = glm::vec2(u, v);
hit_farthest.triangle = i;
hit_farthest.mesh = 0;
}
......
......@@ -59,7 +59,6 @@ namespace glare
m_last_height = raytracer.height();
m_framebuffer = std::make_unique<core::Framebuffer>(raytracer.width(), raytracer.height());
m_framebuffer->addAttachment(gl::Attachment::eColor0);
m_framebuffer->addAttachment(gl::Attachment::eColor1);
m_framebuffer->addAttachment(gl::Attachment::eDepth);
}
......@@ -87,7 +86,6 @@ namespace glare
core::OpenGLState::reset();
m_buffer_depthtest->updateUniformImageRGBA32F("u_gbuffer_texture_01", m_framebuffer->getColorAttachment(0), gl::Access::eReadOnly);
m_buffer_depthtest->updateUniformImageRGBA32F("u_gbuffer_texture_02", m_framebuffer->getColorAttachment(1), gl::Access::eReadOnly);
m_buffer_depthtest->updateUniformImageRGBA32F("u_render_target", raytracer.renderTarget(), gl::Access::eReadWrite);
m_buffer_depthtest->updateStorageBuffer("trace_buffer", raytracer.traceBuffer());
m_buffer_depthtest->updateUniformStruct("u_camera", raytracer.collector()->getActiveCamera());
......
......@@ -204,21 +204,19 @@ namespace glare
struct Ray
{
glm::vec4 direction;
glm::vec4 origin;
glm::ivec2 pixel;
glm::vec2 padding;
glm::vec3 direction;
float px;
glm::vec3 origin;
float py;
};
struct Hit
{
glm::vec3 barycentric;
glm::vec2 barycentric;
glm::uint triangle;
glm::uint mesh;
glm::uint padding[3];
};
struct Bounds
{
glm::vec4 min;
......
#include "LineSpace.h"
#include <engine/Time.h>
#include <omp.h>
namespace glare
{
......@@ -57,36 +58,44 @@ namespace glare
Log_Info << "Linespace is being generated now...";
//Loop through all possible and useful startface-endface-configurations
for (line.begin = Patch(Face::ePosX); line.begin.face < Face::eNegZ; line.begin.face = Face(unsigned(line.begin.face) + 1))
for (line.end = Patch(Face(unsigned(line.begin.face) + 1)); line.end.face <= Face::eNegZ; line.end.face = Face(unsigned(line.end.face) + 1)) {
Log_Info << "Working on lines between Faces " << unsigned(line.begin.face) << " and " << unsigned(line.end.face) << "...";
//This loop is parallelized for CPUs with under 16 logical cores.
#pragma omp parallel for
for (int config = 0; config < 15; ++config) {
Patch begin = c_start_end_patches[config].first;
Patch end = c_start_end_patches[config].second;
#pragma omp critical
{
Log_Info << "Working on lines between Faces " << unsigned(begin.face) << " and " << unsigned(end.face) << "...";
}
//For all start patches...
for (line.begin.index_horizontal = 0; line.begin.index_horizontal < face_widths[unsigned(line.begin.face) % 3]; ++line.begin.index_horizontal)
for (line.begin.index_vertical = 0; line.begin.index_vertical < face_heights[unsigned(line.begin.face) % 3]; ++line.begin.index_vertical)
{
//... and all end patches...
for (line.end.index_horizontal = 0; line.end.index_horizontal < face_widths[unsigned(line.end.face) % 3]; ++line.end.index_horizontal)
for (line.end.index_vertical