Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
labs_ihm_2020
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
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository 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
jorge.josegonc
labs_ihm_2020
Commits
095707f0
Commit
095707f0
authored
4 years ago
by
jorge.josegonc
Browse files
Options
Downloads
Patches
Plain Diff
problem directionnal and choose hourglass
parent
f7b83658
Branches
master
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lab4/src/lab4.js
+19
-3
19 additions, 3 deletions
lab4/src/lab4.js
with
19 additions
and
3 deletions
lab4/src/lab4.js
+
19
−
3
View file @
095707f0
...
...
@@ -56,16 +56,20 @@ var FSHADER_SOURCE =
'
varying vec3 v_normal;
\n
'
+
'
varying vec4 v_VertexPosition;
\n
'
+
'
uniform vec3 u_LightPosition;
\n
'
+
'
uniform vec3 u_AmbientLight;
\n
'
+
'
uniform vec3 u_LightColor;
\n
'
+
'
uniform bool typeLight;
\n
'
+
'
uniform vec3 u_lightDirection;
\n
'
+
'
void main() {
\n
'
+
'
vec3 ambient = u_AmbientLight * v_Color.rgb;
\n
'
+
'
vec3 lightDirection = normalize(u_LightPosition - vec3(v_VertexPosition));
\n
'
+
'
float nDotL = max(dot(v_normal, lightDirection), 0.0);
\n
'
+
'
float nDotL =
(typeLight) ? max(dot(v_normal, u_lightDirection), 0.0) :
max(dot(v_normal, lightDirection), 0.0);
\n
'
+
'
vec3 diffuse = u_LightColor * v_Color.rgb * nDotL;
\n
'
+
'
vec3 shadowCoord = (v_PositionFromLight.xyz/v_PositionFromLight.w)/2.0 + 0.5;
\n
'
+
'
vec4 rgbaDepth = texture2D(u_ShadowMap, shadowCoord.xy);
\n
'
+
'
float depth = rgbaDepth.r;
\n
'
+
// Retrieve the z-value from R
'
float visibility = (shadowCoord.z > depth + 0.005) ? 0.0 : 1.0;
\n
'
+
'
gl_FragColor = vec4(diffuse * visibility, v_Color.a);
\n
'
+
'
gl_FragColor = vec4(
ambient +
diffuse * visibility, v_Color.a);
\n
'
+
'
}
\n
'
;
const
PERSPECTIVE_WIDTH_FROM_LIGHT
=
2048
...
...
@@ -91,6 +95,8 @@ var tmp_normalMatrix = new Matrix4();
var
rotationSecFrustrumMatrix
=
new
Matrix4
();
var
translateFrustrumMatrix
=
new
Matrix4
();
var
isDirectionnal
=
false
;
// Event of key down, move camera or light positions
document
.
addEventListener
(
"
keydown
"
,
(
event
)
=>
{
switch
(
event
.
key
)
{
...
...
@@ -130,6 +136,8 @@ document.addEventListener("keydown", (event) => {
case
'
h
'
:
light_z
-=
STEP
;
break
;
case
'
x
'
:
isDirectionnal
=
!
isDirectionnal
;
default
:
break
;
}
...
...
@@ -172,9 +180,12 @@ function main() {
normalProgram
.
u_ModelMatrix
=
gl
.
getUniformLocation
(
normalProgram
,
'
u_ModelMatrix
'
);
normalProgram
.
u_LightPosition
=
gl
.
getUniformLocation
(
normalProgram
,
'
u_LightPosition
'
);
normalProgram
.
u_LightColor
=
gl
.
getUniformLocation
(
normalProgram
,
'
u_LightColor
'
);
normalProgram
.
u_AmbientLight
=
gl
.
getUniformLocation
(
normalProgram
,
'
u_AmbientLight
'
);
normalProgram
.
typeLight
=
gl
.
getUniformLocation
(
normalProgram
,
'
typeLight
'
);
if
(
normalProgram
.
a_Position
<
0
||
normalProgram
.
a_Color
<
0
||
normalProgram
.
a_Normal
<
0
||
!
normalProgram
.
u_MvpMatrix
||
!
normalProgram
.
u_MvpMatrixFromLight
||
!
normalProgram
.
u_ShadowMap
||
!
normalProgram
.
u_Clicked
||
!
normalProgram
.
u_NormalMatrix
||
!
normalProgram
.
u_ModelMatrix
||
!
normalProgram
.
u_LightPosition
||
!
normalProgram
.
u_LightColor
)
{
!
normalProgram
.
u_ModelMatrix
||
!
normalProgram
.
u_LightPosition
||
!
normalProgram
.
u_LightColor
||
!
normalProgram
.
u_AmbientLight
||
!
normalProgram
.
typeLight
)
{
console
.
log
(
'
Failed to get the storage location of attribute or uniform variable from normalProgram
'
);
return
;
}
...
...
@@ -285,7 +296,12 @@ function main() {
gl
.
useProgram
(
normalProgram
);
gl
.
uniform3f
(
normalProgram
.
u_LightColor
,
1.0
,
1.0
,
1.0
);
// The light is white
gl
.
uniform3f
(
normalProgram
.
u_AmbientLight
,
0.1
,
0.1
,
0.1
);
gl
.
uniform3f
(
normalProgram
.
u_LightPosition
,
light_x
,
light_y
,
light_z
);
gl
.
uniform1i
(
normalProgram
.
typeLight
,
isDirectionnal
);
var
lightD
=
new
Vector3
([
light_x
,
light_y
,
light_z
]);
lightD
.
normalize
();
gl
.
uniform3fv
(
normalProgram
.
u_lightDirection
,
lightD
.
elements
);
gl
.
uniform1i
(
normalProgram
.
u_ShadowMap
,
0
);
// Pass 0 because gl.TEXTURE0 is enabled
// Draw the two frustrum and plane for the normal program
...
...
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