-
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.
Now DynamicStrands rendering embeds into SDK's render system, supporting PBR material, dynamic lighting, and real-time soft shadows.
- Loading branch information
1 parent
b4b5b13
commit 9d20c47
Showing
31 changed files
with
953 additions
and
247 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
3 changes: 3 additions & 0 deletions
3
...ngine_Plugins/EcoSysLab/Internals/EcoSysLabResources/Shaders/Graphics/Fragment/Empty.frag
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
void main() | ||
{ | ||
} |
110 changes: 110 additions & 0 deletions
110
...als/EcoSysLabResources/Shaders/Graphics/Mesh/DynamicStrandsDirectionalLightShadowMap.mesh
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 |
---|---|---|
@@ -0,0 +1,110 @@ | ||
#extension GL_EXT_mesh_shader : enable | ||
#extension GL_ARB_shader_draw_parameters : enable | ||
#extension GL_EXT_control_flow_attributes : require | ||
#extension GL_ARB_shading_language_include : enable | ||
#extension GL_EXT_shader_explicit_arithmetic_types_int8 : require | ||
#extension GL_EXT_shader_atomic_float : require | ||
|
||
#include "PerFrame.glsl" | ||
|
||
#define DYNAMIC_STRANDS_SET 1 | ||
#include "DynamicStrands.glsl" | ||
|
||
const uint WORKGROUP_SIZE = EXT_MESH_SUBGROUP_COUNT * SUBGROUP_SIZE; | ||
|
||
layout(local_size_x = WORKGROUP_SIZE) in; | ||
layout(triangles) out; | ||
|
||
#define TETRAHEDRON_VERTICES_SIZE 4 | ||
#define TETRAHEDRON_TRIANGLE_SIZE 4 | ||
|
||
layout(max_vertices = TETRAHEDRON_VERTICES_SIZE, max_primitives = TETRAHEDRON_TRIANGLE_SIZE) out; | ||
|
||
const uint TETRAHEDRON_VERTEX_ITERATIONS = ((TETRAHEDRON_VERTICES_SIZE + WORKGROUP_SIZE - 1) / WORKGROUP_SIZE); | ||
const uint TETRAHEDRON_PRIMITIVE_ITERATIONS = ((TETRAHEDRON_TRIANGLE_SIZE + WORKGROUP_SIZE - 1) / WORKGROUP_SIZE); | ||
|
||
layout(location = 0) out MS_V_OUT { | ||
vec3 FragPos; | ||
vec3 Normal; | ||
vec3 Tangent; | ||
vec2 TexCoord; | ||
vec4 Color; | ||
} ms_v_out[]; | ||
|
||
struct Task{ | ||
uint baseID; | ||
uint8_t deltaIDs[EXT_TASK_WORK_GROUP_INVOCATIONS]; | ||
}; | ||
|
||
// order them such that the triangle index corresponds to the vertex index on the opposing side | ||
uvec3 triangles[] = { | ||
uvec3(2, 1, 3), | ||
uvec3(0, 2, 3), | ||
uvec3(1, 0, 3), | ||
uvec3(0, 1, 2), | ||
}; | ||
|
||
#define BARRIER() \ | ||
memoryBarrierShared(); \ | ||
barrier(); | ||
|
||
taskPayloadSharedEXT Task ts_in; | ||
|
||
// gl_WorkGroupID.x runs from [0 .. parentTask.groupCountX - 1] | ||
uint tet_id = ts_in.baseID + ts_in.deltaIDs[gl_WorkGroupID.x]; | ||
uint laneID = gl_LocalInvocationID.x; | ||
|
||
|
||
#include "AlphaShape.glsl" | ||
|
||
void main(){ | ||
|
||
// report amount of accepted triangles | ||
SetMeshOutputsEXT(TETRAHEDRON_VERTICES_SIZE, delaunay_tetrahedrons[tet_id].triangles_accepted); | ||
DelaunayTetrahedron tet = delaunay_tetrahedrons[tet_id]; | ||
// set up vertex properties | ||
mat4 transform = EE_DIRECTIONAL_LIGHTS[EE_CAMERA_INDEX].light_space_matrix[base_index]; | ||
|
||
[[unroll]] | ||
for (uint i = 0; i < uint(TETRAHEDRON_VERTEX_ITERATIONS); ++i) | ||
{ | ||
uint vertex_index = laneID + i * WORKGROUP_SIZE; | ||
if (vertex_index >= TETRAHEDRON_VERTICES_SIZE) break; | ||
vec3 vertex_position = uniform_particles[tet.indices[vertex_index]].position_t.xyz; | ||
vec3 vertex_normal = normalize(uniform_particles[tet.indices[vertex_index]].normal_deg.xyz); | ||
|
||
ms_v_out[vertex_index].FragPos = vertex_position; | ||
ms_v_out[vertex_index].Normal = vertex_normal; | ||
ms_v_out[vertex_index].Tangent = uniform_particles[tet.indices[vertex_index]].tangent.xyz; | ||
ms_v_out[vertex_index].TexCoord = vec2(uniform_particles[tet.indices[vertex_index]].tex_coord.x, uniform_particles[tet.indices[vertex_index]].tex_coord.y); | ||
if(vertex_colors == 0){ | ||
ms_v_out[vertex_index].Color = vec4(0.5, 0.5, 0.5, 1.0); | ||
} else if(vertex_colors == 1){ | ||
ms_v_out[vertex_index].Color = vec4(abs(vertex_normal.xyz), 1.0f); | ||
} else if(vertex_colors == 2){ | ||
ms_v_out[vertex_index].Color = vec4(abs(uniform_particles[tet.indices[vertex_index]].tangent.xyz), 1.0f); | ||
} else if(vertex_colors == 3){ | ||
ms_v_out[vertex_index].Color = vec4(mod(uniform_particles[tet.indices[vertex_index]].tex_coord.x, 1.0f), | ||
mod(uniform_particles[tet.indices[vertex_index]].tex_coord.y, 1.0f), | ||
mod(uniform_particles[tet.indices[vertex_index]].tex_coord.z, 1.0f), 1.0f); | ||
} | ||
|
||
gl_MeshVerticesEXT[vertex_index].gl_Position = transform * vec4(vertex_position, 1.0); | ||
} | ||
|
||
// assign all accepted triangles | ||
[[unroll]] | ||
for (uint i = 0; i < uint(TETRAHEDRON_PRIMITIVE_ITERATIONS); ++i) | ||
{ | ||
uint triangle_index = laneID + i * WORKGROUP_SIZE; | ||
if(triangle_index < TETRAHEDRON_TRIANGLE_SIZE){ | ||
|
||
if(delaunay_tetrahedrons[tet_id].render_neighbor[triangle_index] == 1){ | ||
|
||
// count triangles downwards | ||
int index = atomicAdd(delaunay_tetrahedrons[tet_id].triangles_accepted, -1); | ||
gl_PrimitiveTriangleIndicesEXT[index - 1] = triangles[triangle_index]; | ||
} | ||
} | ||
} | ||
} |
110 changes: 110 additions & 0 deletions
110
...Internals/EcoSysLabResources/Shaders/Graphics/Mesh/DynamicStrandsPointLightShadowMap.mesh
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 |
---|---|---|
@@ -0,0 +1,110 @@ | ||
#extension GL_EXT_mesh_shader : enable | ||
#extension GL_ARB_shader_draw_parameters : enable | ||
#extension GL_EXT_control_flow_attributes : require | ||
#extension GL_ARB_shading_language_include : enable | ||
#extension GL_EXT_shader_explicit_arithmetic_types_int8 : require | ||
#extension GL_EXT_shader_atomic_float : require | ||
|
||
#include "PerFrame.glsl" | ||
|
||
#define DYNAMIC_STRANDS_SET 1 | ||
#include "DynamicStrands.glsl" | ||
|
||
const uint WORKGROUP_SIZE = EXT_MESH_SUBGROUP_COUNT * SUBGROUP_SIZE; | ||
|
||
layout(local_size_x = WORKGROUP_SIZE) in; | ||
layout(triangles) out; | ||
|
||
#define TETRAHEDRON_VERTICES_SIZE 4 | ||
#define TETRAHEDRON_TRIANGLE_SIZE 4 | ||
|
||
layout(max_vertices = TETRAHEDRON_VERTICES_SIZE, max_primitives = TETRAHEDRON_TRIANGLE_SIZE) out; | ||
|
||
const uint TETRAHEDRON_VERTEX_ITERATIONS = ((TETRAHEDRON_VERTICES_SIZE + WORKGROUP_SIZE - 1) / WORKGROUP_SIZE); | ||
const uint TETRAHEDRON_PRIMITIVE_ITERATIONS = ((TETRAHEDRON_TRIANGLE_SIZE + WORKGROUP_SIZE - 1) / WORKGROUP_SIZE); | ||
|
||
layout(location = 0) out MS_V_OUT { | ||
vec3 FragPos; | ||
vec3 Normal; | ||
vec3 Tangent; | ||
vec2 TexCoord; | ||
vec4 Color; | ||
} ms_v_out[]; | ||
|
||
struct Task{ | ||
uint baseID; | ||
uint8_t deltaIDs[EXT_TASK_WORK_GROUP_INVOCATIONS]; | ||
}; | ||
|
||
// order them such that the triangle index corresponds to the vertex index on the opposing side | ||
uvec3 triangles[] = { | ||
uvec3(2, 1, 3), | ||
uvec3(0, 2, 3), | ||
uvec3(1, 0, 3), | ||
uvec3(0, 1, 2), | ||
}; | ||
|
||
#define BARRIER() \ | ||
memoryBarrierShared(); \ | ||
barrier(); | ||
|
||
taskPayloadSharedEXT Task ts_in; | ||
|
||
// gl_WorkGroupID.x runs from [0 .. parentTask.groupCountX - 1] | ||
uint tet_id = ts_in.baseID + ts_in.deltaIDs[gl_WorkGroupID.x]; | ||
uint laneID = gl_LocalInvocationID.x; | ||
|
||
|
||
#include "AlphaShape.glsl" | ||
|
||
void main(){ | ||
|
||
// report amount of accepted triangles | ||
SetMeshOutputsEXT(TETRAHEDRON_VERTICES_SIZE, delaunay_tetrahedrons[tet_id].triangles_accepted); | ||
DelaunayTetrahedron tet = delaunay_tetrahedrons[tet_id]; | ||
// set up vertex properties | ||
mat4 transform = EE_POINT_LIGHTS[EE_CAMERA_INDEX].light_space_matrix[base_index]; | ||
|
||
[[unroll]] | ||
for (uint i = 0; i < uint(TETRAHEDRON_VERTEX_ITERATIONS); ++i) | ||
{ | ||
uint vertex_index = laneID + i * WORKGROUP_SIZE; | ||
if (vertex_index >= TETRAHEDRON_VERTICES_SIZE) break; | ||
vec3 vertex_position = uniform_particles[tet.indices[vertex_index]].position_t.xyz; | ||
vec3 vertex_normal = normalize(uniform_particles[tet.indices[vertex_index]].normal_deg.xyz); | ||
|
||
ms_v_out[vertex_index].FragPos = vertex_position; | ||
ms_v_out[vertex_index].Normal = vertex_normal; | ||
ms_v_out[vertex_index].Tangent = uniform_particles[tet.indices[vertex_index]].tangent.xyz; | ||
ms_v_out[vertex_index].TexCoord = vec2(uniform_particles[tet.indices[vertex_index]].tex_coord.x, uniform_particles[tet.indices[vertex_index]].tex_coord.y); | ||
if(vertex_colors == 0){ | ||
ms_v_out[vertex_index].Color = vec4(0.5, 0.5, 0.5, 1.0); | ||
} else if(vertex_colors == 1){ | ||
ms_v_out[vertex_index].Color = vec4(abs(vertex_normal.xyz), 1.0f); | ||
} else if(vertex_colors == 2){ | ||
ms_v_out[vertex_index].Color = vec4(abs(uniform_particles[tet.indices[vertex_index]].tangent.xyz), 1.0f); | ||
} else if(vertex_colors == 3){ | ||
ms_v_out[vertex_index].Color = vec4(mod(uniform_particles[tet.indices[vertex_index]].tex_coord.x, 1.0f), | ||
mod(uniform_particles[tet.indices[vertex_index]].tex_coord.y, 1.0f), | ||
mod(uniform_particles[tet.indices[vertex_index]].tex_coord.z, 1.0f), 1.0f); | ||
} | ||
|
||
gl_MeshVerticesEXT[vertex_index].gl_Position = transform * vec4(vertex_position, 1.0); | ||
} | ||
|
||
// assign all accepted triangles | ||
[[unroll]] | ||
for (uint i = 0; i < uint(TETRAHEDRON_PRIMITIVE_ITERATIONS); ++i) | ||
{ | ||
uint triangle_index = laneID + i * WORKGROUP_SIZE; | ||
if(triangle_index < TETRAHEDRON_TRIANGLE_SIZE){ | ||
|
||
if(delaunay_tetrahedrons[tet_id].render_neighbor[triangle_index] == 1){ | ||
|
||
// count triangles downwards | ||
int index = atomicAdd(delaunay_tetrahedrons[tet_id].triangles_accepted, -1); | ||
gl_PrimitiveTriangleIndicesEXT[index - 1] = triangles[triangle_index]; | ||
} | ||
} | ||
} | ||
} |
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.