Skip to content

Commit

Permalink
🫦 Fun stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
wobbier committed Mar 18, 2024
1 parent fd33aad commit efa0c0b
Show file tree
Hide file tree
Showing 13 changed files with 215 additions and 76 deletions.
31 changes: 24 additions & 7 deletions Modules/Dementia/Source/Path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Path::Path( const std::string& InFile, bool Raw /*= false*/ )
ExtensionPos = (int8_t)LocalPath.rfind( '.' );
ExtensionPos = (int8_t)( LocalPath.size() - ++ExtensionPos );

// yeah don't do this
path = LocalPath.rfind( "Assets" );
if( path != std::string::npos )
{
Expand Down Expand Up @@ -148,17 +149,33 @@ std::string Path::GetLocalPathString() const
return std::string( GetLocalPath() );
}

std::string_view Path::GetFileName() const
std::string_view Path::GetFileName( bool inIncludeExt ) const
{
size_t lastSlash = GetLocalPathString().rfind( '/' );
size_t period = GetLocalPathString().rfind( '.' );
std::string_view localPath = GetLocalPath();
size_t lastSlash = localPath.rfind( '/' );
if( lastSlash != std::string::npos )
{
lastSlash++;
}
else
{
lastSlash = 0;
}

return GetLocalPathString().substr( lastSlash, period );
if( inIncludeExt )
{
return localPath.substr( lastSlash, localPath.size() );
}
else
{
//size_t period = GetLocalPathString().rfind( '.' );
size_t size = localPath.size() - lastSlash - ExtensionPos - 1;

return localPath.substr( lastSlash, size );
}
}

std::string Path::GetFileNameString() const
std::string Path::GetFileNameString( bool inIncludeExt ) const
{
return std::string( GetFileName() );
return std::string( GetFileName( inIncludeExt ) );
}

4 changes: 2 additions & 2 deletions Modules/Dementia/Source/Path.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class Path
std::string_view GetLocalPath() const;
std::string GetLocalPathString() const;

std::string_view GetFileName() const;
std::string GetFileNameString() const;
std::string_view GetFileName( bool inIncludeExt = true ) const;
std::string GetFileNameString( bool inIncludeExt = true ) const;

bool IsFile = false;
bool IsFolder = false;
Expand Down
1 change: 0 additions & 1 deletion Modules/Dementia/Source/Utils/ImGuiUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ namespace ImGui
, const ImVec4& _tintCol = ImVec4( 1.0f, 1.0f, 1.0f, 1.0f )
)
{
ME_ASSERT_MSG( bgfx::isValid( _handle ), "lmao wtf");
return ImageButton( _handle, IMGUI_FLAGS_ALPHA_BLEND, 0, _size, _uv0, _uv1, _framePadding, _bgCol, _tintCol );
}

Expand Down
80 changes: 79 additions & 1 deletion Modules/ImGUI/Source/Utils/HavanaUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <imgui.h>
#include <imgui_internal.h>
#include "imgui_stacklayout.h"

float HavanaUtils::Label( const std::string& Name, float customWidth )
{
Expand Down Expand Up @@ -62,6 +63,82 @@ bool HavanaUtils::EditableVector3( const std::string& Name, Vector3& Vector, flo
{
ImGui::PushID( Name.c_str() );

float widgetWidth = Label( Name, customWidth );
ImGui::PushStyleVar( ImGuiStyleVar_ItemSpacing, { 0.f, 0.f } );
ImGui::PushStyleVar( ImGuiStyleVar_CellPadding, { 2.f, 2.f } );
float paddingX = 0.f;// ImGui::GetStyle().WindowPadding.x;
Vector3 tempVec = Vector;
if( ImGui::BeginTable( "##vec", 3, 0, { widgetWidth - paddingX, 0.f } ) )
{

ImGui::TableNextRow();

float lineHeight = GImGui->Font->FontSize + GImGui->Style.FramePadding.y * 2.f;
ImVec2 buttonSize = { lineHeight + 3.f, lineHeight };

float dragWidths = ( widgetWidth - ( buttonSize.x * 3 ) ) / 3.f;

{
ImGui::TableSetColumnIndex( 0 );
ImGui::PushStyleColor( ImGuiCol_Button, ImVec4( 1.f, 51.f / 255.f, 82.f / 255.f, .66f ) );
ImGui::PushStyleColor( ImGuiCol_ButtonHovered, ImVec4( 1.f, 51.f / 255.f, 82.f / 255.f, 1.f ) );
if( ImGui::Button( "X", buttonSize ) )
{
Vector.x = ResetValue;
}
ImGui::PopStyleColor( 2 );
ImGui::SameLine();
ImGui::PushItemWidth( dragWidths );
ImGui::DragFloat( "##X", &Vector.x, 0.1f );
ImGui::PopItemWidth();
}

{
ImGui::TableSetColumnIndex( 1 );
ImGui::PushStyleColor( ImGuiCol_Button, ImVec4( 139.f / 255.f, 220.f / 255.f, 0.f, .66f ) );
ImGui::PushStyleColor( ImGuiCol_ButtonHovered, ImVec4( 139.f / 255.f, 220.f / 255.f, 0.f, 1.f ) );
if( ImGui::Button( "Y", buttonSize ) )
{
Vector.y = ResetValue;
}
ImGui::PopStyleColor( 2 );
ImGui::SameLine();
ImGui::PushItemWidth( dragWidths );
ImGui::DragFloat( "##Y", &Vector.y, 0.1f );
ImGui::PopItemWidth();
}

{
ImGui::TableSetColumnIndex( 2 );
ImGui::PushStyleColor( ImGuiCol_Button, ImVec4( 40.f / 255.f, 143.f / 255.f, 253.f / 255.f, .66f ) );
ImGui::PushStyleColor( ImGuiCol_ButtonHovered, ImVec4( 40.f / 255.f, 143.f / 255.f, 253.f / 255.f, 1.f ) );
if( ImGui::Button( "Z", buttonSize ) )
{
Vector.z = ResetValue;
}
ImGui::PopStyleColor( 2 );
ImGui::SameLine();
ImGui::PushItemWidth( dragWidths );
ImGui::DragFloat( "##Z", &Vector.z, 0.1f );
ImGui::PopItemWidth();
}

ImGui::EndTable();

}

ImGui::PopStyleVar( 2 );
ImGui::PopID();

return tempVec != Vector;
}

bool HavanaUtils::EditableVector3Spring( const std::string& Name, Vector3& Vector, float ResetValue /*= 0.f*/, float customWidth /*= -1 */ )
{
//ImGui::PushID( Name.c_str() );

ImGui::BeginHorizontal( Name.c_str() );

float widgetWidth = Label( Name, customWidth );
ImGui::PushStyleVar( ImGuiStyleVar_ItemSpacing, { 0.f, 0.f } );
ImGui::PushStyleVar( ImGuiStyleVar_CellPadding, { 2.f, 2.f } );
Expand Down Expand Up @@ -124,7 +201,8 @@ bool HavanaUtils::EditableVector3( const std::string& Name, Vector3& Vector, flo

ImGui::PopStyleVar( 2 );

ImGui::PopID();
//ImGui::PopID();
ImGui::EndHorizontal();

return tempVec != Vector;
}
Expand Down
1 change: 1 addition & 0 deletions Modules/ImGUI/Source/Utils/HavanaUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class HavanaUtils
static void Text( const std::string& Name, const Vector2& Vector );

static bool EditableVector3( const std::string& Name, Vector3& Vector, float ResetValue = 0.f, float customWidth = -1 );
static bool EditableVector3Spring( const std::string& Name, Vector3& Vector, float ResetValue = 0.f, float customWidth = -1 );
static bool EditableVector( const std::string& Name, Vector2& Vector, float ResetValue = 0.f, float customWidth = -1 );

static bool Float( const std::string& Name, float& value );
Expand Down
33 changes: 17 additions & 16 deletions Modules/Moonlight/Source/Materials/ShaderGraphMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,23 @@ void ShaderGraphMaterial::OnDeserialize( const json& InJson )
}
}

void ShaderGraphMaterial::LoadShader( const std::string& inShaderName )
{
m_textures.clear();
// clean this up
s_uniforms.clear();
s_uniformTextures.clear();
Path filePath( inShaderName + ".shader" );
if( filePath.Exists )
{
File shaderGraphFile( filePath );
json parsed = json::parse( shaderGraphFile.Read() );
OnDeserialize( parsed );
}

Material::LoadShader( inShaderName );
}

#if USING( ME_TOOLS )
void ShaderGraphMaterial::OnEditorInspect()
{
Expand All @@ -46,21 +63,5 @@ void ShaderGraphMaterial::OnEditorInspect()
}
}

void ShaderGraphMaterial::LoadShader( const std::string& inShaderName )
{
m_textures.clear();
// clean this up
s_uniforms.clear();
s_uniformTextures.clear();
Path filePath( inShaderName + ".shader" );
if( filePath.Exists )
{
File shaderGraphFile( filePath );
json parsed = json::parse( shaderGraphFile.Read() );
OnDeserialize( parsed );
}

Material::LoadShader( inShaderName );
}

#endif
6 changes: 3 additions & 3 deletions Tools/ShaderEditor/Source/Core/ShaderWriter.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "ShaderWriter.h"

ShaderWriter::ShaderWriter( const std::string& inShaderName )
ShaderWriter::ShaderWriter( const Path& inShaderName )
{
m_shaderFile = File( Path( "../../../Assets/Shaders/" + inShaderName));
m_shaderFile = File( inShaderName );
m_shaderFile.Reset();
}

Expand All @@ -13,7 +13,7 @@ void ShaderWriter::Reset()

void ShaderWriter::WriteLine( const std::string& inLine )
{
for ( int i = 0; i < Tabs; ++i )
for( int i = 0; i < Tabs; ++i )
{
m_shaderFile.Append( "\t" );
}
Expand Down
2 changes: 1 addition & 1 deletion Tools/ShaderEditor/Source/Core/ShaderWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct ExportedTextureInfo
class ShaderWriter
{
public:
ShaderWriter( const std::string& inShaderName );
ShaderWriter( const Path& inShaderName );

void Reset();
void WriteLine( const std::string& inLine );
Expand Down
8 changes: 4 additions & 4 deletions Tools/ShaderEditor/Source/Nodes/BasicNodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,13 +364,13 @@ void BasicShaderMasterNode::ExportPin( int inPinNum, PinType inPinType )

void BasicShaderMasterNode::ExportShitty( Path& inPath, const std::string& inShaderName )
{
File outFile( Path( "../../../Assets/Shaders/" + inPath.GetLocalPathString() ) );
File outFile( inPath );
json outJson = json::parse( outFile.Read() );
json& textures = outJson["Textures"];


{
ShaderWriter file( inShaderName + ".var" );
ShaderWriter file( Path( inPath.FullPath + ".var" ) );
file.WriteLine( "vec4 v_color0 : COLOR0 = vec4(1.0, 0.0, 0.0, 1.0);" );
file.WriteLine( "vec3 v_normal : NORMAL = vec3( 0.0, 0.0, 1.0 );" );
file.WriteLine( "vec2 v_texcoord0 : TEXCOORD0 = vec2( 0.0, 0.0 );" );
Expand All @@ -385,7 +385,7 @@ void BasicShaderMasterNode::ExportShitty( Path& inPath, const std::string& inSha
}

{
ShaderWriter file( inShaderName + ".vert" );
ShaderWriter file( Path( inPath.FullPath + ".vert" ) );
file.WriteLine( "$input a_position, a_normal, a_texcoord0, a_tangent, a_bitangent" );
file.WriteLine( "$output v_color0, v_normal, v_texcoord0" );
file.Append( "\n" );
Expand Down Expand Up @@ -413,7 +413,7 @@ void BasicShaderMasterNode::ExportShitty( Path& inPath, const std::string& inSha
}

{
ShaderWriter file( inShaderName + ".frag" );
ShaderWriter file( Path( inPath.FullPath + ".frag" ) );

file.WriteLine( "$input v_color0, v_normal, v_texcoord0" );
file.Append( "\n" );
Expand Down
46 changes: 28 additions & 18 deletions Tools/ShaderEditor/Source/ShaderEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,36 @@ ShaderEditor::ShaderEditor( ToolCreationFlags& inToolCreationFlags )
void ShaderEditor::OnStart()
{
DockMargins = { 6.f };
{
auto initialInstance = MakeShared<ShaderEditorInstance>();
initialInstance->Init( "BasicInteraction.json" );

m_editorInstances.push_back( initialInstance );
}
{
auto initialInstance = MakeShared<ShaderEditorInstance>();
initialInstance->Init( "BasicShader.json" );

m_editorInstances.push_back( initialInstance );
}
for( auto& instance : m_editorInstances )
{
instance->Start();
}
OpenShader( "../../../Assets/Shaders/BasicInteraction.shader" );
OpenShader( "../../../Assets/Shaders/BasicShader.shader" );
}


void ShaderEditor::OnUpdate()
{
ImGui::BeginMainMenuBar();
ImGui::Button( "File" );
if( ImGui::BeginMenu( "File" ) )
{
if( ImGui::MenuItem( "New..." ) )
{
OpenShader( "../../../Assets/Shaders/NewShader" + std::to_string( m_newFileNum++ ) + ".shader" );
}
ImGui::EndMenu();
}
ImGui::EndMainMenuBar();
DockMargins.top = 20.f;
m_editorInstances.erase(std::remove_if(m_editorInstances.begin(), m_editorInstances.end(), [](auto& instance) {

if( !instance->m_isOpen )
{
return true;
}
return false;
} ), m_editorInstances.end() );
int i = 0;
for( auto& instance : m_editorInstances )
{

ImGui::PushID( i );
instance->OnUpdate();
i++;
Expand Down Expand Up @@ -251,4 +252,13 @@ void ShaderEditor::OnUpdate()
//draw_list->AddRect( ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), ImGui::GetColorU32( ImGuiCol_Border ) );
//
//ImGui::End();
}
}

void ShaderEditor::OpenShader( const std::string& inFileName )
{
auto initialInstance = MakeShared<ShaderEditorInstance>();
initialInstance->Init( Path( inFileName ) );

m_editorInstances.push_back( initialInstance );
initialInstance->Start();
}
3 changes: 3 additions & 0 deletions Tools/ShaderEditor/Source/ShaderEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ class ShaderEditor
void OnStart() override;
void OnUpdate() override;

void OpenShader( const std::string& inFileName );

private:
std::vector<SharedPtr<ShaderEditorInstance>> m_editorInstances;
uint32_t m_newFileNum = 0u;
};
Loading

0 comments on commit efa0c0b

Please sign in to comment.