There is a memory leak
This commit is contained in:
+14
-1
@@ -15,7 +15,7 @@
|
|||||||
{
|
{
|
||||||
"name": "Release",
|
"name": "Release",
|
||||||
"generator": "Visual Studio 17 2022 Win64",
|
"generator": "Visual Studio 17 2022 Win64",
|
||||||
"configurationType": "RelWithDebInfo",
|
"configurationType": "Release",
|
||||||
"buildRoot": "C:/Users/Dynamitos/Seele/bin/",
|
"buildRoot": "C:/Users/Dynamitos/Seele/bin/",
|
||||||
"cmakeCommandArgs": "-DCMAKE_DEBUG_POSTFIX=\"\" -DCMAKE_PLATFORM=x64",
|
"cmakeCommandArgs": "-DCMAKE_DEBUG_POSTFIX=\"\" -DCMAKE_PLATFORM=x64",
|
||||||
"buildCommandArgs": "",
|
"buildCommandArgs": "",
|
||||||
@@ -23,6 +23,19 @@
|
|||||||
"inheritEnvironments": [ "msvc_x64" ],
|
"inheritEnvironments": [ "msvc_x64" ],
|
||||||
"intelliSenseMode": "windows-msvc-x64",
|
"intelliSenseMode": "windows-msvc-x64",
|
||||||
"installRoot": "C:/Program Files/Seele"
|
"installRoot": "C:/Program Files/Seele"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "RelWithDebInfo",
|
||||||
|
"generator": "Visual Studio 17 2022 Win64",
|
||||||
|
"configurationType": "RelWithDebInfo",
|
||||||
|
"buildRoot": "C:/Users/Dynamitos/Seele/bin/",
|
||||||
|
"installRoot": "C:/Program Files/Seele",
|
||||||
|
"cmakeCommandArgs": "-DCMAKE_DEBUG_POSTFIX=\"\" -DCMAKE_PLATFORM=x64",
|
||||||
|
"buildCommandArgs": "",
|
||||||
|
"ctestCommandArgs": "",
|
||||||
|
"inheritEnvironments": [ "msvc_x64" ],
|
||||||
|
"intelliSenseMode": "windows-msvc-x64",
|
||||||
|
"variables": []
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -19,6 +19,7 @@ float4 fragmentMain(in FragmentParameter params) : SV_Target
|
|||||||
{
|
{
|
||||||
MaterialParameter materialParams = params.getMaterialParameter();
|
MaterialParameter materialParams = params.getMaterialParameter();
|
||||||
LightingParameter lightingParams = params.getLightingParameter();
|
LightingParameter lightingParams = params.getLightingParameter();
|
||||||
|
|
||||||
let brdf = pMaterial.prepare(materialParams);
|
let brdf = pMaterial.prepare(materialParams);
|
||||||
float3 result = float3(0, 0, 0);
|
float3 result = float3(0, 0, 0);
|
||||||
for(int i = 0; i < pLightEnv.numDirectionalLights; ++i)
|
for(int i = 0; i < pLightEnv.numDirectionalLights; ++i)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import Common;
|
|||||||
|
|
||||||
interface IBRDF
|
interface IBRDF
|
||||||
{
|
{
|
||||||
float3 evaluate(float3 viewDir_TS, float3 lightDir_TS, float3 lightColor);
|
float3 evaluate(float3x3 tbn, float3 viewDir_WS, float3 lightDir_WS, float3 lightColor);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct BlinnPhong : IBRDF
|
struct BlinnPhong : IBRDF
|
||||||
@@ -23,13 +23,14 @@ struct BlinnPhong : IBRDF
|
|||||||
sheen = 1;
|
sheen = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
float3 evaluate(float3 viewDir_TS, float3 lightDir_TS, float3 lightColor)
|
float3 evaluate(float3x3 tbn, float3 viewDir_WS, float3 lightDir_WS, float3 lightColor)
|
||||||
{
|
{
|
||||||
float nDotL = saturate(dot(normal, lightDir_TS));
|
float3 normal_WS = mul(tbn, normal);
|
||||||
float3 h = normalize(lightDir_TS + viewDir_TS);
|
float diffuse = max(dot(normal_WS, lightDir_WS), 0);
|
||||||
float nDotH = saturate(dot(normal, h));
|
float3 h = lightDir_WS + viewDir_WS;
|
||||||
|
float specular = dot(normal_WS, h);
|
||||||
|
|
||||||
return baseColor;
|
return lightDir_WS * 2 + float3(1, 1, 1);//baseColor * (diffuse + specular) * lightColor;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -48,7 +49,7 @@ struct DisneyBRDF : IBRDF
|
|||||||
float clearCoat = 0;
|
float clearCoat = 0;
|
||||||
float clearCoatGloss = 1;
|
float clearCoatGloss = 1;
|
||||||
|
|
||||||
float3 evaluate(float3 viewDir_TS, float3 lightDir_TS, float3 lightColor)
|
float3 evaluate(float3x3 tbn, float3 viewDir_TS, float3 lightDir_TS, float3 lightColor)
|
||||||
{
|
{
|
||||||
return baseColor;
|
return baseColor;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,8 +14,7 @@ struct DirectionalLight : ILightEnv
|
|||||||
|
|
||||||
float3 illuminate<B:IBRDF>(LightingParameter params, B brdf)
|
float3 illuminate<B:IBRDF>(LightingParameter params, B brdf)
|
||||||
{
|
{
|
||||||
float3 lightDir_TS = mul(params.tbn, normalize(direction.xyz));
|
return brdf.evaluate(params.tbn, params.viewDir_WS, -normalize(direction.xyz), color.xyz);
|
||||||
return brdf.evaluate(params.viewDir_TS, -lightDir_TS, color.xyz);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -26,11 +25,10 @@ struct PointLight : ILightEnv
|
|||||||
|
|
||||||
float3 illuminate<B:IBRDF>(LightingParameter params, B brdf)
|
float3 illuminate<B:IBRDF>(LightingParameter params, B brdf)
|
||||||
{
|
{
|
||||||
float3 position_TS = mul(params.tbn, position_WS.xyz);
|
float3 lightDir_WS = position_WS.xyz - params.position_WS;
|
||||||
float3 lightDir_TS = position_TS - params.position_TS;
|
float d = length(lightDir_WS);
|
||||||
float d = length(lightDir_TS);
|
|
||||||
float illuminance = max(1 - d / colorRange.w, 0);
|
float illuminance = max(1 - d / colorRange.w, 0);
|
||||||
return illuminance * brdf.evaluate(params.viewDir_TS, normalize(lightDir_TS), colorRange.xyz);
|
return brdf.evaluate(params.tbn, params.viewDir_WS, normalize(lightDir_WS), colorRange.xyz);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool insidePlane(Plane plane)
|
bool insidePlane(Plane plane)
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import Common;
|
|||||||
|
|
||||||
struct MaterialParameter
|
struct MaterialParameter
|
||||||
{
|
{
|
||||||
float3 position_TS;
|
|
||||||
float3 position_WS;
|
float3 position_WS;
|
||||||
float2 texCoords;
|
float2 texCoords;
|
||||||
float3 vertexColor;
|
float3 vertexColor;
|
||||||
@@ -11,18 +10,16 @@ struct MaterialParameter
|
|||||||
// data used by light environment
|
// data used by light environment
|
||||||
struct LightingParameter
|
struct LightingParameter
|
||||||
{
|
{
|
||||||
// world to tangent space
|
|
||||||
float3x3 tbn;
|
float3x3 tbn;
|
||||||
float3 position_TS;
|
float3 position_WS;
|
||||||
float3 viewDir_TS;
|
float3 viewDir_WS;
|
||||||
};
|
};
|
||||||
|
|
||||||
// data passed to fragment shader
|
// data passed to fragment shader
|
||||||
struct FragmentParameter
|
struct FragmentParameter
|
||||||
{
|
{
|
||||||
float4 position_CS : SV_Position;
|
float4 position_CS : SV_Position;
|
||||||
float3 position_TS : POSITION0;
|
float3 viewDir_WS : POSITION1;
|
||||||
float3 viewDir_TS : POSITION1;
|
|
||||||
float3 normal_WS : NORMAL0;
|
float3 normal_WS : NORMAL0;
|
||||||
float3 tangent_WS : TANGENT0;
|
float3 tangent_WS : TANGENT0;
|
||||||
float3 biTangent_WS : TANGENT1;
|
float3 biTangent_WS : TANGENT1;
|
||||||
@@ -32,7 +29,6 @@ struct FragmentParameter
|
|||||||
MaterialParameter getMaterialParameter()
|
MaterialParameter getMaterialParameter()
|
||||||
{
|
{
|
||||||
MaterialParameter result;
|
MaterialParameter result;
|
||||||
result.position_TS = position_TS;
|
|
||||||
result.position_WS = position_WS;
|
result.position_WS = position_WS;
|
||||||
result.texCoords = texCoords;
|
result.texCoords = texCoords;
|
||||||
result.vertexColor = vertexColor;
|
result.vertexColor = vertexColor;
|
||||||
@@ -41,9 +37,9 @@ struct FragmentParameter
|
|||||||
LightingParameter getLightingParameter()
|
LightingParameter getLightingParameter()
|
||||||
{
|
{
|
||||||
LightingParameter result;
|
LightingParameter result;
|
||||||
result.tbn = transpose(float3x3(normalize(tangent_WS), normalize(biTangent_WS), normalize(normal_WS)));
|
result.tbn = float3x3(normalize(tangent_WS), normalize(biTangent_WS), normalize(normal_WS));
|
||||||
result.position_TS = position_TS;
|
result.position_WS = position_WS;
|
||||||
result.viewDir_TS = viewDir_TS;
|
result.viewDir_WS = viewDir_WS;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -63,14 +59,11 @@ struct VertexAttributes
|
|||||||
float4 worldPos = mul(transformMatrix, modelPos);
|
float4 worldPos = mul(transformMatrix, modelPos);
|
||||||
float4 viewPos = mul(pViewParams.viewMatrix, worldPos);
|
float4 viewPos = mul(pViewParams.viewMatrix, worldPos);
|
||||||
float4 clipPos = mul(pViewParams.projectionMatrix, viewPos);
|
float4 clipPos = mul(pViewParams.projectionMatrix, viewPos);
|
||||||
float3 tangent_WS = mul(transformMatrix, float4(normalize(tangent_MS), 0)).xyz;
|
float3 tangent_WS = mul(float3x3(transformMatrix), normalize(tangent_MS));
|
||||||
float3 biTangent_WS = mul(transformMatrix, float4(normalize(biTangent_MS), 0)).xyz;
|
float3 biTangent_WS = mul(float3x3(transformMatrix), normalize(biTangent_MS));
|
||||||
float3 normal_WS = mul(transformMatrix, float4(normalize(normal_MS), 0)).xyz;
|
float3 normal_WS = mul(float3x3(transformMatrix), normalize(normal_MS));
|
||||||
// Transforms from world space into tangent space
|
|
||||||
float3x3 tbn = transpose(float3x3(tangent_WS, biTangent_WS, normal_WS));
|
|
||||||
FragmentParameter result;
|
FragmentParameter result;
|
||||||
result.position_TS = mul(tbn, worldPos.xyz);
|
result.viewDir_WS = pViewParams.cameraPos_WS.xyz - worldPos.xyz;
|
||||||
result.viewDir_TS = mul(tbn, pViewParams.cameraPos_WS.xyz - worldPos.xyz);
|
|
||||||
result.normal_WS = normal_WS;
|
result.normal_WS = normal_WS;
|
||||||
result.tangent_WS = tangent_WS;
|
result.tangent_WS = tangent_WS;
|
||||||
result.biTangent_WS = biTangent_WS;
|
result.biTangent_WS = biTangent_WS;
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ void MeshLoader::loadMaterials(const aiScene* scene, const std::string& baseName
|
|||||||
if(material->GetTexture(aiTextureType_NORMALS, 0, &texPath) == AI_SUCCESS)
|
if(material->GetTexture(aiTextureType_NORMALS, 0, &texPath) == AI_SUCCESS)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
std::string outMatFilename = matCode["name"].get<std::string>().append(".asset");
|
std::string outMatFilename = matCode["name"].get<std::string>().append(".json");
|
||||||
std::ofstream outMatFile = std::ofstream(meshDirectory / outMatFilename);
|
std::ofstream outMatFile = std::ofstream(meshDirectory / outMatFilename);
|
||||||
outMatFile << std::setw(4) << matCode;
|
outMatFile << std::setw(4) << matCode;
|
||||||
outMatFile.flush();
|
outMatFile.flush();
|
||||||
|
|||||||
+4
-4
@@ -217,14 +217,14 @@ int main()
|
|||||||
|
|
||||||
WindowCreateInfo mainWindowInfo;
|
WindowCreateInfo mainWindowInfo;
|
||||||
mainWindowInfo.title = "SeeleEngine";
|
mainWindowInfo.title = "SeeleEngine";
|
||||||
mainWindowInfo.width = 1280;
|
mainWindowInfo.width = 1920;
|
||||||
mainWindowInfo.height = 720;
|
mainWindowInfo.height = 1080;
|
||||||
mainWindowInfo.numSamples = 1;
|
mainWindowInfo.numSamples = 1;
|
||||||
mainWindowInfo.preferredFormat = Gfx::SE_FORMAT_B8G8R8A8_SRGB;
|
mainWindowInfo.preferredFormat = Gfx::SE_FORMAT_B8G8R8A8_SRGB;
|
||||||
auto window = windowManager->addWindow(graphics, mainWindowInfo);
|
auto window = windowManager->addWindow(graphics, mainWindowInfo);
|
||||||
ViewportCreateInfo sceneViewInfo;
|
ViewportCreateInfo sceneViewInfo;
|
||||||
sceneViewInfo.dimensions.size.x = 1280;
|
sceneViewInfo.dimensions.size.x = 1920;
|
||||||
sceneViewInfo.dimensions.size.y = 720;
|
sceneViewInfo.dimensions.size.y = 1080;
|
||||||
sceneViewInfo.dimensions.offset.x = 0;
|
sceneViewInfo.dimensions.offset.x = 0;
|
||||||
sceneViewInfo.dimensions.offset.y = 0;
|
sceneViewInfo.dimensions.offset.y = 0;
|
||||||
OGameView sceneView = new Editor::PlayView(graphics, window, sceneViewInfo, binaryPath.generic_string());
|
OGameView sceneView = new Editor::PlayView(graphics, window, sceneViewInfo, binaryPath.generic_string());
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ CameraActor::CameraActor(PScene scene)
|
|||||||
: Actor(scene)
|
: Actor(scene)
|
||||||
{
|
{
|
||||||
attachComponent<Component::Camera>();
|
attachComponent<Component::Camera>();
|
||||||
accessComponent<Component::Transform>().setRelativeLocation(Vector(10, 5, 14));
|
accessComponent<Component::Transform>().setPosition(Vector(10, 5, 14));
|
||||||
}
|
}
|
||||||
|
|
||||||
CameraActor::~CameraActor()
|
CameraActor::~CameraActor()
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ Camera::Camera()
|
|||||||
: viewMatrix(Matrix4())
|
: viewMatrix(Matrix4())
|
||||||
, bNeedsViewBuild(false)
|
, bNeedsViewBuild(false)
|
||||||
{
|
{
|
||||||
yaw = 0;
|
yaw = 3.1415f/2;
|
||||||
pitch = 0.2;
|
pitch = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Camera::~Camera()
|
Camera::~Camera()
|
||||||
@@ -21,40 +21,37 @@ Camera::~Camera()
|
|||||||
|
|
||||||
void Camera::mouseMove(float deltaYaw, float deltaPitch)
|
void Camera::mouseMove(float deltaYaw, float deltaPitch)
|
||||||
{
|
{
|
||||||
yaw -= deltaYaw / 500.f;
|
yaw += deltaYaw / 500.f;
|
||||||
pitch += deltaPitch / 500.f;
|
pitch += deltaPitch / 500.f;
|
||||||
//std::cout << "Yaw: " << yaw << " Pitch: " << pitch << std::endl;
|
|
||||||
Vector cameraDirection = glm::normalize(Vector(cos(yaw) * cos(pitch), sin(pitch), sin(yaw) * cos(pitch)));
|
Vector cameraDirection = glm::normalize(Vector(cos(yaw) * cos(pitch), sin(pitch), sin(yaw) * cos(pitch)));
|
||||||
Vector xyz = glm::cross(cameraDirection, Vector(0, 0, 1));
|
Matrix4 viewMat = glm::lookAt(getTransform().getPosition(), getTransform().getPosition() + cameraDirection, Vector(0, 1, 0));
|
||||||
Quaternion result = Quaternion(glm::dot(cameraDirection, Vector(0, 0, 1)) + 1, xyz.x, xyz.y, xyz.z);
|
getTransform().setRotation(viewMat); // quaternion from matrix, janky but im bad at math
|
||||||
//std::cout << "Result " << Vector(0, 0, 1) * glm::normalize(result) << " cameraDirection: " << cameraDirection << std::endl;
|
|
||||||
getTransform().setRelativeRotation(result);
|
|
||||||
bNeedsViewBuild = true;
|
bNeedsViewBuild = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Camera::mouseScroll(float x)
|
void Camera::mouseScroll(float x)
|
||||||
{
|
{
|
||||||
getTransform().addRelativeLocation(getTransform().getForward()*x);
|
getTransform().translate(getTransform().getForward()*x);
|
||||||
bNeedsViewBuild = true;
|
bNeedsViewBuild = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Camera::moveX(float amount)
|
void Camera::moveX(float amount)
|
||||||
{
|
{
|
||||||
getTransform().addRelativeLocation(getTransform().getForward()*amount);
|
getTransform().translate(getTransform().getForward()*amount);
|
||||||
bNeedsViewBuild = true;
|
bNeedsViewBuild = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Camera::moveY(float amount)
|
void Camera::moveY(float amount)
|
||||||
{
|
{
|
||||||
getTransform().addRelativeLocation(getTransform().getRight()*amount);
|
getTransform().translate(getTransform().getRight()*amount);
|
||||||
bNeedsViewBuild = true;
|
bNeedsViewBuild = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Camera::buildViewMatrix()
|
void Camera::buildViewMatrix()
|
||||||
{
|
{
|
||||||
Vector eyePos = getTransform().getPosition();//getAbsoluteTransform().getPosition();
|
Vector eyePos = getTransform().getPosition();
|
||||||
Vector lookAt = eyePos + glm::normalize(Vector(cos(yaw) * cos(pitch), sin(pitch), sin(yaw) * cos(pitch)));
|
Vector lookAt = eyePos + getTransform().getForward();
|
||||||
viewMatrix = glm::lookAt(eyePos, lookAt, Vector(0, 1, 0));
|
viewMatrix = glm::lookAt(eyePos, lookAt, Vector(0, 1, 0));
|
||||||
|
cameraPos = eyePos;
|
||||||
bNeedsViewBuild = false;
|
bNeedsViewBuild = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ struct Camera
|
|||||||
}
|
}
|
||||||
Vector getCameraPosition() const
|
Vector getCameraPosition() const
|
||||||
{
|
{
|
||||||
return Vector(viewMatrix[3]);
|
return cameraPos;
|
||||||
}
|
}
|
||||||
void mouseMove(float deltaX, float deltaY);
|
void mouseMove(float deltaX, float deltaY);
|
||||||
void mouseScroll(float x);
|
void mouseScroll(float x);
|
||||||
@@ -29,6 +29,8 @@ struct Camera
|
|||||||
void moveY(float amount);
|
void moveY(float amount);
|
||||||
void buildViewMatrix();
|
void buildViewMatrix();
|
||||||
Matrix4 viewMatrix;
|
Matrix4 viewMatrix;
|
||||||
|
Vector cameraPos;
|
||||||
|
Vector cameraDirection;
|
||||||
//Transforms relative to actor
|
//Transforms relative to actor
|
||||||
float yaw;
|
float yaw;
|
||||||
float pitch;
|
float pitch;
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ using namespace Seele::Component;
|
|||||||
|
|
||||||
DEFINE_COMPONENT(Transform)
|
DEFINE_COMPONENT(Transform)
|
||||||
|
|
||||||
|
|
||||||
void Transform::setPosition(Vector pos)
|
void Transform::setPosition(Vector pos)
|
||||||
{
|
{
|
||||||
transform.setPosition(pos);
|
transform.setPosition(pos);
|
||||||
@@ -19,32 +18,15 @@ void Transform::setScale(Vector scale)
|
|||||||
{
|
{
|
||||||
transform.setScale(scale);
|
transform.setScale(scale);
|
||||||
}
|
}
|
||||||
|
void Transform::translate(Vector direction)
|
||||||
void Transform::setRelativeLocation(Vector location)
|
|
||||||
{
|
{
|
||||||
transform = Math::Transform(location, transform.getRotation(), transform.getScale());
|
transform.setPosition(transform.getPosition() + direction);
|
||||||
}
|
}
|
||||||
void Transform::setRelativeRotation(Vector rotation)
|
void Transform::rotate(Quaternion quat)
|
||||||
{
|
{
|
||||||
transform = Math::Transform(transform.getPosition(), Quaternion(rotation), transform.getScale());
|
transform.setRotation(transform.getRotation() * quat);
|
||||||
}
|
}
|
||||||
void Transform::setRelativeRotation(Quaternion rotation)
|
void Transform::scale(Vector scale)
|
||||||
{
|
{
|
||||||
transform = Math::Transform(transform.getPosition(), rotation, transform.getScale());
|
transform.setScale(transform.getScale() + scale);
|
||||||
}
|
|
||||||
void Transform::setRelativeScale(Vector scale)
|
|
||||||
{
|
|
||||||
transform = Math::Transform(transform.getPosition(), transform.getRotation(), scale);
|
|
||||||
}
|
|
||||||
void Transform::addRelativeLocation(Vector translation)
|
|
||||||
{
|
|
||||||
transform = Math::Transform(transform.getPosition() + translation, transform.getRotation(), transform.getScale());
|
|
||||||
}
|
|
||||||
void Transform::addRelativeRotation(Vector rotation)
|
|
||||||
{
|
|
||||||
transform = Math::Transform(transform.getPosition(), transform.getRotation() * Quaternion(rotation), transform.getScale());
|
|
||||||
}
|
|
||||||
void Transform::addRelativeRotation(Quaternion rotation)
|
|
||||||
{
|
|
||||||
transform = Math::Transform(transform.getPosition(), transform.getRotation() * rotation, transform.getScale());
|
|
||||||
}
|
}
|
||||||
@@ -21,15 +21,9 @@ struct Transform
|
|||||||
void setPosition(Vector pos);
|
void setPosition(Vector pos);
|
||||||
void setRotation(Quaternion quat);
|
void setRotation(Quaternion quat);
|
||||||
void setScale(Vector scale);
|
void setScale(Vector scale);
|
||||||
|
void translate(Vector direction);
|
||||||
void setRelativeLocation(Vector location);
|
void rotate(Quaternion quat);
|
||||||
void setRelativeRotation(Quaternion rotation);
|
void scale(Vector scale);
|
||||||
void setRelativeRotation(Vector rotation);
|
|
||||||
void setRelativeScale(Vector scale);
|
|
||||||
|
|
||||||
void addRelativeLocation(Vector translation);
|
|
||||||
void addRelativeRotation(Quaternion rotation);
|
|
||||||
void addRelativeRotation(Vector rotation);
|
|
||||||
private:
|
private:
|
||||||
Math::Transform transform;
|
Math::Transform transform;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -165,8 +165,9 @@ void BasePass::render()
|
|||||||
{
|
{
|
||||||
if (meshData.numIndices > 0)
|
if (meshData.numIndices > 0)
|
||||||
{
|
{
|
||||||
command->drawIndexed(meshData.numIndices, 1, meshData.firstIndex, meshData.indicesOffset, instanceOffset++);
|
command->drawIndexed(meshData.numIndices, 1, meshData.firstIndex, meshData.indicesOffset, instanceOffset);
|
||||||
}
|
}
|
||||||
|
instanceOffset++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
using namespace Seele;
|
using namespace Seele;
|
||||||
|
|
||||||
constexpr static uint64 NUM_DEFAULT_ELEMENTS = 16 * 1024;
|
constexpr static uint64 NUM_DEFAULT_ELEMENTS = 1024 * 1024;
|
||||||
|
|
||||||
void VertexData::resetMeshData()
|
void VertexData::resetMeshData()
|
||||||
{
|
{
|
||||||
@@ -166,7 +166,7 @@ MeshId VertexData::allocateVertexData(uint64 numVertices)
|
|||||||
head += numVertices;
|
head += numVertices;
|
||||||
if (head > verticesAllocated)
|
if (head > verticesAllocated)
|
||||||
{
|
{
|
||||||
verticesAllocated = head;
|
verticesAllocated = std::max(head, verticesAllocated + NUM_DEFAULT_ELEMENTS);
|
||||||
resizeBuffers();
|
resizeBuffers();
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
|
|||||||
@@ -62,12 +62,10 @@ void DescriptorLayout::create()
|
|||||||
|
|
||||||
PipelineLayout::~PipelineLayout()
|
PipelineLayout::~PipelineLayout()
|
||||||
{
|
{
|
||||||
if (layoutHandle != VK_NULL_HANDLE)
|
|
||||||
{
|
|
||||||
vkDestroyPipelineLayout(graphics->getDevice(), layoutHandle, nullptr);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Map<uint32, VkPipelineLayout> cachedLayouts;
|
||||||
|
|
||||||
void PipelineLayout::create()
|
void PipelineLayout::create()
|
||||||
{
|
{
|
||||||
vulkanDescriptorLayouts.resize(descriptorSetLayouts.size());
|
vulkanDescriptorLayouts.resize(descriptorSetLayouts.size());
|
||||||
@@ -105,7 +103,14 @@ void PipelineLayout::create()
|
|||||||
layoutHash = CRC::Calculate(createInfo.pPushConstantRanges, sizeof(VkPushConstantRange) * createInfo.pushConstantRangeCount, CRC::CRC_32());
|
layoutHash = CRC::Calculate(createInfo.pPushConstantRanges, sizeof(VkPushConstantRange) * createInfo.pushConstantRangeCount, CRC::CRC_32());
|
||||||
layoutHash = CRC::Calculate(createInfo.pSetLayouts, sizeof(VkDescriptorSetLayout) * createInfo.setLayoutCount, CRC::CRC_32(), layoutHash);
|
layoutHash = CRC::Calculate(createInfo.pSetLayouts, sizeof(VkDescriptorSetLayout) * createInfo.setLayoutCount, CRC::CRC_32(), layoutHash);
|
||||||
|
|
||||||
|
if (cachedLayouts.contains(layoutHash))
|
||||||
|
{
|
||||||
|
layoutHandle = cachedLayouts[layoutHash];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
VK_CHECK(vkCreatePipelineLayout(graphics->getDevice(), &createInfo, nullptr, &layoutHandle));
|
VK_CHECK(vkCreatePipelineLayout(graphics->getDevice(), &createInfo, nullptr, &layoutHandle));
|
||||||
|
cachedLayouts[layoutHash] = layoutHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PipelineLayout::reset()
|
void PipelineLayout::reset()
|
||||||
@@ -391,7 +396,6 @@ Gfx::PDescriptorSet DescriptorPool::allocateDescriptorSet()
|
|||||||
{
|
{
|
||||||
//If it hasnt been initialized, allocate it
|
//If it hasnt been initialized, allocate it
|
||||||
VK_CHECK(vkAllocateDescriptorSets(graphics->getDevice(), &allocInfo, &cachedHandles[setIndex]->setHandle));
|
VK_CHECK(vkAllocateDescriptorSets(graphics->getDevice(), &allocInfo, &cachedHandles[setIndex]->setHandle));
|
||||||
std::cout << "New descriptor " << cachedHandles[setIndex]->setHandle << std::endl;
|
|
||||||
}
|
}
|
||||||
cachedHandles[setIndex]->allocate();
|
cachedHandles[setIndex]->allocate();
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "Transform.h"
|
#include "Transform.h"
|
||||||
#include <glm/gtx/quaternion.hpp>
|
#include <glm/gtx/quaternion.hpp>
|
||||||
|
#include "Transform.h"
|
||||||
|
|
||||||
using namespace Seele;
|
using namespace Seele;
|
||||||
using namespace Seele::Math;
|
using namespace Seele::Math;
|
||||||
|
|||||||
@@ -60,10 +60,6 @@ void LightEnvironment::addPointLight(Component::PointLight pointLight)
|
|||||||
|
|
||||||
void LightEnvironment::commit()
|
void LightEnvironment::commit()
|
||||||
{
|
{
|
||||||
dirs.add(Component::DirectionalLight{
|
|
||||||
.color = Vector4(1, 1, 1, 1),
|
|
||||||
.direction = Vector4(1, 0, 1, 0),
|
|
||||||
});
|
|
||||||
lightEnv.numDirectionalLights = dirs.size();
|
lightEnv.numDirectionalLights = dirs.size();
|
||||||
lightEnv.numPointLights = points.size();
|
lightEnv.numPointLights = points.size();
|
||||||
lightEnvBuffer->updateContents(DataSource{
|
lightEnvBuffer->updateContents(DataSource{
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ Scene::~Scene()
|
|||||||
|
|
||||||
void Scene::update(float deltaTime)
|
void Scene::update(float deltaTime)
|
||||||
{
|
{
|
||||||
lightEnv->reset();
|
|
||||||
physics.update(deltaTime);
|
physics.update(deltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,10 @@ void KeyboardInput::update(Component::KeyboardInput& input)
|
|||||||
input.mouseY = mouseY;
|
input.mouseY = mouseY;
|
||||||
input.mouse1 = mouse1;
|
input.mouse1 = mouse1;
|
||||||
input.mouse2 = mouse2;
|
input.mouse2 = mouse2;
|
||||||
|
deltaX = mouseX - lastMouseX;
|
||||||
|
deltaY = mouseY - lastMouseY;
|
||||||
|
lastMouseX = mouseX;
|
||||||
|
lastMouseY = mouseY;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeyboardInput::keyCallback(KeyCode code, InputAction action, KeyModifier modifier)
|
void KeyboardInput::keyCallback(KeyCode code, InputAction action, KeyModifier modifier)
|
||||||
@@ -33,10 +37,6 @@ void KeyboardInput::mouseCallback(double x, double y)
|
|||||||
{
|
{
|
||||||
mouseX = x;
|
mouseX = x;
|
||||||
mouseY = y;
|
mouseY = y;
|
||||||
deltaX = x - lastMouseX;
|
|
||||||
deltaY = y - lastMouseY;
|
|
||||||
lastMouseX = x;
|
|
||||||
lastMouseY = y;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeyboardInput::mouseButtonCallback(MouseButton button, InputAction action, KeyModifier modifier)
|
void KeyboardInput::mouseButtonCallback(MouseButton button, InputAction action, KeyModifier modifier)
|
||||||
|
|||||||
@@ -15,4 +15,11 @@ LightGather::~LightGather()
|
|||||||
|
|
||||||
void LightGather::update()
|
void LightGather::update()
|
||||||
{
|
{
|
||||||
|
lightEnv->reset();
|
||||||
|
scene->view<Component::PointLight>([this](Component::PointLight& pointLight) {
|
||||||
|
lightEnv->addPointLight(pointLight);
|
||||||
|
});
|
||||||
|
scene->view<Component::DirectionalLight>([this](Component::DirectionalLight& dirLight) {
|
||||||
|
lightEnv->addDirectionalLight(dirLight);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user