#How can i tamper with polygon drawing order with shader?
1 messages · Page 1 of 1 (latest)
if you set the depth test mode to always to ignore depth and change the render queue on the material then you can make something render later.
https://docs.unity3d.com/ScriptReference/Rendering.RenderQueue.html
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.
i mean manually sort polygons, not meshes
i want to make whats called "artist alghoritm"
its a cheap alternative to Z-Buffer, that renders polygons from farthest to nearest
Wha well then you need to make sure the indicies are in a specific order in the mesh
Well i presume you want to control the order in which triangles perform their fragment
otherwise i am lost as to what you want
wait a min
here is an example of the game that uses artist alghoritm instead of Z-Buffer
Looks weird in places as id expect
there is a reason why depth writing and testing exists
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.
no, it sorts polygons, not meshes
we dont have "polygons" we have triangles
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
how can i do that?
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)
and how do i disable depth test in a regular shader?
There are keywords to change these also in text based shaders I forget what they exactly are rn
uhh, it didnt gave me effect i needed
i need for triangles to derp, not whole meshes
What's the difference?
The whole mesh is nothing but triangles
Ah, so triangles not sorted per-mesh but equally between them
"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.
I'd guess maybe render all meshes procedurally as one, and sort the triangles using a compute shader to win back some performance
i mean mesh either fully visible either fully invisible
Meaning that's how it should be, or is but should not be?
i know, i mean somehow change their draw order
look at the screenshot
here is what i want to achieve
note that some triangles acting a little werid
I think I understand
No clue how feasible it is to do though
my only (and totally not the best idea) is to separate all the models into spare triangles
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
That seems intuitive, but probably the worst way to do it
So we're not talking about triangles, but meshes/draw calls?
no it is about triangles its very confusing 😐
yeah... I want to mimic "artist's alghoritm", pretty good alternative to hardware Z-Buffer (but the only point to have it if you are making your own 3D engine with only CPU)
so it basically "sorts" all triangles, and then renders them in strict order that sorting gave
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?
I want it for an effect. In a game i showed it was used to replace Z-Buffer (this game is just PoC)
no, backface culling should be on
visual
You can't say "used to replace", as they serve different purposes. It "had to disable" depth/z testing for the effect to work.
no
you can look at sources: https://github.com/vectozavr/shooter
the sfml branch one
in context of the game i shown without artist algho would look even worse
Looking at the screenshots in the repository it just looks like a bunch of transparent geometry to me.
No "custom triangle ordering"
what???
look at that
exactly, the gun
Definitely nothing special in the gun
definetly you are blind
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.
Maybe show me what exactly I should be looking at and why..?
also on the green ramp there is a big dent
no, it was an indeed solution because cpus dont have hardware depth test, so smth like that was mandatory
Ah I see. It looked like just overlapping polygons first(I'm viewing it from my phone).
Yes, it's a poor(or intentional) implementation of depth test.
more like poor
depth test is running for each pixel
and artist alghoritm only running for each tri
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?
then the answer to the thread is no
because i cant somehow manage tris
if i wanted to make my game in godot, i would just rewrite the engine lmao
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.
the game was written in C++
and if C++ gave hudge bottleneck in fps, then C# implementation will be 1 fps
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.
C# is jit
- You can compile your game with il2cpp, and probably should.
- You're underestimating modern JIT.
if original game gave me around 80 fps, its rewriite in C# will at maximum will give me 60 fps
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.
anyway im just too lazy to do so
Sure. But then there's il2cpp and native libraries that could mitigate it almost entirely.