Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- matrix orthoProjMatrix;
- float4 elementSize;
- float4 strokeWidth;
- float4 ellipseParams;
- struct VertexShaderInput
- {
- float3 position : POSITION0;
- float4 color : COLOR0;
- float2 texCoord : TEXCOORD0;
- };
- struct PixelShaderInput
- {
- float4 position : POSITION0;
- float2 texCoord : TEXCOORD0;
- float4 color : TEXCOORD1;
- };
- void VertexMain(in VertexShaderInput vsInput, out PixelShaderInput output)
- {
- output = (PixelShaderInput)0;
- output.position = mul(float4(vsInput.position, 1), orthoProjMatrix);
- output.texCoord = vsInput.texCoord;
- output.color = vsInput.color;
- }
- float getEllipseRadius(float x, float y)
- {
- float phi = atan2(y, x);
- float a2 = ellipseParams.x * ellipseParams.x;
- float b2 = ellipseParams.y * ellipseParams.y;
- float ab = ellipseParams.x * ellipseParams.y;
- float sin2 = sin(phi) * sin(phi);
- float cos2 = cos(phi) * cos(phi);
- return (ab) / sqrt(a2 * sin2 + b2 * cos2);
- }
- void PixelMainFill(in PixelShaderInput input, out float4 color : COLOR0)
- {
- float elemX = (-elementSize.x / 2.0f) + elementSize.x * input.texCoord.x;
- float elemY = (-elementSize.y / 2.0f) + elementSize.y * input.texCoord.y;
- float radius = getEllipseRadius(elemX, elemY);
- float radiusCoord = sqrt(elemX * elemX + elemY * elemY);
- if(radiusCoord <= radius)
- color = input.color;
- else
- {
- float diff = radiusCoord - radius;
- if(diff > 3)
- color = float4(0, 0, 0, 0);
- else
- color = lerp(input.color, float4(0, 0, 0, 0), diff / 3.0f);
- }
- }
- void PixelMainDraw(in PixelShaderInput input, out float4 color : COLOR0)
- {
- float elemX = (-elementSize.x / 2.0f) + elementSize.x * input.texCoord.x;
- float elemY = (-elementSize.y / 2.0f) + elementSize.y * input.texCoord.y;
- float radius = getEllipseRadius(elemX, elemY);
- float radiusCoord = sqrt(elemX * elemX + elemY * elemY);
- if(radiusCoord <= radius)
- {
- if((radius - radiusCoord) <= strokeWidth.x)
- color = input.color;
- else
- {
- float diff = (radius - radiusCoord) - strokeWidth.x;
- if(diff > 3)
- color = float4(0, 0, 0, 0);
- else
- color = lerp(input.color, float4(0, 0, 0, 0), diff / 3.0f);
- }
- }
- else
- {
- float diff = radiusCoord - radius;
- if(diff > 3)
- color = float4(0, 0, 0, 0);
- else
- color = lerp(input.color, float4(0, 0, 0, 0), diff / 3.0f);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment