Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
C-Fu
OpenGL
Commits
5191a46f
Commit
5191a46f
authored
Jan 17, 2017
by
C-Fu
Browse files
Added light calculation to fragment shader
parent
9b3ff7f7
Changes
1
Hide whitespace changes
Inline
Side-by-side
QtMeshViewer/Resources/fshader.glsl
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
)
;
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment