Added more objects + tested materials (still needs testing)
This commit is contained in:
commit
4fcb5e313b
|
@ -42,6 +42,8 @@ namespace Sandbox
|
||||||
auto meshes = SHADE::SHAssetManager::GetAllMeshes();
|
auto meshes = SHADE::SHAssetManager::GetAllMeshes();
|
||||||
std::vector<Handle<SHMesh>> handles;
|
std::vector<Handle<SHMesh>> handles;
|
||||||
for (auto const& mesh : meshes)
|
for (auto const& mesh : meshes)
|
||||||
|
{
|
||||||
|
if (mesh.meshName == "Cube.012")
|
||||||
{
|
{
|
||||||
handles.push_back(graphicsSystem->AddMesh(
|
handles.push_back(graphicsSystem->AddMesh(
|
||||||
mesh.header.vertexCount,
|
mesh.header.vertexCount,
|
||||||
|
@ -53,6 +55,7 @@ namespace Sandbox
|
||||||
mesh.indices.data()
|
mesh.indices.data()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
graphicsSystem->BuildMeshBuffers();
|
graphicsSystem->BuildMeshBuffers();
|
||||||
|
|
||||||
// Load Textures
|
// Load Textures
|
||||||
|
@ -69,67 +72,68 @@ namespace Sandbox
|
||||||
auto matInst = graphicsSystem->AddOrGetBaseMaterialInstance();
|
auto matInst = graphicsSystem->AddOrGetBaseMaterialInstance();
|
||||||
auto customMat = graphicsSystem->AddMaterialInstanceCopy(matInst);
|
auto customMat = graphicsSystem->AddMaterialInstanceCopy(matInst);
|
||||||
customMat->SetProperty("data.color", SHVec4(0.0f, 1.0f, 1.0f, 1.0f));
|
customMat->SetProperty("data.color", SHVec4(0.0f, 1.0f, 1.0f, 1.0f));
|
||||||
|
customMat->SetProperty("data.textureIndex", 1);
|
||||||
|
customMat->SetProperty("data.alpha", 0.1f);
|
||||||
|
|
||||||
// Create Stress Test Objects
|
// Create Stress Test Objects
|
||||||
static const SHVec3 TEST_OBJ_SCALE = { 4.0f, 4.0f, 4.0f };
|
static const SHVec3 TEST_OBJ_SCALE = { 0.2f, 0.2f, 0.2f };
|
||||||
constexpr int NUM_ROWS = 2;
|
constexpr int NUM_ROWS = 20;
|
||||||
constexpr int NUM_COLS = 2;
|
constexpr int NUM_COLS = 20;
|
||||||
static const SHVec3 TEST_OBJ_SPACING = { 20.0f, 20.0f, 20.0f };
|
static const SHVec3 TEST_OBJ_SPACING = { 0.2f, 0.2f, 0.2f };
|
||||||
static const SHVec3 TEST_OBJ_START_POS = { - (NUM_COLS / 2 * TEST_OBJ_SPACING.x ) + 15.0f, 0.0f, -2.0f };
|
static const SHVec3 TEST_OBJ_START_POS = { - (NUM_COLS / 2 * TEST_OBJ_SPACING.x ) + 1.0f, -2.0f, -1.0f };
|
||||||
//for (int z = 0; z < NUM_ROWS; ++z)
|
|
||||||
//for (int x = 0; x < NUM_COLS; ++x)
|
|
||||||
//{
|
|
||||||
// auto entity = SHEntityManager::CreateEntity<SHRenderable, SHTransformComponent>();
|
|
||||||
// auto& renderable = *SHComponentManager::GetComponent_s<SHRenderable>(entity);
|
|
||||||
// auto& transform = *SHComponentManager::GetComponent_s<SHTransformComponent>(entity);
|
|
||||||
|
|
||||||
// renderable.Mesh = handles.front();
|
|
||||||
// renderable.SetMaterial(matInst);
|
|
||||||
|
|
||||||
// // Set initial positions
|
|
||||||
// transform.SetWorldPosition(TEST_OBJ_START_POS + SHVec3{ x * TEST_OBJ_SPACING.x, 0.0f, z * TEST_OBJ_SPACING.z });
|
|
||||||
// transform.SetWorldRotation(3.14159265f * 1.5f, -3.14159265f / 2.0f, 0.0f);
|
|
||||||
// transform.SetLocalScale(TEST_OBJ_SCALE);
|
|
||||||
|
|
||||||
// stressTestObjects.emplace_back(entity);
|
|
||||||
//}
|
|
||||||
|
|
||||||
|
for (int y = 0; y < NUM_ROWS; ++y)
|
||||||
|
for (int x = 0; x < NUM_COLS; ++x)
|
||||||
|
{
|
||||||
auto entity = SHEntityManager::CreateEntity<SHRenderable, SHTransformComponent>();
|
auto entity = SHEntityManager::CreateEntity<SHRenderable, SHTransformComponent>();
|
||||||
auto& renderable = *SHComponentManager::GetComponent_s<SHRenderable>(entity);
|
auto& renderable = *SHComponentManager::GetComponent_s<SHRenderable>(entity);
|
||||||
auto& transform = *SHComponentManager::GetComponent_s<SHTransformComponent>(entity);
|
auto& transform = *SHComponentManager::GetComponent_s<SHTransformComponent>(entity);
|
||||||
|
|
||||||
renderable.Mesh = handles.back();
|
renderable.Mesh = handles.front();
|
||||||
renderable.SetMaterial(customMat);
|
renderable.SetMaterial(customMat);
|
||||||
|
|
||||||
|
//Set initial positions
|
||||||
|
transform.SetWorldPosition(TEST_OBJ_START_POS + SHVec3{
|
||||||
|
x * TEST_OBJ_SPACING.x,
|
||||||
|
y * TEST_OBJ_SPACING.y,
|
||||||
|
0.0f
|
||||||
|
});
|
||||||
|
//transform.SetWorldPosition({-1.0f, -1.0f, -1.0f});
|
||||||
|
//transform.SetWorldRotation(3.14159265f * 1.5f, -3.14159265f / 2.0f, 0.0f);
|
||||||
transform.SetLocalScale(TEST_OBJ_SCALE);
|
transform.SetLocalScale(TEST_OBJ_SCALE);
|
||||||
transform.SetWorldPosition({-1.0f, -1.0f, -1.0f});
|
|
||||||
|
|
||||||
//stressTestObjects.emplace_back(entity);
|
stressTestObjects.emplace_back(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
//auto entity = SHEntityManager::CreateEntity<SHRenderable, SHTransformComponent>();
|
||||||
|
//auto& renderable = *SHComponentManager::GetComponent_s<SHRenderable>(entity);
|
||||||
|
//auto& transform = *SHComponentManager::GetComponent_s<SHTransformComponent>(entity);
|
||||||
|
|
||||||
|
//renderable.Mesh = handles.back();
|
||||||
|
//renderable.SetMaterial(customMat);
|
||||||
|
|
||||||
|
//transform.SetLocalScale(TEST_OBJ_SCALE);
|
||||||
|
//transform.SetWorldPosition({-1.0f, -1.0f, -1.0f});
|
||||||
|
|
||||||
// Create blank entity with a script
|
// Create blank entity with a script
|
||||||
testObj = SHADE::SHEntityManager::CreateEntity<SHRenderable, SHTransformComponent>();
|
//testObj = SHADE::SHEntityManager::CreateEntity<SHRenderable, SHTransformComponent>();
|
||||||
auto& testObjRenderable = *SHComponentManager::GetComponent_s<SHRenderable>(testObj);
|
//auto& testObjRenderable = *SHComponentManager::GetComponent_s<SHRenderable>(testObj);
|
||||||
testObjRenderable.Mesh = CUBE_MESH;
|
//testObjRenderable.Mesh = CUBE_MESH;
|
||||||
testObjRenderable.SetMaterial(matInst);
|
//testObjRenderable.SetMaterial(matInst);
|
||||||
|
|
||||||
SHADE::SHScriptEngine* scriptEngine = static_cast<SHADE::SHScriptEngine*>(SHADE::SHSystemManager::GetSystem<SHADE::SHScriptEngine>());
|
SHADE::SHScriptEngine* scriptEngine = static_cast<SHADE::SHScriptEngine*>(SHADE::SHSystemManager::GetSystem<SHADE::SHScriptEngine>());
|
||||||
scriptEngine->AddScript(testObj, "TestScript");
|
scriptEngine->AddScript(testObj, "TestScript");
|
||||||
}
|
}
|
||||||
|
|
||||||
void SBTestScene::Update(float dt)
|
void SBTestScene::Update(float dt)
|
||||||
{
|
{
|
||||||
/*static float rotation = 0.0f;
|
|
||||||
|
|
||||||
auto& transform = *SHADE::SHComponentManager::GetComponent_s<SHADE::SHTransformComponent>(testObj);
|
|
||||||
|
|
||||||
transform.SetLocalRotation(rotation, 0.0f, 0.0f);
|
|
||||||
rotation += dt * 10.0f;*/
|
|
||||||
static float rotation = 0.0f;
|
static float rotation = 0.0f;
|
||||||
|
|
||||||
auto& transform = *SHADE::SHComponentManager::GetComponent_s<SHADE::SHTransformComponent>(testObj);
|
//auto& transform = *SHADE::SHComponentManager::GetComponent_s<SHADE::SHTransformComponent>(testObj);
|
||||||
|
|
||||||
transform.SetWorldPosition({1.0f, 1.0f, -1.0f});
|
//transform.SetWorldPosition({1.0f, 1.0f, -1.0f});
|
||||||
transform.SetWorldRotation(0.0f, 0.0f + rotation, 0.0f);
|
//transform.SetWorldRotation(0.0f, 0.0f + rotation, 0.0f);
|
||||||
rotation += dt * 0.2f;
|
//rotation += dt * 0.2f;
|
||||||
|
|
||||||
// Destroy entity if space is pressed
|
// Destroy entity if space is pressed
|
||||||
if (GetKeyState(VK_SPACE) & 0x8000)
|
if (GetKeyState(VK_SPACE) & 0x8000)
|
||||||
|
|
|
@ -5,38 +5,24 @@
|
||||||
|
|
||||||
layout(location = 0) in struct
|
layout(location = 0) in struct
|
||||||
{
|
{
|
||||||
//mat3 BTN;
|
|
||||||
vec4 vertColor;
|
vec4 vertColor;
|
||||||
//vec3 localSpacePosition;
|
|
||||||
vec2 uv;
|
vec2 uv;
|
||||||
//vec3 localLightPosition;
|
|
||||||
//vec3 localEyePosition;
|
|
||||||
|
|
||||||
} In;
|
} In;
|
||||||
|
|
||||||
//layout(std140, push_constant) uniform TestPushConstant
|
// material stuff
|
||||||
//{
|
layout(location = 2) flat in struct
|
||||||
// mat4 pvMat;
|
{
|
||||||
// vec4 lightPosition;
|
int materialIndex;
|
||||||
// vec4 eyePosition;
|
} In2;
|
||||||
// vec4 ambientColor;
|
|
||||||
// vec4 lightColor;
|
|
||||||
//
|
|
||||||
//} testPushConstant;
|
|
||||||
|
|
||||||
layout(location = 0) out vec4 outColor;
|
|
||||||
|
|
||||||
//layout(binding = 0) uniform sampler2D diffuseMap;
|
|
||||||
//layout(binding = 1) uniform sampler2D normalMap;
|
|
||||||
//layout(binding = 2) uniform sampler2D aoMap;
|
|
||||||
//layout(binding = 3) uniform sampler2D glossinessMap;
|
|
||||||
//layout(binding = 4) uniform sampler2D samplerRoughnessMap;
|
|
||||||
|
|
||||||
layout (set = 0, binding = 1) uniform sampler2D textures[];
|
layout (set = 0, binding = 1) uniform sampler2D textures[];
|
||||||
|
|
||||||
struct MatPropData
|
struct MatPropData
|
||||||
{
|
{
|
||||||
vec4 color;
|
vec4 color;
|
||||||
|
int textureIndex;
|
||||||
float alpha;
|
float alpha;
|
||||||
vec3 beta;
|
vec3 beta;
|
||||||
};
|
};
|
||||||
|
@ -46,42 +32,13 @@ layout(set = 3, binding = 0) buffer MaterialProperties
|
||||||
MatPropData data[];
|
MatPropData data[];
|
||||||
} MatProp;
|
} MatProp;
|
||||||
|
|
||||||
|
layout(location = 0) out vec4 outColor;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
//vec3 normal;
|
|
||||||
|
|
||||||
//// Get the tangent space normal from normal map. It is a BC5 texture and therefore only use red and green
|
outColor = texture(textures[nonuniformEXT(MatProp.data[In2.materialIndex].textureIndex)], In.uv) +
|
||||||
//normal.xy = (texture (normalMap, In.uv).gr * 2.0f) - 1.0f;
|
MatProp.data[In2.materialIndex].color / MatProp.data[In2.materialIndex].alpha;
|
||||||
|
|
||||||
//// z value is derived (TODO: Find out what this does)
|
|
||||||
//normal.z = sqrt(1.0f - dot(normal.xy, normal.xy));
|
|
||||||
|
|
||||||
//// Transform the normal from tangent space to local space
|
|
||||||
//normal = In.BTN * normal;
|
|
||||||
|
|
||||||
//// Get the vector from fragment to light
|
|
||||||
//vec3 localLightDir = normalize(In.localLightPosition - In.localSpacePosition);
|
|
||||||
|
|
||||||
//// get the value of dot between normal from texture and frag to light
|
|
||||||
//float diffuse = max(0, dot(normal, localLightDir));
|
|
||||||
|
|
||||||
//// sample the diffuse texture
|
|
||||||
//vec4 diffuseColor = texture (diffuseMap, In.uv) * In.vertColor;
|
|
||||||
|
|
||||||
//vec3 eyeDirection = normalize(In.localSpacePosition - In.localEyePosition);
|
|
||||||
|
|
||||||
//const float shininess = mix(1, 100, 1 - texture (samplerRoughnessMap, In.uv).r);
|
|
||||||
|
|
||||||
//float specular = pow(max(0, dot(normal, normalize(localLightDir - eyeDirection))), shininess);
|
|
||||||
|
|
||||||
//outColor.rgb = testPushConstant.ambientColor.rgb * diffuseColor.rgb * texture (aoMap, In.uv).rgb;
|
|
||||||
|
|
||||||
//outColor.rgb += testPushConstant.lightColor.rgb * (specular.rrr * 0.4 + diffuse.rrr * diffuseColor.rgb);
|
|
||||||
|
|
||||||
//const float gamma = testPushConstant.eyePosition.w;
|
|
||||||
//outColor.rgb = pow(outColor.rgb, vec3(1.0f / gamma));
|
|
||||||
//outColor.a = diffuseColor.a;
|
|
||||||
|
|
||||||
outColor = texture(textures[0], In.uv) ;
|
|
||||||
//outColor = vec4 (1.0f);
|
//outColor = vec4 (1.0f);
|
||||||
}
|
}
|
Binary file not shown.
|
@ -9,27 +9,20 @@ layout(location = 2) in vec3 aNormal;
|
||||||
layout(location = 3) in vec3 aTangent;
|
layout(location = 3) in vec3 aTangent;
|
||||||
layout(location = 4) in mat4 worldTransform;
|
layout(location = 4) in mat4 worldTransform;
|
||||||
|
|
||||||
//layout(std140, push_constant) uniform TestPushConstant
|
|
||||||
//{
|
|
||||||
// mat4 pvMat;
|
|
||||||
// vec4 lightPosition;
|
|
||||||
// vec4 eyePosition;
|
|
||||||
// vec4 ambientColor;
|
|
||||||
// vec4 lightColor;
|
|
||||||
//
|
|
||||||
//} testPushConstant;
|
|
||||||
|
|
||||||
layout(location = 0) out struct
|
layout(location = 0) out struct
|
||||||
{
|
{
|
||||||
//mat3 BTN;
|
vec4 vertColor; // location 0
|
||||||
vec4 vertColor;
|
vec2 uv; // location = 1
|
||||||
//vec3 localSpacePosition;
|
|
||||||
vec2 uv;
|
|
||||||
//vec3 localLightPosition;
|
|
||||||
//vec3 localEyePosition;
|
|
||||||
|
|
||||||
} Out;
|
} Out;
|
||||||
|
|
||||||
|
// material stuff
|
||||||
|
layout(location = 2) out struct
|
||||||
|
{
|
||||||
|
int materialIndex;
|
||||||
|
} Out2;
|
||||||
|
|
||||||
layout(set = 2, binding = 0) uniform CameraData
|
layout(set = 2, binding = 0) uniform CameraData
|
||||||
{
|
{
|
||||||
vec4 position;
|
vec4 position;
|
||||||
|
@ -38,26 +31,8 @@ layout(set = 2, binding = 0) uniform CameraData
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
//const float gamma = testPushConstant.eyePosition.w;
|
|
||||||
//mat4 W2L = inverse(worldTransform);
|
|
||||||
|
|
||||||
//// Since attributes are instanced we want the local positions of light and eye (camera)
|
|
||||||
//Out.localLightPosition = vec3(W2L * vec4(testPushConstant.lightPosition.xyz, 1.0f));
|
|
||||||
//Out.localEyePosition = vec3(W2L * vec4(testPushConstant.eyePosition.xyz, 1.0f));
|
|
||||||
|
|
||||||
//vec3 biTangent = normalize(cross(aNormal, aTangent));
|
|
||||||
|
|
||||||
//gl_Position = testPushConstant.pvMat * worldTransform * vec4(aVertexPos, 1.0);
|
|
||||||
|
|
||||||
//// Since the normal we are sampling is in tangent space, we want to later convert them to local space
|
|
||||||
//// so we need this matrix to multiply with the sampled texel of the normal map.
|
|
||||||
//Out.BTN = mat3(aTangent, biTangent, aNormal);
|
|
||||||
//Out.localSpacePosition = aVertexPos;
|
|
||||||
//Out.uv = aUV;
|
|
||||||
|
|
||||||
// render NDC first
|
|
||||||
//gl_Position = vec4(aVertexPos, 1.0f);
|
|
||||||
Out.uv = aUV;
|
Out.uv = aUV;
|
||||||
|
Out2.materialIndex = gl_InstanceIndex;
|
||||||
gl_Position = cameraData.vpMat * worldTransform * vec4 (aVertexPos, 1.0f);
|
gl_Position = cameraData.vpMat * worldTransform * vec4 (aVertexPos, 1.0f);
|
||||||
Out.vertColor = vec4 (aVertexPos, 1.0f);
|
Out.vertColor = vec4 (aVertexPos, 1.0f);
|
||||||
}
|
}
|
Binary file not shown.
Loading…
Reference in New Issue