🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Stupid shader trick

Started by
3 comments, last by JoeJ 3 years, 2 months ago

This is just a stupid shader trick question, nothing very practical, so I'm just asking in case anybody enjoys a puzzle like this. I don't want anybody to spend any effort on it if it isn't enjoyable for them.

I used to do a bit of HLSL, but haven't for a while-- have been trying to improve my modelling in Blender. One thing that I can't do with Blender's materials is get the miplevel, and I kind of miss it from my HLSL days. (And I think, given a miplevel, I could get a dUV/dScreenPos, which would be useful for some things).

But after seeing somebody implementing an edge detect using Blender's bump nodes, to implicitly get neighboring samples, it occurs to me that maybe this is possible via enough trickery.

Let's say you have a texture that you can make-- any image you want, whatever's useful for the task-- and a bump-mapped normal of that texture, and a pre-bump normal. Texture uses filtered lookups. Is it possible to recover the miplevel used for those lookups from the difference between the bump-mapped normal and the pre-bump normal?

Advertisement

bandages said:
Is it possible to recover the miplevel used for those lookups from the difference between the bump-mapped normal and the pre-bump normal?

If i get you right then no - normals in different mips may end up just equal.

But you can get a ‘level of detail’ from distance and knowing your detail levels always increase by a factor of two, for example. But can't remember the math. It was something using log2. While looking for it i found this:

https://media.contentapi.ea.com/content/dam/ea/seed/presentations/2019-ray-tracing-gems-chapter-20-akenine-moller-et-al.pdf

Yeah, the problem is, I don't know my dUV/dPos (delta s/delta x for example in that formula.) If anything, that's what I'd prefer to find out (but if I have the miplevel, I can figure it out.)

Found this example in my code:

float lodF = log2(scaleModelSpaceToVoxels * scaleSampleToWorld * nodeScale * 0.25f);

I use it to select mip level when rasterizing a voxel model ( = texture) to another voxel volume ( = screen with ortho projection)

That's simpler because no perspective projection and rotation involved, but i used similar formulas also for such cases. Maybe i did something like: level = log2(distance * K), where K is some constant you may find with trial and error at first. I assume what you want does not have to be as complicated as the paper above.

This topic is closed to new replies.

Advertisement