添加鼠标点击实体事件,添加spirv着色器系统

This commit is contained in:
2025-06-09 13:19:14 +08:00
parent de75ee9481
commit f4aa895bbb
24 changed files with 664 additions and 54 deletions

View File

@ -17,7 +17,9 @@ set(PROJECT_NAME "${PROJECT_NAME}-Editor")
project(${PROJECT_NAME})
file(GLOB_RECURSE SOURCES
src/SandboxApp.cpp
src/Editor/**.cpp)
src/Editor/**.cpp
src/logo/logo.rc
)
add_executable(${PROJECT_NAME} ${SOURCES})

View File

@ -6,12 +6,13 @@
layout(location = 0) in vec3 a_Position;
layout(location = 1) in vec2 a_TexCoord;
uniform mat4 u_ViewProjection;
uniform mat4 u_Transform;
layout(std140, binding = 0) uniform Camera
{
mat4 u_ViewProjection;
};
void main() {
gl_Position = u_ViewProjection * u_Transform * vec4(a_Position, 1.0f);
gl_Position = u_ViewProjection * vec4(a_Position, 1.0f);
}
#type fragment
@ -19,8 +20,7 @@ void main() {
layout(location = 0) out vec4 color;
uniform vec4 u_Color;
void main() {
color = u_Color;
color = vec4(1.0f, 0.0f, 0.0f, 1.0f);
}

View File

@ -1,5 +1,7 @@
// Basic Texture Shader
#type vertex
#version 460 core
#version 450 core
layout(location = 0) in vec3 a_Position;
layout(location = 1) in vec4 a_Color;
@ -8,43 +10,55 @@ layout(location = 3) in float a_TexIndex;
layout(location = 4) in float a_TilingFactor;
layout(location = 5) in int a_EntityID;
uniform mat4 u_ViewProjection;
//uniform mat4 u_Transform;
layout(std140, binding = 0) uniform Camera
{
mat4 u_ViewProjection;
};
out vec2 v_TexCoord;
out vec4 v_Color;
out flat float v_TexIndex;
out float v_TilingFactor;
out flat int v_EntityID;
struct VertexOutput
{
vec4 Color;
vec2 TexCoord;
float TilingFactor;
};
void main() {
v_TexCoord = a_TexCoord;
v_Color = a_Color;
layout (location = 0) out VertexOutput Output;
layout (location = 3) out flat float v_TexIndex;
layout (location = 4) out flat int v_EntityID;
void main()
{
Output.Color = a_Color;
Output.TexCoord = a_TexCoord;
Output.TilingFactor = a_TilingFactor;
v_TexIndex = a_TexIndex;
v_TilingFactor = a_TilingFactor;
v_EntityID = a_EntityID;
gl_Position = u_ViewProjection * vec4(a_Position, 1.0f);
gl_Position = u_ViewProjection * vec4(a_Position, 1.0);
}
#type fragment
#version 460 core
#version 450 core
layout(location = 0) out vec4 color;
layout(location = 1) out int color2;
layout(location = 0) out vec4 o_Color;
layout(location = 1) out int o_EntityID;
in vec2 v_TexCoord;
in vec4 v_Color;
in flat float v_TexIndex;
in float v_TilingFactor;
in flat int v_EntityID;
struct VertexOutput
{
vec4 Color;
vec2 TexCoord;
float TilingFactor;
};
uniform vec4 u_Color;
uniform sampler2D u_Textures[32];
layout (location = 0) in VertexOutput Input;
layout (location = 3) in flat float v_TexIndex;
layout (location = 4) in flat int v_EntityID;
void main() {
layout (binding = 0) uniform sampler2D u_Textures[32];
color = texture(u_Textures[int(v_TexIndex)], v_TexCoord * v_TilingFactor) * v_Color;
// color = v_Color;
color2 = v_EntityID;
void main()
{
o_Color = texture(u_Textures[int(v_TexIndex)], Input.TexCoord * Input.TilingFactor) * Input.Color;
o_EntityID = v_EntityID;
}

View File

@ -0,0 +1,104 @@
// Basic Texture Shader
#type vertex
#version 450 core
layout(location = 0) in vec3 a_Position;
layout(location = 1) in vec4 a_Color;
layout(location = 2) in vec2 a_TexCoord;
layout(location = 3) in float a_TexIndex;
layout(location = 4) in float a_TilingFactor;
layout(location = 5) in int a_EntityID;
layout(std140, binding = 0) uniform Camera
{
mat4 u_ViewProjection;
};
struct VertexOutput
{
vec4 Color;
vec2 TexCoord;
float TilingFactor;
};
layout (location = 0) out VertexOutput Output;
layout (location = 3) out flat float v_TexIndex;
layout (location = 4) out flat int v_EntityID;
void main()
{
Output.Color = a_Color;
Output.TexCoord = a_TexCoord;
Output.TilingFactor = a_TilingFactor;
v_TexIndex = a_TexIndex;
v_EntityID = a_EntityID;
gl_Position = u_ViewProjection * vec4(a_Position, 1.0);
}
#type fragment
#version 450 core
layout(location = 0) out vec4 o_Color;
layout(location = 1) out int o_EntityID;
struct VertexOutput
{
vec4 Color;
vec2 TexCoord;
float TilingFactor;
};
layout (location = 0) in VertexOutput Input;
layout (location = 3) in flat float v_TexIndex;
layout (location = 4) in flat int v_EntityID;
layout (binding = 0) uniform sampler2D u_Textures[32];
void main()
{
vec4 texColor = Input.Color;
switch(int(v_TexIndex))
{
case 0: texColor *= texture(u_Textures[ 0], Input.TexCoord * Input.TilingFactor); break;
case 1: texColor *= texture(u_Textures[ 1], Input.TexCoord * Input.TilingFactor); break;
case 2: texColor *= texture(u_Textures[ 2], Input.TexCoord * Input.TilingFactor); break;
case 3: texColor *= texture(u_Textures[ 3], Input.TexCoord * Input.TilingFactor); break;
case 4: texColor *= texture(u_Textures[ 4], Input.TexCoord * Input.TilingFactor); break;
case 5: texColor *= texture(u_Textures[ 5], Input.TexCoord * Input.TilingFactor); break;
case 6: texColor *= texture(u_Textures[ 6], Input.TexCoord * Input.TilingFactor); break;
case 7: texColor *= texture(u_Textures[ 7], Input.TexCoord * Input.TilingFactor); break;
case 8: texColor *= texture(u_Textures[ 8], Input.TexCoord * Input.TilingFactor); break;
case 9: texColor *= texture(u_Textures[ 9], Input.TexCoord * Input.TilingFactor); break;
case 10: texColor *= texture(u_Textures[10], Input.TexCoord * Input.TilingFactor); break;
case 11: texColor *= texture(u_Textures[11], Input.TexCoord * Input.TilingFactor); break;
case 12: texColor *= texture(u_Textures[12], Input.TexCoord * Input.TilingFactor); break;
case 13: texColor *= texture(u_Textures[13], Input.TexCoord * Input.TilingFactor); break;
case 14: texColor *= texture(u_Textures[14], Input.TexCoord * Input.TilingFactor); break;
case 15: texColor *= texture(u_Textures[15], Input.TexCoord * Input.TilingFactor); break;
case 16: texColor *= texture(u_Textures[16], Input.TexCoord * Input.TilingFactor); break;
case 17: texColor *= texture(u_Textures[17], Input.TexCoord * Input.TilingFactor); break;
case 18: texColor *= texture(u_Textures[18], Input.TexCoord * Input.TilingFactor); break;
case 19: texColor *= texture(u_Textures[19], Input.TexCoord * Input.TilingFactor); break;
case 20: texColor *= texture(u_Textures[20], Input.TexCoord * Input.TilingFactor); break;
case 21: texColor *= texture(u_Textures[21], Input.TexCoord * Input.TilingFactor); break;
case 22: texColor *= texture(u_Textures[22], Input.TexCoord * Input.TilingFactor); break;
case 23: texColor *= texture(u_Textures[23], Input.TexCoord * Input.TilingFactor); break;
case 24: texColor *= texture(u_Textures[24], Input.TexCoord * Input.TilingFactor); break;
case 25: texColor *= texture(u_Textures[25], Input.TexCoord * Input.TilingFactor); break;
case 26: texColor *= texture(u_Textures[26], Input.TexCoord * Input.TilingFactor); break;
case 27: texColor *= texture(u_Textures[27], Input.TexCoord * Input.TilingFactor); break;
case 28: texColor *= texture(u_Textures[28], Input.TexCoord * Input.TilingFactor); break;
case 29: texColor *= texture(u_Textures[29], Input.TexCoord * Input.TilingFactor); break;
case 30: texColor *= texture(u_Textures[30], Input.TexCoord * Input.TilingFactor); break;
case 31: texColor *= texture(u_Textures[31], Input.TexCoord * Input.TilingFactor); break;
}
if (texColor.a == 0.0)
discard;
o_Color = texColor;
o_EntityID = v_EntityID;
}

View File

@ -63,7 +63,7 @@ namespace Hazel
}
// update camera
if (m_ViewportFocused && m_ViewportHovered)
if (m_ViewportFocused)
{
m_CameraController.OnUpdate(ts);
m_EditorCamera.OnUpdate(ts);
@ -284,10 +284,9 @@ namespace Hazel
snapValue = 0.25f;
float snapValues[3] = {snapValue, snapValue, snapValue};
if (ImGuizmo::Manipulate(glm::value_ptr(cameraView), glm::value_ptr(cameraProjection),
ImGuizmo::OPERATION(m_GizmoType), ImGuizmo::LOCAL,
glm::value_ptr(transform), nullptr, snap ? snapValues : nullptr))
glm::value_ptr(transform), nullptr, snap ? snapValues : nullptr) && !Input::IsKeyPressed(SDL_SCANCODE_LALT))
{
if (ImGuizmo::IsUsing())
{
@ -352,11 +351,13 @@ namespace Hazel
void EditorLayer::OnEvent(SDL_Event& e)
{
if (m_ViewportFocused && m_ViewportHovered)
if (m_ViewportFocused)
{
m_CameraController.OnEvent(e);
m_EditorCamera.OnEvent(e);
}
if (e.button.clicks && m_ViewportHovered && !ImGuizmo::IsOver() && Input::IsMouseButtonPressed(SDL_BUTTON_LEFT) && !Input::IsKeyPressed(SDL_SCANCODE_LALT))
m_SceneHierachyPanel.SetSelectedEntity(m_HoveredEntity);
#define SHORTCUT_NEW (SDL_KMOD_CTRL | SDLK_N)
#define SHORTCUT_OPEN (SDL_KMOD_CTRL | SDLK_O)

View File

@ -338,4 +338,9 @@ namespace Hazel
ImGui::ColorEdit4("Color", glm::value_ptr(component.Color));
});
}
void SceneHierachyPanel::SetSelectedEntity(const Entity entity)
{
m_SelectionContext = entity;
}
}

View File

@ -20,6 +20,7 @@ namespace Hazel
void OnImGuiRender();
void DrawComponents(Entity entity);
void SetSelectedEntity(const Entity entity);
Entity GetSelectedEntity() const { return m_SelectionContext; }
private: