Skip to content
Permalink
Browse files

Added missing shaders and temporary test application

  • Loading branch information
wonder-sk committed Jul 19, 2017
1 parent 675a1ae commit 8d4d5ab3eaea694d962b5255b02cd054f23dd2f6
@@ -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
@@ -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)

@@ -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)
@@ -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()
@@ -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 )
@@ -1,6 +1,8 @@
#ifndef DEMTERRAINGENERATOR_H
#define DEMTERRAINGENERATOR_H

#include "qgis_3d.h"

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

@@ -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();
@@ -1,6 +1,8 @@
#ifndef FLATTERRAINGENERATOR_H
#define FLATTERRAINGENERATOR_H

#include "qgis_3d.h"

#include "terraingenerator.h"

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

class FlatTerrainGenerator : public TerrainGenerator
class _3D_EXPORT FlatTerrainGenerator : public TerrainGenerator
{
public:
FlatTerrainGenerator();
@@ -1,6 +1,8 @@
#ifndef MAP3D_H
#define MAP3D_H

#include "qgis_3d.h"

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


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


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

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

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

//! Definition of the world
class Map3D
class _3D_EXPORT Map3D
{
public:
Map3D();
@@ -1,6 +1,8 @@
#ifndef SCENE_H
#define SCENE_H

#include "qgis_3d.h"

#include <Qt3DCore/QEntity>

namespace Qt3DRender
@@ -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:
@@ -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>
@@ -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 );
}
@@ -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.
You can’t perform that action at this time.