Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
OpenGL
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
C-Fu
OpenGL
Commits
4c177f2d
Commit
4c177f2d
authored
Jan 18, 2017
by
Anakin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adjust light functionality,
bugs: - background cannot be changed during runtime
parent
a521dfc2
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
71 additions
and
31 deletions
+71
-31
QtMeshViewer/Header/OglViewerWidget.h
QtMeshViewer/Header/OglViewerWidget.h
+4
-2
QtMeshViewer/Resources/Resources.qrc
QtMeshViewer/Resources/Resources.qrc
+1
-0
QtMeshViewer/Resources/about.txt
QtMeshViewer/Resources/about.txt
+1
-0
QtMeshViewer/Resources/fshader.glsl
QtMeshViewer/Resources/fshader.glsl
+22
-21
QtMeshViewer/Resources/light.png
QtMeshViewer/Resources/light.png
+0
-0
QtMeshViewer/Resources/vshader.glsl
QtMeshViewer/Resources/vshader.glsl
+6
-6
QtMeshViewer/Resources/wireframe.png
QtMeshViewer/Resources/wireframe.png
+0
-0
QtMeshViewer/Source/MainWindow.cpp
QtMeshViewer/Source/MainWindow.cpp
+6
-0
QtMeshViewer/Source/OglViewerWidget.cpp
QtMeshViewer/Source/OglViewerWidget.cpp
+31
-2
No files found.
QtMeshViewer/Header/OglViewerWidget.h
View file @
4c177f2d
...
...
@@ -38,7 +38,7 @@ private:
}
m_rotDirections
;
struct
{
QVector3D
position
=
{
1
0
,
10
,
10
};
QVector3D
position
=
{
1
,
1
,
1
};
QVector3D
intensities
=
{
1
,
0.25
,
0.25
};
}
m_light
;
...
...
@@ -50,7 +50,7 @@ private:
QQuaternion
m_rotation
;
bool
m_wireframe
=
false
;
bool
m_lightOn
=
tru
e
;
bool
m_lightOn
=
fals
e
;
protected:
void
mousePressEvent
(
QMouseEvent
*
e
)
Q_DECL_OVERRIDE
;
...
...
@@ -68,6 +68,7 @@ protected:
private:
void
initShaders
();
void
setConnections
();
void
updateLightPosition
();
private
slots
:
void
resetView
();
...
...
@@ -75,5 +76,6 @@ private slots:
public
slots
:
void
changeDirection
(
int
direction
);
void
toggleWireframe
();
void
toggleLight
();
};
QtMeshViewer/Resources/Resources.qrc
View file @
4c177f2d
...
...
@@ -19,5 +19,6 @@
<file>Z.png</file>
<file>screenshot.png</file>
<file>wireframe.png</file>
<file>light.png</file>
</qresource>
</RCC>
QtMeshViewer/Resources/about.txt
View file @
4c177f2d
...
...
@@ -8,6 +8,7 @@ left mouse - rotate
right mouse - move
scroll - zoom
space - reset view
L - set light to current position
esc - close
using the X, Y, Z Button you can activate/deactivate the rotating directions
...
...
QtMeshViewer/Resources/fshader.glsl
View file @
4c177f2d
...
...
@@ -15,40 +15,41 @@ uniform struct Light {
uniform
bool
b_transparent
;
uniform
bool
b_light
;
varying
vec2
v_
texcoord
;
varying
vec3
v_
p
osition
;
varying
vec3
v_
n
ormal
;
varying
vec2
v_
surfaceUV
;
varying
vec3
v_
surfaceP
osition
;
varying
vec3
v_
surfaceN
ormal
;
void
main
()
{
// variables
float
brightness
;
vec3
diffuse
;
if
(
b_light
==
true
)
// get fragment color from texture
vec4
surfaceColor
=
vec4
(
texture2D
(
texture
,
v_surfaceUV
));
// if not transparent, ignore alpha value and set it to 1
if
(
!
b_transparent
)
surfaceColor
.
a
=
1
.
0
f
;
if
(
b_light
)
{
// calculate normals in worldspace
vec3
normal
=
normalize
(
n_matrix
*
v_n
ormal
);
vec3
normal
World
=
normalize
(
n_matrix
*
v_surfaceN
ormal
);
//get the surface - light vector (cause this is a
candel
)
vec3
surfaceToLight
=
light
.
position
-
v_position
;
//get the surface - light vector (cause this is a
point light
)
vec3
surfaceToLight
=
normalize
(
light
.
position
-
v_surfacePosition
)
;
// calculate the brightness depending on the angle
brightness
=
dot
(
normal
,
surfaceToLight
)
/
(
length
(
surfaceToLight
)
*
length
(
normal
));
brightness
=
clamp
(
brightness
,
0
,
1
);
float
diffuseCoefficient
=
max
(
0
.
0
,
dot
(
normalWorld
,
surfaceToLight
));
// result diffuse color
diffuse
=
diffuseCoefficient
*
surfaceColor
.
rgb
*
light
.
intensities
;
}
else
{
brightness
=
1
;
light
.
intensities
=
vec3
(
1
,
1
,
1
);
diffuse
=
surfaceColor
.
rgb
;
}
// get fragment color from texture
vec4
surfaceColor
=
vec4
(
texture2D
(
texture
,
v_texcoord
));
// if not transparent, ignore alpha value and set it to 1
if
(
!
b_transparent
)
surfaceColor
.
a
=
1
.
0
f
;
// pass the data to ogl
gl_FragColor
=
vec4
(
brightness
*
light
.
intensities
*
surfaceColor
.
rgb
,
surfaceColor
.
a
);
// put all together
gl_FragColor
=
vec4
(
diffuse
,
surfaceColor
.
a
);
}
QtMeshViewer/Resources/light.png
0 → 100644
View file @
4c177f2d
3.47 KB
QtMeshViewer/Resources/vshader.glsl
View file @
4c177f2d
...
...
@@ -12,9 +12,9 @@ attribute vec4 a_position;
attribute
vec2
a_texcoord
;
attribute
vec3
a_normal
;
varying
vec2
v_
texcoord
;
varying
vec3
v_
p
osition
;
varying
vec3
v_
n
ormal
;
varying
vec2
v_
surfaceUV
;
varying
vec3
v_
surfaceP
osition
;
varying
vec3
v_
surfaceN
ormal
;
void
main
()
{
...
...
@@ -23,7 +23,7 @@ void main()
// Pass data to fragment shader
// Value will be automatically interpolated to fragments inside polygon faces
v_
texcoord
=
a_texcoord
;
v_
p
osition
=
vec3
(
norm_matrix
*
m_matrix
*
a_position
);
v_
n
ormal
=
a_normal
;
v_
surfaceUV
=
a_texcoord
;
v_
surfaceP
osition
=
vec3
(
norm_matrix
*
m_matrix
*
a_position
);
v_
surfaceN
ormal
=
a_normal
;
}
QtMeshViewer/Resources/wireframe.png
0 → 100644
View file @
4c177f2d
3.47 KB
QtMeshViewer/Source/MainWindow.cpp
View file @
4c177f2d
...
...
@@ -101,6 +101,12 @@ void MainWindow::setupWidgets()
connect
(
wireframe
,
&
QAction
::
triggered
,
viewer
,
&
OglViewerWidget
::
toggleWireframe
);
ui
->
mainToolBar
->
addAction
(
wireframe
);
QAction
*
light
=
new
QAction
(
QIcon
(
":/images/toolbar/light.png"
),
"Light"
,
this
);
light
->
setCheckable
(
true
);
light
->
setChecked
(
false
);
connect
(
light
,
&
QAction
::
triggered
,
viewer
,
&
OglViewerWidget
::
toggleLight
);
ui
->
mainToolBar
->
addAction
(
light
);
ui
->
mainToolBar
->
addSeparator
();
QAction
*
fileInfo
=
new
QAction
(
QIcon
(
":/images/toolbar/info.png"
),
"File info"
,
this
);
...
...
QtMeshViewer/Source/OglViewerWidget.cpp
View file @
4c177f2d
...
...
@@ -173,14 +173,18 @@ void OglViewerWidget::keyPressEvent(QKeyEvent *e)
{
parentWidget
()
->
close
();
}
else
if
(
e
->
key
()
==
Qt
::
Key_L
)
{
updateLightPosition
();
update
();
}
}
void
OglViewerWidget
::
initializeGL
()
{
initializeOpenGLFunctions
();
//glClearColor(0.5000f, 0.8000f, 1.0000f, 0.0000f);
glClearColor
(
0.02
f
,
0.01
f
,
0.01
f
,
0.0000
f
);
glClearColor
(
0.5000
f
,
0.8000
f
,
1.0000
f
,
0.0000
f
);
initShaders
();
...
...
@@ -269,6 +273,13 @@ void OglViewerWidget::setConnections()
}
void
OglViewerWidget
::
updateLightPosition
()
{
QMatrix4x4
rotateBack
;
rotateBack
.
rotate
(
m_rotation
.
inverted
());
m_light
.
position
=
rotateBack
*
(
-
m_translation
);
}
/////////////////////////////////////////////////////////////////////////
// private slots
...
...
@@ -305,3 +316,21 @@ void OglViewerWidget::toggleWireframe()
m_wireframe
=
1
-
m_wireframe
;
update
();
}
void
OglViewerWidget
::
toggleLight
()
{
m_lightOn
=
1
-
m_lightOn
;
if
(
m_lightOn
)
{
glClearColor
(
m_light
.
intensities
.
x
()
/
100
,
m_light
.
intensities
.
y
()
/
100
,
m_light
.
intensities
.
z
()
/
100
,
0.0000
f
);
updateLightPosition
();
}
else
{
glClearColor
(
0.5000
f
,
0.8000
f
,
1.0000
f
,
0.0000
f
);
}
update
();
}
Write
Preview
Markdown
is supported
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