Graphics Reference
In-Depth Information
levels should be. This would be especially useful in computer aided design
and scientific data visualization, where smooth surfaces should stay smooth
no mater how much you zoom in on them.
#version 400 compatibility
#extension GL_ARB_tessellation_shader : enable
in vec3 vCenter[ ];
in float vRadius[ ];
patch out vec3 tcCenter;
patch out float tcRadius;
uniform float uDetail;
layout( vertices = 1 ) out;
void main( )
{
tcCenter = vCenter[ 0 ];
tcRadius = vRadius[ 0 ];
// get the extreme points of the sphere:
vec4 mx = vec4( vCenter[0] - vec3( vRadius[0], 0., 0. ), 1. );
vec4 px = vec4( vCenter[0] + vec3( vRadius[0], 0., 0. ), 1. );
vec4 my = vec4( vCenter[0] - vec3( 0., vRadius[0], 0. ), 1. );
vec4 py = vec4( vCenter[0] + vec3( 0., vRadius[0], 0. ), 1. );
vec4 mz = vec4( vCenter[0] - vec3( 0., 0., vRadius[0] ), 1. );
vec4 pz = vec4( vCenter[0] + vec3( 0., 0., vRadius[0] ), 1. );
// get the extreme points in clip space:
mx = uModelViewProjectionMatrix * mx;
px = uModelViewProjectionMatrix * px;
my = uModelViewProjectionMatrix * my;
py = uModelViewProjectionMatrix * py;
mz = uModelViewProjectionMatrix * mz;
pz = uModelViewProjectionMatrix * pz;
// get the extreme points in NDC space:
mx.xy /= mx.w;
px.xy /= px.w;
my.xy /= my.w;
py.xy /= py.w;
mz.xy /= mz.w;
pz.xy /= pz.w;
// how much NDC do the extreme points subtend?
float dx = distance( mx.xy, px.xy );
float dy = distance( my.xy, py.xy );
float dz = distance( mz.xy, pz.xy );
float dmax = sqrt( dx*dx + dy*dy + dz*dz );
Search WWH ::




Custom Search