mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-15 16:44:36 +00:00
extra draw gui
add the extra functions for drawing gui elements RoundedRectangle: All draw rect functions now pass through roundedRectangle which uses a shader and can draw borders, and rounds the corners Draw thick line: draws a line thicker than 1 pixel, uses a geometry shader to do this Draw Circle: Draws a circle with a border parameter.
This commit is contained in:
parent
39c2cc09fc
commit
c9d70de609
9 changed files with 654 additions and 170 deletions
|
|
@ -34,7 +34,7 @@
|
||||||
#include "gfx/gfxPrimitiveBuffer.h"
|
#include "gfx/gfxPrimitiveBuffer.h"
|
||||||
#include "gfx/primBuilder.h"
|
#include "gfx/primBuilder.h"
|
||||||
#include "gfx/gfxDebugEvent.h"
|
#include "gfx/gfxDebugEvent.h"
|
||||||
|
#include "materials/shaderData.h"
|
||||||
#include "math/mPolyhedron.impl.h"
|
#include "math/mPolyhedron.impl.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -90,6 +90,33 @@ void GFXDrawUtil::_setupStateBlocks()
|
||||||
rectFill.setZReadWrite(false);
|
rectFill.setZReadWrite(false);
|
||||||
rectFill.setBlend(true, GFXBlendSrcAlpha, GFXBlendInvSrcAlpha);
|
rectFill.setBlend(true, GFXBlendSrcAlpha, GFXBlendInvSrcAlpha);
|
||||||
mRectFillSB = mDevice->createStateBlock(rectFill);
|
mRectFillSB = mDevice->createStateBlock(rectFill);
|
||||||
|
|
||||||
|
// Find ShaderData
|
||||||
|
ShaderData* shaderData;
|
||||||
|
mRoundRectangleShader = Sim::findObject("RoundedRectangleGUI", shaderData) ? shaderData->getShader() : NULL;
|
||||||
|
if (!mRoundRectangleShader)
|
||||||
|
{
|
||||||
|
Con::errorf("GFXDrawUtil - could not find Rounded Rectangle shader");
|
||||||
|
}
|
||||||
|
// Create ShaderConstBuffer and Handles
|
||||||
|
mRoundRectangleShaderConsts = mRoundRectangleShader->allocConstBuffer();
|
||||||
|
|
||||||
|
mCircleShader = Sim::findObject("CircularGUI", shaderData) ? shaderData->getShader() : NULL;
|
||||||
|
if (!mCircleShader)
|
||||||
|
{
|
||||||
|
Con::errorf("GFXDrawUtil - could not find circle shader");
|
||||||
|
}
|
||||||
|
// Create ShaderConstBuffer and Handles
|
||||||
|
mCircleShaderConsts = mCircleShader->allocConstBuffer();
|
||||||
|
|
||||||
|
mThickLineShader = Sim::findObject("ThickLineGUI", shaderData) ? shaderData->getShader() : NULL;
|
||||||
|
if (!mThickLineShader)
|
||||||
|
{
|
||||||
|
Con::errorf("GFXDrawUtil - could not find Thick line shader");
|
||||||
|
}
|
||||||
|
// Create ShaderConstBuffer and Handles
|
||||||
|
mThickLineShaderConsts = mThickLineShader->allocConstBuffer();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
@ -513,57 +540,94 @@ void GFXDrawUtil::drawRect( const Point2F &upperLeft, const Point2F &lowerRight,
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Draw Rectangle Fill
|
// Draw Rectangle Fill
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void GFXDrawUtil::drawRectFill( const RectF &rect, const ColorI &color )
|
void GFXDrawUtil::drawRectFill(const RectF& rect, const ColorI& color, const F32& borderSize, const ColorI& borderColor)
|
||||||
{
|
{
|
||||||
drawRectFill(rect.point, Point2F(rect.extent.x + rect.point.x - 1, rect.extent.y + rect.point.y - 1), color );
|
drawRoundedRect(0.0f, rect.point, Point2F(rect.extent.x + rect.point.x - 1, rect.extent.y + rect.point.y - 1), color, borderSize, borderColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GFXDrawUtil::drawRectFill( const Point2I &upperLeft, const Point2I &lowerRight, const ColorI &color )
|
void GFXDrawUtil::drawRectFill(const Point2I& upperLeft, const Point2I& lowerRight, const ColorI& color, const F32& borderSize, const ColorI& borderColor)
|
||||||
{
|
{
|
||||||
drawRectFill(Point2F((F32)upperLeft.x, (F32)upperLeft.y), Point2F((F32)lowerRight.x, (F32)lowerRight.y), color);
|
drawRoundedRect(0.0f, Point2F((F32)upperLeft.x, (F32)upperLeft.y), Point2F((F32)lowerRight.x, (F32)lowerRight.y), color, borderSize, borderColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GFXDrawUtil::drawRectFill( const RectI &rect, const ColorI &color )
|
void GFXDrawUtil::drawRectFill(const RectI& rect, const ColorI& color, const F32& borderSize, const ColorI& borderColor)
|
||||||
{
|
{
|
||||||
drawRectFill(rect.point, Point2I(rect.extent.x + rect.point.x - 1, rect.extent.y + rect.point.y - 1), color );
|
drawRoundedRect(0.0f, rect.point, Point2I(rect.extent.x + rect.point.x - 1, rect.extent.y + rect.point.y - 1), color, borderSize, borderColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GFXDrawUtil::drawRectFill( const Point2F &upperLeft, const Point2F &lowerRight, const ColorI &color )
|
void GFXDrawUtil::drawRectFill(const Point2F& upperLeft, const Point2F& lowerRight, const ColorI& color, const F32& borderSize,const ColorI& borderColor)
|
||||||
|
{
|
||||||
|
// draw a rounded rect with 0 radiuse.
|
||||||
|
drawRoundedRect(0.0f, upperLeft, lowerRight, color, borderSize, borderColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GFXDrawUtil::drawRoundedRect(const F32& cornerRadius, const RectI& rect, const ColorI& color, const F32& borderSize, const ColorI& borderColor)
|
||||||
|
{
|
||||||
|
drawRoundedRect(cornerRadius, rect.point, Point2I(rect.extent.x + rect.point.x - 1, rect.extent.y + rect.point.y - 1), color, borderSize, borderColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GFXDrawUtil::drawRoundedRect(const F32& cornerRadius, const Point2I& upperLeft, const Point2I& lowerRight, const ColorI& color, const F32& borderSize, const ColorI& borderColor)
|
||||||
|
{
|
||||||
|
drawRoundedRect(cornerRadius, Point2F((F32)upperLeft.x, (F32)upperLeft.y), Point2F((F32)lowerRight.x, (F32)lowerRight.y), color, borderSize, borderColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GFXDrawUtil::drawRoundedRect(const F32& cornerRadius,
|
||||||
|
const Point2F& upperLeft,
|
||||||
|
const Point2F& lowerRight,
|
||||||
|
const ColorI& color,
|
||||||
|
const F32& borderSize,
|
||||||
|
const ColorI& borderColor)
|
||||||
{
|
{
|
||||||
//
|
|
||||||
// Convert Box a----------x
|
|
||||||
// | |
|
|
||||||
// x----------b
|
|
||||||
// Into Quad
|
|
||||||
// v0---------v1
|
|
||||||
// | a x |
|
|
||||||
// | |
|
|
||||||
// | x b |
|
|
||||||
// v2---------v3
|
|
||||||
//
|
|
||||||
|
|
||||||
// NorthWest and NorthEast facing offset vectors
|
// NorthWest and NorthEast facing offset vectors
|
||||||
Point2F nw(-0.5,-0.5); /* \ */
|
Point2F nw(-0.5, -0.5); /* \ */
|
||||||
Point2F ne(0.5,-0.5); /* / */
|
Point2F ne(0.5, -0.5); /* / */
|
||||||
|
|
||||||
GFXVertexBufferHandle<GFXVertexPCT> verts(mDevice, 4, GFXBufferTypeVolatile);
|
GFXVertexBufferHandle<GFXVertexPCT> verts(mDevice, 4, GFXBufferTypeVolatile);
|
||||||
verts.lock();
|
verts.lock();
|
||||||
|
|
||||||
F32 ulOffset = 0.5f - mDevice->getFillConventionOffset();
|
F32 ulOffset = 0.5f - mDevice->getFillConventionOffset();
|
||||||
|
|
||||||
verts[0].point.set( upperLeft.x+nw.x + ulOffset, upperLeft.y+nw.y + ulOffset, 0.0f );
|
verts[0].point.set(upperLeft.x + nw.x + ulOffset, upperLeft.y + nw.y + ulOffset, 0.0f);
|
||||||
verts[1].point.set( lowerRight.x + ne.x + ulOffset, upperLeft.y + ne.y + ulOffset, 0.0f);
|
verts[1].point.set(lowerRight.x + ne.x + ulOffset, upperLeft.y + ne.y + ulOffset, 0.0f);
|
||||||
verts[2].point.set( upperLeft.x - ne.x + ulOffset, lowerRight.y - ne.y + ulOffset, 0.0f);
|
verts[2].point.set(upperLeft.x - ne.x + ulOffset, lowerRight.y - ne.y + ulOffset, 0.0f);
|
||||||
verts[3].point.set( lowerRight.x - nw.x + ulOffset, lowerRight.y - nw.y + ulOffset, 0.0f);
|
verts[3].point.set(lowerRight.x - nw.x + ulOffset, lowerRight.y - nw.y + ulOffset, 0.0f);
|
||||||
for (S32 i = 0; i < 4; i++)
|
for (S32 i = 0; i < 4; i++)
|
||||||
verts[i].color = color;
|
verts[i].color = color;
|
||||||
|
|
||||||
verts.unlock();
|
verts.unlock();
|
||||||
|
mDevice->setVertexBuffer(verts);
|
||||||
|
|
||||||
mDevice->setStateBlock(mRectFillSB);
|
mDevice->setStateBlock(mRectFillSB);
|
||||||
mDevice->setVertexBuffer( verts );
|
|
||||||
mDevice->setupGenericShaders();
|
Point2F topLeftCorner(upperLeft.x + nw.x + ulOffset, upperLeft.y + nw.y + ulOffset);
|
||||||
mDevice->drawPrimitive( GFXTriangleStrip, 0, 2 );
|
Point2F bottomRightCorner(lowerRight.x - nw.x + ulOffset, lowerRight.y - nw.y + ulOffset);
|
||||||
|
|
||||||
|
/*mDevice->setupGenericShaders();*/
|
||||||
|
GFX->setShader(mRoundRectangleShader);
|
||||||
|
GFX->setShaderConstBuffer(mRoundRectangleShaderConsts);
|
||||||
|
|
||||||
|
MatrixF tempMatrix = GFX->getProjectionMatrix() * GFX->getViewMatrix() * GFX->getWorldMatrix();
|
||||||
|
Point2F size((F32)(bottomRightCorner.x - topLeftCorner.x), (F32)(bottomRightCorner.y - topLeftCorner.y));
|
||||||
|
|
||||||
|
F32 minExtent = mMin(size.x, size.y);
|
||||||
|
|
||||||
|
F32 radius = cornerRadius;
|
||||||
|
if ((minExtent * 0.5) < radius)
|
||||||
|
{
|
||||||
|
radius = mClampF(radius, 0.0f, (minExtent * 0.5));
|
||||||
|
}
|
||||||
|
|
||||||
|
mRoundRectangleShaderConsts->set(mRoundRectangleShader->getShaderConstHandle("$modelView"), tempMatrix, GFXSCT_Float4x4);
|
||||||
|
mRoundRectangleShaderConsts->setSafe(mRoundRectangleShader->getShaderConstHandle("$radius"), radius);
|
||||||
|
mRoundRectangleShaderConsts->setSafe(mRoundRectangleShader->getShaderConstHandle("$sizeUni"), size);
|
||||||
|
mRoundRectangleShaderConsts->setSafe(mRoundRectangleShader->getShaderConstHandle("$borderSize"), borderSize);
|
||||||
|
mRoundRectangleShaderConsts->setSafe(mRoundRectangleShader->getShaderConstHandle("$borderCol"), borderColor);
|
||||||
|
|
||||||
|
Point2F rectCenter((F32)(topLeftCorner.x + (size.x / 2.0)), (F32)(topLeftCorner.y + (size.y / 2.0)));
|
||||||
|
mRoundRectangleShaderConsts->setSafe(mRoundRectangleShader->getShaderConstHandle("$rectCenter"), rectCenter);
|
||||||
|
|
||||||
|
mDevice->drawPrimitive(GFXTriangleStrip, 0, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GFXDrawUtil::draw2DSquare( const Point2F &screenPoint, F32 width, F32 spinAngle )
|
void GFXDrawUtil::draw2DSquare( const Point2F &screenPoint, F32 width, F32 spinAngle )
|
||||||
|
|
@ -608,7 +672,73 @@ void GFXDrawUtil::draw2DSquare( const Point2F &screenPoint, F32 width, F32 spinA
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Draw Line
|
// Draw Circle : FILL
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void GFXDrawUtil::drawCircleFill(const RectI& rect, const ColorI& color, F32 radius, const F32& borderSize, const ColorI& borderColor)
|
||||||
|
{
|
||||||
|
drawCircleFill(rect.point, Point2I(rect.extent.x + rect.point.x - 1, rect.extent.y + rect.point.y - 1), color, radius, borderSize, borderColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GFXDrawUtil::drawCircleFill(const Point2I& upperLeft, const Point2I& lowerRight, const ColorI& color, F32 radius, const F32& borderSize, const ColorI& borderColor)
|
||||||
|
{
|
||||||
|
drawCircleFill(Point2F((F32)upperLeft.x, (F32)upperLeft.y), Point2F((F32)lowerRight.x, (F32)lowerRight.y), color, radius, borderSize, borderColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GFXDrawUtil::drawCircleFill(const Point2F& upperLeft, const Point2F& lowerRight, const ColorI& color, F32 radius, const F32& borderSize, const ColorI& borderColor)
|
||||||
|
{
|
||||||
|
// NorthWest and NorthEast facing offset vectors
|
||||||
|
Point2F nw(-0.5, -0.5); /* \ */
|
||||||
|
Point2F ne(0.5, -0.5); /* / */
|
||||||
|
|
||||||
|
GFXVertexBufferHandle<GFXVertexPCT> verts(mDevice, 4, GFXBufferTypeVolatile);
|
||||||
|
verts.lock();
|
||||||
|
|
||||||
|
F32 ulOffset = 0.5f - mDevice->getFillConventionOffset();
|
||||||
|
|
||||||
|
verts[0].point.set(upperLeft.x + nw.x + ulOffset, upperLeft.y + nw.y + ulOffset, 0.0f);
|
||||||
|
verts[1].point.set(lowerRight.x + ne.x + ulOffset, upperLeft.y + ne.y + ulOffset, 0.0f);
|
||||||
|
verts[2].point.set(upperLeft.x - ne.x + ulOffset, lowerRight.y - ne.y + ulOffset, 0.0f);
|
||||||
|
verts[3].point.set(lowerRight.x - nw.x + ulOffset, lowerRight.y - nw.y + ulOffset, 0.0f);
|
||||||
|
for (S32 i = 0; i < 4; i++)
|
||||||
|
verts[i].color = color;
|
||||||
|
|
||||||
|
verts.unlock();
|
||||||
|
mDevice->setVertexBuffer(verts);
|
||||||
|
|
||||||
|
mDevice->setStateBlock(mRectFillSB);
|
||||||
|
|
||||||
|
Point2F topLeftCorner(upperLeft.x + nw.x + ulOffset, upperLeft.y + nw.y + ulOffset);
|
||||||
|
Point2F bottomRightCorner(lowerRight.x - nw.x + ulOffset, lowerRight.y - nw.y + ulOffset);
|
||||||
|
|
||||||
|
/*mDevice->setupGenericShaders();*/
|
||||||
|
GFX->setShader(mCircleShader);
|
||||||
|
GFX->setShaderConstBuffer(mCircleShaderConsts);
|
||||||
|
|
||||||
|
MatrixF tempMatrix = GFX->getProjectionMatrix() * GFX->getViewMatrix() * GFX->getWorldMatrix();
|
||||||
|
Point2F size((F32)(bottomRightCorner.x - topLeftCorner.x), (F32)(bottomRightCorner.y - topLeftCorner.y));
|
||||||
|
|
||||||
|
Point2F rectCenter((F32)(topLeftCorner.x + (size.x / 2.0)), (F32)(topLeftCorner.y + (size.y / 2.0)));
|
||||||
|
mCircleShaderConsts->setSafe(mCircleShader->getShaderConstHandle("$rectCenter"), rectCenter);
|
||||||
|
|
||||||
|
F32 minExtent = mMin(size.x, size.y);
|
||||||
|
F32 shaderRadius = radius;
|
||||||
|
|
||||||
|
if ((minExtent * 0.5) < shaderRadius)
|
||||||
|
{
|
||||||
|
shaderRadius = mClampF(radius, 0.0f, (minExtent * 0.5));
|
||||||
|
}
|
||||||
|
|
||||||
|
mCircleShaderConsts->set(mCircleShader->getShaderConstHandle("$modelView"), tempMatrix, GFXSCT_Float4x4);
|
||||||
|
mCircleShaderConsts->setSafe(mCircleShader->getShaderConstHandle("$radius"), shaderRadius);
|
||||||
|
mCircleShaderConsts->setSafe(mCircleShader->getShaderConstHandle("$sizeUni"), size);
|
||||||
|
mCircleShaderConsts->setSafe(mCircleShader->getShaderConstHandle("$borderSize"), borderSize);
|
||||||
|
mCircleShaderConsts->setSafe(mCircleShader->getShaderConstHandle("$borderCol"), borderColor);
|
||||||
|
|
||||||
|
mDevice->drawPrimitive(GFXTriangleStrip, 0, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Draw Lines : Single Pixel
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void GFXDrawUtil::drawLine( const Point3F &startPt, const Point3F &endPt, const ColorI &color )
|
void GFXDrawUtil::drawLine( const Point3F &startPt, const Point3F &endPt, const ColorI &color )
|
||||||
{
|
{
|
||||||
|
|
@ -648,6 +778,55 @@ void GFXDrawUtil::drawLine( F32 x1, F32 y1, F32 z1, F32 x2, F32 y2, F32 z2, cons
|
||||||
mDevice->drawPrimitive( GFXLineList, 0, 1 );
|
mDevice->drawPrimitive( GFXLineList, 0, 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Draw Lines : Thick
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void GFXDrawUtil::drawThickLine(const Point2I& startPt, const Point2I& endPt, const ColorI& color, const F32& thickness)
|
||||||
|
{
|
||||||
|
drawThickLine(startPt.x, startPt.y, 0.0f, endPt.x, endPt.y, 0.0f, color, thickness);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GFXDrawUtil::drawThickLine(const Point2F& startPt, const Point2F& endPt, const ColorI& color, const F32& thickness)
|
||||||
|
{
|
||||||
|
drawThickLine(startPt.x, startPt.y, 0.0f, endPt.x, endPt.y, 0.0f, color, thickness);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GFXDrawUtil::drawThickLine(F32 x1, F32 y1, F32 z1, F32 x2, F32 y2, F32 z2, const ColorI& color, const F32& thickness)
|
||||||
|
{
|
||||||
|
// less than 2 just draw an ordinary line... why you ever here....
|
||||||
|
if (thickness < 2.0f)
|
||||||
|
{
|
||||||
|
drawLine(x1, y1, z1, x2, y2, z2, color);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
GFXVertexBufferHandle<GFXVertexPCT> verts(mDevice, 2, GFXBufferTypeVolatile);
|
||||||
|
verts.lock();
|
||||||
|
|
||||||
|
verts[0].point.set(x1, y1, z1);
|
||||||
|
verts[1].point.set(x2, y2, z2);
|
||||||
|
verts[0].color = color;
|
||||||
|
verts[1].color = color;
|
||||||
|
|
||||||
|
verts.unlock();
|
||||||
|
|
||||||
|
mDevice->setVertexBuffer(verts);
|
||||||
|
mDevice->setStateBlock(mRectFillSB);
|
||||||
|
GFX->setShader(mThickLineShader);
|
||||||
|
GFX->setShaderConstBuffer(mThickLineShaderConsts);
|
||||||
|
|
||||||
|
MatrixF tempMatrix = GFX->getProjectionMatrix() * GFX->getViewMatrix() * GFX->getWorldMatrix();
|
||||||
|
mThickLineShaderConsts->set(mThickLineShader->getShaderConstHandle("$modelView"), tempMatrix, GFXSCT_Float4x4);
|
||||||
|
mThickLineShaderConsts->setSafe(mThickLineShader->getShaderConstHandle("$thickness"), thickness);
|
||||||
|
|
||||||
|
const Point2I& resolution = GFX->getActiveRenderTarget()->getSize();
|
||||||
|
Point2F TargetSize(1.0 / (F32)resolution.x, 1.0 / (F32)resolution.y);
|
||||||
|
|
||||||
|
mThickLineShaderConsts->setSafe(mThickLineShader->getShaderConstHandle("$oneOverViewport"), TargetSize);
|
||||||
|
|
||||||
|
mDevice->drawPrimitive(GFXLineList, 0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// 3D World Draw Misc
|
// 3D World Draw Misc
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -46,22 +46,36 @@ public:
|
||||||
~GFXDrawUtil();
|
~GFXDrawUtil();
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Draw Rectangles
|
// Draw Rectangles : OUTLINE
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void drawRect( const Point2F &upperLeft, const Point2F &lowerRight, const ColorI &color );
|
void drawRect(const Point2F& upperLeft, const Point2F& lowerRight, const ColorI& color);
|
||||||
void drawRect( const RectF &rect, const ColorI &color );
|
void drawRect(const RectF& rect, const ColorI& color);
|
||||||
void drawRect( const Point2I &upperLeft, const Point2I &lowerRight, const ColorI &color );
|
void drawRect(const Point2I& upperLeft, const Point2I& lowerRight, const ColorI& color);
|
||||||
void drawRect( const RectI &rect, const ColorI &color );
|
void drawRect(const RectI& rect, const ColorI& color);
|
||||||
|
|
||||||
void drawRectFill( const Point2F &upperL, const Point2F &lowerR, const ColorI &color );
|
|
||||||
void drawRectFill( const RectF &rect, const ColorI &color );
|
|
||||||
void drawRectFill( const Point2I &upperLeft, const Point2I &lowerRight, const ColorI &color );
|
|
||||||
void drawRectFill( const RectI &rect, const ColorI &color );
|
|
||||||
|
|
||||||
void draw2DSquare( const Point2F &screenPoint, F32 width, F32 spinAngle = 0.0f );
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Draw Lines
|
// Draw Rectangles : FILL
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void drawRectFill(const Point2F& upperL, const Point2F& lowerR, const ColorI& color, const F32& borderSize = 0.0f, const ColorI& borderColor = ColorI(0, 0, 0, 0));
|
||||||
|
void drawRectFill(const RectF& rect, const ColorI& color, const F32& borderSize = 0.0f, const ColorI& borderColor = ColorI(0, 0, 0, 0));
|
||||||
|
void drawRectFill(const Point2I& upperLeft, const Point2I& lowerRight, const ColorI& color, const F32& borderSize = 0.0f, const ColorI& borderColor = ColorI(0, 0, 0, 0));
|
||||||
|
void drawRectFill(const RectI& rect, const ColorI& color, const F32& borderSize = 0.0f, const ColorI& borderColor = ColorI(0, 0, 0, 0));
|
||||||
|
void drawRoundedRect(const F32& cornerRadius, const RectI& rect, const ColorI& color, const F32& borderSize = 0.0f, const ColorI& borderColor = ColorI(0, 0, 0, 0));
|
||||||
|
void drawRoundedRect(const F32& cornerRadius, const Point2I& upperLeft, const Point2I& lowerRight, const ColorI& color, const F32& borderSize = 0.0f, const ColorI& borderColor = ColorI(0, 0, 0, 0));
|
||||||
|
void drawRoundedRect(const F32& cornerRadius, const Point2F& upperLeft, const Point2F& lowerRight, const ColorI& color, const F32& borderSize = 0.0f, const ColorI& borderColor = ColorI(0, 0, 0, 0));
|
||||||
|
|
||||||
|
void draw2DSquare(const Point2F& screenPoint, F32 width, F32 spinAngle = 0.0f);
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Draw Circle : FILL
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void drawCircleFill(const RectI& rect, const ColorI& color, F32 radius, const F32& borderSize = 0.0f, const ColorI& borderColor = ColorI(0, 0, 0, 0));
|
||||||
|
void drawCircleFill(const Point2I& upperLeft, const Point2I& lowerRight, const ColorI& color, F32 radius, const F32& borderSize = 0.0f, const ColorI& borderColor = ColorI(0, 0, 0, 0));
|
||||||
|
void drawCircleFill(const Point2F& upperLeft, const Point2F& lowerRight, const ColorI& color, F32 radius, const F32& borderSize = 0.0f, const ColorI& borderColor = ColorI(0, 0, 0, 0));
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Draw Lines : Single Pixel
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void drawLine( const Point3F &startPt, const Point3F &endPt, const ColorI &color );
|
void drawLine( const Point3F &startPt, const Point3F &endPt, const ColorI &color );
|
||||||
void drawLine( const Point2F &startPt, const Point2F &endPt, const ColorI &color );
|
void drawLine( const Point2F &startPt, const Point2F &endPt, const ColorI &color );
|
||||||
|
|
@ -69,6 +83,13 @@ public:
|
||||||
void drawLine( F32 x1, F32 y1, F32 x2, F32 y2, const ColorI &color );
|
void drawLine( F32 x1, F32 y1, F32 x2, F32 y2, const ColorI &color );
|
||||||
void drawLine( F32 x1, F32 y1, F32 z1, F32 x2, F32 y2, F32 z2, const ColorI &color );
|
void drawLine( F32 x1, F32 y1, F32 z1, F32 x2, F32 y2, F32 z2, const ColorI &color );
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Draw Lines : Thick
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void drawThickLine(const Point2I& startPt, const Point2I& endPt, const ColorI& color, const F32& thickness);
|
||||||
|
void drawThickLine(const Point2F& startPt, const Point2F& endPt, const ColorI& color, const F32& thickness);
|
||||||
|
void drawThickLine(F32 x1, F32 y1, F32 z1, F32 x2, F32 y2, F32 z2, const ColorI& color, const F32& thickness);
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Draw Text
|
// Draw Text
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
@ -176,6 +197,19 @@ protected:
|
||||||
GFXStateBlockRef mRectFillSB;
|
GFXStateBlockRef mRectFillSB;
|
||||||
|
|
||||||
FontRenderBatcher* mFontRenderBatcher;
|
FontRenderBatcher* mFontRenderBatcher;
|
||||||
|
|
||||||
|
// Expanded shaders
|
||||||
|
// rounded rectangle.
|
||||||
|
GFXShaderRef mRoundRectangleShader;
|
||||||
|
GFXShaderConstBufferRef mRoundRectangleShaderConsts;
|
||||||
|
|
||||||
|
// thick line.
|
||||||
|
GFXShaderRef mCircleShader;
|
||||||
|
GFXShaderConstBufferRef mCircleShaderConsts;
|
||||||
|
|
||||||
|
// thick line.
|
||||||
|
GFXShaderRef mThickLineShader;
|
||||||
|
GFXShaderConstBufferRef mThickLineShaderConsts;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _GFX_GFXDRAWER_H_
|
#endif // _GFX_GFXDRAWER_H_
|
||||||
|
|
|
||||||
|
|
@ -134,45 +134,6 @@ void GuiShaderEditor::onPreRender()
|
||||||
setUpdate();
|
setUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiShaderEditor::drawThickLine(const Point2I& pt1, const Point2I& pt2, U32 thickness, ColorI col1, ColorI col2)
|
|
||||||
{
|
|
||||||
Point2F dir = Point2F(pt2.x - pt1.x, pt2.y - pt1.y);
|
|
||||||
if (dir == Point2F::Zero)
|
|
||||||
return;
|
|
||||||
|
|
||||||
Point2F unitDir = dir / mSqrt(dir.x * dir.x + dir.y * dir.y);
|
|
||||||
Point2F unitPerp(-unitDir.y, unitDir.x);
|
|
||||||
Point2F offset = (thickness / 2.0f) * unitPerp;
|
|
||||||
|
|
||||||
GFX->setStateBlock(mDefaultGuiSB);
|
|
||||||
|
|
||||||
Point2F lT = Point2F(pt1.x, pt1.y) + offset;
|
|
||||||
Point2F lB = Point2F(pt1.x, pt1.y) - offset;
|
|
||||||
Point2F rT = Point2F(pt2.x, pt2.y) + offset;
|
|
||||||
Point2F rB = Point2F(pt2.x, pt2.y) - offset;
|
|
||||||
|
|
||||||
|
|
||||||
PrimBuild::begin(GFXTriangleStrip, 4);
|
|
||||||
|
|
||||||
// top left.
|
|
||||||
PrimBuild::color(col1);
|
|
||||||
PrimBuild::vertex2f(lT.x, lT.y);
|
|
||||||
|
|
||||||
// bottom left.
|
|
||||||
PrimBuild::color(col1);
|
|
||||||
PrimBuild::vertex2f(lB.x, lB.y);
|
|
||||||
|
|
||||||
// top right.
|
|
||||||
PrimBuild::color(col2);
|
|
||||||
PrimBuild::vertex2f(rT.x, rT.y);
|
|
||||||
|
|
||||||
// bottom right.
|
|
||||||
PrimBuild::color(col2);
|
|
||||||
PrimBuild::vertex2f(rB.x, rB.y);
|
|
||||||
|
|
||||||
PrimBuild::end();
|
|
||||||
}
|
|
||||||
|
|
||||||
void GuiShaderEditor::renderNodes(Point2I offset, const RectI& updateRect)
|
void GuiShaderEditor::renderNodes(Point2I offset, const RectI& updateRect)
|
||||||
{
|
{
|
||||||
// Save the current clip rect
|
// Save the current clip rect
|
||||||
|
|
@ -224,17 +185,14 @@ void GuiShaderEditor::renderNodes(Point2I offset, const RectI& updateRect)
|
||||||
if (node->mSelected)
|
if (node->mSelected)
|
||||||
border = mProfile->mBorderColorSEL;
|
border = mProfile->mBorderColorSEL;
|
||||||
|
|
||||||
RectI socketRect(pos, Point2I(mNodeSize, mNodeSize));
|
|
||||||
drawer->drawRect(socketRect, border);
|
|
||||||
socketRect.inset(1, 1);
|
|
||||||
|
|
||||||
ColorI fill = mProfile->mFillColor;
|
ColorI fill = mProfile->mFillColor;
|
||||||
if (hasConnection(input))
|
if (hasConnection(input))
|
||||||
{
|
{
|
||||||
fill = ColorI::WHITE;
|
fill = ColorI::WHITE;
|
||||||
}
|
}
|
||||||
|
|
||||||
drawer->drawRectFill(socketRect, fill);
|
RectI socketRect(pos, Point2I(mNodeSize, mNodeSize));
|
||||||
|
drawer->drawCircleFill(socketRect, fill, mNodeSize / 2, 2.0f, border);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (NodeOutput* output : node->mOutputNodes)
|
for (NodeOutput* output : node->mOutputNodes)
|
||||||
|
|
@ -246,9 +204,8 @@ void GuiShaderEditor::renderNodes(Point2I offset, const RectI& updateRect)
|
||||||
if (node->mSelected)
|
if (node->mSelected)
|
||||||
border = mProfile->mBorderColorSEL;
|
border = mProfile->mBorderColorSEL;
|
||||||
|
|
||||||
RectI socketRect(pos, Point2I(mNodeSize, mNodeSize));
|
if(node->mSelected)
|
||||||
drawer->drawRect(socketRect, border);
|
border = mProfile->mBorderColorSEL;
|
||||||
socketRect.inset(1, 1);
|
|
||||||
|
|
||||||
ColorI fill = mProfile->mFillColor;
|
ColorI fill = mProfile->mFillColor;
|
||||||
if (hasConnection(output))
|
if (hasConnection(output))
|
||||||
|
|
@ -256,7 +213,8 @@ void GuiShaderEditor::renderNodes(Point2I offset, const RectI& updateRect)
|
||||||
fill = ColorI::WHITE;
|
fill = ColorI::WHITE;
|
||||||
}
|
}
|
||||||
|
|
||||||
drawer->drawRectFill(socketRect, fill);
|
RectI socketRect(pos, Point2I(mNodeSize, mNodeSize));
|
||||||
|
drawer->drawCircleFill(socketRect, fill, mNodeSize / 2, 2.0f, border);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -292,7 +250,7 @@ void GuiShaderEditor::renderConnections(Point2I offset, const RectI& updateRect)
|
||||||
start += Point2I(mNodeSize / 2, mNodeSize / 2);
|
start += Point2I(mNodeSize / 2, mNodeSize / 2);
|
||||||
end += Point2I(mNodeSize / 2, mNodeSize / 2);
|
end += Point2I(mNodeSize / 2, mNodeSize / 2);
|
||||||
|
|
||||||
drawThickLine(start, end, mNodeSize/3);
|
drawer->drawThickLine(start, end,ColorI(255,255,255,255), (F32)mNodeSize/3);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restore the clip rect to what it was at the start
|
// Restore the clip rect to what it was at the start
|
||||||
|
|
@ -328,11 +286,12 @@ void GuiShaderEditor::onRender(Point2I offset, const RectI& updateRect)
|
||||||
|
|
||||||
RectI sockActive(start, Point2I(mNodeSize, mNodeSize));
|
RectI sockActive(start, Point2I(mNodeSize, mNodeSize));
|
||||||
start += Point2I(mNodeSize / 2, mNodeSize / 2);
|
start += Point2I(mNodeSize / 2, mNodeSize / 2);
|
||||||
drawThickLine(start, mLastMousePos + offset, mNodeSize/3);
|
|
||||||
|
drawer->drawThickLine(start, mLastMousePos + offset, ColorI(255, 255, 255, 255), (F32)mNodeSize / 3);
|
||||||
|
|
||||||
// draw socket overlay over the top of the line.
|
// draw socket overlay over the top of the line.
|
||||||
sockActive.inset(1, 1);
|
sockActive.inset(1, 1);
|
||||||
drawer->drawRectFill(sockActive, ColorI(255, 255, 255));
|
drawer->drawCircleFill(sockActive, ColorI(255, 255, 255), mNodeSize / 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Draw selection rectangle last so it is rendered on top.
|
// Draw selection rectangle last so it is rendered on top.
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,13 @@ void GuiShaderNode::renderNode(Point2I offset, const RectI& updateRect, const S3
|
||||||
RectI winRect;
|
RectI winRect;
|
||||||
winRect.point = offset;
|
winRect.point = offset;
|
||||||
winRect.extent = getExtent();
|
winRect.extent = getExtent();
|
||||||
drawer->drawRectFill(winRect, mProfile->mFillColor);
|
|
||||||
|
ColorI border = mProfile->mBorderColor;
|
||||||
|
|
||||||
|
if (mSelected)
|
||||||
|
border = mProfile->mBorderColorSEL;
|
||||||
|
|
||||||
|
drawer->drawRoundedRect(15.0f, winRect, mProfile->mFillColor, 3.0f, border);
|
||||||
|
|
||||||
// draw header
|
// draw header
|
||||||
ColorI header(50, 50, 50, 128);
|
ColorI header(50, 50, 50, 128);
|
||||||
|
|
@ -148,7 +154,7 @@ void GuiShaderNode::renderNode(Point2I offset, const RectI& updateRect, const S3
|
||||||
U32 headerSize = 30;
|
U32 headerSize = 30;
|
||||||
headRect.point = offset;
|
headRect.point = offset;
|
||||||
headRect.extent = Point2I(getExtent().x, headerSize);
|
headRect.extent = Point2I(getExtent().x, headerSize);
|
||||||
drawer->drawRectFill(headRect, header);
|
drawer->drawRoundedRect(15.0f, headRect, header);
|
||||||
|
|
||||||
// draw header text.
|
// draw header text.
|
||||||
U32 strWidth = mProfile->mFont->getStrWidth(mTitle.c_str());
|
U32 strWidth = mProfile->mFont->getStrWidth(mTitle.c_str());
|
||||||
|
|
@ -157,14 +163,6 @@ void GuiShaderNode::renderNode(Point2I offset, const RectI& updateRect, const S3
|
||||||
drawer->drawText(mProfile->mFont, headerPos + offset, mTitle);
|
drawer->drawText(mProfile->mFont, headerPos + offset, mTitle);
|
||||||
drawer->clearBitmapModulation();
|
drawer->clearBitmapModulation();
|
||||||
|
|
||||||
ColorI border = mProfile->mBorderColor;
|
|
||||||
|
|
||||||
if (mSelected)
|
|
||||||
border = mProfile->mBorderColorSEL;
|
|
||||||
|
|
||||||
drawer->drawRect(winRect, border);
|
|
||||||
|
|
||||||
|
|
||||||
if (mInputNodes.size() > 0 || mOutputNodes.size() > 0)
|
if (mInputNodes.size() > 0 || mOutputNodes.size() > 0)
|
||||||
{
|
{
|
||||||
U32 textPadX = nodeSize, textPadY = mProfile->mFont->getFontSize() + (nodeSize / 2);
|
U32 textPadX = nodeSize, textPadY = mProfile->mFont->getFontSize() + (nodeSize / 2);
|
||||||
|
|
@ -175,7 +173,7 @@ void GuiShaderNode::renderNode(Point2I offset, const RectI& updateRect, const S3
|
||||||
drawer->drawText(mProfile->mFont, slotPos + offset, input->name);
|
drawer->drawText(mProfile->mFont, slotPos + offset, input->name);
|
||||||
|
|
||||||
if (input->pos == Point2I::Zero || mPrevNodeSize != nodeSize)
|
if (input->pos == Point2I::Zero || mPrevNodeSize != nodeSize)
|
||||||
input->pos = Point2I(-(nodeSize / 2), slotPos.y + ((mProfile->mFont->getFontSize() / 2) - (nodeSize / 2)));
|
input->pos = Point2I(-(nodeSize / 2) + 1, slotPos.y + ((mProfile->mFont->getFontSize() / 2) - (nodeSize / 2)));
|
||||||
|
|
||||||
slotPos.y += textPadY;
|
slotPos.y += textPadY;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -150,3 +150,31 @@ singleton ShaderData( CubemapSaveShader )
|
||||||
|
|
||||||
pixVersion = 3.0;
|
pixVersion = 3.0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// GUI shaders
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
singleton ShaderData( RoundedRectangleGUI )
|
||||||
|
{
|
||||||
|
DXVertexShaderFile = $Core::CommonShaderPath @ "/fixedFunction/colorV.hlsl";
|
||||||
|
DXPixelShaderFile = $Core::CommonShaderPath @ "/fixedFunction/roundedRectangleP.hlsl";
|
||||||
|
|
||||||
|
pixVersion = 3.0;
|
||||||
|
};
|
||||||
|
|
||||||
|
singleton ShaderData( CircularGUI )
|
||||||
|
{
|
||||||
|
DXVertexShaderFile = $Core::CommonShaderPath @ "/fixedFunction/colorV.hlsl";
|
||||||
|
DXPixelShaderFile = $Core::CommonShaderPath @ "/fixedFunction/circleP.hlsl";
|
||||||
|
|
||||||
|
pixVersion = 3.0;
|
||||||
|
};
|
||||||
|
|
||||||
|
singleton ShaderData( ThickLineGUI )
|
||||||
|
{
|
||||||
|
DXVertexShaderFile = $Core::CommonShaderPath @ "/fixedFunction/colorV.hlsl";
|
||||||
|
DXGeometryShaderFile = $Core::CommonShaderPath @ "/fixedFunction/thickLineG.hlsl";
|
||||||
|
DXPixelShaderFile = $Core::CommonShaderPath @ "/fixedFunction/thickLineP.hlsl";
|
||||||
|
|
||||||
|
pixVersion = 3.0;
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,66 @@
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Copyright (c) 2012 GarageGames, LLC
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to
|
||||||
|
// deal in the Software without restriction, including without limitation the
|
||||||
|
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||||
|
// sell copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||||
|
// IN THE SOFTWARE.
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include "../shaderModel.hlsl"
|
||||||
|
|
||||||
|
struct Conn
|
||||||
|
{
|
||||||
|
float4 HPOS : TORQUE_POSITION;
|
||||||
|
float4 color : COLOR;
|
||||||
|
};
|
||||||
|
|
||||||
|
uniform float2 sizeUni;
|
||||||
|
uniform float radius;
|
||||||
|
uniform float2 rectCenter;
|
||||||
|
uniform float borderSize;
|
||||||
|
uniform float4 borderCol;
|
||||||
|
|
||||||
|
float circle(float2 p, float radius)
|
||||||
|
{
|
||||||
|
float dist = length(p - float2(0.5,0.5));
|
||||||
|
return 1.0 - smoothstep(radius - (radius*0.01),
|
||||||
|
radius + (radius*0.01),
|
||||||
|
dot(dist,dist) * 4.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
float4 main(Conn IN) : TORQUE_TARGET0
|
||||||
|
{
|
||||||
|
float distance = length(IN.HPOS.xy - rectCenter);
|
||||||
|
if(distance > radius)
|
||||||
|
{
|
||||||
|
discard;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(distance < radius)
|
||||||
|
{
|
||||||
|
if(distance < (radius - borderSize))
|
||||||
|
{
|
||||||
|
return IN.color;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return borderCol;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return IN.color;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,109 @@
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Copyright (c) 2012 GarageGames, LLC
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to
|
||||||
|
// deal in the Software without restriction, including without limitation the
|
||||||
|
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||||
|
// sell copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||||
|
// IN THE SOFTWARE.
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include "../shaderModel.hlsl"
|
||||||
|
|
||||||
|
struct Conn
|
||||||
|
{
|
||||||
|
float4 HPOS : TORQUE_POSITION;
|
||||||
|
float4 color : COLOR;
|
||||||
|
};
|
||||||
|
|
||||||
|
uniform float2 sizeUni;
|
||||||
|
uniform float2 rectCenter;
|
||||||
|
uniform float radius;
|
||||||
|
uniform float borderSize;
|
||||||
|
uniform float4 borderCol;
|
||||||
|
|
||||||
|
float RoundedRectSDF(float2 p, float2 size, float radius)
|
||||||
|
{
|
||||||
|
float2 halfSize = size / 2.0;
|
||||||
|
|
||||||
|
// Calculate distance to each side of the rectangle
|
||||||
|
float2 dist = abs(p) - halfSize + radius;
|
||||||
|
|
||||||
|
// Compute the distance to the rounded corners
|
||||||
|
float cornerDist = length(max(abs(p) - (halfSize - float2(radius, radius)), 0.0));
|
||||||
|
|
||||||
|
// Return the minimum distance (negative inside, positive outside)
|
||||||
|
return min(max(dist.x, dist.y), 0.0) + cornerDist - radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
float4 main(Conn IN) : TORQUE_TARGET0
|
||||||
|
{
|
||||||
|
float2 p = IN.HPOS.xy;
|
||||||
|
float2 halfSize = sizeUni * 0.5;
|
||||||
|
float halfBorder = borderSize * 0.5;
|
||||||
|
|
||||||
|
p -= rectCenter;
|
||||||
|
|
||||||
|
// Calculate signed distance field for rounded rectangle
|
||||||
|
float4 fromColor = IN.color;
|
||||||
|
// alpha
|
||||||
|
float4 toColor = float4(0.0, 0.0, 0.0, 0.0);
|
||||||
|
|
||||||
|
float cornerRadius = radius;
|
||||||
|
|
||||||
|
// if ((p.y < 0.0 && p.x < 0.0) || // top left corner
|
||||||
|
// (p.y < 0.0 && p.x > 0.0) || // top right corner
|
||||||
|
// (p.y > 0.0 && p.x > 0.0) || // bottom right corner.
|
||||||
|
// (p.y > 0.0 && p.x < 0.0)) // bottom left corner
|
||||||
|
// {
|
||||||
|
// cornerRadius = radius;
|
||||||
|
// }
|
||||||
|
|
||||||
|
if(cornerRadius > 0.0 || halfBorder > 0.0)
|
||||||
|
{
|
||||||
|
float sdf = RoundedRectSDF(p, sizeUni, cornerRadius - halfBorder);
|
||||||
|
|
||||||
|
clip(0.01 - sdf);
|
||||||
|
|
||||||
|
if(halfBorder > 0.0)
|
||||||
|
{
|
||||||
|
if(sdf < 0.0)
|
||||||
|
{
|
||||||
|
// if ((p.y >= -halfSize.y - radius + halfBorder && p.y <= -halfSize.y + radius - halfBorder) || // top border
|
||||||
|
// (p.y >= halfSize.y - radius + halfBorder && p.y <= halfSize.y + radius - halfBorder) || // bottom border
|
||||||
|
// (p.x >= -halfSize.x - radius + halfBorder && p.x <= -halfSize.x + radius - halfBorder) || // left border
|
||||||
|
// (p.x >= halfSize.x - radius + halfBorder && p.x <= halfSize.x + radius - halfBorder) ) { // right border
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
toColor = borderCol;
|
||||||
|
}
|
||||||
|
|
||||||
|
sdf = abs(sdf) - halfBorder;
|
||||||
|
|
||||||
|
// Apply smoothing to create rounded effect
|
||||||
|
float blending = smoothstep(1.0, -1.0, sdf);
|
||||||
|
|
||||||
|
return lerp(fromColor, toColor, blending);
|
||||||
|
}
|
||||||
|
|
||||||
|
float alpha = smoothstep(1.0, 0.0, sdf);
|
||||||
|
return float4(IN.color.rgb, IN.color.a * alpha);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return IN.color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,77 @@
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Copyright (c) 2012 GarageGames, LLC
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to
|
||||||
|
// deal in the Software without restriction, including without limitation the
|
||||||
|
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||||
|
// sell copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||||
|
// IN THE SOFTWARE.
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include "../shaderModel.hlsl"
|
||||||
|
|
||||||
|
struct Conn
|
||||||
|
{
|
||||||
|
float4 HPOS : TORQUE_POSITION;
|
||||||
|
float4 color : COLOR;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct PSConn
|
||||||
|
{
|
||||||
|
float4 HPOS : TORQUE_POSITION;
|
||||||
|
float4 color : COLOR;
|
||||||
|
};
|
||||||
|
|
||||||
|
uniform float thickness;
|
||||||
|
uniform float2 oneOverViewport;
|
||||||
|
|
||||||
|
[maxvertexcount(4)]
|
||||||
|
void main(line Conn lineSegment[2], inout TriangleStream<PSConn> outstream)
|
||||||
|
{
|
||||||
|
// Calculate the direction of the line segment
|
||||||
|
float2 direction = normalize(lineSegment[1].HPOS.xy - lineSegment[0].HPOS.xy);
|
||||||
|
|
||||||
|
// Calculate perpendicular direction
|
||||||
|
float2 perpendicular = normalize(float2(-direction.y, direction.x));
|
||||||
|
|
||||||
|
// Calculate offset for thickness
|
||||||
|
float2 offset = float2(thickness * oneOverViewport.x, thickness * oneOverViewport.y) * perpendicular;
|
||||||
|
|
||||||
|
// Calculate vertices for the line with thickness
|
||||||
|
float2 p0 = lineSegment[0].HPOS.xy + offset;
|
||||||
|
float2 p1 = lineSegment[0].HPOS.xy - offset;
|
||||||
|
float2 p2 = lineSegment[1].HPOS.xy + offset;
|
||||||
|
float2 p3 = lineSegment[1].HPOS.xy - offset;
|
||||||
|
|
||||||
|
PSConn output;
|
||||||
|
|
||||||
|
output.HPOS = float4(p0, 0.0f, 1.0f);
|
||||||
|
output.color = lineSegment[0].color;
|
||||||
|
outstream.Append(output);
|
||||||
|
|
||||||
|
output.HPOS = float4(p1, 0.0f, 1.0f);
|
||||||
|
output.color = lineSegment[0].color;
|
||||||
|
outstream.Append(output);
|
||||||
|
|
||||||
|
output.HPOS = float4(p2, 0.0f, 1.0f);
|
||||||
|
output.color = lineSegment[1].color;
|
||||||
|
outstream.Append(output);
|
||||||
|
|
||||||
|
output.HPOS = float4(p3, 0.0f, 1.0f);
|
||||||
|
output.color = lineSegment[1].color;
|
||||||
|
outstream.Append(output);
|
||||||
|
|
||||||
|
outstream.RestartStrip();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Copyright (c) 2012 GarageGames, LLC
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to
|
||||||
|
// deal in the Software without restriction, including without limitation the
|
||||||
|
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||||
|
// sell copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||||
|
// IN THE SOFTWARE.
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include "../shaderModel.hlsl"
|
||||||
|
|
||||||
|
struct PSConn
|
||||||
|
{
|
||||||
|
float4 HPOS : TORQUE_POSITION;
|
||||||
|
float4 color : COLOR;
|
||||||
|
};
|
||||||
|
|
||||||
|
float4 main(PSConn IN) : TORQUE_TARGET0
|
||||||
|
{
|
||||||
|
return IN.color;
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue