FiberVISH 0.2
Fish - The Fiber Bundle API for the Vish Visualization Shell
CrystalSurface.cpp
Spherical surface displayed via CrystalSurface module.

Display a triangular surface as transparent object with a pretty shader using conventional depth-sorting (NOT depth-peeling).

The most simple version of a surface rendered is demonstrated by MonochromeSurface .

#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>
using namespace Wizt;
using namespace Fiber;
using namespace Eagle;
namespace
{
/*
Render a triangular surface transparently.
*/
class CrystalSurface : public VSkeletonRenderObject, public Programmable
{
public:
using glsl = RenderNamespace::glsl;
// using GridInspector = Fiber::GridInspector< BundleProperty::Anything >;
glsl vertex_shader(VRenderContext&Context) const override
{
return embed_glsl( {
#embed "CrystalSurface.vert"
} );
}
glsl fragment_shader(VRenderContext&Context) const override
{
return embed_glsl( {
#embed "CrystalSurface.frag"
} );
}
struct MyState : State, TriangularSurface
{
using TriangularSurface::operator=;
};
RefPtr<State> newState() const override
{
return new MyState();
}
SurfaceBackColor;
TypedSlot<double> Transparency,
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 renderGL(VGLRenderContext&Context) const override;
bool update(VRequest&R, double precision) override;
static string createChildname(const string&parent_name)
{
return "CrystalSurface(" + parent_name + ")";
}
};
bool CrystalSurface::update(VRequest&Context, double precision)
{
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.");
}
{
, Cells(TriangleCells)
{
assert( Cells->getTypedStorage() );
const std::vector<TriangleCell>&Cls = Cells->getTypedStorage()->get_vector();
this->CurrentIBO = new IndexBuffer<TriangleCell>( Cls );
draw_mode = GL_TRIANGLES;
}
void prefix() override
{
glEnable(GL_DEPTH_TEST); // see depth buffer
glDepthMask(GL_FALSE); // but don't write to it
}
void postfix() override
{
}
};
bool CrystalSurface::renderGL(VGLRenderContext&Context) const
{
RefPtr<MyState> myState = getState(Context);
if (!myState)
return false;
if (!Surface)
return false;
if (!Surface.CoordField)
{
printf("Did not find coordinates :( \n");
return false;
}
if (!Surface.CellField)
{
printf("Did not find triangles :( \n");
return false;
}
//
// Generic OpenGL section, these settings affect all VBO's rendered later
//
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);
// glColorMaterial( GL_FRONT_AND_BACK, GL_DIFFUSE);
// glEnable( GL_COLOR_MATERIAL );
rgba_float_t SurfColor {1,0,0,0.5 };
{
double Alpha = 0.5;
SurfColor[3] = Alpha;
SurfBackColor[3] = Alpha;
}
// glEnable( GL_DEPTH_TEST );
// glEnable( GL_MULTISAMPLE_ARB );
// glEnable( GL_SAMPLE_ALPHA_TO_COVERAGE_ARB );
// glColor4f( 1,0,0,.8);
// glMaterial( GL::FRONT, GL::DIFFUSE, makeColor( 1., 0.,0., 0.3) );
// glMaterial( GL::BACK , GL::DIFFUSE, makeColor( .3, 1.,0., 0.3) );
// printf(">>>>> CrystalSurface: RENDER cells for t=%ld, %lu Triangles\n",
// myState->CellField->time_value(), Cells->nElements() );
RefPtr<Field> Tmp = Surface.getTriangleBaryCenters();
RefPtr<CreativeArrayBase> BaryCenters = Tmp->getCreator();
RefPtr<GLProgram> MyProgram = CompileShader( Context, "CrystalSurface" );
MyProgram->use();
Alpha << Context > MyProgram;
//
// VBO Access via GLCache, retrieve and re-use or generate new VBO
//
const string VBOKey = "";
RefPtr<ValueSet> V;// = ScaleFactor(Context);
unsigned ViewCacheSize = 1;
try
{
myVBO = Context( *Surface )( typeid(*this) )( V )(VERTEXBUFFER(), VBOKey);
// Call the VBO if it's there and all ready to go.
if (myVBO
&& !myVBO->isOlderThan( *Surface.CellField)
&& !myVBO->isOlderThan( *Surface.CoordField) )
{
if (RefPtr<TriangleRenderer> TR = myVBO->getRenderer() )
{
assert( TR->MyElementSorter );
TR->CurrentIBO = TR->sortByDepth(Context, BaryCenters, ViewCacheSize );
if (myVBO->call() )
{
return true;
}
}
}
}
catch(const GLCacheError&Err)
{}
if (!myVBO)
myVBO = Context[*Surface][ typeid(*this) ][ V ]( VERTEXBUFFER(), VBOKey);
myVBO->clear();
//
// Loading fields as vertex arrays and append them to the VBO.
//
using namespace Eagle::PhysicalSpace;
myVBO->append( new TypedVertexArray<point3>( myState->getCoords()->myChunk() ) );
if (RefPtr<TriangularSurface::NormalVectorArray_t> VertexNormals = Surface.getNormals() )
{
myVBO->append( new TypedNormalArray<bivector3>( VertexNormals->myChunk() ));
}
RefPtr<TriangleRenderer> TR = new TriangleRenderer(myState->getCoords(), myState->CellField->getData() );
TR->MyElementSorter = new GL::TypedElementSorter<TriangleCell>(myState->CellField->getCreator() );
TR->CurrentIBO = TR->sortByDepth(Context, BaryCenters, ViewCacheSize );
myVBO->setRenderer( TR );
myVBO->call();
return true;
}
} // anon namespace
namespace
{
using namespace Panthalassa;
MyCreator( Category( "Display" ) + VIdentifier( "CrystalSurface" ) + Application( "General" ) +
Description( "Show trianglular surface transparently, emphasizing the outline regions." ) +
Help( "todo" ) +
Url( "http://vish.fiberbundle.net/wiki" ),
ObjectQuality::OUTDATED );
}
An iterator with an optional DataCreator, which is just a class to intercept creation of data along a...
Definition CreativeIterator.hpp:34
Base class for objects that render information given on the triangle of a Grid.
Definition TriangleRenderer.hpp:22
virtual void postfix()
virtual void prefix()
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
std::nullptr_t NullPtr
note: cannot derive from FloatingSkeletonRenderer as long as independent base class TriangleRenderer ...
RenderNamespace::glsl embed_glsl(const char(&file_content)[N])
TRANSPARENT_OBJECT
Definition Lytica.hpp:7
Definition GridInspector.hpp:13
A triangular surface stored on a Grid.
Definition TriangularSurface.hpp:43
Base class to draw a selection of elements as OpenGL points.
Definition PartialElementRenderer.hpp:85