1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
uniform float LightType;
uniform float2 Center;
uniform float Radius;
uniform float ValidRadius;
uniform float Intensity;
uniform float3 Color;
uniform shader BackgroundTexture;
float EllipseSDF(in vec2 R, in float Radius) { return length(R) - Radius; }
float RectangleSDF(in vec2 R, in float Radius) { vec2 Box = vec2(Radius, Radius); vec2 Delta = abs(R) - Box; return length(max(Delta, vec2(0.))) + min(max(Delta.x, Delta.y), 0.0); }
float Phi(in float Value) { return 1.0 - pow(Value, 0.3); }
vec3 SDFContribution(in float Distance, in float Intensity, in float ValidRadius, in vec3 Color) { vec3 col = vec3(0., 0., 0.); if (Distance <= 0.0) { float D = Intensity + 1.; col = Color * D; } else if (Distance <= ValidRadius) { float F = (Distance / ValidRadius); float D = Phi(F) * (Intensity + 1.); col = vec3(Color[0] * D, Color[1] * D, Color[2] * D); }
return col; }
vec3 SampleEllipse(in vec2 Center, in vec3 Color, in float Radius, in float ValidRadius, in float Intensity, in vec2 Coord) { vec2 R = Center - Coord;
float sdf = EllipseSDF(R, Radius); return SDFContribution(sdf, Intensity, ValidRadius, Color); }
vec3 SampleRectangle(in vec2 Center, in vec3 Color, in float Radius, in float ValidRadius, in float Intensity, in vec2 Coord) { vec2 R = Center - Coord;
float sdf = RectangleSDF(R, Radius); return SDFContribution(sdf, Intensity, ValidRadius, Color); }
vec3 GammaFixed(in vec3 R) { return vec3(pow(R[0], 0.9), pow(R[1], 0.9), pow(R[2], 0.9)); }
vec4 main(in vec2 fragCoord) { vec4 fragColor = BackgroundTexture.eval(fragCoord); if (LightType < 10.) fragColor += vec4(SampleEllipse(Center, Color, Radius, ValidRadius, Intensity, fragCoord), 1.); else fragColor += vec4(SampleRectangle(Center, Color, Radius, ValidRadius, Intensity, fragCoord), 1.);
return fragColor; }
|