Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes

Wizt::SplatRenderObject Class Reference
[The Fish Eye Retina - Fiber Bundle to OpenGL Gateway via Vish API]

Base class for render object that draw a splat for each vertex of a Grid object. More...

#include <SplatRenderObject.hpp>

List of all members.

Classes

Public Member Functions

Static Public Member Functions

Public Attributes

Static Public Attributes


Detailed Description

Base class for render object that draw a splat for each vertex of a Grid object.

Subclasses may define the way how such splats are drawn, and parameterize them based on the given input fields.

Todo:
Derive from class Programmable instead of doing same stuff here manually. Code is currently messy with VGLRenderContext and VRenderContext mixed.
Author:
Werner Benger

Constructor & Destructor Documentation

Wizt::SplatRenderObject::SplatRenderObject ( const string &  name,
int  p,
const RefPtr< VCreationPreferences > &  VP,
double  SizeScale = 5.0,
int  AnimationVisibility = 5 
)

Constructor.

Parameters:
AnimationVisibility The expert level of the AnimationSpeed parameter. It sets an uniform float "fractime" in the shader program to cycle between 0.0 and 1.0 in a certain speed. If the AnimationSpeed is larger than 0.0, then the rendering will auto-update.

Member Function Documentation

RefPtr< VBO::Renderer > Wizt::SplatRenderObject::createRenderer ( VGLRenderContext Context,
const RefPtr< MemBase > &  FieldCoordinates,
const RefPtr< FragmentSelector > &  FS 
) const [virtual]

Render function: create a renderer object.

Overrides virtual function from FragmentPainter .

Reimplemented from Wizt::FragmentPainter.

void Wizt::SplatRenderObject::render ( VGLRenderContext Context  )  const [virtual]

Creates an OpenGL Shader, and finally calls renderFragments().

If a file Name().vert or Name().frag exists, then the GLGS source code within these files will be loaded instead of the intrinsic code.

Reimplemented from Wizt::VertexRenderObject.

const char * Wizt::SplatRenderObject::setPointAttenuation (  )  [static]

A vertex shader fragment defining a function that will set the gl_PointSize to some value suitable for splats that get smaller in distance.

Also it will let them fade out once too small. Add this code to the prefix of some vertex shader.

void main(void)
{
        gl_FrontColor.rgb = vec3(0.5,0.5,0.3);
        gl_Position = ftransform();

        gl_FrontColor.a = setPointAttenuation();
 }

This function will return the following GLGS code:

uniform float size;

float setPointAttenuation()
{
vec4 eyeCoord = gl_ModelViewMatrix * gl_Vertex;
float dist = distance(eyeCoord, vec4(0.0, 0.0, 0.0, 1.0));
float att = 1.0/dist;
float diameter = clamp(size* att, 0.0,100.0);

float   fadeThreshold = 1.0;
float   fadePower = 1.5;
        gl_PointSize = max(diameter, fadeThreshold);
float   fade = min(diameter, fadeThreshold)/fadeThreshold;
        return pow(fade, fadePower)
}
void Wizt::SplatRenderObject::setRendererParameters ( VGLRenderContext Context,
const RefPtr< VBO::Renderer > &  theRenderer,
const RefPtr< CreativeArrayBase > &  VertexCoordinates,
const RefPtr< GLProgram > &  theShaderProgram 
) const [virtual]

Update a renderer object, in case the fragment selector is newer.

Render function: set parameters in the renderer that don't need re-creation of the VBO

Reimplemented from Wizt::FragmentPainter.

void Wizt::SplatRenderObject::setShaderVariables ( VGLRenderContext Context,
const RefPtr< GLProgram > &  ShaderProgram 
) const [virtual]

Virtual function to set variables in the shader program, such as parameters from the Vish inputs.

Typical code might just assign slots to uniform variables:

           struct       MySplatter : SplatRenderObject
           {
                TypedSlot<double>   Value;

                MySplatter(...)
                : SplatRenderObject(...)
                , Value(this, "value", 0.23)
                {}

                override string vertex_shader(VRenderContext&Context) const
                {
                        return "uniform float value; ....";
                }

                override void setShaderVariables(VRenderContext&Context, const RefPtr<Program>&ShaderProgram) const
                {
                        Value << Context > ShaderProgram;
                }
           };

Note that the name of the slot must be equal to the name of the uniform variable in the shader program for this to work. If the names don't match, then an OpenGL error exception will be thrown.

Reimplemented in VectorViz::VectorSpeckle.


Member Data Documentation

Default fragment shader code, must derive from to get this 2D texture.

           uniform sampler2D PSFTexture;
           void main (void)
           {
           vec4 psf  = texture2D( PSFTexture, gl_TexCoord[0].st);
           gl_FragColor = psf*gl_Color;
           }

When creating the shader program, do

And in function setRendererParameters() call

const char Wizt::SplatRenderObject::default_vertex_shader = " }\n" [static]

Default vertex shader code that sets point size and transparency attenuation for very small points.

To make use of this functionality, the code returned by setPointAttenuation() must be included in the code provided by an implementation of this function, and the setPointAttenuation() function needs to be called in the vertex shader. Its return value is a transparency factor that is supposed to be used to attenuate the alpha value of the given colors. The default main function as returned by the vertex_shader function is

void main(void)
{
        gl_FrontColor.rgb = vec3(0.5,0.5,0.3);
        gl_Position = ftransform();
        gl_FrontColor.a = setPointAttenuation();
}