My project asks for realtime shadows and a z-fighting effect.
The problem is, apparently I have to choose one. The only Rendering Path that seems to enable realtime shadows with point lights is Deferred Lighting, but it’s so good that kills all z-fighting effects I created by placing objects on top of each other.
So, I think the solution to have realtime shadows with point lights and z-fighting effects would be to use a shader to simulate the effect, which is not static as a texture, but changes as the camera that is rendering moves.
I have no experience with shaders.
Maybe someone could help with it? Please.
I really need a shader to produce this effect, since my tests showed me that even with the same build, the z-fighting does not occur on some machines. I create z-fighting effects by positioning objects reeeeeally close to each other, but not on the same position.
I think it has something to do with GPUs, but I have no idea and I really hope I’m wrong, because would be impossible to predict what gpus my players would have.
Anyone helping in the shader, please?
Any ideas how to fix this?
Thanks
Z-fighting is generally seen as an ugly error to be avoided. It is a result of errors when trying to determine the depth of an object/pixel at render time. Because games are virtual, objects can physically inhabit the same space/plane and the math used to sort and render each pixel doesn’t care if such a thing as two pixels coexisting in the exact same space-time coordinates, it’ll try to render them anyway and generally when you tell a computer to attempt something impossible the results are no very pretty.
I have no idea why you’d want to produce such a problem intentionally, regardless It is most defiantly not a good idea to rely on errors and glitches for “effects”.
Perhaps if you described the intended effect rather than the final visual result someone could point you in the right direction. All I can suggest right now is to read up on the concept of moire patterns and other similar optical artefacts that you might be able to re-produce with careful texture creation and point filtering.
Yes, it’s wrong to bet my cards on something I have no control of. But the game asks for the aesthetic effect.
What I need is the most approximate visual of the z-fighting, not necessarily being a real z-fighting problem happening in real time.
Thanks for the tip on moire patterns, I’ll read that and try to extract useful informations.
Well, the intended effect is something like a texture flickering, something producing visually very weird optical artifacts when the player rotates the camera (though would be ok if it happens whike the camera is idle).
I like the idea to reproduce it with textures, but what do you think is the best solution? The effect will happen with more than one object, so I think would be better to have something I can apply to any object and get the visual effect (affecting its texture, maybe changing the material for a “moireMaterial” which would create the effect on top of that).
Creating a moire-like texture, setting its Filter Mode to Point and animating the texture?
Sorry, I’m a bit confused.
Shouldn’t be too difficult. Create a large texture and animate UV offsets based on view angle in a shader. Perhaps not even that, just modulate the base texture with a colour derived from perlin noise seeded with the view angle. You’ll probably want to use a custom lighting model surface shader which gives you the view angle normal vector for each pixel:
Thank you.
I’m almost out of time atm, but I intent to read it soon.
Meanwhile, I’m using the “UVScroller.js” script which comes with Bootcamp Demo (that neat unity 3 example project), more precisely at Scripts>graphics.
To use it:
Create a Diffuse Detail material;
Add the base moiré pattern texture in the Base slot;
Add a second moiré pattern texture in the Detail slot (same as the base one but slightly rotated to create the visual glitch);
In the “Texture to Scroll”, set at least Size 1;
Write “_Detail” in the Element 0 (this is because you want to UVScroll only the texture you inserted in the Deail slot of the material;