Greetings! I’m brand new to the forums so pardon if I’m putting this in the wrong place or format!
I was working in the NME on a skybox shader for mapping equirectangular images to UV spheres and I ran into a big roadblock. To make it work I need to be able to use the actual value of PI and TAU (2*PI) in my calculations. Unfortunately since I can only replace them with a 4 point precision float I end up with a horrible jagged seam where the image ends meets. The rest appears flawless and as expected.
I originally wrote my shader in Unity’s Shadergraph and it works absolutely fine there. Was hoping since math.pi is already a thing we could get that integrated as input options into the NME sooner than later <3
Otherwise thank you guys for making such a wonderful interface for WebXR shaders. It’s been the one thing really keeping me from moving operations mostly over to WebXR from Unity and thanks to the NME (and now the NGE weeeee!) I can bring my special effects to the masses
Just to follow up on this. I did try making a simple custom block that outputs only PI up to 50 decimal places hoping that would help but I’m still getting the jagged seam. Perhaps the engine itself is truncating decimal precision to 4 regardless? I’ve used three separate mathematical formulas to get my image wrapped and every one is producing the exact same issue.
Well that’s interesting about display versus storage. Hmm, maybe PI isn’t my actual issue here then. Either way PI should be a default input block.
In that case I’m not sure what is happening here but this math works fine in Unity Shadergraph. I’m doing all of this in the NME GUI so here’s my several various route attempts all mashed into one for you.
The group it’s currently connected to, if you unclamp the texture’s UVs and use the inspector’s rotate slider you can also see that it’s not the image’s seam causing this since it will rotate and the glitchy seam remains static in place.
Sure why not. You will probably not gain any new information from this but this is a proper demonstration of the same exact math but in Unity Shadergraph:
Tessellation really has nothing to do with it, mesh shape shouldn’t affect anything except the overall silhouette. This effect is entirely dependent on view direction alone (well and the wrap/clamping on the texture file). I made a sample scene with 3 different shapes so you can see what I mean. It’s like looking out of a window in all directions basically. Infinite distance and seamless. I’ve never seen artifacts like this in Unity, the worse I get there is mipmap aliasing on the seam which can be fixed by disabling mipmaps on the panorama texture file.
I wrote this Unity shader years ago and it’s always worked flawlessly. I’ve combined it with other effects too with no problems. So I thought why shouldn’t the most basic math of it work in Babylon right? Yet, it isn’t. And subsequent attempts through different mathematics still produced an identical seam, even across multiple Babylon and custom mesh types, which to me now seems it could be a deeper Babylon issue in view direction calculations but that’s just speculation of course.
However I’ve been working to bring some of my Unity shaders over to the NME for some Frame projects and there’s a few other strange Babylon vs. Unity calculation issues I’ve found that I plan to post about soon as well but I want to keep this topic focused for now
The problem is that Babylon.js tries to generate code in the vertex shader by default, when possible, to save performance.
In your case, the uv calculation is done in the vertex shader, which is why there are some artifacts.
You can force some blocks to execute in the fragment shader by setting their target property to Fragment. That’s what I did for the VectorMerger block in the node material below, which is enough to make all the calculation happen in the fragment shader:
I also set the filtering of the texture to “linear” instead of “linear & mip linear”, else you get a one pixel line artifact.
Ah! I would not have thought of that, brilliant thank you!
Yeah I originally had it on just linear but was frantically playing around with every setting and likely forgot to put it back before saving it. Similar to Unity mips are just not the way.
This is a great tip to know going forward too, it might help explain some of the other oddness I’ve found. Now that I know about this I’ll experiment further before posting.
I actually opened the example before reading what you did, and had a nice long stare between them scrutinizing each connection going “what changed?!” then I came back and read what you did and it all made sense. Thought it was funny though
So to sum up this thread, I guess PI and TAU are not really needed as default inputs after all. If the system remembers more than it displays they can just be pasted floats screw it. But hey look at this lovely new knowledge coming from it all!