Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shader visualizer #83

Merged
merged 2 commits into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions TGC.MonoGame.Samples/Content/Effects/ShaderIncludes.fx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
float plot(float originalY, float functionResult)
{
return smoothstep(0.02, 0.0, abs(functionResult - originalY));
}

float sdSegment(float2 initialPoint, float2 a, float2 b)
{
float2 pa = initialPoint - a;
float2 ba = b - a;
float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );
return length( pa - ba*h );
}

float sdCircle(float2 initialPoint, float radius)
{
return length(initialPoint) - radius;
}

float sdBox( in float2 p, in float2 b )
{
float2 d = abs(p)-b;
return length(max(d,0.0)) + min(max(d.x,d.y),0.0);
}

float2x2 rotation2D(float angle)
{
float sinAngle = sin(angle);
float cosAngle = cos(angle);

return float2x2(cosAngle, -sinAngle,
sinAngle, cosAngle);
}

float2 random2(float2 p)
{
return frac(sin(float2(dot(p,float2(127.1,311.7)),dot(p,float2(269.5,183.3))))*43758.5453);
}

float3 random3(float3 c)
{
float j = 4096.0 * sin(dot(c, float3(17.0, 59.4, 15.0)));
float3 r;
r.z = frac(512.0 * j);
j *= .125;
r.x = frac(512.0 * j);
j *= .125;
r.y = frac(512.0 * j);
return r;
}
2 changes: 2 additions & 0 deletions TGC.MonoGame.Samples/Content/Effects/ShaderVisualizer.fx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#define PS_SHADERMODEL ps_4_0_level_9_1
#endif

#include "ShaderIncludes.fx"

float Time = 0.0;

struct VertexShaderInput
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private void ConfigureWatcher()
private void ReplaceShader(object sender, FileSystemEventArgs eventArgs)
{
// Can be triggered by temp files with suffixes
if (!eventArgs.Name.Equals(ShaderCodeFileName))
if (eventArgs.Name.Equals(ShaderCodeFileName))
{
CompileShader();
if (!CompileError)
Expand Down
Loading