Skip to content

Commit

Permalink
Shader visualizer (#83)
Browse files Browse the repository at this point in the history
* Fixed the Shader Reloader and added includes
  • Loading branch information
AVinitzca authored Nov 19, 2023
1 parent a3398d4 commit e711ef6
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
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

0 comments on commit e711ef6

Please sign in to comment.