#Drawing lines in a compute shader

1 messages · Page 1 of 1 (latest)

keen flax
#

So I'm basically making a simple 2D RayTracing engine (don't ask why) and i'm drawing thousands of lines every frame which makes my pc lag because it's all running on my poor CPU :( so i want to make it run on my GPU so it's hopefully faster. From what I've read online, I'm pretty sure i should use a compute shader but I don't think it's got GL functionality.

Now if some of you smart people know how to fix those weird patterns in the light, you're also welcome to help :)

Code on StackOverflow: https://stackoverflow.com/questions/74590679/drawing-gl-lines-in-a-compute-shader

eternal nymph
#

Post your question and code here

keen flax
#

`//RenderLines is called onPostRender (I want to draw it under GameObjects but it doesn't work :/)
void RenderLines(Camera cam)
{
DrawLines();
}

void DrawLines()
{
    //Loop lineCount times and render a line for each loop
    for (int i = 0; i < lineCount; i++)
    {
        float curRot = i * (diameter / lineCount) - angle;
        Vector2 pos = GetRotation2D(transform.position, reach, curRot);
        
        RaycastHit2D hit = Physics2D.Raycast(transform.position, pos  - (Vector2)transform.position, reach);
        if (hit.collider != null)
        {
            pos = hit.point;
        }

        RenderLine(pos);
    }
}

//Get position from angle?
Vector2 GetRotation2D(Vector3 center, float dist, float ang)
{
    Vector2 pos = new Vector2();

    pos.x = center.x + (dist * Mathf.Cos(ang / (180f / Mathf.PI)));
    pos.y = center.y + (dist * Mathf.Sin(ang / (180f / Mathf.PI)));

    return pos;
}

//Render a line using GL
void RenderLine(Vector2 point)
{
    GL.Begin(GL.LINES);
    material.SetPass(0);
    GL.Color(rayColor);
    GL.Vertex(transform.position);
    GL.Vertex(point);
    GL.End();
}`
eternal nymph
#

I'm confused

keen flax
#

wha

eternal nymph
#

there is no GL on compute shader

#

so what you ask is not possible if I understand correctly

#

@keen flax

keen flax
#

._.

eternal nymph
#

[]xy

vital mothBOT
#

The XY Problem

The XY problem is asking about your attempted solution rather than your actual problem. This leads to enormous amounts of wasted time and energy, both on the part of people asking for help, and on the part of those providing help.

  • You want to do X
  • You don't know how to do X, but think you can solve it if you can just about manage to do Y
  • You don't know how to do Y either, so you ask for help with Y
  • Others try to help you with Y, but are confused because Y seems like a strange problem to want to solve
  • After much interaction and wasted time, it finally becomes clear that the you really want help with X, and that Y wasn't even a suitable solution for X
    Source: http://xyproblem.info/

Please include information about a broader picture along with any attempted solution, including solutions you have already ruled out and why.

keen flax
#

I guess I'll try to render a texture and put it under objects or something idk

eternal nymph
#

what is your actual problem

keen flax
#

I want to draw lines

eternal nymph
#

bruh

keen flax
#

I like lines

#

But they are slow

eternal nymph
#

See that makes more sense

#

so you should have asked: how can I draw lines using a compute shader

keen flax
#

Oh yeah

#

Whoops

#

Drawing lines in a compute shader

eternal nymph
#

feel like a compute shader might not even be the best tool

#

maybe just a normal shader could do it

keen flax
#

Ok

eternal nymph
#

like you might need to collect your line draw calls together

#

so instead of sending one by one send a bunch in a batch