mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 14:29:13 +02:00
first cut a variable point size point rendering
This commit is contained in:
parent
f3bc633dea
commit
b3aac56d29
7 changed files with 182 additions and 4 deletions
32
interface/resources/shaders/point_size.vert
Normal file
32
interface/resources/shaders/point_size.vert
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
#version 120
|
||||||
|
|
||||||
|
attribute float voxelSizeIn;
|
||||||
|
varying float voxelSize;
|
||||||
|
uniform float viewportWidth;
|
||||||
|
uniform float viewportHeight;
|
||||||
|
|
||||||
|
void main(void) {
|
||||||
|
gl_FrontColor = gl_Color;
|
||||||
|
vec4 cornerOriginal = gl_Vertex;
|
||||||
|
vec4 corner = gl_ModelViewProjectionMatrix * gl_Vertex;
|
||||||
|
|
||||||
|
vec4 farCornerVertex = gl_Vertex;
|
||||||
|
farCornerVertex[0] += voxelSizeIn;
|
||||||
|
farCornerVertex[1] += voxelSizeIn;
|
||||||
|
farCornerVertex[2] += voxelSizeIn;
|
||||||
|
vec4 farCorner = gl_ModelViewProjectionMatrix * farCornerVertex;
|
||||||
|
|
||||||
|
float voxelScreenWidth = abs((farCorner.x / farCorner.w) - (corner.x / corner.w)) * viewportWidth / 2.0;
|
||||||
|
float voxelScreenHeight = abs((farCorner.y / farCorner.w) - (corner.y / corner.w)) * viewportHeight / 2.0;
|
||||||
|
float voxelScreenLength = sqrt(voxelScreenHeight * voxelScreenHeight + voxelScreenWidth * voxelScreenWidth);
|
||||||
|
|
||||||
|
vec4 centerVertex = gl_Vertex;
|
||||||
|
float halfSizeIn = voxelSizeIn / 2;
|
||||||
|
centerVertex[0] += halfSizeIn;
|
||||||
|
centerVertex[1] += halfSizeIn;
|
||||||
|
centerVertex[2] += halfSizeIn;
|
||||||
|
vec4 center = gl_ModelViewProjectionMatrix * centerVertex;
|
||||||
|
|
||||||
|
gl_Position = center;
|
||||||
|
gl_PointSize = voxelScreenLength;
|
||||||
|
}
|
|
@ -1665,6 +1665,7 @@ void Application::init() {
|
||||||
_glowEffect.init();
|
_glowEffect.init();
|
||||||
_ambientOcclusionEffect.init();
|
_ambientOcclusionEffect.init();
|
||||||
_voxelShader.init();
|
_voxelShader.init();
|
||||||
|
_pointShader.init();
|
||||||
|
|
||||||
_handControl.setScreenDimensions(_glWidget->width(), _glWidget->height());
|
_handControl.setScreenDimensions(_glWidget->width(), _glWidget->height());
|
||||||
|
|
||||||
|
|
|
@ -55,12 +55,12 @@
|
||||||
#include "renderer/GeometryCache.h"
|
#include "renderer/GeometryCache.h"
|
||||||
#include "renderer/GlowEffect.h"
|
#include "renderer/GlowEffect.h"
|
||||||
#include "renderer/VoxelShader.h"
|
#include "renderer/VoxelShader.h"
|
||||||
|
#include "renderer/PointShader.h"
|
||||||
#include "renderer/TextureCache.h"
|
#include "renderer/TextureCache.h"
|
||||||
#include "ui/BandwidthDialog.h"
|
#include "ui/BandwidthDialog.h"
|
||||||
#include "ui/ChatEntry.h"
|
#include "ui/ChatEntry.h"
|
||||||
#include "ui/VoxelStatsDialog.h"
|
#include "ui/VoxelStatsDialog.h"
|
||||||
#include "ui/RearMirrorTools.h"
|
#include "ui/RearMirrorTools.h"
|
||||||
#include "ui/LodToolsDialog.h"
|
|
||||||
|
|
||||||
class QAction;
|
class QAction;
|
||||||
class QActionGroup;
|
class QActionGroup;
|
||||||
|
@ -162,6 +162,9 @@ public:
|
||||||
virtual void domainChanged(QString domain);
|
virtual void domainChanged(QString domain);
|
||||||
|
|
||||||
VoxelShader& getVoxelShader() { return _voxelShader; }
|
VoxelShader& getVoxelShader() { return _voxelShader; }
|
||||||
|
PointShader& getPointShader() { return _pointShader; }
|
||||||
|
|
||||||
|
glm::vec2 getViewportDimensions() const{ return glm::vec2(_glWidget->width(),_glWidget->height()); }
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void sendAvatarFaceVideoMessage(int frameCount, const QByteArray& data);
|
void sendAvatarFaceVideoMessage(int frameCount, const QByteArray& data);
|
||||||
|
@ -383,6 +386,7 @@ private:
|
||||||
GlowEffect _glowEffect;
|
GlowEffect _glowEffect;
|
||||||
AmbientOcclusionEffect _ambientOcclusionEffect;
|
AmbientOcclusionEffect _ambientOcclusionEffect;
|
||||||
VoxelShader _voxelShader;
|
VoxelShader _voxelShader;
|
||||||
|
PointShader _pointShader;
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
Audio _audio;
|
Audio _audio;
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
#include "Menu.h"
|
#include "Menu.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "InfoView.h"
|
#include "InfoView.h"
|
||||||
|
#include "ui/LodToolsDialog.h"
|
||||||
|
|
||||||
Menu* Menu::_instance = NULL;
|
Menu* Menu::_instance = NULL;
|
||||||
|
|
||||||
|
|
|
@ -1257,13 +1257,28 @@ void VoxelSystem::render(bool texture) {
|
||||||
|
|
||||||
if (!_voxelsAsPoints) {
|
if (!_voxelsAsPoints) {
|
||||||
Application::getInstance()->getVoxelShader().begin();
|
Application::getInstance()->getVoxelShader().begin();
|
||||||
|
|
||||||
attributeLocation = Application::getInstance()->getVoxelShader().attributeLocation("voxelSizeIn");
|
attributeLocation = Application::getInstance()->getVoxelShader().attributeLocation("voxelSizeIn");
|
||||||
glEnableVertexAttribArray(attributeLocation);
|
glEnableVertexAttribArray(attributeLocation);
|
||||||
glVertexAttribPointer(attributeLocation, 1, GL_FLOAT, false, sizeof(VoxelShaderVBOData), BUFFER_OFFSET(3*sizeof(float)));
|
glVertexAttribPointer(attributeLocation, 1, GL_FLOAT, false, sizeof(VoxelShaderVBOData), BUFFER_OFFSET(3*sizeof(float)));
|
||||||
} else {
|
} else {
|
||||||
const float POINT_SIZE = 4.0;
|
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
|
||||||
glPointSize(POINT_SIZE);
|
|
||||||
|
glm::vec2 viewDimensions = Application::getInstance()->getViewportDimensions();
|
||||||
|
float viewportWidth = viewDimensions.x;
|
||||||
|
float viewportHeight = viewDimensions.y;
|
||||||
|
|
||||||
|
Application::getInstance()->getPointShader().begin();
|
||||||
|
|
||||||
|
int uniformLocation = Application::getInstance()->getPointShader().uniformLocation("viewportWidth");
|
||||||
|
Application::getInstance()->getPointShader().setUniformValue(uniformLocation, viewportWidth);
|
||||||
|
|
||||||
|
uniformLocation = Application::getInstance()->getPointShader().uniformLocation("viewportHeight");
|
||||||
|
Application::getInstance()->getPointShader().setUniformValue(uniformLocation, viewportHeight);
|
||||||
|
|
||||||
|
attributeLocation = Application::getInstance()->getVoxelShader().attributeLocation("voxelSizeIn");
|
||||||
|
//printf("attributeLocation=%d\n", attributeLocation);
|
||||||
|
glEnableVertexAttribArray(attributeLocation);
|
||||||
|
glVertexAttribPointer(attributeLocation, 1, GL_FLOAT, false, sizeof(VoxelShaderVBOData), BUFFER_OFFSET(3*sizeof(float)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1287,6 +1302,10 @@ void VoxelSystem::render(bool texture) {
|
||||||
if (!_voxelsAsPoints) {
|
if (!_voxelsAsPoints) {
|
||||||
Application::getInstance()->getVoxelShader().end();
|
Application::getInstance()->getVoxelShader().end();
|
||||||
glDisableVertexAttribArray(attributeLocation);
|
glDisableVertexAttribArray(attributeLocation);
|
||||||
|
} else {
|
||||||
|
Application::getInstance()->getPointShader().end();
|
||||||
|
glDisableVertexAttribArray(attributeLocation);
|
||||||
|
glDisable(GL_VERTEX_PROGRAM_POINT_SIZE);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
PerformanceWarning warn(showWarnings, "render().. TRIANGLES...");
|
PerformanceWarning warn(showWarnings, "render().. TRIANGLES...");
|
||||||
|
|
73
interface/src/renderer/PointShader.cpp
Normal file
73
interface/src/renderer/PointShader.cpp
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
//
|
||||||
|
// PointShader.cpp
|
||||||
|
// interface
|
||||||
|
//
|
||||||
|
// Created by Brad Hefta-Gaub on 9/22/13.
|
||||||
|
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||||
|
|
||||||
|
// include this before QOpenGLFramebufferObject, which includes an earlier version of OpenGL
|
||||||
|
#include "InterfaceConfig.h"
|
||||||
|
|
||||||
|
#include <QOpenGLFramebufferObject>
|
||||||
|
|
||||||
|
#include "Application.h"
|
||||||
|
#include "PointShader.h"
|
||||||
|
#include "ProgramObject.h"
|
||||||
|
#include "RenderUtil.h"
|
||||||
|
|
||||||
|
PointShader::PointShader()
|
||||||
|
: _initialized(false)
|
||||||
|
{
|
||||||
|
_program = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
PointShader::~PointShader() {
|
||||||
|
if (_initialized) {
|
||||||
|
delete _program;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ProgramObject* PointShader::createPointShaderProgram(const QString& name) {
|
||||||
|
ProgramObject* program = new ProgramObject();
|
||||||
|
program->addShaderFromSourceFile(QGLShader::Vertex, "resources/shaders/" + name + ".vert" );
|
||||||
|
program->link();
|
||||||
|
return program;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PointShader::init() {
|
||||||
|
if (_initialized) {
|
||||||
|
qDebug("[ERROR] PointShader is already initialized.\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
switchToResourcesParentIfRequired();
|
||||||
|
_program = createPointShaderProgram("point_size");
|
||||||
|
_initialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PointShader::begin() {
|
||||||
|
_program->bind();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PointShader::end() {
|
||||||
|
_program->release();
|
||||||
|
}
|
||||||
|
|
||||||
|
int PointShader::attributeLocation(const char * name) const {
|
||||||
|
if (_program) {
|
||||||
|
return _program->attributeLocation(name);
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int PointShader::uniformLocation(const char * name) const {
|
||||||
|
if (_program) {
|
||||||
|
return _program->uniformLocation(name);
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PointShader::setUniformValue(int attributeLocation, float value) {
|
||||||
|
_program->setUniformValue(attributeLocation, value);
|
||||||
|
}
|
48
interface/src/renderer/PointShader.h
Normal file
48
interface/src/renderer/PointShader.h
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
//
|
||||||
|
// PointShader.h
|
||||||
|
// interface
|
||||||
|
//
|
||||||
|
// Created by Brad Hefta-Gaub on 9/23/13.
|
||||||
|
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef __interface__PointShader__
|
||||||
|
#define __interface__PointShader__
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
class ProgramObject;
|
||||||
|
|
||||||
|
/// A generic full screen glow effect.
|
||||||
|
class PointShader : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
PointShader();
|
||||||
|
~PointShader();
|
||||||
|
|
||||||
|
void init();
|
||||||
|
|
||||||
|
/// Starts using the voxel geometry shader effect.
|
||||||
|
void begin();
|
||||||
|
|
||||||
|
/// Stops using the voxel geometry shader effect.
|
||||||
|
void end();
|
||||||
|
|
||||||
|
/// Gets access to attributes from the shader program
|
||||||
|
int attributeLocation(const char * name) const;
|
||||||
|
int uniformLocation(const char * name) const;
|
||||||
|
void setUniformValue(int attributeLocation, float value);
|
||||||
|
|
||||||
|
static ProgramObject* createPointShaderProgram(const QString& name);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
bool _initialized;
|
||||||
|
|
||||||
|
ProgramObject* _program;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* defined(__interface__PointShader__) */
|
Loading…
Reference in a new issue