mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-01-19 20:24:49 +00:00
gui shaders for opengl
First opengl geometry shader along with the other shaders for gui rendering opengl side.
This commit is contained in:
parent
d9c4269d8b
commit
fbed04050a
|
|
@ -462,7 +462,7 @@ bool GFXGLShader::_init()
|
|||
if (!mGeometryFile.isEmpty())
|
||||
{
|
||||
macros.last().name = "TORQUE_GEOMETRY_SHADER";
|
||||
compiledGeometryShader = initShader(mPixelFile, GFXShaderStage::GEOMETRY_SHADER, macros);
|
||||
compiledGeometryShader = initShader(mGeometryFile, GFXShaderStage::GEOMETRY_SHADER, macros);
|
||||
if (!compiledGeometryShader)
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -192,7 +192,7 @@ void GuiShaderEditor::renderNodes(Point2I offset, const RectI& updateRect)
|
|||
}
|
||||
|
||||
RectI socketRect(pos, Point2I(mNodeSize, mNodeSize));
|
||||
drawer->drawCircleFill(socketRect, fill, mNodeSize / 2, 2.0f, border);
|
||||
drawer->drawCircleFill(socketRect, fill, mNodeSize / 2, 1.0f, border);
|
||||
}
|
||||
|
||||
for (NodeOutput* output : node->mOutputNodes)
|
||||
|
|
@ -208,7 +208,7 @@ void GuiShaderEditor::renderNodes(Point2I offset, const RectI& updateRect)
|
|||
}
|
||||
|
||||
RectI socketRect(pos, Point2I(mNodeSize, mNodeSize));
|
||||
drawer->drawCircleFill(socketRect, fill, mNodeSize / 2, 2.0f, border);
|
||||
drawer->drawCircleFill(socketRect, fill, mNodeSize / 2, 1.0f, border);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -244,7 +244,7 @@ void GuiShaderEditor::renderConnections(Point2I offset, const RectI& updateRect)
|
|||
start += Point2I(mNodeSize / 2, mNodeSize / 2);
|
||||
end += Point2I(mNodeSize / 2, mNodeSize / 2);
|
||||
|
||||
drawer->drawThickLine(start, end,ColorI(255,255,255,255), (F32)mNodeSize/3);
|
||||
drawer->drawThickLine(start, end,ColorI(255,255,255,255), 2.0f);
|
||||
}
|
||||
|
||||
// Restore the clip rect to what it was at the start
|
||||
|
|
@ -288,10 +288,9 @@ void GuiShaderEditor::onRender(Point2I offset, const RectI& updateRect)
|
|||
RectI sockActive(start, Point2I(mNodeSize, mNodeSize));
|
||||
start += Point2I(mNodeSize / 2, mNodeSize / 2);
|
||||
|
||||
drawer->drawThickLine(start, mLastMousePos + offset, color, (F32)mNodeSize / 3);
|
||||
drawer->drawThickLine(start, mLastMousePos + offset, color, 2.0f);
|
||||
|
||||
// draw socket overlay over the top of the line.
|
||||
sockActive.inset(1, 1);
|
||||
drawer->drawCircleFill(sockActive, color, mNodeSize / 2);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@ ConsoleDocClass(MathAddNode,
|
|||
"@internal"
|
||||
);
|
||||
|
||||
|
||||
MathAddNode::MathAddNode()
|
||||
: GuiShaderNode()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -158,6 +158,9 @@ singleton ShaderData( RoundedRectangleGUI )
|
|||
{
|
||||
DXVertexShaderFile = $Core::CommonShaderPath @ "/fixedFunction/colorV.hlsl";
|
||||
DXPixelShaderFile = $Core::CommonShaderPath @ "/fixedFunction/roundedRectangleP.hlsl";
|
||||
|
||||
OGLVertexShaderFile = $Core::CommonShaderPath @ "/fixedFunction/gl/colorV.glsl";
|
||||
OGLPixelShaderFile = $Core::CommonShaderPath @ "/fixedFunction/gl/roundedRectangleP.glsl";
|
||||
|
||||
pixVersion = 3.0;
|
||||
};
|
||||
|
|
@ -166,6 +169,9 @@ singleton ShaderData( CircularGUI )
|
|||
{
|
||||
DXVertexShaderFile = $Core::CommonShaderPath @ "/fixedFunction/colorV.hlsl";
|
||||
DXPixelShaderFile = $Core::CommonShaderPath @ "/fixedFunction/circleP.hlsl";
|
||||
|
||||
OGLVertexShaderFile = $Core::CommonShaderPath @ "/fixedFunction/gl/colorV.glsl";
|
||||
OGLPixelShaderFile = $Core::CommonShaderPath @ "/fixedFunction/gl/circleP.glsl";
|
||||
|
||||
pixVersion = 3.0;
|
||||
};
|
||||
|
|
@ -175,6 +181,10 @@ singleton ShaderData( ThickLineGUI )
|
|||
DXVertexShaderFile = $Core::CommonShaderPath @ "/fixedFunction/colorV.hlsl";
|
||||
DXGeometryShaderFile = $Core::CommonShaderPath @ "/fixedFunction/thickLineG.hlsl";
|
||||
DXPixelShaderFile = $Core::CommonShaderPath @ "/fixedFunction/thickLineP.hlsl";
|
||||
|
||||
OGLVertexShaderFile = $Core::CommonShaderPath @ "/fixedFunction/gl/colorV.glsl";
|
||||
OGLGeometryShaderFile = $Core::CommonShaderPath @ "/fixedFunction/gl/thickLineG.glsl";
|
||||
OGLPixelShaderFile = $Core::CommonShaderPath @ "/fixedFunction/gl/thickLineP.glsl";
|
||||
|
||||
pixVersion = 3.0;
|
||||
};
|
||||
|
|
@ -50,10 +50,10 @@ float4 main(Conn IN) : TORQUE_TARGET0
|
|||
{
|
||||
distance = abs(distance) - radius;
|
||||
|
||||
if(distance < (radius - (borderSize * 0.5)))
|
||||
if(distance < (radius - (borderSize)))
|
||||
{
|
||||
toColor = IN.color;
|
||||
distance = abs(distance) - (borderSize * 0.5);
|
||||
distance = abs(distance) - (borderSize);
|
||||
}
|
||||
|
||||
float blend = smoothstep(0.0, 1.0, distance);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,62 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
in vec4 color;
|
||||
|
||||
out vec4 OUT_col;
|
||||
|
||||
uniform vec2 sizeUni;
|
||||
uniform float radius;
|
||||
uniform vec2 rectCenter;
|
||||
uniform float borderSize;
|
||||
uniform vec4 borderCol;
|
||||
|
||||
float circle(vec2 p, vec2 center, float r)
|
||||
{
|
||||
return length(p - center);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
float dist = circle(gl_FragCoord.xy, rectCenter, radius);
|
||||
|
||||
vec4 fromColor = borderCol;
|
||||
vec4 toColor = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
|
||||
if(dist < radius)
|
||||
{
|
||||
dist = abs(dist) - radius;
|
||||
|
||||
if(dist < (radius - (borderSize)))
|
||||
{
|
||||
toColor = color;
|
||||
dist = abs(dist) - (borderSize);
|
||||
}
|
||||
|
||||
float blend = smoothstep(0.0, 1.0, dist);
|
||||
OUT_col = mix(fromColor, toColor, blend);
|
||||
}
|
||||
|
||||
dist = abs(dist) - radius;
|
||||
float blend = smoothstep(0.0, 1.0, dist);
|
||||
OUT_col = mix(fromColor, toColor, blend);
|
||||
}
|
||||
|
|
@ -0,0 +1,98 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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.
|
||||
//-----------------------------------------------------------------------------
|
||||
in vec4 color;
|
||||
|
||||
out vec4 OUT_col;
|
||||
|
||||
uniform vec2 sizeUni;
|
||||
uniform vec2 rectCenter;
|
||||
uniform vec2 oneOverViewport;
|
||||
uniform float radius;
|
||||
uniform float borderSize;
|
||||
uniform vec4 borderCol;
|
||||
|
||||
float RoundedRectSDF(vec2 p, vec2 size, float radius)
|
||||
{
|
||||
// Calculate distance to each side of the rectangle
|
||||
vec2 dist = abs(p) - size + vec2(radius, radius);
|
||||
|
||||
// Compute the distance to the rounded corners
|
||||
float cornerDist = length(max(dist, 0.0));
|
||||
|
||||
// Return the minimum distance (negative inside, positive outside)
|
||||
return min(max(dist.x, dist.y), 0.0) + cornerDist - radius;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 p = gl_FragCoord.xy;
|
||||
|
||||
float halfBorder = borderSize * 0.5;
|
||||
vec2 halfSize = sizeUni * 0.5;
|
||||
p -= rectCenter;
|
||||
|
||||
// Calculate signed distance field for rounded rectangle
|
||||
vec4 fromColor = borderCol;
|
||||
// alpha
|
||||
vec4 toColor = vec4(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, halfSize, cornerRadius - halfBorder);
|
||||
|
||||
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 = color;
|
||||
sdf = abs(sdf) / borderSize;
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
fromColor = color;
|
||||
}
|
||||
|
||||
float alpha = smoothstep(-1.0, 1.0, sdf);
|
||||
OUT_col = mix(fromColor, toColor, alpha);
|
||||
}
|
||||
else
|
||||
{
|
||||
OUT_col = color;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
layout (lines) in;
|
||||
layout (triangle_strip, max_vertices = 4) out;
|
||||
|
||||
in VS_OUT {
|
||||
vec4 color;
|
||||
} gs_in[];
|
||||
|
||||
|
||||
out vec4 fragColor;
|
||||
|
||||
uniform float thickness;
|
||||
uniform vec2 oneOverViewport;
|
||||
|
||||
void main()
|
||||
{
|
||||
// Calculate the direction of the line segment
|
||||
vec2 direction = normalize(gl_in[1].gl_Position.xy - gl_in[0].gl_Position.xy);
|
||||
|
||||
// Calculate perpendicular direction
|
||||
vec2 perpendicular = normalize(vec2(-direction.y, direction.x));
|
||||
|
||||
// Calculate offset for thickness
|
||||
vec2 offset = vec2(thickness * oneOverViewport.x, thickness * oneOverViewport.y) * perpendicular;
|
||||
|
||||
// Calculate vertices for the line with thickness
|
||||
vec2 p0 = gl_in[0].gl_Position.xy + offset;
|
||||
vec2 p1 = gl_in[0].gl_Position.xy - offset;
|
||||
vec2 p2 = gl_in[1].gl_Position.xy + offset;
|
||||
vec2 p3 = gl_in[1].gl_Position.xy - offset;
|
||||
|
||||
fragColor = gs_in[0].color;
|
||||
gl_Position = vec4(p0, 0.0f, 1.0f);
|
||||
EmitVertex();
|
||||
|
||||
gl_Position = vec4(p1, 0.0f, 1.0f);
|
||||
EmitVertex();
|
||||
|
||||
gl_Position = vec4(p2, 0.0f, 1.0f);
|
||||
EmitVertex();
|
||||
|
||||
gl_Position = vec4(p3, 0.0f, 1.0f);
|
||||
EmitVertex();
|
||||
|
||||
EndPrimitive();
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
in vec4 fragColor;
|
||||
|
||||
out vec4 OUT_col;
|
||||
|
||||
void main()
|
||||
{
|
||||
OUT_col = fragColor;
|
||||
}
|
||||
Loading…
Reference in a new issue