Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rlgl] Add rlCullDistance variables/getters and rlSetClipPlanes function #3912

Merged
merged 1 commit into from
Apr 23, 2024

Conversation

KotzaBoss
Copy link
Contributor

@KotzaBoss KotzaBoss commented Apr 11, 2024

NOTE: The PR at the moment is just a proof-of-concept to show the scale of modifications necessary to make this happen. Should it be reviewed well i will add the utils for rlClipDistanceNear and fix any use of RL_CULL_DISTANCE*, for example in the camera. Also i am not too sure about the name, when "cull" when "clip"

Reasoning

As discussed on discord here and then mentioned here the current CULL_DISTANCEs are hardcoded and require a full recompile to change.

By adding static rlCullDistance globals and accessor function we can make this a runtime configurable value.

Overview:

The current RL_CULL_DISTANCE_ remain as configuration of the initial cull distances. New code may include:

  • Static variables:
    • rlCullDistanceFar
    • rlCullDistanceNear
  • Accessors:
    • rlGetClipPlaneNear()
    • rlGetClipPlaneFar()
    • rlGetDefaultClipPlaneNear()
    • rlGetDefaultClipPlaneFar()
  • Setters:
    • rlSetClipPlanes(double near, double far)
    • rlSetClipPlaneNear(double value)
    • rlSetClipPlaneFar(double value)
    • rlResetClipPlanes()

Example

Screencast.from.2024-04-11.11-11-42.webm

@raysan5
Copy link
Owner

raysan5 commented Apr 11, 2024

@KotzaBoss Thanks for draft. Please, could you share some use case where clip planes need to be dynamically changed? I feel this functionality is very limited in scope, only useful for very specific circunstances.

Still, I can consider adding a rlSetClipPlanes(), in raylib I priorityze minimalism, I can't see the need for more than one function.

@KotzaBoss
Copy link
Contributor Author

KotzaBoss commented Apr 11, 2024

Even the rlSetClipPlanes is enough imo, i wrote the extended functions for completeness. Essentially all i proposed can be reduced to:

#include <raylib.h>
#include <rlgl.h>

#define MY_CULL_DISTANCE_FAR 5000.0

rlSetClipPlanes(RL_CULL_DISTANCE_NEAR, MY_CULL_DISTANCE_FAR);

if (i_must_reset_cull_distance)
    rlSetClipPlanes(RL_CULL_DISTANCE_NEAR, RL_CULL_DISTANCE_FAR);

Though internaly there may need to be some change from using the RL_CULL_DISTANCE_ to using some Get functions or accessing the static variables directly. I am not sure about thread safety in raylib so i suppose getters would be safer.

Is this acceptable?

@raysan5
Copy link
Owner

raysan5 commented Apr 11, 2024

Is this acceptable?

Yes, that would be perfect

@KotzaBoss KotzaBoss force-pushed the clip-distance-variable branch 2 times, most recently from a976ac4 to 6f67458 Compare April 11, 2024 11:06
@KotzaBoss KotzaBoss changed the title DRAFT: Add rlClipDistanceVariable and accessor functions [rlgl] Add rlCullDistance variables/getters and rlSetClipPlanes function Apr 11, 2024
@KotzaBoss KotzaBoss force-pushed the clip-distance-variable branch from 6f67458 to 115314c Compare April 11, 2024 11:08
@KotzaBoss
Copy link
Contributor Author

As of now the camera is just defining its own CAMERA_CULL_DISTANCE to be the config's RL_CULL_DISTANCE. For the test i present i did not change anything in the camera and it works.

Are my changes therefore enough?

@electrolys
Copy link

@KotzaBoss Thanks for draft. Please, could you share some use case where clip planes need to be dynamically changed? I feel this functionality is very limited in scope, only useful for very specific circunstances.

Still, I can consider adding a rlSetClipPlanes(), in raylib I priorityze minimalism, I can't see the need for more than one function.

i would have to change the far plane in my voxel game all the time for different render distances if i didn't just switch to a infinite projection matrix

@KotzaBoss KotzaBoss force-pushed the clip-distance-variable branch from 115314c to dbb8f3b Compare April 21, 2024 15:03
The `RL_CULL_DISTANCE_` definition remains as the initial value
of the variables.

Basic usage can be:
```c
#include <raylib.h>
#include <rlgl.h>

rlSetClipPlanes(RL_CULL_DISTANCE_NEAR, MY_CULL_DISTANCE_FAR);

if (must_reset_clip_planes)
    rlSetClipPlanes(RL_CULL_DISTANCE_NEAR, RL_CULL_DISTANCE_FAR);
```
@KotzaBoss KotzaBoss force-pushed the clip-distance-variable branch from dbb8f3b to 468d7ed Compare April 22, 2024 11:17
@raysan5 raysan5 merged commit 4b0e25d into raysan5:master Apr 23, 2024
@raysan5
Copy link
Owner

raysan5 commented Apr 23, 2024

@KotzaBoss Thanks for the improvement, merging!

@paulmelis
Copy link
Contributor

@KotzaBoss Thanks for draft. Please, could you share some use case where clip planes need to be dynamically changed? I feel this functionality is very limited in scope, only useful for very specific circunstances.

Thanks for merging rlSetClipPlanes(). Another case where you want control over near/far ranges is when rendering shadow maps. There you want control over the depth range to maximize use of depth precision.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants