Skip to content

Commit

Permalink
Re-enabled debug circle rendering with fill.
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewRichards-Code committed Nov 27, 2024
1 parent e8570d3 commit e798e0f
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 31 deletions.
86 changes: 60 additions & 26 deletions CrossPlatform/RenderPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1225,32 +1225,48 @@ void RenderPlatform::DrawCircle(GraphicsDeviceContext &deviceContext,const doubl

void RenderPlatform::DrawCircle(GraphicsDeviceContext &deviceContext,const float *pos,const float *dir,float radius,const float *colr,bool fill,bool view_centred)
{
PosColourVertex line_vertices[36];
vec3 direction(dir);
direction = normalize(direction);
vec3 z(0,0,1.f);
vec3 y(0,1.f,0);
vec3 x=cross(z,direction);
if(length(x)>.1f)
x=normalize(x);
vec3 z(0, 0, 1.f);
vec3 y(0, 1.f, 0);
vec3 x = cross(z, direction);
if (length(x) > .1f)
x = normalize(x);
else
x=cross(direction,y);
x*=radius;
y = cross(direction , x);
int l=0;
for(int j=0;j<_countof(line_vertices);j++)
{
float angle =(float(j)/float(_countof(line_vertices)-1))*2.0f*3.1415926536f;
vec3 p =vec3((x * cos(angle) + y * sin(angle)));
line_vertices[l].pos =vec3(pos)+p;
line_vertices[l++].colour =colr;
x = cross(direction, y);
x *= radius;
y = cross(direction, x);

mat4 wvp;
if (view_centred)
crossplatform::MakeCentredViewProjMatrix((float *)&wvp, deviceContext.viewStruct.view, deviceContext.viewStruct.proj);
else
crossplatform::MakeViewProjMatrix((float *)&wvp, deviceContext.viewStruct.view, deviceContext.viewStruct.proj);
debugConstants.debugWorldViewProj = wvp;
debugConstants.debugWorldViewProj.transpose();
debugConstants.debugColour = colr;
debugConstants.centre_position = pos;
debugConstants.x_axis = x;
debugConstants.y_axis = y;
SetConstantBuffer(deviceContext, &debugConstants);

EffectTechniqueGroup *group = debugEffect->GetTechniqueGroupByName("circle");
if (fill)
{
debugEffect->Apply(deviceContext, group->GetTechniqueByName("filled"));
SetTopology(deviceContext, Topology::TRIANGLESTRIP);
Draw(deviceContext, 64, 0);
debugEffect->Unapply(deviceContext);
}
DrawLines(deviceContext, line_vertices, _countof(line_vertices), true, false, view_centred);

debugEffect->Apply(deviceContext, group->GetTechniqueByName("outline"));
SetTopology(deviceContext, Topology::LINESTRIP);
Draw(deviceContext, 32, 0);
debugEffect->Unapply(deviceContext);
}

void RenderPlatform::DrawCircle(GraphicsDeviceContext &deviceContext, const double *pos, const double *dir, double radius, const float *colr, bool fill, bool view_centred)
{
PosColourVertex line_vertices[36];
vec3d direction(dir);
direction = normalize(direction);
vec3d z(0, 0, 1.0);
Expand All @@ -1262,15 +1278,33 @@ void RenderPlatform::DrawCircle(GraphicsDeviceContext &deviceContext, const doub
x = cross(direction, y);
x *= radius;
y = cross(direction, x);
int l = 0;
for (int j = 0; j < _countof(line_vertices); j++)
{
double angle = (double(j) / float(_countof(line_vertices) - 1)) * 2.0 * 3.1415926536;
vec3d p = vec3d((x * cos(angle) + y * sin(angle)));
line_vertices[l].pos = vec3(vec3d(pos) + p);
line_vertices[l++].colour = colr;

mat4 wvp;
if (view_centred)
crossplatform::MakeCentredViewProjMatrix((float *)&wvp, deviceContext.viewStruct.view, deviceContext.viewStruct.proj);
else
crossplatform::MakeViewProjMatrix((float *)&wvp, deviceContext.viewStruct.view, deviceContext.viewStruct.proj);
debugConstants.debugWorldViewProj = wvp;
debugConstants.debugWorldViewProj.transpose();
debugConstants.debugColour = colr;
debugConstants.centre_position = pos;
debugConstants.x_axis = x;
debugConstants.y_axis = y;
SetConstantBuffer(deviceContext, &debugConstants);

EffectTechniqueGroup *group = debugEffect->GetTechniqueGroupByName("circle");
if (fill)
{
debugEffect->Apply(deviceContext, group->GetTechniqueByName("filled"));
SetTopology(deviceContext, Topology::TRIANGLESTRIP);
Draw(deviceContext, 64, 0);
debugEffect->Unapply(deviceContext);
}
DrawLines(deviceContext, line_vertices, _countof(line_vertices), true, false, view_centred);

debugEffect->Apply(deviceContext, group->GetTechniqueByName("outline"));
SetTopology(deviceContext, Topology::LINESTRIP);
Draw(deviceContext, 32, 0);
debugEffect->Unapply(deviceContext);
}

void RenderPlatform::SetModelMatrix(GraphicsDeviceContext &deviceContext, const double *m, const crossplatform::PhysicalLightRenderData &physicalLightRenderData)
Expand Down
10 changes: 5 additions & 5 deletions CrossPlatform/Shaders/debug.sfx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ shader v2f CircleVS(idOnly IN)
{
v2f OUT;
float angle =2.0*3.1415926536*float(IN.vertex_id)/31.0;
vec4 pos =vec4(100.0*vec3(radius*vec2(cos(angle),sin(angle)),1.0),1.0);
vec4 pos =vec4(vec3(x_axis*cos(angle)+y_axis*sin(angle))+centre_position,1.0);
OUT.hPosition =mul(debugWorldViewProj,vec4(pos.xyz,1.0));
OUT.colour =debugColour;
return OUT;
Expand All @@ -101,10 +101,10 @@ shader v2f CircleVS(idOnly IN)
shader v2f FilledCircleVS(idOnly IN)
{
v2f OUT;
// int i=int(IN.vertex_id/2);
int j=int(IN.vertex_id%uint(2));
float angle =2.0*3.1415926536*float(IN.vertex_id)/31.0;
vec4 pos =vec4(100.0*vec3(radius*j*vec2(cos(angle),sin(angle)),1.0),1.0);
int i =int(IN.vertex_id/2);
int j =int(IN.vertex_id%uint(2));
float angle =2.0*3.1415926536*float(i)/31.0;
vec4 pos =vec4(vec3(x_axis*cos(angle)+y_axis*sin(angle))*j+centre_position,1.0);
OUT.hPosition =mul(debugWorldViewProj,vec4(pos.xyz,1.0));
OUT.colour =debugColour;
return OUT;
Expand Down
7 changes: 7 additions & 0 deletions CrossPlatform/Shaders/debug_constants.sl
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,12 @@ SIMUL_CONSTANT_BUFFER(DebugConstants,7)

uniform vec3 line_end;
uniform float dc_pad3;

uniform vec3 centre_position;
uniform float dc_pad4;
uniform vec3 x_axis;
uniform float dc_pad5;
uniform vec3 y_axis;
uniform float dc_pad6;
SIMUL_CONSTANT_BUFFER_END
#endif

0 comments on commit e798e0f

Please sign in to comment.