Commit cbfa0200 authored by Christopher Tenter's avatar Christopher Tenter

checkin new per-pixel linked-list oit renderer

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free-Staging@19462 383ad7c9-94d9-4d36-a494-682f7c89f535
parent a1802ea5
include (plugin)
openflipper_plugin ( INSTALLDATA Shaders )
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2014 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org *
* *
*--------------------------------------------------------------------------- *
* This file is part of OpenFlipper. *
* *
* OpenFlipper is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the *
* following exceptions: *
* *
* If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. *
* *
* OpenFlipper is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU LesserGeneral Public *
* License along with OpenFlipper. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision: 13374 $ *
* $LastChangedBy: moebius $ *
* $Date: 2012-01-13 09:38:16 +0100 (Fri, 13 Jan 2012) $ *
* *
\*===========================================================================*/
#pragma once
#include <QObject>
#include <OpenFlipper/BasePlugin/BaseInterface.hh>
#include <OpenFlipper/BasePlugin/RenderInterface.hh>
#include <OpenFlipper/BasePlugin/LoggingInterface.hh>
#include <ACG/GL/IRenderer.hh>
#include <ACG/GL/globjects.hh>
#include <ACG/GL/FBO.hh>
class OITLinkedList : public QObject, BaseInterface, RenderInterface, LoggingInterface, ACG::IRenderer
{
Q_OBJECT
Q_INTERFACES(BaseInterface)
Q_INTERFACES(RenderInterface)
Q_INTERFACES(LoggingInterface)
#if QT_VERSION >= 0x050000
Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-Render-OITLinkedList")
#endif
signals:
// LoggingInterface
void log(Logtype _type, QString _message);
void log(QString _message);
public:
OITLinkedList();
~OITLinkedList();
QString name() { return (QString("OITLinkedList")); };
QString description( ) { return (QString(tr("Order independent transparency with per pixel linked lists"))); };
public slots:
QString version() { return QString("1.0"); };
QString renderObjectsInfo(bool _outputShaderInfo);
private slots:
//BaseInterface
void initializePlugin();
void exit(){}
// RenderInterface
void render(ACG::GLState* _glState, Viewer::ViewerProperties& _properties);
QString rendererName() {return QString("OITLinkedList");}
void supportedDrawModes(ACG::SceneGraph::DrawModes::DrawMode& _mode) {_mode = ACG::SceneGraph::DrawModes::DEFAULT;}
QString checkOpenGL();
private:
void prepareBuffers(int w, int h);
void renderOIT(int w, int h, bool multisampled);
// counter for number of processed fragments
ACG::AtomicCounter fragCounter_;
// stores start offset into FLBuffer
ACG::TextureBuffer startOffsetBuffer_;
// ABuffer: per pixel linked list buffer
ACG::TextureBuffer ABuffer_;
};
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2014 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org *
* *
*--------------------------------------------------------------------------- *
* This file is part of OpenFlipper. *
* *
* OpenFlipper is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the *
* following exceptions: *
* *
* If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. *
* *
* OpenFlipper is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU LesserGeneral Public *
* License along with OpenFlipper. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision: 18127 $ *
* $LastChangedBy: moebius $ *
* $Date: 2014-02-05 10:12:54 +0100 (Wed, 05 Feb 2014) $ *
* *
\*===========================================================================*/
/** @file
*
* Contains definitions of the OITLinkedList Renderer that require qt headers
* which are incompatible with glew.h.
*/
#include "OITLinkedList.hh"
#include <QGLFormat>
QString OITLinkedList::checkOpenGL()
{
// Get version and check
QGLFormat::OpenGLVersionFlags flags = QGLFormat::openGLVersionFlags();
if ( !flags.testFlag(QGLFormat::OpenGL_Version_4_0) ) // actually 4.2 required, but flag missing in qt 4.8
return QString("Insufficient OpenGL Version! OpenGL 4.0 or higher required");
// Check extensions
QString glExtensions = QString((const char*)glGetString(GL_EXTENSIONS));
QString missing("");
if ( !glExtensions.contains("ARB_shader_image_load_store") )
missing += "ARB_shader_image_load_store extension missing\n";
if ( !glExtensions.contains("GL_ARB_shader_atomic_counters") )
missing += "GL_ARB_shader_atomic_counters extension missing\n";
if ( !glExtensions.contains("GL_ARB_gpu_shader5") )
missing += "GL_ARB_gpu_shader5 extension missing\n";
return missing;
}
\ No newline at end of file
#version 420
// reset offset to 0xffffffff for all pixels
layout(pixel_center_integer) in vec4 gl_FragCoord;
layout(binding = 0, r32ui) uniform uimageBuffer g_StartOffsetBuffer;
uniform uvec2 g_ScreenSize;
void main()
{
uvec2 absFragCoord = uvec2(gl_FragCoord.xy);
uint uPixelID = absFragCoord.x + g_ScreenSize.x * absFragCoord.y;
imageStore(g_StartOffsetBuffer, int(uPixelID), uvec4(0xffffffff,0,0,0));
}
\ No newline at end of file
#version 420
// use OITLL_MSAA macro to enable coverage multisampling
#define MAXLISTSIZE 16
// default: pixel center at absIndex + vec2(0.5, 0.5)
// force pixel ceter at absIndex
layout(pixel_center_integer) in vec4 gl_FragCoord;
in vec2 vTexCoord;
out vec4 outColor;
layout(binding = 0, r32ui) uniform uimageBuffer g_StartOffsetBuffer;
layout(binding = 1, rgba32ui) uniform uimageBuffer g_ABuffer;
uniform uvec2 g_ScreenSize;
struct FragListEntry
{
uint color;
float depth;
};
void main()
{
uvec2 absFragCoord = uvec2(gl_FragCoord.xy); // * g_ScreenSize);
uint uiPixelID = absFragCoord.x + g_ScreenSize.x * absFragCoord.y;
// sorted list of the current pixel list
FragListEntry list[MAXLISTSIZE];
// get offset to head of the list
uint uiOffset = imageLoad(g_StartOffsetBuffer, int(uiPixelID)).r;
uint startOffset = uiOffset;
// keep track of list size
int listSize = 0;
vec4 dbgColor = vec4(1,1,1,1);
// read linked list from ABuffer, starting at offset of list head
while (uiOffset != 0xffffffff && listSize < MAXLISTSIZE)
{
uvec4 fragEntry = imageLoad(g_ABuffer, int(uiOffset));
// fragEntry : (color, depth, next, coverage)
#ifdef OITLL_MSAA
// check if sample is covered by rasterized triangle
if ((fragEntry.w & (1 << gl_SampleID)) != 0)
#endif
{
list[listSize].color = fragEntry.x;
list[listSize].depth = uintBitsToFloat(fragEntry.y);
// insertion sort
int j = listSize;
int prev = max(j-1, 0);
// insertion sort: front to back
while( (j > 0) && (list[prev].depth > list[j].depth) )
{
// swap
FragListEntry tmp = list[j];
list[j] = list[prev];
list[prev] = tmp;
--j;
prev = max(j-1, 0);
}
listSize = min(listSize+1, MAXLISTSIZE);
}
// goto next entry
uiOffset = fragEntry.z;
}
vec4 color = vec4(0,0,0,1);
// blend back to front
for (int i = listSize-1; i >= 0; --i)
{
vec4 fragColor = unpackUnorm4x8(list[i].color);
color.xyz = mix(color.xyz, fragColor.xyz, fragColor.w);
}
outColor = color; // * gl_NumSamples;
// weird bug, for some reason color != (0,0,0,1) for unshaded pixels
if (startOffset == 0xffffffff)
outColor = vec4(0,0,0,1);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment