Commit 142d3513 authored by Michele Bosi's avatar Michele Bosi

Vivid: GLSL shaders less dependent on "compatibility" GL profile.

parent 35b3d6c0
......@@ -41,7 +41,7 @@ vec4 LightingStage()
}
else
{
vec3 l = normalize( gl_LightSource[0].position.xyz - CP.xyz );
vec3 l = normalize( vl_Vivid.light.position.xyz - CP.xyz );
vec3 e = normalize( vec3( 0, 0, 0 ) - CP.xyz ); // vec3( 0.0, 0.0 ,1.0 ) for GL_LIGHT_MODEL_LOCAL_VIEWER = FALSE
vec3 n = normalize( N );
vec3 H = normalize( l + e );
......@@ -54,20 +54,20 @@ vec4 LightingStage()
n = n * -1;
}
vec3 diffuse = gl_FrontMaterial.diffuse.rgb * gl_LightSource[0].diffuse.rgb;
vec3 diffuse = vl_Vivid.material.diffuse.rgb * vl_Vivid.light.diffuse.rgb;
diffuse = diffuse * vec3( max( 0.0, NdotL ) );
float NdotH = max( 0.0, dot( n, H ) );
vec3 specular = vec3( 0.0 );
if ( NdotL > 0.0 ) {
specular = gl_FrontMaterial.specular.rgb * gl_LightSource[0].specular.rgb * pow( NdotH, gl_FrontMaterial.shininess );
specular = vl_Vivid.material.specular.rgb * vl_Vivid.light.specular.rgb * pow( NdotH, vl_Vivid.material.shininess );
}
vec3 ambient = gl_FrontMaterial.ambient.rgb * gl_LightSource[0].ambient.rgb + gl_FrontMaterial.ambient.rgb * gl_LightModel.ambient.rgb;
vec3 emission = gl_FrontMaterial.emission.rgb;
vec3 ambient = vl_Vivid.material.ambient.rgb * vl_Vivid.light.ambient.rgb + vl_Vivid.material.ambient.rgb * gl_LightModel.ambient.rgb;
vec3 emission = vl_Vivid.material.emission.rgb;
color.rgb = ambient + emission + diffuse + specular;
color.a = gl_FrontMaterial.diffuse.a;
color.a = vl_Vivid.material.diffuse.a;
}
if ( vl_Vivid.enablePointSprite ) {
......@@ -199,33 +199,33 @@ vec4 ClippingStage( vec4 color )
vec4 FogStage( vec4 color )
{
if ( vl_Vivid.smartFog.mode > 0 && color.a > 0 ) {
if ( vl_Vivid.fog.mode > 0 && color.a > 0 ) {
// Compute fog factor
float dist = length( CP.xyz );
float fog_factor = 0;
if ( vl_Vivid.smartFog.mode == 1 ) {
if ( vl_Vivid.fog.mode == 1 ) {
// Linear
fog_factor = ( gl_Fog.end - dist ) * gl_Fog.scale;
fog_factor = ( vl_Vivid.fog.end - dist ) * vl_Vivid.fog.scale;
} else
if ( vl_Vivid.smartFog.mode == 2 ) {
if ( vl_Vivid.fog.mode == 2 ) {
// Exp
fog_factor = 1.0 / exp( gl_Fog.density * dist );
fog_factor = 1.0 / exp( vl_Vivid.fog.density * dist );
} else
if ( vl_Vivid.smartFog.mode == 3 ) {
if ( vl_Vivid.fog.mode == 3 ) {
// Exp2
fog_factor = 1.0 / exp( ( gl_Fog.density * dist ) * ( gl_Fog.density * dist ) );
fog_factor = 1.0 / exp( ( vl_Vivid.fog.density * dist ) * ( vl_Vivid.fog.density * dist ) );
}
fog_factor = clamp( fog_factor, 0, 1.0 );
if (vl_Vivid.smartFog.target == 0) {
if (vl_Vivid.fog.target == 0) {
// Color
color.xyz = mix( gl_Fog.color.xyz, color.xyz, fog_factor );
color.xyz = mix( vl_Vivid.fog.color.xyz, color.xyz, fog_factor );
} else
if (vl_Vivid.smartFog.target == 1) {
if (vl_Vivid.fog.target == 1) {
// Transparency
color.a = color.a * fog_factor;
} else
if (vl_Vivid.smartFog.target == 2) {
if (vl_Vivid.fog.target == 2) {
// Saturation
color.xyz = AdjustSaturation( color.xyz, fog_factor );
}
......
......@@ -32,8 +32,27 @@ uniform sampler3D vl_UserTexture3D; // Always set to vl::VividRendering::UserTex
struct vl_SmartFogParameters {
int mode; // 0 = OFF, 1 = Linear, 2 = Exp, 3 = Exp2
int target; // 0 = Color, 1 = Alpha, 2 = Saturation
vec4 color;
float density;
float start;
float end;
};
struct vl_MaterialParameters {
vec4 diffuse;
vec4 specular;
vec4 ambient;
vec4 emission;
float shininess;
}
struct vl_LightParameters {
vec4 position;
vec4 diffuse;
vec4 specular;
vec4 ambient;
}
// Smart Clip Stage
const int VL_SMART_CLIP_SIZE = 4;
......@@ -52,7 +71,7 @@ struct vl_SmartClipParameters {
// Outline
struct OutlineParameters {
struct vl_OutlineParameters {
// <per-Shader>
// Clipping plane for Slice Outline mode in World Coordinates
vec4 slicePlane;
......@@ -132,10 +151,16 @@ struct vl_VividParameters {
vl_StencilParameters stencil;
// <automatic> / <per-Shader>
OutlineParameters outline;
vl_OutlineParameters outline;
// <per-shader>
vl_MaterialParameters material;
// <per-Shader>
vl_SmartFogParameters fog;
// <per-Shader>
vl_SmartFogParameters smartFog;
vl_LightParameters light;
// <per-Shader>
vl_SmartClipParameters smartClip[ VL_SMART_CLIP_SIZE ];
......
......@@ -55,10 +55,10 @@ VividRendering::VividRendering() {
mRenderingMode = Vivid::DepthPeeling;
mOpacity = 1.0f;
mOpacity = 1;
mOutline3DEyeOffset = 0.0f; // 0.25mm works well with VTK
mOutline3DClipOffset = 0.0f; // 0.0005 is more general but can create artifacts
mOutline3DEyeOffset = 0; // 0.25mm works well with VTK
mOutline3DClipOffset = 0; // 0.0005 is more general but can create artifacts
mBackgroundImageEnabled = false;
......@@ -90,13 +90,32 @@ ref<Effect> VividRendering::makeVividEffect(Effect* effect) {
// Here we set only the uniforms that are not marked as <automatic> in vivid-uniforms.glsl
ref<Effect> fx = effect == NULL ? new Effect() : effect;
fx->shader()->gocLineWidth();
fx->shader()->gocPointSize();
fx->shader()->gocPolygonMode();
fx->shader()->gocMaterial();
fx->shader()->gocFog();
fx->shader()->gocLightModel();
fx->shader()->setRenderState( new vl::Light, 0 );
// Material
fx->shader()->gocUniform( "vl_Vivid.material.diffuse" )->setUniform( fvec4(0.8f, 0.8f, 0.8f, 1) );
fx->shader()->gocUniform( "vl_Vivid.material.specular" )->setUniform( fvec4(0, 0, 0, 1) );
fx->shader()->gocUniform( "vl_Vivid.material.ambient" )->setUniform( fvec4(0.2f, 0.2f, 0.2f, 1) );
fx->shader()->gocUniform( "vl_Vivid.material.emission" )->setUniform( fvec4(0, 0, 0, 1) );
fx->shader()->gocUniform( "vl_Vivid.material.shininess" )->setUniformF( 128 );
// Fog
fx->shader()->gocUniform("vl_Vivid.smartFog.mode")->setUniformI( 0 ); // 0=Off, 1=Linear, 2=Exp, 3=Exp2
fx->shader()->gocUniform("vl_Vivid.smartFog.target")->setUniformI( 0 ); // 0=Color, 1=Alpha, 2=Saturation
fx->shader()->gocUniform("vl_Vivid.smartFog.start")->setUniformF( 0 );
fx->shader()->gocUniform("vl_Vivid.smartFog.end")->setUniformF( 1 );
fx->shader()->gocUniform("vl_Vivid.smartFog.density")->setUniformF( 1 );
fx->shader()->gocUniform("vl_Vivid.smartFog.color")->setUniform( vl::black );
// Light
fx->shader()->gocUniform( "vl_Vivid.light.diffuse" )->setUniform( fvec4(1, 1, 1, 1) );
fx->shader()->gocUniform( "vl_Vivid.light.specular" )->setUniform( fvec4(1, 1, 1, 1) );
fx->shader()->gocUniform( "vl_Vivid.light.ambient" )->setUniform( fvec4(0, 0, 0, 1) );
fx->shader()->gocUniform( "vl_Vivid.light.position" )->setUniform( fvec4(0, 0, 0, 1) );
fx->shader()->gocUniform( "vl_Vivid.enableLighting" )->setUniformI( 1 );
fx->shader()->gocUniform( "vl_Vivid.enablePointSprite" )->setUniformI( 0 );
......@@ -106,10 +125,6 @@ ref<Effect> VividRendering::makeVividEffect(Effect* effect) {
fx->shader()->gocUniform("vl_Vivid.outline.width")->setUniformF( 2.0f );
fx->shader()->gocUniform("vl_Vivid.outline.slicePlane")->setUniform( vl::vec4( 1, 0, 0, 0 ) );
// Smart Fog: all the other settings are taken from the standard Fog object
fx->shader()->gocUniform("vl_Vivid.smartFog.mode")->setUniformI( 0 ); // 0=Off, 1=Linear, 2=Exp, 3=Exp2
fx->shader()->gocUniform("vl_Vivid.smartFog.target")->setUniformI( 0 ); // 0=Color, 1=Alpha, 2=Saturation
// Smart Clipping
for( char i = '0'; i < '4'; ++i ) {
fx->shader()->gocUniform((std::string("vl_Vivid.smartClip[") + i + "].mode").c_str())->setUniformI( 0 ); // 0=OFF, 1=Sphere, 2=Box, 3=Plane
......@@ -143,11 +158,14 @@ ref<Effect> VividRendering::makeVividEffect(Effect* effect) {
fx->shader()->enable( vl::EN_DEPTH_TEST );
fx->shader()->enable( vl::EN_LIGHTING );
fx->shader()->setRenderState( new vl::Light, 0 );
fx->shader()->gocMaterial()->setColorMaterialEnabled( false );
fx->shader()->gocMaterial()->setColorMaterial( vl::PF_FRONT_AND_BACK, vl::CM_DIFFUSE );
fx->shader()->gocLightModel()->setTwoSide( true );
fx->shader()->gocLightModel()->setLocalViewer( true );
fx->shader()->gocDepthMask()->set( true );
return fx;
......
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