Commit 1d2af4a8 authored by Johannes Braun's avatar Johannes Braun
Browse files

Reformatted shader program

parent 02aa841f
<linespace version="1.0">
<item name="subdivisions" value="20"/>
<item name="radial-subdivision" value="40"/>
<item name="subdivisions" value="2"/>
<item name="radial-subdivision" value="2"/>
<item name="generator" value="gpu"/>
</linespace>
......@@ -8,8 +8,8 @@
layout(local_size_variable) in;
#include <raytracer/basic_structs.glh>
#include <raytracer/utilities.glh>
#include <raytracer/basic_structs.glsl>
#include <raytracer/utilities.glsl>
#define FACE_BIAS 0.003
#define T_MIN_BIAS 0.0001
......@@ -77,7 +77,7 @@ struct StackElement
bool lspace_intersectsAny(const in Ray ray, const in float max_t, inout uint voxel_index, inout vec4 debug_color)
{
//TODO: FIX!
//Why? Somewhere in here there is a HUGE buffer overflow. At least I think so. It may also be some kind of indetermined loop or something of that I can't think right now.
return false;
......@@ -117,7 +117,7 @@ bool lspace_intersectsAny(const in Ray ray, const in float max_t, inout uint vox
//if (faceIsPlausible(start_position[i]) || faceIsPlausible(start_position[i] - u_linespace.resolution)) stack[0].sFaceIndex = i;
stack[0].start_face_index = max(stack[0].start_face_index + 1, (i + 1) * int(faceIsPlausible(start_position[i]) || faceIsPlausible(start_position[i] - u_linespace.resolution))) - 1;
}
//Now, the start face index is -1, if the ray begins inside the voxel, otherwise it is between 0 and 2
//Temporary variables used when traversing.
......@@ -148,8 +148,8 @@ bool lspace_intersectsAny(const in Ray ray, const in float max_t, inout uint vox
Voxel current_voxel = u_ntree.voxels[stack[last_stack_depth].node_index];
bool has_children = current_voxel.children.min != 0;
int next_node_index = int(current_voxel.children.min)
+ stack[last_stack_depth].current_index.z * int(u_linespace.resolution_pow2)
+ stack[last_stack_depth].current_index.y * int(u_linespace.resolution)
+ stack[last_stack_depth].current_index.z * int(u_linespace.resolution_pow2)
+ stack[last_stack_depth].current_index.y * int(u_linespace.resolution)
+ stack[last_stack_depth].current_index.x;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// DEBUG
......@@ -157,9 +157,9 @@ bool lspace_intersectsAny(const in Ray ray, const in float max_t, inout uint vox
return false;*/
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
stack[last_stack_depth].end_face_index = max(0,
stack[last_stack_depth].end_face_index = max(0,
int(stack[last_stack_depth].t_next.y < stack[last_stack_depth].t_next.x && stack[last_stack_depth].t_next.y < stack[last_stack_depth].t_next.z));
stack[last_stack_depth].end_face_index = max(stack[last_stack_depth].end_face_index,
stack[last_stack_depth].end_face_index = max(stack[last_stack_depth].end_face_index,
2*int(stack[last_stack_depth].t_next.y < stack[last_stack_depth].t_next.x && stack[last_stack_depth].t_next.y < stack[last_stack_depth].t_next.z));
if(!has_children)
......@@ -169,7 +169,7 @@ bool lspace_intersectsAny(const in Ray ray, const in float max_t, inout uint vox
//if (stack[tempStackDepth].tMin > (currNode.childrenSize.x*2.0f)) return true;
//Traverse candidates if needed.
}
}
else
{
bool continue_traversal = false;
......@@ -252,4 +252,4 @@ bool lspace_intersectsAny(const in Ray ray, const in float max_t, inout uint vox
return false;
}
#endif //!__LINESPACE_GLH
\ No newline at end of file
#endif //!__LINESPACE_GLH
#version 430
#extension GL_ARB_shading_language_include : require
#include <raytracer/std.glh>
#include <raytracer/basic_structs.glh>
#include <raytracer/buffers.glh>
#include <raytracer/utilities.glh>
#include <raytracer/std.glsl>
#include <raytracer/basic_structs.glsl>
#include <raytracer/buffers.glsl>
#include <raytracer/utilities.glsl>
struct Patch
{
......@@ -93,4 +93,4 @@ void main()
}
EndPrimitive();
//}
}
\ No newline at end of file
}
#ifndef __GL_BUFFERS
#define __GL_BUFFERS
#include <raytracer/std.glh>
#include <raytracer/std.glsl>
STD_BUFFER lights_buffer
{
......@@ -28,9 +28,9 @@ STD_BUFFER_R material_buffer
Material b_materials[];
};
STD_BUFFER trace_buffer
STD_BUFFER trace_buffer
{
Trace b_traces[];
};
#endif //__GL_BUFFERS
\ No newline at end of file
#endif //__GL_BUFFERS
#ifdef __GL_BVH
#define __GL_BVH
#include <raytracer/basic_structs.glh>
#include <raytracer/buffers.glh>
#include <raytracer/intersections.glh>
#include <raytracer/std.glh>
#include <raytracer/basic_structs.glsl>
#include <raytracer/buffers.glsl>
#include <raytracer/intersections.glsl>
#include <raytracer/std.glsl>
struct BVHNode
{
......@@ -15,7 +15,7 @@ struct BVHNode
uint parent;
};
STD_BUFFER_R bvh_node_buffer
STD_BUFFER_R bvh_node_buffer
{
BVHNode b_bvh_nodes[];
};
......@@ -26,7 +26,7 @@ bool traverse(const in Ray ray, inout Hit hit, const in bool nearest_only, const
{
float t = 0;
float t_min = FLT_MAX;
// Check once the AABB for the whole scene
bool hit_scene = intersectsRayBounds(ray, b_bvh_nodes[0].bounds);
bool hit_triangle = false;
......@@ -48,7 +48,7 @@ bool traverse(const in Ray ray, inout Hit hit, const in bool nearest_only, const
//both hit
if (hit_left && hit_right)
{
// shift bitstack and mark as branched, so we can use the marker
// shift bitstack and mark as branched, so we can use the marker
// when backtracking to stop here and use the right child.
bitstack = bitstack << 1;
current_node = id_left;
......@@ -140,4 +140,4 @@ bool bvh__intersectsAny(const in Ray ray, const in float max_distance)
return traverse(ray, unused_hit, true, max_distance);
}
#endif //__GL_BVH
\ No newline at end of file
#endif //__GL_BVH
#ifndef __GL_LINESPACE
#define __GL_LINESPACE
#include <raytracer/basic_structs.glh>
#include <raytracer/buffers.glh>
#include <raytracer/intersections.glh>
#include <raytracer/std.glh>
#include <raytracer/utilities.glh>
#include <raytracer/basic_structs.glsl>
#include <raytracer/buffers.glsl>
#include <raytracer/intersections.glsl>
#include <raytracer/std.glsl>
#include <raytracer/utilities.glsl>
const uint face_width_axis[3] = {2, 2, 0};
const uint face_height_axis[3] = {1, 0, 1};
......@@ -43,7 +43,7 @@ struct PatchInfo
float t;
};
const uint m_radial_subdivisions = 40; //TODO: put into ssbo
const uint m_radial_subdivisions = 2; //TODO: put into ssbo
uint id_from_direction(vec3 direction, uint quarter_subdivision, uint axis_up, uint axis_horizontal, uint axis_vertical)
{
......@@ -80,10 +80,12 @@ uint lineIndex(const in Ray ray, const in Mesh mesh, float t, int face, bool rev
vec3 direction = ray.direction;
//direction *= (face > 2) ? -1 : 1;
direction *= (face > 2) ? -1 : 1;
direction *= (reverse) ? -1 : 1;
//direction[face % 3] *= 1.5f;
//direction[face % 3] *= (dot(face_normal, direction) < 0) ? -1 : 1;
// float dir1 = dot(direction, vec3(0, 1, 0));
......
#ifndef __GL_BVH
#define __GL_BVH
#include <raytracer/basic_structs.glh>
#include <raytracer/buffers.glh>
#include <raytracer/intersections.glh>
#include <raytracer/std.glh>
#include <raytracer/utilities.glh>
#include <raytracer/basic_structs.glsl>
#include <raytracer/buffers.glsl>
#include <raytracer/intersections.glsl>
#include <raytracer/std.glsl>
#include <raytracer/utilities.glsl>
Bounds getNodeBounds(int index, const in Mesh mesh)
{
......@@ -36,7 +36,7 @@ bool traverseBVH(const in Mesh mesh, const in Ray local_ray, const in bool use_f
//both hit
if (hit_left && hit_right)
{
// shift bitstack and mark as branched, so we can use the marker
// shift bitstack and mark as branched, so we can use the marker
// when backtracking to stop here and use the right child.
bitstack = bitstack << 1;
current_node = id_left;
......@@ -88,7 +88,7 @@ bool traverseBVH(const in Mesh mesh, const in Ray local_ray, const in bool use_f
nearest.triangle = i;
nearest.mesh = mesh.id;
}
if (also_farthest && t > t_max) {
t_max = t;
......@@ -124,4 +124,4 @@ bool traverseBVH(const in Mesh mesh, const in Ray local_ray, const in bool use_f
return hit_triangle;
}
#endif //__GL_BVH
\ No newline at end of file
#endif //__GL_BVH
#ifndef __GL_MESH_DATASTRUCTURE
#define __GL_MESH_DATASTRUCTURE
#include <raytracer/datastructure/mesh_bvh.glh>
#include <raytracer/datastructure/mesh_angular_linespace.glh>
//#include <raytracer/datastructure/mesh_linespace.glh>
#include <raytracer/datastructure/mesh_bvh.glsl>
#include <raytracer/datastructure/mesh_angular_linespace.glsl>
//#include <raytracer/datastructure/mesh_linespace.glsl>
uniform bool u_use_ls;
......
#ifndef __GL_LINESPACE
#define __GL_LINESPACE
#include <raytracer/basic_structs.glh>
#include <raytracer/buffers.glh>
#include <raytracer/intersections.glh>
#include <raytracer/std.glh>
#include <raytracer/utilities.glh>
#include <raytracer/basic_structs.glsl>
#include <raytracer/buffers.glsl>
#include <raytracer/intersections.glsl>
#include <raytracer/std.glsl>
#include <raytracer/utilities.glsl>
uint ls__faceRangeIndex(uint in_face, uint out_face)
{
......
......@@ -3,12 +3,12 @@
#extension GL_ARB_shading_language_include : require
#extension GL_ARB_compute_variable_group_size : require
#include <raytracer/basic_structs.glh>
#include <raytracer/datastructure/mesh_datastructure.glh>
#include <raytracer/buffers.glh>
#include <raytracer/utilities.glh>
#include <raytracer/random.glh>
#include <raytracer/properties/camera.glh>
#include <raytracer/basic_structs.glsl>
#include <raytracer/datastructure/mesh_datastructure.glsl>
#include <raytracer/buffers.glsl>
#include <raytracer/utilities.glsl>
#include <raytracer/random.glsl>
#include <raytracer/properties/camera.glsl>
layout(local_size_variable) in;
......@@ -49,4 +49,4 @@ void resetImportance(int id)
b_traces[id].properties.shadow_importance = 1.f;
b_traces[id].properties.bounce_amount = 0;
b_traces[id].properties.travelled_distance = 0;
}
\ No newline at end of file
}
......@@ -3,11 +3,11 @@
#extension GL_ARB_shading_language_include : require
#extension GL_ARB_compute_variable_group_size : require
#include <raytracer/basic_structs.glh>
#include <raytracer/buffers.glh>
#include <raytracer/random.glh>
#include <raytracer/utilities.glh>
#include <raytracer/properties/camera.glh>
#include <raytracer/basic_structs.glsl>
#include <raytracer/buffers.glsl>
#include <raytracer/random.glsl>
#include <raytracer/utilities.glsl>
#include <raytracer/properties/camera.glsl>
layout(rgba32f) uniform readonly image2D u_gbuffer_texture_01;
......@@ -40,7 +40,7 @@ void main()
b_traces[id].hit.triangle = uint(texel_01.z);
b_traces[id].hit.mesh = uint(texel_01.w);
}
resetImportance(id);
}
}
\ No newline at end of file
}
......@@ -5,8 +5,8 @@
layout(points) in;
layout(triangle_strip, max_vertices = 3) out;
#include <raytracer/basic_structs.glh>
#include <raytracer/buffers.glh>
#include <raytracer/basic_structs.glsl>
#include <raytracer/buffers.glsl>
uniform mat4 u_mvp;
......@@ -39,4 +39,4 @@ void main()
EmitVertex();
EndPrimitive();
}
\ No newline at end of file
}
#ifndef __INTERSECTIONS_GLH
#define __INTERSECTIONS_GLH
#include <raytracer/basic_structs.glh>
#include <raytracer/buffers.glh>
#include <raytracer/utilities.glh>
#include <raytracer/basic_structs.glsl>
#include <raytracer/buffers.glsl>
#include <raytracer/utilities.glsl>
bool intersectsBounds(const in Ray ray, const in Bounds bounds)
{
......@@ -236,4 +236,4 @@ bool intersectsTriangleLocal(const in Ray ray, int triangle_index, const in Mesh
}
#endif //!__INTERSECTIONS_GLH
\ No newline at end of file
#endif //!__INTERSECTIONS_GLH
......@@ -3,10 +3,10 @@
#extension GL_ARB_shading_language_include : require
#extension GL_ARB_compute_variable_group_size : require
#include <raytracer/basic_structs.glh>
#include <raytracer/buffers.glh>
#include <raytracer/datastructure/mesh_bvh.glh>
#include <raytracer/std.glh>
#include <raytracer/basic_structs.glsl>
#include <raytracer/buffers.glsl>
#include <raytracer/datastructure/mesh_bvh.glsl>
#include <raytracer/std.glsl>
layout(local_size_variable) in;
......@@ -125,7 +125,7 @@ void generate(uint gid)
//Invalidate intersections
Hit nearest;
Hit farthest;
nearest.mesh = nearest.triangle = -1;
farthest.mesh = farthest.triangle = -1;
nearest.barycentric = vec2(-1);
......@@ -136,12 +136,12 @@ void generate(uint gid)
float t_min = FLT_MAX;
u_mesh.traverseBVH(ray, false, FLT_MAX, true, nearest, farthest, t_min);
if(nearest.valid())
{
line.nearest.triangle = int(nearest.triangle);
}
if(farthest.valid())
{
line.farthest.triangle = int(farthest.triangle);
......
#ifndef __GL_BVH
#define __GL_BVH
#include <raytracer/basic_structs.glh>
#include <raytracer/buffers.glh>
#include <raytracer/intersections.glh>
#include <raytracer/std.glh>
#include <raytracer/basic_structs.glsl>
#include <raytracer/buffers.glsl>
#include <raytracer/intersections.glsl>
#include <raytracer/std.glsl>
Bounds getNodeBounds(int index, const in Mesh mesh)
{
......@@ -45,7 +45,7 @@ bool traverse(const in uint mesh_id, const in Ray ray, inout Hit hit, const in b
//both hit
if (hit_left && hit_right)
{
// shift bitstack and mark as branched, so we can use the marker
// shift bitstack and mark as branched, so we can use the marker
// when backtracking to stop here and use the right child.
bitstack = bitstack << 1;
current_node = id_left;
......@@ -151,4 +151,4 @@ bool bvh__intersectsAny(const in Ray ray, const in float max_distance)
return false;
}
#endif //__GL_BVH
\ No newline at end of file
#endif //__GL_BVH
......@@ -16,17 +16,17 @@ uniform struct
} u_render_config;
#endif
#include <raytracer/std.glh>
#include <raytracer/basic_structs.glh>
#include <raytracer/buffers.glh>
#include <raytracer/utilities.glh>
#include <raytracer/std.glsl>
#include <raytracer/basic_structs.glsl>
#include <raytracer/buffers.glsl>
#include <raytracer/utilities.glsl>
#include <raytracer/datastructure/mesh_datastructure.glh>
#include <raytracer/datastructure/mesh_datastructure.glsl>
#include <raytracer/properties/camera.glh>
#include <raytracer/properties/environment.glh>
#include <raytracer/properties/bsdf.glh>
#include <raytracer/properties/lights.glh>
#include <raytracer/properties/camera.glsl>
#include <raytracer/properties/environment.glsl>
#include <raytracer/properties/bsdf.glsl>
#include <raytracer/properties/lights.glsl>
layout(local_size_variable) in;
......@@ -89,8 +89,8 @@ bool shade(int id, inout vec3 radiance, uint bounce, out uint bsdf_id)
Hit hit = trace.hit;
Ray ray = trace.ray;
float clamp_color_max = mix(u_render_config.clamp_direct, u_render_config.clamp_indirect, bounce.clamp(0.f, 1.f));
//Sample environment when not hitting anything.
if(!hit.valid())
{
......@@ -102,7 +102,7 @@ bool shade(int id, inout vec3 radiance, uint bounce, out uint bsdf_id)
Material material;
Vertex vertex = hit.getVertex(material);
vec4 diffuse = material.getDiffuse(vertex.texcoord);
b_traces[id].properties.travelled_distance += b_traces[id].hit.valid() ? (distance(b_traces[id].ray.origin, vertex.position.xyz)) : FLT_MAX;
//As the px and py values of the ray are floats instead of integers,
......@@ -115,9 +115,9 @@ bool shade(int id, inout vec3 radiance, uint bounce, out uint bsdf_id)
vec3 light_influence;
Ray out_ray;
vec3 reflectance = material.sampleBSDF(random_sample, vertex, ray, out_ray, light_influence, pdf, bsdf_id);
b_traces[id].addBounceAmount(bsdf_id, 1);
if(b_traces[id].getBounceAmount(bsdf_id) > getBounceThreshold(bsdf_id))
{
b_traces[id].hit.invalidate();
......@@ -207,4 +207,4 @@ void main()
//Divide color storage by sample count to retrieve the final color.
writeRenderTarget(id, loadColorStore(id) / (u_render_config.current_sample + 1));
}
\ No newline at end of file
}
#ifndef __BSDF_DIFFUSE_GLH
#define __BDSF_DIFFUSE_GLH
#include <raytracer/basic_structs.glh>
#include <raytracer/random.glh>
#include <raytracer/utilities.glh>
#include <raytracer/properties/ray_transform.glh>
#include <raytracer/properties/fresnel.glh>
#include <raytracer/basic_structs.glsl>
#include <raytracer/random.glsl>
#include <raytracer/utilities.glsl>
#include <raytracer/properties/ray_transform.glsl>
#include <raytracer/properties/fresnel.glsl>
vec3 sampleDiffuse(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, out uint bsdf_id)
{
......@@ -16,7 +16,7 @@ vec3 sampleDiffuse(const in Material material, const in vec2 random, const in Ve
pdf = abs(dot(vec4(ray_out.direction, 0), vertex.normal)) * ONE_OVER_PI;
bsdf_id = 0;
if (pdf == 0.f)
{
return vec3(0.f);
......@@ -40,7 +40,7 @@ vec3 sampleTranslucent(const in Material material, const in vec2 random, const i
pdf = abs(dot(ray_out.direction, vertex.normal.xyz)) * ONE_OVER_PI;
ray_out.origin = vertex.position.xyz + 1e-5f * ray_in.direction;
bsdf_id = 1;
if (pdf == 0.f)
......@@ -80,10 +80,10 @@ vec3 sampleGlass(const in Material material, const in vec2 random, const in Vert
pdf = 1.0f - fresnel;
vec3 ft = diffuse*material.getTransparent(vertex.texcoord).rgb * (1.0f - fresnel);
ft *= ( eta_i * eta_i ) / ( eta_t * eta_t );
bsdf_id = 3;
return ft / abs(dot(ray_out.direction, vertex.normal.xyz));
}
bsdf_id = 2;
......@@ -124,11 +124,11 @@ vec3 sampleRoughGlass(const in Material material, const in vec2 random, const in
pdf = mix(1.0f - fresnel, abs(dot(ray_out.direction, vertex.normal.xyz)) * ONE_OVER_PI, roughness);
vec3 ft = diffuse*material.getTransparent(vertex.texcoord).rgb * (1.0f - fresnel);
ft *= ( eta_i * eta_i ) / ( eta_t * eta_t );
bsdf_id = 3;
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);
}
......@@ -143,7 +143,7 @@ vec3 sampleRoughGlass(const in Material material, const in vec2 random, const in
ray_out.direction.xyz = localToWorldNormal(sampledPoint * vec3(-1, -1, 1), reflected);
}
bsdf_id = 2;
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(vertex.texcoord).rgb / abs(dot(ray_out.direction, vertex.normal.xyz)), diffuse * ONE_OVER_PI, roughness);
......@@ -155,7 +155,7 @@ vec3 sampleTransparent(const in Material material, const in vec2 random, const i
ray_out.direction = ray_in.direction;
ray_out.origin = vertex.position.xyz + 1e-5 * ray_out.direction;
pdf = 1;
bsdf_id = 4;
light_influence = vec3(0);
......@@ -186,7 +186,7 @@ vec3 sampleGlossy(const in Material material, const in vec2 random, const in Ver
ray_out.direction.xyz = normalize(localToWorldNormal(sampledPoint, reflected));
bsdf_id = 2;
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));
......@@ -258,4 +258,4 @@ vec3 sampleBSDF(const in Material material, const in vec2 random, const in Verte
}
}
#endif //!__BDSF_DIFFUSE_GLH
\ No newline at end of file
#endif //!__BDSF_DIFFUSE_GLH
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