Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added missing shaders and temporary test application
  • Loading branch information
wonder-sk committed Sep 15, 2017
1 parent 675a1ae commit 8d4d5ab
Show file tree
Hide file tree
Showing 16 changed files with 694 additions and 11 deletions.
15 changes: 14 additions & 1 deletion src/3d/CMakeLists.txt
Expand Up @@ -48,6 +48,8 @@ SET(QGIS_3D_MOC_HDRS

QT5_WRAP_CPP(QGIS_3D_MOC_SRCS ${QGIS_3D_MOC_HDRS})

QT5_ADD_RESOURCES(QGIS_3D_RCC_SRCS shaders.qrc)

# install headers

SET(QGIS_3D_HDRS
Expand Down Expand Up @@ -100,7 +102,7 @@ INCLUDE_DIRECTORIES(SYSTEM
#############################################################
# qgis_3d library

ADD_LIBRARY(qgis_3d SHARED ${QGIS_3D_SRCS} ${QGIS_3D_MOC_SRCS} ${QGIS_3D_HDRS})
ADD_LIBRARY(qgis_3d SHARED ${QGIS_3D_SRCS} ${QGIS_3D_MOC_SRCS} ${QGIS_3D_HDRS} ${QGIS_3D_RCC_SRCS})

qt5_use_modules(qgis_3d 3DCore 3DRender 3DInput 3DLogic 3DExtras)

Expand Down Expand Up @@ -174,3 +176,14 @@ IF (APPLE AND QGIS_MACAPP_INSTALL_DEV)
INSTALL(CODE "EXECUTE_PROCESS(COMMAND install_name_tool -id \"${QGIS_MACAPP_DEV_PREFIX}/qgis_3d.framework/Versions/${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}/qgis_3d\" \"$ENV{DESTDIR}${QGIS_MACAPP_DEV_PREFIX}/qgis_3d.framework/qgis_3d\")")
INSTALL(CODE "EXECUTE_PROCESS(COMMAND install_name_tool -change \"${CMAKE_INSTALL_NAME_DIR}/qgis_core.framework/Versions/${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}/qgis_core\" \"${QGIS_MACAPP_DEV_PREFIX}/qgis_core.framework/Versions/${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}/qgis_core\" \"$ENV{DESTDIR}${QGIS_MACAPP_DEV_PREFIX}/qgis_3d.framework/qgis_3d\")")
ENDIF (APPLE AND QGIS_MACAPP_INSTALL_DEV)


#############################################################
# qgis 3d test executable (temporary)

add_executable(qgis3d
testapp/main.cpp
testapp/sidepanel.cpp
testapp/window3d.cpp
)
target_link_libraries(qgis3d qgis_3d)
4 changes: 3 additions & 1 deletion src/3d/aabb.h
@@ -1,12 +1,14 @@
#ifndef AABB_H
#define AABB_H

#include "qgis_3d.h"

#include <math.h>
#include <QList>
#include <QVector3D>

//! axis-aligned bounding box - in world coords
class AABB
class _3D_EXPORT AABB
{
public:
AABB()
Expand Down
4 changes: 3 additions & 1 deletion src/3d/cameracontroller.h
@@ -1,12 +1,14 @@
#ifndef CAMERACONTROLLER_H
#define CAMERACONTROLLER_H

#include "qgis_3d.h"

#include <Qt3DCore/QEntity>
#include <Qt3DInput>
#include <Qt3DRender>


class CameraController : public Qt3DCore::QEntity
class _3D_EXPORT CameraController : public Qt3DCore::QEntity
{
Q_OBJECT
Q_PROPERTY( Qt3DRender::QCamera *camera READ camera WRITE setCamera NOTIFY cameraChanged )
Expand Down
4 changes: 3 additions & 1 deletion src/3d/demterraingenerator.h
@@ -1,6 +1,8 @@
#ifndef DEMTERRAINGENERATOR_H
#define DEMTERRAINGENERATOR_H

#include "qgis_3d.h"

#include "terraingenerator.h"
#include "terrainchunkloader.h"

Expand All @@ -15,7 +17,7 @@ class QgsRasterLayer;
/**
* Implementation of terrain generator that uses a raster layer with DEM to build terrain.
*/
class DemTerrainGenerator : public TerrainGenerator
class _3D_EXPORT DemTerrainGenerator : public TerrainGenerator
{
public:
DemTerrainGenerator();
Expand Down
4 changes: 3 additions & 1 deletion src/3d/flatterraingenerator.h
@@ -1,6 +1,8 @@
#ifndef FLATTERRAINGENERATOR_H
#define FLATTERRAINGENERATOR_H

#include "qgis_3d.h"

#include "terraingenerator.h"

#include "qgsrectangle.h"
Expand All @@ -12,7 +14,7 @@ namespace Qt3DExtras
class QPlaneGeometry;
}

class FlatTerrainGenerator : public TerrainGenerator
class _3D_EXPORT FlatTerrainGenerator : public TerrainGenerator
{
public:
FlatTerrainGenerator();
Expand Down
12 changes: 7 additions & 5 deletions src/3d/map3d.h
@@ -1,6 +1,8 @@
#ifndef MAP3D_H
#define MAP3D_H

#include "qgis_3d.h"

#include <memory>
#include <QColor>
#include <QMatrix4x4>
Expand Down Expand Up @@ -39,7 +41,7 @@ AltitudeBinding altBindingFromString( const QString &str );


//! Basic shading material used for rendering
class PhongMaterialSettings
class _3D_EXPORT PhongMaterialSettings
{
public:
PhongMaterialSettings()
Expand Down Expand Up @@ -71,7 +73,7 @@ class PhongMaterialSettings
};


class PolygonRenderer
class _3D_EXPORT PolygonRenderer
{
public:
PolygonRenderer();
Expand All @@ -94,7 +96,7 @@ class PolygonRenderer
QgsMapLayerRef layerRef; //!< Layer used to extract polygons from
};

class PointRenderer
class _3D_EXPORT PointRenderer
{
public:
PointRenderer();
Expand All @@ -115,7 +117,7 @@ class PointRenderer
QgsMapLayerRef layerRef; //!< Layer used to extract points from
};

class LineRenderer
class _3D_EXPORT LineRenderer
{
public:
LineRenderer();
Expand Down Expand Up @@ -146,7 +148,7 @@ class QgsProject;
class QDomElement;

//! Definition of the world
class Map3D
class _3D_EXPORT Map3D
{
public:
Map3D();
Expand Down
4 changes: 3 additions & 1 deletion src/3d/scene.h
@@ -1,6 +1,8 @@
#ifndef SCENE_H
#define SCENE_H

#include "qgis_3d.h"

#include <Qt3DCore/QEntity>

namespace Qt3DRender
Expand All @@ -27,7 +29,7 @@ class ChunkedEntity;
/**
* Entity that encapsulates our 3D scene - contains all other entities (such as terrain) as children.
*/
class Scene : public Qt3DCore::QEntity
class _3D_EXPORT Scene : public Qt3DCore::QEntity
{
Q_OBJECT
public:
Expand Down
7 changes: 7 additions & 0 deletions src/3d/shaders.qrc
@@ -0,0 +1,7 @@
<RCC>
<qresource prefix="/">
<file>shaders/instanced.frag</file>
<file>shaders/instanced.vert</file>
<file>shaders/light.inc.frag</file>
</qresource>
</RCC>
24 changes: 24 additions & 0 deletions src/3d/shaders/instanced.frag
@@ -0,0 +1,24 @@
#version 150 core

// copy of phong.frag from qt3d extras

uniform vec3 ka; // Ambient reflectivity
uniform vec3 kd; // Diffuse reflectivity
uniform vec3 ks; // Specular reflectivity
uniform float shininess; // Specular shininess factor

uniform vec3 eyePosition;

in vec3 worldPosition;
in vec3 worldNormal;

out vec4 fragColor;

#pragma include light.inc.frag

void main()
{
vec3 diffuseColor, specularColor;
adsModel(worldPosition, worldNormal, eyePosition, shininess, diffuseColor, specularColor);
fragColor = vec4( ka + kd * diffuseColor + ks * specularColor, 1.0 );
}
28 changes: 28 additions & 0 deletions src/3d/shaders/instanced.vert
@@ -0,0 +1,28 @@
#version 150 core

in vec3 vertexPosition;
in vec3 vertexNormal;
in vec3 pos;

out vec3 worldPosition;
out vec3 worldNormal;

uniform mat4 modelView;
uniform mat3 modelViewNormal;
uniform mat4 modelViewProjection;

uniform mat4 inst; // transform of individual object instance
uniform mat4 instNormal; // should be mat3 but Qt3D only supports mat4...

void main()
{
// TODO: i think this is not entirely correct: the translation by "pos" works
// like this only because we assume that "inst" matrix only does translation/scale/rotation
// which all keep "w" set to 1. correctly we should use translation matrix...
vec4 offsetPos = inst * vec4(vertexPosition, 1.0) + vec4(pos, 0.0);

worldNormal = normalize(modelViewNormal * mat3(instNormal) * vertexNormal);
worldPosition = vec3(modelView * offsetPos);

gl_Position = modelViewProjection * offsetPos;
}

0 comments on commit 8d4d5ab

Please sign in to comment.