Display a triangular surface as transparent object with a pretty shader using conventional depth-sorting (NOT depth-peeling).
#include <ocean/GLvish/VGLRenderObject.hpp>
#include <ocean/GLvish/BoundingBox.hpp>
#include <ocean/GLvish/ArrayTypes.hpp>
#include <ocean/GLvish/colors.hpp>
#include <ocean/shrimp/VObjectStatus.hpp>
#include <eagle/PhysicalSpace.hpp>
#include <field/Cell.hpp>
#include <GL/fiberGL.hpp>
#include <baseop/ExpandBBox.hpp>
#include <eye/retina/VSkeletonRenderObject.hpp>
#include <grid/types/TriangularSurface.hpp>
#include <bundle/BundleProperty.hpp>
#include <bone/GridActor.hpp>
#include <GL/PartialElementRenderer.hpp>
#include <GLvish/Programmable.hpp>
namespace
{
{
public:
{
#embed "CrystalSurface.vert"
} );
}
{
#embed "CrystalSurface.frag"
} );
}
{
using TriangularSurface::operator=;
};
RefPtr<State> newState() const override
{
return new MyState();
}
SurfaceBackColor;
Alpha,
Colority;
CrystalSurface(const string&name, int, const RefPtr<VCreationPreferences>&VP)
, SurfaceColor(this, "color", {1.,.1,1., 1.0},0)
, SurfaceBackColor(this, "backcolor", {.0, 1.,1.0, 1.0},0)
, Transparency(this, "transparency", 0.5, 0)
, Alpha(this, "alpha", 1.0, 2)
, Colority(this, "colorness", 0.5, 1)
{}
bool update(
VRequest&R,
double precision)
override;
{
return "CrystalSurface(" + parent_name + ")";
}
};
{
RefPtr<MyState> S = myState(
Context);
RefPtr<Grid> G = findMostRecentGrid(
Context );
if (!G)
{
return setStatusError(
Context,
"No Grid found.");
}
*S = G;
if (!*S)
return setStatusError(
Context,
"No surface available.");
setBoundingBall(
Context, getBoundingBox( S->CoordField ) );
return setStatusInfo(
Context,
"Surface ready to render.");
}
struct TriangleRenderer : GL::PartialElementRenderer
{
RefPtr<TriangularSurface::CellArray_t> Cells;
const RefPtr<TriangularSurface::CellArray_t>&TriangleCells)
: GL::PartialElementRenderer( FieldCoordinates,
NullPtr() )
, Cells(TriangleCells)
{
assert( TriangleCells );
assert( Cells->getTypedStorage() );
draw_mode = GL_TRIANGLES;
}
void prefix() override
{
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE);
glEnable(GL_NORMALIZE);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable( GL_BLEND );
}
void postfix() override
{
glDepthMask(GL_TRUE);
}
};
{
RefPtr<MyState> myState = getState(
Context);
if (!myState)
return false;
if (!Surface)
return false;
{
printf("Did not find coordinates :( \n");
return false;
}
{
printf("Did not find triangles :( \n");
return false;
}
glEnable(GL_LIGHTING);
glMaterialf( GL_FRONT, GL_SHININESS, 3 );
glMaterialf( GL_BACK , GL_SHININESS, 50 );
glMaterial( GL::FRONT_AND_BACK, GL::AMBIENT , Color{0,0,.01,0} );
glMaterial( GL::FRONT_AND_BACK, GL::SPECULAR, Color{0.5,0.5,.53, 0} );
glMaterial( GL::FRONT_AND_BACK, GL::EMISSION, Color{0., 0.,0., 0} );
glColor4f(1,0,0, 0.5);
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
SurfaceColor << Context >> SurfColor;
SurfaceBackColor << Context >> SurfBackColor;
{
double Alpha = 0.5;
SurfColor[3] = Alpha;
SurfBackColor[3] = Alpha;
}
glMaterial( GL::FRONT, GL::DIFFUSE, SurfColor );
glMaterial( GL::BACK , GL::DIFFUSE, SurfBackColor );
RefPtr<Field> Tmp = Surface.
getTriangleBaryCenters();
RefPtr<CreativeArrayBase> BaryCenters = Tmp->getCreator();
glEnable( GL_VERTEX_PROGRAM_TWO_SIDE );
RefPtr<GLProgram> MyProgram = CompileShader(
Context,
"CrystalSurface" );
MyProgram->use();
Transparency << Context > MyProgram;
Alpha << Context > MyProgram;
Colority << Context > MyProgram;
const string VBOKey = "";
RefPtr<ValueSet> V;
RefPtr<VBO> myVBO;
RefPtr<TriangleRenderer> MyTriangleRenderer;
unsigned ViewCacheSize = 1;
try
{
if (myVBO
{
if (RefPtr<TriangleRenderer> TR = myVBO->getRenderer() )
{
assert( TR->MyElementSorter );
TR->CurrentIBO = TR->sortByDepth(
Context, BaryCenters, ViewCacheSize );
if (myVBO->call() )
{
return true;
}
}
}
}
{}
if (!myVBO)
assert( myVBO );
myVBO->clear();
if (RefPtr<TriangularSurface::NormalVectorArray_t> VertexNormals = Surface.
getNormals() )
{
}
RefPtr<TriangleRenderer> TR = new TriangleRenderer(myState->getCoords(), myState->CellField->getData() );
TR->CurrentIBO = TR->sortByDepth(
Context, BaryCenters, ViewCacheSize );
myVBO->setRenderer( TR );
myVBO->call();
return true;
}
}
namespace
{
MyCreator(
Category(
"Display" ) + VIdentifier(
"CrystalSurface" ) +
Application(
"General" ) +
Description(
"Show trianglular surface transparently, emphasizing the outline regions." ) +
Url(
"http://vish.fiberbundle.net/wiki" ),
}
Base class for objects rendering skeletons of a fiber bundle.
Definition VSkeletonRenderObject.hpp:21
Given a fragmented field of curvilinear coordinates, (3D array of coordinates), build a uniform Grid ...
Definition FAQ.dox:2
StrongPtr< Object, ObjectBase > RefPtr
Wizt::VCreatorProperty< Wizt::VCreatorProperties::URL > Url
Wizt::VCreatorProperty< Wizt::VCreatorProperties::APPLICATION > Application
Wizt::VCreatorProperty< Wizt::VCreatorProperties::DESCRIPTION > Description
Wizt::VCreatorProperty< Wizt::VCreatorProperties::SHORTHELP > Help
Wizt::VCreatorProperty< Wizt::VCreatorProperties::CATEGORY > Category
note: cannot derive from FloatingSkeletonRenderer as long as independent base class TriangleRenderer ...
virtual string createChildname(const string &parent_name) const
RenderNamespace::glsl embed_glsl(const char(&file_content)[N])
Definition GridInspector.hpp:13
A triangular surface stored on a Grid.
Definition TriangularSurface.hpp:43
RefPtr< Field > CellField
Field for the triangle indices.
Definition TriangularSurface.hpp:66
RefPtr< Field > CoordField
Field for the vertex coordinates.
Definition TriangularSurface.hpp:59
Definition PartialElementRenderer.hpp:56