Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
VkCV Framework
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Vulkan2021
VkCV Framework
Commits
e509d231
Commit
e509d231
authored
3 years ago
by
Alexander Gauggel
Browse files
Options
Downloads
Patches
Plain Diff
[
#94
] Corrected ray direction computation
parent
e040fad8
No related branches found
No related tags found
1 merge request
!77
Resolve "SAF-R Module"
Pipeline
#27133
passed
3 years ago
Stage: build
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
projects/saf_r/shaders/raytracing.comp
+21
-5
21 additions, 5 deletions
projects/saf_r/shaders/raytracing.comp
projects/saf_r/src/main.cpp
+3
-3
3 additions, 3 deletions
projects/saf_r/src/main.cpp
with
24 additions
and
8 deletions
projects/saf_r/shaders/raytracing.comp
+
21
−
5
View file @
e509d231
...
...
@@ -160,11 +160,27 @@ vec3 castRay(const vec3 initialOrigin, const vec3 initialDirection, int max_dept
vec3 computeDirection(ivec2 coord){
ivec2 outImageRes = imageSize(outImage);
float fov = pi / 2.f;
float x = (2 * (float(coord.x) + 0.5f) / float(outImageRes.x) - 1) * tan(fov / 2.f) * outImageRes.x / float(outImageRes.y);
float y = -(2 * (float(coord.y) + 0.5f) / float(outImageRes.y) - 1) * tan(fov / 2.f);
vec3 directionViewSpace = normalize(vec3(x, y, 1));
ivec2 outImageRes = imageSize(outImage);
float fovDegree = 45;
float fov = fovDegree * pi / 180;
vec2 uv = coord / vec2(outImageRes);
vec2 ndc = 2 * uv - 1;
float tanFovHalf = tan(fov / 2.f);
float aspectRatio = outImageRes.x / float(outImageRes.y);
float x = ndc.x * tanFovHalf * aspectRatio;
float y = -ndc.y * tanFovHalf;
// z component must be chosen so vector length equals 1
// setting z=1 and normalizing shortens x and y, changing the fov
// the final length must satisfy:
// 1 = |v| <=>
// 1 = sqrt(x^2 + y^2 + z^2) <=>
// 1 = x^2 + y^2 + z^2 <=>
// 1 - x^2 - y^2 = z^2 <=>
// sqrt(1 - x^2 - y^2) = z
vec3 directionViewSpace = vec3(x, y, sqrt(1 - x*x - y*y));
vec3 directionWorldSpace = mat3(viewToWorld) * directionViewSpace;
return directionWorldSpace;
}
...
...
This diff is collapsed.
Click to expand it.
projects/saf_r/src/main.cpp
+
3
−
3
View file @
e509d231
...
...
@@ -99,9 +99,9 @@ int main(int argc, const char** argv) {
//lights for the scene
std
::
vector
<
safrScene
::
Light
>
lights
;
lights
.
push_back
(
safrScene
::
Light
(
glm
::
vec3
(
-
20
,
20
,
20
),
1.5
));
lights
.
push_back
(
safrScene
::
Light
(
glm
::
vec3
(
30
,
50
,
-
25
),
1.8
));
lights
.
push_back
(
safrScene
::
Light
(
glm
::
vec3
(
30
,
20
,
30
),
1.7
));
lights
.
push_back
(
safrScene
::
Light
(
glm
::
vec3
(
-
20
,
20
,
20
),
1.5
));
lights
.
push_back
(
safrScene
::
Light
(
glm
::
vec3
(
30
,
50
,
-
25
),
1.8
));
lights
.
push_back
(
safrScene
::
Light
(
glm
::
vec3
(
30
,
20
,
30
),
1.7
));
//create the raytracer image for rendering
safrScene
scene
;
vkcv
::
asset
::
Texture
texData
=
scene
.
render
(
spheres
,
lights
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment