Display a triangular surface as transparent object with a pretty shader using conventional depth-sorting (NOT depth-peeling).
#include <ocean/plankton/VPipeline.hpp>
#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 <ocean/shrimp/VEnum.hpp>
#include <eagle/PhysicalSpace.hpp>
#include <field/Cell.hpp>
#include <GL/fiberGL.hpp>
#include <GL/FieldBuffer.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>
#include <bone/FishField.hpp>
#include <ocean/GLvish/VGLColormap.hpp>
#include <baseop/GridField.hpp>
namespace
{
#define FSHADER_COLORMAP_NAME "ColormapTexture"
{
public:
{
#embed "TransparentColoredSurface.vert"
} );
}
{
#embed "TransparentColoredSurface.frag"
} );
}
{
RefPtr<Field> ColorField;
string ColorFieldName,
ErrorMessage;
using TriangularSurface::operator=;
};
RefPtr<State> newState() const override
{
return new MyState();
}
Shininess,
Alpha,
Speculartransparency;
enum { NumberOfInputFields = 1 };
TransparentColoredSurface(const string&name, int, const RefPtr<VCreationPreferences>&VP)
, Transparency(this, "transparency", 0.0, 0)
, Shininess(this, "shininess", 0.5, 0)
, Alpha(this, "alpha", 1.0, 2)
, Speculartransparency(this, "speculartransparency", 0.0,3)
, InputRange(
this,
"range",
Range(0,1), 0 )
, SurfaceColorField(this, "field" )
{}
bool update(
VRequest&R,
double precision)
override;
{
return "TransparentColoredSurface(" + parent_name + ")";
}
};
{
SurfaceColorField << Context >>
FS;
MyGrid << Context >> GS;
RefPtr<MyState> S = myState(
Context);
*S = GF;
if (!*S)
return setStatusError(
Context,
"No surface available.");
if (!S->CartesianVertices)
return setStatusError(
Context,
"No vertices on the surface available.");
S->ColorFieldName =
FS();
S->ColorField = GF;
if (S->ColorField)
{
puts("YAYYYYYYYY HAVE COLORFIELD");
printf("And it should have a name: %s\n", S->ColorFieldName.c_str() );
}
else
puts("NOPE. NO COLORFIELD");
setBoundingBall(
Context, getBoundingBox( S->CoordField ) );
if (S->ErrorMessage.length()>0)
return setStatusError(
Context, S->ErrorMessage );
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_TRUE);
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;
myState->ErrorMessage = "";
if (!Surface)
{
myState->ErrorMessage = "Grid is not a surface";
return false;
}
{
printf("Did not find coordinates :( \n");
myState->ErrorMessage = "Did not find surface coordinates.";
return false;
}
{
printf("Did not find triangles :( \n");
myState->ErrorMessage = "Did not find triangles.";
return false;
}
if (!myState->CellField->getData() )
{
printf("Did not find triangles indices :( \n");
myState->ErrorMessage = "Did not find triangle indices (no data in triangle field)";
return false;
}
RefPtr<Field> Colors = myState->ColorField;
if (!Colors)
{
myState->ErrorMessage = "No such field: \"" + myState->ColorFieldName + "\"";
return false;
}
glEnable(GL_LIGHTING);
double Shine = 0.5;
Shininess << Context >> Shine;
glMaterialf( GL_FRONT, GL_SHININESS, Shine );
glMaterialf( GL_BACK , GL_SHININESS, Shine );
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);
RefPtr<Field> Tmp = Surface.
getTriangleBaryCenters();
RefPtr<CreativeArrayBase> BaryCenters = Tmp->getCreator();
glEnable( GL_VERTEX_PROGRAM_TWO_SIDE );
RefPtr<GLProgram> MyProgram = CompileShader(
Context,
"TransparentColoredSurface" );
assert( MyProgram );
MyProgram->use();
Transparency << Context > MyProgram;
Alpha << Context > MyProgram;
Speculartransparency << Context > MyProgram;
string VBOKey = myState->ColorFieldName ;
RefPtr<ValueSet> V;
RefPtr<VBO> myVBO;
RefPtr<TriangleRenderer> MyTriangleRenderer;
VColormap Cmap;
Colormap << Context >> Cmap;
RefPtr<GLTexture1D> CmapTexture =
if (CmapTexture)
{
MyProgram->setUniformTexture( FSHADER_COLORMAP_NAME , *CmapTexture);
}
Range ColorMapRange(0,1);
InputRange << Context >> ColorMapRange;
unsigned ViewCacheSize = 1;
try
{
if (myVBO
&& !myVBO->isOlderThan( InputRange->
age(
Context) )
&& (Colors && !myVBO->isOlderThan( *Colors) ) )
{
if (RefPtr<TriangleRenderer> TR = myVBO->getRenderer() )
{
assert( TR->MyElementSorter );
TR->CurrentIBO = TR->sortByDepth(
Context, BaryCenters, ViewCacheSize );
if (myVBO->call() )
{
myState->ErrorMessage = "";
return true;
}
}
}
}
{}
if (!myVBO)
assert( myVBO );
myVBO->clear();
if (RefPtr<TriangularSurface::NormalVectorArray_t> VertexNormals = Surface.
getNormals() )
{
}
#if 0
if (!Colors)
{
index_t nVertices = Surface.
CartesianVertices->getPositions()->getData()->nElements();
for(index_t i=0; i<nVertices; i++)
{
double fi = i/(nVertices-1.0);
(*SurfaceColors)[ MIndex(i) ] = fi;
}
Colors =
new Field(SurfaceColors);
}
#endif
assert(Colors);
{
myVBO->append( newColorArray( colordata->myChunk() ));
}
{
RefPtr<MemBase> FieldData = Colors->getData();
{
}
else
FieldData = colordata;
RefPtr<BufferArray> TCA =
myVBO->append( TCA );
}
{
puts("TransparentColoredSurface::render() Apparently this is not called!?!?");
RefPtr<MemBase> FieldData = Colors->getData();
{
}
else
FieldData = colordata;
RefPtr<BufferArray> TCA =
myVBO->append( TCA );
}
else
{
puts("TransparentColoredSurface::render() Apparently this IS called!?!?");
myState->ErrorMessage = "Color field has unsupported type "
+ ", only RGB or double supported";
return false;
}
RefPtr<TriangleRenderer> TR = new TriangleRenderer(myState->getCoords(), myState->CellField->getData() );
TR->CurrentIBO = TR->sortByDepth(
Context, BaryCenters, ViewCacheSize );
myVBO->setRenderer( TR );
myVBO->call();
return true;
}
struct GridInspector
{
{
}
};
}
An internal class that stores a couple of textual names.
Definition FieldSelector.hpp:18
A Field is a collection of CreativeArrayBase reference pointers which are accessed via FragmentID obj...
Definition Field.hpp:245
Context information to select a grid from within a bundle.
Definition GridSelector.hpp:26
A concrete Grid Property which looks for the existence of a Skeleton of the specified dimension and i...
Definition BundleProperty.hpp:76
An intermediate class that allows to operate on the pure type information of some memory array.
Definition TypedArray.hpp:58
const Ageable & age(const RefPtr< ValuePool > &Context) const
Base class for objects rendering skeletons of a fiber bundle.
Definition VSkeletonRenderObject.hpp:21
MEMCORE_API std::string Typename(const std::type_info &t)
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::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])
Class for ranges of types, such as minimum/maximum.
Definition Range.hpp:379
Definition fs/init.hpp:20
A helper class to retrieve fields given on a Grid.
Definition GridField.hpp:19
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
static SkeletonID ID()
2D objects of index depth 1 .
Definition TriangularSurface.hpp:131
RefPtr< Field > CoordField
Field for the vertex coordinates.
Definition TriangularSurface.hpp:59
RefPtr< Representation > CartesianVertices
Collection of all fields given on vertices relative to cartesian coordinates.
Definition TriangularSurface.hpp:69
Templated static member function to load data from MemArrays into vertex arrays.
Definition FieldBuffer.hpp:38
Definition PartialElementRenderer.hpp:56
static bool Enable(const RefPtr< Colormap > &Cmap, const RefPtr< GLTexture1D > &CmapTexture, const bool clampP, bool Discrete)