Skip to content
Snippets Groups Projects
Verified Commit 9b7dd742 authored by Tobias Frisch's avatar Tobias Frisch
Browse files

[82] Value adjustments and fma replacements

parent 9aee8460
No related branches found
No related tags found
1 merge request!70Resolve "Voxel cone tracing"
...@@ -6,18 +6,18 @@ ...@@ -6,18 +6,18 @@
// nice math blob from the moment shadow mapping presentation // nice math blob from the moment shadow mapping presentation
float ComputeMSMShadowIntensity(vec4 _4Moments, float FragmentDepth, float DepthBias, float MomentBias) float ComputeMSMShadowIntensity(vec4 _4Moments, float FragmentDepth, float DepthBias, float MomentBias)
{ {
vec4 b=mix(_4Moments, vec4(0.5f,0.5f,0.5f,0.5f),MomentBias); vec4 b=mix(_4Moments, vec4(0.5),MomentBias);
vec3 z; vec3 z;
z[0]=FragmentDepth-DepthBias; z[0]=FragmentDepth-DepthBias;
float L32D22=-b[0] * b[1] + b[2]; float L32D22=fma(-b[0], b[1], b[2]);
float D22= -b[0] * b[0] + b[1]; float D22=fma(-b[0], b[0], b[1]);
float SquaredDepthVariance=-b[1]*b[1]+b[3]; float SquaredDepthVariance=fma(-b[1], b[1], b[3]);
float D33D22=dot(vec2(SquaredDepthVariance,-L32D22), float D33D22=dot(vec2(SquaredDepthVariance,-L32D22),
vec2(D22, L32D22)); vec2(D22, L32D22));
float InvD22=1.0f/D22; float InvD22=1.0/D22;
float L32=L32D22*InvD22; float L32=L32D22*InvD22;
vec3 c=vec3(1.0f,z[0],z[0]*z[0]); vec3 c=vec3(1.0,z[0],z[0]*z[0]);
c[1]-=b.x; c[1]-=b.x;
c[2]-=b.y+L32*c[1]; c[2]-=b.y+L32*c[1];
c[1]*=InvD22; c[1]*=InvD22;
...@@ -26,13 +26,13 @@ float ComputeMSMShadowIntensity(vec4 _4Moments, float FragmentDepth, float Depth ...@@ -26,13 +26,13 @@ float ComputeMSMShadowIntensity(vec4 _4Moments, float FragmentDepth, float Depth
c[0]-=dot(c.yz,b.xy); c[0]-=dot(c.yz,b.xy);
float p=c[1]/c[2]; float p=c[1]/c[2];
float q=c[0]/c[2]; float q=c[0]/c[2];
float r=sqrt((p*p*0.25f)-q); float r=sqrt((p*p*0.25)-q);
z[1]=-p*0.5f-r; z[1]=-p*0.5-r;
z[2]=-p*0.5f+r; z[2]=-p*0.5+r;
vec4 Switch= vec4 Switch=
(z[2]<z[0])?vec4(z[1],z[0],1.0f,1.0f):( (z[2]<z[0])?vec4(z[1],z[0],1.0,1.0):(
(z[1]<z[0])?vec4(z[0],z[1],0.0f,1.0f): (z[1]<z[0])?vec4(z[0],z[1],0.0,1.0):
vec4(0.0f,0.0f,0.0f,0.0f)); vec4(0.0));
float Quotient=(Switch[0]*z[2]-b[0]*(Switch[0]+z[2])+b[1]) float Quotient=(Switch[0]*z[2]-b[0]*(Switch[0]+z[2])+b[1])
/((z[2]-Switch[1])*(z[0]-z[1])); /((z[2]-Switch[1])*(z[0]-z[1]));
return clamp(Switch[2]+Switch[3]*Quotient, 0, 1); return clamp(Switch[2]+Switch[3]*Quotient, 0, 1);
...@@ -40,10 +40,10 @@ float ComputeMSMShadowIntensity(vec4 _4Moments, float FragmentDepth, float Depth ...@@ -40,10 +40,10 @@ float ComputeMSMShadowIntensity(vec4 _4Moments, float FragmentDepth, float Depth
vec4 quantizeMoments(vec4 moments){ vec4 quantizeMoments(vec4 moments){
mat4 T = mat4( mat4 T = mat4(
-2.07224649f, 13.7948857237f, 0.105877704f, 9.7924062118f, -2.07224649, 13.7948857237, 0.105877704, 9.7924062118,
32.23703778f, -59.4683975703f, -1.9077466311f, -33.7652110555f, 32.23703778, -59.4683975703, -1.9077466311, -33.7652110555,
-68.571074599f, 82.0359750338f, 9.3496555107f, 47.9456096605f, -68.571074599, 82.0359750338, 9.3496555107, 47.9456096605,
39.3703274134f, -35.364903257f, -6.6543490743f, -23.9728048165f); 39.3703274134, -35.364903257, -6.6543490743, -23.9728048165);
vec4 quantized = T * moments; vec4 quantized = T * moments;
quantized[0] += 0.0359558848; quantized[0] += 0.0359558848;
return quantized; return quantized;
...@@ -52,10 +52,10 @@ vec4 quantizeMoments(vec4 moments){ ...@@ -52,10 +52,10 @@ vec4 quantizeMoments(vec4 moments){
vec4 unquantizeMoments(vec4 moments){ vec4 unquantizeMoments(vec4 moments){
moments[0] -= 0.0359558848; moments[0] -= 0.0359558848;
mat4 T = mat4( mat4 T = mat4(
0.2227744146f, 0.1549679261f, 0.1451988946f, 0.163127443f, 0.2227744146, 0.1549679261, 0.1451988946, 0.163127443,
0.0771972861f, 0.1394629426f, 0.2120202157f, 0.2591432266f, 0.0771972861, 0.1394629426, 0.2120202157, 0.2591432266,
0.7926986636f, 0.7963415838f, 0.7258694464f, 0.6539092497f, 0.7926986636, 0.7963415838, 0.7258694464, 0.6539092497,
0.0319417555f, -0.1722823173f, -0.2758014811f, -0.3376131734f); 0.0319417555, -0.1722823173, -0.2758014811, -0.3376131734);
return T * moments; return T * moments;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment