-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
34 changed files
with
1,589 additions
and
1,176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 52 additions & 45 deletions
97
EvoEngine_SDK/Internals/DefaultResources/Shaders/Compute/RayTracerCamera.comp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,84 @@ | ||
#extension GL_ARB_shading_language_include : enable | ||
|
||
#define SCENE_LEVEL_BVH_BLOCK_BINDING 0 | ||
#define NODE_INDICES_BLOCK_BINDING 1 | ||
#define NODE_INFO_LIST_BLOCK_BINDING 2 | ||
#define NODE_LEVEL_BVH_NODES_BLOCK_BINDING 3 | ||
#define MESH_INDICES_BLOCK_BINDING 4 | ||
#define MESH_INFO_LIST_BLOCK_BINDING 5 | ||
#define MESH_LEVEL_BVH_NODES_BLOCK_BINDING 6 | ||
#define TRIANGLE_INDICES_BLOCK_BINDING 7 | ||
#define LOCAL_TRIANGLE_INDICES_BLOCK_BINDING 8 | ||
#define SCENE_TRIANGLES_BLOCK_BINDING 9 | ||
#define SCENE_VERTEX_POSITIONS_BLOCK_BINDING 10 | ||
#define SCENE_INFO_BLOCK_BINDING 11 | ||
#extension GL_EXT_nonuniform_qualifier : enable | ||
#define TRACE_DATA_SET 0 | ||
#define EE_PER_FRAME_SET 0 | ||
#define SCENE_GRAPH_DATA_BINDING 0 | ||
#define SCENE_GEOMETRY_DATA_BINDING 1 | ||
#define SCENE_INFO_BLOCK_BINDING 2 | ||
#include "Trace.glsl" | ||
|
||
#define EE_ENVIRONMENTAL_BLOCK_BINDING 12 | ||
#include "Environment.glsl" | ||
|
||
#define EE_MATERIAL_BLOCK_BINDING 13 | ||
#define EE_MATERIAL_BLOCK_BINDING 3 | ||
#include "Materials.glsl" | ||
|
||
#define EE_INSTANCE_BLOCK_BINDING 14 | ||
#define EE_INSTANCE_BLOCK_BINDING 4 | ||
#include "Instances.glsl" | ||
|
||
#define EE_DIRECTIONAL_LIGHT_BLOCK_BINDING 15 | ||
#define EE_POINT_LIGHT_BLOCK_BINDING 16 | ||
#define EE_SPOT_LIGHT_BLOCK_BINDING 17 | ||
#include "Lights.glsl" | ||
|
||
#define EE_TEXTURE_2DS_BINDING 18 | ||
#define EE_CUBEMAPS_BINDING 19 | ||
#define EE_TEXTURE_2DS_BINDING 6 | ||
#define EE_CUBEMAPS_BINDING 7 | ||
#include "Textures.glsl" | ||
|
||
#include "Random.glsl" | ||
|
||
layout(set = TRACE_DATA_SET, binding = 5, rgba32f) uniform image2D result_image; | ||
|
||
layout(push_constant) uniform RAY_CASTING_CONSTANTS{ | ||
vec4 resolution_xy_sample_bounce; | ||
mat4 inverse_projection_view; | ||
}; | ||
void Execute(uint pixel_index); | ||
|
||
layout (local_size_x = 256, local_size_y = 1, local_size_z = 1) in; | ||
|
||
#define FLT_MAX 3.402823466e+38 | ||
|
||
void main() { | ||
uint pixel_index = gl_GlobalInvocationID.x; | ||
uint seed = pixel_index; | ||
Execute(pixel_index); | ||
} | ||
|
||
void Execute(uint pixel_index) { | ||
uint resolution_x = floatBitsToUint(resolution_xy_sample_bounce.x); | ||
uint resolution_y = floatBitsToUint(resolution_xy_sample_bounce.y); | ||
uint sample_count = floatBitsToUint(resolution_xy_sample_bounce.z); | ||
uint bounce_count = floatBitsToUint(resolution_xy_sample_bounce.w); | ||
|
||
float x_coordinate = float(pixel_index % resolution_x); | ||
float y_coordinate = float(pixel_index % resolution_y); | ||
uint seed = pixel_index; | ||
if(pixel_index < resolution_x * resolution_y){ | ||
uint sample_count = floatBitsToUint(resolution_xy_sample_bounce.z); | ||
uint bounce_count = floatBitsToUint(resolution_xy_sample_bounce.w); | ||
|
||
float half_x = float(resolution_x) * .5; | ||
float half_y = float(resolution_y) * .5; | ||
float x_coordinate = float(pixel_index % resolution_y); | ||
float y_coordinate = float(pixel_index / resolution_y); | ||
|
||
for(uint sample_index = 0; sample_index < sample_count; sample_index += 1){ | ||
vec2 screen = vec2((x_coordinate + EE_RANDOM(seed) - half_x) / half_x, | ||
(y_coordinate + EE_RANDOM(seed) - half_y) / half_y); | ||
vec4 start = inverse_projection_view * vec4(screen.x, screen.y, 0.0, 1.0); | ||
vec4 end = inverse_projection_view * vec4(screen.x, screen.y, 1.0, 1.0); | ||
start /= start.w; | ||
end /= end.w; | ||
float half_x = float(resolution_x) * .5; | ||
float half_y = float(resolution_y) * .5; | ||
RayDescriptor ray_descriptor; | ||
ray_descriptor.origin = start.xyz; | ||
ray_descriptor.direction = normalize(end.xyz - start.xyz); | ||
ray_descriptor.t_min = 0.; | ||
ray_Dexcriptor.t_max = FLT_MAX; | ||
HitInfo hit_info = Trace(ray_descriptor, true, false, hit); | ||
ray_descriptor.t_max = FLT_MAX; | ||
|
||
vec4 color; | ||
float screen_x = (x_coordinate + EE_RANDOM(seed) - half_x) / half_x; | ||
float screen_y = (y_coordinate + EE_RANDOM(seed) - half_y) / half_y; | ||
vec4 camera_start = inverse_projection_view * vec4(screen_x, screen_y, 0.0, 1.0); | ||
vec4 camera_end = inverse_projection_view * vec4(screen_x, screen_y, 1.0, 1.0); | ||
camera_start /= camera_start.w; | ||
camera_end /= camera_end.w; | ||
vec3 sample_origin = camera_start.xyz; | ||
vec3 sample_direction = normalize(camera_end.xyz - camera_start.xyz); | ||
bool hit = false; | ||
ray_descriptor.origin = sample_origin; | ||
ray_descriptor.direction = sample_direction; | ||
HitInfo hit_info = Trace(ray_descriptor, false, false, hit); | ||
if (hit) { | ||
|
||
uint material_index = EE_INSTANCES[hit_info.instance_index].material_index; | ||
MaterialProperties mat_props = EE_MATERIAL_PROPERTIES[material_index]; | ||
Vertex p0, p1, p2; | ||
GetTriangle(hit_info.triangle_index, p0, p1, p2); | ||
vec2 tex_coord = hit_info.barycentric.x * p0.tex_coord + hit_info.barycentric.y * p1.tex_coord + hit_info.barycentric.z * p2.tex_coord; | ||
vec4 albedo = mat_props.albedo; | ||
if (mat_props.albedo_map_index != -1) { | ||
albedo = texture(EE_TEXTURE_2DS[mat_props.albedo_map_index], tex_coord); | ||
} | ||
color = albedo; | ||
} | ||
vec4 accumlated = imageLoad(result_image, ivec2(x_coordinate, y_coordinate)) * sample_count; | ||
imageStore(result_image, ivec2(x_coordinate, y_coordinate), (color + accumlated) / (sample_count + 1)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.