custom camera FOV ?

Blitz3D Forums/Blitz3D Beginners Area/custom camera FOV ?

RemiD(Posted 2016) [#1]
hello,

is there a way to change the camera fov, by specifying an angle of view (like 90°) ?
i have found this :
Function SetCameraFOV(Camera, FOV#)
 CameraZoom Camera, 1.0 / Tan(FOV#/2.0)
End Function

here : http://www.blitzbasic.com/codearcs/codearcs.php?code=676

is this correct ?

thanks,


RemiD(Posted 2016) [#2]
after some tests, i don't think this is correct, the camera field of view is different than a zoom...

what i am looking for is a function to increase/decrease the camera fov so that the entities which are outside the fov will be automatically not considered for rendering.
this can be useful when trying to render only a small area at the center of the screen (for example a 2w2h cameraviewport) to detect the color of the shape which is in front of and nearest to the camera.

i suppose that i could code a procedure to determine which entities are in a kind of cone or box in front of the camera, considering their centers and bounding box extremities...


Bobysait(Posted 2016) [#3]
Don't really understand what you're looking for.
Perhaps the CameraViewport command ?
CameraViewport cam, 0,0,1,1
(and maybe set the zoom to something big enough ... while using CameraProjMode 2 it will flatten the view and enlarge it so it will only show what you want)


RemiD(Posted 2016) [#4]
@Bobysait>>i am rather looking for a way to keep the same camera fov (apparently 90° is the default for Blitz3d (camerazoom 1.0)) but reduce the "view frustum" so that only a few meshes in front of the camera and near enough the camera are considered for rendering.
but apparently there is no function to do that...


Bobysait(Posted 2016) [#5]
then make a renderworld with projmode 2 and use the camera range to reduice the display of the entities -> in projmode 2 (orthographics) the range set the aspect of the camera, not only the depth.


RemiD(Posted 2016) [#6]
this does not help because the number of meshes rendered stays the same. the idea is to decrease the rendering time.

i will code my own procedure to hide all meshes and show only the meshes which are in an oriented cone or in an oriented box in front of the camera but it would be a good functionality to have...


Bobysait(Posted 2016) [#7]
you don't use it correctly then.
If the viewport is smaller and the focus is lower, there is less entity in the frustum, so less entity rendered.

I doubt you're implementing it well, or ... I really don't understand what you're trying to do.

[edit]
Wait ...
You're trying to remove entities from the rendering pass while they are actually visible from the camera when rendering ?
No way you can do that unless you do it manually.


RemiD(Posted 2016) [#8]

If the viewport is smaller and the focus is lower, there is less entity in the frustum, so less entity rendered.


not true here, with a cameraviewport of 2w2h or with a cameraviewport of 640w480h the same number of triangles are rendered, and the cameraprojmode "orthographic " does not decrease the number of triangles rendered either... (assuming trisrendered() returns the correct number... i put it just after renderworld())


_PJ_(Posted 2016) [#9]
Function SetCameraFOV(Camera, FOV#)
CameraZoom Camera, 1.0 / Tan(FOV#/2.0)
End Function

This is the correct method to change the horizontal field-of-view angle.

Blitz3D offers no support for changing the vertical Field of View.

__
i am rather looking for a way to keep the same camera fov (apparently 90° is the default for Blitz3d (camerazoom 1.0)) but reduce the "view frustum" so that only a few meshes in front of the camera and near enough the camera are considered for rendering.
but apparently there is no function to do that...
__
In which case you ought to consider:


CameraRange and CameraFogRange* can affect the rendering of ALL geometry along a relative Z axis.
For sepcific entities, use EntityAutoFade


*You must remember to set CameraFogMode for Fog effects.


RemiD(Posted 2016) [#10]
@_PJ_>>thanks, i know about camerarange :)
i am rather talking about the shape of the frustrum, not only the range.
the idea was to keep the same FOV but to be able to only render the meshes which are inside a thin box/cone starting at the camera pov and going forward (taking into account the orientation of the camera), without having to do the calculations with a custom procedure (which may take more time than rendering all entities in the fov)


Bobysait(Posted 2016) [#11]

not true here, with a cameraviewport of 2w2h or with a cameraviewport of 640w480h the same number of triangles are rendered, and the cameraprojmode "orthographic " does not decrease the number of triangles rendered either... (assuming trisrendered() returns the correct number... i put it just after renderworld())


I told you to use cameraviewport AND CameraZoom or CameraRange (and/or use projmode)
Only setting the viewport does not change the "entity in frustum test" it only lowers the resolution for your rendering.
Setting CameraRange in orthographic mode will lower the frustum, so the "entity in frustum test" will remove a lot of entities.
(same for CameraZoom in perspective mode)
Use both and it will work.


RemiD(Posted 2016) [#12]
double post


RemiD(Posted 2016) [#13]
@Bobysait>>no, if i assume that what trisrendered() returns after the renderworld is correct, it does not change the number of triangles rendered... (even with a cameraviewport of 2w2h and a cameraprojmode "orthographic " (i don't want to change the camera fov/zoom or the camerarange)


RemiD(Posted 2016) [#14]
wait, what do you mean by "focus is lower":

If the viewport is smaller and the focus is lower, there is less entity in the frustum, so less entity rendered.




Bobysait(Posted 2016) [#15]
field of view of the camera.
set by CameraZoom and/or CameraRange (camerarange (the near divided by the far) should modify the aspect of the view)


@Bobysait>>no, if i assume that what trisrendered() returns after the renderworld is correct, it does not change the number of triangles rendered... (even with a cameraviewport of 2w2h and a cameraprojmode "orthographic " (i don't want to change the camera fov/zoom)


If there is a single entity and it's partially visible, it's fully rendered.
frustum culling only affect entities, not triangles

But anyway, if you don't want to modify the zoom, then you're ... screwed :)


Floyd(Posted 2016) [#16]
So to summarize, making a viewport half as big as the screen will clip the drawing to a smaller area, but will still render everything. It will all appear half size.

Then setting camerazoom to 2 will cancel out the "half size" problem. Entities which are now completely out of view will not be rendered.


RemiD(Posted 2016) [#17]
Yes but if you decrease the camera fov, the view is not the same, so what i want is rather to modify the camera frustrum in order to render only the meshes which are in front of the camera (like in a 1width x 1height x camerangedepth box), but since there is no function to do that, i will code my own procedure...


Midimaster(Posted 2016) [#18]
I did something similar in my car racing game. I have a lot of trees (>2000) and big problems with performance. I decided only to render the trees which are near (left and right) to the "ahead" direction of the camera. The "maximum angle" should stay variable. And I wanted to prefer those trees which are closer to the camera. So the distance should stay variable.

So each loop the algo started searching trees and after it found 200 trees all other trees were "switched of". This was very fast (<1ms) and rendering the 200 trees caused no performance problems any more.

A selfmade "swich-off" algo will be faster than the camera settings.


RemiD(Posted 2016) [#19]
double post


RemiD(Posted 2016) [#20]
What i want to achieve is to do a small 2w2h (or 1w1h) render with only colored shapes (fullbright) which are in front of the camera (taking into account its orientation), (without changing the camera fov/zoom) but only render the shapes which are in an area small in width and height but long in depth (corresponding to the camerarange), so that i can then analyze the rendered color and determine if the rendered shape corresponds to a targeted vertex/texel (already colored with this color, in fullbright) (this is for a vertices lighting/shading procedure or for a texels lighting/shading procedure)

if i would be able to define the view frustum, this would speed up the render a lot ! but i will try to hide all meshes and show only the necessary meshes (in the area in front of the camera) with my own procedure and maybe it will be fast enough (i doubt it)


Flanker(Posted 2016) [#21]
Maybe you can use DeltaPitch and DeltaYaw to know if an entity is near the center of the camera. If your camera doesn't "roll" on its Z axis, you can define a window in degrees :



I hope it is what you're looking for.


Kryzon(Posted 2016) [#22]
I think what you're after is called the "scissor test", being able to define a rectangle on the screen that crops rendering to that area.
This is not the same as the viewport (with which you'd have to use zoom as well, like Floyd mentioned). You can set a scissor rectangle to only render to a region of the viewport.

You need access to some D3D functions.
Maybe you can do it with those DX7 DLLs like AShadow.

https://msdn.microsoft.com/pt-br/library/windows/desktop/bb147354(v=vs.85).aspx


RemiD(Posted 2016) [#23]
@Flanker>>yes i have thought of using deltapitch and deltayaw to do a point in an oriented cone check, or i can use a point in an oriented box check.
i know i can use my own procedures, but if i do that for many entities this will probably take too much time and be useless...
being able to set the shape of the view frustum would automatically not render the meshes which are out of the view frustum and thus be faster. but there is no functionality to do that, so i will try with my own procedure... (similar to what you suggest)


RemiD(Posted 2016) [#24]
@Flanker>>i have tested to use a check using deltapitch and deltayaw (i use 10degrees) and it is fast enough if there are less than 100 entities in the zone. thanks


gpete(Posted 2016) [#25]
just use this;

its in the online manual...
---------------------------------------

CameraZoom camera,zoom#

Parameters:
camera - camera handle
zoom# - zoom factor of camera

Description:
Sets zoom factor for a camera. Defaults to 1.

Example:
None.


Flanker(Posted 2016) [#26]
Hello RemiD, you can have better performances by separating DeltaPitch and DeltaYaw checks :
	For e.entity = Each entity
		If Abs(DeltaYaw(camera,e\mesh)) < 20
			If Abs(DeltaPitch(camera,e\mesh)) < 10
				ShowEntity e\mesh
			Else
				HideEntity e\mesh
			EndIf
		Else
			HideEntity e\mesh
		EndIf
	Next


Anyway, there is a problem I didn't see at first, it works well only for entities at the same Z as the camera... Try to look up or down in my example, with 10000 entities and you'll see what I mean.

Maybe you can use CameraProject to check if an entity is in a specific window on the screen, I don't know if it's fast.


Guy Fawkes(Posted 2016) [#27]
hello,

is there a way to change the camera fov, by specifying an angle of view (like 90°) ?
i have found this :

Function SetCameraFOV(Camera, FOV#)
 CameraZoom Camera, 1.0 / Tan(FOV#/2.0)
End Function



here : http://www.blitzbasic.com/codearcs/codearcs.php?code=676

is this correct ?

thanks,


Why don't you do it yourself, Remi? Since you seem to know everything. Have a nice day, I'm not going to be posting to you anymore. You do not DESERVE my presence.

Make fun of this all you want. I'm done.

Bye!


RemiD(Posted 2016) [#28]
@Guy Fawkes>>i am not asking for somebody else to create (or debug) code for me (contrary to what you often do) but just asking for a way to achieve this.


Have a nice day,


have a nice day too


I'm not going to be posting to you anymore.


good


You do not DESERVE my presence.


i indeed don't, please focus on doing your more important things.


RemiD(Posted 2016) [#29]
@Flanker>>i see what you mean, maybe a good alternative (for what i want to achieve) would be to use math to calculate a 3dpoint in an oriented 3dbox or a 3dpoint in an oriented 3dcone, or a 3dpoint in a view frustum... I will see what i can find on the web (this is not urgent anyway)
Thanks,


gpete(Posted 2016) [#30]
random thought..... how about a rectangular line pick function- that can detect shapes, mesh etc....like a scanning beam...