Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
grafhf2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tóth Miklós Tibor
grafhf2
Commits
3c63b83f
Verified
Commit
3c63b83f
authored
Apr 15, 2021
by
Tóth Miklós Tibor
Browse files
Options
Downloads
Patches
Plain Diff
actually positional light
parent
4d091853
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Skeleton.cpp
+18
-8
18 additions, 8 deletions
Skeleton.cpp
with
18 additions
and
8 deletions
Skeleton.cpp
+
18
−
8
View file @
3c63b83f
...
@@ -196,6 +196,15 @@ struct Light {
...
@@ -196,6 +196,15 @@ struct Light {
position
=
_position
;
position
=
_position
;
Le
=
_Le
;
Le
=
_Le
;
}
}
vec3
getDirection
(
const
vec3
&
from
)
const
{
return
normalize
(
position
-
from
);
}
float
getDistance
(
const
vec3
&
point
)
const
{
vec3
d
=
point
-
position
;
return
sqrtf
(
dot
(
d
,
d
));
}
};
};
float
rnd
()
{
return
(
float
)
rand
()
/
RAND_MAX
;
}
float
rnd
()
{
return
(
float
)
rand
()
/
RAND_MAX
;
}
...
@@ -257,11 +266,11 @@ public:
...
@@ -257,11 +266,11 @@ public:
return
bestHit
;
return
bestHit
;
}
}
bool
shadowIntersect
(
Ray
ray
)
{
// for directional lights
bool
shadowIntersect
(
Ray
ray
,
Light
*
light
)
{
// for directional lights
for
(
Intersectable
*
object
:
objects
)
{
for
(
Intersectable
*
object
:
objects
)
{
Hit
hit
=
object
->
intersect
(
ray
);
Hit
hit
=
object
->
intersect
(
ray
);
if
(
hit
.
t
<
0
)
if
(
hit
.
t
>
0
)
if
(
hit
.
t
>
length
(
hit
.
position
-
ray
.
start
))
if
(
light
->
getDistance
(
ray
.
start
)
>
hit
.
t
)
return
true
;
return
true
;
}
}
return
false
;
return
false
;
...
@@ -281,12 +290,13 @@ public:
...
@@ -281,12 +290,13 @@ public:
for
(
Light
*
light
:
lights
)
{
for
(
Light
*
light
:
lights
)
{
Ray
shadowRay
(
hit
.
position
+
hit
.
normal
*
epsilon
,
light
->
position
);
Ray
shadowRay
(
hit
.
position
+
hit
.
normal
*
epsilon
,
light
->
position
);
float
cosTheta
=
dot
(
hit
.
normal
,
light
->
position
);
float
cosTheta
=
dot
(
hit
.
normal
,
light
->
position
);
if
(
cosTheta
>
0
&&
!
shadowIntersect
(
shadowRay
))
{
// shadow computation
if
(
cosTheta
>
0
&&
!
shadowIntersect
(
shadowRay
,
light
))
{
// shadow computation
outRadiance
=
outRadiance
+
light
->
Le
*
hit
.
material
->
kd
*
cosTheta
;
vec3
le
=
light
->
Le
/
powf
(
light
->
getDistance
(
hit
.
position
),
2
);
vec3
halfway
=
normalize
(
-
ray
.
dir
+
light
->
position
);
outRadiance
=
outRadiance
+
le
*
hit
.
material
->
kd
*
cosTheta
;
vec3
halfway
=
normalize
(
-
ray
.
dir
+
light
->
getDirection
(
hit
.
position
));
float
cosDelta
=
dot
(
hit
.
normal
,
halfway
);
float
cosDelta
=
dot
(
hit
.
normal
,
halfway
);
if
(
cosDelta
>
0
)
outRadiance
=
outRadiance
+
light
->
Le
*
hit
.
material
->
ks
*
if
(
cosDelta
>
0
)
powf
(
cosDelta
,
hit
.
material
->
shininess
);
outRadiance
=
outRadiance
+
le
*
hit
.
material
->
ks
*
powf
(
cosDelta
,
hit
.
material
->
shininess
);
}
}
}
}
}
}
...
...
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