Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
OpenGL
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Container registry
Model registry
Analyze
Contributor analytics
Repository analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
C-Fu
OpenGL
Commits
5191a46f
Commit
5191a46f
authored
8 years ago
by
C-Fu
Browse files
Options
Downloads
Patches
Plain Diff
Added light calculation to fragment shader
parent
9b3ff7f7
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
QtMeshViewer/Resources/fshader.glsl
+19
-3
19 additions, 3 deletions
QtMeshViewer/Resources/fshader.glsl
with
19 additions
and
3 deletions
QtMeshViewer/Resources/fshader.glsl
+
19
−
3
View file @
5191a46f
...
...
@@ -4,21 +4,37 @@ precision mediump int;
precision
mediump
float
;
#endif
uniform
mat3
n_matrix
;
uniform
sampler2D
texture
;
uniform
struct
Light
{
vec3
position
;
vec3
intensities
;
}
light
;
uniform
bool
b_transparent
;
varying
vec2
v_texcoord
;
varying
vec4
v_position
;
varying
vec3
v_normal
;
void
main
()
{
vec3
normal
=
normalize
(
n_matrix
*
v_normal
);
vec3
surfaceToLight
=
light
.
position
-
v_position
;
float
brightness
=
dot
(
normal
,
surfaceToLight
)
/
(
length
(
surfaceToLight
)
*
length
(
normal
));
brightness
=
clamp
(
brightness
,
0
,
1
);
// Set fragment color from texture
vec4
final
Color
=
vec4
(
texture2D
(
texture
,
v_texcoord
));
vec4
surface
Color
=
vec4
(
texture2D
(
texture
,
v_texcoord
));
if
(
!
b_transparent
)
{
final
Color
.
a
=
1
.
0
f
;
surface
Color
.
a
=
1
.
0
f
;
}
gl_FragColor
=
final
Color
;
gl_FragColor
=
vec4
(
brightness
*
light
.
intensities
*
surfaceColor
.
rgb
,
surface
Color
.
a
)
;
}
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