-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a3e2e9b
Showing
19 changed files
with
649 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: Build | ||
|
||
on: push | ||
|
||
jobs: | ||
now: | ||
runs-on: windows-2022 | ||
permissions: | ||
contents: write | ||
|
||
steps: | ||
- name: Check out code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Build | ||
if: runner.os == 'Windows' | ||
shell: pwsh | ||
run: | | ||
.\build_shaders.bat | ||
tar -czf RNDX.tar.gz shaders | ||
copy RNDX.tar.gz C:\RNDX.tar.gz | ||
copy rndx.lua C:\rndx.lua | ||
- name: Release | ||
if: runner.os == 'Windows' | ||
uses: ncipollo/release-action@v1 | ||
with: | ||
tag: 1 | ||
allowUpdates: true | ||
artifacts: | | ||
C:\RNDX.tar.gz | ||
C:\rndx.lua |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
*.vcs | ||
*.inc | ||
sound.cache | ||
shaders |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# 🎨 RNDX | ||
|
||
**Draw rounded shapes with ease.** | ||
RNDX is a lightweight and efficient library designed to make drawing rounded shapes simple, fast, and visually stunning. | ||
|
||
Using Shader Model 3.0, RNDX provides perfect anti-aliasing with no performance hit, allowing you to create beautiful interfaces and visuals with ease. | ||
|
||
![Screenshot](thumbnail.png) | ||
![Screenshot](thumbnail2.png) | ||
![Screenshot](sbot.png) | ||
|
||
--- | ||
|
||
## ✨ Why RNDX? | ||
|
||
- **Blazing Fast Performance**: Optimized for speed, RNDX is incredibly lightweight and efficient. _(It will get even faster once we [get `mat:SetFloat4()`](https://github.com/Facepunch/garrysmod-requests/issues/2606)!)_ | ||
- **Perfect Anti-Aliasing**: Enjoy smooth, pixel-perfect corners with no performance hit. | ||
- **Simple & Intuitive**: No complex objects or states—just call a function and draw! | ||
- **Seamless Integration**: Works flawlessly inside `3D2D` and `Panel:Paint*` functions without any hacks. | ||
|
||
--- | ||
|
||
## 🛠️ Get Started | ||
|
||
1. Download `RNDX.tar.gz` & `rndx.lua` from [GitHub releases](https://github.com/Srlion/RNDX/releases/latest). | ||
2. Add the content of `RNDX.tar.gz` to your **gmod client** `garrysmod` folder. (Temporarily until we get `thirdparty` support!) | ||
3. `AddCSLuaFile` & `include` `rndx.lua`. | ||
4. Voilà! You're ready to draw rounded shapes with ease. 🎉 | ||
|
||
--- | ||
|
||
## 📐 Usage | ||
|
||
```lua | ||
hook.Add("HUDPaint", "RNDX Example", function() | ||
local flags = RNDX.NO_TL + RNDX.NO_TR + RNDX.SHAPE_IOS | ||
RNDX.Draw(10, 100, 100, 200, 200, nil, flags + RNDX.BLUR) | ||
RNDX.Draw(10, 100, 100, 200, 200, Color(255, 0, 0, 150), flags) | ||
RNDX.DrawOutlined(10, 100, 100, 200, 200, Color(0, 255, 0), 10, flags) | ||
end) | ||
``` | ||
|
||
## 📚 Documentation | ||
|
||
### Flags | ||
|
||
- **`RNDX.NO_TL`**: Disables top-left corner. | ||
- **`RNDX.NO_TR`**: Disables top-right corner. | ||
- **`RNDX.NO_BL`**: Disables bottom-left corner. | ||
- **`RNDX.NO_BR`**: Disables bottom-right corner. | ||
- **`RNDX.BLUR`**: Use blur for the shape. | ||
|
||
--- | ||
|
||
- **`RNDX.SHAPE_CIRCLE`** | ||
- **`RNDX.SHAPE_FIGMA`** <-- Default | ||
- **`RNDX.SHAPE_IOS`** | ||
|
||
![Screenshot](shapes.jpg) | ||
|
||
--- | ||
|
||
### Functions | ||
|
||
### `RNDX.Draw(rad, x, y, w, h, col, flags)` | ||
|
||
### `RNDX.DrawOutlined(rad, x, y, w, h, col, thickness, flags)` | ||
|
||
### `RNDX.DrawTexture(rad, x, y, w, h, col, texture, flags)` | ||
|
||
### `RNDX.DrawMaterial(rad, x, y, w, h, col, mat, flags)` | ||
|
||
### `RNDX.DrawCircle(x, y, r, col, flags)` <-- Just a wrapper for `RNDX.Draw` with `RNDX.SHAPE_CIRCLE`. | ||
|
||
### `RNDX.DrawCircle(x, y, r, col, thickness, flags)` | ||
|
||
--- | ||
|
||
## 🚀 Why Choose RNDX Over Alternatives? | ||
|
||
| Feature | RNDX | [Circles](https://github.com/SneakySquid/Circles) | [paint](https://github.com/Jaffies/paint) | [melonstuff](https://github.com/melonstuff) | | ||
| ----------------- | ------------------------------- | ------------------------------------------------- | ----------------------------------------- | ------------------------------------------- | | ||
| **Speed** | ⚡ Extremely Fast | 🐌 Slow with many circles | ⚡ Fast | 🐌 Slow | | ||
| **Anti-Aliasing** | ✅ Perfect, no performance cost | ❌ None | ❌ Poor (Source Engine AA) | ❌ None | | ||
| **Ease of Use** | 🎯 Simple & Minimal | 🎯 Simple | 🧩 Complex & Bloated | 🎯 Easy | | ||
| **Documentation** | 📖 Clear & Concise | 📖 Good | ❌ Overwhelming & Undocumented | 📖 Good | | ||
|
||
--- | ||
|
||
## 📜 License | ||
|
||
RNDX is open-source and free to use. Feel free to contribute or report issues on GitHub! | ||
|
||
Make sure to give credits! | ||
|
||
--- | ||
|
||
## 🌟 Credits | ||
|
||
- [ficool2](https://github.com/ficool2) - For [sdk_screenspace_shaders](https://github.com/ficool2/sdk_screenspace_shaders) & finding out that we can use shaders in source engine games! | ||
- [Rubat](https://github.com/robotboy655) - For allowing us to use shaders in Garry's Mod! | ||
- [Svetov/Jaffies/FriendlyStealer](https://github.com/Jaffies) - For lots of help throughout the development of RNDX! Also suggested multiple stuff to improve the performance! | ||
- [Shadertoy Rounded Code](https://www.shadertoy.com/view/fsdyzB) | ||
- [Shadertoy Blur Code](https://www.shadertoy.com/view/Xd33Rf) | ||
- And AI because I don't understand how shaders work! | ||
|
||
**RNDX**: Because drawing rounded shapes should be simple, fast, and beautiful. 🎉 |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
[CmdletBinding()] | ||
param ( | ||
[Parameter(Mandatory=$true, ValueFromPipeline=$true)][System.IO.FileInfo]$File, | ||
[Parameter(Mandatory=$true)][string]$Version, | ||
[Parameter(Mandatory=$false)][System.UInt32]$Threads | ||
) | ||
|
||
if ($Version -notin @("20b", "30", "40", "41", "50", "51")) { | ||
return | ||
} | ||
|
||
$fileList = $File.OpenText() | ||
while ($null -ne ($line = $fileList.ReadLine())) { | ||
if ($line -match '^\s*$' -or $line -match '^\s*//') { | ||
continue | ||
} | ||
|
||
# Create a vmt file from template for each shader if it doesn't exist | ||
$baseName = [System.IO.Path]::GetFileNameWithoutExtension($line) -replace "_ps2x$", "" | ||
$templatePath = Join-Path $PSScriptRoot "../../../materials/effects/shaders/template.vmt" | ||
$vmtPath = Join-Path $PSScriptRoot "../../../materials/effects/shaders/$baseName.vmt" | ||
|
||
if ((Test-Path $templatePath) -and -not (Test-Path $vmtPath)) { | ||
$content = Get-Content $templatePath -Raw | ||
$content = $content -replace '\$pixshader\s+"[^"]*"', "`$pixshader `"$baseName`_ps20`"" | ||
Set-Content -Path $vmtPath -Value $content | ||
} | ||
|
||
if ($Threads -ne 0) { | ||
& "$PSScriptRoot\ShaderCompile" "/O" "3" "-threads" $Threads "-ver" $Version "-shaderpath" $File.DirectoryName $line | ||
continue | ||
} | ||
|
||
& "$PSScriptRoot\ShaderCompile" "/O" "3" "-ver" $Version "-shaderpath" $File.DirectoryName $line | ||
} | ||
$fileList.Close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
@echo off | ||
|
||
echo Building inc files and worklist for %inputbase%... | ||
|
||
powershell -NoLogo -ExecutionPolicy Bypass -Command "bin\process_shaders.ps1 -Version 30 'compile_shader_list.txt'" | ||
|
||
echo Done! | ||
echo. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// common data shared among all screenspace shaders | ||
|
||
// up to four textures available for sampling | ||
sampler TexBase : register( s0 ); // $basetexture | ||
sampler Tex1 : register( s1 ); // $texture1 | ||
sampler Tex2 : register( s2 ); // $texture2 | ||
sampler Tex3 : register( s3 ); // $texture3 | ||
|
||
// normalized dimensions for each texture above | ||
// (x = 1.0 / width, y = 1.0 / height) | ||
// NOT AVAILABLE IN L4D2/PORTAL 2 | ||
float2 TexBaseSize : register( c4 ); | ||
float2 Tex1Size : register( c5 ); | ||
float2 Tex2Size : register( c6 ); | ||
float2 Tex3Size : register( c7 ); | ||
|
||
// customizable parameters $c0, $c1, $c2, $c3, $c4 | ||
const float4 Constants0 : register( c0 ); | ||
const float4 Constants1 : register( c1 ); | ||
const float4 Constants2 : register( c2 ); | ||
const float4 Constants3 : register( c3 ); | ||
// ONLY AVAILABLE IN L4D2/PORTAL2 ( | ||
const float4 Constants4 : register( c4 ); | ||
|
||
// eye position in world coordinates | ||
// WARNING: this is calculated from the view matrix | ||
// on a screen overlay, this will return near-zero values | ||
// use PlayerPosition VMT proxy as a workaround | ||
const float4 EyePosition : register( c10 ); | ||
|
||
// xyz will be 0, 0, 0 (black) if mesh is rendered without fog | ||
const float4 FogColor : register( c29 ); | ||
// range of compressed depth buffer. usually 1.0 / 192 | ||
#define DepthRange FogColor.w | ||
|
||
const float4 HDRParams : register( c30 ); | ||
// exposure scale (bounded by tonemap controller's min/max) | ||
#define TonemapScale HDRParams.x | ||
// 16 in HDR, 4.59479 in LDR | ||
#define LightmapScale HDRParams.y | ||
// 16 in HDR, 1 in LDR | ||
#define EnvmapScale HDRParams.z | ||
// gamma, equivalent to pow(TonemapScale, 1.0 / 2.2) | ||
#define GammaScale HDRParams.w | ||
|
||
// interpolated vertex data from vertex shader, do not change | ||
struct PS_INPUT | ||
{ | ||
// texture coordinates | ||
float2 uv : TEXCOORD0; | ||
// vertex color | ||
float4 color : TEXCOORD1; | ||
// screenspace position | ||
float2 pos : VPOS; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// this code here is from fuckton of sources | ||
// but was mainly using https://www.shadertoy.com/view/fsdyzB | ||
// then some help came from Svetov/Jaffies (https://github.com/Jaffies) | ||
// and some help from AI lol | ||
#include "common.hlsl" | ||
|
||
#define RADIUS Constants0 | ||
#define SIZE Constants1.xy | ||
#define POWER_PARAMETER Constants1.z | ||
#define OUTLINE_THICKNESS Constants2.x | ||
#define AA Constants2.y // Anti-aliasing smoothness (pixels) | ||
|
||
float length_custom(float2 vec) { | ||
float2 powered = pow(vec, POWER_PARAMETER); | ||
return pow(dot(powered, 1.0), 1.0 / POWER_PARAMETER); | ||
} | ||
|
||
float rounded_box_sdf(float2 p, float2 b, float4 r) { | ||
float2 quadrant = step(0.0, p.xy); | ||
float radius = lerp( | ||
lerp(r.w, r.x, quadrant.y), | ||
lerp(r.z, r.y, quadrant.y), | ||
quadrant.x | ||
); | ||
float2 q = abs(p) - b + radius; | ||
float2 q_clamped = max(q, 0.0); | ||
float len = length_custom(q_clamped); | ||
return min(max(q.x, q.y), 0.0) + len - radius; | ||
} | ||
|
||
float calculate_rounded_alpha(PS_INPUT i) { | ||
float2 screen_pos = i.uv.xy * SIZE; | ||
float2 rect_half_size = SIZE * 0.5; | ||
|
||
// Compute outer SDF distance (original radii) | ||
float distance_outer = rounded_box_sdf(screen_pos - rect_half_size, rect_half_size, RADIUS); | ||
|
||
// Adjust inner radii and size for outline | ||
float2 inner_half_size = max(rect_half_size - OUTLINE_THICKNESS, 0.0); | ||
float4 inner_radius = max(RADIUS - OUTLINE_THICKNESS, 0.0); | ||
float distance_inner = rounded_box_sdf(screen_pos - rect_half_size, inner_half_size, inner_radius); | ||
|
||
// Offset SDF distances by AA to implicitly increase visual radius | ||
float adjusted_distance_outer = distance_outer + AA; | ||
float adjusted_distance_inner = distance_inner + AA; | ||
|
||
// Compute alpha with smoothstep (like Shadertoy's edge softness) | ||
float alpha_outer = 1.0 - smoothstep(0.0, AA, adjusted_distance_outer); | ||
float alpha_inner = 1.0 - smoothstep(0.0, AA, adjusted_distance_inner); | ||
|
||
// Combine results (outer alpha minus inner alpha) | ||
return alpha_outer * (1.0 - alpha_inner); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// common data shared among all screenspace shaders | ||
|
||
// up to four textures available for sampling | ||
sampler TexBase : register( s0 ); // $basetexture | ||
sampler Tex1 : register( s1 ); // $texture1 | ||
sampler Tex2 : register( s2 ); // $texture2 | ||
sampler Tex3 : register( s3 ); // $texture3 | ||
|
||
// normalized dimensions for each texture above | ||
// (x = 1.0 / width, y = 1.0 / height) | ||
|
||
// customizable parameters $c0, $c1, $c2, $c3 | ||
const float4 Constants0 : register( c0 ); | ||
const float4 Constants1 : register( c1 ); | ||
const float4 Constants2 : register( c2 ); | ||
const float4 Constants3 : register( c3 ); | ||
|
||
const float4x4 cModelViewProj : register(c4); | ||
const float4x4 cViewProj : register(c8); | ||
|
||
// interpolated vertex data from vertex shader, do not change | ||
struct VS_INPUT | ||
{ | ||
float4 pos : POSITION; | ||
// texture coordinates | ||
float2 uv : TEXCOORD0; | ||
// vertex color (if mesh has one) | ||
float4 color : COLOR0; | ||
|
||
float4 normal : NORMAL; | ||
}; | ||
|
||
struct VS_OUTPUT | ||
{ | ||
float4 projPos : POSITION; | ||
float2 uv : TEXCOORD0; | ||
float4 color : TEXCOORD1; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
rndx_r_shaders1_ps30.hlsl | ||
rndx_bv_shaders1_ps30.hlsl | ||
rndx_bh_shaders1_ps30.hlsl | ||
rndx_vertex_shaders1_vs30.hlsl |
Oops, something went wrong.