circle shader
This commit is contained in:
10
shaders/circle.frag.hlsl
Normal file
10
shaders/circle.frag.hlsl
Normal file
@@ -0,0 +1,10 @@
|
||||
#include "common/pixel.hlsl"
|
||||
#include "common/sdf.hlsl"
|
||||
|
||||
// Pixel shader main function
|
||||
float4 main(PSInput input) : SV_TARGET
|
||||
{
|
||||
float4 color = input.color;
|
||||
color.a = abs(sdf.circle(input.uv, 1)) <= 0.05 ? 1:0 ;
|
||||
return color;
|
||||
}
|
||||
41
shaders/common/sdf.hlsl
Normal file
41
shaders/common/sdf.hlsl
Normal file
@@ -0,0 +1,41 @@
|
||||
struct SDF {
|
||||
|
||||
float dot2(float2 a)
|
||||
{
|
||||
return dot(a,a);
|
||||
}
|
||||
|
||||
float circle(float2 p, float r)
|
||||
{
|
||||
return length(p) - r;
|
||||
}
|
||||
|
||||
// p = uv point
|
||||
// b = width,height
|
||||
// r = roundedness of the 4 corners
|
||||
float rounded_box(float2 p, float2 b, float4 r)
|
||||
{
|
||||
r.xy = (p.x>0.0)?r.xy : r.zw;
|
||||
r.x = (p.y>0.0)?r.x : r.y;
|
||||
float2 q = abs(p)-b+r.x;
|
||||
return min(max(q.x,q.y),0.0) + length(max(q,0.0)) - r.x;
|
||||
}
|
||||
|
||||
float box(float2 p, float2 b)
|
||||
{
|
||||
float2 d = abs(p)-b;
|
||||
return length(max(d,0)) + min(max(d.x,d.y),0);
|
||||
}
|
||||
|
||||
float heart( in float2 p )
|
||||
{
|
||||
p.x = abs(p.x);
|
||||
|
||||
if( p.y+p.x>1.0 )
|
||||
return sqrt(dot2(p-float2(0.25,0.75))) - sqrt(2.0)/4.0;
|
||||
|
||||
return sqrt(min(dot2(p-float2(0.00,1.00)), dot2(p-0.5*max(p.x+p.y,0.0)))) * sign(p.x-p.y);
|
||||
}
|
||||
};
|
||||
|
||||
SDF sdf;
|
||||
@@ -8,42 +8,48 @@ mkdir -p reflection
|
||||
|
||||
# Vertex shaders
|
||||
for filename in *.vert.hlsl; do
|
||||
if [ -f "$filename" ]; then echo "compiling ${filename}"
|
||||
# Produce SPIR-V
|
||||
dxc -spirv -T vs_6_0 -Fo "spv/${filename/.hlsl/.spv}" "$filename"
|
||||
# Produce DXIL + PDB
|
||||
dxc -Zi -Fd "dxil/${filename/.hlsl/.pdb}" -T vs_6_0 -Fo "dxil/${filename/.hlsl/.dxil}" "$filename"
|
||||
# Convert SPIR-V to Metal Shader Language
|
||||
spirv-cross "spv/${filename/.hlsl/.spv}" --msl > "msl/${filename/.hlsl/.msl}"
|
||||
# Generate reflection
|
||||
spirv-cross "spv/${filename/.hlsl/.spv}" --reflect > "reflection/${filename/.hlsl/.json}"
|
||||
if [ -f "$filename" ]; then
|
||||
outSpv="spv/${filename/.hlsl/.spv}"
|
||||
outDxil="dxil/${filename/.hlsl/.dxil}"
|
||||
outMsl="msl/${filename/.hlsl/.msl}"
|
||||
outReflect="reflection/${filename/.hlsl/.json}"
|
||||
# Produce SPIR-V
|
||||
dxc -spirv -T vs_6_0 -Fo "$outSpv" "$filename"
|
||||
# Produce DXIL with embedded debug info (example)
|
||||
shadercross "$filename" -o "$outDxil"
|
||||
# dxc -Zi -Qembed_debug -T vs_6_0 -Fo "$outDxil" "$filename"
|
||||
# Convert SPIR-V to Metal Shader Language
|
||||
spirv-cross "$outSpv" --msl > "$outMsl"
|
||||
# Generate reflection
|
||||
spirv-cross "$outSpv" --reflect > "$outReflect"
|
||||
fi
|
||||
done
|
||||
|
||||
# Fragment shaders
|
||||
for filename in *.frag.hlsl; do
|
||||
if [ -f "$filename" ]; then echo "compiling ${filename}"
|
||||
# Produce SPIR-V
|
||||
dxc -spirv -T ps_6_0 -Fo "spv/${filename/.hlsl/.spv}" "$filename"
|
||||
# Produce DXIL + PDB
|
||||
dxc -Zi -Fd "dxil/${filename/.hlsl/.pdb}" -T ps_6_0 -Fo "dxil/${filename/.hlsl/.dxil}" "$filename"
|
||||
# Convert SPIR-V to Metal Shader Language
|
||||
spirv-cross "spv/${filename/.hlsl/.spv}" --msl > "msl/${filename/.hlsl/.msl}"
|
||||
# Generate reflection
|
||||
spirv-cross "spv/${filename/.hlsl/.spv}" --reflect > "reflection/${filename/.hlsl/.json}"
|
||||
if [ -f "$filename" ]; then
|
||||
outSpv="spv/${filename/.hlsl/.spv}"
|
||||
outDxil="dxil/${filename/.hlsl/.dxil}"
|
||||
outMsl="msl/${filename/.hlsl/.msl}"
|
||||
outReflect="reflection/${filename/.hlsl/.json}"
|
||||
dxc -spirv -T ps_6_0 -Fo "$outSpv" "$filename"
|
||||
shadercross "$filename" -o "$outDxil"
|
||||
# dxc -Zi -Qembed_debug -T ps_6_0 -Fo "$outDxil" "$filename"
|
||||
spirv-cross "$outSpv" --msl > "$outMsl"
|
||||
spirv-cross "$outSpv" --reflect > "$outReflect"
|
||||
fi
|
||||
done
|
||||
|
||||
# Compute shaders
|
||||
for filename in *.comp.hlsl; do
|
||||
if [ -f "$filename" ]; then echo "compiling ${filename}"
|
||||
# Produce SPIR-V
|
||||
dxc -spirv -T cs_6_0 -Fo "spv/${filename/.hlsl/.spv}" "$filename"
|
||||
# Produce DXIL + PDB
|
||||
dxc -Zi -Fd "dxil/${filename/.hlsl/.pdb}" -T cs_6_0 -Fo "dxil/${filename/.hlsl/.dxil}" "$filename"
|
||||
# Convert SPIR-V to Metal Shader Language
|
||||
spirv-cross "spv/${filename/.hlsl/.spv}" --msl > "msl/${filename/.hlsl/.msl}"
|
||||
# Generate reflection
|
||||
spirv-cross "spv/${filename/.hlsl/.spv}" --reflect > "reflection/${filename/.hlsl/.json}"
|
||||
if [ -f "$filename" ]; then
|
||||
outSpv="spv/${filename/.hlsl/.spv}"
|
||||
outDxil="dxil/${filename/.hlsl/.dxil}"
|
||||
outMsl="msl/${filename/.hlsl/.msl}"
|
||||
outReflect="reflection/${filename/.hlsl/.json}"
|
||||
dxc -spirv -T cs_6_0 -Fo "$outSpv" "$filename"
|
||||
dxc -Zi -Qembed_debug -T cs_6_0 -Fo "$outDxil" "$filename"
|
||||
spirv-cross "$outSpv" --msl > "$outMsl"
|
||||
spirv-cross "$outSpv" --reflect > "$outReflect"
|
||||
fi
|
||||
done
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#include "common/common.hlsl"
|
||||
|
||||
struct VSOutput
|
||||
{
|
||||
float4 pos : SV_POSITION;
|
||||
|
||||
@@ -17,5 +17,6 @@ VSOutput main(VSInput input)
|
||||
VSOutput output;
|
||||
output.pos = mul(float4(input.pos, 1.0f), world_to_projection);
|
||||
output.color = input.color;
|
||||
output.color.r = frac(time);
|
||||
return output;
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -34,8 +34,10 @@ struct main0_in
|
||||
vertex main0_out main0(main0_in in [[stage_in]], constant type_TransformBuffer& TransformBuffer [[buffer(0)]])
|
||||
{
|
||||
main0_out out = {};
|
||||
float4 _28 = in.in_var_color;
|
||||
_28.x = fract(TransformBuffer.time);
|
||||
out.gl_Position = float4(in.in_var_pos, 1.0) * TransformBuffer.world_to_projection;
|
||||
out.out_var_COLOR = in.in_var_color;
|
||||
out.out_var_COLOR = _28;
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
}
|
||||
],
|
||||
"types" : {
|
||||
"_6" : {
|
||||
"_7" : {
|
||||
"name" : "type.TransformBuffer",
|
||||
"members" : [
|
||||
{
|
||||
@@ -101,7 +101,7 @@
|
||||
],
|
||||
"ubos" : [
|
||||
{
|
||||
"type" : "_6",
|
||||
"type" : "_7",
|
||||
"name" : "type.TransformBuffer",
|
||||
"block_size" : 316,
|
||||
"set" : 1,
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
struct SDF {
|
||||
float circle(vec2 p, float r)
|
||||
{
|
||||
return length(p) - r;
|
||||
}
|
||||
|
||||
// p = uv point
|
||||
// b = width,height
|
||||
// r = roundedness of the 4 corners
|
||||
float rounded_box(vec2 p, vec2 b, vec4 r)
|
||||
{
|
||||
r.xy = (p.x>0.0)?r.xy : r.zw;
|
||||
r.x = (p.y>0.0)?r.x : r.y;
|
||||
vec2 q = abs(p)-b+r.x;
|
||||
return min(max(q.x,q.y),0.0) + length(max(q,0.0)) - r.x;
|
||||
}
|
||||
|
||||
float box(vec2 p, vec2 b)
|
||||
{
|
||||
vec2 d = abs(p)-b;
|
||||
return length(max(d,0)) + min(max(d.x,d.y),0);
|
||||
}
|
||||
|
||||
float heart( in vec2 p )
|
||||
{
|
||||
p.x = abs(p.x);
|
||||
|
||||
if( p.y+p.x>1.0 )
|
||||
return sqrt(dot2(p-vec2(0.25,0.75))) - sqrt(2.0)/4.0;
|
||||
|
||||
return sqrt(min(dot2(p-vec2(0.00,1.00)), dot2(p-0.5*max(p.x+p.y,0.0)))) * sign(p.x-p.y);
|
||||
}
|
||||
}
|
||||
|
||||
SDF sdf;
|
||||
@@ -1,7 +1,2 @@
|
||||
#include "common/vertex.hlsl"
|
||||
|
||||
// Vertex shader
|
||||
output vertex(output i)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user