Fixes
This commit is contained in:
@ -17,6 +17,7 @@
|
|||||||
#include <IAEngine/Components/SpriteRenderer.hpp>
|
#include <IAEngine/Components/SpriteRenderer.hpp>
|
||||||
|
|
||||||
#include <IAEngine/Nodes/Node.hpp>
|
#include <IAEngine/Nodes/Node.hpp>
|
||||||
|
#include <IAEngine/Rendering/Renderer.hpp>
|
||||||
|
|
||||||
#include <IAEngine/Time.hpp>
|
#include <IAEngine/Time.hpp>
|
||||||
|
|
||||||
@ -60,6 +61,7 @@ namespace ia::iae
|
|||||||
|
|
||||||
VOID SpriteRendererComponent::Draw()
|
VOID SpriteRendererComponent::Draw()
|
||||||
{
|
{
|
||||||
|
Renderer::SetParallaxFactor(m_parallaxFactor);
|
||||||
const auto &animFrame = m_currentAnimationState;
|
const auto &animFrame = m_currentAnimationState;
|
||||||
animFrame.Texture.Draw(m_node->SortOffset() + m_sortOffset, m_node->GetPosition() + animFrame.Position,
|
animFrame.Texture.Draw(m_node->SortOffset() + m_sortOffset, m_node->GetPosition() + animFrame.Position,
|
||||||
m_node->GetScale() * animFrame.Scale, m_node->GetRotation().z + animFrame.Rotation.z,
|
m_node->GetScale() * animFrame.Scale, m_node->GetRotation().z + animFrame.Rotation.z,
|
||||||
|
|||||||
@ -31,9 +31,9 @@ namespace ia::iae
|
|||||||
SDL_GPUSamplerCreateInfo createInfo{.min_filter = SDL_GPU_FILTER_LINEAR,
|
SDL_GPUSamplerCreateInfo createInfo{.min_filter = SDL_GPU_FILTER_LINEAR,
|
||||||
.mag_filter = SDL_GPU_FILTER_LINEAR,
|
.mag_filter = SDL_GPU_FILTER_LINEAR,
|
||||||
.mipmap_mode = SDL_GPU_SAMPLERMIPMAPMODE_LINEAR,
|
.mipmap_mode = SDL_GPU_SAMPLERMIPMAPMODE_LINEAR,
|
||||||
.address_mode_u = SDL_GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE,
|
.address_mode_u = SDL_GPU_SAMPLERADDRESSMODE_REPEAT,
|
||||||
.address_mode_v = SDL_GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE,
|
.address_mode_v = SDL_GPU_SAMPLERADDRESSMODE_REPEAT,
|
||||||
.address_mode_w = SDL_GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE,
|
.address_mode_w = SDL_GPU_SAMPLERADDRESSMODE_REPEAT,
|
||||||
.max_anisotropy = 1.0f,
|
.max_anisotropy = 1.0f,
|
||||||
.enable_anisotropy = true};
|
.enable_anisotropy = true};
|
||||||
g_defaultSampler = SDL_CreateGPUSampler(g_gpuDevice, &createInfo);
|
g_defaultSampler = SDL_CreateGPUSampler(g_gpuDevice, &createInfo);
|
||||||
|
|||||||
@ -38,7 +38,7 @@ namespace ia::iae
|
|||||||
const auto vertexShader = LoadShaderFromMemory(ShaderStage::VERTEX, SHADER_SOURCE_UNLITMESH_VERT,
|
const auto vertexShader = LoadShaderFromMemory(ShaderStage::VERTEX, SHADER_SOURCE_UNLITMESH_VERT,
|
||||||
sizeof(SHADER_SOURCE_UNLITMESH_VERT), 0, 3, 0, 0);
|
sizeof(SHADER_SOURCE_UNLITMESH_VERT), 0, 3, 0, 0);
|
||||||
const auto pixelShader = LoadShaderFromMemory(ShaderStage::PIXEL, SHADER_SOURCE_UNLITMESH_FRAG,
|
const auto pixelShader = LoadShaderFromMemory(ShaderStage::PIXEL, SHADER_SOURCE_UNLITMESH_FRAG,
|
||||||
sizeof(SHADER_SOURCE_UNLITMESH_FRAG), 1, 1, 0, 0);
|
sizeof(SHADER_SOURCE_UNLITMESH_FRAG), 1, 2, 0, 0);
|
||||||
|
|
||||||
SDL_GPUColorTargetDescription colorTargets[] = {{
|
SDL_GPUColorTargetDescription colorTargets[] = {{
|
||||||
.format = SDL_GetGPUSwapchainTextureFormat(g_gpuDevice, g_windowHandle),
|
.format = SDL_GetGPUSwapchainTextureFormat(g_gpuDevice, g_windowHandle),
|
||||||
|
|||||||
@ -55,6 +55,8 @@ namespace ia::iae
|
|||||||
glm::mat4 matView{1.0f};
|
glm::mat4 matView{1.0f};
|
||||||
glm::mat4 matModel{1.0f};
|
glm::mat4 matModel{1.0f};
|
||||||
|
|
||||||
|
FLOAT32 g_parallaxFactor{0.0f};
|
||||||
|
|
||||||
BOOL Renderer::Initialize()
|
BOOL Renderer::Initialize()
|
||||||
{
|
{
|
||||||
SDL_GetWindowSizeInPixels(g_windowHandle, &s_width, &s_height);
|
SDL_GetWindowSizeInPixels(g_windowHandle, &s_width, &s_height);
|
||||||
@ -100,8 +102,7 @@ namespace ia::iae
|
|||||||
{
|
{
|
||||||
SDL_GPUTextureCreateInfo createInfo{.type = SDL_GPU_TEXTURETYPE_2D,
|
SDL_GPUTextureCreateInfo createInfo{.type = SDL_GPU_TEXTURETYPE_2D,
|
||||||
.format = SDL_GPU_TEXTUREFORMAT_D16_UNORM,
|
.format = SDL_GPU_TEXTUREFORMAT_D16_UNORM,
|
||||||
.usage =
|
.usage = SDL_GPU_TEXTUREUSAGE_DEPTH_STENCIL_TARGET,
|
||||||
SDL_GPU_TEXTUREUSAGE_DEPTH_STENCIL_TARGET,
|
|
||||||
.width = (UINT32) s_width,
|
.width = (UINT32) s_width,
|
||||||
.height = (UINT32) s_height,
|
.height = (UINT32) s_height,
|
||||||
.layer_count_or_depth = 1,
|
.layer_count_or_depth = 1,
|
||||||
@ -234,17 +235,26 @@ namespace ia::iae
|
|||||||
SDL_PushGPUFragmentUniformData(g_cmdBuffer, 0, &textureState, sizeof(textureState));
|
SDL_PushGPUFragmentUniformData(g_cmdBuffer, 0, &textureState, sizeof(textureState));
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID SetModelTransformMatrix(IN FLOAT32 sortOffset, IN CONST glm::vec3 &position, IN CONST glm::vec3 &scale, IN FLOAT32 rotation)
|
VOID SetModelTransformMatrix(IN FLOAT32 sortOffset, IN CONST glm::vec3 &position, IN CONST glm::vec3 &scale,
|
||||||
|
IN FLOAT32 rotation)
|
||||||
{
|
{
|
||||||
|
if (g_parallaxFactor <= 0.0f)
|
||||||
|
matView = g_camera.GetViewMatrix();
|
||||||
|
else
|
||||||
|
matView = glm::mat4(1.0f);
|
||||||
|
SDL_PushGPUVertexUniformData(g_cmdBuffer, 1, &matView, sizeof(matView));
|
||||||
|
g_parallaxFactor *= g_camera.Position().x/640.0f;
|
||||||
|
SDL_PushGPUFragmentUniformData(g_cmdBuffer, 1, &g_parallaxFactor, sizeof(g_parallaxFactor));
|
||||||
|
|
||||||
const auto depthTestOffset = sortOffset + (Engine::GetActiveScene()->YSortingEnabled() ? position.y : 0);
|
const auto depthTestOffset = sortOffset + (Engine::GetActiveScene()->YSortingEnabled() ? position.y : 0);
|
||||||
matModel = glm::translate(glm::mat4(1.0f), {position.x, position.y, position.z + depthTestOffset});
|
matModel = glm::translate(glm::mat4(1.0f), {position.x, position.y, position.z + depthTestOffset + (g_parallaxFactor < 0.0f ? 0.0f : -100.0f)});
|
||||||
matModel = glm::rotate(matModel, rotation, glm::vec3(0.0f, 0.0f, 1.0f));
|
matModel = glm::rotate(matModel, rotation, glm::vec3(0.0f, 0.0f, 1.0f));
|
||||||
matModel = glm::scale(matModel, scale);
|
matModel = glm::scale(matModel, scale);
|
||||||
SDL_PushGPUVertexUniformData(g_cmdBuffer, 2, &matModel, sizeof(matModel));
|
SDL_PushGPUVertexUniformData(g_cmdBuffer, 2, &matModel, sizeof(matModel));
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID Renderer::Draw(IN FLOAT32 sortOffset, IN CONST glm::vec3 &position, IN CONST glm::vec3 &scale, IN FLOAT32 rotation,
|
VOID Renderer::Draw(IN FLOAT32 sortOffset, IN CONST glm::vec3 &position, IN CONST glm::vec3 &scale,
|
||||||
IN Handle vertexBufferHandle, IN INT32 vertexCount)
|
IN FLOAT32 rotation, IN Handle vertexBufferHandle, IN INT32 vertexCount)
|
||||||
{
|
{
|
||||||
SetModelTransformMatrix(sortOffset, position, scale, rotation);
|
SetModelTransformMatrix(sortOffset, position, scale, rotation);
|
||||||
SDL_GPUBufferBinding bindings[] = {{.buffer = (SDL_GPUBuffer *) vertexBufferHandle, .offset = 0}};
|
SDL_GPUBufferBinding bindings[] = {{.buffer = (SDL_GPUBuffer *) vertexBufferHandle, .offset = 0}};
|
||||||
@ -252,8 +262,9 @@ namespace ia::iae
|
|||||||
SDL_DrawGPUPrimitives(g_renderPass, vertexCount, 1, 0, 0);
|
SDL_DrawGPUPrimitives(g_renderPass, vertexCount, 1, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID Renderer::Draw(IN FLOAT32 sortOffset, IN CONST glm::vec3 &position, IN CONST glm::vec3 &scale, IN FLOAT32 rotation,
|
VOID Renderer::Draw(IN FLOAT32 sortOffset, IN CONST glm::vec3 &position, IN CONST glm::vec3 &scale,
|
||||||
IN Handle vertexBufferHandle, IN Handle indexBufferHandle, IN INT32 indexCount)
|
IN FLOAT32 rotation, IN Handle vertexBufferHandle, IN Handle indexBufferHandle,
|
||||||
|
IN INT32 indexCount)
|
||||||
{
|
{
|
||||||
SetModelTransformMatrix(sortOffset, position, scale, rotation);
|
SetModelTransformMatrix(sortOffset, position, scale, rotation);
|
||||||
SDL_GPUBufferBinding bindings[] = {{.buffer = (SDL_GPUBuffer *) vertexBufferHandle, .offset = 0},
|
SDL_GPUBufferBinding bindings[] = {{.buffer = (SDL_GPUBuffer *) vertexBufferHandle, .offset = 0},
|
||||||
@ -267,4 +278,9 @@ namespace ia::iae
|
|||||||
{
|
{
|
||||||
return &g_camera;
|
return &g_camera;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VOID Renderer::SetParallaxFactor(IN FLOAT32 value)
|
||||||
|
{
|
||||||
|
g_parallaxFactor = value;
|
||||||
|
}
|
||||||
} // namespace ia::iae
|
} // namespace ia::iae
|
||||||
|
|||||||
@ -11,10 +11,14 @@ layout(set = 3, binding = 0) uniform UniformBufferObject {
|
|||||||
bool flipV;
|
bool flipV;
|
||||||
bool flipH;
|
bool flipH;
|
||||||
} ubo;
|
} ubo;
|
||||||
|
layout(set = 3, binding = 1) uniform UniformBufferObject2 {
|
||||||
|
float parallaxFactor;
|
||||||
|
} ubo2;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec2 uv = inTexCoord;
|
vec2 uv = inTexCoord;
|
||||||
|
uv.x += ubo2.parallaxFactor;
|
||||||
if(ubo.flipH) uv.x = 1 - uv.x;
|
if(ubo.flipH) uv.x = 1 - uv.x;
|
||||||
if(ubo.flipV) uv.y = 1 - uv.y;
|
if(ubo.flipV) uv.y = 1 - uv.y;
|
||||||
outColor = texture(texSampler, uv) * ubo.colorOverlay;
|
outColor = texture(texSampler, uv) * ubo.colorOverlay;
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -76,6 +76,11 @@ namespace ia::iae
|
|||||||
return m_sortOffset;
|
return m_sortOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FLOAT32& ParallaxFactor()
|
||||||
|
{
|
||||||
|
return m_parallaxFactor;
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
VOID Draw();
|
VOID Draw();
|
||||||
VOID Update();
|
VOID Update();
|
||||||
@ -84,6 +89,7 @@ namespace ia::iae
|
|||||||
VOID UpdateAnimation();
|
VOID UpdateAnimation();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
FLOAT32 m_parallaxFactor{0.0f};
|
||||||
FLOAT32 m_sortOffset{};
|
FLOAT32 m_sortOffset{};
|
||||||
BOOL m_isFlippedV{false};
|
BOOL m_isFlippedV{false};
|
||||||
BOOL m_isFlippedH{false};
|
BOOL m_isFlippedH{false};
|
||||||
|
|||||||
@ -51,6 +51,8 @@ namespace ia::iae
|
|||||||
|
|
||||||
STATIC Camera2D* GetCamera();
|
STATIC Camera2D* GetCamera();
|
||||||
|
|
||||||
|
STATIC VOID SetParallaxFactor(IN FLOAT32 value);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
STATIC INT32 Width()
|
STATIC INT32 Width()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user