OK nz0, now I better understand what you're trying to do. My advice for a lens flare effect is to drop the near plane clipping approach entirely and just use depth write/read. I have a lot of lens flare effects in my games (the Evochron link in my signature is one) and I basically use this technique:
- Create lens flare plane surfaces for each segment of the effect.
- Apply the blend mode and transparency needed to apply it additive/mixed on top of anything else in the scene.
- Depending on requirements, apply SetObjectDepthWrite(obj,0) or SetObjectDepthReadMode(obj,7) to remove depth sorting.
I use a column of lens flares that stack out toward the light source with elements on each side of the central viewing angle of the camera. So my placement setup looks something like this:
- Place a hidden guide object at camera, point in the direct of the camera, move out to the minimum near plane distance I need/want.
- Point the hidden guide object at the light source and move forward/backward along the column angle needed for placing each flare.
- Place flares at required points, adjust spacing from camera to stay close the near plane.
- Scale and fade as needed based on angle to light source from camera center position.
- Realign all flares with the camera's angle, rotate on local Z for angle to light source.
Some of that is optional and can be done in different ways, so it's a flexible method. Here are a couple of helper functions that I use to align objects with each other and objects to the camera for such operations:
+ Code Snippetfunction SetObjectToCameraOrientation(obj,cam)
SetObjectRotationQuat(obj,GetCameraQuatW(cam),GetCameraQuatX(cam),GetCameraQuatY(cam),GetCameraQuatZ(cam))
endfunction
function SetObjectToObjectOrientation(objFrom,objTo)
SetObjectRotationQuat(objFrom,GetObjectQuatW(objTo),GetObjectQuatX(objTo),GetObjectQuatY(objTo),GetObjectQuatZ(objTo))
endfunction