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

Improved Raymarching view sub-system. #198

Merged

Conversation

shadielhajj
Copy link
Collaborator

@shadielhajj shadielhajj commented Aug 13, 2024

The previous raymarching view subsystem forces a look-at camera (a camera which calculates it's orientation to look at a specified target point). This is useful in some cases, but very awkward in others (such as fly-overs, landscapes, etc..).

The new system allows us to directly specify a view matrix. This can be used to:

  1. Use a view matrix calculated by the host engine (eg. a game engine).
  2. Calculate our own view matrix from a variety of functions.

Currently implemented view matrix functions:

  1. lookAtViewMatrix (the previous behaviour)
  2. viewMatrix (a typical camera specified using camera position and rotation)

This leaves the system open to extension with more camera matrix functions such as orbital cameras, etc...

For convenience and backward compatibility, we include a helper functions which replicates the previous behaviour.

vec4 raymarch(vec3 cameraPosition, vec3 cameraLookAt, vec2 st)
{
    float depth = 0.0;
    vec3 worldPos = vec3(0.0, 0.0, 0.0);
    vec3 worldNormal = vec3(0.0, 0.0, 0.0);
    mat4 viewMatrix = lookAtViewMatrix(cameraPosition, cameraLookAt);
    return raymarch(viewMatrix, st, depth, worldPos, worldNormal);
}

To use a different camera function, such as a basic rotatable camera

mat4 viewMatrix = viewMatrix(CameraPosition, CameraRotation*DEG2RAD);
vec4 renderOut = raymarch(viewMatrix, st, eyeDepth, worldPosition, worldNormals);

@patriciogonzalezvivo
Copy link
Owner

patriciogonzalezvivo commented Aug 13, 2024

This is great! Beautiful work! Love the direction, less ray marching-specifics, more useful and reusable functions we can use in other cases.

NIT: do you mind dropping the ...Matrix or lookAtViewMatrix.* and viewMatrix.*. Most of the functions in space/ return matrices. For now we are not adding that into the names. But is a good point to have in mind. Specially if we stumble with some name collision.

@shadielhajj
Copy link
Collaborator Author

shadielhajj commented Aug 13, 2024

This is great! Beautiful work! Love the direction, less ray marching-specifics, more useful and reusable functions we can use in other cases.

Exactly!! :-D

NIT: do you mind dropping the ...Matrix or lookAtViewMatrix.* and viewMatrix.*. Most of the functions in space/ return matrices. For now we are not adding that into the names. But is a good point to have in mind. Specially if we stumble with some name collision.

Sure. Just renamed them to lookAtView and eulerView (also considered dofView, for Degrees of Freedom, but felt it's a bit obscure).

@patriciogonzalezvivo

@patriciogonzalezvivo patriciogonzalezvivo merged commit 7d83479 into patriciogonzalezvivo:main Aug 13, 2024
@shadielhajj shadielhajj deleted the feature/camera branch August 14, 2024 08:42
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.

2 participants