refactoring

This commit is contained in:
mschuetz 2015-05-23 16:07:47 +02:00
parent bd1c9a8110
commit 49418f5a49
10 changed files with 370 additions and 155 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -217,7 +217,6 @@ Potree.Shaders["pointcloud.vs"] = [
" vOpacity = opacity;",
" vLinearDepth = -mvPosition.z;",
" vDepth = mvPosition.z / gl_Position.w;",
" vNormal = (modelMatrix * vec4(normal, 0.0)).xyz;",
" vNormal = normalMatrix * normal;",
"",
"",
@ -264,9 +263,9 @@ Potree.Shaders["pointcloud.vs"] = [
" vColor = color;",
" #endif",
" ",
" if(vNormal.z < 0.0){",
" gl_Position = vec4(1000.0, 1000.0, 1000.0, 1.0);",
" }",
" //if(vNormal.z < 0.0){",
" // gl_Position = vec4(1000.0, 1000.0, 1000.0, 1.0);",
" //}",
" ",
" // ---------------------",
" // POINT SIZE",
@ -342,27 +341,48 @@ Potree.Shaders["pointcloud.fs"] = [
"// uniform vec3 cameraPosition;",
"",
"",
"",
"uniform mat4 projectionMatrix;",
"",
"uniform vec3 diffuse;",
"uniform float opacity;",
"uniform vec3 ambient;",
"uniform vec3 emissive;",
"uniform vec3 specular;",
"uniform float shininess;",
"",
"uniform vec3 ambientLightColor;",
"",
"#if MAX_POINT_LIGHTS > 0",
"#if defined(color_type_phong)",
"",
" uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];",
" uniform vec3 diffuse;",
" uniform vec3 ambient;",
" uniform vec3 emissive;",
" uniform vec3 specular;",
" uniform float shininess;",
" uniform vec3 ambientLightColor;",
"",
" uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];",
" uniform float pointLightDistance[ MAX_POINT_LIGHTS ];",
" #if MAX_POINT_LIGHTS > 0",
"",
" uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];",
" uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];",
" uniform float pointLightDistance[ MAX_POINT_LIGHTS ];",
"",
" #endif",
"",
" #if MAX_DIR_LIGHTS > 0",
"",
" uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];",
" uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];",
"",
" #endif",
"",
"#endif",
"",
"//#if MAX_SPOT_LIGHTS > 0",
"//",
"// uniform vec3 spotLightColor[ MAX_SPOT_LIGHTS ];",
"// uniform vec3 spotLightPosition[ MAX_SPOT_LIGHTS ];",
"// uniform vec3 spotLightDirection[ MAX_SPOT_LIGHTS ];",
"// uniform float spotLightAngleCos[ MAX_SPOT_LIGHTS ];",
"// uniform float spotLightExponent[ MAX_SPOT_LIGHTS ];",
"//",
"// uniform float spotLightDistance[ MAX_SPOT_LIGHTS ];",
"//",
"//#endif",
"",
"uniform float fov;",
"uniform float spacing;",
"uniform float near;",
@ -429,62 +449,106 @@ Potree.Shaders["pointcloud.fs"] = [
" #endif",
" ",
" vec3 normal = normalize( vNormal );",
" normal.z = abs(normal.z);",
" vec3 viewPosition = normalize( vViewPosition );",
" ",
" #if defined(color_type_phong)",
"",
" // code taken from three.js phong light fragment shader",
" ",
" #if defined MAX_POINT_LIGHTS > 0",
" #if MAX_POINT_LIGHTS > 0",
"",
" vec3 pointDiffuse = vec3( 0.0 );",
" vec3 pointSpecular = vec3( 0.0 );",
" vec3 pointDiffuse = vec3( 0.0 );",
" vec3 pointSpecular = vec3( 0.0 );",
"",
" for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {",
" for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {",
"",
" vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );",
" vec3 lVector = lPosition.xyz + vViewPosition.xyz;",
" vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );",
" vec3 lVector = lPosition.xyz + vViewPosition.xyz;",
"",
" float lDistance = 1.0;",
" if ( pointLightDistance[ i ] > 0.0 )",
" lDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );",
" float lDistance = 1.0;",
" if ( pointLightDistance[ i ] > 0.0 )",
" lDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );",
"",
" lVector = normalize( lVector );",
" lVector = normalize( lVector );",
"",
" // diffuse",
" // diffuse",
"",
" float dotProduct = dot( normal, lVector );",
" float dotProduct = dot( normal, lVector );",
"",
" #ifdef WRAP_AROUND",
" #ifdef WRAP_AROUND",
"",
" float pointDiffuseWeightFull = max( dotProduct, 0.0 );",
" float pointDiffuseWeightHalf = max( 0.5 * dotProduct + 0.5, 0.0 );",
" float pointDiffuseWeightFull = max( dotProduct, 0.0 );",
" float pointDiffuseWeightHalf = max( 0.5 * dotProduct + 0.5, 0.0 );",
"",
" vec3 pointDiffuseWeight = mix( vec3( pointDiffuseWeightFull ), vec3( pointDiffuseWeightHalf ), wrapRGB );",
" vec3 pointDiffuseWeight = mix( vec3( pointDiffuseWeightFull ), vec3( pointDiffuseWeightHalf ), wrapRGB );",
"",
" #else",
" #else",
"",
" float pointDiffuseWeight = max( dotProduct, 0.0 );",
" float pointDiffuseWeight = max( dotProduct, 0.0 );",
"",
" #endif",
" #endif",
"",
" pointDiffuse += diffuse * pointLightColor[ i ] * pointDiffuseWeight * lDistance;",
" pointDiffuse += diffuse * pointLightColor[ i ] * pointDiffuseWeight * lDistance;",
"",
" // specular",
" // specular",
"",
" vec3 pointHalfVector = normalize( lVector + viewPosition );",
" float pointDotNormalHalf = max( dot( normal, pointHalfVector ), 0.0 );",
" float pointSpecularWeight = specularStrength * max( pow( pointDotNormalHalf, shininess ), 0.0 );",
" vec3 pointHalfVector = normalize( lVector + viewPosition );",
" float pointDotNormalHalf = max( dot( normal, pointHalfVector ), 0.0 );",
" float pointSpecularWeight = specularStrength * max( pow( pointDotNormalHalf, shininess ), 0.0 );",
"",
" float specularNormalization = ( shininess + 2.0 ) / 8.0;",
" float specularNormalization = ( shininess + 2.0 ) / 8.0;",
"",
" vec3 schlick = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( lVector, pointHalfVector ), 0.0 ), 5.0 );",
" pointSpecular += schlick * pointLightColor[ i ] * pointSpecularWeight * pointDiffuseWeight * lDistance * specularNormalization;",
" pointSpecular = vec3(0.0, 0.0, 0.0);",
" }",
" vec3 schlick = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( lVector, pointHalfVector ), 0.0 ), 5.0 );",
" pointSpecular += schlick * pointLightColor[ i ] * pointSpecularWeight * pointDiffuseWeight * lDistance * specularNormalization;",
" pointSpecular = vec3(0.0, 0.0, 0.0);",
" }",
" ",
" #endif",
" ",
" #if MAX_DIR_LIGHTS > 0",
"",
" vec3 dirDiffuse = vec3( 0.0 );",
" vec3 dirSpecular = vec3( 0.0 );",
"",
" for( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {",
"",
" vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );",
" vec3 dirVector = normalize( lDirection.xyz );",
"",
" // diffuse",
"",
" float dotProduct = dot( normal, dirVector );",
"",
" #ifdef WRAP_AROUND",
"",
" float dirDiffuseWeightFull = max( dotProduct, 0.0 );",
" float dirDiffuseWeightHalf = max( 0.5 * dotProduct + 0.5, 0.0 );",
"",
" vec3 dirDiffuseWeight = mix( vec3( dirDiffuseWeightFull ), vec3( dirDiffuseWeightHalf ), wrapRGB );",
"",
" #else",
"",
" float dirDiffuseWeight = max( dotProduct, 0.0 );",
"",
" #endif",
"",
" dirDiffuse += diffuse * directionalLightColor[ i ] * dirDiffuseWeight;",
"",
" // specular",
"",
" vec3 dirHalfVector = normalize( dirVector + viewPosition );",
" float dirDotNormalHalf = max( dot( normal, dirHalfVector ), 0.0 );",
" float dirSpecularWeight = specularStrength * max( pow( dirDotNormalHalf, shininess ), 0.0 );",
"",
" float specularNormalization = ( shininess + 2.0 ) / 8.0;",
"",
" vec3 schlick = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( dirVector, dirHalfVector ), 0.0 ), 5.0 );",
" dirSpecular += schlick * directionalLightColor[ i ] * dirSpecularWeight * dirDiffuseWeight * specularNormalization;",
" }",
"",
" #endif",
" ",
" vec3 totalDiffuse = vec3( 0.0 );",
" vec3 totalSpecular = vec3( 0.0 );",
" ",
@ -495,6 +559,13 @@ Potree.Shaders["pointcloud.fs"] = [
"",
" #endif",
" ",
" #if MAX_DIR_LIGHTS > 0",
"",
" totalDiffuse += dirDiffuse;",
" totalSpecular += dirSpecular;",
"",
" #endif",
" ",
" gl_FragColor.xyz = gl_FragColor.xyz * ( emissive + totalDiffuse + ambientLightColor * ambient ) + totalSpecular;",
"",
" #endif",

File diff suppressed because one or more lines are too long

View File

@ -76,7 +76,7 @@ Potree.BinaryLoader.prototype.parse = function(node, buffer){
geometry.addAttribute("intensity", new THREE.BufferAttribute(new Float32Array(buffer), 1));
}else if(parseInt(property) === PointAttributeNames.CLASSIFICATION){
geometry.addAttribute("classification", new THREE.BufferAttribute(new Float32Array(buffer), 1));
}else if(parseInt(property) === PointAttributeNames.NORMAL){
}else if(parseInt(property) === PointAttributeNames.NORMAL_SPHEREMAPPED){
geometry.addAttribute("normal", new THREE.BufferAttribute(new Float32Array(buffer), 3));
}
}

View File

@ -15,7 +15,7 @@ PointAttributeNames.NORMAL_FLOATS = 4; // float x, y, z;
PointAttributeNames.FILLER = 5;
PointAttributeNames.INTENSITY = 6;
PointAttributeNames.CLASSIFICATION = 7;
PointAttributeNames.NORMAL = 8;
PointAttributeNames.NORMAL_SPHEREMAPPED = 8;
/**
* Some types of possible point attribute data formats
@ -87,8 +87,8 @@ PointAttribute.CLASSIFICATION = new PointAttribute(
PointAttributeNames.CLASSIFICATION,
PointAttributeTypes.DATA_TYPE_UINT8, 1);
PointAttribute.NORMAL = new PointAttribute(
PointAttributeNames.NORMAL,
PointAttribute.NORMAL_SPHEREMAPPED = new PointAttribute(
PointAttributeNames.NORMAL_SPHEREMAPPED,
PointAttributeTypes.DATA_TYPE_UINT8, 2);
/**
@ -140,7 +140,7 @@ PointAttributes.prototype.hasColors = function(){
PointAttributes.prototype.hasNormals = function(){
for(var name in this.attributes){
var pointAttribute = this.attributes[name];
if(pointAttribute === PointAttribute.NORMAL_FLOATS){
if(pointAttribute === PointAttribute.NORMAL_SPHEREMAPPED || pointAttribute === PointAttribute.NORMAL_FLOATS){
return true;
}
}

View File

@ -142,7 +142,8 @@ Potree.PointCloudMaterial = function(parameters){
blendDepth: { type: "f", value: this._blendDepth },
depthMap: { type: "t", value: null },
diffuse: { type: "fv", value: [1,1,1]},
ambientLightColor: { type: "fv", value: null },
ambient: { type: "fv", value: [0.1, 0.1, 0.1]},
ambientLightColor: { type: "fv", value: [1, 1, 1] },
directionalLightColor: { type: "fv", value: null },
directionalLightDirection: { type: "fv", value: null },
pointLightColor: { type: "fv", value: null },

View File

@ -13,27 +13,48 @@
// uniform vec3 cameraPosition;
uniform mat4 projectionMatrix;
uniform vec3 diffuse;
uniform float opacity;
uniform vec3 ambient;
uniform vec3 emissive;
uniform vec3 specular;
uniform float shininess;
uniform vec3 ambientLightColor;
#if MAX_POINT_LIGHTS > 0
#if defined(color_type_phong)
uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];
uniform vec3 diffuse;
uniform vec3 ambient;
uniform vec3 emissive;
uniform vec3 specular;
uniform float shininess;
uniform vec3 ambientLightColor;
uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];
uniform float pointLightDistance[ MAX_POINT_LIGHTS ];
#if MAX_POINT_LIGHTS > 0
uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];
uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];
uniform float pointLightDistance[ MAX_POINT_LIGHTS ];
#endif
#if MAX_DIR_LIGHTS > 0
uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];
uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];
#endif
#endif
//#if MAX_SPOT_LIGHTS > 0
//
// uniform vec3 spotLightColor[ MAX_SPOT_LIGHTS ];
// uniform vec3 spotLightPosition[ MAX_SPOT_LIGHTS ];
// uniform vec3 spotLightDirection[ MAX_SPOT_LIGHTS ];
// uniform float spotLightAngleCos[ MAX_SPOT_LIGHTS ];
// uniform float spotLightExponent[ MAX_SPOT_LIGHTS ];
//
// uniform float spotLightDistance[ MAX_SPOT_LIGHTS ];
//
//#endif
uniform float fov;
uniform float spacing;
uniform float near;
@ -100,62 +121,106 @@ void main() {
#endif
vec3 normal = normalize( vNormal );
normal.z = abs(normal.z);
vec3 viewPosition = normalize( vViewPosition );
#if defined(color_type_phong)
// code taken from three.js phong light fragment shader
#if defined MAX_POINT_LIGHTS > 0
#if MAX_POINT_LIGHTS > 0
vec3 pointDiffuse = vec3( 0.0 );
vec3 pointSpecular = vec3( 0.0 );
vec3 pointDiffuse = vec3( 0.0 );
vec3 pointSpecular = vec3( 0.0 );
for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {
for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {
vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );
vec3 lVector = lPosition.xyz + vViewPosition.xyz;
vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );
vec3 lVector = lPosition.xyz + vViewPosition.xyz;
float lDistance = 1.0;
if ( pointLightDistance[ i ] > 0.0 )
lDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );
float lDistance = 1.0;
if ( pointLightDistance[ i ] > 0.0 )
lDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );
lVector = normalize( lVector );
lVector = normalize( lVector );
// diffuse
// diffuse
float dotProduct = dot( normal, lVector );
float dotProduct = dot( normal, lVector );
#ifdef WRAP_AROUND
#ifdef WRAP_AROUND
float pointDiffuseWeightFull = max( dotProduct, 0.0 );
float pointDiffuseWeightHalf = max( 0.5 * dotProduct + 0.5, 0.0 );
float pointDiffuseWeightFull = max( dotProduct, 0.0 );
float pointDiffuseWeightHalf = max( 0.5 * dotProduct + 0.5, 0.0 );
vec3 pointDiffuseWeight = mix( vec3( pointDiffuseWeightFull ), vec3( pointDiffuseWeightHalf ), wrapRGB );
vec3 pointDiffuseWeight = mix( vec3( pointDiffuseWeightFull ), vec3( pointDiffuseWeightHalf ), wrapRGB );
#else
#else
float pointDiffuseWeight = max( dotProduct, 0.0 );
float pointDiffuseWeight = max( dotProduct, 0.0 );
#endif
#endif
pointDiffuse += diffuse * pointLightColor[ i ] * pointDiffuseWeight * lDistance;
pointDiffuse += diffuse * pointLightColor[ i ] * pointDiffuseWeight * lDistance;
// specular
// specular
vec3 pointHalfVector = normalize( lVector + viewPosition );
float pointDotNormalHalf = max( dot( normal, pointHalfVector ), 0.0 );
float pointSpecularWeight = specularStrength * max( pow( pointDotNormalHalf, shininess ), 0.0 );
vec3 pointHalfVector = normalize( lVector + viewPosition );
float pointDotNormalHalf = max( dot( normal, pointHalfVector ), 0.0 );
float pointSpecularWeight = specularStrength * max( pow( pointDotNormalHalf, shininess ), 0.0 );
float specularNormalization = ( shininess + 2.0 ) / 8.0;
float specularNormalization = ( shininess + 2.0 ) / 8.0;
vec3 schlick = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( lVector, pointHalfVector ), 0.0 ), 5.0 );
pointSpecular += schlick * pointLightColor[ i ] * pointSpecularWeight * pointDiffuseWeight * lDistance * specularNormalization;
pointSpecular = vec3(0.0, 0.0, 0.0);
}
vec3 schlick = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( lVector, pointHalfVector ), 0.0 ), 5.0 );
pointSpecular += schlick * pointLightColor[ i ] * pointSpecularWeight * pointDiffuseWeight * lDistance * specularNormalization;
pointSpecular = vec3(0.0, 0.0, 0.0);
}
#endif
#if MAX_DIR_LIGHTS > 0
vec3 dirDiffuse = vec3( 0.0 );
vec3 dirSpecular = vec3( 0.0 );
for( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {
vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );
vec3 dirVector = normalize( lDirection.xyz );
// diffuse
float dotProduct = dot( normal, dirVector );
#ifdef WRAP_AROUND
float dirDiffuseWeightFull = max( dotProduct, 0.0 );
float dirDiffuseWeightHalf = max( 0.5 * dotProduct + 0.5, 0.0 );
vec3 dirDiffuseWeight = mix( vec3( dirDiffuseWeightFull ), vec3( dirDiffuseWeightHalf ), wrapRGB );
#else
float dirDiffuseWeight = max( dotProduct, 0.0 );
#endif
dirDiffuse += diffuse * directionalLightColor[ i ] * dirDiffuseWeight;
// specular
vec3 dirHalfVector = normalize( dirVector + viewPosition );
float dirDotNormalHalf = max( dot( normal, dirHalfVector ), 0.0 );
float dirSpecularWeight = specularStrength * max( pow( dirDotNormalHalf, shininess ), 0.0 );
float specularNormalization = ( shininess + 2.0 ) / 8.0;
vec3 schlick = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( dirVector, dirHalfVector ), 0.0 ), 5.0 );
dirSpecular += schlick * directionalLightColor[ i ] * dirSpecularWeight * dirDiffuseWeight * specularNormalization;
}
#endif
vec3 totalDiffuse = vec3( 0.0 );
vec3 totalSpecular = vec3( 0.0 );
@ -166,6 +231,13 @@ void main() {
#endif
#if MAX_DIR_LIGHTS > 0
totalDiffuse += dirDiffuse;
totalSpecular += dirSpecular;
#endif
gl_FragColor.xyz = gl_FragColor.xyz * ( emissive + totalDiffuse + ambientLightColor * ambient ) + totalSpecular;
#endif

View File

@ -216,7 +216,6 @@ void main() {
vOpacity = opacity;
vLinearDepth = -mvPosition.z;
vDepth = mvPosition.z / gl_Position.w;
vNormal = (modelMatrix * vec4(normal, 0.0)).xyz;
vNormal = normalMatrix * normal;
@ -263,9 +262,9 @@ void main() {
vColor = color;
#endif
if(vNormal.z < 0.0){
gl_Position = vec4(1000.0, 1000.0, 1000.0, 1.0);
}
//if(vNormal.z < 0.0){
// gl_Position = vec4(1000.0, 1000.0, 1000.0, 1.0);
//}
// ---------------------
// POINT SIZE

View File

@ -105,7 +105,7 @@ onmessage = function(event){
attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute};
}else if(pointAttribute.name === PointAttribute.NORMAL.name){
}else if(pointAttribute.name === PointAttribute.NORMAL_SPHEREMAPPED.name){
var buff = new ArrayBuffer(numPoints*4*3);
var normals = new Float32Array(buff);