Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@
[submodule "StarEngine/vendor/Box2D"]
path = StarEngine/vendor/Box2D
url = https://github.com/sheazywi/box2d
[submodule "StarEngine/vendor/msdf-atlas-gen"]
path = StarEngine/vendor/msdf-atlas-gen
url = https://github.com/sheazywi/msdf-atlas-gen
2 changes: 2 additions & 0 deletions Dependencies.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ IncludeDir["mono"] = "%{wks.location}/StarEngine/vendor/mono/include"
IncludeDir["shaderc"] = "%{wks.location}/StarEngine/vendor/shaderc/include"
IncludeDir["SPIRV_Cross"] = "%{wks.location}/StarEngine/vendor/SPIRV-Cross"
IncludeDir["VulkanSDK"] = "%{VULKAN_SDK}/Include"
IncludeDir["msdfgen"] = "%{wks.location}/StarEngine/vendor/msdf-atlas-gen/msdfgen"
IncludeDir["msdf_atlas_gen"] = "%{wks.location}/StarEngine/vendor/msdf-atlas-gen/msdf-atlas-gen"

LibraryDir = {}

Expand Down
108 changes: 60 additions & 48 deletions StarEditor/SandboxProject/Assets/Scenes/Physics2D.starscene
Original file line number Diff line number Diff line change
@@ -1,10 +1,63 @@
Scene: Untitled
Entities:
- Entity: 14040563719264005740
- Entity: 12327645238897851592
TagComponent:
Tag: Player
Tag: Welcome
TransformComponent:
Translation: [0, 5, 0]
Translation: [-3.79999995, 1.79999995, 0]
Rotation: [0, 0, 0]
Scale: [1, 1, 1]
TextComponent:
TextString: Welcome to StarEditor
Color: [1, 1, 1, 1]
Kerning: 0
LineSpacing: 0
- Entity: 6793217508611625246
TagComponent:
Tag: Circle
TransformComponent:
Translation: [0, 0, 0]
Rotation: [0, 0, 0]
Scale: [1, 1, 1]
CircleRendererComponent:
Color: [0.934362948, 0.497845858, 0, 1]
Thickness: 1
Fade: 0.00499999989
RigidBody2DComponent:
BodyType: Dynamic
FixedRotation: false
CircleCollider2DComponent:
Offset: [0, 0]
Radius: 0.5
Density: 1
Friction: 0.5
Restitution: 1
RestitutionThreshold: 0.5
- Entity: 7665505456185074185
TagComponent:
Tag: Platform
TransformComponent:
Translation: [0, -10, 0]
Rotation: [0, 0, 0]
Scale: [10, 1, 1]
SpriteRendererComponent:
Color: [1, 1, 1, 1]
TilingFactor: 1
RigidBody2DComponent:
BodyType: Static
FixedRotation: true
BoxCollider2DComponent:
Offset: [0, 0]
Size: [0.5, 0.5]
Density: 1
Friction: 0.5
Restitution: 0
RestitutionThreshold: 0.5
- Entity: 16059016071823036758
TagComponent:
Tag: Cube
TransformComponent:
Translation: [0, 10, 0]
Rotation: [0, 0, 0]
Scale: [1, 1, 1]
SpriteRendererComponent:
Expand All @@ -18,7 +71,7 @@ Entities:
Size: [0.5, 0.5]
Density: 1
Friction: 0.5
Restitution: 0
Restitution: 0.100000001
RestitutionThreshold: 0.5
- Entity: 16241606122818465121
TagComponent:
Expand All @@ -38,11 +91,11 @@ Entities:
OrthographicFar: 1
Primary: true
FixedAspectRatio: false
- Entity: 16059016071823036758
- Entity: 14040563719264005740
TagComponent:
Tag: Cube
Tag: Player
TransformComponent:
Translation: [0, 10, 0]
Translation: [0, 5, 0]
Rotation: [0, 0, 0]
Scale: [1, 1, 1]
SpriteRendererComponent:
Expand All @@ -51,51 +104,10 @@ Entities:
RigidBody2DComponent:
BodyType: Dynamic
FixedRotation: false
BoxCollider2DComponent:
Offset: [0, 0]
Size: [0.5, 0.5]
Density: 1
Friction: 0.5
Restitution: 0.100000001
RestitutionThreshold: 0.5
- Entity: 7665505456185074185
TagComponent:
Tag: Platform
TransformComponent:
Translation: [0, -10, 0]
Rotation: [0, 0, 0]
Scale: [10, 1, 1]
SpriteRendererComponent:
Color: [1, 1, 1, 1]
TilingFactor: 1
RigidBody2DComponent:
BodyType: Static
FixedRotation: true
BoxCollider2DComponent:
Offset: [0, 0]
Size: [0.5, 0.5]
Density: 1
Friction: 0.5
Restitution: 0
RestitutionThreshold: 0.5
- Entity: 6793217508611625246
TagComponent:
Tag: Circle
TransformComponent:
Translation: [0, 0, 0]
Rotation: [0, 0, 0]
Scale: [1, 1, 1]
CircleRendererComponent:
Color: [0.934362948, 0.497845858, 0, 1]
Thickness: 1
Fade: 0.00499999989
RigidBody2DComponent:
BodyType: Dynamic
FixedRotation: false
CircleCollider2DComponent:
Offset: [0, 0]
Radius: 0.5
Density: 1
Friction: 0.5
Restitution: 1
RestitutionThreshold: 0.5
79 changes: 79 additions & 0 deletions StarEditor/assets/shaders/Renderer2D_Text.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// MSDF text 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 int a_EntityID;

layout(std140, binding = 0) uniform Camera
{
mat4 u_ViewProjection;
};

struct VertexOutput
{
vec4 Color;
vec2 TexCoord;
};

layout (location = 0) out VertexOutput Output;
layout (location = 2) out flat int v_EntityID;

void main()
{
Output.Color = a_Color;
Output.TexCoord = a_TexCoord;
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;
};

layout (location = 0) in VertexOutput Input;
layout (location = 2) in flat int v_EntityID;

layout (binding = 0) uniform sampler2D u_FontAtlas;

float screenPxRange() {
const float pxRange = 2.0; // set to distance field's pixel range
vec2 unitRange = vec2(pxRange)/vec2(textureSize(u_FontAtlas, 0));
vec2 screenTexSize = vec2(1.0)/fwidth(Input.TexCoord);
return max(0.5*dot(unitRange, screenTexSize), 1.0);
}

float median(float r, float g, float b) {
return max(min(r, g), min(max(r, g), b));
}

void main()
{
vec4 texColor = Input.Color * texture(u_FontAtlas, Input.TexCoord);

vec3 msd = texture(u_FontAtlas, Input.TexCoord).rgb;
float sd = median(msd.r, msd.g, msd.b);
float screenPxDistance = screenPxRange()*(sd - 0.5);
float opacity = clamp(screenPxDistance + 0.5, 0.0, 1.0);
if (opacity == 0.0)
discard;

vec4 bgColor = vec4(0.0);
o_Color = mix(bgColor, Input.Color, opacity);
if (o_Color.a == 0.0)
discard;

o_EntityID = v_EntityID;
}
13 changes: 11 additions & 2 deletions StarEditor/src/EditorLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "StarEngine/Utils/PlatformUtils.h"
#include "StarEngine/Math/Math.h"
#include "StarEngine/Scripting/ScriptEngine.h"
#include "StarEngine/Renderer/Font.h"

#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
Expand All @@ -12,13 +13,16 @@
#include "imgui/imgui_internal.h"
#include "ImGuizmo.h"


namespace StarEngine {

static Ref<Font> s_Font;

EditorLayer::EditorLayer()
: Layer("EditorLayer"), m_CameraController(1280.0f / 720.0f, true), m_SquareColor({ 0.2f, 0.3f, 0.8f, 1.0f })
{

s_Font = Font::GetDefault();

}

void EditorLayer::OnAttach()
Expand Down Expand Up @@ -264,6 +268,10 @@ namespace StarEngine {

ImGui::Checkbox("Show Physics Colliders", &m_ShowPhysicsColliders);

ImGui::Separator();

ImGui::Image((ImTextureID)s_Font->GetAtlasTexture()->GetRendererID(), { 512,512 }, { 0, 1 }, { 1, 0 });

ImGui::End();

ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2{ 0, 0 });
Expand Down Expand Up @@ -596,8 +604,9 @@ namespace StarEngine {
glm::vec3 translation = tc.Translation + glm::vec3(bc2d.Offset, 0.001f);
glm::vec3 scale = tc.Scale * glm::vec3(bc2d.Size * 2.0f, 1.0f);

glm::mat4 transform = glm::translate(glm::mat4(1.0f), translation)
glm::mat4 transform = glm::translate(glm::mat4(1.0f), tc.Translation)
* glm::rotate(glm::mat4(1.0f), tc.Rotation.z, glm::vec3(0.0f, 0.0f, 1.0f))
* glm::translate(glm::mat4(1.0f), glm::vec3(bc2d.Offset, 0.001f))
* glm::scale(glm::mat4(1.0f), scale);

Renderer2D::DrawRect(transform, glm::vec4(0, 1, 0, 1));
Expand Down
9 changes: 9 additions & 0 deletions StarEditor/src/Panels/SceneHierarchyPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <imgui/imgui.h>
#include <imgui/imgui_internal.h>
#include <imgui/misc/cpp/imgui_stdlib.h>

#include <glm/gtc/type_ptr.hpp>

Expand Down Expand Up @@ -247,6 +248,7 @@ namespace StarEngine
DisplayAddComponentEntry<RigidBody2DComponent>("RigidBody 2D");
DisplayAddComponentEntry<BoxCollider2DComponent>("Box Collider 2D");
DisplayAddComponentEntry<CircleCollider2DComponent>("Circle Collider 2D");
DisplayAddComponentEntry<TextComponent>("Text Component");

ImGui::EndPopup();
}
Expand Down Expand Up @@ -474,6 +476,13 @@ namespace StarEngine
ImGui::DragFloat("Restitution Threshold", &component.RestitutionThreshold, 0.01f, 0.0f);
});

DrawComponent<TextComponent>("Text Renderer", entity, [](auto& component)
{
ImGui::InputTextMultiline("Text String", &component.TextString);
ImGui::ColorEdit4("Color", glm::value_ptr(component.Color));
ImGui::DragFloat("Kerning", &component.Kerning, 0.025f);
ImGui::DragFloat("Line Spacing", &component.LineSpacing, 0.025f);
});
}

template<typename T>
Expand Down
38 changes: 31 additions & 7 deletions StarEngine-ScriptCore/Source/StarEngine/InternalCalls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,57 @@ namespace StarEngine
{
public static class InternalCalls
{
#region Entity
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal extern static bool Entity_HasComponent(ulong entityID, Type componentType);

[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal extern static ulong Entity_FindEntityByName(string name);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal extern static object GetScriptInstance(ulong entityID);
#endregion

#region TransformComponent
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal extern static void TransformComponent_GetTranslation(ulong entityID, out Vector3 translation);

[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal extern static void TransformComponent_SetTranslation(ulong entityID, ref Vector3 translation);
#endregion

#region Rigidbody2DComponent
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal extern static void RigidBody2DComponent_ApplyLinearImpulse(ulong entityID, ref Vector2 impulse, ref Vector2 point, bool wake);

[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal extern static void Rigidbody2DComponent_GetLinearVelocity(ulong entityID, out Vector2 linearVelocity);
internal extern static void RigidBody2DComponent_GetLinearVelocity(ulong entityID, out Vector2 linearVelocity);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal extern static RigidBody2DComponent.BodyType Rigidbody2DComponent_GetType(ulong entityID);
internal extern static RigidBody2DComponent.BodyType RigidBody2DComponent_GetType(ulong entityID);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal extern static void Rigidbody2DComponent_SetType(ulong entityID, RigidBody2DComponent.BodyType type);

internal extern static void RigidBody2DComponent_SetType(ulong entityID, RigidBody2DComponent.BodyType type);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal extern static void RigidBody2DComponent_ApplyLinearImpulseToCenter(ulong entityID, ref Vector2 impulse, bool wake);
#endregion

#region TextComponent
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal extern static string TextComponent_GetText(ulong entityID);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal extern static void TextComponent_SetText(ulong entityID, string text);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal extern static void TextComponent_GetColor(ulong entityID, out Vector4 color);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal extern static void TextComponent_SetColor(ulong entityID, ref Vector4 color);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal extern static float TextComponent_GetKerning(ulong entityID);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal extern static void TextComponent_SetKerning(ulong entityID, float kerning);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal extern static float TextComponent_GetLineSpacing(ulong entityID);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal extern static void TextComponent_SetLineSpacing(ulong entityID, float lineSpacing);
#endregion

#region Rigidbody2DComponent
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal extern static bool Input_IsKeyDown(KeyCode keycode);
#endregion
}
}
Loading
Loading