mirror of
https://github.com/overte-org/overte.git
synced 2025-04-19 16:23:39 +02:00
hacking on voxel geometry shader
This commit is contained in:
parent
297652a83b
commit
3d4341cee4
8 changed files with 320 additions and 3 deletions
46
interface/resources/shaders/duplicate_geometry.geom
Normal file
46
interface/resources/shaders/duplicate_geometry.geom
Normal file
|
@ -0,0 +1,46 @@
|
|||
#version 420
|
||||
|
||||
layout(triangles) in;
|
||||
layout (triangle_strip, max_vertices=6) out;
|
||||
|
||||
layout (std140) uniform Matrices {
|
||||
mat4 projModelViewMatrix;
|
||||
mat3 normalMatrix;
|
||||
};
|
||||
|
||||
in VertexData {
|
||||
vec2 texCoord;
|
||||
vec3 normal;
|
||||
} VertexIn[];
|
||||
|
||||
out VertexData {
|
||||
vec2 texCoord;
|
||||
vec3 normal;
|
||||
} VertexOut;
|
||||
|
||||
void main()
|
||||
{
|
||||
for(int i = 0; i < gl_in.length(); i++)
|
||||
{
|
||||
// copy attributes
|
||||
gl_Position = projModelViewMatrix * gl_in[i].gl_Position;
|
||||
VertexOut.normal = normalize(normalMatrix * VertexIn[i].normal);
|
||||
VertexOut.texCoord = VertexIn[i].texCoord;
|
||||
|
||||
// done with the vertex
|
||||
EmitVertex();
|
||||
}
|
||||
EndPrimitive();
|
||||
|
||||
for(int i = 0; i < gl_in.length(); i++)
|
||||
{
|
||||
// copy attributes and displace copy
|
||||
gl_Position = projModelViewMatrix * (gl_in[i].gl_Position + vec4(20.0, 0.0, 0.0, 0.0));
|
||||
VertexOut.normal = normalize(normalMatrix * VertexIn[i].normal);
|
||||
VertexOut.texCoord = VertexIn[i].texCoord;
|
||||
|
||||
// done with the vertex
|
||||
EmitVertex();
|
||||
}
|
||||
EndPrimitive();
|
||||
}
|
150
interface/resources/shaders/passthrough.geom
Normal file
150
interface/resources/shaders/passthrough.geom
Normal file
|
@ -0,0 +1,150 @@
|
|||
#version 120
|
||||
#extension GL_ARB_geometry_shader4 : enable
|
||||
|
||||
// use GL_POINTS
|
||||
// have point be the corner of voxel
|
||||
// have a second dataset (? similar to how voxel avatars pass in bones??)
|
||||
// which is the voxel size?
|
||||
//
|
||||
// In vertex shader DON'T transform.. therefor passing the world coordinate xyz to geometric shader
|
||||
// In geometric shader calculate xyz for triangles the same way we currently do triangles outside of OpenGL
|
||||
// do transform on these triangles
|
||||
// gl_Position = gl_ModelViewProjectionMatrix * cube_coord;
|
||||
//
|
||||
// output GL_TRIANGLE_STRIP
|
||||
//
|
||||
// NOTE: updateNodeInArrays() does the covert from voxel corner to 12 triangles or 36 points or 36*3 floats
|
||||
// but since it operates on the array of floats, it is kinda weird and hard to follow. The %3 is for the
|
||||
// xyz.. and identityVertices[j] term in the math is actually a string of floats but they should be thought
|
||||
// of as triplets of x,y,z
|
||||
//
|
||||
// do we need to add the light to these colors??
|
||||
//
|
||||
|
||||
//GEOMETRY SHADER
|
||||
///////////////////////
|
||||
void main()
|
||||
{
|
||||
//increment variable
|
||||
int i;
|
||||
vec4 vertex;
|
||||
vec4 color,red,green,blue;
|
||||
|
||||
green = vec4(0,1.0,0,1.0);
|
||||
red = vec4(1.0,0,0,1.0);
|
||||
blue = vec4(0,0,1.0,1.0);
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
//This example has two parts
|
||||
// step a) draw the primitive pushed down the pipeline
|
||||
// there are gl_VerticesIn # of vertices
|
||||
// put the vertex value into gl_Position
|
||||
// use EmitVertex => 'create' a new vertex
|
||||
// use EndPrimitive to signal that you are done creating a primitive!
|
||||
// step b) create a new piece of geometry
|
||||
// I just do the same loop, but I negate the vertex.z
|
||||
// result => the primitive is now mirrored.
|
||||
//Pass-thru!
|
||||
for(i = 0; i < gl_VerticesIn; i++) {
|
||||
color = gl_FrontColorIn[i];
|
||||
gl_FrontColor = color; //
|
||||
gl_Position = gl_ModelViewProjectionMatrix * gl_PositionIn[i];
|
||||
EmitVertex();
|
||||
}
|
||||
EndPrimitive();
|
||||
|
||||
for(i = 0; i < gl_VerticesIn; i++) {
|
||||
gl_FrontColor = red; //
|
||||
vertex = gl_PositionIn[i];
|
||||
vertex.y += 0.05f;
|
||||
gl_Position = gl_ModelViewProjectionMatrix * vertex;
|
||||
EmitVertex();
|
||||
}
|
||||
EndPrimitive();
|
||||
|
||||
for(i = 0; i < gl_VerticesIn; i++) {
|
||||
gl_FrontColor = green; //
|
||||
vertex = gl_PositionIn[i];
|
||||
vertex.x += 0.05f;
|
||||
gl_Position = gl_ModelViewProjectionMatrix * vertex;
|
||||
EmitVertex();
|
||||
}
|
||||
EndPrimitive();
|
||||
|
||||
for(i = 0; i < gl_VerticesIn; i++) {
|
||||
gl_FrontColor = blue; //
|
||||
vertex = gl_PositionIn[i];
|
||||
vertex.z += 0.05f;
|
||||
gl_Position = gl_ModelViewProjectionMatrix * vertex;
|
||||
EmitVertex();
|
||||
}
|
||||
EndPrimitive();
|
||||
|
||||
/**
|
||||
|
||||
for(i = 0; i < gl_VerticesIn; i++) {
|
||||
green = vec4(0,1.0,0,1.0);
|
||||
red = vec4(1.0,0,0,1.0);
|
||||
//gl_FrontColor = gl_FrontColorIn[i];
|
||||
gl_FrontColor = red;
|
||||
|
||||
// v -> v+x -> v+x+y
|
||||
vertex = gl_PositionIn[i];
|
||||
gl_Position = vertex;
|
||||
EmitVertex();
|
||||
vertex.x += 0.1f;
|
||||
gl_Position = vertex;
|
||||
EmitVertex();
|
||||
vertex.y += 0.1f;
|
||||
gl_Position = vertex;
|
||||
EmitVertex();
|
||||
EndPrimitive();
|
||||
|
||||
// v+x+y -> v+y -> v
|
||||
vertex = gl_PositionIn[i];
|
||||
vertex.x += 0.1f;
|
||||
vertex.y += 0.1f;
|
||||
gl_Position = vertex;
|
||||
EmitVertex();
|
||||
vertex.x -= 0.1f;
|
||||
gl_Position = vertex;
|
||||
EmitVertex();
|
||||
vertex.y -= 0.1f;
|
||||
gl_Position = vertex;
|
||||
EmitVertex();
|
||||
EndPrimitive();
|
||||
// v+z -> v+z+x -> v+z+x+y
|
||||
gl_FrontColor = green;
|
||||
vertex = gl_PositionIn[i];
|
||||
vertex.z -= 0.1f;
|
||||
gl_Position = vertex;
|
||||
EmitVertex();
|
||||
|
||||
vertex.x += 0.1f;
|
||||
gl_Position = vertex;
|
||||
EmitVertex();
|
||||
vertex.y += 0.1f;
|
||||
gl_Position = vertex;
|
||||
EmitVertex();
|
||||
EndPrimitive();
|
||||
|
||||
// v+z+x+y -> v+z+y -> v+z
|
||||
vertex = gl_PositionIn[i];
|
||||
vertex.z -= 0.1f;
|
||||
vertex.x += 0.1f;
|
||||
vertex.y += 0.1f;
|
||||
gl_Position = vertex;
|
||||
EmitVertex();
|
||||
vertex.x -= 0.1f;
|
||||
gl_Position = vertex;
|
||||
EmitVertex();
|
||||
vertex.y -= 0.1f;
|
||||
gl_Position = vertex;
|
||||
EmitVertex();
|
||||
EndPrimitive();
|
||||
|
||||
}
|
||||
**/
|
||||
|
||||
|
||||
}
|
6
interface/resources/shaders/passthrough.vert
Normal file
6
interface/resources/shaders/passthrough.vert
Normal file
|
@ -0,0 +1,6 @@
|
|||
#version 120
|
||||
|
||||
void main(void) {
|
||||
gl_FrontColor = gl_Color; //vec4(1.0, 0.0, 0.0, 1.0);
|
||||
gl_Position = gl_Vertex;// ftransform();
|
||||
}
|
|
@ -389,6 +389,7 @@ void Application::paintGL() {
|
|||
|
||||
} else {
|
||||
_glowEffect.prepare();
|
||||
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
|
@ -1539,6 +1540,7 @@ void Application::init() {
|
|||
|
||||
_glowEffect.init();
|
||||
_ambientOcclusionEffect.init();
|
||||
_testGeometry.init();
|
||||
|
||||
_handControl.setScreenDimensions(_glWidget->width(), _glWidget->height());
|
||||
|
||||
|
@ -2579,7 +2581,9 @@ void Application::displaySide(Camera& whichCamera) {
|
|||
|
||||
// brad's frustum for debugging
|
||||
if (Menu::getInstance()->isOptionChecked(MenuOption::DisplayFrustum)) {
|
||||
_testGeometry.begin();
|
||||
renderViewFrustum(_viewFrustum);
|
||||
_testGeometry.end();
|
||||
}
|
||||
|
||||
// render voxel fades if they exist
|
||||
|
|
|
@ -51,6 +51,7 @@
|
|||
#include "renderer/AmbientOcclusionEffect.h"
|
||||
#include "renderer/GeometryCache.h"
|
||||
#include "renderer/GlowEffect.h"
|
||||
#include "renderer/TestGeometry.h"
|
||||
#include "renderer/TextureCache.h"
|
||||
#include "ui/BandwidthDialog.h"
|
||||
#include "ui/ChatEntry.h"
|
||||
|
@ -342,6 +343,7 @@ private:
|
|||
|
||||
GlowEffect _glowEffect;
|
||||
AmbientOcclusionEffect _ambientOcclusionEffect;
|
||||
TestGeometry _testGeometry;
|
||||
|
||||
#ifndef _WIN32
|
||||
Audio _audio;
|
||||
|
|
65
interface/src/renderer/TestGeometry.cpp
Normal file
65
interface/src/renderer/TestGeometry.cpp
Normal file
|
@ -0,0 +1,65 @@
|
|||
//
|
||||
// TestGeometry.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 "TestGeometry.h"
|
||||
#include "ProgramObject.h"
|
||||
#include "RenderUtil.h"
|
||||
|
||||
TestGeometry::TestGeometry()
|
||||
: _initialized(false)
|
||||
{
|
||||
}
|
||||
|
||||
TestGeometry::~TestGeometry() {
|
||||
if (_initialized) {
|
||||
delete _testProgram;
|
||||
}
|
||||
}
|
||||
|
||||
static ProgramObject* createGeometryShaderProgram(const QString& name) {
|
||||
ProgramObject* program = new ProgramObject();
|
||||
program->addShaderFromSourceFile(QGLShader::Vertex, "resources/shaders/passthrough.vert" );
|
||||
|
||||
|
||||
program->addShaderFromSourceFile(QGLShader::Geometry, "resources/shaders/" + name + ".geom" );
|
||||
|
||||
program->setGeometryInputType(GL_LINES);
|
||||
program->setGeometryOutputType(GL_LINE_STRIP);
|
||||
program->setGeometryOutputVertexCount(100); // hack?
|
||||
|
||||
program->link();
|
||||
//program->log();
|
||||
|
||||
return program;
|
||||
}
|
||||
|
||||
void TestGeometry::init() {
|
||||
if (_initialized) {
|
||||
qDebug("[ERROR] TestProgram is already initialized.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
switchToResourcesParentIfRequired();
|
||||
|
||||
_testProgram = createGeometryShaderProgram("passthrough");
|
||||
_initialized = true;
|
||||
}
|
||||
|
||||
void TestGeometry::begin() {
|
||||
_testProgram->bind();
|
||||
}
|
||||
|
||||
void TestGeometry::end() {
|
||||
_testProgram->release();
|
||||
}
|
||||
|
44
interface/src/renderer/TestGeometry.h
Normal file
44
interface/src/renderer/TestGeometry.h
Normal file
|
@ -0,0 +1,44 @@
|
|||
//
|
||||
// TestGeometry.h
|
||||
// interface
|
||||
//
|
||||
// Created by Andrzej Kapolka on 8/7/13.
|
||||
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef __interface__TestGeometry__
|
||||
#define __interface__TestGeometry__
|
||||
|
||||
#include <QObject>
|
||||
#include <QStack>
|
||||
|
||||
class QOpenGLFramebufferObject;
|
||||
|
||||
class ProgramObject;
|
||||
|
||||
/// A generic full screen glow effect.
|
||||
class TestGeometry : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TestGeometry();
|
||||
~TestGeometry();
|
||||
|
||||
void init();
|
||||
|
||||
/// Starts using the geometry shader effect.
|
||||
void begin();
|
||||
|
||||
/// Stops using the geometry shader effect.
|
||||
void end();
|
||||
|
||||
public slots:
|
||||
|
||||
private:
|
||||
|
||||
bool _initialized;
|
||||
|
||||
ProgramObject* _testProgram;
|
||||
};
|
||||
|
||||
#endif /* defined(__interface__TestGeometry__) */
|
|
@ -33,9 +33,9 @@ const int NUMBER_OF_CHILDREN = 8;
|
|||
const int MAX_VOXEL_PACKET_SIZE = 1492;
|
||||
const int MAX_TREE_SLICE_BYTES = 26;
|
||||
const int MAX_VOXELS_PER_SYSTEM = 200000;
|
||||
const int VERTICES_PER_VOXEL = 24;
|
||||
const int VERTEX_POINTS_PER_VOXEL = 3 * VERTICES_PER_VOXEL;
|
||||
const int INDICES_PER_VOXEL = 3 * 12;
|
||||
const int VERTICES_PER_VOXEL = 24; // 6 sides * 4 corners per side
|
||||
const int VERTEX_POINTS_PER_VOXEL = 3 * VERTICES_PER_VOXEL; // ???? xyz for each VERTICE_PER_VOXEL??
|
||||
const int INDICES_PER_VOXEL = 3 * 12; // 6 sides * 2 triangles per size * 3 vertices per triangle
|
||||
const int COLOR_VALUES_PER_VOXEL = NUMBER_OF_COLORS * VERTICES_PER_VOXEL;
|
||||
|
||||
typedef unsigned long int glBufferIndex;
|
||||
|
|
Loading…
Reference in a new issue