refactoring

This commit is contained in:
mschuetz 2015-11-05 17:45:25 +01:00
parent cef148ad95
commit 4add21817e
6 changed files with 28 additions and 57 deletions

View File

@ -481,6 +481,8 @@ Potree.Shaders["pointcloud.fs"] = [
"//",
"//#endif",
"",
"uniform float blendHardness;",
"uniform float blendDepthSupplement;",
"uniform float fov;",
"uniform float spacing;",
"uniform float near;",
@ -522,7 +524,7 @@ Potree.Shaders["pointcloud.fs"] = [
" #if defined weighted_splats",
" vec2 uv = gl_FragCoord.xy / vec2(screenWidth, screenHeight);",
" float sDepth = texture2D(depthMap, uv).r;",
" if(vLinearDepth > sDepth + vRadius){",
" if(vLinearDepth > sDepth + vRadius + blendDepthSupplement){",
" discard;",
" }",
" #endif",
@ -552,7 +554,7 @@ Potree.Shaders["pointcloud.fs"] = [
" #endif",
" ",
" #if defined weighted_splats",
" float w = pow(1.0 - (u*u + v*v), 2.0);",
" float w = pow(1.0 - (u*u + v*v), blendHardness);",
" gl_FragColor.rgb = gl_FragColor.rgb * w;",
" gl_FragColor.a = w;",
" #endif",
@ -774,13 +776,6 @@ Potree.Shaders["edl.fs"] = [
" return 1.0 - (linearDepth - near) / (far - near);",
"}",
"",
"float expToLinear(float z){",
" z = 2.0 * z - 1.0;",
" float linear = (2.0 * near * far) / (far + near - z * (far - near));",
"",
" return linear;",
"}",
"",
"// this actually only returns linear depth values if LOG_BIAS is 1.0",
"// lower values work out more nicely, though.",
"#define LOG_BIAS 0.01",
@ -788,12 +783,7 @@ Potree.Shaders["edl.fs"] = [
" return (pow((1.0 + LOG_BIAS * far), z) - 1.0) / LOG_BIAS;",
"}",
"",
"float obscurance(float z, float dist){",
" return max(0.0, z) / dist;",
"}",
"",
"float computeObscurance(float linearDepth){",
" vec4 P = vec4(0, 0, 1, -ztransform(linearDepth));",
" vec2 uvRadius = radius / vec2(screenWidth, screenHeight);",
" ",
" float sum = 0.0;",
@ -805,10 +795,9 @@ Potree.Shaders["edl.fs"] = [
" float neighbourDepth = logToLinear(texture2D(colorMap, N_abs_pos).a);",
" ",
" if(neighbourDepth != 0.0){",
" float Zn = ztransform(neighbourDepth);",
" float Znp = dot( vec4( N_rel_pos, Zn, 1.0), P );",
" float Znp = ztransform(neighbourDepth) - ztransform(linearDepth);",
" ",
" sum += obscurance( Znp, 0.05 * linearDepth );",
" sum += max(0.0, Znp) / (0.05 * linearDepth);",
" }",
" }",
" ",
@ -1803,6 +1792,8 @@ Potree.PointCloudMaterial = function(parameters){
var attributes = {};
var uniforms = {
spacing: { type: "f", value: 1.0 },
blendHardness: { type: "f", value: 2.0 },
blendDepthSupplement: { type: "f", value: 0.0 },
fov: { type: "f", value: 1.0 },
screenWidth: { type: "f", value: 1.0 },
screenHeight: { type: "f", value: 1.0 },

File diff suppressed because one or more lines are too long

View File

@ -419,6 +419,8 @@ Potree.Shaders["pointcloud.fs"] = [
"//",
"//#endif",
"",
"uniform float blendHardness;",
"uniform float blendDepthSupplement;",
"uniform float fov;",
"uniform float spacing;",
"uniform float near;",
@ -460,7 +462,7 @@ Potree.Shaders["pointcloud.fs"] = [
" #if defined weighted_splats",
" vec2 uv = gl_FragCoord.xy / vec2(screenWidth, screenHeight);",
" float sDepth = texture2D(depthMap, uv).r;",
" if(vLinearDepth > sDepth + vRadius){",
" if(vLinearDepth > sDepth + vRadius + blendDepthSupplement){",
" discard;",
" }",
" #endif",
@ -490,7 +492,7 @@ Potree.Shaders["pointcloud.fs"] = [
" #endif",
" ",
" #if defined weighted_splats",
" float w = pow(1.0 - (u*u + v*v), 2.0);",
" float w = pow(1.0 - (u*u + v*v), blendHardness);",
" gl_FragColor.rgb = gl_FragColor.rgb * w;",
" gl_FragColor.a = w;",
" #endif",
@ -712,13 +714,6 @@ Potree.Shaders["edl.fs"] = [
" return 1.0 - (linearDepth - near) / (far - near);",
"}",
"",
"float expToLinear(float z){",
" z = 2.0 * z - 1.0;",
" float linear = (2.0 * near * far) / (far + near - z * (far - near));",
"",
" return linear;",
"}",
"",
"// this actually only returns linear depth values if LOG_BIAS is 1.0",
"// lower values work out more nicely, though.",
"#define LOG_BIAS 0.01",
@ -726,12 +721,7 @@ Potree.Shaders["edl.fs"] = [
" return (pow((1.0 + LOG_BIAS * far), z) - 1.0) / LOG_BIAS;",
"}",
"",
"float obscurance(float z, float dist){",
" return max(0.0, z) / dist;",
"}",
"",
"float computeObscurance(float linearDepth){",
" vec4 P = vec4(0, 0, 1, -ztransform(linearDepth));",
" vec2 uvRadius = radius / vec2(screenWidth, screenHeight);",
" ",
" float sum = 0.0;",
@ -743,10 +733,9 @@ Potree.Shaders["edl.fs"] = [
" float neighbourDepth = logToLinear(texture2D(colorMap, N_abs_pos).a);",
" ",
" if(neighbourDepth != 0.0){",
" float Zn = ztransform(neighbourDepth);",
" float Znp = dot( vec4( N_rel_pos, Zn, 1.0), P );",
" float Znp = ztransform(neighbourDepth) - ztransform(linearDepth);",
" ",
" sum += obscurance( Znp, 0.05 * linearDepth );",
" sum += max(0.0, Znp) / (0.05 * linearDepth);",
" }",
" }",
" ",

View File

@ -118,6 +118,8 @@ Potree.PointCloudMaterial = function(parameters){
var attributes = {};
var uniforms = {
spacing: { type: "f", value: 1.0 },
blendHardness: { type: "f", value: 2.0 },
blendDepthSupplement: { type: "f", value: 0.0 },
fov: { type: "f", value: 1.0 },
screenWidth: { type: "f", value: 1.0 },
screenHeight: { type: "f", value: 1.0 },

View File

@ -31,13 +31,6 @@ float ztransform(float linearDepth){
return 1.0 - (linearDepth - near) / (far - near);
}
float expToLinear(float z){
z = 2.0 * z - 1.0;
float linear = (2.0 * near * far) / (far + near - z * (far - near));
return linear;
}
// this actually only returns linear depth values if LOG_BIAS is 1.0
// lower values work out more nicely, though.
#define LOG_BIAS 0.01
@ -45,12 +38,7 @@ float logToLinear(float z){
return (pow((1.0 + LOG_BIAS * far), z) - 1.0) / LOG_BIAS;
}
float obscurance(float z, float dist){
return max(0.0, z) / dist;
}
float computeObscurance(float linearDepth){
vec4 P = vec4(0, 0, 1, -ztransform(linearDepth));
vec2 uvRadius = radius / vec2(screenWidth, screenHeight);
float sum = 0.0;
@ -62,10 +50,9 @@ float computeObscurance(float linearDepth){
float neighbourDepth = logToLinear(texture2D(colorMap, N_abs_pos).a);
if(neighbourDepth != 0.0){
float Zn = ztransform(neighbourDepth);
float Znp = dot( vec4( N_rel_pos, Zn, 1.0), P );
float Znp = ztransform(neighbourDepth) - ztransform(linearDepth);
sum += obscurance( Znp, 0.05 * linearDepth );
sum += max(0.0, Znp) / (0.05 * linearDepth);
}
}

View File

@ -56,6 +56,8 @@ uniform float opacity;
//
//#endif
uniform float blendHardness;
uniform float blendDepthSupplement;
uniform float fov;
uniform float spacing;
uniform float near;
@ -97,7 +99,7 @@ void main() {
#if defined weighted_splats
vec2 uv = gl_FragCoord.xy / vec2(screenWidth, screenHeight);
float sDepth = texture2D(depthMap, uv).r;
if(vLinearDepth > sDepth + vRadius){
if(vLinearDepth > sDepth + vRadius + blendDepthSupplement){
discard;
}
#endif
@ -127,7 +129,7 @@ void main() {
#endif
#if defined weighted_splats
float w = pow(1.0 - (u*u + v*v), 2.0);
float w = pow(1.0 - (u*u + v*v), blendHardness);
gl_FragColor.rgb = gl_FragColor.rgb * w;
gl_FragColor.a = w;
#endif