Merge branch 'main' into SP3-13-Assets-Manager
This commit is contained in:
commit
d3b44f9c22
|
@ -0,0 +1,83 @@
|
|||
#version 450
|
||||
|
||||
struct DirectionalLightStruct
|
||||
{
|
||||
vec3 direction;
|
||||
uint isActive;
|
||||
uint cullingMask;
|
||||
vec4 diffuseColor;
|
||||
};
|
||||
|
||||
struct AmbientLightStruct
|
||||
{
|
||||
vec4 ambientColor;
|
||||
float strength;
|
||||
uint isActive;
|
||||
uint cullingMask;
|
||||
};
|
||||
|
||||
layout(local_size_x = 16, local_size_y = 16) in;
|
||||
layout(set = 4, binding = 0, rgba32f) uniform image2D positions;
|
||||
layout(set = 4, binding = 1, rgba32f) uniform image2D normals;
|
||||
layout(set = 4, binding = 2, rgba8) uniform image2D albedo;
|
||||
layout(set = 4, binding = 3, r32ui) uniform uimage2D lightLayerData;
|
||||
layout(set = 4, binding = 4, rgba8) uniform image2D targetImage;
|
||||
|
||||
layout(set = 1, binding = 0) uniform LightCounts
|
||||
{
|
||||
uint directionalLights;
|
||||
uint pointLights;
|
||||
uint spotLights;
|
||||
uint ambientLights;
|
||||
|
||||
} lightCounts;
|
||||
|
||||
layout(std430, set = 1, binding = 1) buffer DirectionalLightData
|
||||
{
|
||||
DirectionalLightStruct dLightData[];
|
||||
} DirLightData;
|
||||
|
||||
layout(std430, set = 1, binding = 4) buffer AmbientLightData
|
||||
{
|
||||
AmbientLightStruct aLightData[];
|
||||
} AmbLightData;
|
||||
|
||||
void main()
|
||||
{
|
||||
// convenient variables
|
||||
ivec2 globalThread = ivec2(gl_GlobalInvocationID);
|
||||
|
||||
// Get the diffuse color of the pixel
|
||||
vec3 pixelDiffuse = imageLoad (albedo, globalThread).rgb;
|
||||
|
||||
// Get position of fragment in world space
|
||||
vec3 positionWorld = imageLoad (positions, globalThread).rgb;
|
||||
|
||||
// normal of fragment
|
||||
vec3 normalWorld = imageLoad(normals, globalThread).rgb;
|
||||
|
||||
vec3 fragColor = vec3 (0.0f);
|
||||
|
||||
for (int i = 0; i < lightCounts.directionalLights; ++i)
|
||||
{
|
||||
// get normalized direction of light
|
||||
vec3 dLightNormalized = normalize (DirLightData.dLightData[i].direction);
|
||||
|
||||
// Get diffuse strength
|
||||
float diffuseStrength = max (0, dot (dLightNormalized, normalWorld));
|
||||
|
||||
// Calculate the fragment color
|
||||
fragColor += DirLightData.dLightData[i].diffuseColor.rgb * diffuseStrength.rrr * pixelDiffuse;
|
||||
}
|
||||
|
||||
for (int i = 0; i < lightCounts.ambientLights; ++i)
|
||||
{
|
||||
// Just do some add
|
||||
//fragColor += pixelDiffuse.rgb * AmbLightData.aLightData[i].ambientColor.rgb * vec3 (0.5f);
|
||||
fragColor += pixelDiffuse.rgb * AmbLightData.aLightData[i].ambientColor.rgb * vec3 (AmbLightData.aLightData[i].strength);
|
||||
}
|
||||
|
||||
// store result into result image
|
||||
imageStore(targetImage, ivec2(gl_GlobalInvocationID.xy), vec4(fragColor, 1.0f));
|
||||
|
||||
}
|
Binary file not shown.
|
@ -0,0 +1,3 @@
|
|||
Name: DeferredComposite_CS
|
||||
ID: 42814284
|
||||
Type: 2
|
|
@ -1,3 +1,3 @@
|
|||
Name: Kirsch_CS
|
||||
ID: 19931255
|
||||
ID: 39301863
|
||||
Type: 2
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
Name: PureCopy_CS
|
||||
ID: 29659779
|
||||
ID: 34987209
|
||||
Type: 2
|
||||
|
|
|
@ -13,37 +13,38 @@ struct MatPropData
|
|||
|
||||
layout(location = 0) in struct
|
||||
{
|
||||
vec4 vertColor;
|
||||
vec2 uv;
|
||||
vec4 vertPos; // location 0
|
||||
vec2 uv; // location = 1
|
||||
vec4 normal; // location = 2
|
||||
|
||||
} In;
|
||||
|
||||
// material stuff
|
||||
layout(location = 2) flat in struct
|
||||
layout(location = 3) flat in struct
|
||||
{
|
||||
int materialIndex;
|
||||
uint eid;
|
||||
uint lightLayerIndex;
|
||||
} In2;
|
||||
|
||||
//layout (set = 0, binding = )
|
||||
|
||||
layout (set = 0, binding = 1) uniform sampler2D textures[]; // for textures (global)
|
||||
layout (set = 3, binding = 0) buffer MaterialProperties // For materials
|
||||
layout (std430, set = 3, binding = 0) buffer MaterialProperties // For materials
|
||||
{
|
||||
MatPropData data[];
|
||||
} MatProp;
|
||||
|
||||
layout(location = 0) out vec4 outColor;
|
||||
layout(location = 0) out vec4 position;
|
||||
layout(location = 1) out uint outEntityID;
|
||||
layout(location = 2) out uint lightLayerIndices;
|
||||
layout(location = 3) out vec4 normals;
|
||||
layout(location = 4) out vec4 albedo;
|
||||
|
||||
void main()
|
||||
{
|
||||
outColor = texture(textures[nonuniformEXT(MatProp.data[In2.materialIndex].textureIndex)], In.uv) +
|
||||
MatProp.data[In2.materialIndex].color / MatProp.data[In2.materialIndex].alpha;
|
||||
position = In.vertPos;
|
||||
normals = In.normal;
|
||||
albedo = texture(textures[nonuniformEXT(MatProp.data[In2.materialIndex].textureIndex)], In.uv) + MatProp.data[In2.materialIndex].color / MatProp.data[In2.materialIndex].alpha;
|
||||
|
||||
outEntityID = In2.eid;
|
||||
lightLayerIndices = In2.lightLayerIndex;
|
||||
//outColor = vec4 (1.0f);
|
||||
}
|
Binary file not shown.
|
@ -1,3 +1,3 @@
|
|||
Name: TestCube_FS
|
||||
ID: 18415057
|
||||
ID: 37450402
|
||||
Type: 2
|
||||
|
|
|
@ -14,13 +14,14 @@ layout(location = 8) in uvec2 integerData;
|
|||
|
||||
layout(location = 0) out struct
|
||||
{
|
||||
vec4 vertColor; // location 0
|
||||
vec4 vertPos; // location 0
|
||||
vec2 uv; // location = 1
|
||||
vec4 normal; // location = 2
|
||||
|
||||
} Out;
|
||||
|
||||
// material stuff
|
||||
layout(location = 2) out struct
|
||||
layout(location = 3) out struct
|
||||
{
|
||||
int materialIndex;
|
||||
uint eid;
|
||||
|
@ -36,10 +37,14 @@ layout(set = 2, binding = 0) uniform CameraData
|
|||
|
||||
void main()
|
||||
{
|
||||
Out.uv = aUV;
|
||||
|
||||
Out2.materialIndex = gl_InstanceIndex;
|
||||
Out2.eid = integerData[0];
|
||||
Out2.lightLayerIndex = integerData[1];
|
||||
|
||||
Out.vertPos = worldTransform * vec4(aVertexPos, 1.0f);
|
||||
Out.uv = aUV;
|
||||
Out.normal.rgb = mat3(transpose(inverse(worldTransform))) * aNormal.rgb;
|
||||
Out.normal.rgb = normalize (Out.normal.rgb);
|
||||
gl_Position = cameraData.vpMat * worldTransform * vec4 (aVertexPos, 1.0f);
|
||||
Out.vertColor = vec4 (aVertexPos, 1.0f);
|
||||
}
|
Binary file not shown.
|
@ -1,3 +1,3 @@
|
|||
Name: TestCube_VS
|
||||
ID: 29315909
|
||||
ID: 41688429
|
||||
Type: 2
|
||||
|
|
|
@ -158,12 +158,22 @@ namespace Sandbox
|
|||
SHComponentManager::AddComponent<SHLightComponent>(0);
|
||||
SHComponentManager::RemoveComponent <SHRigidBodyComponent>(0);
|
||||
SHComponentManager::RemoveComponent <SHColliderComponent>(0);
|
||||
|
||||
auto ambientLight = SHEntityManager::CreateEntity<SHLightComponent>();
|
||||
SHComponentManager::GetComponent<SHLightComponent>(ambientLight)->SetColor(SHVec4(1.0f, 1.0f, 1.0f, 1.0f));
|
||||
SHComponentManager::GetComponent<SHLightComponent>(ambientLight)->SetStrength(0.25f);
|
||||
SHComponentManager::GetComponent<SHLightComponent>(ambientLight)->SetType(SH_LIGHT_TYPE::AMBIENT);
|
||||
}
|
||||
|
||||
void SBTestScene::Update(float dt)
|
||||
{
|
||||
static float rotation = 0.0f;
|
||||
SHVec3 direction{0.0f, 0.0f, 1.0f};
|
||||
direction = SHVec3::RotateY(direction, rotation);
|
||||
|
||||
auto* lightComp =SHComponentManager::GetComponent<SHLightComponent>(0);
|
||||
lightComp->SetDirection (direction);
|
||||
rotation += 0.005f;
|
||||
//auto& transform = *SHADE::SHComponentManager::GetComponent_s<SHADE::SHTransformComponent>(testObj);
|
||||
|
||||
//transform.SetWorldPosition({1.0f, 1.0f, -1.0f});
|
||||
|
|
|
@ -61,8 +61,25 @@ namespace SHADE
|
|||
/// </summary>
|
||||
public CallbackAction() {}
|
||||
/// <summary>
|
||||
/// Constructs a CallbackAction that represents a call to the specified method on the
|
||||
/// specified target.
|
||||
/// Constructs a CallbackAction that represents a call to the specified static
|
||||
/// method.
|
||||
/// </summary>
|
||||
/// <param name="method">Method to call.</param>
|
||||
/// <exception cref="ArgumentException">
|
||||
/// Thrown if a method that is not compatible with the target is specified. The method's
|
||||
/// source type must match the target's type.
|
||||
/// </exception>
|
||||
public CallbackAction(MethodInfo method)
|
||||
{
|
||||
// No errors, assign
|
||||
targetMethod = method;
|
||||
|
||||
// Create storage for parameters for calling
|
||||
parameters = new Object[1];
|
||||
}
|
||||
/// <summary>
|
||||
/// Constructs a CallbackAction that represents a call to a specified member
|
||||
/// method on the specified target.
|
||||
/// </summary>
|
||||
/// <param name="target">Object to call the method on.</param>
|
||||
/// <param name="method">Method to call.</param>
|
||||
|
@ -86,7 +103,7 @@ namespace SHADE
|
|||
/// <summary>
|
||||
/// Constructs a Callback action based on an action.
|
||||
/// </summary>
|
||||
/// <param name="action"></param>
|
||||
/// <param name="action">Action that wraps a function to be called.</param>
|
||||
public CallbackAction(Action<T1> action)
|
||||
{
|
||||
targetAction = action;
|
||||
|
@ -103,7 +120,7 @@ namespace SHADE
|
|||
{
|
||||
targetAction.Invoke(t1);
|
||||
}
|
||||
else if (TargetObject != null && targetMethod != null)
|
||||
else if (targetMethod != null)
|
||||
{
|
||||
parameters[0] = t1;
|
||||
_ = targetMethod.Invoke(TargetObject, parameters);
|
||||
|
@ -138,8 +155,25 @@ namespace SHADE
|
|||
/// </summary>
|
||||
public CallbackAction() {}
|
||||
/// <summary>
|
||||
/// Constructs a CallbackAction that represents a call to the specified method on the
|
||||
/// specified target.
|
||||
/// Constructs a CallbackAction that represents a call to the specified static
|
||||
/// method.
|
||||
/// </summary>
|
||||
/// <param name="method">Method to call.</param>
|
||||
/// <exception cref="ArgumentException">
|
||||
/// Thrown if a method that is not compatible with the target is specified. The method's
|
||||
/// source type must match the target's type.
|
||||
/// </exception>
|
||||
public CallbackAction(MethodInfo method)
|
||||
{
|
||||
// No errors, assign
|
||||
targetMethod = method;
|
||||
|
||||
// Create storage for parameters for calling
|
||||
parameters = new Object[2];
|
||||
}
|
||||
/// <summary>
|
||||
/// Constructs a CallbackAction that represents a call to a specified member
|
||||
/// method on the specified target.
|
||||
/// </summary>
|
||||
/// <param name="target">Object to call the method on.</param>
|
||||
/// <param name="method">Method to call.</param>
|
||||
|
@ -158,12 +192,12 @@ namespace SHADE
|
|||
targetMethod = method;
|
||||
|
||||
// Create storage for parameters for calling
|
||||
parameters = new Object[1];
|
||||
parameters = new Object[2];
|
||||
}
|
||||
/// <summary>
|
||||
/// Constructs a Callback action based on an action.
|
||||
/// </summary>
|
||||
/// <param name="action"></param>
|
||||
/// <param name="action">Action that wraps a function to be called.</param>
|
||||
public CallbackAction(Action<T1, T2> action)
|
||||
{
|
||||
targetAction = action;
|
||||
|
@ -180,7 +214,7 @@ namespace SHADE
|
|||
{
|
||||
targetAction.Invoke(t1, t2);
|
||||
}
|
||||
else if (TargetObject != null && targetMethod != null)
|
||||
else if (targetMethod != null)
|
||||
{
|
||||
parameters[0] = t1;
|
||||
parameters[1] = t2;
|
||||
|
@ -216,8 +250,25 @@ namespace SHADE
|
|||
/// </summary>
|
||||
public CallbackAction() {}
|
||||
/// <summary>
|
||||
/// Constructs a CallbackAction that represents a call to the specified method on the
|
||||
/// specified target.
|
||||
/// Constructs a CallbackAction that represents a call to the specified static
|
||||
/// method.
|
||||
/// </summary>
|
||||
/// <param name="method">Method to call.</param>
|
||||
/// <exception cref="ArgumentException">
|
||||
/// Thrown if a method that is not compatible with the target is specified. The method's
|
||||
/// source type must match the target's type.
|
||||
/// </exception>
|
||||
public CallbackAction(MethodInfo method)
|
||||
{
|
||||
// No errors, assign
|
||||
targetMethod = method;
|
||||
|
||||
// Create storage for parameters for calling
|
||||
parameters = new Object[3];
|
||||
}
|
||||
/// <summary>
|
||||
/// Constructs a CallbackAction that represents a call to a specified member
|
||||
/// method on the specified target.
|
||||
/// </summary>
|
||||
/// <param name="target">Object to call the method on.</param>
|
||||
/// <param name="method">Method to call.</param>
|
||||
|
@ -236,12 +287,12 @@ namespace SHADE
|
|||
targetMethod = method;
|
||||
|
||||
// Create storage for parameters for calling
|
||||
parameters = new Object[1];
|
||||
parameters = new Object[3];
|
||||
}
|
||||
/// <summary>
|
||||
/// Constructs a Callback action based on an action.
|
||||
/// </summary>
|
||||
/// <param name="action"></param>
|
||||
/// <param name="action">Action that wraps a function to be called.</param>
|
||||
public CallbackAction(Action<T1, T2, T3> action)
|
||||
{
|
||||
targetAction = action;
|
||||
|
@ -258,7 +309,7 @@ namespace SHADE
|
|||
{
|
||||
targetAction.Invoke(t1, t2, t3);
|
||||
}
|
||||
else if (TargetObject != null && targetMethod != null)
|
||||
else if (targetMethod != null)
|
||||
{
|
||||
parameters[0] = t1;
|
||||
parameters[1] = t2;
|
||||
|
@ -295,8 +346,25 @@ namespace SHADE
|
|||
/// </summary>
|
||||
public CallbackAction() {}
|
||||
/// <summary>
|
||||
/// Constructs a CallbackAction that represents a call to the specified method on the
|
||||
/// specified target.
|
||||
/// Constructs a CallbackAction that represents a call to the specified static
|
||||
/// method.
|
||||
/// </summary>
|
||||
/// <param name="method">Method to call.</param>
|
||||
/// <exception cref="ArgumentException">
|
||||
/// Thrown if a method that is not compatible with the target is specified. The method's
|
||||
/// source type must match the target's type.
|
||||
/// </exception>
|
||||
public CallbackAction(MethodInfo method)
|
||||
{
|
||||
// No errors, assign
|
||||
targetMethod = method;
|
||||
|
||||
// Create storage for parameters for calling
|
||||
parameters = new Object[4];
|
||||
}
|
||||
/// <summary>
|
||||
/// Constructs a CallbackAction that represents a call to a specified member
|
||||
/// method on the specified target.
|
||||
/// </summary>
|
||||
/// <param name="target">Object to call the method on.</param>
|
||||
/// <param name="method">Method to call.</param>
|
||||
|
@ -315,12 +383,12 @@ namespace SHADE
|
|||
targetMethod = method;
|
||||
|
||||
// Create storage for parameters for calling
|
||||
parameters = new Object[1];
|
||||
parameters = new Object[4];
|
||||
}
|
||||
/// <summary>
|
||||
/// Constructs a Callback action based on an action.
|
||||
/// </summary>
|
||||
/// <param name="action"></param>
|
||||
/// <param name="action">Action that wraps a function to be called.</param>
|
||||
public CallbackAction(Action<T1, T2, T3, T4> action)
|
||||
{
|
||||
targetAction = action;
|
||||
|
@ -337,7 +405,7 @@ namespace SHADE
|
|||
{
|
||||
targetAction.Invoke(t1, t2, t3, t4);
|
||||
}
|
||||
else if (TargetObject != null && targetMethod != null)
|
||||
else if (targetMethod != null)
|
||||
{
|
||||
parameters[0] = t1;
|
||||
parameters[1] = t2;
|
||||
|
@ -375,8 +443,25 @@ namespace SHADE
|
|||
/// </summary>
|
||||
public CallbackAction() {}
|
||||
/// <summary>
|
||||
/// Constructs a CallbackAction that represents a call to the specified method on the
|
||||
/// specified target.
|
||||
/// Constructs a CallbackAction that represents a call to the specified static
|
||||
/// method.
|
||||
/// </summary>
|
||||
/// <param name="method">Method to call.</param>
|
||||
/// <exception cref="ArgumentException">
|
||||
/// Thrown if a method that is not compatible with the target is specified. The method's
|
||||
/// source type must match the target's type.
|
||||
/// </exception>
|
||||
public CallbackAction(MethodInfo method)
|
||||
{
|
||||
// No errors, assign
|
||||
targetMethod = method;
|
||||
|
||||
// Create storage for parameters for calling
|
||||
parameters = new Object[5];
|
||||
}
|
||||
/// <summary>
|
||||
/// Constructs a CallbackAction that represents a call to a specified member
|
||||
/// method on the specified target.
|
||||
/// </summary>
|
||||
/// <param name="target">Object to call the method on.</param>
|
||||
/// <param name="method">Method to call.</param>
|
||||
|
@ -395,12 +480,12 @@ namespace SHADE
|
|||
targetMethod = method;
|
||||
|
||||
// Create storage for parameters for calling
|
||||
parameters = new Object[1];
|
||||
parameters = new Object[5];
|
||||
}
|
||||
/// <summary>
|
||||
/// Constructs a Callback action based on an action.
|
||||
/// </summary>
|
||||
/// <param name="action"></param>
|
||||
/// <param name="action">Action that wraps a function to be called.</param>
|
||||
public CallbackAction(Action<T1, T2, T3, T4, T5> action)
|
||||
{
|
||||
targetAction = action;
|
||||
|
@ -417,7 +502,7 @@ namespace SHADE
|
|||
{
|
||||
targetAction.Invoke(t1, t2, t3, t4, t5);
|
||||
}
|
||||
else if (TargetObject != null && targetMethod != null)
|
||||
else if (targetMethod != null)
|
||||
{
|
||||
parameters[0] = t1;
|
||||
parameters[1] = t2;
|
||||
|
@ -456,8 +541,25 @@ namespace SHADE
|
|||
/// </summary>
|
||||
public CallbackAction() {}
|
||||
/// <summary>
|
||||
/// Constructs a CallbackAction that represents a call to the specified method on the
|
||||
/// specified target.
|
||||
/// Constructs a CallbackAction that represents a call to the specified static
|
||||
/// method.
|
||||
/// </summary>
|
||||
/// <param name="method">Method to call.</param>
|
||||
/// <exception cref="ArgumentException">
|
||||
/// Thrown if a method that is not compatible with the target is specified. The method's
|
||||
/// source type must match the target's type.
|
||||
/// </exception>
|
||||
public CallbackAction(MethodInfo method)
|
||||
{
|
||||
// No errors, assign
|
||||
targetMethod = method;
|
||||
|
||||
// Create storage for parameters for calling
|
||||
parameters = new Object[6];
|
||||
}
|
||||
/// <summary>
|
||||
/// Constructs a CallbackAction that represents a call to a specified member
|
||||
/// method on the specified target.
|
||||
/// </summary>
|
||||
/// <param name="target">Object to call the method on.</param>
|
||||
/// <param name="method">Method to call.</param>
|
||||
|
@ -476,12 +578,12 @@ namespace SHADE
|
|||
targetMethod = method;
|
||||
|
||||
// Create storage for parameters for calling
|
||||
parameters = new Object[1];
|
||||
parameters = new Object[6];
|
||||
}
|
||||
/// <summary>
|
||||
/// Constructs a Callback action based on an action.
|
||||
/// </summary>
|
||||
/// <param name="action"></param>
|
||||
/// <param name="action">Action that wraps a function to be called.</param>
|
||||
public CallbackAction(Action<T1, T2, T3, T4, T5, T6> action)
|
||||
{
|
||||
targetAction = action;
|
||||
|
@ -498,7 +600,7 @@ namespace SHADE
|
|||
{
|
||||
targetAction.Invoke(t1, t2, t3, t4, t5, t6);
|
||||
}
|
||||
else if (TargetObject != null && targetMethod != null)
|
||||
else if (targetMethod != null)
|
||||
{
|
||||
parameters[0] = t1;
|
||||
parameters[1] = t2;
|
||||
|
@ -538,8 +640,25 @@ namespace SHADE
|
|||
/// </summary>
|
||||
public CallbackAction() {}
|
||||
/// <summary>
|
||||
/// Constructs a CallbackAction that represents a call to the specified method on the
|
||||
/// specified target.
|
||||
/// Constructs a CallbackAction that represents a call to the specified static
|
||||
/// method.
|
||||
/// </summary>
|
||||
/// <param name="method">Method to call.</param>
|
||||
/// <exception cref="ArgumentException">
|
||||
/// Thrown if a method that is not compatible with the target is specified. The method's
|
||||
/// source type must match the target's type.
|
||||
/// </exception>
|
||||
public CallbackAction(MethodInfo method)
|
||||
{
|
||||
// No errors, assign
|
||||
targetMethod = method;
|
||||
|
||||
// Create storage for parameters for calling
|
||||
parameters = new Object[7];
|
||||
}
|
||||
/// <summary>
|
||||
/// Constructs a CallbackAction that represents a call to a specified member
|
||||
/// method on the specified target.
|
||||
/// </summary>
|
||||
/// <param name="target">Object to call the method on.</param>
|
||||
/// <param name="method">Method to call.</param>
|
||||
|
@ -558,12 +677,12 @@ namespace SHADE
|
|||
targetMethod = method;
|
||||
|
||||
// Create storage for parameters for calling
|
||||
parameters = new Object[1];
|
||||
parameters = new Object[7];
|
||||
}
|
||||
/// <summary>
|
||||
/// Constructs a Callback action based on an action.
|
||||
/// </summary>
|
||||
/// <param name="action"></param>
|
||||
/// <param name="action">Action that wraps a function to be called.</param>
|
||||
public CallbackAction(Action<T1, T2, T3, T4, T5, T6, T7> action)
|
||||
{
|
||||
targetAction = action;
|
||||
|
@ -580,7 +699,7 @@ namespace SHADE
|
|||
{
|
||||
targetAction.Invoke(t1, t2, t3, t4, t5, t6, t7);
|
||||
}
|
||||
else if (TargetObject != null && targetMethod != null)
|
||||
else if (targetMethod != null)
|
||||
{
|
||||
parameters[0] = t1;
|
||||
parameters[1] = t2;
|
||||
|
@ -621,8 +740,25 @@ namespace SHADE
|
|||
/// </summary>
|
||||
public CallbackAction() {}
|
||||
/// <summary>
|
||||
/// Constructs a CallbackAction that represents a call to the specified method on the
|
||||
/// specified target.
|
||||
/// Constructs a CallbackAction that represents a call to the specified static
|
||||
/// method.
|
||||
/// </summary>
|
||||
/// <param name="method">Method to call.</param>
|
||||
/// <exception cref="ArgumentException">
|
||||
/// Thrown if a method that is not compatible with the target is specified. The method's
|
||||
/// source type must match the target's type.
|
||||
/// </exception>
|
||||
public CallbackAction(MethodInfo method)
|
||||
{
|
||||
// No errors, assign
|
||||
targetMethod = method;
|
||||
|
||||
// Create storage for parameters for calling
|
||||
parameters = new Object[8];
|
||||
}
|
||||
/// <summary>
|
||||
/// Constructs a CallbackAction that represents a call to a specified member
|
||||
/// method on the specified target.
|
||||
/// </summary>
|
||||
/// <param name="target">Object to call the method on.</param>
|
||||
/// <param name="method">Method to call.</param>
|
||||
|
@ -641,12 +777,12 @@ namespace SHADE
|
|||
targetMethod = method;
|
||||
|
||||
// Create storage for parameters for calling
|
||||
parameters = new Object[1];
|
||||
parameters = new Object[8];
|
||||
}
|
||||
/// <summary>
|
||||
/// Constructs a Callback action based on an action.
|
||||
/// </summary>
|
||||
/// <param name="action"></param>
|
||||
/// <param name="action">Action that wraps a function to be called.</param>
|
||||
public CallbackAction(Action<T1, T2, T3, T4, T5, T6, T7, T8> action)
|
||||
{
|
||||
targetAction = action;
|
||||
|
@ -663,7 +799,7 @@ namespace SHADE
|
|||
{
|
||||
targetAction.Invoke(t1, t2, t3, t4, t5, t6, t7, t8);
|
||||
}
|
||||
else if (TargetObject != null && targetMethod != null)
|
||||
else if (targetMethod != null)
|
||||
{
|
||||
parameters[0] = t1;
|
||||
parameters[1] = t2;
|
||||
|
@ -705,8 +841,25 @@ namespace SHADE
|
|||
/// </summary>
|
||||
public CallbackAction() {}
|
||||
/// <summary>
|
||||
/// Constructs a CallbackAction that represents a call to the specified method on the
|
||||
/// specified target.
|
||||
/// Constructs a CallbackAction that represents a call to the specified static
|
||||
/// method.
|
||||
/// </summary>
|
||||
/// <param name="method">Method to call.</param>
|
||||
/// <exception cref="ArgumentException">
|
||||
/// Thrown if a method that is not compatible with the target is specified. The method's
|
||||
/// source type must match the target's type.
|
||||
/// </exception>
|
||||
public CallbackAction(MethodInfo method)
|
||||
{
|
||||
// No errors, assign
|
||||
targetMethod = method;
|
||||
|
||||
// Create storage for parameters for calling
|
||||
parameters = new Object[9];
|
||||
}
|
||||
/// <summary>
|
||||
/// Constructs a CallbackAction that represents a call to a specified member
|
||||
/// method on the specified target.
|
||||
/// </summary>
|
||||
/// <param name="target">Object to call the method on.</param>
|
||||
/// <param name="method">Method to call.</param>
|
||||
|
@ -725,12 +878,12 @@ namespace SHADE
|
|||
targetMethod = method;
|
||||
|
||||
// Create storage for parameters for calling
|
||||
parameters = new Object[1];
|
||||
parameters = new Object[9];
|
||||
}
|
||||
/// <summary>
|
||||
/// Constructs a Callback action based on an action.
|
||||
/// </summary>
|
||||
/// <param name="action"></param>
|
||||
/// <param name="action">Action that wraps a function to be called.</param>
|
||||
public CallbackAction(Action<T1, T2, T3, T4, T5, T6, T7, T8, T9> action)
|
||||
{
|
||||
targetAction = action;
|
||||
|
@ -747,7 +900,7 @@ namespace SHADE
|
|||
{
|
||||
targetAction.Invoke(t1, t2, t3, t4, t5, t6, t7, t8, t9);
|
||||
}
|
||||
else if (TargetObject != null && targetMethod != null)
|
||||
else if (targetMethod != null)
|
||||
{
|
||||
parameters[0] = t1;
|
||||
parameters[1] = t2;
|
||||
|
@ -790,8 +943,25 @@ namespace SHADE
|
|||
/// </summary>
|
||||
public CallbackAction() {}
|
||||
/// <summary>
|
||||
/// Constructs a CallbackAction that represents a call to the specified method on the
|
||||
/// specified target.
|
||||
/// Constructs a CallbackAction that represents a call to the specified static
|
||||
/// method.
|
||||
/// </summary>
|
||||
/// <param name="method">Method to call.</param>
|
||||
/// <exception cref="ArgumentException">
|
||||
/// Thrown if a method that is not compatible with the target is specified. The method's
|
||||
/// source type must match the target's type.
|
||||
/// </exception>
|
||||
public CallbackAction(MethodInfo method)
|
||||
{
|
||||
// No errors, assign
|
||||
targetMethod = method;
|
||||
|
||||
// Create storage for parameters for calling
|
||||
parameters = new Object[10];
|
||||
}
|
||||
/// <summary>
|
||||
/// Constructs a CallbackAction that represents a call to a specified member
|
||||
/// method on the specified target.
|
||||
/// </summary>
|
||||
/// <param name="target">Object to call the method on.</param>
|
||||
/// <param name="method">Method to call.</param>
|
||||
|
@ -810,12 +980,12 @@ namespace SHADE
|
|||
targetMethod = method;
|
||||
|
||||
// Create storage for parameters for calling
|
||||
parameters = new Object[1];
|
||||
parameters = new Object[10];
|
||||
}
|
||||
/// <summary>
|
||||
/// Constructs a Callback action based on an action.
|
||||
/// </summary>
|
||||
/// <param name="action"></param>
|
||||
/// <param name="action">Action that wraps a function to be called.</param>
|
||||
public CallbackAction(Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> action)
|
||||
{
|
||||
targetAction = action;
|
||||
|
@ -832,7 +1002,7 @@ namespace SHADE
|
|||
{
|
||||
targetAction.Invoke(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10);
|
||||
}
|
||||
else if (TargetObject != null && targetMethod != null)
|
||||
else if (targetMethod != null)
|
||||
{
|
||||
parameters[0] = t1;
|
||||
parameters[1] = t2;
|
||||
|
|
|
@ -78,8 +78,25 @@ namespace SHADE
|
|||
/// </summary>
|
||||
public CallbackAction() {}
|
||||
/// <summary>
|
||||
/// Constructs a CallbackAction that represents a call to the specified method on the
|
||||
/// specified target.
|
||||
/// Constructs a CallbackAction that represents a call to the specified static
|
||||
/// method.
|
||||
/// </summary>
|
||||
/// <param name="method">Method to call.</param>
|
||||
/// <exception cref="ArgumentException">
|
||||
/// Thrown if a method that is not compatible with the target is specified. The method's
|
||||
/// source type must match the target's type.
|
||||
/// </exception>
|
||||
public CallbackAction(MethodInfo method)
|
||||
{
|
||||
// No errors, assign
|
||||
targetMethod = method;
|
||||
|
||||
// Create storage for parameters for calling
|
||||
parameters = new Object[<#=i#>];
|
||||
}
|
||||
/// <summary>
|
||||
/// Constructs a CallbackAction that represents a call to a specified member
|
||||
/// method on the specified target.
|
||||
/// </summary>
|
||||
/// <param name="target">Object to call the method on.</param>
|
||||
/// <param name="method">Method to call.</param>
|
||||
|
@ -98,12 +115,12 @@ namespace SHADE
|
|||
targetMethod = method;
|
||||
|
||||
// Create storage for parameters for calling
|
||||
parameters = new Object[1];
|
||||
parameters = new Object[<#=i#>];
|
||||
}
|
||||
/// <summary>
|
||||
/// Constructs a Callback action based on an action.
|
||||
/// </summary>
|
||||
/// <param name="action"></param>
|
||||
/// <param name="action">Action that wraps a function to be called.</param>
|
||||
public CallbackAction(Action<<# for (int t = 1; t < i + 1; ++t) { #>T<#=t#><# if (t != i) { #>, <# } #><# } #>> action)
|
||||
{
|
||||
targetAction = action;
|
||||
|
@ -120,7 +137,7 @@ namespace SHADE
|
|||
{
|
||||
targetAction.Invoke(<# for (int t = 1; t < i + 1; ++t) { #>t<#=t#><# if (t != i) { #>, <# } #><# } #>);
|
||||
}
|
||||
else if (TargetObject != null && targetMethod != null)
|
||||
else if (targetMethod != null)
|
||||
{
|
||||
<# for (int t = 0; t < i; ++t) {#>parameters[<#=t#>] = t<#=t+1#>;
|
||||
<# } #>_ = targetMethod.Invoke(TargetObject, parameters);
|
||||
|
|
|
@ -13,10 +13,24 @@
|
|||
#include "Editor/IconsFontAwesome6.h"
|
||||
#include "ECS_Base/Components/SHComponent.h"
|
||||
#include "Editor/SHEditorWidgets.hpp"
|
||||
#include "Graphics/MiddleEnd/Lights/SHLightComponent.h"
|
||||
#include "Physics/Components/SHColliderComponent.h"
|
||||
#include "Reflection/SHReflectionMetadata.h"
|
||||
namespace SHADE
|
||||
{
|
||||
template<typename T>
|
||||
std::vector<const char*> GetRTTREnumNames()
|
||||
{
|
||||
auto const rttrType = rttr::type::get<T>();
|
||||
if(!rttrType.is_enumeration())
|
||||
return {};
|
||||
auto const enumAlign = rttrType.get_enumeration();
|
||||
auto const names = enumAlign.get_names();
|
||||
std::vector<const char*> result;
|
||||
std::transform(names.begin(), names.end(), std::back_inserter(result), [](rttr::string_view const& name){return name.data();});
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename T, std::enable_if_t<std::is_base_of<SHComponent, T>::value, bool> = true>
|
||||
static void DrawContextMenu(T* component)
|
||||
{
|
||||
|
@ -290,4 +304,34 @@ namespace SHADE
|
|||
}
|
||||
else DrawContextMenu(component);
|
||||
}
|
||||
|
||||
template<>
|
||||
static void DrawComponent(SHLightComponent* component)
|
||||
{
|
||||
if (!component)
|
||||
return;
|
||||
const auto componentType = rttr::type::get(*component);
|
||||
SHEditorWidgets::CheckBox("##IsActive", [component]() {return component->isActive; }, [component](bool const& active) {component->isActive = active; });
|
||||
ImGui::SameLine();
|
||||
if (ImGui::CollapsingHeader(componentType.get_name().data()))
|
||||
{
|
||||
DrawContextMenu(component);
|
||||
|
||||
static auto const enumAlign = rttr::type::get<SH_LIGHT_TYPE>().get_enumeration();
|
||||
static std::vector<const char*> list(GetRTTREnumNames<SH_LIGHT_TYPE>());
|
||||
|
||||
SHEditorWidgets::ComboBox("Type", list, [component] {return static_cast<int>(component->GetType()); }, [component](int const& idx)
|
||||
{
|
||||
component->SetType(static_cast<SH_LIGHT_TYPE>(idx));
|
||||
});
|
||||
SHEditorWidgets::DragVec3("Position", {"X", "Y", "Z"}, [component](){return component->GetPosition();}, [component](SHVec3 const& vec){component->SetPosition(vec);});
|
||||
SHEditorWidgets::DragVec3("Direction", {"X", "Y", "Z"}, [component](){return component->GetDirection();}, [component](SHVec3 const& vec){component->SetDirection(vec);});
|
||||
SHEditorWidgets::ColorPicker("Color", [component](){return component->GetColor();}, [component](SHVec4 const& rgba){component->SetColor(rgba);});
|
||||
SHEditorWidgets::DragFloat("Strength", [component](){return component->GetStrength();}, [component](float const& value){component->SetStrength(value);});
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawContextMenu(component);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -100,6 +100,10 @@ namespace SHADE
|
|||
{
|
||||
DrawComponent(rigidbodyComponent);
|
||||
}
|
||||
if(auto lightComponent = SHComponentManager::GetComponent_s<SHLightComponent>(eid))
|
||||
{
|
||||
DrawComponent(lightComponent);
|
||||
}
|
||||
if (auto cameraComponent = SHComponentManager::GetComponent_s<SHCameraComponent>(eid))
|
||||
{
|
||||
DrawComponent(cameraComponent);
|
||||
|
|
|
@ -192,8 +192,8 @@ namespace SHADE
|
|||
ImGuiColors::colors[i], 4);
|
||||
|
||||
ImGui::SameLine(0, g.Style.ItemInnerSpacing.x);
|
||||
ImGui::PopID();
|
||||
ImGui::PopItemWidth();
|
||||
ImGui::PopID();
|
||||
}
|
||||
ImGui::EndColumns();
|
||||
ImGui::PopID();
|
||||
|
@ -615,5 +615,43 @@ namespace SHADE
|
|||
}
|
||||
return edited;
|
||||
}
|
||||
|
||||
static bool ColorPicker(const std::string_view& label, std::function<SHVec4(void)> get, std::function<void(SHVec4 const&)> set, std::string_view const& tooltip = {}, float speed = 0.1f, const char* displayFormat = "%.3f", float valueMin = 0.0f, float valueMax = 0.0f,
|
||||
ImGuiSliderFlags flags = 0)
|
||||
{
|
||||
bool changed = false;
|
||||
ImGui::BeginGroup();
|
||||
ImGui::PushID(label.data());
|
||||
|
||||
SHVec4 values = get();
|
||||
//changed |= DragN<float, 4>(label.data(), {"R", "G", "B", "A"}, { &values.x, &values.y, &values.z, &values.w }, speed, displayFormat, valueMin, valueMax, flags);
|
||||
//ImGui::SameLine();
|
||||
TextLabel(label);
|
||||
changed = ImGui::ColorEdit4("##Col4", &values.x, ImGuiColorEditFlags_AlphaPreviewHalf | ImGuiColorEditFlags_AlphaBar | ImGuiColorEditFlags_DisplayRGB );
|
||||
static bool startRecording = false;
|
||||
if(changed)
|
||||
{
|
||||
SHCommandManager::PerformCommand(std::reinterpret_pointer_cast<SHBaseCommand>(std::make_shared<SHCommand<SHVec4>>(get(), values, set)), startRecording);
|
||||
if(!startRecording)
|
||||
startRecording = true;
|
||||
}
|
||||
if (startRecording && ImGui::IsMouseReleased(ImGuiMouseButton_Left))
|
||||
{
|
||||
startRecording = false;
|
||||
}
|
||||
ImGui::PopID();
|
||||
ImGui::EndGroup();
|
||||
if (!tooltip.empty())
|
||||
{
|
||||
if (ImGui::IsItemHovered())
|
||||
{
|
||||
ImGui::BeginTooltip();
|
||||
ImGui::Text(tooltip.data());
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
};
|
||||
|
||||
}//namespace SHADE
|
||||
|
|
|
@ -186,9 +186,10 @@ namespace SHADE
|
|||
vk::PhysicalDeviceFeatures features{}; // ADD MORE FEATURES HERE IF NEEDED
|
||||
|
||||
// point and lines fill mode
|
||||
features.fillModeNonSolid = true;
|
||||
features.fillModeNonSolid = VK_TRUE;
|
||||
features.samplerAnisotropy = VK_TRUE;
|
||||
features.multiDrawIndirect = true;
|
||||
features.multiDrawIndirect = VK_TRUE;
|
||||
features.independentBlend = VK_TRUE;
|
||||
|
||||
// for wide lines
|
||||
features.wideLines = true;
|
||||
|
|
|
@ -194,7 +194,8 @@ namespace SHADE
|
|||
{
|
||||
SHLOG_WARNING("[SHBatch] Entity with a missing SHRenderable found!");
|
||||
}
|
||||
propsCurrPtr += singleMatPropAlignedSize;
|
||||
//propsCurrPtr += singleMatPropAlignedSize;
|
||||
propsCurrPtr += singleMatPropSize;
|
||||
}
|
||||
|
||||
// Transfer to GPU
|
||||
|
@ -316,7 +317,7 @@ namespace SHADE
|
|||
{
|
||||
singleMatPropSize = SHADER_INFO->GetBytesRequired();
|
||||
singleMatPropAlignedSize = device->PadSSBOSize(static_cast<uint32_t>(singleMatPropSize));
|
||||
matPropTotalBytes = numTotalElements * singleMatPropAlignedSize;
|
||||
matPropTotalBytes = numTotalElements * singleMatPropSize;
|
||||
if (matPropsDataSize < matPropTotalBytes)
|
||||
{
|
||||
matPropsData.reset(new char[matPropTotalBytes]);
|
||||
|
@ -375,7 +376,8 @@ namespace SHADE
|
|||
{
|
||||
SHLOG_WARNING("[SHBatch] Entity with a missing SHRenderable found!");
|
||||
}
|
||||
propsCurrPtr += singleMatPropAlignedSize;
|
||||
//propsCurrPtr += singleMatPropAlignedSize;
|
||||
propsCurrPtr += singleMatPropSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,36 +47,35 @@ namespace SHADE
|
|||
// For global data (generic data and textures)
|
||||
Handle<SHVkDescriptorSetLayout> staticGlobalLayout = logicalDevice->CreateDescriptorSetLayout(SHGraphicsConstants::DescriptorSetIndex::STATIC_GLOBALS,{ genericDataBinding, texturesBinding });
|
||||
|
||||
|
||||
std::vector<SHVkDescriptorSetLayout::Binding> lightBindings{};
|
||||
for (uint32_t i = 0; i < SHUtilities::ToUnderlying(SH_LIGHT_TYPE::NUM_TYPES); ++i)
|
||||
|
||||
// This is the binding we use to count the lights (binding 0)
|
||||
lightBindings.push_back(SHVkDescriptorSetLayout::Binding
|
||||
{
|
||||
.Type = vk::DescriptorType::eUniformBufferDynamic,
|
||||
.Stage = vk::ShaderStageFlagBits::eCompute,
|
||||
.BindPoint = 0,
|
||||
.DescriptorCount = 1,
|
||||
|
||||
});
|
||||
|
||||
for (uint32_t i = 1; i <= SHUtilities::ToUnderlying(SH_LIGHT_TYPE::NUM_TYPES); ++i)
|
||||
{
|
||||
lightBindings.push_back (SHVkDescriptorSetLayout::Binding
|
||||
{
|
||||
.Type = vk::DescriptorType::eStorageBufferDynamic,
|
||||
.Stage = vk::ShaderStageFlagBits::eFragment,
|
||||
.Stage = vk::ShaderStageFlagBits::eCompute,
|
||||
.BindPoint = i,
|
||||
.DescriptorCount = 1,
|
||||
});
|
||||
}
|
||||
//SHVkDescriptorSetLayout::Binding pointLightBinding
|
||||
//{
|
||||
// .Type = vk::DescriptorType::eStorageBufferDynamic,
|
||||
// .Stage = vk::ShaderStageFlagBits::eFragment,
|
||||
// .BindPoint = SHGraphicsConstants::DescriptorSetBindings::POINT_LIGHT_DATA,
|
||||
// .DescriptorCount = 1,
|
||||
//};
|
||||
|
||||
//SHVkDescriptorSetLayout::Binding spotLightBinding
|
||||
//{
|
||||
// .Type = vk::DescriptorType::eStorageBufferDynamic,
|
||||
// .Stage = vk::ShaderStageFlagBits::eFragment,
|
||||
// .BindPoint = SHGraphicsConstants::DescriptorSetBindings::SPOT_LIGHT_DATA,
|
||||
// .DescriptorCount = 1,
|
||||
//};
|
||||
|
||||
// For Dynamic global data (lights)
|
||||
Handle<SHVkDescriptorSetLayout> dynamicGlobalLayout = logicalDevice->CreateDescriptorSetLayout(SHGraphicsConstants::DescriptorSetIndex::DYNAMIC_GLOBALS, lightBindings);
|
||||
|
||||
|
||||
SHVkDescriptorSetLayout::Binding cameraDataBinding
|
||||
{
|
||||
.Type = vk::DescriptorType::eUniformBufferDynamic,
|
||||
|
|
|
@ -94,32 +94,14 @@ namespace SHADE
|
|||
/***************************************************************************/
|
||||
static constexpr uint32_t IMAGE_AND_SAMPLERS_DATA = 1;
|
||||
|
||||
///***************************************************************************/
|
||||
///*!
|
||||
// \brief
|
||||
// DescriptorSet binding for directional lights.
|
||||
/***************************************************************************/
|
||||
/*!
|
||||
\brief
|
||||
DescriptorSet binding for combined image sampler data.
|
||||
|
||||
//*/
|
||||
///***************************************************************************/
|
||||
//static constexpr uint32_t DIRECTIONAL_LIGHT_DATA = 0;
|
||||
|
||||
///***************************************************************************/
|
||||
///*!
|
||||
// \brief
|
||||
// DescriptorSet binding for directional lights.
|
||||
|
||||
//*/
|
||||
///***************************************************************************/
|
||||
//static constexpr uint32_t POINT_LIGHT_DATA = 1;
|
||||
|
||||
///***************************************************************************/
|
||||
///*!
|
||||
// \brief
|
||||
// DescriptorSet binding for directional lights.
|
||||
|
||||
//*/
|
||||
///***************************************************************************/
|
||||
//static constexpr uint32_t SPOT_LIGHT_DATA = 2;
|
||||
*/
|
||||
/***************************************************************************/
|
||||
static constexpr uint32_t LIGHTING_COUNT = 0;
|
||||
|
||||
/***************************************************************************/
|
||||
/*!
|
||||
|
|
|
@ -73,15 +73,7 @@ namespace SHADE
|
|||
if (width == 0 || height == 0)
|
||||
return;
|
||||
|
||||
#ifdef SHEDITOR
|
||||
|
||||
//PrepareResize(1, 1, SHVec2(0, 0));
|
||||
|
||||
#else
|
||||
|
||||
PrepareResize(resizeWidth, resizeHeight, SHVec2(0, 0));
|
||||
|
||||
#endif
|
||||
PrepareResize(resizeWidth, resizeHeight);
|
||||
});
|
||||
|
||||
window->RegisterWindowCloseCallback([&](void)
|
||||
|
@ -160,26 +152,45 @@ namespace SHADE
|
|||
|
||||
// Initialize world render graph
|
||||
worldRenderGraph->Init(device, swapchain);
|
||||
worldRenderGraph->AddResource("Scene Pre-Process", { SH_ATT_DESC_TYPE_FLAGS::COLOR, SH_ATT_DESC_TYPE_FLAGS::INPUT, SH_ATT_DESC_TYPE_FLAGS::STORAGE }, windowDims.first, windowDims.second);
|
||||
worldRenderGraph->AddResource("Scene", { SH_ATT_DESC_TYPE_FLAGS::COLOR, SH_ATT_DESC_TYPE_FLAGS::INPUT, SH_ATT_DESC_TYPE_FLAGS::STORAGE }, windowDims.first, windowDims.second);
|
||||
worldRenderGraph->AddResource("Position", { SH_ATT_DESC_TYPE_FLAGS::COLOR, SH_ATT_DESC_TYPE_FLAGS::INPUT, SH_ATT_DESC_TYPE_FLAGS::STORAGE }, windowDims.first, windowDims.second, vk::Format::eR32G32B32A32Sfloat);
|
||||
worldRenderGraph->AddResource("Normals", { SH_ATT_DESC_TYPE_FLAGS::COLOR, SH_ATT_DESC_TYPE_FLAGS::INPUT, SH_ATT_DESC_TYPE_FLAGS::STORAGE }, windowDims.first, windowDims.second, vk::Format::eR32G32B32A32Sfloat);
|
||||
worldRenderGraph->AddResource("Albedo", { SH_ATT_DESC_TYPE_FLAGS::COLOR, SH_ATT_DESC_TYPE_FLAGS::INPUT, SH_ATT_DESC_TYPE_FLAGS::STORAGE }, windowDims.first, windowDims.second);
|
||||
worldRenderGraph->AddResource("Depth Buffer", { SH_ATT_DESC_TYPE_FLAGS::DEPTH_STENCIL }, windowDims.first, windowDims.second, vk::Format::eD32SfloatS8Uint);
|
||||
worldRenderGraph->AddResource("Entity ID", { SH_ATT_DESC_TYPE_FLAGS::COLOR }, windowDims.first, windowDims.second, vk::Format::eR32Uint, 1, vk::ImageUsageFlagBits::eTransferSrc);
|
||||
worldRenderGraph->AddResource("Light Layer Indices", { SH_ATT_DESC_TYPE_FLAGS::COLOR }, windowDims.first, windowDims.second, vk::Format::eR32Uint, 1, vk::ImageUsageFlagBits::eTransferSrc);
|
||||
worldRenderGraph->AddResource("Light Layer Indices", { SH_ATT_DESC_TYPE_FLAGS::COLOR, SH_ATT_DESC_TYPE_FLAGS::INPUT, SH_ATT_DESC_TYPE_FLAGS::STORAGE }, windowDims.first, windowDims.second, vk::Format::eR32Uint, 1, vk::ImageUsageFlagBits::eTransferSrc);
|
||||
worldRenderGraph->AddResource("Scene", { SH_ATT_DESC_TYPE_FLAGS::COLOR, SH_ATT_DESC_TYPE_FLAGS::INPUT, SH_ATT_DESC_TYPE_FLAGS::STORAGE }, windowDims.first, windowDims.second);
|
||||
|
||||
auto gBufferNode = worldRenderGraph->AddNode("G-Buffer",
|
||||
{
|
||||
"Position",
|
||||
"Entity ID",
|
||||
"Light Layer Indices",
|
||||
"Normals",
|
||||
"Albedo",
|
||||
"Depth Buffer",
|
||||
"Scene"
|
||||
},
|
||||
{}); // no predecessors
|
||||
|
||||
auto gBufferNode = worldRenderGraph->AddNode("G-Buffer", { "Light Layer Indices", "Entity ID", "Depth Buffer", "Scene", "Scene Pre-Process"}, {}); // no predecessors
|
||||
auto gBufferSubpass = gBufferNode->AddSubpass("G-Buffer Write");
|
||||
gBufferSubpass->AddColorOutput("Scene Pre-Process");
|
||||
gBufferSubpass->AddColorOutput("Position");
|
||||
gBufferSubpass->AddColorOutput("Entity ID");
|
||||
gBufferSubpass->AddColorOutput("Light Layer Indices");
|
||||
gBufferSubpass->AddColorOutput("Normals");
|
||||
gBufferSubpass->AddColorOutput("Albedo");
|
||||
gBufferSubpass->AddDepthOutput("Depth Buffer", SH_ATT_DESC_TYPE_FLAGS::DEPTH_STENCIL);
|
||||
|
||||
//// kirsch
|
||||
//auto kirschShader = shaderModuleLibrary.GetShaderModule("KirschCs");
|
||||
//gBufferNode->AddNodeCompute(kirschShader, { "Scene Pre-Process", "Scene" });
|
||||
//auto kirschShader = shaderModuleLibrary.GetShaderModule("KirschCs.glsl");
|
||||
//gBufferNode->AddNodeCompute(kirschShader, { "Position", "Scene" });
|
||||
|
||||
// copy
|
||||
auto pureCopyShader = shaderModuleLibrary.GetBuiltInShaderModule("PureCopy_CS");
|
||||
gBufferNode->AddNodeCompute(pureCopyShader, { "Scene Pre-Process", "Scene" });
|
||||
//// copy
|
||||
//auto pureCopyShader = shaderModuleLibrary.GetShaderModule("PureCopyCs.glsl");
|
||||
//gBufferNode->AddNodeCompute(pureCopyShader, { "Position", "Scene" });
|
||||
|
||||
// deferred composite
|
||||
auto deferredCompositeShader = shaderModuleLibrary.GetBuiltInShaderModule("DeferredComposite_CS");
|
||||
gBufferNode->AddNodeCompute(deferredCompositeShader, { "Position", "Normals", "Albedo", "Light Layer Indices", "Scene" });
|
||||
|
||||
|
||||
auto dummyNode = worldRenderGraph->AddNode("Dummy Pass", { "Scene" }, {"G-Buffer"}); // no predecessors
|
||||
|
@ -311,6 +322,12 @@ namespace SHADE
|
|||
void SHGraphicsSystem::Run(double) noexcept
|
||||
{
|
||||
if (window->IsMinimized() || renderContext.GetWindowIsDead())
|
||||
{
|
||||
restoredFromMinimize = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (restoredFromMinimize)
|
||||
return;
|
||||
|
||||
// Frame data for the current frame
|
||||
|
@ -362,6 +379,7 @@ namespace SHADE
|
|||
|
||||
// Force set the pipeline layout
|
||||
currentCmdBuffer->ForceSetPipelineLayout(SHGraphicsGlobalData::GetDummyPipelineLayout(), SH_PIPELINE_TYPE::GRAPHICS);
|
||||
currentCmdBuffer->ForceSetPipelineLayout(SHGraphicsGlobalData::GetDummyPipelineLayout(), SH_PIPELINE_TYPE::COMPUTE);
|
||||
|
||||
// Bind all the buffers required for meshes
|
||||
for (auto& [buffer, bindingPoint] : MESH_DATA)
|
||||
|
@ -444,7 +462,15 @@ namespace SHADE
|
|||
void SHGraphicsSystem::BeginRender()
|
||||
{
|
||||
if (window->IsMinimized() || renderContext.GetWindowIsDead())
|
||||
{
|
||||
restoredFromMinimize = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (restoredFromMinimize)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Finalise all batches
|
||||
for (auto vp : viewports)
|
||||
|
@ -493,7 +519,17 @@ namespace SHADE
|
|||
void SHGraphicsSystem::EndRender()
|
||||
{
|
||||
if (window->IsMinimized() || renderContext.GetWindowIsDead())
|
||||
{
|
||||
restoredFromMinimize = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (restoredFromMinimize)
|
||||
{
|
||||
restoredFromMinimize = false;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
const uint32_t CURR_FRAME_IDX = renderContext.GetCurrentFrame();
|
||||
auto& currFrameData = renderContext.GetCurrentFrameData();
|
||||
|
|
|
@ -360,5 +360,7 @@ namespace SHADE
|
|||
|
||||
uint32_t resizeWidth;
|
||||
uint32_t resizeHeight;
|
||||
bool restoredFromMinimize = false;
|
||||
|
||||
};
|
||||
}
|
|
@ -58,7 +58,7 @@ namespace SHADE
|
|||
}
|
||||
|
||||
// Get offset and return the memory directly
|
||||
T* dataPtr = propMemory.get() + PROP_INFO->offset;
|
||||
T* dataPtr = reinterpret_cast<T*>(propMemory.get() + PROP_INFO->offset);
|
||||
return *dataPtr;
|
||||
}
|
||||
template<typename T>
|
||||
|
|
|
@ -69,7 +69,7 @@ namespace SHADE
|
|||
|
||||
// Search Override Data for the property
|
||||
uint32_t PROP_IDX = SHADER_INFO->GetVariableIndex(key);
|
||||
auto prop = std::find(overrideData.begin(), overrideData.end(), [&](const OverrideData& data)
|
||||
auto prop = std::find_if(overrideData.begin(), overrideData.end(), [&](const OverrideData& data)
|
||||
{
|
||||
return PROP_IDX == data.Index;
|
||||
});
|
||||
|
@ -77,7 +77,7 @@ namespace SHADE
|
|||
throw std::invalid_argument("Attempted to get an property that was not set previously!");
|
||||
|
||||
// Get offset and return the memory directly
|
||||
T* dataPtr = dataStore.get() + prop->StoredDataOffset;
|
||||
T* dataPtr = reinterpret_cast<T*>(dataStore.get() + prop->StoredDataOffset);
|
||||
return *dataPtr;
|
||||
}
|
||||
template<typename T>
|
||||
|
|
|
@ -17,7 +17,8 @@ of DigiPen Institute of Technology is prohibited.
|
|||
// Project Includes
|
||||
#include "Resource/SHHandle.h"
|
||||
#include "Resource/SHResourceLibrary.h"
|
||||
#include "Math/SHMath.h"
|
||||
#include "Math/Vector/SHVec2.h"
|
||||
#include "Math/Vector/SHVec3.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace SHADE
|
|||
material = {};
|
||||
oldMaterial = {};
|
||||
|
||||
lightLayer = 0;
|
||||
lightLayer = 1;
|
||||
}
|
||||
|
||||
void SHRenderable::OnDestroy()
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace SHADE
|
|||
lightData.Reset();
|
||||
SetType(SH_LIGHT_TYPE::DIRECTIONAL);
|
||||
indexInBuffer = std::numeric_limits<uint32_t>::max();
|
||||
active = true;
|
||||
isActive = true;
|
||||
Unbind();
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ namespace SHADE
|
|||
|
||||
}
|
||||
|
||||
void SHLightComponent::SetPosition(SHVec3 position) noexcept
|
||||
void SHLightComponent::SetPosition(SHVec3 const& position) noexcept
|
||||
{
|
||||
lightData.position = position;
|
||||
MakeDirty();
|
||||
|
@ -34,20 +34,20 @@ namespace SHADE
|
|||
}
|
||||
|
||||
|
||||
void SHLightComponent::SetDirection(SHVec3 direction) noexcept
|
||||
void SHLightComponent::SetDirection(SHVec3 const& direction) noexcept
|
||||
{
|
||||
lightData.direction = direction;
|
||||
MakeDirty();
|
||||
}
|
||||
|
||||
|
||||
void SHLightComponent::SetDiffuseColor(SHVec4 diffuseColor) noexcept
|
||||
void SHLightComponent::SetColor(SHVec4 const& color) noexcept
|
||||
{
|
||||
lightData.diffuseColor = diffuseColor;
|
||||
lightData.color = color;
|
||||
MakeDirty();
|
||||
}
|
||||
|
||||
void SHLightComponent::ModifyLayer(uint8_t layerIndex, bool value) noexcept
|
||||
void SHLightComponent::ModifyCullingMask(uint8_t layerIndex, bool value) noexcept
|
||||
{
|
||||
if (value)
|
||||
lightData.cullingMask |= (1u << layerIndex);
|
||||
|
@ -57,6 +57,10 @@ namespace SHADE
|
|||
MakeDirty();
|
||||
}
|
||||
|
||||
void SHLightComponent::SetCullingMask(uint32_t const& value) noexcept
|
||||
{
|
||||
lightData.cullingMask = value;
|
||||
}
|
||||
|
||||
void SHLightComponent::SetAllLayers(void) noexcept
|
||||
{
|
||||
|
@ -93,11 +97,11 @@ namespace SHADE
|
|||
indexInBuffer = inIndexInBuffer;
|
||||
}
|
||||
|
||||
void SHLightComponent::SetActive(bool flag) noexcept
|
||||
{
|
||||
MakeDirty();
|
||||
active = flag;
|
||||
|
||||
void SHLightComponent::SetStrength(float value) noexcept
|
||||
{
|
||||
lightData.strength = value;
|
||||
MakeDirty();
|
||||
}
|
||||
|
||||
SHLightData const& SHLightComponent::GetLightData(void) const noexcept
|
||||
|
@ -105,6 +109,32 @@ namespace SHADE
|
|||
return lightData;
|
||||
}
|
||||
|
||||
SHVec3 const& SHLightComponent::GetPosition(void) const noexcept
|
||||
{
|
||||
return lightData.position;
|
||||
}
|
||||
|
||||
SH_LIGHT_TYPE SHLightComponent::GetType(void) const noexcept
|
||||
{
|
||||
return lightData.type;
|
||||
}
|
||||
|
||||
SHVec3 const& SHLightComponent::GetDirection(void) const noexcept
|
||||
{
|
||||
return lightData.direction;
|
||||
}
|
||||
|
||||
SHVec4 const& SHLightComponent::GetColor(void) const noexcept
|
||||
{
|
||||
return lightData.color;
|
||||
}
|
||||
|
||||
uint32_t const& SHLightComponent::GetCullingMask(void) const noexcept
|
||||
{
|
||||
return lightData.cullingMask;
|
||||
}
|
||||
|
||||
|
||||
bool SHLightComponent::IsDirty(void) const noexcept
|
||||
{
|
||||
return dirty;
|
||||
|
@ -120,4 +150,32 @@ namespace SHADE
|
|||
return indexInBuffer;
|
||||
}
|
||||
|
||||
float SHLightComponent::GetStrength(void) const noexcept
|
||||
{
|
||||
return lightData.strength;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
RTTR_REGISTRATION
|
||||
{
|
||||
using namespace SHADE;
|
||||
using namespace rttr;
|
||||
|
||||
registration::enumeration<SH_LIGHT_TYPE>("Light Type")
|
||||
(
|
||||
value("Directional", SH_LIGHT_TYPE::DIRECTIONAL),
|
||||
value("Point", SH_LIGHT_TYPE::POINT),
|
||||
value("Spot", SH_LIGHT_TYPE::SPOT),
|
||||
value("Ambient", SH_LIGHT_TYPE::AMBIENT)
|
||||
);
|
||||
|
||||
registration::class_<SHLightComponent>("Light Component")
|
||||
.property("Position", &SHLightComponent::GetPosition, &SHLightComponent::SetPosition)
|
||||
.property("Type", &SHLightComponent::GetType, &SHLightComponent::SetType)
|
||||
.property("Direction", &SHLightComponent::GetDirection, &SHLightComponent::SetDirection)
|
||||
.property("Color", &SHLightComponent::GetColor, &SHLightComponent::SetColor)
|
||||
.property("Layer", &SHLightComponent::GetCullingMask, &SHLightComponent::SetCullingMask)
|
||||
.property("Strength", &SHLightComponent::GetStrength, &SHLightComponent::SetStrength)
|
||||
;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <rttr/registration>
|
||||
#include "ECS_Base/Components/SHComponent.h"
|
||||
#include "SHLightData.h"
|
||||
|
||||
|
@ -24,8 +25,6 @@ namespace SHADE
|
|||
//! If the light's data is already in the buffers, this will be set to true.
|
||||
bool bound;
|
||||
|
||||
//! If the light is active, this is true.
|
||||
bool active;
|
||||
|
||||
public:
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
@ -37,24 +36,31 @@ namespace SHADE
|
|||
/*-----------------------------------------------------------------------*/
|
||||
/* SETTERS AND GETTERS */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
void SetPosition (SHVec3 position) noexcept;
|
||||
void SetType (SH_LIGHT_TYPE type) noexcept;
|
||||
void SetDirection (SHVec3 direction) noexcept;
|
||||
void SetDiffuseColor (SHVec4 diffuseColor) noexcept;
|
||||
void ModifyLayer (uint8_t layerIndex, bool value) noexcept;
|
||||
void SetAllLayers (void) noexcept;
|
||||
void ClearAllLayers (void) noexcept;
|
||||
void SetPosition (SHVec3 const& position) noexcept; // serialized
|
||||
void SetType (SH_LIGHT_TYPE type) noexcept; // serialized
|
||||
void SetDirection (SHVec3 const& direction) noexcept; // serialized
|
||||
void SetColor (SHVec4 const& color) noexcept; // serialized
|
||||
void ModifyCullingMask (uint8_t layerIndex, bool value) noexcept; // serialized
|
||||
void SetCullingMask (uint32_t const& value) noexcept;
|
||||
void SetAllLayers (void) noexcept; // serialized
|
||||
void ClearAllLayers (void) noexcept; // serialized
|
||||
void MakeDirty (void) noexcept;
|
||||
void ClearDirtyFlag (void) noexcept;
|
||||
void Unbind (void) noexcept;
|
||||
void SetBound (uint32_t inIndexInBuffer) noexcept;
|
||||
void SetActive (bool flag) noexcept;
|
||||
void SetStrength (float value) noexcept; // serialized
|
||||
|
||||
|
||||
SHLightData const& GetLightData (void) const noexcept;
|
||||
SHVec3 const& GetPosition (void) const noexcept; // serialized
|
||||
SH_LIGHT_TYPE GetType (void) const noexcept; // serialized
|
||||
SHVec3 const& GetDirection (void) const noexcept; // serialized
|
||||
SHVec4 const& GetColor (void) const noexcept; // serialized
|
||||
uint32_t const& GetCullingMask (void) const noexcept; // serialized
|
||||
bool IsDirty (void) const noexcept;
|
||||
bool GetBound (void) const noexcept;
|
||||
uint32_t GetIndexInBuffer (void) const noexcept;
|
||||
|
||||
float GetStrength (void) const noexcept;
|
||||
RTTR_ENABLE()
|
||||
};
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace SHADE
|
|||
direction = SHVec3::Forward;
|
||||
|
||||
// Diffuse color set to 1
|
||||
diffuseColor = SHVec4::One;
|
||||
color = SHVec4::One;
|
||||
}
|
||||
|
||||
}
|
|
@ -10,6 +10,7 @@ namespace SHADE
|
|||
DIRECTIONAL = 0,
|
||||
POINT,
|
||||
SPOT,
|
||||
AMBIENT,
|
||||
NUM_TYPES
|
||||
};
|
||||
|
||||
|
@ -40,7 +41,11 @@ namespace SHADE
|
|||
uint32_t cullingMask;
|
||||
|
||||
//! Diffuse color emitted by the light
|
||||
SHVec4 diffuseColor;
|
||||
SHVec4 color;
|
||||
|
||||
//! Strength of the light
|
||||
float strength;
|
||||
|
||||
|
||||
void Reset (void) noexcept;
|
||||
//! TODO:
|
||||
|
|
|
@ -42,13 +42,23 @@ namespace SHADE
|
|||
|
||||
lightPtr->cullingMask = lightData.cullingMask;
|
||||
lightPtr->direction = lightData.direction;
|
||||
lightPtr->diffuseColor = lightData.diffuseColor;
|
||||
lightPtr->diffuseColor = lightData.color;
|
||||
lightPtr->active = lightComp->isActive;
|
||||
break;
|
||||
}
|
||||
case SH_LIGHT_TYPE::POINT:
|
||||
break;
|
||||
case SH_LIGHT_TYPE::SPOT:
|
||||
break;
|
||||
case SH_LIGHT_TYPE::AMBIENT:
|
||||
{
|
||||
SHAmbientLightData* lightPtr = reinterpret_cast<SHAmbientLightData*>(address);
|
||||
lightPtr->ambientColor = lightData.color;
|
||||
lightPtr->strength = lightData.strength;
|
||||
lightPtr->cullingMask = lightData.cullingMask;
|
||||
lightPtr->active = lightComp->isActive;
|
||||
break;
|
||||
}
|
||||
case SH_LIGHT_TYPE::NUM_TYPES:
|
||||
break;
|
||||
default:
|
||||
|
@ -57,6 +67,7 @@ namespace SHADE
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************/
|
||||
/*!
|
||||
|
||||
|
@ -76,8 +87,9 @@ namespace SHADE
|
|||
// boilerplate
|
||||
intermediateData = nullptr;
|
||||
|
||||
// initialize alignment
|
||||
lightDataAlignmentSize = logicalDevice->PadSSBOSize(GetLightTypeSize(type));
|
||||
// Get data required for struct
|
||||
lightDataSize = GetLightTypeSize(type);
|
||||
lightDataAlignedSize = logicalDevice->PadSSBOSize(lightDataSize);
|
||||
|
||||
// So create some data!
|
||||
Expand(logicalDevice);
|
||||
|
@ -94,7 +106,7 @@ namespace SHADE
|
|||
/***************************************************************************/
|
||||
void SHLightingSubSystem::PerTypeData::Expand(Handle<SHVkLogicalDevice> logicalDevice) noexcept
|
||||
{
|
||||
if (lightDataAlignmentSize == 0)
|
||||
if (lightDataSize == 0)
|
||||
{
|
||||
SHLOG_ERROR ("One of the types of lights have not been accounted for. Make sure lightDataAlignmentSize is not nullptr.");
|
||||
return;
|
||||
|
@ -111,10 +123,12 @@ namespace SHADE
|
|||
numLights = 0;
|
||||
|
||||
// Initialize the data for lights
|
||||
intermediateData = std::make_unique<uint8_t[]>(lightDataAlignmentSize * maxLights);
|
||||
intermediateData = std::make_unique<uint8_t[]>(lightDataSize * maxLights);
|
||||
|
||||
lightDataTotalAlignedSize = logicalDevice->PadSSBOSize(lightDataAlignedSize * maxLights);
|
||||
|
||||
// We want to initialize 3 times the amount of data required.
|
||||
dataBuffer = logicalDevice->CreateBuffer(maxLights * lightDataAlignmentSize * SHGraphicsConstants::NUM_FRAME_BUFFERS, nullptr, maxLights * lightDataAlignmentSize * SHGraphicsConstants::NUM_FRAME_BUFFERS, vk::BufferUsageFlagBits::eStorageBuffer, VMA_MEMORY_USAGE_AUTO, VMA_ALLOCATION_CREATE_MAPPED_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT);
|
||||
dataBuffer = logicalDevice->CreateBuffer(lightDataTotalAlignedSize * SHGraphicsConstants::NUM_FRAME_BUFFERS, nullptr, lightDataTotalAlignedSize * SHGraphicsConstants::NUM_FRAME_BUFFERS, vk::BufferUsageFlagBits::eStorageBuffer, VMA_MEMORY_USAGE_AUTO, VMA_ALLOCATION_CREATE_MAPPED_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -122,24 +136,27 @@ namespace SHADE
|
|||
uint32_t const OLD_MAX_LIGHTS = maxLights;
|
||||
|
||||
// before we increase the number of lights, create space to store old data.
|
||||
std::unique_ptr<uint8_t[]> oldData = std::make_unique<uint8_t[]>(lightDataAlignmentSize * OLD_MAX_LIGHTS);
|
||||
std::unique_ptr<uint8_t[]> oldData = std::make_unique<uint8_t[]>(lightDataSize * OLD_MAX_LIGHTS);
|
||||
|
||||
// copy data over.
|
||||
std::memcpy (oldData.get(), intermediateData.get(), lightDataAlignmentSize * OLD_MAX_LIGHTS);
|
||||
std::memcpy (oldData.get(), intermediateData.get(), lightDataSize * OLD_MAX_LIGHTS);
|
||||
|
||||
// now we start to expand....
|
||||
|
||||
// double space for lights
|
||||
maxLights *= 2;
|
||||
|
||||
// calculate total + padding
|
||||
lightDataTotalAlignedSize = logicalDevice->PadSSBOSize(lightDataAlignedSize * maxLights);
|
||||
|
||||
// destroy old data and initialize container for double the amount of data.
|
||||
intermediateData = std::make_unique<uint8_t[]>(lightDataAlignmentSize * maxLights);
|
||||
intermediateData = std::make_unique<uint8_t[]>(lightDataSize * maxLights);
|
||||
|
||||
// copy old data to new container
|
||||
std::memcpy(intermediateData.get(), oldData.get(), lightDataAlignmentSize * OLD_MAX_LIGHTS);
|
||||
std::memcpy(intermediateData.get(), oldData.get(), lightDataSize * OLD_MAX_LIGHTS);
|
||||
|
||||
// Resize the GPU buffer. TODO: Replace with Resize no copy here
|
||||
dataBuffer->ResizeReplace(maxLights * lightDataAlignmentSize * SHGraphicsConstants::NUM_FRAME_BUFFERS, oldData.get(), lightDataAlignmentSize * OLD_MAX_LIGHTS);
|
||||
dataBuffer->ResizeReplace(maxLights * lightDataTotalAlignedSize * SHGraphicsConstants::NUM_FRAME_BUFFERS, oldData.get(), lightDataTotalAlignedSize * OLD_MAX_LIGHTS);
|
||||
}
|
||||
|
||||
|
||||
|
@ -171,6 +188,9 @@ namespace SHADE
|
|||
case SH_LIGHT_TYPE::SPOT:
|
||||
// TOOD: Change after creating spot light struct
|
||||
return 4;
|
||||
case SH_LIGHT_TYPE::AMBIENT:
|
||||
return sizeof(SHAmbientLightData);
|
||||
return 4;
|
||||
case SH_LIGHT_TYPE::NUM_TYPES:
|
||||
default:
|
||||
return 4;
|
||||
|
@ -187,7 +207,12 @@ namespace SHADE
|
|||
|
||||
uint32_t SHLightingSubSystem::PerTypeData::GetAlignmentSize(void) const noexcept
|
||||
{
|
||||
return lightDataAlignmentSize;
|
||||
return lightDataTotalAlignedSize;
|
||||
}
|
||||
|
||||
uint32_t SHLightingSubSystem::PerTypeData::GetDataSize(void) const noexcept
|
||||
{
|
||||
return lightDataSize;
|
||||
}
|
||||
|
||||
uint32_t SHLightingSubSystem::PerTypeData::GetNumLights(void) const noexcept
|
||||
|
@ -231,7 +256,7 @@ namespace SHADE
|
|||
// Now that the container is big enough, bind the new light
|
||||
|
||||
// Get address of write location
|
||||
void* writeLocation = reinterpret_cast<uint8_t*>(intermediateData.get()) + (lightDataAlignmentSize * numLights);
|
||||
void* writeLocation = reinterpret_cast<uint8_t*>(intermediateData.get()) + (lightDataAlignedSize * numLights);
|
||||
|
||||
// Write the light data to address
|
||||
WriteLightToAddress(writeLocation, unboundLight);
|
||||
|
@ -257,7 +282,7 @@ namespace SHADE
|
|||
/***************************************************************************/
|
||||
void SHLightingSubSystem::PerTypeData::ModifyLight(SHLightComponent* lightComp) noexcept
|
||||
{
|
||||
void* writeLocation = reinterpret_cast<uint8_t*>(intermediateData.get()) + (lightDataAlignmentSize * lightComp->GetIndexInBuffer());
|
||||
void* writeLocation = reinterpret_cast<uint8_t*>(intermediateData.get()) + (lightDataAlignedSize * lightComp->GetIndexInBuffer());
|
||||
WriteLightToAddress(writeLocation, lightComp);
|
||||
}
|
||||
|
||||
|
@ -266,10 +291,15 @@ namespace SHADE
|
|||
if (intermediateData)
|
||||
{
|
||||
// we want to write to the offset of the current frame
|
||||
dataBuffer->WriteToMemory(intermediateData.get(), lightDataAlignmentSize * numLights, 0, lightDataAlignmentSize * maxLights * frameIndex);
|
||||
dataBuffer->WriteToMemory(intermediateData.get(), lightDataAlignedSize * numLights, 0, lightDataAlignedSize * maxLights * frameIndex);
|
||||
}
|
||||
}
|
||||
|
||||
void SHLightingSubSystem::PerTypeData::ResetNumLights(void) noexcept
|
||||
{
|
||||
numLights = 0;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
/*!
|
||||
|
||||
|
@ -287,12 +317,12 @@ namespace SHADE
|
|||
|
||||
// We bind the buffer with the correct desc set binding
|
||||
lightingDataDescSet->ModifyWriteDescBuffer(SHGraphicsConstants::DescriptorSetIndex::DYNAMIC_GLOBALS,
|
||||
binding,
|
||||
binding + 1, // we want to +1 here because the first binding is reserved for count
|
||||
{ &buffer, 1 },
|
||||
0,
|
||||
perTypeData[binding].GetAlignmentSize() * perTypeData[binding].GetMaxLights());
|
||||
perTypeData[binding].GetDataSize() * perTypeData[binding].GetMaxLights());
|
||||
|
||||
lightingDataDescSet->UpdateDescriptorSetBuffer(SHGraphicsConstants::DescriptorSetIndex::DYNAMIC_GLOBALS, binding);
|
||||
lightingDataDescSet->UpdateDescriptorSetBuffer(SHGraphicsConstants::DescriptorSetIndex::DYNAMIC_GLOBALS, binding + 1); // +1 here, same reason. see above
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
@ -307,16 +337,27 @@ namespace SHADE
|
|||
{
|
||||
for (uint32_t i = 0; i < SHGraphicsConstants::NUM_FRAME_BUFFERS; ++i)
|
||||
{
|
||||
for (uint32_t j = 0; j < dynamicOffsets.size(); ++j)
|
||||
dynamicOffsets[i][0] = i * lightCountsAlignedSize;
|
||||
// Even if the first binding is a count, we want to account for that too
|
||||
for (uint32_t j = 0; j < static_cast<uint32_t>(SH_LIGHT_TYPE::NUM_TYPES); ++j)
|
||||
{
|
||||
auto const& typeData = perTypeData[j];
|
||||
{
|
||||
dynamicOffsets[i][j] = j * typeData.GetAlignmentSize() * typeData.GetMaxLights();
|
||||
// +1 because 1st reserved for count
|
||||
dynamicOffsets[i][j + 1] = i * typeData.GetAlignmentSize();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SHLightingSubSystem::ResetNumLights(void) noexcept
|
||||
{
|
||||
for (auto& data : perTypeData)
|
||||
{
|
||||
data.ResetNumLights();
|
||||
}
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
/*!
|
||||
|
||||
|
@ -346,12 +387,26 @@ namespace SHADE
|
|||
// initialize all the data first. We add more lights here as we add more types.
|
||||
perTypeData[i].InitializeData(logicalDevice, static_cast<SH_LIGHT_TYPE>(i));
|
||||
UpdateDescSet(i);
|
||||
|
||||
// no lights at first
|
||||
lightCountsData[i] = 0;
|
||||
}
|
||||
|
||||
lightCountsAlignedSize = sizeof (uint32_t) * NUM_LIGHT_TYPES;
|
||||
lightCountsAlignedSize = logicalDevice->PadUBOSize(lightCountsAlignedSize);
|
||||
|
||||
// Create the GPU buffer to hold light count
|
||||
lightCountsBuffer = logicalDevice->CreateBuffer(lightCountsAlignedSize * SHGraphicsConstants::NUM_FRAME_BUFFERS, nullptr, lightCountsAlignedSize * SHGraphicsConstants::NUM_FRAME_BUFFERS, vk::BufferUsageFlagBits::eUniformBuffer, VMA_MEMORY_USAGE_AUTO, VMA_ALLOCATION_CREATE_MAPPED_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT);
|
||||
|
||||
lightingDataDescSet->ModifyWriteDescBuffer(SHGraphicsConstants::DescriptorSetIndex::DYNAMIC_GLOBALS, SHGraphicsConstants::DescriptorSetBindings::LIGHTING_COUNT, {&lightCountsBuffer, 1}, 0, sizeof (uint32_t) * NUM_LIGHT_TYPES);
|
||||
lightingDataDescSet->UpdateDescriptorSetBuffer(SHGraphicsConstants::DescriptorSetIndex::DYNAMIC_GLOBALS, SHGraphicsConstants::DescriptorSetBindings::LIGHTING_COUNT);
|
||||
|
||||
for (uint32_t i = 0; i < SHGraphicsConstants::NUM_FRAME_BUFFERS; ++i)
|
||||
{
|
||||
dynamicOffsets[i].resize(NUM_LIGHT_TYPES);
|
||||
dynamicOffsets[i].resize(NUM_LIGHT_TYPES + 1); // +1 for the count
|
||||
}
|
||||
|
||||
numLightComponents = 0;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
@ -366,17 +421,32 @@ namespace SHADE
|
|||
/***************************************************************************/
|
||||
void SHLightingSubSystem::Run(Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex) noexcept
|
||||
{
|
||||
static uint32_t constexpr NUM_LIGHT_TYPES = SHUtilities::ToUnderlying(SH_LIGHT_TYPE::NUM_TYPES);
|
||||
|
||||
auto& lightComps = SHComponentManager::GetDense<SHLightComponent>();
|
||||
bool expanded = false;
|
||||
bool rewrite = false;
|
||||
|
||||
if (numLightComponents > lightComps.size())
|
||||
{
|
||||
rewrite = true;
|
||||
ResetNumLights();
|
||||
}
|
||||
|
||||
numLightComponents = lightComps.size();
|
||||
|
||||
for (auto& light : lightComps)
|
||||
{
|
||||
auto enumValue = SHUtilities::ToUnderlying(light.GetLightData().type);
|
||||
|
||||
// First we want to make sure the light is already bound to the system. if it
|
||||
// isn't, we write it to the correct buffer.
|
||||
if (!light.GetBound())
|
||||
if (!light.GetBound() || rewrite)
|
||||
{
|
||||
perTypeData[enumValue].AddLight(logicalDevice, &light, expanded);
|
||||
|
||||
//// add to light count
|
||||
//++lightCountsData[enumValue];
|
||||
}
|
||||
|
||||
// if there was modification to the light data
|
||||
|
@ -396,6 +466,13 @@ namespace SHADE
|
|||
data.WriteToGPU(frameIndex);
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < NUM_LIGHT_TYPES; ++i)
|
||||
{
|
||||
lightCountsData[i] = perTypeData[i].GetNumLights();
|
||||
}
|
||||
|
||||
lightCountsBuffer->WriteToMemory(lightCountsData.data(), static_cast<uint32_t>(lightCountsData.size()) * sizeof (uint32_t), 0, lightCountsAlignedSize * frameIndex);
|
||||
|
||||
// If any of the buffers got expanded, the descriptor set is invalid because the expanded buffer
|
||||
// is a new buffer. If some expansion was detected, update descriptor sets.
|
||||
if (expanded)
|
||||
|
@ -412,7 +489,7 @@ namespace SHADE
|
|||
ComputeDynamicOffsets();
|
||||
|
||||
// Bind descriptor set (We bind at an offset because the buffer holds NUM_FRAME_BUFFERS sets of data).
|
||||
cmdBuffer->BindDescriptorSet(lightingDataDescSet, SH_PIPELINE_TYPE::GRAPHICS, SHGraphicsConstants::DescriptorSetIndex::DYNAMIC_GLOBALS, {dynamicOffsets[frameIndex]});
|
||||
cmdBuffer->BindDescriptorSet(lightingDataDescSet, SH_PIPELINE_TYPE::COMPUTE, SHGraphicsConstants::DescriptorSetIndex::DYNAMIC_GLOBALS, {dynamicOffsets[frameIndex]});
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,27 @@ namespace SHADE
|
|||
uint32_t cullingMask;
|
||||
|
||||
//! Diffuse color emitted by the light
|
||||
SHVec4 diffuseColor;
|
||||
alignas (16) SHVec4 diffuseColor;
|
||||
|
||||
};
|
||||
|
||||
// Represents how the data will be interpreted in GPU. we want to copy to a container of these before passing to GPU.
|
||||
struct SHAmbientLightData
|
||||
{
|
||||
//! Diffuse color emitted by the light
|
||||
SHVec4 ambientColor;
|
||||
|
||||
//! Strength of the ambient light
|
||||
float strength;
|
||||
|
||||
//! Represents if the light is active or not
|
||||
uint32_t active;
|
||||
|
||||
//! Each bit in this 32 bit field will represent a layer. If the bit is set,
|
||||
//! when a fragment is being evaluated, the shader will use the fragment's
|
||||
//! layer value to AND with the light's. If result is 1, do lighting calculations.
|
||||
uint32_t cullingMask;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
@ -45,7 +65,7 @@ namespace SHADE
|
|||
/*-----------------------------------------------------------------------*/
|
||||
/* STATIC MEMBER VARIABLES */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
static constexpr uint32_t STARTING_NUM_LIGHTS = 20;
|
||||
static constexpr uint32_t STARTING_NUM_LIGHTS = 50;
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* PRIVATE MEMBER VARIABLES */
|
||||
|
@ -53,8 +73,13 @@ namespace SHADE
|
|||
//! Capacity of the container.
|
||||
uint32_t maxLights;
|
||||
|
||||
//! SSBOs need to be aligned. This is to pad lighting structs
|
||||
uint32_t lightDataAlignmentSize;
|
||||
//! SSBOs need to be aligned. This is to pad descriptor offset
|
||||
uint32_t lightDataTotalAlignedSize;
|
||||
|
||||
//! size needed to store 1 struct object
|
||||
uint32_t lightDataSize;
|
||||
|
||||
uint32_t lightDataAlignedSize;
|
||||
|
||||
//! type of the light. Will be used later when we want to expand
|
||||
SH_LIGHT_TYPE lightType;
|
||||
|
@ -80,6 +105,7 @@ namespace SHADE
|
|||
void AddLight (Handle<SHVkLogicalDevice> logicalDevice, SHLightComponent* unboundLight, bool expanded) noexcept;
|
||||
void ModifyLight (SHLightComponent* lightComp) noexcept;
|
||||
void WriteToGPU (uint32_t frameIndex) noexcept;
|
||||
void ResetNumLights (void) noexcept;
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* GETTERS */
|
||||
|
@ -87,6 +113,7 @@ namespace SHADE
|
|||
static uint32_t GetLightTypeSize (SH_LIGHT_TYPE type) noexcept;
|
||||
Handle<SHVkBuffer> GetDataBuffer (void) const noexcept;
|
||||
uint32_t GetAlignmentSize (void) const noexcept;
|
||||
uint32_t GetDataSize (void) const noexcept;
|
||||
uint32_t GetNumLights (void) const noexcept;
|
||||
uint32_t GetMaxLights (void) const noexcept;
|
||||
};
|
||||
|
@ -105,11 +132,26 @@ namespace SHADE
|
|||
//! Container to store dynamic offsets for binding descriptor sets
|
||||
std::array<std::vector<uint32_t>, static_cast<uint32_t>(SHGraphicsConstants::NUM_FRAME_BUFFERS)> dynamicOffsets;
|
||||
|
||||
//! holds the data that represents how many lights are in the scene
|
||||
std::array<uint32_t, static_cast<uint32_t>(SH_LIGHT_TYPE::NUM_TYPES)> lightCountsData;
|
||||
|
||||
//! GPU buffer to hold lightCountData
|
||||
Handle<SHVkBuffer> lightCountsBuffer;
|
||||
|
||||
//! For padding in the buffer
|
||||
uint32_t lightCountsAlignedSize;
|
||||
|
||||
//! Number of SHLightComponents recorded. If at the beginning of the run function the size returned by the dense
|
||||
//! set is less than the size recorded, rewrite all light components into the its respective buffers. If its more,
|
||||
//! don't do anything.
|
||||
uint32_t numLightComponents;
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* PRIVATE MEMBER FUNCTIONS */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
void UpdateDescSet (uint32_t binding) noexcept;
|
||||
void ComputeDynamicOffsets (void) noexcept;
|
||||
void ResetNumLights (void) noexcept;
|
||||
|
||||
public:
|
||||
|
||||
|
|
|
@ -133,6 +133,7 @@ namespace SHADE
|
|||
{
|
||||
SHLOG_ERROR("Frame index retrieved from vkAcquireNextImageKHR is not the same as currentFrame.");
|
||||
}
|
||||
|
||||
currentFrame = frameIndex;
|
||||
}
|
||||
|
||||
|
|
|
@ -214,66 +214,4 @@ namespace SHADE
|
|||
SHLOG_ERROR("Image layouts are invalid. ");
|
||||
}
|
||||
}
|
||||
|
||||
vk::Format SHTextureLibrary::ddsLoaderToVkFormat(tinyddsloader::DDSFile::DXGIFormat format, bool isLinear)
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
case tinyddsloader::DDSFile::DXGIFormat::BC1_UNorm:
|
||||
return vk::Format::eBc1RgbaUnormBlock;
|
||||
case tinyddsloader::DDSFile::DXGIFormat::BC1_UNorm_SRGB:
|
||||
return vk::Format::eBc1RgbaSrgbBlock;
|
||||
case tinyddsloader::DDSFile::DXGIFormat::BC2_UNorm:
|
||||
case tinyddsloader::DDSFile::DXGIFormat::BC2_UNorm_SRGB:
|
||||
return isLinear ? vk::Format::eBc2UnormBlock : vk::Format::eBc2SrgbBlock;
|
||||
case tinyddsloader::DDSFile::DXGIFormat::BC3_UNorm:
|
||||
case tinyddsloader::DDSFile::DXGIFormat::BC3_UNorm_SRGB:
|
||||
return isLinear ? vk::Format::eBc3UnormBlock : vk::Format::eBc3SrgbBlock;
|
||||
case tinyddsloader::DDSFile::DXGIFormat::BC5_UNorm:
|
||||
case tinyddsloader::DDSFile::DXGIFormat::BC5_SNorm:
|
||||
return isLinear ? vk::Format::eBc5UnormBlock : vk::Format::eBc5SnormBlock;
|
||||
case tinyddsloader::DDSFile::DXGIFormat::R8G8B8A8_UNorm:
|
||||
case tinyddsloader::DDSFile::DXGIFormat::R8G8B8A8_UNorm_SRGB:
|
||||
return isLinear ? vk::Format::eR8G8B8A8Unorm : vk::Format::eR8G8B8A8Srgb;
|
||||
case tinyddsloader::DDSFile::DXGIFormat::R8G8B8A8_SNorm:
|
||||
return vk::Format::eR8G8B8A8Snorm;
|
||||
case tinyddsloader::DDSFile::DXGIFormat::B8G8R8A8_UNorm:
|
||||
case tinyddsloader::DDSFile::DXGIFormat::B8G8R8A8_UNorm_SRGB:
|
||||
return isLinear ? vk::Format::eB8G8R8A8Unorm : vk::Format::eB8G8R8A8Srgb;
|
||||
case tinyddsloader::DDSFile::DXGIFormat::B8G8R8X8_UNorm:
|
||||
case tinyddsloader::DDSFile::DXGIFormat::B8G8R8X8_UNorm_SRGB:
|
||||
return isLinear ? vk::Format::eB8G8R8A8Unorm : vk::Format::eB8G8R8Srgb;
|
||||
default:
|
||||
throw std::runtime_error("Unsupported DDS format.");
|
||||
}
|
||||
|
||||
//switch (format)
|
||||
//{
|
||||
//case tinyddsloader::DDSFile::DXGIFormat::R8G8B8A8_UNorm:
|
||||
//case tinyddsloader::DDSFile::DXGIFormat::R8G8B8A8_UNorm_SRGB:
|
||||
// return (isLinear) ? vk::Format::eR8G8B8A8Unorm : vk::Format::eR8G8B8A8Srgb;
|
||||
//
|
||||
|
||||
//case tinyddsloader::DDSFile::DXGIFormat::B8G8R8A8_UNorm:
|
||||
//case tinyddsloader::DDSFile::DXGIFormat::B8G8R8A8_UNorm_SRGB:
|
||||
// return (isLinear) ? vk::Format::eB8G8R8A8Unorm : vk::Format::eB8G8R8A8Srgb;
|
||||
//
|
||||
|
||||
//case tinyddsloader::DDSFile::DXGIFormat::BC1_UNorm:
|
||||
//case tinyddsloader::DDSFile::DXGIFormat::BC1_UNorm_SRGB:
|
||||
// return (isLinear) ? vk::Format::eBc1RgbaUnormBlock : vk::Format::eBc1RgbaSrgbBlock;
|
||||
|
||||
//case tinyddsloader::DDSFile::DXGIFormat::BC2_UNorm:
|
||||
//case tinyddsloader::DDSFile::DXGIFormat::BC2_UNorm_SRGB:
|
||||
// return (isLinear) ? vk::Format::eBc2UnormBlock : vk::Format::eBc2SrgbBlock;
|
||||
|
||||
//case tinyddsloader::DDSFile::DXGIFormat::BC3_UNorm:
|
||||
//case tinyddsloader::DDSFile::DXGIFormat::BC3_UNorm_SRGB:
|
||||
// return (isLinear) ? vk::Format::eBc3UnormBlock : vk::Format::eBc3SrgbBlock;
|
||||
|
||||
//case tinyddsloader::DDSFile::DXGIFormat::BC5_UNorm:
|
||||
// return (isLinear) ? vk::Format::eBc5UnormBlock : vk::Format::eBc5SnormBlock;
|
||||
//
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,8 +14,6 @@ of DigiPen Institute of Technology is prohibited.
|
|||
|
||||
// STL Includes
|
||||
#include <vector>
|
||||
// External Dependencies
|
||||
#include "tinyddsloader.h"
|
||||
// Project Includes
|
||||
#include "Resource/SHHandle.h"
|
||||
#include "Resource/SHResourceLibrary.h"
|
||||
|
@ -169,6 +167,5 @@ namespace SHADE
|
|||
/* Helper Functions */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
void preparePipelineBarriers(vk::ImageLayout oldLayout, vk::ImageLayout newLayout, vk::PipelineStageFlagBits& srcStage, vk::PipelineStageFlagBits& dstStage, std::vector<vk::ImageMemoryBarrier>& barriers);
|
||||
vk::Format ddsLoaderToVkFormat(tinyddsloader::DDSFile::DXGIFormat format, bool isLinear);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -276,7 +276,7 @@ namespace SHADE
|
|||
}
|
||||
|
||||
// Create the subpass compute with the resources
|
||||
auto nodeCompute = graphStorage->resourceManager->Create<SHRenderGraphNodeCompute>(graphStorage, computeShaderModule, std::move(nodeComputeResources));
|
||||
auto nodeCompute = graphStorage->resourceManager->Create<SHRenderGraphNodeCompute>(graphStorage, computeShaderModule, std::move(nodeComputeResources), nodeComputes.empty());
|
||||
nodeComputes.push_back(nodeCompute);
|
||||
|
||||
return nodeCompute;
|
||||
|
|
|
@ -13,12 +13,13 @@
|
|||
|
||||
namespace SHADE
|
||||
{
|
||||
SHRenderGraphNodeCompute::SHRenderGraphNodeCompute(Handle<SHRenderGraphStorage> graphStorage, Handle<SHVkShaderModule> computeShaderModule, std::vector<Handle<SHRenderGraphResource>>&& subpassComputeResources, float inNumWorkGroupScale/* = 1.0f*/) noexcept
|
||||
SHRenderGraphNodeCompute::SHRenderGraphNodeCompute(Handle<SHRenderGraphStorage> graphStorage, Handle<SHVkShaderModule> computeShaderModule, std::vector<Handle<SHRenderGraphResource>>&& subpassComputeResources, bool followingEndRP, float inNumWorkGroupScale/* = 1.0f*/) noexcept
|
||||
: computePipeline{}
|
||||
, pipelineLayout{}
|
||||
, resources{}
|
||||
, groupSizeX{0}
|
||||
, groupSizeY{0}
|
||||
, followingEndRenderpass {followingEndRP}
|
||||
, numWorkGroupScale {std::clamp(inNumWorkGroupScale, 0.0f, 1.0f)}
|
||||
{
|
||||
SHPipelineLayoutParams pipelineLayoutParams
|
||||
|
@ -53,7 +54,6 @@ namespace SHADE
|
|||
descSetGroups[i] = graphStorage->descriptorPool->Allocate(layouts, variableCounts);
|
||||
}
|
||||
|
||||
|
||||
HandleResize();
|
||||
}
|
||||
|
||||
|
@ -68,8 +68,9 @@ namespace SHADE
|
|||
// dispatch compute
|
||||
cmdBuffer->ComputeDispatch(groupSizeX, groupSizeY, 1);
|
||||
|
||||
// TODO: barrier
|
||||
|
||||
cmdBuffer->PipelineBarrier((followingEndRenderpass) ? vk::PipelineStageFlagBits::eFragmentShader : vk::PipelineStageFlagBits::eComputeShader,
|
||||
vk::PipelineStageFlagBits::eFragmentShader,
|
||||
{}, {}, {}, memoryBarriers[frameIndex]);
|
||||
}
|
||||
|
||||
void SHRenderGraphNodeCompute::HandleResize(void) noexcept
|
||||
|
@ -104,6 +105,36 @@ namespace SHADE
|
|||
|
||||
groupSizeX = maxWidth / workGroupSizeX;
|
||||
groupSizeY = maxHeight / workGroupSizeY;
|
||||
|
||||
for (uint32_t i = 0; auto& barriers : memoryBarriers)
|
||||
{
|
||||
barriers.clear();
|
||||
|
||||
for (auto& resource : resources)
|
||||
{
|
||||
vk::AccessFlags srcAccessMask = (followingEndRenderpass) ? vk::AccessFlagBits::eInputAttachmentRead : (vk::AccessFlagBits::eShaderRead | vk::AccessFlagBits::eShaderWrite);
|
||||
barriers.push_back(vk::ImageMemoryBarrier
|
||||
{
|
||||
.srcAccessMask = srcAccessMask,
|
||||
.dstAccessMask = vk::AccessFlagBits::eShaderRead | vk::AccessFlagBits::eShaderWrite,
|
||||
.oldLayout = vk::ImageLayout::eGeneral,
|
||||
.newLayout = vk::ImageLayout::eGeneral,
|
||||
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||
.image = resource->GetImage((resource->resourceTypeFlags & static_cast<uint32_t>(SH_ATT_DESC_TYPE_FLAGS::COLOR_PRESENT)) ? i : 0)->GetVkImage(),
|
||||
.subresourceRange = vk::ImageSubresourceRange
|
||||
{
|
||||
.aspectMask = resource->imageAspectFlags,
|
||||
.baseMipLevel = 0,
|
||||
.levelCount = resource->mipLevels,
|
||||
.baseArrayLayer = 0,
|
||||
.layerCount = 1,
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "Resource/SHHandle.h"
|
||||
#include "Graphics/MiddleEnd/Interface/SHGraphicsConstants.h"
|
||||
#include "Graphics/SHVulkanIncludes.h"
|
||||
#include <initializer_list>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
|
@ -44,8 +45,12 @@ namespace SHADE
|
|||
|
||||
float numWorkGroupScale;
|
||||
|
||||
bool followingEndRenderpass;
|
||||
|
||||
std::array<std::vector<vk::ImageMemoryBarrier>, SHGraphicsConstants::NUM_FRAME_BUFFERS> memoryBarriers;
|
||||
|
||||
public:
|
||||
SHRenderGraphNodeCompute(Handle<SHRenderGraphStorage> graphStorage, Handle<SHVkShaderModule> computeShaderModule, std::vector<Handle<SHRenderGraphResource>>&& subpassComputeResources, float inNumWorkGroupScale = 1.0f) noexcept;
|
||||
SHRenderGraphNodeCompute(Handle<SHRenderGraphStorage> graphStorage, Handle<SHVkShaderModule> computeShaderModule, std::vector<Handle<SHRenderGraphResource>>&& subpassComputeResources, bool followingEndRP, float inNumWorkGroupScale = 1.0f) noexcept;
|
||||
|
||||
void Execute (Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex) noexcept;
|
||||
void HandleResize (void) noexcept;
|
||||
|
|
|
@ -195,6 +195,11 @@ namespace SHADE
|
|||
template<typename T>
|
||||
inline bool operator==(const Handle<T>& rhs) const noexcept;
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Query Functions */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
inline SHResourceLibraryBase* GetLibrary() const;
|
||||
|
||||
protected:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Data Members */
|
||||
|
@ -206,6 +211,7 @@ namespace SHADE
|
|||
/*-----------------------------------------------------------------------------*/
|
||||
template<typename T>
|
||||
friend class Handle;
|
||||
friend class Convert;
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -96,6 +96,11 @@ namespace SHADE
|
|||
return id.Raw == rhs.id.Raw && library == static_cast<void*>(rhs.library);
|
||||
}
|
||||
|
||||
SHResourceLibraryBase* SHADE::Handle<void>::GetLibrary() const
|
||||
{
|
||||
return library;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* ISelfHandle<T> - Constructors */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
|
|
@ -70,13 +70,13 @@ namespace SHADE
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
SparseSet<T>::reference SparseSet<T>::at(index_type idx)
|
||||
typename SparseSet<T>::reference SparseSet<T>::at(index_type idx)
|
||||
{
|
||||
return const_cast<reference>(static_cast<const SparseSet<T>&>(*this).at(idx));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
SparseSet<T>::const_reference SparseSet<T>::at(index_type idx) const
|
||||
typename SparseSet<T>::const_reference SparseSet<T>::at(index_type idx) const
|
||||
{
|
||||
// Range Check
|
||||
if (idx >= sparseArray.size() || !contains(idx))
|
||||
|
@ -84,7 +84,7 @@ namespace SHADE
|
|||
return denseArray[sparseArray[idx]];
|
||||
}
|
||||
template<typename T>
|
||||
SparseSet<T>::size_type SparseSet<T>::size() const
|
||||
typename SparseSet<T>::size_type SparseSet<T>::size() const
|
||||
{
|
||||
return denseArray.size();
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ namespace SHADE
|
|||
}
|
||||
template<typename T>
|
||||
template<typename ...Args>
|
||||
SparseSet<T>::reference SparseSet<T>::insert(index_type idx, Args && ...args)
|
||||
typename SparseSet<T>::reference SparseSet<T>::insert(index_type idx, Args && ...args)
|
||||
{
|
||||
// We need to resize the array
|
||||
if (idx >= sparseArray.size())
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "Math/Transform/SHTransformComponent.h"
|
||||
#include "Physics/Components/SHRigidBodyComponent.h"
|
||||
#include "ECS_Base/Managers/SHSystemManager.h"
|
||||
#include "Graphics/MiddleEnd/Lights/SHLightComponent.h"
|
||||
#include "Scripting/SHScriptEngine.h"
|
||||
|
||||
namespace SHADE
|
||||
|
@ -192,6 +193,10 @@ namespace SHADE
|
|||
{
|
||||
components[rttr::type::get<SHRigidBodyComponent>().get_name().data()] = SHSerializationHelper::SerializeComponentToNode(rigidbody);
|
||||
}
|
||||
if(const auto light = SHComponentManager::GetComponent_s<SHLightComponent>(eid))
|
||||
{
|
||||
components[rttr::type::get<SHLightComponent>().get_name().data()] = SHSerializationHelper::SerializeComponentToNode(light);
|
||||
}
|
||||
node[ComponentsNode] = components;
|
||||
|
||||
YAML::Node scripts;
|
||||
|
@ -250,6 +255,10 @@ namespace SHADE
|
|||
if (id.has_value())
|
||||
componentIDList.push_back(id.value());
|
||||
|
||||
id = GetComponentID<SHLightComponent>(componentsNode);
|
||||
if(id.has_value())
|
||||
componentIDList.push_back(id.value());
|
||||
|
||||
return componentIDList;
|
||||
}
|
||||
|
||||
|
@ -260,5 +269,6 @@ namespace SHADE
|
|||
return;
|
||||
SHSerializationHelper::InitializeComponentFromNode<SHTransformComponent>(componentsNode, eid);
|
||||
SHSerializationHelper::ConvertNodeToComponent<SHRenderable>(componentsNode, eid);
|
||||
SHSerializationHelper::InitializeComponentFromNode<SHLightComponent>(componentsNode, eid);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -386,12 +386,12 @@ namespace SHADE
|
|||
return;
|
||||
auto rttrType = rttr::type::get<ComponentType>();
|
||||
auto componentNode = componentsNode[rttrType.get_name().data()];
|
||||
if (componentsNode.IsNull())
|
||||
if(!componentNode.IsDefined())
|
||||
return;
|
||||
auto properties = rttrType.get_properties();
|
||||
for (auto const& prop : properties)
|
||||
{
|
||||
if (componentNode[prop.get_name().data()])
|
||||
if (componentNode[prop.get_name().data()].IsDefined())
|
||||
{
|
||||
InitializeProperty<ComponentType>(component, prop, componentNode[prop.get_name().data()]);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,119 @@
|
|||
/************************************************************************************//*!
|
||||
\file Material.cxx
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Oct 28, 2022
|
||||
\brief Contains the implementation of the functions of the managed Material
|
||||
class.
|
||||
|
||||
Note: This file is written in C++17/CLI.
|
||||
|
||||
Copyright (C) 2022 DigiPen Institute of Technology.
|
||||
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||
of DigiPen Institute of Technology is prohibited.
|
||||
*//*************************************************************************************/
|
||||
// Precompiled Headers
|
||||
#include "SHpch.h"
|
||||
// Primary Header
|
||||
#include "Material.hxx"
|
||||
// Standard Library
|
||||
#include <stdexcept>
|
||||
// Project Includes
|
||||
#include "Utility/Convert.hxx"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Macro Definitions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
#define SET_PROP(NATIVE_TYPE, MANAGED_TYPE) \
|
||||
(T::typeid == MANAGED_TYPE::typeid) \
|
||||
{ \
|
||||
const NATIVE_TYPE VAL = safe_cast<NATIVE_TYPE>(System::Convert::ChangeType(value, MANAGED_TYPE::typeid)); \
|
||||
NativeObject->SetProperty<NATIVE_TYPE>(PROP_NAME, VAL); \
|
||||
} \
|
||||
|
||||
#define SET_PROP_CONVERT(NATIVE_TYPE, MANAGED_TYPE) \
|
||||
(T::typeid == MANAGED_TYPE::typeid) \
|
||||
{ \
|
||||
const NATIVE_TYPE VAL = Convert::ToNative(safe_cast<MANAGED_TYPE>(System::Convert::ChangeType(value, MANAGED_TYPE::typeid))); \
|
||||
NativeObject->SetProperty<NATIVE_TYPE>(PROP_NAME, VAL); \
|
||||
} \
|
||||
|
||||
#define GET_PROP(NATIVE_TYPE, MANAGED_TYPE) \
|
||||
(T::typeid == MANAGED_TYPE::typeid) \
|
||||
{ \
|
||||
return safe_cast<T>(NativeObject->GetProperty<NATIVE_TYPE>(PROP_NAME)); \
|
||||
} \
|
||||
|
||||
#define GET_PROP_CONVERT(NATIVE_TYPE, MANAGED_TYPE) \
|
||||
(T::typeid == MANAGED_TYPE::typeid) \
|
||||
{ \
|
||||
return safe_cast<T>(Convert::ToCLI(NativeObject->GetProperty<NATIVE_TYPE>(PROP_NAME))); \
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Explicit Template Instantiation */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
template ref class NativeAsset<SHMaterialInstance>;
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Constructors/Destructor */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
Material::Material(Handle<SHMaterialInstance> material)
|
||||
: NativeAsset<SHMaterialInstance>{ material }
|
||||
{}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Material Properties Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
generic<typename T>
|
||||
void Material::SetProperty(System::String^ name, T value)
|
||||
{
|
||||
if (!NativeObject)
|
||||
throw gcnew System::InvalidOperationException("Attempted to set property on an invalid material!");
|
||||
|
||||
// Call the correct one based on type
|
||||
const std::string PROP_NAME = Convert::ToNative(name);
|
||||
try
|
||||
{
|
||||
if SET_PROP (int, System::Int32)
|
||||
else if SET_PROP (int, System::Int64)
|
||||
else if SET_PROP (float, float)
|
||||
else if SET_PROP (double, double)
|
||||
else if SET_PROP_CONVERT(SHVec2, Vector2)
|
||||
else if SET_PROP_CONVERT(SHVec3, Vector3)
|
||||
// TODO: Vector4
|
||||
}
|
||||
catch (const std::invalid_argument&)
|
||||
{
|
||||
throw gcnew System::ArgumentException("Attempted to modify an invalid property on a material.");
|
||||
}
|
||||
}
|
||||
|
||||
generic<typename T>
|
||||
T Material::GetProperty(System::String^ name)
|
||||
{
|
||||
if (!NativeObject)
|
||||
throw gcnew System::InvalidOperationException("[Material] Attempted to get property of an invalid material!");
|
||||
|
||||
// Call the correct one based on type
|
||||
const std::string PROP_NAME = Convert::ToNative(name);
|
||||
try
|
||||
{
|
||||
if GET_PROP (int, System::Int32)
|
||||
else if GET_PROP (int, System::Int64)
|
||||
else if GET_PROP (float, float)
|
||||
else if GET_PROP (double, double)
|
||||
else if GET_PROP_CONVERT(SHVec2, Vector2)
|
||||
else if GET_PROP_CONVERT(SHVec3, Vector3)
|
||||
// TODO: Vector4
|
||||
}
|
||||
catch (const std::invalid_argument&)
|
||||
{
|
||||
throw gcnew System::ArgumentException("Attempted to retrieve a property on a material with an invalid type.");
|
||||
}
|
||||
|
||||
throw gcnew System::ArgumentException("Attempted to retrieve an invalid property on a material.");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
/************************************************************************************//*!
|
||||
\file Material.hxx
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Oct 28, 2022
|
||||
\brief Contains the definition of the managed Mesh class.
|
||||
|
||||
Note: This file is written in C++17/CLI.
|
||||
|
||||
Copyright (C) 2022 DigiPen Institute of Technology.
|
||||
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||
of DigiPen Institute of Technology is prohibited.
|
||||
*//*************************************************************************************/
|
||||
#pragma once
|
||||
|
||||
// External Dependencies
|
||||
#include "Resource/SHHandle.h"
|
||||
#include "Graphics/MiddleEnd/Interface/SHMaterialInstance.h"
|
||||
// Project Includes
|
||||
#include "NativeAsset.hxx"
|
||||
#include "Engine/GenericHandle.hxx"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/// <summary>
|
||||
/// Managed counterpart of the native MaterialInstance object containing material
|
||||
/// data that can be fed to Renderables for rendering.
|
||||
/// </summary>
|
||||
public ref class Material : public NativeAsset<SHMaterialInstance>
|
||||
{
|
||||
internal:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Constructors/Destructor */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Constructor for the Material
|
||||
/// </summary>
|
||||
/// <param name="material">Handle to the native material object.</param>
|
||||
Material(Handle<SHMaterialInstance> material);
|
||||
|
||||
public:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Properties */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
// TODO: Change Shader
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Material Properties Functions */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Set the value of a specific property.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of property to set.</typeparam>
|
||||
/// <param name="name">Name of the property to set.</param>
|
||||
/// <param name="value">Value to set te property to.</param>
|
||||
/// <exception cref="System.InvalidOperationException">
|
||||
/// If this Material object is invalid.
|
||||
/// </exception>
|
||||
/// <exception cref="System.ArgumentException">
|
||||
/// If the name or type was specified that does not match the material's shader's
|
||||
/// defined properties.
|
||||
/// </exception>
|
||||
generic<typename T>
|
||||
void SetProperty(System::String^ name, T value);
|
||||
/// <summary>
|
||||
/// Retrieves the value of a specified property on the material.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of property to get.</typeparam>
|
||||
/// <param name="name">Name of the property to get.</param>
|
||||
/// <returns>Value of that property on the material.</returns>
|
||||
/// <exception cref="System.InvalidOperationException">
|
||||
/// If this Material object is invalid.
|
||||
/// </exception>
|
||||
/// <exception cref="System.ArgumentException">
|
||||
/// If the name or type was specified that does not match the material's shader's
|
||||
/// defined properties.
|
||||
/// </exception>
|
||||
generic<typename T>
|
||||
T GetProperty(System::String^ name);
|
||||
};
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
/************************************************************************************//*!
|
||||
\file Mesh.cxx
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Oct 28, 2022
|
||||
\brief Contains the implementation of the functions of the managed Mesh class.
|
||||
|
||||
Note: This file is written in C++17/CLI.
|
||||
|
||||
Copyright (C) 2022 DigiPen Institute of Technology.
|
||||
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||
of DigiPen Institute of Technology is prohibited.
|
||||
*//*************************************************************************************/
|
||||
// Precompiled Headers
|
||||
#include "SHpch.h"
|
||||
// Primary Header
|
||||
#include "Mesh.hxx"
|
||||
// Project Headers
|
||||
#include "Utility/Convert.hxx"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Explicit Template Instantiation */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
template ref class NativeAsset<SHMesh>;
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Constructors/Destructor */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
Mesh::Mesh(Handle<SHMesh> mesh)
|
||||
: NativeAsset<SHMesh> { mesh }
|
||||
{}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/************************************************************************************//*!
|
||||
\file Mesh.hxx
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Oct 28, 2022
|
||||
\brief Contains the definition of the managed Mesh class.
|
||||
|
||||
Note: This file is written in C++17/CLI.
|
||||
|
||||
Copyright (C) 2022 DigiPen Institute of Technology.
|
||||
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||
of DigiPen Institute of Technology is prohibited.
|
||||
*//*************************************************************************************/
|
||||
#pragma once
|
||||
|
||||
// External Dependencies
|
||||
#include "Resource/SHHandle.h"
|
||||
#include "Graphics/MiddleEnd/Interface/SHMeshLibrary.h"
|
||||
// Project Includes
|
||||
#include "NativeAsset.hxx"
|
||||
#include "Engine/GenericHandle.hxx"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/// <summary>
|
||||
/// Managed counterpart of the native Mesh object containing vertex data that can
|
||||
/// be fed to Renderables for rendering.
|
||||
/// </summary>
|
||||
public ref class Mesh : public NativeAsset<SHMesh>
|
||||
{
|
||||
internal:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Constructors/Destructor */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Constructor for the Mesh
|
||||
/// </summary>
|
||||
/// <param name="mesh">Handle to the mesh object.</param>
|
||||
Mesh(Handle<SHMesh> mesh);
|
||||
};
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
/************************************************************************************//*!
|
||||
\file NativeAsset.cxx
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Oct 28, 2022
|
||||
\brief Contains the explicit template instantiation for some types of the
|
||||
templated managed NativeAsset class.
|
||||
|
||||
Note: This file is written in C++17/CLI.
|
||||
|
||||
Copyright (C) 2022 DigiPen Institute of Technology.
|
||||
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||
of DigiPen Institute of Technology is prohibited.
|
||||
*//*************************************************************************************/
|
||||
#include "SHpch.h"
|
||||
// Primary Include
|
||||
#include "NativeAsset.hxx"
|
||||
// Project Includes
|
||||
#include "Engine/GenericHandle.hxx"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Explicit Tempalte Instantiations */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
/************************************************************************************//*!
|
||||
\file NativeAsset.h++
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Oct 28, 2022
|
||||
\brief Contains the definition of templated functions for the managed
|
||||
NativeAsset classes.
|
||||
|
||||
Note: This file is written in C++17/CLI.
|
||||
|
||||
Copyright (C) 2022 DigiPen Institute of Technology.
|
||||
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||
of DigiPen Institute of Technology is prohibited.
|
||||
*//*************************************************************************************/
|
||||
#pragma once
|
||||
|
||||
// Primary Include
|
||||
#include "NativeAsset.hxx"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Properties */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
template <typename NativeAssetType>
|
||||
GenericHandle NativeAsset<NativeAssetType>::NativeObjectHandle::get()
|
||||
{
|
||||
return nativeObjHandle;
|
||||
}
|
||||
template <typename NativeAssetType>
|
||||
Handle<NativeAssetType> NativeAsset<NativeAssetType>::NativeObject::get()
|
||||
try
|
||||
{
|
||||
return Handle<NativeAssetType>(Convert::ToNative(nativeObjHandle));
|
||||
}
|
||||
catch (const BadHandleCastException&)
|
||||
{
|
||||
return Handle<NativeAssetType>(); // Null handle
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Constructors */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
template <typename NativeAssetType>
|
||||
NativeAsset<NativeAssetType>::NativeAsset(Handle<NativeAssetType> nativeObj)
|
||||
: nativeObjHandle{ Convert::ToCLI(Handle<void>(nativeObj)) }
|
||||
{}
|
||||
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
/************************************************************************************//*!
|
||||
\file NativeAsset.hxx
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Oct 28, 2022
|
||||
\brief Contains the template definition of the managed class that represents
|
||||
native assets with a pointer to the corresponding native object.
|
||||
|
||||
Note: This file is written in C++17/CLI.
|
||||
|
||||
Copyright (C) 2021 DigiPen Institute of Technology.
|
||||
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||
of DigiPen Institute of Technology is prohibited.
|
||||
*//*************************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "Engine/GenericHandle.hxx"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/// <summary>
|
||||
/// Generalised template class for a managed representation of a native asset
|
||||
/// </summary>
|
||||
/// <typeparam name="NativeAssetType">
|
||||
/// The type of the asset's native representation.
|
||||
/// </typeparam>
|
||||
template<typename NativeAssetType>
|
||||
public ref class NativeAsset
|
||||
{
|
||||
internal:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Properties */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Generic handle for the native object
|
||||
/// </summary>
|
||||
property GenericHandle NativeObjectHandle
|
||||
{
|
||||
GenericHandle get();
|
||||
}
|
||||
/// <summary>
|
||||
/// Copy of the Handle to the native object.
|
||||
/// </summary>
|
||||
property Handle<NativeAssetType> NativeObject
|
||||
{
|
||||
Handle<NativeAssetType> get();
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Constructors/Destructor */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Constructor for the native asset
|
||||
/// </summary>
|
||||
/// <param name="ptr">Native asset object.</param>
|
||||
NativeAsset(Handle<NativeAssetType> ptr);
|
||||
|
||||
protected:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Data Members */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
GenericHandle nativeObjHandle;
|
||||
};
|
||||
}
|
||||
|
||||
#include "NativeAsset.h++"
|
|
@ -27,7 +27,7 @@ namespace SHADE
|
|||
/// <summary>
|
||||
/// Base interface for all Collider Shapes.
|
||||
/// </summary>
|
||||
public ref class CollisionShape
|
||||
public ref class CollisionShape abstract
|
||||
{
|
||||
public:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
@ -194,7 +194,7 @@ namespace SHADE
|
|||
/* Properties */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Total number of ColliderBounds in the Collider component.
|
||||
/// Total number of ColliderShapes in the Collider component.
|
||||
/// </summary>
|
||||
property int CollisionShapeCount
|
||||
{
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
/************************************************************************************//*!
|
||||
\file Renderable.cxx
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Oct 28, 2022
|
||||
\brief Contains the definition of the functions of the managed Renderable class.
|
||||
|
||||
Note: This file is written in C++17/CLI.
|
||||
|
||||
Copyright (C) 2022 DigiPen Institute of Technology.
|
||||
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||
of DigiPen Institute of Technology is prohibited.
|
||||
*//*************************************************************************************/
|
||||
// Precompiled Headers
|
||||
#include "SHpch.h"
|
||||
// Primary Header
|
||||
#include "Renderable.hxx"
|
||||
#include "Assets/NativeAsset.hxx"
|
||||
#include "Utility/Convert.hxx"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Constructors */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
Renderable::Renderable(Entity entity)
|
||||
: Component(entity)
|
||||
{}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Properties */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
SHADE::Mesh^ Renderable::Mesh::get()
|
||||
{
|
||||
return gcnew SHADE::Mesh(GetNativeComponent()->GetMesh());
|
||||
}
|
||||
void Renderable::Mesh::set(SHADE::Mesh^ value)
|
||||
{
|
||||
if (value == nullptr)
|
||||
{
|
||||
GetNativeComponent()->SetMesh(Handle<SHMesh>());
|
||||
}
|
||||
else
|
||||
{
|
||||
GetNativeComponent()->SetMesh(Handle<SHMesh>(Convert::ToNative(value->NativeObjectHandle)));
|
||||
}
|
||||
}
|
||||
SHADE::Material^ Renderable::Material::get()
|
||||
{
|
||||
return gcnew SHADE::Material(GetNativeComponent()->GetMaterial());
|
||||
}
|
||||
void Renderable::Material::set(SHADE::Material^ value)
|
||||
{
|
||||
if (value == nullptr)
|
||||
{
|
||||
GetNativeComponent()->SetMaterial(Handle<SHMaterialInstance>());
|
||||
}
|
||||
else
|
||||
{
|
||||
GetNativeComponent()->SetMaterial(Handle<SHMaterialInstance>(Convert::ToNative(value->NativeObjectHandle)));
|
||||
}
|
||||
}
|
||||
System::Byte Renderable::LightLayer::get()
|
||||
{
|
||||
return GetNativeComponent()->GetLightLayer();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
/************************************************************************************//*!
|
||||
\file Renderable.hxx
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Oct 28, 2022
|
||||
\brief Contains the definition of the managed Renderable class with the
|
||||
declaration of functions for working with it.
|
||||
|
||||
Note: This file is written in C++17/CLI.
|
||||
|
||||
Copyright (C) 2022 DigiPen Institute of Technology.
|
||||
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||
of DigiPen Institute of Technology is prohibited.
|
||||
*//*************************************************************************************/
|
||||
#pragma once
|
||||
|
||||
// Project Includes
|
||||
#include "Components/Component.hxx"
|
||||
#include "Math/Vector3.hxx"
|
||||
#include "Math/Quaternion.hxx"
|
||||
// External Dependencies
|
||||
#include "Graphics/MiddleEnd/Interface/SHRenderable.h"
|
||||
#include "Assets/Mesh.hxx"
|
||||
#include "Assets/Material.hxx"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/// <summary>
|
||||
/// CLR version of the SHADE Engine's SHRenderableComponent.
|
||||
/// </summary>
|
||||
public ref class Renderable : public Component<SHRenderable>
|
||||
{
|
||||
internal:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Constructors */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Constructs a Renderable Component that represents a native Renderable
|
||||
/// component tied to the specified Entity.
|
||||
/// </summary>
|
||||
/// <param name="entity">Entity that this Component will be tied to.</param>
|
||||
Renderable(Entity entity);
|
||||
|
||||
public:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Properties */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Mesh used to render this Renderable.
|
||||
/// </summary>
|
||||
property SHADE::Mesh^ Mesh
|
||||
{
|
||||
SHADE::Mesh^ get();
|
||||
void set(SHADE::Mesh^ value);
|
||||
}
|
||||
/// <summary>
|
||||
/// Material used to render this Renderable.
|
||||
/// </summary>
|
||||
property SHADE::Material^ Material
|
||||
{
|
||||
SHADE::Material^ get();
|
||||
void set(SHADE::Material^ value);
|
||||
}
|
||||
/// <summary>
|
||||
/// Material used to render this Renderable.
|
||||
/// </summary>
|
||||
property System::Byte LightLayer
|
||||
{
|
||||
System::Byte get();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
/************************************************************************************//*!
|
||||
\file Renderable.cxx
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Oct 28, 2022
|
||||
\brief Contains the definition of the functions of the managed Renderable class.
|
||||
|
||||
Note: This file is written in C++17/CLI.
|
||||
|
||||
Copyright (C) 2022 DigiPen Institute of Technology.
|
||||
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||
of DigiPen Institute of Technology is prohibited.
|
||||
*//*************************************************************************************/
|
||||
#include "SHpch.h"
|
||||
#include "GenericHandle.hxx"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Constructors */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
GenericHandle::GenericHandle(Handle<void> handle)
|
||||
: id { handle.GetId().Raw }
|
||||
, library { reinterpret_cast<void*>(handle.GetLibrary()) }
|
||||
{}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Properties */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
System::UInt64 GenericHandle::Id::get()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
System::IntPtr GenericHandle::Library::get()
|
||||
{
|
||||
return library;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Overloaded Operators */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
GenericHandle::operator bool()
|
||||
{
|
||||
return library.ToPointer() != nullptr && id != System::UInt64::MaxValue;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
/************************************************************************************//*!
|
||||
\file Handle.hxx
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Oct 28, 2022
|
||||
\brief Contains the definition of the managed GenericHandle struct.
|
||||
|
||||
Note: This file is written in C++17/CLI.
|
||||
|
||||
Copyright (C) 2022 DigiPen Institute of Technology.
|
||||
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||
of DigiPen Institute of Technology is prohibited.
|
||||
*//*************************************************************************************/
|
||||
#pragma once
|
||||
|
||||
// External Dependencies
|
||||
#include "Resource/SHHandle.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/// <summary>
|
||||
/// Managed version of the generic Handle<void>.
|
||||
/// </summary>
|
||||
public value struct GenericHandle
|
||||
{
|
||||
public:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Constructors */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Constructs a GenericHandle for a native generic Handle<void>.
|
||||
/// </summary>
|
||||
/// <param name="handle">Handle to create a GenericHandle from.</param>
|
||||
explicit GenericHandle(Handle<void> handle);
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Properties */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// The internal ID of the handle.
|
||||
/// </summary>
|
||||
property System::UInt64 Id
|
||||
{
|
||||
System::UInt64 get();
|
||||
}
|
||||
/// <summary>
|
||||
/// The library that the handle was issued by.
|
||||
/// </summary>
|
||||
property System::IntPtr Library
|
||||
{
|
||||
System::IntPtr get();
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Overloaded Operators */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Converts to true if this is a valid Handle.
|
||||
/// </summary>
|
||||
inline operator bool();
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Data Members */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
System::UInt64 id;
|
||||
System::IntPtr library;
|
||||
};
|
||||
}
|
|
@ -0,0 +1,154 @@
|
|||
/************************************************************************************//*!
|
||||
\file Color.cxx
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Nov 3, 2021
|
||||
\brief Contains the definition of the functions of the managed Color struct.
|
||||
|
||||
Note: This file is written in C++17/CLI.
|
||||
|
||||
Copyright (C) 2021 DigiPen Institute of Technology.
|
||||
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||
of DigiPen Institute of Technology is prohibited.
|
||||
*//*************************************************************************************/
|
||||
// Precompiled Headers
|
||||
#include "SHpch.h"
|
||||
// Primary Header
|
||||
#include "Graphics/Color.hxx"
|
||||
// Standard Libraries
|
||||
#include <algorithm>
|
||||
// Project Includes
|
||||
#include "Math/Math.hxx"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Constructors */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
Color::Color(float _red)
|
||||
: Color { _red, 0.0f, 0.0f, 1.0f }
|
||||
{}
|
||||
Color::Color(float _red, float _green)
|
||||
: Color { _red, _green, 0.0f, 1.0f }
|
||||
{}
|
||||
Color::Color(float _red, float _green, float _blue)
|
||||
: Color { _red, _green, _blue, 1.0f }
|
||||
{}
|
||||
Color::Color(float _red, float _green, float _blue, float _alpha)
|
||||
: r { _red }
|
||||
, g { _green }
|
||||
, b { _blue }
|
||||
, a { _alpha }
|
||||
{}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* IEquatable */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
bool Color::Equals(Object^ o)
|
||||
{
|
||||
try
|
||||
{
|
||||
Color col = safe_cast<Color>(o);
|
||||
return Equals(col);
|
||||
}
|
||||
catch (System::InvalidCastException^)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Object Overrides */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
bool Color::Equals(Color other)
|
||||
{
|
||||
return Math::CompareFloat(this->r, other.r)
|
||||
&&
|
||||
Math::CompareFloat(this->g, other.g)
|
||||
&&
|
||||
Math::CompareFloat(this->b, other.b)
|
||||
&&
|
||||
Math::CompareFloat(this->a, other.a);
|
||||
}
|
||||
int Color::GetHashCode()
|
||||
{
|
||||
const int HASH = 19;
|
||||
const int HASH2 = 23;
|
||||
const int HASH3 = 29;
|
||||
return r.GetHashCode() * HASH
|
||||
+ g.GetHashCode() * HASH2
|
||||
+ b.GetHashCode() * HASH3
|
||||
+ a.GetHashCode();
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Static Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
Color Color::Lerp(Color colA, Color colB, float t)
|
||||
{
|
||||
return LerpUnclamped(colA, colB, std::clamp(t, 0.0f, 1.0f));
|
||||
}
|
||||
|
||||
Color Color::LerpUnclamped(Color colA, Color colB, float t)
|
||||
{
|
||||
return colA + ((colB - colA) * t);
|
||||
}
|
||||
Color Color::operator+(Color lhs, Color rhs)
|
||||
{
|
||||
return Color
|
||||
(
|
||||
lhs.r + rhs.r,
|
||||
lhs.g + rhs.g,
|
||||
lhs.b + rhs.b,
|
||||
lhs.a + rhs.a
|
||||
);
|
||||
}
|
||||
Color Color::operator-(Color lhs, Color rhs)
|
||||
{
|
||||
return Color
|
||||
(
|
||||
lhs.r - rhs.r,
|
||||
lhs.g - rhs.g,
|
||||
lhs.b - rhs.b,
|
||||
lhs.a - rhs.a
|
||||
);
|
||||
}
|
||||
Color Color::operator*(Color lhs, Color rhs)
|
||||
{
|
||||
return Color
|
||||
(
|
||||
lhs.r * rhs.r,
|
||||
lhs.g * rhs.g,
|
||||
lhs.b * rhs.b,
|
||||
lhs.a * rhs.a
|
||||
);
|
||||
}
|
||||
Color Color::operator*(Color lhs, float rhs)
|
||||
{
|
||||
return Color
|
||||
(
|
||||
lhs.r * rhs,
|
||||
lhs.g * rhs,
|
||||
lhs.b * rhs,
|
||||
lhs.a * rhs
|
||||
);
|
||||
}
|
||||
Color Color::operator/(Color lhs, float rhs)
|
||||
{
|
||||
return Color
|
||||
(
|
||||
lhs.r / rhs,
|
||||
lhs.g / rhs,
|
||||
lhs.b / rhs,
|
||||
lhs.a / rhs
|
||||
);
|
||||
}
|
||||
bool Color::operator==(Color lhs, Color rhs)
|
||||
{
|
||||
return lhs.Equals(rhs);
|
||||
}
|
||||
bool Color::operator!=(Color lhs, Color rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,287 @@
|
|||
/************************************************************************************//*!
|
||||
\file Color.hxx
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Oct 28, 2022
|
||||
\brief Contains the definition of the managed Color struct with the
|
||||
declaration of functions for working with it.
|
||||
|
||||
Note: This file is written in C++17/CLI.
|
||||
|
||||
Copyright (C) 2022 DigiPen Institute of Technology.
|
||||
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||
of DigiPen Institute of Technology is prohibited.
|
||||
*//*************************************************************************************/
|
||||
#pragma once
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/// <summary>
|
||||
/// CLR version of the the SHADE Engine's Color struct which describes a Color
|
||||
/// encoded using floating point numbers that range from 0.0f to 1.0f.
|
||||
/// </summary>
|
||||
[System::Runtime::InteropServices::StructLayout(System::Runtime::InteropServices::LayoutKind::Sequential)]
|
||||
public value struct Color : public System::IEquatable<Color>
|
||||
{
|
||||
public:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Type Definitions */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// A static class that contains a set of default Colors.
|
||||
/// </summary>
|
||||
ref class Defaults abstract sealed
|
||||
{
|
||||
public:
|
||||
/*-------------------------------------------------------------------------*/
|
||||
/* Properties */
|
||||
/*-------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Pure black.
|
||||
/// </summary>
|
||||
static property Color Black
|
||||
{
|
||||
Color get() { return Color(0.0f, 0.0f, 0.0f); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Light Gray, lighter than gray.
|
||||
/// </summary>
|
||||
static property Color LightGray
|
||||
{
|
||||
Color get() { return Color(0.827451f, 0.827451f, 0.827451f); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Gray, halfway between black and white.
|
||||
/// </summary>
|
||||
static property Color Gray
|
||||
{
|
||||
Color get() { return Color(0.5f, 0.5f, 0.5f); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Dark Gray, darker than gray.
|
||||
/// </summary>
|
||||
static property Color DarkGray
|
||||
{
|
||||
Color get() { return Color(0.622f, 0.622f, 0.622f); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Pure white.
|
||||
/// </summary>
|
||||
static property Color White
|
||||
{
|
||||
Color get() { return Color(1.0f, 1.0f, 1.0f); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Pure red.
|
||||
/// </summary>
|
||||
static property Color Red
|
||||
{
|
||||
Color get() { return Color(1.0f, 0.0f, 0.0f); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Pure green.
|
||||
/// </summary>
|
||||
static property Color Green
|
||||
{
|
||||
Color get() { return Color(0.0f, 1.0f, 0.0f); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Pure blue.
|
||||
/// </summary>
|
||||
static property Color Blue
|
||||
{
|
||||
Color get() { return Color(0.0f, 0.0f, 1.0f); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Pure cyan, mix of pure green and blue.
|
||||
/// </summary>
|
||||
static property Color Cyan
|
||||
{
|
||||
Color get() { return Color(0.0f, 1.0f, 1.0f); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Pure magenta, mix of pure red and blue.
|
||||
/// </summary>
|
||||
static property Color Magenta
|
||||
{
|
||||
Color get() { return Color(1.0f, 0.0f, 1.0f); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Pure yellow, mix of pure red and green.
|
||||
/// </summary>
|
||||
static property Color Yellow
|
||||
{
|
||||
Color get() { return Color(1.0f, 1.0f, 0.0f); }
|
||||
}
|
||||
};
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Constructors */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Constructor to construct a Color with the specified components with the
|
||||
/// green, blue and alpha component set to 1.0f.
|
||||
/// </summary>
|
||||
/// <param name="_red">Red component to set.</param>
|
||||
Color(float _red);
|
||||
/// <summary>
|
||||
/// Constructor to construct a Color with the specified components with the
|
||||
/// blue and alpha component set to 1.0f.
|
||||
/// </summary>
|
||||
/// <param name="_red">Red component to set.</param>
|
||||
/// <param name="_green">Green component to set.</param>
|
||||
Color(float _red, float _green);
|
||||
/// <summary>
|
||||
/// Constructor to construct a Color with the specified components with the
|
||||
/// alpha component set to 1.0f.
|
||||
/// </summary>
|
||||
/// <param name="_red">Red component to set.</param>
|
||||
/// <param name="_green">Green component to set.</param>
|
||||
/// <param name="_blue">Blue component to set.</param>
|
||||
Color(float _red, float _green, float _blue);
|
||||
/// <summary>
|
||||
/// Constructor to construct a Color with the specified components.
|
||||
/// </summary>
|
||||
/// <param name="_red">Red component to set.</param>
|
||||
/// <param name="_green">Green component to set.</param>
|
||||
/// <param name="_blue">Blue component to set.</param>
|
||||
/// <param name="_alpha">Alpha component to set.</param>
|
||||
Color(float _red, float _green, float _blue, float _alpha);
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Public Members */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Red component of the colour. Ranges from 0.0f to 1.0f.
|
||||
/// </summary>
|
||||
float r;
|
||||
/// <summary>
|
||||
/// Green component of the colour. Ranges from 0.0f to 1.0f.
|
||||
/// </summary>
|
||||
float g;
|
||||
/// <summary>
|
||||
/// Blue component of the colour. Ranges from 0.0f to 1.0f.
|
||||
/// </summary>
|
||||
float b;
|
||||
/// <summary>
|
||||
/// Alpha component of the colour. Ranges from 0.0f to 1.0f.
|
||||
/// </summary>
|
||||
float a;
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* IEquatable */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Compares equality with an object of the same type.
|
||||
/// </summary>
|
||||
/// <param name="other">The object to compare with.</param>
|
||||
/// <returns>True if both objects are the same.</returns>
|
||||
virtual bool Equals(Color other);
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Object */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Compares equality with another unboxed object.
|
||||
/// </summary>
|
||||
/// <param name="o">The unboxed object to compare with.</param>
|
||||
/// <returns>True if both objects are the same.</returns>
|
||||
bool Equals(Object^ o) override;
|
||||
/// <summary>
|
||||
/// Gets a unique hash for this object.
|
||||
/// </summary>
|
||||
/// <returns>Unique hash for this object.</returns>
|
||||
int GetHashCode() override;
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Static Functions */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Linearly interpolates between two specified points.
|
||||
/// This is most commonly used to find a point some fraction of the way along a
|
||||
/// line between two endpoints.
|
||||
/// </summary>
|
||||
/// <param name="colA">The start Color, returned when t = 0.0.</param>
|
||||
/// <param name="colB">The end Color, returned when t = 1.0.</param>
|
||||
/// <param name="t">
|
||||
/// Value used to interpolate between a and b which is clamped to
|
||||
/// the range[0, 1].
|
||||
/// </param>
|
||||
/// <returns>The interpolated Vector3.</returns>
|
||||
static Color Lerp(Color colA, Color colB, float t);
|
||||
/// <summary>
|
||||
/// Linearly interpolates between two specified points.
|
||||
/// This is most commonly used to find a point some fraction of the way along a
|
||||
/// line between two endpoints.
|
||||
/// Unlike Lerp(), t is not clamped to a range at all.
|
||||
/// </summary>
|
||||
/// <param name="colA">The start Color, returned when t = 0.0.</param>
|
||||
/// <param name="colB">The end Color, returned when t = 1.0.</param>
|
||||
/// <param name="t">Value used to interpolate between a and b.</param>
|
||||
/// <returns>The interpolated Color.</returns>
|
||||
static Color LerpUnclamped(Color colA, Color colB, float t);
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Overloaded Operators */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Adds two Colors together and returns the result.
|
||||
/// </summary>
|
||||
/// <param name="lhs">Color to add.</param>
|
||||
/// <param name="rhs">Another Color to add.</param>
|
||||
/// <returns>The result of lhs added to rhs</returns>
|
||||
static Color operator+(Color lhs, Color rhs);
|
||||
/// <summary>
|
||||
/// Subtracts a Color from another Color and returns the result.
|
||||
/// </summary>
|
||||
/// <param name="lhs">Color to subtract from.</param>
|
||||
/// <param name="rhs">Another Color to subtract.</param>
|
||||
/// <returns>The result of rhs subtracted from lhs.</returns>
|
||||
static Color operator-(Color lhs, Color rhs);
|
||||
/// <summary>
|
||||
/// Calculates the component-wise multiplication of two Colors and returns the
|
||||
/// result.
|
||||
/// </summary>
|
||||
/// <param name="lhs">Color to multiply with.</param>
|
||||
/// <param name="rhs">Another Color to multiply with.</param>
|
||||
/// <returns>The result of rhs subtracted from lhs.</returns>
|
||||
static Color operator*(Color lhs, Color rhs);
|
||||
/// <summary>
|
||||
/// Calculates the multiplication of a Color with a scalar value and returns
|
||||
/// the result.
|
||||
/// </summary>
|
||||
/// <param name="lhs">Color to multiply with.</param>
|
||||
/// <param name="rhs">Scalar to multiply with.</param>
|
||||
/// <returns>The result of the scalar multiplication.</returns>
|
||||
static Color operator*(Color lhs, float rhs);
|
||||
/// <summary>
|
||||
/// Calculates the division of a Color with a scalar value and returns
|
||||
/// the result.
|
||||
/// </summary>
|
||||
/// <param name="lhs">Scalar to divide with.</param>
|
||||
/// <param name="rhs">Color to divide with.</param>
|
||||
/// <returns>The result of the scalar division.</returns>
|
||||
static Color operator/(Color lhs, float rhs);
|
||||
/// <summary>
|
||||
/// Checks if two Colors are approximately equal.
|
||||
/// </summary>
|
||||
/// <param name="lhs">Color to compare.</param>
|
||||
/// <param name="rhs">Another Color to compare.</param>
|
||||
/// <returns>
|
||||
/// True if all components are approximately equal within the default
|
||||
/// tolerance value.
|
||||
/// </returns>
|
||||
static bool operator==(Color lhs, Color rhs);
|
||||
/// <summary>
|
||||
/// Checks if two Colors are not approximately equal.
|
||||
/// </summary>
|
||||
/// <param name="lhs">Color to compare.</param>
|
||||
/// <param name="rhs">Another Color to compare.</param>
|
||||
/// <returns>
|
||||
/// True if all components are not approximately equal within the default
|
||||
/// tolerance value.
|
||||
/// </returns>
|
||||
static bool operator!=(Color lhs, Color rhs);
|
||||
};
|
||||
}
|
|
@ -54,4 +54,15 @@ namespace SHADE
|
|||
{
|
||||
return (value - a) / (b - a);
|
||||
}
|
||||
|
||||
bool Math::CompareFloat(float a, float b)
|
||||
{
|
||||
return CompareFloat(a, b, Epsilon);
|
||||
}
|
||||
|
||||
bool Math::CompareFloat(float a, float b, float tolerance)
|
||||
{
|
||||
return System::MathF::Abs(a - b) < tolerance;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -81,12 +81,30 @@ namespace SHADE
|
|||
/// <returns>The interpolated float result between the two float values.</returns>
|
||||
static float LerpUnclamped(float a, float b, float t);
|
||||
/// <summary>
|
||||
/// Calculates the linear parameter t that produces the interpolant value within the range [a, b].
|
||||
/// Calculates the linear parameter t that produces the interpolant value within
|
||||
/// the range [a, b].
|
||||
/// </summary>
|
||||
/// <param name="a">Start value.</param>
|
||||
/// <param name="b">End value.</param>
|
||||
/// <param name="value">Value between start and end.</param>
|
||||
/// <returns>Percentage of value between start and end.</returns>
|
||||
static float InverseLerp(float a, float b, float value);
|
||||
/// <summary>
|
||||
/// Compares if two float values are close enough to be the same with a tolerance
|
||||
/// of Epsilon.
|
||||
/// </summary>
|
||||
/// <param name="a">One of the values to compare.</param>
|
||||
/// <param name="b">The other value to compare.</param>
|
||||
/// <returns>True if a and b are practically the same.</returns>
|
||||
static bool CompareFloat(float a, float b);
|
||||
/// <summary>
|
||||
/// Compares if two float values are close enough to be the same with the
|
||||
/// specified tolerance value.
|
||||
/// </summary>
|
||||
/// <param name="a">One of the values to compare.</param>
|
||||
/// <param name="b">The other value to compare.</param>
|
||||
/// <param name="tolerance">Tolerance for floating point comparison.</param>
|
||||
/// <returns>True if a and b are practically the same.</returns>
|
||||
static bool CompareFloat(float a, float b, float tolerance);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -84,4 +84,20 @@ namespace SHADE
|
|||
{
|
||||
return msclr::interop::marshal_as<System::String^>(str);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Handle Conversions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
Handle<void> Convert::ToNative(GenericHandle handle)
|
||||
{
|
||||
Handle<void> nativeHandle;
|
||||
nativeHandle.id.Raw = handle.Id;
|
||||
nativeHandle.library = reinterpret_cast<SHResourceLibraryBase*>(handle.Library.ToPointer());
|
||||
return nativeHandle;
|
||||
}
|
||||
|
||||
GenericHandle Convert::ToCLI(Handle<void> handle)
|
||||
{
|
||||
return GenericHandle(handle);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ of DigiPen Institute of Technology is prohibited.
|
|||
#include "Math/Vector/SHVec3.h"
|
||||
#include "Math/SHQuaternion.h"
|
||||
#include "Math/SHRay.h"
|
||||
#include "Resource/SHHandle.h"
|
||||
|
||||
// Project Includes
|
||||
#include "Engine/Entity.hxx"
|
||||
|
@ -27,6 +28,7 @@ of DigiPen Institute of Technology is prohibited.
|
|||
#include "Math/Vector3.hxx"
|
||||
#include "Math/Quaternion.hxx"
|
||||
#include "Math/Ray.hxx"
|
||||
#include "Engine/GenericHandle.hxx"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
@ -118,6 +120,23 @@ namespace SHADE
|
|||
/// <param name="str">The native std::string to convert from.</param>
|
||||
/// <returns>Managed copy of a native std::string.</returns>
|
||||
static System::String^ ToCLI(const std::string& str);
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Handle Conversions */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Converts from a managed GenericHandle to a Handle<void>.
|
||||
/// </summary>
|
||||
/// <param name="handle">GenericHandle to convert from.</param>
|
||||
/// <returns>Native generic Handle.</returns>
|
||||
static Handle<void> ToNative(GenericHandle handle);
|
||||
/// <summary>
|
||||
/// Converts from a native generic Handle<void> to a managed GenericHandle.
|
||||
/// </summary>
|
||||
/// <param name="handle">The native handle to convert.</param>
|
||||
/// <returns>Managed copy of the native Handle.</returns>
|
||||
static GenericHandle ToCLI(Handle<void> handle);
|
||||
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -28,7 +28,7 @@ public class PhysicsTest : Script
|
|||
Debug.LogError("Collider is NULL!");
|
||||
}
|
||||
|
||||
var subColider = Collider.ColliderBoundsCount;
|
||||
var subColider = Collider.CollisionShapeCount;
|
||||
Debug.Log($"There are {subColider} colliders.");
|
||||
}
|
||||
protected override void update()
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
#version 450
|
||||
|
||||
struct DirectionalLightStruct
|
||||
{
|
||||
vec3 direction;
|
||||
uint isActive;
|
||||
uint cullingMask;
|
||||
vec4 diffuseColor;
|
||||
};
|
||||
|
||||
struct AmbientLightStruct
|
||||
{
|
||||
vec4 ambientColor;
|
||||
float strength;
|
||||
uint isActive;
|
||||
uint cullingMask;
|
||||
};
|
||||
|
||||
layout(local_size_x = 16, local_size_y = 16) in;
|
||||
layout(set = 4, binding = 0, rgba32f) uniform image2D positions;
|
||||
layout(set = 4, binding = 1, rgba32f) uniform image2D normals;
|
||||
layout(set = 4, binding = 2, rgba8) uniform image2D albedo;
|
||||
layout(set = 4, binding = 3, r32ui) uniform uimage2D lightLayerData;
|
||||
layout(set = 4, binding = 4, rgba8) uniform image2D targetImage;
|
||||
|
||||
layout(set = 1, binding = 0) uniform LightCounts
|
||||
{
|
||||
uint directionalLights;
|
||||
uint pointLights;
|
||||
uint spotLights;
|
||||
uint ambientLights;
|
||||
|
||||
} lightCounts;
|
||||
|
||||
layout(std430, set = 1, binding = 1) buffer DirectionalLightData
|
||||
{
|
||||
DirectionalLightStruct dLightData[];
|
||||
} DirLightData;
|
||||
|
||||
layout(std430, set = 1, binding = 4) buffer AmbientLightData
|
||||
{
|
||||
AmbientLightStruct aLightData[];
|
||||
} AmbLightData;
|
||||
|
||||
void main()
|
||||
{
|
||||
// convenient variables
|
||||
ivec2 globalThread = ivec2(gl_GlobalInvocationID);
|
||||
|
||||
// Get the diffuse color of the pixel
|
||||
vec3 pixelDiffuse = imageLoad (albedo, globalThread).rgb;
|
||||
|
||||
// Get position of fragment in world space
|
||||
vec3 positionWorld = imageLoad (positions, globalThread).rgb;
|
||||
|
||||
// normal of fragment
|
||||
vec3 normalWorld = imageLoad(normals, globalThread).rgb;
|
||||
|
||||
vec3 fragColor = vec3 (0.0f);
|
||||
|
||||
for (int i = 0; i < lightCounts.directionalLights; ++i)
|
||||
{
|
||||
// get normalized direction of light
|
||||
vec3 dLightNormalized = normalize (DirLightData.dLightData[i].direction);
|
||||
|
||||
// Get diffuse strength
|
||||
float diffuseStrength = max (0, dot (dLightNormalized, normalWorld));
|
||||
|
||||
// Calculate the fragment color
|
||||
fragColor += DirLightData.dLightData[i].diffuseColor.rgb * diffuseStrength.rrr * pixelDiffuse;
|
||||
}
|
||||
|
||||
for (int i = 0; i < lightCounts.ambientLights; ++i)
|
||||
{
|
||||
// Just do some add
|
||||
//fragColor += pixelDiffuse.rgb * AmbLightData.aLightData[i].ambientColor.rgb * vec3 (0.5f);
|
||||
fragColor += pixelDiffuse.rgb * AmbLightData.aLightData[i].ambientColor.rgb * vec3 (AmbLightData.aLightData[i].strength);
|
||||
}
|
||||
|
||||
// store result into result image
|
||||
imageStore(targetImage, ivec2(gl_GlobalInvocationID.xy), vec4(fragColor, 1.0f));
|
||||
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue