#How can i tamper with polygon drawing order with shader?

1 messages · Page 1 of 1 (latest)

quiet bone
#

I want to alter polygon rendering order a little bit, replacing whats called Z-Buffer

formal crag
formal crag
# quiet bone i need to manually sort them

Then set their render queue to a value that does what you desire. Or render the meshes yourself with Graphics.DrawMesh() and without depth testing they will be in the order you desire.

quiet bone
#

i want to make whats called "artist alghoritm"
its a cheap alternative to Z-Buffer, that renders polygons from farthest to nearest

formal crag
#

Wha well then you need to make sure the indicies are in a specific order in the mesh

quiet bone
#

you mean ccw?

#

because of backface culling?

formal crag
#

Well i presume you want to control the order in which triangles perform their fragment

#

otherwise i am lost as to what you want

quiet bone
#

wait a min

#

here is an example of the game that uses artist alghoritm instead of Z-Buffer

formal crag
#

Looks weird in places as id expect

#

there is a reason why depth writing and testing exists

quiet bone
#

i know

#

and i want this effect

formal crag
#

using shader graph you can disable depth write and make depth test always pass and it should produce a similar effect.
It would require careful ordering of mesh drawing however and im not sure how to achieve the effect any better myself.

quiet bone
formal crag
#

we dont have "polygons" we have triangles

quiet bone
#

ok, that changes nothing

#

that is what i meant

formal crag
#

transparent rendering already does something like what you want. Unity will draw meshes in order based on distance from the camera and they don't write depth.

#

id play around and see what you can get

formal crag
#

using standard/urp lit/whatever you can change it to transparent and that should already disable depth writing.
It still will depth test but because the mesh is not writing depth as it draws its triangles can be in the "wrong order".

Or with a shader graph shader you can customise depth writing and depth testing (as shown in the image)

quiet bone
formal crag
#

There are keywords to change these also in text based shaders I forget what they exactly are rn

quiet bone
#

uhh, it didnt gave me effect i needed

#

i need for triangles to derp, not whole meshes

rapid vault
#

Ah, so triangles not sorted per-mesh but equally between them

gentle dagger
#

"ordering polygons/triangles in a mesh during rendering" doesn't make sense. Vertex shaders run many threads for several vertices(and as a consequence, triangles) at the same time. That's exactly what makes the GPU faster than Cpu. Making them run in order, would kill performance.
You could probably implement software rasterization on the cpu, but prepare to lose a lot of the frame budget to it. And I'm not sure how you'd approach it in unity anyway.

rapid vault
#

I'd guess maybe render all meshes procedurally as one, and sort the triangles using a compute shader to win back some performance

quiet bone
#

i mean mesh either fully visible either fully invisible

rapid vault
quiet bone
quiet bone
quiet bone
#

note that some triangles acting a little werid

rapid vault
#

I think I understand
No clue how feasible it is to do though

quiet bone
#

my only (and totally not the best idea) is to separate all the models into spare triangles

rapid vault
#

Maybe the combined mesh idea has a chance of working, or you could look into what kind of control a custom SRP would give you over rendering

rapid vault
gentle dagger
formal crag
#

no it is about triangles its very confusing 😐

quiet bone
#

so it basically "sorts" all triangles, and then renders them in strict order that sorting gave

gentle dagger
#

I don't think it's a "good alternative" for hardware depth testing.
And the purpose seems to be completely different. The former one is an optimization technique. The latter seems to be an artistic visual effect.

#

You could try disabling depth testing, backface culling and making the shader transparent. This would get closer to your desired effect, but the screenshot you shared earlier seems to be more than just that.

#

What is the goal you're trying to achieve anyway? Is it the specific visual look or are you assuming that would improve performance?

quiet bone
quiet bone
gentle dagger
quiet bone
#

the sfml branch one

quiet bone
gentle dagger
#

Looking at the screenshots in the repository it just looks like a bunch of transparent geometry to me.

#

No "custom triangle ordering"

quiet bone
#

look at that

#

exactly, the gun

gentle dagger
#

Definitely nothing special in the gun

quiet bone
#

definetly you are blind

gentle dagger
#

3D game engine with custom CPU rendering
So you can virtually do anything with it. At the cost of performance. I don't think it's worth using unity if you want to reimplement it.

gentle dagger
quiet bone
quiet bone
gentle dagger
# quiet bone

Ah I see. It looked like just overlapping polygons first(I'm viewing it from my phone).

gentle dagger
quiet bone
#

more like poor

#

depth test is running for each pixel

#

and artist alghoritm only running for each tri

gentle dagger
#

But that doesn't change the fact that it's a cpu rendering technique and you can't really adapt it to use in unity. You could implement software rasterization in C#, writing to a texture and then rendering the final image normally on the gpu(via a ui raw image) for example. But why..? Can't you just use that engine instead?

quiet bone
#

because i cant somehow manage tris

#

if i wanted to make my game in godot, i would just rewrite the engine lmao

gentle dagger
# quiet bone because i cant somehow manage tris

You can. You can totally modify triangle order in a mesh. It's just that it wouldn't help much with GPU rendering.
And with cpu rendering you might not even need to. You can have a separate collection of indices or some other mechanism to render them in the order that you want.

#

It all falls down to implementing the cpu renderer.

quiet bone
#

the game was written in C++

#

and if C++ gave hudge bottleneck in fps, then C# implementation will be 1 fps

gentle dagger
#

There wouldn't be much difference.

#

You seem to misunderstand the difference between C++ and C#.

#

And if you really wanted to, you could write it in C++ and use as a native plugin.

#

But yeah, it's gonna be heavy either way. There's a reason no one is rendering games on the cpu.

#

It might be feasible in a very simple scene with minimal rendering features, but even then you'll get less frame time for other stuff in your game.

gentle dagger
#
  1. You can compile your game with il2cpp, and probably should.
  2. You're underestimating modern JIT.
quiet bone
#

if original game gave me around 80 fps, its rewriite in C# will at maximum will give me 60 fps

gentle dagger
#

There might be like 10-20% difference, and even that in edge cases. Most C++ code isn't even using C++ to its max capabilities. Same about C# though.

quiet bone
#

anyway im just too lazy to do so

gentle dagger