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
fbb8f73c
Commit
fbb8f73c
authored
3 years ago
by
Alex Laptop
Browse files
Options
Downloads
Patches
Plain Diff
Plane now working
parent
c5ad8b0d
No related branches found
No related tags found
1 merge request
!101
Path tracing
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
projects/path_tracer/shaders/path_tracer.comp
+42
-4
42 additions, 4 deletions
projects/path_tracer/shaders/path_tracer.comp
projects/path_tracer/src/main.cpp
+10
-7
10 additions, 7 deletions
projects/path_tracer/src/main.cpp
with
52 additions
and
11 deletions
projects/path_tracer/shaders/path_tracer.comp
+
42
−
4
View file @
fbb8f73c
...
@@ -27,7 +27,7 @@ struct Sphere{
...
@@ -27,7 +27,7 @@ struct Sphere{
struct Plane{
struct Plane{
vec3 center;
vec3 center;
float padding0
;
int materialIndex
;
vec3 N;
vec3 N;
float padding1;
float padding1;
vec2 extent;
vec2 extent;
...
@@ -59,7 +59,7 @@ layout( push_constant ) uniform constants{
...
@@ -59,7 +59,7 @@ layout( push_constant ) uniform constants{
int planeCount;
int planeCount;
};
};
bool ray
_i
ntersect(const vec3 origin, const vec3 dir, out float t0, const int id){
bool ray
SphereI
ntersect(const vec3 origin, const vec3 dir, out float t0, const int id){
vec3 L = inSpheres[id].center - origin;
vec3 L = inSpheres[id].center - origin;
float tca = dot(L, dir);
float tca = dot(L, dir);
float d2 = dot(L, L) - tca * tca;
float d2 = dot(L, L) - tca * tca;
...
@@ -78,6 +78,30 @@ bool ray_intersect(const vec3 origin, const vec3 dir, out float t0, const int id
...
@@ -78,6 +78,30 @@ bool ray_intersect(const vec3 origin, const vec3 dir, out float t0, const int id
return true;
return true;
}
}
// see: https://www.scratchapixel.com/lessons/3d-basic-rendering/minimal-ray-tracer-rendering-simple-shapes/ray-plane-and-ray-disk-intersection
bool rayPlaneIntersect(const vec3 origin, vec3 direction, out float intersectionDistance, const int id){
Plane plane = inPlanes[id];
vec3 toPlane = plane.center - origin;
float denom = dot(direction, plane.N);
if(abs(denom) < 0.001)
return false;
intersectionDistance = dot(toPlane, plane.N) / denom;
if(intersectionDistance < 0)
return false;
vec3 intersection = origin + direction * intersectionDistance;
vec3 right = plane.N.x < 0.99 ? vec3(1, 0, 0) : vec3(0, 0, 1);
vec3 up = normalize(cross(plane.N, right));
right = cross(plane.N, up);
vec3 centerToIntersection = intersection - plane.center;
float projectedRight = dot(centerToIntersection, right);
float projectedUp = dot(centerToIntersection, up);
return abs(projectedRight) < plane.extent.x && abs(projectedUp) < plane.extent.y;
}
struct Intersection{
struct Intersection{
bool hit;
bool hit;
vec3 pos;
vec3 pos;
...
@@ -93,7 +117,7 @@ Intersection sceneIntersect(const vec3 rayOrigin, const vec3 rayDirection) {
...
@@ -93,7 +117,7 @@ Intersection sceneIntersect(const vec3 rayOrigin, const vec3 rayDirection) {
for (int i = 0; i < sphereCount; i++) {
for (int i = 0; i < sphereCount; i++) {
float d;
float d;
if (ray
_i
ntersect(rayOrigin, rayDirection, d, i)) {
if (ray
SphereI
ntersect(rayOrigin, rayDirection, d, i)) {
intersection.hit = true;
intersection.hit = true;
...
@@ -105,6 +129,20 @@ Intersection sceneIntersect(const vec3 rayOrigin, const vec3 rayDirection) {
...
@@ -105,6 +129,20 @@ Intersection sceneIntersect(const vec3 rayOrigin, const vec3 rayDirection) {
}
}
}
}
}
}
for (int i = 0; i < planeCount; i++){
float d;
if (rayPlaneIntersect(rayOrigin, rayDirection, d, i)) {
intersection.hit = true;
if(d < min_d){
min_d = d;
intersection.pos = rayOrigin + rayDirection * d;
intersection.N = inPlanes[i].N;
intersection.material = inMaterials[inPlanes[i].materialIndex];
}
}
}
return intersection;
return intersection;
}
}
...
@@ -114,7 +152,7 @@ vec3 biasHitPosition(vec3 hitPos, vec3 rayDirection, vec3 N){
...
@@ -114,7 +152,7 @@ vec3 biasHitPosition(vec3 hitPos, vec3 rayDirection, vec3 N){
}
}
vec3 computeHitLighting(Intersection intersection, vec3 V, out float outReflectionThroughput){
vec3 computeHitLighting(Intersection intersection, vec3 V, out float outReflectionThroughput){
float lightIntensityDiffuse = 0;
float lightIntensityDiffuse = 0;
float lightIntensitySpecular = 0;
float lightIntensitySpecular = 0;
...
...
This diff is collapsed.
Click to expand it.
projects/path_tracer/src/main.cpp
+
10
−
7
View file @
fbb8f73c
...
@@ -33,10 +33,11 @@ namespace temp {
...
@@ -33,10 +33,11 @@ namespace temp {
};
};
struct
Plane
{
struct
Plane
{
Plane
(
const
glm
::
vec3
&
c
,
const
glm
::
vec3
&
n
,
const
glm
::
vec2
e
)
:
center
(
c
),
normal
(
n
),
extent
(
e
)
{}
Plane
(
const
glm
::
vec3
&
c
,
const
glm
::
vec3
&
n
,
const
glm
::
vec2
e
,
int
m
)
:
center
(
c
),
normal
(
n
),
extent
(
e
),
materialIndex
(
m
)
{}
glm
::
vec3
center
;
glm
::
vec3
center
;
float
padding0
;
uint32_t
materialIndex
;
glm
::
vec3
normal
;
glm
::
vec3
normal
;
float
padding1
;
float
padding1
;
glm
::
vec2
extent
;
glm
::
vec2
extent
;
...
@@ -79,9 +80,9 @@ int main(int argc, const char** argv) {
...
@@ -79,9 +80,9 @@ int main(int argc, const char** argv) {
materials
.
emplace_back
(
temp
::
Material
(
glm
::
vec3
(
0.9
,
0.1
,
0.0
),
glm
::
vec3
(
0.3
,
0.1
,
0.1
),
10.
f
));
materials
.
emplace_back
(
temp
::
Material
(
glm
::
vec3
(
0.9
,
0.1
,
0.0
),
glm
::
vec3
(
0.3
,
0.1
,
0.1
),
10.
f
));
materials
.
emplace_back
(
temp
::
Material
(
glm
::
vec3
(
0.0
,
10.0
,
0.8
),
glm
::
vec3
(
1.0
,
1.0
,
1.0
),
1425.
f
));
materials
.
emplace_back
(
temp
::
Material
(
glm
::
vec3
(
0.0
,
10.0
,
0.8
),
glm
::
vec3
(
1.0
,
1.0
,
1.0
),
1425.
f
));
const
int
ivoryIndex
=
0
;
const
u
int
32_t
ivoryIndex
=
0
;
const
int
rubberIndex
=
1
;
const
u
int
32_t
rubberIndex
=
1
;
const
int
mirrorIndex
=
2
;
const
u
int
32_t
mirrorIndex
=
2
;
std
::
vector
<
temp
::
Sphere
>
spheres
;
std
::
vector
<
temp
::
Sphere
>
spheres
;
spheres
.
emplace_back
(
temp
::
Sphere
(
glm
::
vec3
(
-
3.0
,
0.0
,
16
),
2
,
ivoryIndex
));
spheres
.
emplace_back
(
temp
::
Sphere
(
glm
::
vec3
(
-
3.0
,
0.0
,
16
),
2
,
ivoryIndex
));
...
@@ -90,7 +91,7 @@ int main(int argc, const char** argv) {
...
@@ -90,7 +91,7 @@ int main(int argc, const char** argv) {
spheres
.
emplace_back
(
temp
::
Sphere
(
glm
::
vec3
(
7.0
,
5.0
,
18
),
4
,
mirrorIndex
));
spheres
.
emplace_back
(
temp
::
Sphere
(
glm
::
vec3
(
7.0
,
5.0
,
18
),
4
,
mirrorIndex
));
std
::
vector
<
temp
::
Plane
>
planes
;
std
::
vector
<
temp
::
Plane
>
planes
;
planes
.
emplace_back
(
temp
::
Plane
(
glm
::
vec3
(
-
3.0
,
0.0
,
16
),
glm
::
vec3
(
0
,
1
,
0
),
glm
::
vec2
(
1
)
));
planes
.
emplace_back
(
temp
::
Plane
(
glm
::
vec3
(
0
,
-
1
,
0
),
glm
::
vec3
(
0
,
1
,
0
),
glm
::
vec2
(
3
),
ivoryIndex
));
std
::
vector
<
temp
::
Light
>
lights
;
std
::
vector
<
temp
::
Light
>
lights
;
lights
.
emplace_back
(
temp
::
Light
(
glm
::
vec3
(
-
20
,
20
,
20
),
1.5
));
lights
.
emplace_back
(
temp
::
Light
(
glm
::
vec3
(
-
20
,
20
,
20
),
1.5
));
...
@@ -172,12 +173,14 @@ int main(int argc, const char** argv) {
...
@@ -172,12 +173,14 @@ int main(int argc, const char** argv) {
glm
::
mat4
viewToWorld
;
glm
::
mat4
viewToWorld
;
int32_t
lightCount
;
int32_t
lightCount
;
int32_t
sphereCount
;
int32_t
sphereCount
;
int32_t
planeCount
;
};
};
RaytracingPushConstantData
raytracingPushData
;
RaytracingPushConstantData
raytracingPushData
;
raytracingPushData
.
viewToWorld
=
glm
::
inverse
(
cameraManager
.
getActiveCamera
().
getView
());
raytracingPushData
.
lightCount
=
lights
.
size
();
raytracingPushData
.
lightCount
=
lights
.
size
();
raytracingPushData
.
sphereCount
=
spheres
.
size
();
raytracingPushData
.
sphereCount
=
spheres
.
size
();
raytracingPushData
.
viewToWorld
=
glm
::
inverse
(
cameraManager
.
getActiveCamera
().
getView
()
);
raytracingPushData
.
planeCount
=
planes
.
size
(
);
vkcv
::
PushConstants
pushConstantsCompute
(
sizeof
(
RaytracingPushConstantData
));
vkcv
::
PushConstants
pushConstantsCompute
(
sizeof
(
RaytracingPushConstantData
));
pushConstantsCompute
.
appendDrawcall
(
raytracingPushData
);
pushConstantsCompute
.
appendDrawcall
(
raytracingPushData
);
...
...
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