diff --git a/build.cpp b/build.cpp index ab1a675..26cc3f3 100755 --- a/build.cpp +++ b/build.cpp @@ -38,15 +38,16 @@ DECLARE_BUILD_STAGE(install_game) if ( GET_PROJECT_VALUE(config, "bundle") == "true" ) { return 0; } + filesystem2->CopyFile(szOutputDir, GET_PROJECT_OBJECT(launcher, "launcher")); filesystem2->MakeDirectory(CUtlString("%s/core/",szOutputDir.GetString())); - filesystem2->CopyFile(szOutputDir, GET_PROJECT_OBJECT(launcher, "launcher")); filesystem2->CopyDirectory(CUtlString("%s/core/",szOutputDir.GetString()), "funnyassets/maps"); filesystem2->CopyDirectory(CUtlString("%s/core/",szOutputDir.GetString()), "funnyassets/models"); filesystem2->CopyDirectory(CUtlString("%s/core/",szOutputDir.GetString()), "funnyassets/meshes"); filesystem2->CopyDirectory(CUtlString("%s/core/",szOutputDir.GetString()), "funnyassets/materials"); filesystem2->CopyDirectory(CUtlString("%s/core/",szOutputDir.GetString()), "funnyassets/textures"); filesystem2->CopyDirectory(CUtlString("%s/core/",szOutputDir.GetString()), "funnyassets/physics"); + filesystem2->CopyDirectory(CUtlString("%s/core/",szOutputDir.GetString()), "funnyassets/fonts"); filesystem2->CopyFile(CUtlString("%s/core/",szOutputDir.GetString()), "funnyassets/default.cfg"); filesystem2->CopyDirectory(CUtlString("%s/core/",szOutputDir.GetString()), "build/funnygame/assets/shaders"); if (Target_t::DefaultTarget().kernel == TARGET_KERNEL_WINDOWS) diff --git a/engine/engine.cpp b/engine/engine.cpp index ba2fb5f..17ca51f 100644 --- a/engine/engine.cpp +++ b/engine/engine.cpp @@ -158,6 +158,8 @@ extern "C" void FunnyMain( int argc, char **argv ) fCurrent = Plat_GetTime(); }; + Plat_Exit(0); + g_pClientGame->Shutdown(); g_pServerGame->Shutdown(); g_pRenderContext->Shutdown(); diff --git a/engine/kottui.cpp b/engine/kottui.cpp index 77dbd80..7f02679 100644 --- a/engine/kottui.cpp +++ b/engine/kottui.cpp @@ -1,23 +1,399 @@ #include "kottui/kottui.h" +#include "tier0/lib.h" +#include "tier0/mem.h" +#include "tier1/utlstring.h" +#include "tier2/ifilesystem.h" +#include "tier2/fileformats/json.h" +#include "trig.h" + +struct GlyphData_t +{ + uint32_t m_uCharacter; + float m_fX; + float m_fY; + float m_fWidth; + float m_fHeight; +}; + +class CKotRenderFont: public IKotRenderFont +{ +public: + virtual IImage *GetAtlas() override; + virtual bool IsLetterPresent( uint32_t letter ) override; + virtual float GetLetterX( uint32_t letter ) override; + virtual float GetLetterY( uint32_t letter ) override; + virtual float GetWidth( uint32_t letter ) override; + virtual float GetHeight( uint32_t letter ) override; + + virtual bool IsMono() override; + virtual uint32_t GetLetterWidth() override; + virtual uint32_t GetLetterHeight() override; + + GlyphData_t *m_glyphs; + uint32_t m_uGlyphCount; + IImage *m_pAtlas; +}; class CKotUIBuffer: public IKotUIBuffer { public: - virtual void SetColor( char c ) = 0; - virtual void SetPosition( int iY, int iX ) = 0; - virtual void Printf(const char *szFormat, ...) = 0; - virtual void PutChar( char c ) = 0; - virtual void Clear( char c ) = 0; + virtual void SetPosition( int iY, int iX ) override; + + virtual void Move( int iY, int iX ) override; + + virtual void SetColor( char c ) override; + virtual void Clear( char c ) override; + + virtual void PutChar( char c ) override; + virtual void Printf(const char *szFormat, ...) override; + + virtual void Draw( IImage *pImage ) override; + + virtual void SetTextSize( int iY, int iX ) override; + virtual void SetTextFont( IKotRenderFont *pFont ) override; + + uint32_t *m_buffer; + ColorAlpha *m_primaryColor; + ColorAlpha *m_secondaryColor; + int m_iWidth = 0; + int m_iHeight = 0; + IBuffer *m_pDataBuffer; + + IMaterial *m_pMaterial; + IRenderContext *m_pRenderContext; + IKotRenderFont *m_pFont; + + uint32_t m_uCursor = 0; }; class CKotUIManager: public IKotUIManager { public: - virtual void SetTextSize( int iY, int iX ) = 0; - virtual void SetTextFont( IRenderFont *pFont ) = 0; + virtual void Init() override; + virtual void Shutdown() override; + virtual void ConnectInterface( void *pIface, const char *szName ) override; - virtual void CreateBuffer( int iWidth, int iHeight, int iY, int iX ) = 0; - virtual void Draw( IRenderContext *pRenderContext ); + virtual IKotRenderFont *LoadFont( const char *szPath ) override; + + virtual IKotUIBuffer *CreateBuffer( int iWidth, int iHeight ) override; + virtual void DeleteBuffer( IKotUIBuffer *pBuffer ) override; + + + IRenderContext *m_pRenderContext; + ITextureArray *m_pFonts; }; -IKotUIManager *KotUIManager(); +static IShader *s_pShader; +static CKotUIManager s_kotUIManager; +static IVertexBuffer *s_pGlyphBuffer; + +IKotUIManager *KotUIManager() +{ + return &s_kotUIManager; +} +EXPOSE_INTERFACE_FN(KotUIManager, IKotUIManager, KOT_UI_INTEFACE_VERSION); + +IImage *CKotRenderFont::GetAtlas() +{ + return m_pAtlas; +} + +bool CKotRenderFont::IsLetterPresent( uint32_t letter ) +{ + for ( int i = 0; i < m_uGlyphCount; i++ ) + { + GlyphData_t g = m_glyphs[i]; + if (g.m_uCharacter == letter) + return true; + } + return false; +} + +float CKotRenderFont::GetLetterX( uint32_t letter ) +{ + for ( int i = 0; i < m_uGlyphCount; i++ ) + { + GlyphData_t g = m_glyphs[i]; + if (g.m_uCharacter == letter) + return g.m_fX; + } + return 0; +} + +float CKotRenderFont::GetLetterY( uint32_t letter ) +{ + for ( int i = 0; i < m_uGlyphCount; i++ ) + { + GlyphData_t g = m_glyphs[i]; + if (g.m_uCharacter == letter) + return g.m_fY; + } + return 0; +} + +float CKotRenderFont::GetWidth( uint32_t letter ) +{ + for ( int i = 0; i < m_uGlyphCount; i++ ) + { + GlyphData_t g = m_glyphs[i]; + if (g.m_uCharacter == letter) + return g.m_fWidth; + } + return 0; +} + +float CKotRenderFont::GetHeight( uint32_t letter ) +{ + for ( int i = 0; i < m_uGlyphCount; i++ ) + { + GlyphData_t g = m_glyphs[i]; + if (g.m_uCharacter == letter) + return g.m_fHeight; + } + return 0; +} + + + +void CKotUIBuffer::SetPosition( int iY, int iX ) +{ + +} + +void CKotUIBuffer::Move( int iY, int iX ) +{ + m_uCursor = iY*m_iWidth+iX; + m_uCursor = m_uCursor % (m_iWidth * m_iHeight); +} + +void CKotUIBuffer::SetColor( char c ) +{ + +} + +void CKotUIBuffer::Clear( char c ) +{ + +} + +void CKotUIBuffer::PutChar( char c ) +{ + m_buffer[m_uCursor] = c; + Move(0, m_uCursor+1); + +} + +void CKotUIBuffer::Printf(const char *szFormat, ...) +{ + + va_list vlArgs; + va_start(vlArgs, szFormat); + va_list vlArgs2; + va_copy(vlArgs2, vlArgs); + + size_t nSize = V_vsnprintf(NULL, 0, szFormat, vlArgs2); + va_end(vlArgs2); + char *psz = (char*)V_malloc(nSize+1); + va_copy(vlArgs2, vlArgs); + V_vsnprintf(psz, nSize+1, szFormat, vlArgs2); + for ( size_t u = 0, i = m_uCursor; u < nSize; u++, i = (i + 1 % (m_iWidth * m_iHeight)) ) + { + m_buffer[i] = psz[u]; + } + va_end(vlArgs2); + V_free(psz); + va_end(vlArgs); + Move(0, m_uCursor+1); + +} + +struct TextDrawData_t +{ + float m_vTexcoordOffsetX; + float m_vTexcoordOffsetY; + float m_vTexcoordSizeX; + float m_vTexcoordSizeY; + float m_fPosX; + float m_fPosY; + float m_fSizeX; + float m_fSizeY; + float m_fColor[4]; + float m_fColor2[4]; +}; + +struct ScreenData_t +{ + float m_fScreenSizeX; + float m_fScreenSizeY; +}; + +void CKotUIBuffer::Draw( IImage *pImage ) +{ + uint32_t uGlyphCount = m_iWidth*m_iHeight; + uint32_t uRealGlyphCount = 0; + + IRenderCommandList *pList = m_pRenderContext->CreateCommandList(); + pList->StartRecording(); + + m_pDataBuffer->Lock(); + TextDrawData_t *pData = (TextDrawData_t*)m_pDataBuffer->Map(); + for ( uint32_t i = 0; i < uGlyphCount; i++ ) + { + uint32_t l = m_buffer[i]; + if ( !m_pFont->IsLetterPresent(l) ) + continue; + pData[uRealGlyphCount].m_vTexcoordOffsetX = m_pFont->GetLetterX(l); + pData[uRealGlyphCount].m_vTexcoordOffsetY = m_pFont->GetLetterY(l); + pData[uRealGlyphCount].m_vTexcoordSizeX = m_pFont->GetWidth(l); + pData[uRealGlyphCount].m_vTexcoordSizeY = m_pFont->GetHeight(l); + pData[uRealGlyphCount].m_fSizeX = 16; + pData[uRealGlyphCount].m_fSizeY = 16; + pData[uRealGlyphCount].m_fPosX = i%m_iWidth*16; + pData[uRealGlyphCount].m_fPosY = i/m_iWidth*16; + uRealGlyphCount++; + } + m_pDataBuffer->Unmap(); + m_pDataBuffer->Unlock(); + + IBuffer *pScreenBuffer = m_pRenderContext->CreateConstantBuffer(sizeof(ScreenData_t)); + pScreenBuffer->Lock(); + ScreenData_t *pScreenData = (ScreenData_t*)pScreenBuffer->Map(); + pScreenData->m_fScreenSizeX = pImage->GetImageWidth(); + pScreenData->m_fScreenSizeY = pImage->GetImageHeight(); + pScreenBuffer->Unmap(); + pScreenBuffer->Unlock(); + + m_pMaterial = m_pRenderContext->CreateMaterial(s_pShader); + m_pMaterial->PSSetShaderResource(0, m_pDataBuffer); + m_pMaterial->PSSetShaderResource(1, pScreenBuffer); + m_pMaterial->PSSetTexture(2, m_pFont->GetAtlas()); + m_pMaterial->PSSetSampler(3, m_pRenderContext->GetDefaultSampler()); + + + pList->SetRenderTarget(0, pImage); + pList->SetLoadStoreModes(0, LOAD_MODE_LOAD, STORE_MODE_STORE); + pList->SetRenderResolution(pImage->GetImageWidth(), pImage->GetImageHeight()); + + pList->SetMaterial(m_pMaterial); + pList->SetVertexBuffer(0, s_pGlyphBuffer); + pList->DrawPrimitives(6, 0, uRealGlyphCount, 0); + + pList->EndRecording(); + m_pRenderContext->SubmitCommandList(pList); + +} + +void CKotUIBuffer::SetTextSize( int iY, int iX ) +{ + + +} + +void CKotUIBuffer::SetTextFont( IKotRenderFont *pFont ) +{ + m_pFont = pFont; + +} + + +void CKotUIManager::Init() +{ + s_pShader = m_pRenderContext->CreateShader("game/core/shaders/kottui.shader_c"); + s_pShader->AddLayout(0, 8); + s_pShader->AddAttribute(0, 0, VERTEX_FORMAT_XY32_SFLOAT, 0); + s_pShader->AddOutputImage(0, IMAGE_FORMAT_RGBA8_UNORM); + s_pShader->Build(); + s_pGlyphBuffer = m_pRenderContext->CreateVertexBuffer(sizeof(float)*12); + void *pBuffer = s_pGlyphBuffer->Map(); + float vertices[12] = { + 0, 0, + 0, 1, + 1, 0, + 1, 0, + 0, 1, + 1, 1, + }; + V_memcpy(pBuffer, vertices, sizeof(vertices)); + s_pGlyphBuffer->Unmap(); + + m_pFonts = m_pRenderContext->CreateTextureArray(); + + +} + +void CKotUIManager::Shutdown() +{ + +} + +void CKotUIManager::ConnectInterface( void *pFace, const char *psz ) +{ + if (!V_strcmp(psz, RENDER_CONTEXT_INTERFACE_VERSION)) + m_pRenderContext = (IRenderContext*)pFace; +} + +IKotRenderFont *CKotUIManager::LoadFont( const char *szPath ) +{ + CUtlString szAtlas = CUtlString("%s.png", szPath); + CUtlString szMeta = CUtlString("%s.fmd", szPath); + + IFileHandle *pMetadataFile = filesystem->Open(szMeta, FILEMODE_READ); + if (!pMetadataFile) + return NULL; + const char *szMetadata = filesystem->ReadString(pMetadataFile); + filesystem->Close(pMetadataFile); + + + IJSONValue *pValue = JSONManager()->ReadString(szMetadata); + IJSONArray *pGlyphs = pValue->GetObject()->GetValue("glyphs")->GetArray(); + uint32_t uAtlas = m_pFonts->LoadTexture(szAtlas); + + CKotRenderFont *pFont = new CKotRenderFont; + pFont->m_pAtlas = pFont->m_pAtlas = m_pFonts->GetTexture(uAtlas); + uint32_t atlasWidth = pValue->GetObject()->GetValue("atlas")->GetObject()->GetValue("width")->GetNumberValue(); + uint32_t atlasHeight = pValue->GetObject()->GetValue("atlas")->GetObject()->GetValue("height")->GetNumberValue(); + + pFont->m_uGlyphCount = 0; + pFont->m_glyphs = (GlyphData_t*)V_malloc(sizeof(GlyphData_t)*pGlyphs->GetCount()); + for ( uint32_t i = 0; i < pGlyphs->GetCount(); i++ ) + { + GlyphData_t glyph = {}; + IJSONObject *pGlyph = pGlyphs->GetParameter(i)->GetObject(); + if (pGlyph->GetValue("atlasBounds") == NULL) + continue; + IJSONObject *pAtlasBounds = pGlyph->GetValue("atlasBounds")->GetObject(); + glyph.m_uCharacter = pGlyph->GetValue("unicode")->GetNumberValue(); + glyph.m_fX = pAtlasBounds->GetValue("left")->GetNumberValue()/atlasWidth; + glyph.m_fY = 1-(pAtlasBounds->GetValue("bottom")->GetNumberValue()/atlasHeight); + glyph.m_fWidth = ( + pAtlasBounds->GetValue("right")->GetNumberValue() + - pAtlasBounds->GetValue("left")->GetNumberValue() + ) / atlasWidth; + glyph.m_fHeight = ( + pAtlasBounds->GetValue("bottom")->GetNumberValue() + - pAtlasBounds->GetValue("top")->GetNumberValue() + ) / atlasHeight; + pFont->m_glyphs[pFont->m_uGlyphCount++] = glyph; + } + return pFont; + +} + +IKotUIBuffer *CKotUIManager::CreateBuffer( int iWidth, int iHeight ) +{ + CKotUIBuffer *pBuffer = new CKotUIBuffer; + pBuffer->m_pRenderContext = m_pRenderContext; + pBuffer->m_buffer = (uint32_t*)V_malloc(sizeof(uint32_t)*iWidth*iHeight); + V_memset(pBuffer->m_buffer, 0, sizeof(uint32_t)*iWidth*iHeight); + pBuffer->m_iWidth = iWidth; + pBuffer->m_iHeight = iHeight; + + pBuffer->m_pDataBuffer = m_pRenderContext->CreateStorageBuffer(sizeof(TextDrawData_t)*iWidth*iHeight); + return pBuffer; +} + +void CKotUIManager::DeleteBuffer( IKotUIBuffer *pBuffer ) +{ + +} + diff --git a/external/funnystdlib b/external/funnystdlib index 8f8343e..4a2e606 160000 --- a/external/funnystdlib +++ b/external/funnystdlib @@ -1 +1 @@ -Subproject commit 8f8343e2506a7ec51b8cb644e050f789614a803e +Subproject commit 4a2e606e2bf37fb1e5da2bcc4ba1d7709eee4d08 diff --git a/funnyassets/fonts/IBMPlexMono-Regular.fmd b/funnyassets/fonts/IBMPlexMono-Regular.fmd new file mode 100644 index 0000000..32aa92c --- /dev/null +++ b/funnyassets/fonts/IBMPlexMono-Regular.fmd @@ -0,0 +1 @@ +{"atlas":{"type":"msdf","distanceRange":2,"distanceRangeMiddle":0,"size":32.25,"width":264,"height":288,"yOrigin":"bottom","grid":{"cellWidth":22,"cellHeight":36,"columns":12,"rows":8,"originY":0.26356589147286824}},"metrics":{"emSize":1,"lineHeight":1.3,"ascender":1.0249999999999999,"descender":-0.27500000000000002,"underlineY":-0.17000000000000001,"underlineThickness":0.059999999999999998},"glyphs":[{"unicode":32,"advance":0.59999999999999998},{"unicode":33,"advance":0.59999999999999998,"planeBounds":{"left":-0.025581395348837219,"bottom":-0.26356589147286819,"right":0.62558139534883717,"top":0.82170542635658905},"atlasBounds":{"left":0.5,"bottom":252.5,"right":21.5,"top":287.5}},{"unicode":34,"advance":0.59999999999999998,"planeBounds":{"left":-0.025081395348837191,"bottom":-0.26356589147286819,"right":0.62608139534883722,"top":0.82170542635658905},"atlasBounds":{"left":22.5,"bottom":252.5,"right":43.5,"top":287.5}},{"unicode":35,"advance":0.59999999999999998,"planeBounds":{"left":-0.025581395348837192,"bottom":-0.26356589147286819,"right":0.62558139534883717,"top":0.82170542635658905},"atlasBounds":{"left":44.5,"bottom":252.5,"right":65.5,"top":287.5}},{"unicode":36,"advance":0.59999999999999998,"planeBounds":{"left":-0.024581395348837225,"bottom":-0.26356589147286819,"right":0.62658139534883717,"top":0.82170542635658905},"atlasBounds":{"left":66.5,"bottom":252.5,"right":87.5,"top":287.5}},{"unicode":37,"advance":0.59999999999999998,"planeBounds":{"left":-0.025581395348837205,"bottom":-0.26356589147286819,"right":0.62558139534883717,"top":0.82170542635658905},"atlasBounds":{"left":88.5,"bottom":252.5,"right":109.5,"top":287.5}},{"unicode":38,"advance":0.59999999999999998,"planeBounds":{"left":-0.0270813953488372,"bottom":-0.26356589147286819,"right":0.62408139534883722,"top":0.82170542635658905},"atlasBounds":{"left":110.5,"bottom":252.5,"right":131.5,"top":287.5}},{"unicode":39,"advance":0.59999999999999998,"planeBounds":{"left":-0.025581395348837192,"bottom":-0.26356589147286819,"right":0.62558139534883717,"top":0.82170542635658905},"atlasBounds":{"left":132.5,"bottom":252.5,"right":153.5,"top":287.5}},{"unicode":40,"advance":0.59999999999999998,"planeBounds":{"left":0.023918604651162783,"bottom":-0.26356589147286819,"right":0.67508139534883715,"top":0.82170542635658905},"atlasBounds":{"left":154.5,"bottom":252.5,"right":175.5,"top":287.5}},{"unicode":41,"advance":0.59999999999999998,"planeBounds":{"left":-0.075081395348837218,"bottom":-0.26356589147286819,"right":0.57608139534883718,"top":0.82170542635658905},"atlasBounds":{"left":176.5,"bottom":252.5,"right":197.5,"top":287.5}},{"unicode":42,"advance":0.59999999999999998,"planeBounds":{"left":-0.025581395348837219,"bottom":-0.26356589147286819,"right":0.62558139534883717,"top":0.82170542635658905},"atlasBounds":{"left":198.5,"bottom":252.5,"right":219.5,"top":287.5}},{"unicode":43,"advance":0.59999999999999998,"planeBounds":{"left":-0.025581395348837219,"bottom":-0.26356589147286819,"right":0.62558139534883717,"top":0.82170542635658905},"atlasBounds":{"left":220.5,"bottom":252.5,"right":241.5,"top":287.5}},{"unicode":44,"advance":0.59999999999999998,"planeBounds":{"left":-0.030581395348837193,"bottom":-0.26356589147286819,"right":0.62058139534883716,"top":0.82170542635658905},"atlasBounds":{"left":242.5,"bottom":252.5,"right":263.5,"top":287.5}},{"unicode":45,"advance":0.59999999999999998,"planeBounds":{"left":-0.025581395348837192,"bottom":-0.26356589147286819,"right":0.62558139534883717,"top":0.82170542635658905},"atlasBounds":{"left":0.5,"bottom":216.5,"right":21.5,"top":251.5}},{"unicode":46,"advance":0.59999999999999998,"planeBounds":{"left":-0.025581395348837219,"bottom":-0.26356589147286819,"right":0.62558139534883717,"top":0.82170542635658905},"atlasBounds":{"left":22.5,"bottom":216.5,"right":43.5,"top":251.5}},{"unicode":47,"advance":0.59999999999999998,"planeBounds":{"left":-0.025581395348837205,"bottom":-0.26356589147286819,"right":0.62558139534883717,"top":0.82170542635658905},"atlasBounds":{"left":44.5,"bottom":216.5,"right":65.5,"top":251.5}},{"unicode":48,"advance":0.59999999999999998,"planeBounds":{"left":-0.025581395348837219,"bottom":-0.26356589147286819,"right":0.62558139534883717,"top":0.82170542635658905},"atlasBounds":{"left":66.5,"bottom":216.5,"right":87.5,"top":251.5}},{"unicode":49,"advance":0.59999999999999998,"planeBounds":{"left":-0.022581395348837206,"bottom":-0.26356589147286819,"right":0.62858139534883717,"top":0.82170542635658905},"atlasBounds":{"left":88.5,"bottom":216.5,"right":109.5,"top":251.5}},{"unicode":50,"advance":0.59999999999999998,"planeBounds":{"left":-0.024581395348837191,"bottom":-0.26356589147286819,"right":0.62658139534883717,"top":0.82170542635658905},"atlasBounds":{"left":110.5,"bottom":216.5,"right":131.5,"top":251.5}},{"unicode":51,"advance":0.59999999999999998,"planeBounds":{"left":-0.042581395348837217,"bottom":-0.26356589147286819,"right":0.60858139534883715,"top":0.82170542635658905},"atlasBounds":{"left":132.5,"bottom":216.5,"right":153.5,"top":251.5}},{"unicode":52,"advance":0.59999999999999998,"planeBounds":{"left":-0.027581395348837228,"bottom":-0.26356589147286819,"right":0.62358139534883716,"top":0.82170542635658905},"atlasBounds":{"left":154.5,"bottom":216.5,"right":175.5,"top":251.5}},{"unicode":53,"advance":0.59999999999999998,"planeBounds":{"left":-0.022581395348837192,"bottom":-0.26356589147286819,"right":0.62858139534883717,"top":0.82170542635658905},"atlasBounds":{"left":176.5,"bottom":216.5,"right":197.5,"top":251.5}},{"unicode":54,"advance":0.59999999999999998,"planeBounds":{"left":-0.025581395348837192,"bottom":-0.26356589147286819,"right":0.62558139534883717,"top":0.82170542635658905},"atlasBounds":{"left":198.5,"bottom":216.5,"right":219.5,"top":251.5}},{"unicode":55,"advance":0.59999999999999998,"planeBounds":{"left":-0.02758139534883719,"bottom":-0.26356589147286819,"right":0.62358139534883716,"top":0.82170542635658905},"atlasBounds":{"left":220.5,"bottom":216.5,"right":241.5,"top":251.5}},{"unicode":56,"advance":0.59999999999999998,"planeBounds":{"left":-0.025581395348837178,"bottom":-0.26356589147286819,"right":0.62558139534883717,"top":0.82170542635658905},"atlasBounds":{"left":242.5,"bottom":216.5,"right":263.5,"top":251.5}},{"unicode":57,"advance":0.59999999999999998,"planeBounds":{"left":-0.025581395348837192,"bottom":-0.26356589147286819,"right":0.62558139534883717,"top":0.82170542635658905},"atlasBounds":{"left":0.5,"bottom":180.5,"right":21.5,"top":215.5}},{"unicode":58,"advance":0.59999999999999998,"planeBounds":{"left":-0.025581395348837219,"bottom":-0.26356589147286819,"right":0.62558139534883717,"top":0.82170542635658905},"atlasBounds":{"left":22.5,"bottom":180.5,"right":43.5,"top":215.5}},{"unicode":59,"advance":0.59999999999999998,"planeBounds":{"left":-0.030581395348837193,"bottom":-0.26356589147286819,"right":0.62058139534883716,"top":0.82170542635658905},"atlasBounds":{"left":44.5,"bottom":180.5,"right":65.5,"top":215.5}},{"unicode":60,"advance":0.59999999999999998,"planeBounds":{"left":-0.025581395348837205,"bottom":-0.26356589147286819,"right":0.62558139534883717,"top":0.82170542635658905},"atlasBounds":{"left":66.5,"bottom":180.5,"right":87.5,"top":215.5}},{"unicode":61,"advance":0.59999999999999998,"planeBounds":{"left":-0.025581395348837219,"bottom":-0.26356589147286819,"right":0.62558139534883717,"top":0.82170542635658905},"atlasBounds":{"left":88.5,"bottom":180.5,"right":109.5,"top":215.5}},{"unicode":62,"advance":0.59999999999999998,"planeBounds":{"left":-0.025581395348837205,"bottom":-0.26356589147286819,"right":0.62558139534883717,"top":0.82170542635658905},"atlasBounds":{"left":110.5,"bottom":180.5,"right":131.5,"top":215.5}},{"unicode":63,"advance":0.59999999999999998,"planeBounds":{"left":-0.032081395348837208,"bottom":-0.26356589147286819,"right":0.61908139534883722,"top":0.82170542635658905},"atlasBounds":{"left":132.5,"bottom":180.5,"right":153.5,"top":215.5}},{"unicode":64,"advance":0.59999999999999998,"planeBounds":{"left":-0.032081395348837194,"bottom":-0.26356589147286819,"right":0.61908139534883722,"top":0.82170542635658905},"atlasBounds":{"left":154.5,"bottom":180.5,"right":175.5,"top":215.5}},{"unicode":65,"advance":0.59999999999999998,"planeBounds":{"left":-0.025081395348837184,"bottom":-0.26356589147286819,"right":0.62608139534883722,"top":0.82170542635658905},"atlasBounds":{"left":176.5,"bottom":180.5,"right":197.5,"top":215.5}},{"unicode":66,"advance":0.59999999999999998,"planeBounds":{"left":-0.010081395348837176,"bottom":-0.26356589147286819,"right":0.64108139534883724,"top":0.82170542635658905},"atlasBounds":{"left":198.5,"bottom":180.5,"right":219.5,"top":215.5}},{"unicode":67,"advance":0.59999999999999998,"planeBounds":{"left":-0.021581395348837205,"bottom":-0.26356589147286819,"right":0.62958139534883717,"top":0.82170542635658905},"atlasBounds":{"left":220.5,"bottom":180.5,"right":241.5,"top":215.5}},{"unicode":68,"advance":0.59999999999999998,"planeBounds":{"left":-0.0060813953488371769,"bottom":-0.26356589147286819,"right":0.64508139534883724,"top":0.82170542635658905},"atlasBounds":{"left":242.5,"bottom":180.5,"right":263.5,"top":215.5}},{"unicode":69,"advance":0.59999999999999998,"planeBounds":{"left":-0.020581395348837205,"bottom":-0.26356589147286819,"right":0.63058139534883717,"top":0.82170542635658905},"atlasBounds":{"left":0.5,"bottom":144.5,"right":21.5,"top":179.5}},{"unicode":70,"advance":0.59999999999999998,"planeBounds":{"left":-0.015581395348837191,"bottom":-0.26356589147286819,"right":0.63558139534883717,"top":0.82170542635658905},"atlasBounds":{"left":22.5,"bottom":144.5,"right":43.5,"top":179.5}},{"unicode":71,"advance":0.59999999999999998,"planeBounds":{"left":-0.036581395348837191,"bottom":-0.26356589147286819,"right":0.61458139534883716,"top":0.82170542635658905},"atlasBounds":{"left":44.5,"bottom":144.5,"right":65.5,"top":179.5}},{"unicode":72,"advance":0.59999999999999998,"planeBounds":{"left":-0.025581395348837192,"bottom":-0.26356589147286819,"right":0.62558139534883717,"top":0.82170542635658905},"atlasBounds":{"left":66.5,"bottom":144.5,"right":87.5,"top":179.5}},{"unicode":73,"advance":0.59999999999999998,"planeBounds":{"left":-0.025581395348837205,"bottom":-0.26356589147286819,"right":0.62558139534883717,"top":0.82170542635658905},"atlasBounds":{"left":88.5,"bottom":144.5,"right":109.5,"top":179.5}},{"unicode":74,"advance":0.59999999999999998,"planeBounds":{"left":-0.048581395348837195,"bottom":-0.26356589147286819,"right":0.60258139534883726,"top":0.82170542635658905},"atlasBounds":{"left":110.5,"bottom":144.5,"right":131.5,"top":179.5}},{"unicode":75,"advance":0.59999999999999998,"planeBounds":{"left":0.0059186046511628234,"bottom":-0.26356589147286819,"right":0.65708139534883725,"top":0.82170542635658905},"atlasBounds":{"left":132.5,"bottom":144.5,"right":153.5,"top":179.5}},{"unicode":76,"advance":0.59999999999999998,"planeBounds":{"left":0.0019186046511628092,"bottom":-0.26356589147286819,"right":0.65308139534883725,"top":0.82170542635658905},"atlasBounds":{"left":154.5,"bottom":144.5,"right":175.5,"top":179.5}},{"unicode":77,"advance":0.59999999999999998,"planeBounds":{"left":-0.025581395348837233,"bottom":-0.26356589147286819,"right":0.62558139534883717,"top":0.82170542635658905},"atlasBounds":{"left":176.5,"bottom":144.5,"right":197.5,"top":179.5}},{"unicode":78,"advance":0.59999999999999998,"planeBounds":{"left":-0.025581395348837192,"bottom":-0.26356589147286819,"right":0.62558139534883717,"top":0.82170542635658905},"atlasBounds":{"left":198.5,"bottom":144.5,"right":219.5,"top":179.5}},{"unicode":79,"advance":0.59999999999999998,"planeBounds":{"left":-0.025581395348837219,"bottom":-0.26356589147286819,"right":0.62558139534883717,"top":0.82170542635658905},"atlasBounds":{"left":220.5,"bottom":144.5,"right":241.5,"top":179.5}},{"unicode":80,"advance":0.59999999999999998,"planeBounds":{"left":-0.0090813953488372186,"bottom":-0.26356589147286819,"right":0.64208139534883724,"top":0.82170542635658905},"atlasBounds":{"left":242.5,"bottom":144.5,"right":263.5,"top":179.5}},{"unicode":81,"advance":0.59999999999999998,"planeBounds":{"left":-0.025581395348837219,"bottom":-0.26356589147286819,"right":0.62558139534883717,"top":0.82170542635658905},"atlasBounds":{"left":0.5,"bottom":108.5,"right":21.5,"top":143.5}},{"unicode":82,"advance":0.59999999999999998,"planeBounds":{"left":-0.0060813953488372055,"bottom":-0.26356589147286819,"right":0.64508139534883724,"top":0.82170542635658905},"atlasBounds":{"left":22.5,"bottom":108.5,"right":43.5,"top":143.5}},{"unicode":83,"advance":0.59999999999999998,"planeBounds":{"left":-0.032081395348837208,"bottom":-0.26356589147286819,"right":0.61908139534883722,"top":0.82170542635658905},"atlasBounds":{"left":44.5,"bottom":108.5,"right":65.5,"top":143.5}},{"unicode":84,"advance":0.59999999999999998,"planeBounds":{"left":-0.025581395348837199,"bottom":-0.26356589147286819,"right":0.62558139534883717,"top":0.82170542635658905},"atlasBounds":{"left":66.5,"bottom":108.5,"right":87.5,"top":143.5}},{"unicode":85,"advance":0.59999999999999998,"planeBounds":{"left":-0.025581395348837192,"bottom":-0.26356589147286819,"right":0.62558139534883717,"top":0.82170542635658905},"atlasBounds":{"left":88.5,"bottom":108.5,"right":109.5,"top":143.5}},{"unicode":86,"advance":0.59999999999999998,"planeBounds":{"left":-0.025581395348837226,"bottom":-0.26356589147286819,"right":0.62558139534883717,"top":0.82170542635658905},"atlasBounds":{"left":110.5,"bottom":108.5,"right":131.5,"top":143.5}},{"unicode":87,"advance":0.59999999999999998,"planeBounds":{"left":-0.025581395348837192,"bottom":-0.26356589147286819,"right":0.62558139534883717,"top":0.82170542635658905},"atlasBounds":{"left":132.5,"bottom":108.5,"right":153.5,"top":143.5}},{"unicode":88,"advance":0.59999999999999998,"planeBounds":{"left":-0.025081395348837212,"bottom":-0.26356589147286819,"right":0.62608139534883722,"top":0.82170542635658905},"atlasBounds":{"left":154.5,"bottom":108.5,"right":175.5,"top":143.5}},{"unicode":89,"advance":0.59999999999999998,"planeBounds":{"left":-0.025581395348837219,"bottom":-0.26356589147286819,"right":0.62558139534883717,"top":0.82170542635658905},"atlasBounds":{"left":176.5,"bottom":108.5,"right":197.5,"top":143.5}},{"unicode":90,"advance":0.59999999999999998,"planeBounds":{"left":-0.025581395348837185,"bottom":-0.26356589147286819,"right":0.62558139534883717,"top":0.82170542635658905},"atlasBounds":{"left":198.5,"bottom":108.5,"right":219.5,"top":143.5}},{"unicode":91,"advance":0.59999999999999998,"planeBounds":{"left":0.039418604651162779,"bottom":-0.26356589147286819,"right":0.69058139534883722,"top":0.82170542635658905},"atlasBounds":{"left":220.5,"bottom":108.5,"right":241.5,"top":143.5}},{"unicode":92,"advance":0.59999999999999998,"planeBounds":{"left":-0.025581395348837205,"bottom":-0.26356589147286819,"right":0.62558139534883717,"top":0.82170542635658905},"atlasBounds":{"left":242.5,"bottom":108.5,"right":263.5,"top":143.5}},{"unicode":93,"advance":0.59999999999999998,"planeBounds":{"left":-0.090581395348837218,"bottom":-0.26356589147286819,"right":0.56058139534883722,"top":0.82170542635658905},"atlasBounds":{"left":0.5,"bottom":72.5,"right":21.5,"top":107.5}},{"unicode":94,"advance":0.59999999999999998,"planeBounds":{"left":-0.025581395348837185,"bottom":-0.26356589147286819,"right":0.62558139534883717,"top":0.82170542635658905},"atlasBounds":{"left":22.5,"bottom":72.5,"right":43.5,"top":107.5}},{"unicode":95,"advance":0.59999999999999998,"planeBounds":{"left":-0.025581395348837205,"bottom":-0.26356589147286819,"right":0.62558139534883717,"top":0.82170542635658905},"atlasBounds":{"left":44.5,"bottom":72.5,"right":65.5,"top":107.5}},{"unicode":96,"advance":0.59999999999999998,"planeBounds":{"left":-0.059581395348837191,"bottom":-0.26356589147286819,"right":0.59158139534883725,"top":0.82170542635658905},"atlasBounds":{"left":66.5,"bottom":72.5,"right":87.5,"top":107.5}},{"unicode":97,"advance":0.59999999999999998,"planeBounds":{"left":-0.017581395348837178,"bottom":-0.26356589147286819,"right":0.63358139534883717,"top":0.82170542635658905},"atlasBounds":{"left":88.5,"bottom":72.5,"right":109.5,"top":107.5}},{"unicode":98,"advance":0.59999999999999998,"planeBounds":{"left":-0.0080813953488372055,"bottom":-0.26356589147286819,"right":0.64308139534883724,"top":0.82170542635658905},"atlasBounds":{"left":110.5,"bottom":72.5,"right":131.5,"top":107.5}},{"unicode":99,"advance":0.59999999999999998,"planeBounds":{"left":-0.025581395348837205,"bottom":-0.26356589147286819,"right":0.62558139534883717,"top":0.82170542635658905},"atlasBounds":{"left":132.5,"bottom":72.5,"right":153.5,"top":107.5}},{"unicode":100,"advance":0.59999999999999998,"planeBounds":{"left":-0.043081395348837204,"bottom":-0.26356589147286819,"right":0.60808139534883721,"top":0.82170542635658905},"atlasBounds":{"left":154.5,"bottom":72.5,"right":175.5,"top":107.5}},{"unicode":101,"advance":0.59999999999999998,"planeBounds":{"left":-0.025581395348837192,"bottom":-0.26356589147286819,"right":0.62558139534883717,"top":0.82170542635658905},"atlasBounds":{"left":176.5,"bottom":72.5,"right":197.5,"top":107.5}},{"unicode":102,"advance":0.59999999999999998,"planeBounds":{"left":-0.017081395348837205,"bottom":-0.26356589147286819,"right":0.63408139534883723,"top":0.82170542635658905},"atlasBounds":{"left":198.5,"bottom":72.5,"right":219.5,"top":107.5}},{"unicode":103,"advance":0.59999999999999998,"planeBounds":{"left":-0.011581395348837212,"bottom":-0.26356589147286819,"right":0.63958139534883718,"top":0.82170542635658905},"atlasBounds":{"left":220.5,"bottom":72.5,"right":241.5,"top":107.5}},{"unicode":104,"advance":0.59999999999999998,"planeBounds":{"left":-0.022581395348837206,"bottom":-0.26356589147286819,"right":0.62858139534883717,"top":0.82170542635658905},"atlasBounds":{"left":242.5,"bottom":72.5,"right":263.5,"top":107.5}},{"unicode":105,"advance":0.59999999999999998,"planeBounds":{"left":0.00041860465116280921,"bottom":-0.26356589147286819,"right":0.65158139534883719,"top":0.82170542635658905},"atlasBounds":{"left":0.5,"bottom":36.5,"right":21.5,"top":71.5}},{"unicode":106,"advance":0.59999999999999998,"planeBounds":{"left":-0.05158139534883719,"bottom":-0.26356589147286819,"right":0.59958139534883725,"top":0.82170542635658905},"atlasBounds":{"left":22.5,"bottom":36.5,"right":43.5,"top":71.5}},{"unicode":107,"advance":0.59999999999999998,"planeBounds":{"left":0.013918604651162809,"bottom":-0.26356589147286819,"right":0.66508139534883726,"top":0.82170542635658905},"atlasBounds":{"left":44.5,"bottom":36.5,"right":65.5,"top":71.5}},{"unicode":108,"advance":0.59999999999999998,"planeBounds":{"left":-0.025581395348837192,"bottom":-0.26356589147286819,"right":0.62558139534883717,"top":0.82170542635658905},"atlasBounds":{"left":66.5,"bottom":36.5,"right":87.5,"top":71.5}},{"unicode":109,"advance":0.59999999999999998,"planeBounds":{"left":-0.025581395348837192,"bottom":-0.26356589147286819,"right":0.62558139534883717,"top":0.82170542635658905},"atlasBounds":{"left":88.5,"bottom":36.5,"right":109.5,"top":71.5}},{"unicode":110,"advance":0.59999999999999998,"planeBounds":{"left":-0.022581395348837206,"bottom":-0.26356589147286819,"right":0.62858139534883717,"top":0.82170542635658905},"atlasBounds":{"left":110.5,"bottom":36.5,"right":131.5,"top":71.5}},{"unicode":111,"advance":0.59999999999999998,"planeBounds":{"left":-0.025581395348837205,"bottom":-0.26356589147286819,"right":0.62558139534883717,"top":0.82170542635658905},"atlasBounds":{"left":132.5,"bottom":36.5,"right":153.5,"top":71.5}},{"unicode":112,"advance":0.59999999999999998,"planeBounds":{"left":-0.0080813953488372055,"bottom":-0.26356589147286819,"right":0.64308139534883724,"top":0.82170542635658905},"atlasBounds":{"left":154.5,"bottom":36.5,"right":175.5,"top":71.5}},{"unicode":113,"advance":0.59999999999999998,"planeBounds":{"left":-0.043081395348837204,"bottom":-0.26356589147286819,"right":0.60808139534883721,"top":0.82170542635658905},"atlasBounds":{"left":176.5,"bottom":36.5,"right":197.5,"top":71.5}},{"unicode":114,"advance":0.59999999999999998,"planeBounds":{"left":-0.007581395348837219,"bottom":-0.26356589147286819,"right":0.64358139534883718,"top":0.82170542635658905},"atlasBounds":{"left":198.5,"bottom":36.5,"right":219.5,"top":71.5}},{"unicode":115,"advance":0.59999999999999998,"planeBounds":{"left":-0.030081395348837192,"bottom":-0.26356589147286819,"right":0.62108139534883722,"top":0.82170542635658905},"atlasBounds":{"left":220.5,"bottom":36.5,"right":241.5,"top":71.5}},{"unicode":116,"advance":0.59999999999999998,"planeBounds":{"left":-0.043081395348837176,"bottom":-0.26356589147286819,"right":0.60808139534883721,"top":0.82170542635658905},"atlasBounds":{"left":242.5,"bottom":36.5,"right":263.5,"top":71.5}},{"unicode":117,"advance":0.59999999999999998,"planeBounds":{"left":-0.028581395348837205,"bottom":-0.26356589147286819,"right":0.62258139534883716,"top":0.82170542635658905},"atlasBounds":{"left":0.5,"bottom":0.5,"right":21.5,"top":35.5}},{"unicode":118,"advance":0.59999999999999998,"planeBounds":{"left":-0.025581395348837192,"bottom":-0.26356589147286819,"right":0.62558139534883717,"top":0.82170542635658905},"atlasBounds":{"left":22.5,"bottom":0.5,"right":43.5,"top":35.5}},{"unicode":119,"advance":0.59999999999999998,"planeBounds":{"left":-0.025581395348837219,"bottom":-0.26356589147286819,"right":0.62558139534883717,"top":0.82170542635658905},"atlasBounds":{"left":44.5,"bottom":0.5,"right":65.5,"top":35.5}},{"unicode":120,"advance":0.59999999999999998,"planeBounds":{"left":-0.025081395348837219,"bottom":-0.26356589147286819,"right":0.62608139534883722,"top":0.82170542635658905},"atlasBounds":{"left":66.5,"bottom":0.5,"right":87.5,"top":35.5}},{"unicode":121,"advance":0.59999999999999998,"planeBounds":{"left":-0.025581395348837212,"bottom":-0.26356589147286819,"right":0.62558139534883717,"top":0.82170542635658905},"atlasBounds":{"left":88.5,"bottom":0.5,"right":109.5,"top":35.5}},{"unicode":122,"advance":0.59999999999999998,"planeBounds":{"left":-0.025581395348837205,"bottom":-0.26356589147286819,"right":0.62558139534883717,"top":0.82170542635658905},"atlasBounds":{"left":110.5,"bottom":0.5,"right":131.5,"top":35.5}},{"unicode":123,"advance":0.59999999999999998,"planeBounds":{"left":-0.025581395348837192,"bottom":-0.26356589147286819,"right":0.62558139534883717,"top":0.82170542635658905},"atlasBounds":{"left":132.5,"bottom":0.5,"right":153.5,"top":35.5}},{"unicode":124,"advance":0.59999999999999998,"planeBounds":{"left":-0.025581395348837192,"bottom":-0.26356589147286819,"right":0.62558139534883717,"top":0.82170542635658905},"atlasBounds":{"left":154.5,"bottom":0.5,"right":175.5,"top":35.5}},{"unicode":125,"advance":0.59999999999999998,"planeBounds":{"left":-0.025581395348837192,"bottom":-0.26356589147286819,"right":0.62558139534883717,"top":0.82170542635658905},"atlasBounds":{"left":176.5,"bottom":0.5,"right":197.5,"top":35.5}},{"unicode":126,"advance":0.59999999999999998,"planeBounds":{"left":-0.025581395348837226,"bottom":-0.26356589147286819,"right":0.62558139534883717,"top":0.82170542635658905},"atlasBounds":{"left":198.5,"bottom":0.5,"right":219.5,"top":35.5}}],"kerning":[]} diff --git a/funnyassets/fonts/IBMPlexMono-Regular.fontdata b/funnyassets/fonts/IBMPlexMono-Regular.fontdata deleted file mode 100644 index c2541cb..0000000 --- a/funnyassets/fonts/IBMPlexMono-Regular.fontdata +++ /dev/null @@ -1,2 +0,0 @@ -12 8 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ - diff --git a/funnyassets/fonts/IBMPlexMono-Regular.png b/funnyassets/fonts/IBMPlexMono-Regular.png index dfef87f..39753be 100644 Binary files a/funnyassets/fonts/IBMPlexMono-Regular.png and b/funnyassets/fonts/IBMPlexMono-Regular.png differ diff --git a/funnyassets/shaders/kottui.shader b/funnyassets/shaders/kottui.shader new file mode 100644 index 0000000..21bdfac --- /dev/null +++ b/funnyassets/shaders/kottui.shader @@ -0,0 +1,85 @@ + +#include "macros.hlsl" +COMMON { + struct PS_INPUT + { + float4 m_vPosition: SV_POSITION; + float2 m_vUV: TEXCOORD0; + uint m_uFont; + } + struct TextDrawData_t + { + float2 m_vTexcoordOffset; + float2 m_vTexcoordSize; + + float2 m_vPos; + float2 m_vSize; + float4 m_vFGColor; + float4 m_vBGColor; + } + + StructuredBuffer g_textData: register( t0 ); + cbuffer ScreenData_t: register( b1 ) + { + float2 g_vScreenSize; + } + Texture2D g_atlas: register( t2 ); + SamplerState g_atlasSampler: register(s3); +} +VS +{ + struct VS_INPUT + { + float2 m_vPosition: POSITION; + } + + + PS_INPUT vsMain( VS_INPUT input, uint uInstance: SV_InstanceID, uint uBaseInstance: SV_StartInstanceLocation ) + { + uint uInstance = uBaseInstance + uInstance; + float2 position = input.m_vPosition; + position*=g_textData[uInstance].m_vSize; + position+=g_textData[uInstance].m_vPos; + position/=g_vScreenSize; + position.y = 1-position.y; + position*=2; + position-=1; + float2 uv = input.m_vPosition; + uv.y = 1-uv.y; + uv*=g_textData[uInstance].m_vTexcoordSize; + uv+=g_textData[uInstance].m_vTexcoordOffset; + PS_INPUT output = {}; + output.m_vPosition = float4(position, 0, 1); + output.m_vUV = uv; + return output; + } + + +} +PS +{ + struct PS_OUTPUT + { + float4 m_vAlbedo: SV_Target0; + } + + float ScreenPixelRange( float2 uv ) + { + uint uWidth, uHeight; + g_atlas.GetDimensions(uWidth, uHeight); + float2 vUnitRange = 2.0/float2(uWidth, uHeight); + float2 vScreenTexSize = 1.0/fwidth(uv); + return max(0.5*dot(vUnitRange, vScreenTexSize), 1); + } + + PS_OUTPUT psMain( PS_INPUT input ) + { + PS_OUTPUT output = {}; + float4 vMsd = g_atlas.Sample(g_atlasSampler, input.m_vUV.xy); + float fSd = median3(vMsd.x, vMsd.y, vMsd.z); + float fScreenPixelDistance = ScreenPixelRange(input.m_vUV)*(fSd-0.5); + float fOpacity = clamp(fScreenPixelDistance+0.5, 0.0, 1.0); + output.m_vAlbedo = fOpacity; + return output; + } +} diff --git a/funnyassets/shaders/mesh_raster.shader b/funnyassets/shaders/mesh_raster.shader index 337cd65..c4561f0 100644 --- a/funnyassets/shaders/mesh_raster.shader +++ b/funnyassets/shaders/mesh_raster.shader @@ -90,8 +90,7 @@ PS if ( data.m_material.m_uAlbedo != -1 ) { output.m_vAlbedo = g_textures[data.m_material.m_uAlbedo] - .Sample(g_textureSampler, input.m_vTexCoord.xy) - * data.m_material.m_vAlbedoColor; + .Sample(g_textureSampler, input.m_vTexCoord.xy); } else { diff --git a/game/client/assetmgr.cpp b/game/client/assetmgr.cpp index 2d16d9d..a2369fb 100644 --- a/game/client/assetmgr.cpp +++ b/game/client/assetmgr.cpp @@ -10,6 +10,7 @@ #define MAX_SHADER_COUNT 1024 #define MAX_PHYSICS_COUNT 1024 +#define MAX_FONT_COUNT 128 template class CAssetArc diff --git a/game/client/entitysystem.cpp b/game/client/entitysystem.cpp index b3dbf33..a7f16a9 100644 --- a/game/client/entitysystem.cpp +++ b/game/client/entitysystem.cpp @@ -240,14 +240,10 @@ void CEntitySystem::NetRecvPacket( NetPacket_t *pPacket ) } break; case k_EMessage_EntityDeleted: - C_BaseEntity **ppEntities = m_pEntities; - for ( int i = 0; i < MAX_EDICTS; i++ ) - { - if (ppEntities[i] == NULL) - { - - } + { + DestroyEntityByIndex((uint32_t)pPlayerPacket->m_deleteEntity.m_uIndex); } + break; default: break; } diff --git a/game/client/game.cpp b/game/client/game.cpp index 42c8b63..6574e26 100644 --- a/game/client/game.cpp +++ b/game/client/game.cpp @@ -38,6 +38,7 @@ IEngineBridge *EngineBridge() EXPOSE_INTERFACE_FN(EngineBridge, IEngineBridge, ENGINE_BRIDGE_INTERFACE_VERSION) +static IKotUIBuffer *s_pUIBuffer; void CFunnyGameBridge::Init() { @@ -70,6 +71,22 @@ void CFunnyGameBridge::Init() g_pPhysicsWorld = g_pPhysics->CreateWorld(); g_pHumanDeviceManager->SetDefaultInput(g_pMainInput); + + CreateInterfaceFn fnEngineFactory = Sys_GetFactory("engine"); + g_pKotUI = (IKotUIManager*)fnEngineFactory(KOT_UI_INTEFACE_VERSION, NULL); + + g_pKotUI->ConnectInterface(g_pRenderContext, RENDER_CONTEXT_INTERFACE_VERSION); + g_pKotUI->Init(); + IKotRenderFont *pFont = g_pKotUI->LoadFont("game/core/fonts/IBMPlexMono-Regular"); + s_pUIBuffer = g_pKotUI->CreateBuffer(40, 30); + s_pUIBuffer->SetTextFont(pFont); + s_pUIBuffer->SetTextSize(, int iX) + s_pUIBuffer->Move(0, 0); + s_pUIBuffer->Printf("hello %f", 20.0); + s_pUIBuffer->Move(1, 0); + s_pUIBuffer->Printf("hello %f", 40.0); + s_pUIBuffer->Move(2, 0); + s_pUIBuffer->Printf("hello %f", 40.0); } void CFunnyGameBridge::Tick( float fDelta ) @@ -166,6 +183,7 @@ void CFunnyGameBridge::Frame( float fDelta ) EntitySystem()->NetSendThink(pCurrentServer); } g_pWorldRenderer->Frame(fDelta); + s_pUIBuffer->Draw(g_pMainWindow->GetOutputImage()); } void CFunnyGameBridge::Shutdown() diff --git a/game/client/milmoba/player.cpp b/game/client/milmoba/player.cpp index 25beb07..55d4cc7 100644 --- a/game/client/milmoba/player.cpp +++ b/game/client/milmoba/player.cpp @@ -32,7 +32,7 @@ void C_MOBAPlayer::Think( float fDelta ) g_pWorldRenderer->SetCameraPosition(vCameraPos); Quat vCameraRot; glm_euler_yxz_quat((vec3){m_fPitch, m_fYaw, 0}, *(versor*)&vCameraRot); - g_pWorldRenderer->SetCameraRotation(vCameraRot); + //g_pWorldRenderer->SetCameraRotation(vCameraRot); } BaseClass::Think(fDelta); }; diff --git a/game/client/worldrender.cpp b/game/client/worldrender.cpp index c13d73c..e9fa751 100644 --- a/game/client/worldrender.cpp +++ b/game/client/worldrender.cpp @@ -298,7 +298,12 @@ void CFunnyWorldRenderer::Frame( float fDelta ) m_pRasterCommandList->SetViewport(0, 0, uWidth, uHeight, 0, 1); m_pRasterCommandList->SetScissors(0, 0, uWidth, uHeight); m_pRasterCommandList->SetClearColor(0, 0, 0, 0, 0); + m_pRasterCommandList->SetClearColor(1, 0, 0, 0, 0); + m_pRasterCommandList->SetClearColor(2, 0, 0, 0, 0); m_pRasterCommandList->SetClearDepth(1); + m_pRasterCommandList->SetLoadStoreModes(0, LOAD_MODE_CLEAR, STORE_MODE_STORE); + m_pRasterCommandList->SetLoadStoreModes(1, LOAD_MODE_CLEAR, STORE_MODE_STORE); + m_pRasterCommandList->SetLoadStoreModes(2, LOAD_MODE_CLEAR, STORE_MODE_STORE); uint32_t uTotalMeshes = 0; uint32_t u = 0; for ( auto mesh: m_pMeshes) diff --git a/game/shared/game.h b/game/shared/game.h index 5c92d98..fa7c974 100644 --- a/game/shared/game.h +++ b/game/shared/game.h @@ -40,6 +40,8 @@ extern EngineConsts_t *g_pEngineConstants; extern IPhysics *g_pPhysics; extern IPhysicsWorld *g_pPhysicsWorld; +extern IKotUIManager *g_pKotUI; + #define FUNNY_SECURE_PORT 27015 #define FUNNY_QUERY_PORT 27016 diff --git a/materialsystem/vulkan/commands/draw.cpp b/materialsystem/vulkan/commands/draw.cpp index d80fefa..21833c8 100644 --- a/materialsystem/vulkan/commands/draw.cpp +++ b/materialsystem/vulkan/commands/draw.cpp @@ -38,11 +38,22 @@ DECLARE_VULKAN_COMMAND(Begin) VkRenderingAttachmentInfo a = {}; a.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO; a.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; - a.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; - a.clearValue.color.float32[0] = i.m_fClearColor[0]; - a.clearValue.color.float32[1] = i.m_fClearColor[1]; - a.clearValue.color.float32[2] = i.m_fClearColor[2]; - a.clearValue.color.float32[3] = i.m_fClearColor[3]; + switch( i.m_eLoadMode ) + { + case LOAD_MODE_DONT_CARE: + a.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; + break; + case LOAD_MODE_LOAD: + a.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD; + break; + case LOAD_MODE_CLEAR: + a.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; + a.clearValue.color.float32[0] = i.m_fClearColor[0]; + a.clearValue.color.float32[1] = i.m_fClearColor[1]; + a.clearValue.color.float32[2] = i.m_fClearColor[2]; + a.clearValue.color.float32[3] = i.m_fClearColor[3]; + break; + } a.storeOp = VK_ATTACHMENT_STORE_OP_STORE; a.imageView = ((CVkImage*)VulkanGetObject(i.m_stImage, iCurrentFrame))->m_imageView; attachments.AppendTail(a); diff --git a/materialsystem/vulkan/material.cpp b/materialsystem/vulkan/material.cpp index 7814f0c..ce355e2 100644 --- a/materialsystem/vulkan/material.cpp +++ b/materialsystem/vulkan/material.cpp @@ -76,6 +76,17 @@ void CVkMaterial::PSSetTextureArray( uint32_t uSet, ITextureArray *pArray ) SetShaderResource(0, uSet, pArray); } +void CVkMaterial::PSSetTexture( uint32_t uRegister, IImage *pImage ) +{ + SetShaderResource(uRegister, 0, pImage); +} + +void CVkMaterial::PSSetSampler( uint32_t uRegister, ISampler *pImage ) +{ + SetShaderResource(uRegister, 0, pImage); +} + + void CVkMaterial::SetShaderResource( uint32_t uRegister, uint32_t uSet, IRenderingObject *pObject) { if ( m_pVkShader->m_setLayouts.GetSize() == 0 ) @@ -84,6 +95,8 @@ void CVkMaterial::SetShaderResource( uint32_t uRegister, uint32_t uSet, IRenderi IRenderingObject *pVkObject; CVkBuffer *pBuffer; CVkTextureArray *pArray; + CVkImage *pImage; + CVkSampler *pSampler; }; pVkObject = pObject; if (dynamic_cast(pObject)) @@ -101,6 +114,36 @@ void CVkMaterial::SetShaderResource( uint32_t uRegister, uint32_t uSet, IRenderi stInfo.range = pBuffer->m_nSize; vkUpdateDescriptorSets(m_pVkShader->m_hDevice, 1, &write, 0, 0); } + if (dynamic_cast(pObject)) + { + VkWriteDescriptorSet write = {}; + VkDescriptorImageInfo stInfo = {}; + write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + write.dstSet = m_hSets[uSet]; + write.dstBinding = uRegister; + write.dstArrayElement = 0; + write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; + write.descriptorCount = 1; + write.pImageInfo = &stInfo; + stInfo.imageView = pImage->m_imageView; + stInfo.imageLayout = VK_IMAGE_LAYOUT_GENERAL; + vkUpdateDescriptorSets(m_pVkShader->m_hDevice, 1, &write, 0, 0); + + } + if (dynamic_cast(pObject)) + { + VkWriteDescriptorSet write = {}; + VkDescriptorImageInfo stInfo = {}; + write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + write.dstSet = m_hSets[uSet]; + write.dstBinding = uRegister; + write.dstArrayElement = 0; + write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; + write.descriptorCount = 1; + write.pImageInfo = &stInfo; + stInfo.sampler = pSampler->m_sampler; + vkUpdateDescriptorSets(m_pVkShader->m_hDevice, 1, &write, 0, 0); + } if (dynamic_cast(pObject)) { VkWriteDescriptorSet writes[2] = {}; diff --git a/materialsystem/vulkan/rendercommandlist.cpp b/materialsystem/vulkan/rendercommandlist.cpp index a1dba4a..bdccb97 100644 --- a/materialsystem/vulkan/rendercommandlist.cpp +++ b/materialsystem/vulkan/rendercommandlist.cpp @@ -36,6 +36,15 @@ void CVkRenderCommandList::SetClearColor( uint32_t uIndex, float r, float g, flo pOutput->m_fClearColor[3] = a; } +void CVkRenderCommandList::SetLoadStoreModes( uint32_t uIndex, ELoadMode eLoadMode, EStoreMode eStoreMode ) +{ + SwitchRenderingStage(RENDERING_STAGE_SETUP_RASTER); + VulkanRenderOutput_t *pOutput = FindOrCreateRenderOutput(uIndex); + pOutput->m_eLoadMode = eLoadMode; + pOutput->m_eStoreMode = eStoreMode; + +} + void CVkRenderCommandList::SetDepthTarget( IImage *pDepth ) { SwitchRenderingStage(RENDERING_STAGE_SETUP_RASTER); diff --git a/materialsystem/vulkan/rendercontext.cpp b/materialsystem/vulkan/rendercontext.cpp index 9d026c0..a1de245 100644 --- a/materialsystem/vulkan/rendercontext.cpp +++ b/materialsystem/vulkan/rendercontext.cpp @@ -325,6 +325,11 @@ uint32_t CVkBuffer::GetSize() return m_nSize; } +void CVkSampler::SetDebugName( const char *szName ) +{ + +}; + CVkTextureArray::~CVkTextureArray() { @@ -357,7 +362,6 @@ void CVkTextureArray::Build() samplerInfo.mipLodBias = 0.0f; samplerInfo.minLod = 0.0f; samplerInfo.maxLod = VK_LOD_CLAMP_NONE; - vkCreateSampler(m_hDevice, &samplerInfo, nullptr, &m_hSampler); LoadTexture("game/core/textures/error.png"); @@ -427,6 +431,11 @@ uint32_t CVkTextureArray::GetTextureID( const char *szPath ) { } +IImage *CVkTextureArray::GetTexture( uint32_t uTextureID ) +{ + return m_pImages[uTextureID]; +} + void CVkTextureArray::UnloadTexture( uint32_t uTextureID ) { @@ -477,6 +486,8 @@ public: virtual ITextureArray *CreateTextureArray() override; virtual void DestroyTextureArray() override; + + virtual ISampler *GetDefaultSampler() override; private: VkPhysicalDevice SelectPhysicalDevice( CUtlVector physicalDevices ); CUtlVector GetDeviceExtensions(); @@ -498,6 +509,8 @@ private: CUtlVector m_scheduledRemovalTextureArrays; CUtlVector m_scheduledRemovalBuffers; CUtlVector m_scheduledRemovalImages; + + CVkSampler m_defaultSampler; }; EXPOSE_INTERFACE(CVkRenderContext, IRenderContext, RENDER_CONTEXT_INTERFACE_VERSION); @@ -677,12 +690,18 @@ void CVkRenderContext::DestroyTextureArray() { } +ISampler *CVkRenderContext::GetDefaultSampler() +{ + return &m_defaultSampler; + +} VkPipelineLayout g_pLibraryEmptyLayout; static IVkCommandBuffer *s_pPresentCommandBuffer; void CVkRenderContext::Init() { + VkResult r; int nExtensionCount; @@ -834,6 +853,23 @@ void CVkRenderContext::Init() m_pCommandBufferManager = (IVkCommandBufferManager*)CreateInterface(VULKAN_COMMAND_BUFFER_MANAGER_INTERFACE_NAME, NULL); m_pCommandBufferManager->SetVulkanHandlers(s_vkInstance, s_vkDevice); m_pCommandBufferManager->Init(); + + VkSamplerCreateInfo samplerInfo = {}; + samplerInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; + samplerInfo.magFilter = VK_FILTER_LINEAR; + samplerInfo.minFilter = VK_FILTER_LINEAR; + samplerInfo.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT; + samplerInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT; + samplerInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT; + samplerInfo.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK; + samplerInfo.unnormalizedCoordinates = VK_FALSE; + samplerInfo.compareEnable = VK_FALSE; + samplerInfo.compareOp = VK_COMPARE_OP_ALWAYS; + samplerInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR; + samplerInfo.mipLodBias = 0.0f; + samplerInfo.minLod = 0.0f; + samplerInfo.maxLod = VK_LOD_CLAMP_NONE; + vkCreateSampler(s_vkDevice, &samplerInfo, nullptr, &m_defaultSampler.m_sampler); } void CVkRenderContext::Frame( float fDeltaTime ) @@ -1059,8 +1095,8 @@ formatPicked: pImage->m_eImageType = IMAGE_TYPE_2D; pImage->m_eMultisampleType = MULTISAMPLE_TYPE_NONE; pImage->m_eFormat = IMAGE_FORMAT_BGRA8_UNORM; - pImage->m_nHeight = 1280; - pImage->m_nWidth = 720; + pImage->m_nHeight = pWindow->GetRenderWidth(); + pImage->m_nWidth = pWindow->GetRenderHeight(); pImage->m_ePreferredLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; pImage->CreateImageView(); window.m_images[i] = pImage; diff --git a/materialsystem/vulkan/vulkan_state.h b/materialsystem/vulkan/vulkan_state.h index 3c58c19..48a580f 100644 --- a/materialsystem/vulkan/vulkan_state.h +++ b/materialsystem/vulkan/vulkan_state.h @@ -225,6 +225,13 @@ public: uint32_t m_nSize; }; +class CVkSampler: public ISampler +{ +public: + virtual void SetDebugName( const char *szName ) override; + VkSampler m_sampler; +}; + class CVkPipelineLibrary { public: @@ -349,6 +356,7 @@ public: virtual void SetDebugName( const char *szName ) override; virtual uint32_t LoadTexture( const char *szPath ) override; virtual uint32_t GetTextureID( const char *szPath ) override; + virtual IImage *GetTexture( uint32_t uTextureID ) override; virtual void UnloadTexture( uint32_t uTextureID ) override; void Frame(); @@ -374,7 +382,10 @@ public: virtual void PSSetShaderResource( uint32_t uRegister, IRenderingObject *pResource ) override; virtual void PSSetConstantsBuffer( uint32_t uRegister, IBuffer *pConstants ) override; + virtual void PSSetTextureArray( uint32_t uSet, ITextureArray *pArray ) override; + virtual void PSSetTexture( uint32_t uRegister, IImage *pImage ) override; + virtual void PSSetSampler( uint32_t uRegister, ISampler *pImage ) override; CVkShader *m_pVkShader; CUtlVector m_hSets; @@ -402,6 +413,7 @@ struct VulkanMaterialCommandBuffer_t }; + enum EVkFrameObjectType_t { FRAME_OBJECT_TYPE_SINGLE, @@ -438,6 +450,7 @@ public: virtual void SetRenderTarget( uint32_t uIndex, IImage *pImage ) override; virtual void SetClearColor( uint32_t uIndex, float r, float g, float b, float a ) override; + virtual void SetLoadStoreModes( uint32_t uIndex, ELoadMode eLoadMode, EStoreMode eStoreMode ) override; virtual void SetDepthTarget( IImage *pDepth ) override; virtual void SetClearDepth( float fVal ) override; diff --git a/public/cl_entity.h b/public/cl_entity.h deleted file mode 100644 index e69de29..0000000 diff --git a/public/imouseinput.h b/public/imouseinput.h deleted file mode 100644 index e69de29..0000000 diff --git a/public/jsonformat.h b/public/jsonformat.h deleted file mode 100644 index e69de29..0000000 diff --git a/public/kottui/kottui.h b/public/kottui/kottui.h index 1980b58..0565fa1 100644 --- a/public/kottui/kottui.h +++ b/public/kottui/kottui.h @@ -5,15 +5,19 @@ #include "../materialsystem/igamewindow.h" #include "tier2/iappsystem.h" -abstract_class IRenderFont +abstract_class IKotRenderFont { public: - virtual IImage *GetAtlas(); - virtual bool IsLetterPresent( uint32_t letter ); - virtual float GetLetterX( uint32_t letter ); - virtual float GetLetterY( uint32_t letter ); - virtual float GetWidthX( uint32_t letter ); - virtual float GetWidthY( uint32_t letter ); + virtual IImage *GetAtlas() = 0; + virtual bool IsLetterPresent( uint32_t letter ) = 0; + virtual float GetLetterX( uint32_t letter ) = 0; + virtual float GetLetterY( uint32_t letter ) = 0; + virtual float GetWidth( uint32_t letter ) = 0; + virtual float GetHeight( uint32_t letter ) = 0; + + virtual bool IsMono() = 0; + virtual uint32_t GetLetterWidth() = 0; + virtual uint32_t GetLetterHeight() = 0; }; abstract_class IKotUIBuffer @@ -29,18 +33,21 @@ public: virtual void PutChar( char c ) = 0; virtual void Printf(const char *szFormat, ...) = 0; - virtual void Draw( IRenderContext *pRenderContext ); + virtual void Draw( IImage *pImage ) = 0; virtual void SetTextSize( int iY, int iX ) = 0; - virtual void SetTextFont( IRenderFont *pFont ) = 0; + virtual void SetTextFont( IKotRenderFont *pFont ) = 0; }; -abstract_class IKotUIManager: public IAppSystem +abstract_class IKotUIManager: public IAppSystem2 { public: - virtual void CreateBuffer( int iWidth, int iHeight ) = 0; + virtual IKotRenderFont *LoadFont( const char *szPath ) = 0; + virtual IKotUIBuffer *CreateBuffer( int iWidth, int iHeight ) = 0; + virtual void DeleteBuffer( IKotUIBuffer *pBuffer ) = 0; }; + IKotUIManager *KotUIManager(); #define KOT_UI_INTEFACE_VERSION "KotUI001" diff --git a/public/materialsystem/imaterialsystem.h b/public/materialsystem/imaterialsystem.h index efd9b8c..0df4aef 100644 --- a/public/materialsystem/imaterialsystem.h +++ b/public/materialsystem/imaterialsystem.h @@ -166,12 +166,18 @@ public: virtual EMultisampleType GetMultisampleType() = 0; }; +abstract_class ISampler : public IRenderingObject +{ + +}; + abstract_class ITextureArray: public IRenderingObject { public: virtual void Build() = 0; virtual uint32_t LoadTexture( const char *szPath ) = 0; virtual uint32_t GetTextureID( const char *szPath ) = 0; + virtual IImage *GetTexture( uint32_t uTextureID ) = 0; virtual void UnloadTexture( uint32_t uTextureID ) = 0; }; @@ -250,6 +256,8 @@ public: virtual void VSSetConstantsBuffer( uint32_t uRegister, IBuffer *pImage ) = 0; virtual void PSSetConstantsBuffer( uint32_t uRegister, IBuffer *pImage ) = 0; virtual void PSSetTextureArray( uint32_t uSet, ITextureArray *pArray ) = 0; + virtual void PSSetTexture( uint32_t uRegister, IImage *pImage ) = 0; + virtual void PSSetSampler( uint32_t uRegister, ISampler *pImage ) = 0; }; abstract_class IRenderCommandList @@ -259,6 +267,7 @@ public: virtual void SetRenderTarget( uint32_t uIndex, IImage *pImage ) = 0; virtual void SetClearColor( uint32_t uIndex, float r, float g, float b, float a ) = 0; + virtual void SetLoadStoreModes( uint32_t uIndex, ELoadMode eLoadMode, EStoreMode eStoreMode ) = 0; virtual void SetDepthTarget( IImage *pDepth ) = 0; virtual void SetClearDepth( float fVal ) = 0; @@ -321,6 +330,8 @@ public: virtual ITextureArray *CreateTextureArray() = 0; virtual void DestroyTextureArray() = 0; + + virtual ISampler *GetDefaultSampler() = 0; }; #define RENDER_CONTEXT_INTERFACE_VERSION "RenderContext001" diff --git a/public/sv_entity.h b/public/sv_entity.h deleted file mode 100644 index e69de29..0000000 diff --git a/shadercompiler/psMain b/shadercompiler/psMain index b4520cf..facea72 100644 Binary files a/shadercompiler/psMain and b/shadercompiler/psMain differ