Hi.
In my previous post I made a distance shader in 2 days (with a bunch of problems).
I can now make it work (without problems), but I do have to pass a value (the location of the camera) every update.
Thus, I looked into other ways to solve this, and I have re-found Filters.
Now I am wondering if it is possible to achieve this using a filter:
It uses the (world) position & camera position to calculate distance (per object).
If it even is possible to do this with a filter, how should I do this?
NOTE: I know little about filters, mainly because of the lack of a normal tutorial on it.
What exactly is wrong with that?
Though you can use “uniform vec3 g_CameraPostion;” that is a global uniform that passes the world space position of the camera to your shader without the need of passing it yourself.
You have to declare CameraPositon in the WorldParam section of your technique in the j3md file.
In a more general way you can use all these predefines global uniforms and if you declare them the engine will pass them for you on each frame.
all global uniforms have to be declared with a “g_” prefix in the shader to be used.
The depth of field filter calculates distance per screen pixel if that’s what you are interested in. It’s using the z-buffer so its distances are only as accurate as the z-buffer inversion.
I believe that filter’s shader even has a big long comment about how it does the calculation to get distance from the z-buffer… including a URL as I recall.