• entries
14
9
• views
13129

# Ellipses

861 views

Directx, What a pain in the butt! I learned opengl with no problems when it came to using uniform data and sending it to the shaders. Constant Buffers are not nearly as user friendly. I am sure they have wonderful attributes to them, but geez. But I did get my ellipses working along with my curved lines. I am using control points to define the length and width of both and then creating triangles that have u,v points to define the curves.

The Ellipse uvsuv[0] = Vector2f(0.0f, 2.0f);uv[1] = Vector2f(2.0f, 0.0f);uv[2] = Vector2f(0.0f, 2.0f);
The uvs are 2.0 so a curve of 1 radius will touch the hypotenuse (longest side of a right triangle).
The vertices are added along with indices to form a diamond of triangles. The ellipse will be within the triangle.objects[a].shapes.AddVertex(p[0], col[2], uv[0]);objects[a].shapes.AddVertex(p[1], col[2], uv[1]);objects[a].shapes.AddVertex(p[2], col[2], uv[1]);objects[a].shapes.AddVertex(p[3], col[0], uv[2]);objects[a].shapes.AddVertex(p[4], col[2], uv[0]);objects[a].shapes.AddTriangle(0, 3, 1);objects[a].shapes.AddTriangle(0, 2, 3);objects[a].shapes.AddTriangle(4, 1, 3);objects[a].shapes.AddTriangle(4, 3, 2);

I am discarding any pixel that is greater than a length of 1. I am using the uvs to determine length.float4 PShader(float4 position : SV_POSITION, float4 color : COLOR, float2 uv : UV) : SV_TARGET{float result = sqrt(uv.x * uv.x + uv.y * uv.y);if (color.a < 1.0) color = float4(.50, .50, .50, 1.0) * color;if (result > 1) discard; return color;}
[sharedmedia=gallery:images:5748]

## 1 Comment

Just realized the sqrt part was not needed.  Anything less than one squared will still be less than one.  Anything more than one squared will still be more than one.

## Create an account

Register a new account