From 5ec815edf803506faadcdd0988770dd6484f9fe5 Mon Sep 17 00:00:00 2001 From: Tania Castillo <31288525+tvcastillod@users.noreply.github.com> Date: Tue, 25 Jul 2023 17:07:23 -0500 Subject: [PATCH 001/118] added file for experimentation --- docs/experimental/viz_sh_odf.py | 139 ++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 docs/experimental/viz_sh_odf.py diff --git a/docs/experimental/viz_sh_odf.py b/docs/experimental/viz_sh_odf.py new file mode 100644 index 000000000..f5a651742 --- /dev/null +++ b/docs/experimental/viz_sh_odf.py @@ -0,0 +1,139 @@ +""" +This spript includes the basic implementation of Spherical Harmonics +""" + +import numpy as np +import os + +from fury import actor, window +from fury.shaders import (attribute_to_actor, compose_shader, + import_fury_shader, shader_to_actor) + + +class Sphere: + vertices = None + faces = None + + +if __name__ == '__main__': + centers = np.array([[0, 0, 0], [-10, 0, 0], [10, 0, 0]]) + vecs = np.array([[0, 1, 0], [0, 1, 0], [0, 1, 0]]) + colors = np.array([[0, 0, 1], [0, 1, 0], [1, 0, 0]]) + vals = np.array([1.0, 1.0, 1.0, 1.0]) + + box_sd_stg_actor = actor.box(centers=centers, directions=vecs, + colors=colors, scales=1.0) + + big_centers = np.repeat(centers, 8, axis=0) + attribute_to_actor(box_sd_stg_actor, big_centers, 'center') + + big_directions = np.repeat(vecs, 8, axis=0) + attribute_to_actor(box_sd_stg_actor, big_directions, 'direction') + + big_scales = np.repeat(vals, 8, axis=0) + attribute_to_actor(box_sd_stg_actor, big_scales, 'scale') + + vs_dec = \ + """ + in vec3 center; + in vec3 direction; + in float scale; + + out vec4 vertexMCVSOutput; + out vec3 centerMCVSOutput; + out vec3 directionVSOutput; + out float scaleVSOutput; + """ + + vs_impl = \ + """ + vertexMCVSOutput = vertexMC; + centerMCVSOutput = center; + directionVSOutput = direction; + scaleVSOutput = scale; + """ + + shader_to_actor(box_sd_stg_actor, 'vertex', decl_code=vs_dec, + impl_code=vs_impl) + + fs_vars_dec = \ + """ + in vec4 vertexMCVSOutput; + in vec3 centerMCVSOutput; + in vec3 directionVSOutput; + in float scaleVSOutput; + + uniform mat4 MCVCMatrix; + """ + + vec_to_vec_rot_mat = import_fury_shader(os.path.join( + 'utils', 'vec_to_vec_rot_mat.glsl')) + + sd_cylinder = import_fury_shader(os.path.join('sdf', 'sd_sphere.frag')) + + sdf_map = \ + """ + float map(in vec3 position) + { + return sdSphere((position - centerMCVSOutput)/scaleVSOutput, .5) + *scaleVSOutput; + } + """ + + central_diffs_normal = import_fury_shader(os.path.join( + 'sdf', 'central_diffs.frag')) + + cast_ray = import_fury_shader(os.path.join( + 'ray_marching', 'cast_ray.frag')) + + blinn_phong_model = import_fury_shader(os.path.join( + 'lighting', 'blinn_phong_model.frag')) + + fs_dec = compose_shader([fs_vars_dec, vec_to_vec_rot_mat, sd_cylinder, + sdf_map, central_diffs_normal, cast_ray, + blinn_phong_model]) + + shader_to_actor(box_sd_stg_actor, 'fragment', decl_code=fs_dec) + + sdf_frag_impl = \ + """ + vec3 pnt = vertexMCVSOutput.xyz; + + // Ray Origin + // Camera position in world space + vec3 ro = (-MCVCMatrix[3] * MCVCMatrix).xyz; + + // Ray Direction + vec3 rd = normalize(pnt - ro); + + // Light Direction + vec3 ld = normalize(ro - pnt); + + ro += pnt - ro; + + float t = castRay(ro, rd); + + if(t < 20) + { + vec3 pos = ro + t * rd; + vec3 normal = centralDiffsNormals(pos, .0001); + fragOutput0 = vec4(vertexColorVSOutput.xyz, 1.0); + } + else + { + discard; + } + """ + + shader_to_actor(box_sd_stg_actor, 'fragment', impl_code=sdf_frag_impl, + block='light') + + # Scene setup + scene = window.Scene() + + scene.add(box_sd_stg_actor) + + scene.reset_camera() + scene.reset_clipping_range() + + window.show(scene, reset_camera=False) \ No newline at end of file From 4464ee4e4b348ab644498f9e01547bf5e1df1a92 Mon Sep 17 00:00:00 2001 From: Tania Castillo <31288525+tvcastillod@users.noreply.github.com> Date: Mon, 7 Aug 2023 19:08:05 -0500 Subject: [PATCH 002/118] added SH implementation with 2 parameters --- docs/experimental/viz_sh_odf.py | 279 ++++++++++++++++++++++++++++---- 1 file changed, 248 insertions(+), 31 deletions(-) diff --git a/docs/experimental/viz_sh_odf.py b/docs/experimental/viz_sh_odf.py index f5a651742..4a02106e9 100644 --- a/docs/experimental/viz_sh_odf.py +++ b/docs/experimental/viz_sh_odf.py @@ -1,11 +1,11 @@ """ This spript includes the basic implementation of Spherical Harmonics """ - +''' import numpy as np import os -from fury import actor, window +from fury import actor, window, ui from fury.shaders import (attribute_to_actor, compose_shader, import_fury_shader, shader_to_actor) @@ -16,10 +16,12 @@ class Sphere: if __name__ == '__main__': - centers = np.array([[0, 0, 0], [-10, 0, 0], [10, 0, 0]]) + centers = np.array([[-1.2, 0, 0], [0, 0, 0], [1.2, 0, 0]]) vecs = np.array([[0, 1, 0], [0, 1, 0], [0, 1, 0]]) colors = np.array([[0, 0, 1], [0, 1, 0], [1, 0, 0]]) - vals = np.array([1.0, 1.0, 1.0, 1.0]) + vals = np.array([1.0, 1.0, 1.0]) + lvals = np.array([6, 5, 3]) + mvals = np.array([-4, 4, 2]) box_sd_stg_actor = actor.box(centers=centers, directions=vecs, colors=colors, scales=1.0) @@ -33,16 +35,26 @@ class Sphere: big_scales = np.repeat(vals, 8, axis=0) attribute_to_actor(box_sd_stg_actor, big_scales, 'scale') + big_lvals = np.repeat(lvals, 8, axis=0) + attribute_to_actor(box_sd_stg_actor, big_lvals, 'lval') + + big_mvals = np.repeat(mvals, 8, axis=0) + attribute_to_actor(box_sd_stg_actor, big_mvals, 'mval') + vs_dec = \ """ in vec3 center; in vec3 direction; in float scale; - + in float lval; + in float mval; + out vec4 vertexMCVSOutput; out vec3 centerMCVSOutput; out vec3 directionVSOutput; out float scaleVSOutput; + out float lvalVSOutput; + out float mvalVSOutput; """ vs_impl = \ @@ -51,6 +63,8 @@ class Sphere: centerMCVSOutput = center; directionVSOutput = direction; scaleVSOutput = scale; + lvalVSOutput = lval; + mvalVSOutput = mval; """ shader_to_actor(box_sd_stg_actor, 'vertex', decl_code=vs_dec, @@ -62,29 +76,149 @@ class Sphere: in vec3 centerMCVSOutput; in vec3 directionVSOutput; in float scaleVSOutput; - + in float lvalVSOutput; + in float mvalVSOutput; + uniform mat4 MCVCMatrix; """ vec_to_vec_rot_mat = import_fury_shader(os.path.join( 'utils', 'vec_to_vec_rot_mat.glsl')) - sd_cylinder = import_fury_shader(os.path.join('sdf', 'sd_sphere.frag')) + sd_cylinder = \ + """ + float sdSphere(vec3 p, float r) + { + return length(p) - r; + } + """ sdf_map = \ """ - float map(in vec3 position) + + #define PI 3.1415926535898 + + // Clenshaw Legendre normalized + float Pgn(int l, int m, float x) + { + float p0 = 0., p1 = 0., p2 = 0.; + + for (int k = l; k >= 0; k--) + { + float k1 = float(k + 1); + float m1 = float(2 * m) + k1; + float m2 = float(2 * (m + k) + 1); + + p2 = p1; + p1 = p0; + + p0 = 0.; + if (l == m + k) + p0 = 1.; + + float u0 = sqrt( + (m2 * (m2 + 2.0)) / + (k1 * m1) + ); + + float u1 = sqrt( + (k1 * m1 * (m2 + 4.0)) / + ((k1 + 1.0) * (m1 + 1.0) * m2) + ); + + p0 += p1 * u0 * x; + p0 -= u1 * p2; + } + + for (int k = 1; k <= m; k++) + { + p0 *= sqrt( + (1.0 - 0.5/float(k)) * (1.0 - x) * (1.0 + x) + ); + } + + p0 *= sqrt((0.5 * float(m) + 0.25)/PI); + + return p0; + } + + float SH( in int l, in int m, in vec3 s ) { - return sdSphere((position - centerMCVSOutput)/scaleVSOutput, .5) - *scaleVSOutput; + vec3 ns = normalize(s); + + if (m < 0) { + float c = ns.x; + ns.x = ns.z; + ns.z = c; + m = -m; + } + + // spherical coordinates + float thetax = ns.y; + float phi = atan(ns.z, ns.x)+PI/2.; + + float pl = Pgn(l, m, thetax); + + float r = (m - (2 * (m/2)) == 0 ? 1. : -1.) * cos(float(m) * phi) * pl; + + return r; } + + vec3 map( in vec3 p ) + { + p = p - centerMCVSOutput; + vec3 p00 = p; + + float r, d; vec3 n, s, res; + + #define SHAPE (vec3(d-abs(r), sign(r),d)) + + int l = int(lvalVSOutput); + int m = int(mvalVSOutput); + + d=length(p00); n=p00/d; r = SH(l, m, n)*scaleVSOutput; s = SHAPE; res = s; + + return vec3( res.x, 0.5+0.5*res.y, res.z ); + } + """ - central_diffs_normal = import_fury_shader(os.path.join( - 'sdf', 'central_diffs.frag')) + central_diffs_normal = \ + """ + vec3 centralDiffsNormals(in vec3 pos) + { + //vec2 e = vec2(1.0,-1.0)*0.5773*0.0005; + vec2 e = vec2(0.001, -1.0); + return normalize( e.xyy*map( pos + e.xyy ).x + + e.yyx*map( pos + e.yyx ).x + + e.yxy*map( pos + e.yxy ).x + + e.xxx*map( pos + e.xxx ).x ); + } + """ - cast_ray = import_fury_shader(os.path.join( - 'ray_marching', 'cast_ray.frag')) + cast_ray = \ + """ + vec3 castRay(in vec3 ro, vec3 rd) + { + vec3 res = vec3(1e10,-1.0, 1.0); + + float maxd = 4.0; + float h = 1.0; + float t = 0.0; + vec2 m = vec2(-1.0); + for( int i=0; i<2000; i++ ) + { + if( h<0.01||t>maxd ) break; + vec3 res = map( ro+rd*t ); + h = res.x; + m = res.yz; + t += h*0.1; + } + if( t -0.5 ) { - vec3 pos = ro + t * rd; - vec3 normal = centralDiffsNormals(pos, .0001); - fragOutput0 = vec4(vertexColorVSOutput.xyz, 1.0); + vec3 pos = ro + t.y * rd; + vec3 normal = centralDiffsNormals(pos); + vec3 ref = reflect( rd, normal ); + + + float occ = clamp( 2.0*t.z, 0.0, 1.0 ); + float sss = pow( clamp( 1.0 + dot(normal, rd), 0.0, 1.0 ), 1.0 ); + + // lights + vec3 lin = 2.5*occ*vec3(1.0,1.00,1.00)*(0.6+0.4*normal.y); + lin += 1.0*sss*vec3(1.0,0.95,0.70)*occ; + + vec3 mater = 0.5*mix( vec3(1.0,0.6,0.15), vec3(0.2,0.4,0.5), t.y ); + + fragOutput0 = vec4( mater * lin , 1.0); } else { @@ -128,12 +274,83 @@ class Sphere: shader_to_actor(box_sd_stg_actor, 'fragment', impl_code=sdf_frag_impl, block='light') - # Scene setup - scene = window.Scene() + slider_l = ui.LineSlider2D( + center=(100, 250), + length=100, + initial_value=2, + orientation='horizontal', + min_value=0, + max_value=10, + text_alignment='bottom', + ) + + slider_m = ui.LineSlider2D( + center=(100, 200), + length=100, + initial_value=2, + orientation='horizontal', + min_value=-10, + max_value=10, + text_alignment='bottom', + ) + + def changeL(slider): + l = int(slider.value) + lvals = np.array([l, 5, 3]) + big_lvals = np.repeat(lvals, 8, axis=0) + attribute_to_actor(box_sd_stg_actor, big_lvals, 'lval') + + def changeM(slider): + m = int(slider.value) + mvals = np.array([m, 4, 2]) + big_mvals = np.repeat(mvals, 8, axis=0) + attribute_to_actor(box_sd_stg_actor, big_mvals, 'mval') + slider_m.min_value = int(slider_l.value) * -1 + slider_m.max_value = int(slider_l.value) + + slider_m.on_change = changeM + slider_l.on_change = changeL + + show_manager = window.ShowManager(size=(700, 700)) + show_manager.scene.add(box_sd_stg_actor) + show_manager.scene.add(slider_m) + show_manager.scene.add(slider_l) + + show_manager.start() +''' + +import numpy as np +from dipy.io.image import load_nifti, save_nifti +from dipy.io.gradients import read_bvals_bvecs +from dipy.core.gradients import gradient_table + +import dipy.reconst.dti as dti + +from dipy.data import get_fnames + +hardi_fname, hardi_bval_fname, hardi_bvec_fname = get_fnames('stanford_hardi') + +data, affine = load_nifti(hardi_fname) + +bvals, bvecs = read_bvals_bvecs(hardi_bval_fname, hardi_bvec_fname) +gtab = gradient_table(bvals, bvecs) + +tenmodel = dti.TensorModel(gtab) + +from dipy.data import get_sphere +sphere = get_sphere('repulsion724') + +interactive = True +from fury import actor, window +scene = window.Scene() - scene.add(box_sd_stg_actor) +tensor_odfs = tenmodel.fit(data[45:50, 73:78, 38:39]).odf(sphere) +print(tensor_odfs) +print(tensor_odfs.shape) - scene.reset_camera() - scene.reset_clipping_range() +odf_actor = actor.odf_slicer(tensor_odfs, sphere=sphere, scale=0.5, + colormap=None) +scene.add(odf_actor) - window.show(scene, reset_camera=False) \ No newline at end of file +if interactive: + window.show(scene) From dffb17cb9e40d14973781cf807a9525601996a86 Mon Sep 17 00:00:00 2001 From: Tania Castillo <31288525+tvcastillod@users.noreply.github.com> Date: Wed, 9 Aug 2023 10:57:09 -0500 Subject: [PATCH 003/118] adjusted script --- docs/experimental/viz_sh_odf.py | 39 +-------------------------------- 1 file changed, 1 insertion(+), 38 deletions(-) diff --git a/docs/experimental/viz_sh_odf.py b/docs/experimental/viz_sh_odf.py index 4a02106e9..97d51e513 100644 --- a/docs/experimental/viz_sh_odf.py +++ b/docs/experimental/viz_sh_odf.py @@ -1,7 +1,7 @@ """ This spript includes the basic implementation of Spherical Harmonics """ -''' + import numpy as np import os @@ -317,40 +317,3 @@ def changeM(slider): show_manager.scene.add(slider_l) show_manager.start() -''' - -import numpy as np -from dipy.io.image import load_nifti, save_nifti -from dipy.io.gradients import read_bvals_bvecs -from dipy.core.gradients import gradient_table - -import dipy.reconst.dti as dti - -from dipy.data import get_fnames - -hardi_fname, hardi_bval_fname, hardi_bvec_fname = get_fnames('stanford_hardi') - -data, affine = load_nifti(hardi_fname) - -bvals, bvecs = read_bvals_bvecs(hardi_bval_fname, hardi_bvec_fname) -gtab = gradient_table(bvals, bvecs) - -tenmodel = dti.TensorModel(gtab) - -from dipy.data import get_sphere -sphere = get_sphere('repulsion724') - -interactive = True -from fury import actor, window -scene = window.Scene() - -tensor_odfs = tenmodel.fit(data[45:50, 73:78, 38:39]).odf(sphere) -print(tensor_odfs) -print(tensor_odfs.shape) - -odf_actor = actor.odf_slicer(tensor_odfs, sphere=sphere, scale=0.5, - colormap=None) -scene.add(odf_actor) - -if interactive: - window.show(scene) From b61aaf5d97aa5d83a332236730fce9f298ab06ea Mon Sep 17 00:00:00 2001 From: Tania Castillo <31288525+tvcastillod@users.noreply.github.com> Date: Tue, 15 Aug 2023 23:44:03 -0500 Subject: [PATCH 004/118] added coefficients to experimental implementation --- docs/experimental/viz_sh_odf.py | 396 ++++++++++++++++++++------------ 1 file changed, 246 insertions(+), 150 deletions(-) diff --git a/docs/experimental/viz_sh_odf.py b/docs/experimental/viz_sh_odf.py index 97d51e513..d1138ace0 100644 --- a/docs/experimental/viz_sh_odf.py +++ b/docs/experimental/viz_sh_odf.py @@ -5,220 +5,265 @@ import numpy as np import os -from fury import actor, window, ui +from fury import actor, window from fury.shaders import (attribute_to_actor, compose_shader, import_fury_shader, shader_to_actor) -class Sphere: - vertices = None - faces = None +if __name__ == '__main__': + centers = np.array([[0, -1, 0], [1.0, -1, 0], [2.0, -1, 0], [3.0, -1, 0]]) + vecs = np.array([[0, 1, 0], [0, 1, 0], [0, 1, 0], [0, 1, 0]]) + colors = np.array([[0, 0, 1], [0, 1, 0], [1, 0, 0], [0, 1, 0]]) + vals = np.array([1.2, 4.2, 2.0, 2.0]) + coeffs = np.array( + [[0.2820735, 0.15236554, -0.04038717, -0.11270988, -0.04532376, + 0.14921817, 0.00257928, 0.0040734, -0.05313807, 0.03486542, + 0.04083064, 0.02105767, -0.04389586, -0.04302812, 0.1048641], + [2.82094529e-01, 7.05702620e-03, 3.20326265e-02, -2.88333917e-02, + 5.33638381e-03, 1.18306258e-02, -2.21964945e-04, 5.54136434e-04, + 1.25108672e-03, -4.69248914e-03, 4.30155475e-04, -1.15585609e-03, + -4.69016480e-04, 1.44523500e-03, 3.96346915e-04], + [0.28549338, 0.0978267, -0.11544838, 0.12525354, -0.00126003, + 0.00320594, 0.04744155, -0.07141446, 0.03211689, 0.04711322, + 0.08064896, 0.00154299, 0.00086506, 0.00162543, -0.00444893], + [0.28208936, -0.13133252, -0.04701012, -0.06303016, -0.0468775, + 0.02348355, 0.03991898, 0.02587433, 0.02645416, 0.00668765, + 0.00890633, 0.02189304, 0.00387415, 0.01665629, -0.01427194]]) + + box_sd_stg_actor = actor.box(centers=np.array([centers[0]]), scales=1.0) + + big_centers = np.repeat(np.array([centers[0]]), 8, axis=0) + attribute_to_actor(box_sd_stg_actor, big_centers, 'center') + big_scales = np.repeat(np.array([vals[0]]), 8, axis=0) + attribute_to_actor(box_sd_stg_actor, big_scales, 'scale') -if __name__ == '__main__': - centers = np.array([[-1.2, 0, 0], [0, 0, 0], [1.2, 0, 0]]) - vecs = np.array([[0, 1, 0], [0, 1, 0], [0, 1, 0]]) - colors = np.array([[0, 0, 1], [0, 1, 0], [1, 0, 0]]) - vals = np.array([1.0, 1.0, 1.0]) - lvals = np.array([6, 5, 3]) - mvals = np.array([-4, 4, 2]) + box_sd_stg_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniform1fv( + "coeffs", 15, coeffs[0]) - box_sd_stg_actor = actor.box(centers=centers, directions=vecs, - colors=colors, scales=1.0) + box_sd_stg_actor3 = actor.box(centers=np.array([centers[2]]), scales=1.0) - big_centers = np.repeat(centers, 8, axis=0) - attribute_to_actor(box_sd_stg_actor, big_centers, 'center') + big_centers = np.repeat(np.array([centers[2]]), 8, axis=0) + attribute_to_actor(box_sd_stg_actor3, big_centers, 'center') - big_directions = np.repeat(vecs, 8, axis=0) - attribute_to_actor(box_sd_stg_actor, big_directions, 'direction') + big_scales = np.repeat(np.array([vals[2]]), 8, axis=0) + attribute_to_actor(box_sd_stg_actor3, big_scales, 'scale') - big_scales = np.repeat(vals, 8, axis=0) - attribute_to_actor(box_sd_stg_actor, big_scales, 'scale') + box_sd_stg_actor3.GetShaderProperty().GetFragmentCustomUniforms().SetUniform1fv( + "coeffs", 15, coeffs[2]) + + box_sd_stg_actor2 = actor.box(centers=np.array([centers[1]]), scales=1.0) + + big_centers = np.repeat(np.array([centers[1]]), 8, axis=0) + attribute_to_actor(box_sd_stg_actor2, big_centers, 'center') + + big_scales = np.repeat(np.array([vals[1]]), 8, axis=0) + attribute_to_actor(box_sd_stg_actor2, big_scales, 'scale') + + box_sd_stg_actor2.GetShaderProperty().GetFragmentCustomUniforms().SetUniform1fv( + "coeffs", 15, coeffs[1]) - big_lvals = np.repeat(lvals, 8, axis=0) - attribute_to_actor(box_sd_stg_actor, big_lvals, 'lval') + box_sd_stg_actor4 = actor.box(centers=np.array([centers[3]]), scales=1.0) - big_mvals = np.repeat(mvals, 8, axis=0) - attribute_to_actor(box_sd_stg_actor, big_mvals, 'mval') + big_centers = np.repeat(np.array([centers[3]]), 8, axis=0) + attribute_to_actor(box_sd_stg_actor4, big_centers, 'center') + + big_scales = np.repeat(np.array([vals[3]]), 8, axis=0) + attribute_to_actor(box_sd_stg_actor4, big_scales, 'scale') + + box_sd_stg_actor4.GetShaderProperty().GetFragmentCustomUniforms().SetUniform1fv( + "coeffs", 15, coeffs[3]) vs_dec = \ """ in vec3 center; - in vec3 direction; in float scale; - in float lval; - in float mval; out vec4 vertexMCVSOutput; out vec3 centerMCVSOutput; - out vec3 directionVSOutput; out float scaleVSOutput; - out float lvalVSOutput; - out float mvalVSOutput; """ vs_impl = \ """ vertexMCVSOutput = vertexMC; centerMCVSOutput = center; - directionVSOutput = direction; scaleVSOutput = scale; - lvalVSOutput = lval; - mvalVSOutput = mval; """ shader_to_actor(box_sd_stg_actor, 'vertex', decl_code=vs_dec, impl_code=vs_impl) + shader_to_actor(box_sd_stg_actor2, 'vertex', decl_code=vs_dec, + impl_code=vs_impl) + shader_to_actor(box_sd_stg_actor3, 'vertex', decl_code=vs_dec, + impl_code=vs_impl) + shader_to_actor(box_sd_stg_actor4, 'vertex', decl_code=vs_dec, + impl_code=vs_impl) fs_vars_dec = \ """ in vec4 vertexMCVSOutput; in vec3 centerMCVSOutput; - in vec3 directionVSOutput; in float scaleVSOutput; - in float lvalVSOutput; - in float mvalVSOutput; uniform mat4 MCVCMatrix; + + layout(std140) uniform MyBlock + { + float coeffss[15]; + }; + """ vec_to_vec_rot_mat = import_fury_shader(os.path.join( 'utils', 'vec_to_vec_rot_mat.glsl')) sd_cylinder = \ - """ - float sdSphere(vec3 p, float r) - { - return length(p) - r; - } - """ + """ + float sdSphere(vec3 p, float r) + { + return length(p) - r; + } + """ sdf_map = \ """ - + #define PI 3.1415926535898 // Clenshaw Legendre normalized float Pgn(int l, int m, float x) { float p0 = 0., p1 = 0., p2 = 0.; - + for (int k = l; k >= 0; k--) { float k1 = float(k + 1); float m1 = float(2 * m) + k1; float m2 = float(2 * (m + k) + 1); - + p2 = p1; p1 = p0; - + p0 = 0.; if (l == m + k) p0 = 1.; - + float u0 = sqrt( (m2 * (m2 + 2.0)) / (k1 * m1) ); - + float u1 = sqrt( (k1 * m1 * (m2 + 4.0)) / ((k1 + 1.0) * (m1 + 1.0) * m2) ); - + p0 += p1 * u0 * x; p0 -= u1 * p2; } - + for (int k = 1; k <= m; k++) { p0 *= sqrt( (1.0 - 0.5/float(k)) * (1.0 - x) * (1.0 + x) ); } - + p0 *= sqrt((0.5 * float(m) + 0.25)/PI); - + return p0; } float SH( in int l, in int m, in vec3 s ) { vec3 ns = normalize(s); - + if (m < 0) { - float c = ns.x; - ns.x = ns.z; - ns.z = c; m = -m; } - + // spherical coordinates float thetax = ns.y; float phi = atan(ns.z, ns.x)+PI/2.; - + float pl = Pgn(l, m, thetax); - - float r = (m - (2 * (m/2)) == 0 ? 1. : -1.) * cos(float(m) * phi) * pl; - + + float r = pow(-1.0, float(m)) * cos(float(m) * phi) * pl; + if (m != 0) { + r *= sqrt(2.0); + } return r; } - + vec3 map( in vec3 p ) { p = p - centerMCVSOutput; vec3 p00 = p; - + float r, d; vec3 n, s, res; #define SHAPE (vec3(d-abs(r), sign(r),d)) - - int l = int(lvalVSOutput); - int m = int(mvalVSOutput); - - d=length(p00); n=p00/d; r = SH(l, m, n)*scaleVSOutput; s = SHAPE; res = s; - + d=length(p00); + n=p00/d; + float sc = scaleVSOutput; + r = coeffs[0]*SH(0, 0, n)*sc; + r += coeffs[1]*SH(2, -2, n)*sc; + r += coeffs[2]*SH(2, -1, n)*sc; + r += coeffs[3]*SH(2, 0, n)*sc; + r += coeffs[4]*SH(2, 1, n)*sc; + r += coeffs[5]*SH(2, 2, n)*sc; + r += coeffs[6]*SH(4, -4, n)*sc; + r += coeffs[7]*SH(4, -3, n)*sc; + r += coeffs[8]*SH(4, -2, n)*sc; + r += coeffs[9]*SH(4, -1, n)*sc; + r += coeffs[10]*SH(4, 0, n)*sc; + r += coeffs[11]*SH(4, 1, n)*sc; + r += coeffs[12]*SH(4, 2, n)*sc; + r += coeffs[13]*SH(4, 3, n)*sc; + r += coeffs[14]*SH(4, 4, n)*sc; + + s = SHAPE; res = s; return vec3( res.x, 0.5+0.5*res.y, res.z ); } - """ central_diffs_normal = \ - """ - vec3 centralDiffsNormals(in vec3 pos) - { - //vec2 e = vec2(1.0,-1.0)*0.5773*0.0005; - vec2 e = vec2(0.001, -1.0); - return normalize( e.xyy*map( pos + e.xyy ).x + - e.yyx*map( pos + e.yyx ).x + - e.yxy*map( pos + e.yxy ).x + - e.xxx*map( pos + e.xxx ).x ); - } - """ + """ + vec3 centralDiffsNormals(in vec3 pos) + { + //vec2 e = vec2(1.0,-1.0)*0.5773*0.0005; + vec2 e = vec2(0.001, -1.0); + return normalize( e.xyy*map( pos + e.xyy ).x + + e.yyx*map( pos + e.yyx ).x + + e.yxy*map( pos + e.yxy ).x + + e.xxx*map( pos + e.xxx ).x ); + } + """ cast_ray = \ - """ - vec3 castRay(in vec3 ro, vec3 rd) - { - vec3 res = vec3(1e10,-1.0, 1.0); - - float maxd = 4.0; - float h = 1.0; - float t = 0.0; - vec2 m = vec2(-1.0); - for( int i=0; i<2000; i++ ) + """ + vec3 castRay(in vec3 ro, vec3 rd) { - if( h<0.01||t>maxd ) break; - vec3 res = map( ro+rd*t ); - h = res.x; - m = res.yz; - t += h*0.1; + vec3 res = vec3(1e10,-1.0, 1.0); + + float maxd = 4.0; + float h = 1.0; + float t = 0.0; + vec2 m = vec2(-1.0); + for( int i=0; i<2000; i++ ) + { + if( h<0.01||t>maxd ) break; + vec3 res = map( ro+rd*t ); + h = res.x; + m = res.yz; + t += h*0.1; + } + if( t -0.5 ) { vec3 pos = ro + t.y * rd; + vec3 normal = centralDiffsNormals(pos); - vec3 ref = reflect( rd, normal ); - - + float occ = clamp( 2.0*t.z, 0.0, 1.0 ); float sss = pow( clamp( 1.0 + dot(normal, rd), 0.0, 1.0 ), 1.0 ); - + // lights - vec3 lin = 2.5*occ*vec3(1.0,1.00,1.00)*(0.6+0.4*normal.y); + vec3 lin = 2.5*occ*vec3(1.0,1.0,1.0)*(0.6+0.4*normal.y); lin += 1.0*sss*vec3(1.0,0.95,0.70)*occ; - - vec3 mater = 0.5*mix( vec3(1.0,0.6,0.15), vec3(0.2,0.4,0.5), t.y ); - - fragOutput0 = vec4( mater * lin , 1.0); + + vec3 mater = 0.5*mix( vec3(1.0,1.0,0.0), vec3(1.0,1.0,1.0), t.y); + + fragOutput0 = vec4( lin, 1.0); + } else { @@ -273,47 +321,95 @@ class Sphere: shader_to_actor(box_sd_stg_actor, 'fragment', impl_code=sdf_frag_impl, block='light') + shader_to_actor(box_sd_stg_actor2, 'fragment', impl_code=sdf_frag_impl, + block='light') + shader_to_actor(box_sd_stg_actor3, 'fragment', impl_code=sdf_frag_impl, + block='light') + shader_to_actor(box_sd_stg_actor4, 'fragment', impl_code=sdf_frag_impl, + block='light') - slider_l = ui.LineSlider2D( - center=(100, 250), - length=100, - initial_value=2, - orientation='horizontal', - min_value=0, - max_value=10, - text_alignment='bottom', - ) - - slider_m = ui.LineSlider2D( - center=(100, 200), - length=100, - initial_value=2, - orientation='horizontal', - min_value=-10, - max_value=10, - text_alignment='bottom', - ) - - def changeL(slider): - l = int(slider.value) - lvals = np.array([l, 5, 3]) - big_lvals = np.repeat(lvals, 8, axis=0) - attribute_to_actor(box_sd_stg_actor, big_lvals, 'lval') - - def changeM(slider): - m = int(slider.value) - mvals = np.array([m, 4, 2]) - big_mvals = np.repeat(mvals, 8, axis=0) - attribute_to_actor(box_sd_stg_actor, big_mvals, 'mval') - slider_m.min_value = int(slider_l.value) * -1 - slider_m.max_value = int(slider_l.value) - - slider_m.on_change = changeM - slider_l.on_change = changeL - - show_manager = window.ShowManager(size=(700, 700)) + show_manager = window.ShowManager(size=(700, 500)) show_manager.scene.add(box_sd_stg_actor) - show_manager.scene.add(slider_m) - show_manager.scene.add(slider_l) + show_manager.scene.add(box_sd_stg_actor2) + show_manager.scene.add(box_sd_stg_actor3) + show_manager.scene.add(box_sd_stg_actor4) + + from dipy.reconst.shm import sh_to_sf + from dipy.data import get_sphere + + sphere = get_sphere('repulsion724') + + sh_basis = 'descoteaux07' + sh_order = 4 + tensor_sh = coeffs = np.array( + [[[[0.2820735, 0.15236554, -0.04038717, -0.11270988, -0.04532376, + 0.14921817, 0.00257928, 0.0040734, -0.05313807, 0.03486542, + 0.04083064, 0.02105767, -0.04389586, -0.04302812, 0.1048641]]], + [[[2.82094529e-01, 7.05702620e-03, 3.20326265e-02, -2.88333917e-02, + 5.33638381e-03, 1.18306258e-02, -2.21964945e-04, 5.54136434e-04, + 1.25108672e-03, -4.69248914e-03, 4.30155475e-04, -1.15585609e-03, + -4.69016480e-04, 1.44523500e-03, 3.96346915e-04]]], + [[[0.28549338, 0.0978267, -0.11544838, 0.12525354, -0.00126003, + 0.00320594, 0.04744155, -0.07141446, 0.03211689, 0.04711322, + 0.08064896, 0.00154299, 0.00086506, 0.00162543, -0.00444893]]], + [[[0.28208936, -0.13133252, -0.04701012, -0.06303016, -0.0468775, + 0.02348355, 0.03991898, 0.02587433, 0.02645416, 0.00668765, + 0.00890633, 0.02189304, 0.00387415, 0.01665629, -0.01427194]]]]) + tensor_sf = sh_to_sf(tensor_sh, sh_order=4, basis_type='descoteaux07', + sphere=sphere) + + odf_actor = actor.odf_slicer(tensor_sf, sphere=sphere, scale=0.5, + colormap=None) + show_manager.scene.add(odf_actor) show_manager.start() + +''' + +import numpy as np +from dipy.io.image import load_nifti, save_nifti +from dipy.io.gradients import read_bvals_bvecs +from dipy.core.gradients import gradient_table + +import dipy.reconst.dti as dti + +from dipy.data import get_fnames + +hardi_fname, hardi_bval_fname, hardi_bvec_fname = get_fnames('stanford_hardi') + +data, affine = load_nifti(hardi_fname) + +bvals, bvecs = read_bvals_bvecs(hardi_bval_fname, hardi_bvec_fname) +gtab = gradient_table(bvals, bvecs) + +tenmodel = dti.TensorModel(gtab) + +from dipy.data import get_sphere + +sphere = get_sphere('repulsion724') + +interactive = True +from fury import actor, window + +scene = window.Scene() + +tensor_odfs = tenmodel.fit(data[45:47, 73:74, 38:39]).odf(sphere) + +from dipy.reconst.shm import sf_to_sh, sh_to_sf + + +sh_basis = 'descoteaux07' +sh_order = 4 + +tensor_sh = sf_to_sh(tensor_odfs, sphere, sh_order, sh_basis) +print(tensor_sh) +tensor_sf = sh_to_sf(tensor_sh, sh_order=4, basis_type='descoteaux07', + sphere=sphere) + +odf_actor = actor.odf_slicer(tensor_sf, sphere=sphere, scale=0.5, + colormap=None) +scene.add(odf_actor) + +if interactive: + window.show(scene) +''' \ No newline at end of file From 91f5ea57c76b8fc7bab979870daa01329411d150 Mon Sep 17 00:00:00 2001 From: Tania Castillo <31288525+tvcastillod@users.noreply.github.com> Date: Thu, 24 Aug 2023 17:10:14 -0500 Subject: [PATCH 005/118] deleted unused variables --- docs/experimental/viz_sh_odf.py | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/docs/experimental/viz_sh_odf.py b/docs/experimental/viz_sh_odf.py index d1138ace0..cbdb90032 100644 --- a/docs/experimental/viz_sh_odf.py +++ b/docs/experimental/viz_sh_odf.py @@ -107,23 +107,6 @@ in float scaleVSOutput; uniform mat4 MCVCMatrix; - - layout(std140) uniform MyBlock - { - float coeffss[15]; - }; - - """ - - vec_to_vec_rot_mat = import_fury_shader(os.path.join( - 'utils', 'vec_to_vec_rot_mat.glsl')) - - sd_cylinder = \ - """ - float sdSphere(vec3 p, float r) - { - return length(p) - r; - } """ sdf_map = \ @@ -268,9 +251,8 @@ blinn_phong_model = import_fury_shader(os.path.join( 'lighting', 'blinn_phong_model.frag')) - fs_dec = compose_shader([fs_vars_dec, vec_to_vec_rot_mat, sd_cylinder, - sdf_map, central_diffs_normal, cast_ray, - blinn_phong_model]) + fs_dec = compose_shader([fs_vars_dec, sdf_map, central_diffs_normal, + cast_ray, blinn_phong_model]) shader_to_actor(box_sd_stg_actor, 'fragment', decl_code=fs_dec) shader_to_actor(box_sd_stg_actor2, 'fragment', decl_code=fs_dec) From 7ad49f1fe929ccf32f199c271af7d9baa4cff2ed Mon Sep 17 00:00:00 2001 From: Tania Castillo <31288525+tvcastillod@users.noreply.github.com> Date: Thu, 24 Aug 2023 17:35:39 -0500 Subject: [PATCH 006/118] added files for experimentation on each issue --- .../SH-ODF experimental/colormapping.py | 314 +++++++++++++ .../SH-ODF experimental/direction_scaling.py | 412 ++++++++++++++++++ .../texture_coefficients.py | 328 ++++++++++++++ 3 files changed, 1054 insertions(+) create mode 100644 docs/experimental/SH-ODF experimental/colormapping.py create mode 100644 docs/experimental/SH-ODF experimental/direction_scaling.py create mode 100644 docs/experimental/SH-ODF experimental/texture_coefficients.py diff --git a/docs/experimental/SH-ODF experimental/colormapping.py b/docs/experimental/SH-ODF experimental/colormapping.py new file mode 100644 index 000000000..b44c8a677 --- /dev/null +++ b/docs/experimental/SH-ODF experimental/colormapping.py @@ -0,0 +1,314 @@ +""" +This spript includes COLORMAP experimentation for ODF glyphs +""" +import numpy as np +import os + +from fury import actor, window +from fury.shaders import (attribute_to_actor, compose_shader, + import_fury_shader, shader_to_actor) +from fury.utils import rgb_to_vtk + +if __name__ == '__main__': + centers = np.array([[0, -1, 0], [1.0, -1, 0], [2.0, -1, 0], [3.0, -1, 0]]) + vecs = np.array([[0, 1, 0], [0, 1, 0], [0, 1, 0], [0, 1, 0]]) + colors = np.array([[0, 0, 1], [0, 1, 0], [1, 0, 0], [0, 1, 0]]) + vals = np.array([1.0, 4.2, 2.0, 2.0]) + coeffs = np.array( + [[0.2820735, 0.15236554, -0.04038717, -0.11270988, -0.04532376, + 0.14921817, 0.00257928, 0.0040734, -0.05313807, 0.03486542, + 0.04083064, 0.02105767, -0.04389586, -0.04302812, 0.1048641], + [2.82094529e-01, 7.05702620e-03, 3.20326265e-02, -2.88333917e-02, + 5.33638381e-03, 1.18306258e-02, -2.21964945e-04, 5.54136434e-04, + 1.25108672e-03, -4.69248914e-03, 4.30155475e-04, -1.15585609e-03, + -4.69016480e-04, 1.44523500e-03, 3.96346915e-04], + [0.28549338, 0.0978267, -0.11544838, 0.12525354, -0.00126003, + 0.00320594, 0.04744155, -0.07141446, 0.03211689, 0.04711322, + 0.08064896, 0.00154299, 0.00086506, 0.00162543, -0.00444893], + [0.28208936, -0.13133252, -0.04701012, -0.06303016, -0.0468775, + 0.02348355, 0.03991898, 0.02587433, 0.02645416, 0.00668765, + 0.00890633, 0.02189304, 0.00387415, 0.01665629, -0.01427194]]) + + box_sd_stg_actor = actor.box(centers=np.array([centers[0]]), scales=1.0) + + big_centers = np.repeat(np.array([centers[0]]), 8, axis=0) + attribute_to_actor(box_sd_stg_actor, big_centers, 'center') + + big_scales = np.repeat(np.array([vals[2]]), 8, axis=0) + attribute_to_actor(box_sd_stg_actor, big_scales, 'scale') + + box_sd_stg_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniform1fv( + "coeffs", 15, coeffs[2]) + + # ========================================================================= + from fury.lib import Texture + from fury.colormap import create_colormap + + colormap = create_colormap(np.arange(0.0, 1.0, 1 / 256), "plasma") + + if len(colormap.shape) == 2: + colormap = np.array([colormap]) + + texture = Texture() + + cmap = (255 * colormap).astype(np.uint8) + cmap = rgb_to_vtk(cmap) + + texture.SetInputDataObject(cmap) + texture.InterpolateOn() + texture.SetWrap(Texture.ClampToEdge) + texture.SetBlendingMode(0) + texture.MipmapOn() + + box_sd_stg_actor.GetProperty().SetTexture("colormap", texture) + # ========================================================================= + + vs_dec = \ + """ + in vec3 center; + in float scale; + + out vec4 vertexMCVSOutput; + out vec3 centerMCVSOutput; + out float scaleVSOutput; + """ + + vs_impl = \ + """ + vertexMCVSOutput = vertexMC; + centerMCVSOutput = center; + scaleVSOutput = scale; + """ + + shader_to_actor(box_sd_stg_actor, 'vertex', decl_code=vs_dec, + impl_code=vs_impl) + + fs_vars_dec = \ + """ + in vec4 vertexMCVSOutput; + in vec3 centerMCVSOutput; + in float scaleVSOutput; + + uniform mat4 MCVCMatrix; + """ + + sdf_map = \ + """ + + #define PI 3.1415926535898 + + // Clenshaw Legendre normalized + float Pgn(int l, int m, float x) + { + float p0 = 0., p1 = 0., p2 = 0.; + + for (int k = l; k >= 0; k--) + { + float k1 = float(k + 1); + float m1 = float(2 * m) + k1; + float m2 = float(2 * (m + k) + 1); + + p2 = p1; + p1 = p0; + + p0 = 0.; + if (l == m + k) + p0 = 1.; + + float u0 = sqrt( + (m2 * (m2 + 2.0)) / + (k1 * m1) + ); + + float u1 = sqrt( + (k1 * m1 * (m2 + 4.0)) / + ((k1 + 1.0) * (m1 + 1.0) * m2) + ); + + p0 += p1 * u0 * x; + p0 -= u1 * p2; + } + + for (int k = 1; k <= m; k++) + { + p0 *= sqrt( + (1.0 - 0.5/float(k)) * (1.0 - x) * (1.0 + x) + ); + } + + p0 *= sqrt((0.5 * float(m) + 0.25)/PI); + + return p0; + } + + float SH( in int l, in int m, in vec3 s ) + { + vec3 ns = normalize(s); + + if (m < 0) { + m = -m; + } + + // spherical coordinates + float thetax = ns.y; + float phi = atan(ns.z, ns.x)+PI/2.; + + float pl = Pgn(l, m, thetax); + + float r = pow(-1.0, float(m)) * cos(float(m) * phi) * pl; + if (m != 0) { + r *= sqrt(2.0); + } + return r; + } + + vec3 map( in vec3 p ) + { + p = p - centerMCVSOutput; + vec3 p00 = p; + + float r, d; vec3 n, s, res; + + #define SHAPE (vec3(d-abs(r), sign(r),d)) + //#define SHAPE (vec3(d-0.35, -1.0+2.0*clamp(0.5 + 16.0*r,0.0,1.0),d)) + d=length(p00); + n=p00/d; + float sc = scaleVSOutput; + r = coeffs[0]*SH(0, 0, n)*sc; + r += coeffs[1]*SH(2, -2, n)*sc; + r += coeffs[2]*SH(2, -1, n)*sc; + r += coeffs[3]*SH(2, 0, n)*sc; + r += coeffs[4]*SH(2, 1, n)*sc; + r += coeffs[5]*SH(2, 2, n)*sc; + r += coeffs[6]*SH(4, -4, n)*sc; + r += coeffs[7]*SH(4, -3, n)*sc; + r += coeffs[8]*SH(4, -2, n)*sc; + r += coeffs[9]*SH(4, -1, n)*sc; + r += coeffs[10]*SH(4, 0, n)*sc; + r += coeffs[11]*SH(4, 1, n)*sc; + r += coeffs[12]*SH(4, 2, n)*sc; + r += coeffs[13]*SH(4, 3, n)*sc; + r += coeffs[14]*SH(4, 4, n)*sc; + + s = SHAPE; res = s; + return vec3( res.x, 0.5+0.5*res.y, res.z ); + } + """ + + central_diffs_normal = \ + """ + vec3 centralDiffsNormals(in vec3 pos) + { + //vec2 e = vec2(1.0,-1.0)*0.5773*0.0005; + vec2 e = vec2(0.001, -1.0); + return normalize( e.xyy*map( pos + e.xyy ).x + + e.yyx*map( pos + e.yyx ).x + + e.yxy*map( pos + e.yxy ).x + + e.xxx*map( pos + e.xxx ).x ); + } + """ + + cast_ray = \ + """ + vec3 castRay(in vec3 ro, vec3 rd) + { + vec3 res = vec3(1e10,-1.0, 1.0); + + float maxd = 4.0; + float h = 1.0; + float t = 0.0; + vec2 m = vec2(-1.0); + for( int i=0; i<2000; i++ ) + { + if( h<0.01||t>maxd ) break; + vec3 res = map( ro+rd*t ); + h = res.x; + m = res.yz; + t += h*0.1; + } + if( t -0.5 ) + { + vec3 pos = ro + t.y * rd; + + vec3 normal = centralDiffsNormals(pos); + + float occ = clamp( 2.0*t.z, 0.0, 1.0 ); + float sss = pow( clamp( 1.0 + dot(normal, rd), 0.0, 1.0 ), 1.0 ); + + // lights + vec3 lin = 2.5*occ*vec3(1.0,1.0,1.0)*(0.6+0.4*normal.y); + lin += 1.0*sss*vec3(1.0,0.95,0.70)*occ; + + vec3 mater = 0.5*mix( vec3(1.0,1.0,0.0), vec3(1.0,1.0,1.0), t.y); + + // ================================================================ + //vec2 tex_coords = gl_FragCoord.xy/t.xy; + vec4 text = texture(colormap, t.xy); + fragOutput0 = vec4( text.rgb, 1.0); + // ================================================================ + + } + else + { + discard; + } + """ + + shader_to_actor(box_sd_stg_actor, 'fragment', impl_code=sdf_frag_impl, + block='light') + + show_manager = window.ShowManager(size=(700, 500)) + show_manager.scene.add(box_sd_stg_actor) + + from dipy.reconst.shm import sh_to_sf + from dipy.data import get_sphere + + sphere = get_sphere('repulsion724') + + sh_basis = 'descoteaux07' + sh_order = 4 + tensor_sh = np.array( + [[[[0.28549338, 0.0978267, -0.11544838, 0.12525354, -0.00126003, + 0.00320594, 0.04744155, -0.07141446, 0.03211689, 0.04711322, + 0.08064896, 0.00154299, 0.00086506, 0.00162543, -0.00444893]]]]) + tensor_sf = sh_to_sf(tensor_sh, sh_order=4, basis_type='descoteaux07', + sphere=sphere) + + odf_actor = actor.odf_slicer(tensor_sf, sphere=sphere, scale=0.5, + colormap='plasma') + show_manager.scene.add(odf_actor) + + show_manager.start() diff --git a/docs/experimental/SH-ODF experimental/direction_scaling.py b/docs/experimental/SH-ODF experimental/direction_scaling.py new file mode 100644 index 000000000..1f14ec7ef --- /dev/null +++ b/docs/experimental/SH-ODF experimental/direction_scaling.py @@ -0,0 +1,412 @@ +""" +This spript includes DIRECTION and SCALING experimentation of ODF glyphs +""" + +import numpy as np +import os + +from fury import actor, window +from fury.shaders import (attribute_to_actor, compose_shader, + import_fury_shader, shader_to_actor) + +if __name__ == '__main__': + + from dipy.reconst.shm import sh_to_sf + from dipy.data import get_sphere + + sphere = get_sphere('repulsion724') + + sh_basis = 'descoteaux07' + sh_order = 4 + tensor_sh = coeffs = np.array( + [[[[0.2820735, 0.15236554, -0.04038717, -0.11270988, -0.04532376, + 0.14921817, 0.00257928, 0.0040734, -0.05313807, 0.03486542, + 0.04083064, 0.02105767, -0.04389586, -0.04302812, 0.1048641]]], + [[[2.82094529e-01, 7.05702620e-03, 3.20326265e-02, -2.88333917e-02, + 5.33638381e-03, 1.18306258e-02, -2.21964945e-04, 5.54136434e-04, + 1.25108672e-03, -4.69248914e-03, 4.30155475e-04, -1.15585609e-03, + -4.69016480e-04, 1.44523500e-03, 3.96346915e-04]]], + [[[0.28549338, 0.0978267, -0.11544838, 0.12525354, -0.00126003, + 0.00320594, 0.04744155, -0.07141446, 0.03211689, 0.04711322, + 0.08064896, 0.00154299, 0.00086506, 0.00162543, -0.00444893]]], + [[[0.28208936, -0.13133252, -0.04701012, -0.06303016, -0.0468775, + 0.02348355, 0.03991898, 0.02587433, 0.02645416, 0.00668765, + 0.00890633, 0.02189304, 0.00387415, 0.01665629, -0.01427194]]]]) + tensor_sf = sh_to_sf(tensor_sh, sh_order=4, basis_type='descoteaux07', + sphere=sphere) + + # ========================================================================= + + from dipy.direction import peak_directions + + shape = tensor_sf.shape[:3] + npeaks = 1 # maximum number of peaks returned for a given voxel + peak_dirs = np.zeros((shape + (npeaks, 3))) + peak_values = np.zeros((shape + (npeaks,))) + + for idx in np.ndindex(shape): # iterate through each voxel + # Get peaks of odf + direction, pk, _ = peak_directions(tensor_sf[idx], sphere) + + # Calculate peak metrics + if pk.shape[0] != 0: + n = min(npeaks, pk.shape[0]) + peak_dirs[idx][:n] = direction[:n] + peak_values[idx][:n] = pk[:n] + + fodf_peaks = actor.peak_slicer(peak_dirs, peak_values) + print(peak_dirs) + print(peak_values) + + directions = np.array([[-0.91864797, -0.39090129, -0.05728953], + [-0.85608654, -0.29356156, 0.42536742], + [-0.87974526, 0.05612567, -0.47212094], + [-0.10475293, -0.97474003, -0.19725286]]) + values = np.array([0.35194137, 0.10609437, 0.22764033, 0.22833656]) + + # ========================================================================= + + centers = np.array([[0, -1, 0], [1.0, -1, 0], [2.0, -1, 0], [3.0, -1, 0]]) + vecs = np.array([[0, 1, 0], [0, 1, 0], [0, 1, 0], [0, 1, 0]]) + colors = np.array([[0, 0, 1], [0, 1, 0], [1, 0, 0], [0, 1, 0]]) + scales = 1 / values * .4 + coeffs = np.array( + [[0.2820735, 0.15236554, -0.04038717, -0.11270988, -0.04532376, + 0.14921817, 0.00257928, 0.0040734, -0.05313807, 0.03486542, + 0.04083064, 0.02105767, -0.04389586, -0.04302812, 0.1048641], + [2.82094529e-01, 7.05702620e-03, 3.20326265e-02, -2.88333917e-02, + 5.33638381e-03, 1.18306258e-02, -2.21964945e-04, 5.54136434e-04, + 1.25108672e-03, -4.69248914e-03, 4.30155475e-04, -1.15585609e-03, + -4.69016480e-04, 1.44523500e-03, 3.96346915e-04], + [0.28549338, 0.0978267, -0.11544838, 0.12525354, -0.00126003, + 0.00320594, 0.04744155, -0.07141446, 0.03211689, 0.04711322, + 0.08064896, 0.00154299, 0.00086506, 0.00162543, -0.00444893], + [0.28208936, -0.13133252, -0.04701012, -0.06303016, -0.0468775, + 0.02348355, 0.03991898, 0.02587433, 0.02645416, 0.00668765, + 0.00890633, 0.02189304, 0.00387415, 0.01665629, -0.01427194]]) + + box_sd_stg_actor = actor.box(centers=np.array([centers[0]]), scales=1.0) + + big_centers = np.repeat(np.array([centers[0]]), 8, axis=0) + attribute_to_actor(box_sd_stg_actor, big_centers, 'center') + + big_scales = np.repeat(np.array([scales[0]]), 8, axis=0) + attribute_to_actor(box_sd_stg_actor, big_scales, 'scale') + + big_directions = np.repeat(np.array([directions[0]]), 8, axis=0) + attribute_to_actor(box_sd_stg_actor, big_directions, 'direction') + + box_sd_stg_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniform1fv( + "coeffs", 15, coeffs[0]) + + box_sd_stg_actor3 = actor.box(centers=np.array([centers[2]]), scales=1.0) + + big_centers = np.repeat(np.array([centers[2]]), 8, axis=0) + attribute_to_actor(box_sd_stg_actor3, big_centers, 'center') + + big_scales = np.repeat(np.array([scales[2]]), 8, axis=0) + attribute_to_actor(box_sd_stg_actor3, big_scales, 'scale') + + big_directions = np.repeat(np.array([directions[2]]), 8, axis=0) + attribute_to_actor(box_sd_stg_actor3, big_directions, 'direction') + + box_sd_stg_actor3.GetShaderProperty().GetFragmentCustomUniforms().SetUniform1fv( + "coeffs", 15, coeffs[2]) + + box_sd_stg_actor2 = actor.box(centers=np.array([centers[1]]), scales=1.0) + + big_centers = np.repeat(np.array([centers[1]]), 8, axis=0) + attribute_to_actor(box_sd_stg_actor2, big_centers, 'center') + + big_scales = np.repeat(np.array([scales[1]]), 8, axis=0) + attribute_to_actor(box_sd_stg_actor2, big_scales, 'scale') + + big_directions = np.repeat(np.array([directions[1]]), 8, axis=0) + attribute_to_actor(box_sd_stg_actor2, big_directions, 'direction') + + box_sd_stg_actor2.GetShaderProperty().GetFragmentCustomUniforms().SetUniform1fv( + "coeffs", 15, coeffs[1]) + + box_sd_stg_actor4 = actor.box(centers=np.array([centers[3]]), scales=1.0) + + big_centers = np.repeat(np.array([centers[3]]), 8, axis=0) + attribute_to_actor(box_sd_stg_actor4, big_centers, 'center') + + big_scales = np.repeat(np.array([scales[3]]), 8, axis=0) + attribute_to_actor(box_sd_stg_actor4, big_scales, 'scale') + + big_directions = np.repeat(np.array([directions[3]]), 8, axis=0) + attribute_to_actor(box_sd_stg_actor4, big_directions, 'direction') + + box_sd_stg_actor4.GetShaderProperty().GetFragmentCustomUniforms(). \ + SetUniform1fv("coeffs", 15, coeffs[3]) + + vs_dec = \ + """ + in vec3 center; + in float scale; + in vec3 direction; + + out vec4 vertexMCVSOutput; + out vec3 centerMCVSOutput; + out float scaleVSOutput; + out vec3 directionVSOutput; + """ + + vs_impl = \ + """ + vertexMCVSOutput = vertexMC; + centerMCVSOutput = center; + scaleVSOutput = scale; + directionVSOutput = direction; + """ + + shader_to_actor(box_sd_stg_actor, 'vertex', decl_code=vs_dec, + impl_code=vs_impl) + shader_to_actor(box_sd_stg_actor2, 'vertex', decl_code=vs_dec, + impl_code=vs_impl) + shader_to_actor(box_sd_stg_actor3, 'vertex', decl_code=vs_dec, + impl_code=vs_impl) + shader_to_actor(box_sd_stg_actor4, 'vertex', decl_code=vs_dec, + impl_code=vs_impl) + + fs_vars_dec = \ + """ + in vec4 vertexMCVSOutput; + in vec3 centerMCVSOutput; + in float scaleVSOutput; + in vec3 directionVSOutput; + + uniform mat4 MCVCMatrix; + """ + + vec_to_vec_rot_mat = import_fury_shader(os.path.join( + 'utils', 'vec_to_vec_rot_mat.glsl')) + + sdf_map = \ + """ + + #define PI 3.1415926535898 + + // Clenshaw Legendre normalized + float Pgn(int l, int m, float x) + { + float p0 = 0., p1 = 0., p2 = 0.; + + for (int k = l; k >= 0; k--) + { + float k1 = float(k + 1); + float m1 = float(2 * m) + k1; + float m2 = float(2 * (m + k) + 1); + + p2 = p1; + p1 = p0; + + p0 = 0.; + if (l == m + k) + p0 = 1.; + + float u0 = sqrt( + (m2 * (m2 + 2.0)) / + (k1 * m1) + ); + + float u1 = sqrt( + (k1 * m1 * (m2 + 4.0)) / + ((k1 + 1.0) * (m1 + 1.0) * m2) + ); + + p0 += p1 * u0 * x; + p0 -= u1 * p2; + } + + for (int k = 1; k <= m; k++) + { + p0 *= sqrt( + (1.0 - 0.5/float(k)) * (1.0 - x) * (1.0 + x) + ); + } + + p0 *= sqrt((0.5 * float(m) + 0.25)/PI); + + return p0; + } + + float SH( in int l, in int m, in vec3 s ) + { + vec3 ns = normalize(s); + + if (m < 0) { + m = -m; + } + + // spherical coordinates + // ================================================================ + + float thetax = ns.z; + float phi = atan(ns.y, ns.x); + + // ================================================================ + + float pl = Pgn(l, m, thetax); + + float r = pow(-1.0, float(m)) * cos(float(m) * phi) * pl; + if (m != 0) { + r *= sqrt(2.0); + } + return r; + } + + vec3 map( in vec3 p ) + { + p = p - centerMCVSOutput; + + // ================================================================ + + mat4 rot = vec2VecRotMat(normalize(vec3(directionVSOutput.x, + directionVSOutput.y, 0)), + normalize(vec3(-1, 0, 0))); + p = ( rot * vec4(p, 0.0)).xyz; + + // ================================================================ + vec3 p00 = p; + + float r, d; vec3 n, s, res; + + #define SHAPE (vec3(d-abs(r), sign(r),d)) + d=length(p00); + n=p00/d; + float sc = scaleVSOutput; + r = coeffs[0]*SH(0, 0, n)*sc; + r += coeffs[1]*SH(2, -2, n)*sc; + r += coeffs[2]*SH(2, -1, n)*sc; + r += coeffs[3]*SH(2, 0, n)*sc; + r += coeffs[4]*SH(2, 1, n)*sc; + r += coeffs[5]*SH(2, 2, n)*sc; + r += coeffs[6]*SH(4, -4, n)*sc; + r += coeffs[7]*SH(4, -3, n)*sc; + r += coeffs[8]*SH(4, -2, n)*sc; + r += coeffs[9]*SH(4, -1, n)*sc; + r += coeffs[10]*SH(4, 0, n)*sc; + r += coeffs[11]*SH(4, 1, n)*sc; + r += coeffs[12]*SH(4, 2, n)*sc; + r += coeffs[13]*SH(4, 3, n)*sc; + r += coeffs[14]*SH(4, 4, n)*sc; + + s = SHAPE; res = s; + return vec3( res.x, 0.5+0.5*res.y, res.z ); + } + """ + + central_diffs_normal = \ + """ + vec3 centralDiffsNormals(in vec3 pos) + { + //vec2 e = vec2(1.0,-1.0)*0.5773*0.0005; + vec2 e = vec2(0.001, -1.0); + return normalize( e.xyy*map( pos + e.xyy ).x + + e.yyx*map( pos + e.yyx ).x + + e.yxy*map( pos + e.yxy ).x + + e.xxx*map( pos + e.xxx ).x ); + } + """ + + cast_ray = \ + """ + vec3 castRay(in vec3 ro, vec3 rd) + { + vec3 res = vec3(1e10,-1.0, 1.0); + + float maxd = 4.0; + float h = 1.0; + float t = 0.0; + vec2 m = vec2(-1.0); + for( int i=0; i<2000; i++ ) + { + if( h<0.01||t>maxd ) break; + vec3 res = map( ro+rd*t ); + h = res.x; + m = res.yz; + t += h*0.1; + } + if( t -0.5 ) + { + vec3 pos = ro + t.y * rd; + + vec3 normal = centralDiffsNormals(pos); + + float occ = clamp( 2.0*t.z, 0.0, 1.0 ); + float sss = pow( clamp( 1.0 + dot(normal, rd), 0.0, 1.0 ), 1.0 ); + + // lights + vec3 lin = 2.5*occ*vec3(1.0,1.0,1.0)*(0.6+0.4*normal.y); + lin += 1.0*sss*vec3(1.0,0.95,0.70)*occ; + + vec3 mater = 0.5*mix( vec3(1.0,1.0,0.0), vec3(1.0,1.0,1.0), t.y); + + fragOutput0 = vec4( lin, 1.0); + + } + else + { + discard; + } + """ + + shader_to_actor(box_sd_stg_actor, 'fragment', impl_code=sdf_frag_impl, + block='light') + shader_to_actor(box_sd_stg_actor2, 'fragment', impl_code=sdf_frag_impl, + block='light') + shader_to_actor(box_sd_stg_actor3, 'fragment', impl_code=sdf_frag_impl, + block='light') + shader_to_actor(box_sd_stg_actor4, 'fragment', impl_code=sdf_frag_impl, + block='light') + + show_manager = window.ShowManager(size=(700, 500)) + show_manager.scene.add(box_sd_stg_actor) + show_manager.scene.add(box_sd_stg_actor2) + show_manager.scene.add(box_sd_stg_actor3) + show_manager.scene.add(box_sd_stg_actor4) + + odf_actor = actor.odf_slicer(tensor_sf, sphere=sphere, scale=0.5, + colormap=None, opacity=.3) + show_manager.scene.add(odf_actor) + show_manager.scene.add(fodf_peaks) + + show_manager.start() \ No newline at end of file diff --git a/docs/experimental/SH-ODF experimental/texture_coefficients.py b/docs/experimental/SH-ODF experimental/texture_coefficients.py new file mode 100644 index 000000000..525f04daa --- /dev/null +++ b/docs/experimental/SH-ODF experimental/texture_coefficients.py @@ -0,0 +1,328 @@ +""" +This spript includes TEXTURE experimentation for passing SH coeffients +""" +import numpy as np +import os + +from fury.lib import Texture + +from fury import actor, window +from fury.shaders import (attribute_to_actor, compose_shader, + import_fury_shader, shader_to_actor) +from fury.utils import rgb_to_vtk + + +# ============================================================================= +def get_cubemap_from_ndarrays(array): + texture = Texture() + texture.CubeMapOn() + arr = np.ones((4, 15, 3)) + arr[:, :, 0] = array + arr[:, :, 1] = array + arr[:, :, 2] = array + print(arr) + grid = rgb_to_vtk(arr.astype(np.uint8)) + for i in range(6): + texture.SetInputDataObject(i, grid) + return texture +# ============================================================================= + + +if __name__ == '__main__': + centers = np.array([[0, -1, 0], [1.0, -1, 0], [2.0, -1, 0], [3.0, -1, 0]]) + vecs = np.array([[0, 1, 0], [0, 1, 0], [0, 1, 0], [0, 1, 0]]) + colors = np.array([[0, 0, 1], [0, 1, 0], [1, 0, 0], [0, 1, 0]]) + vals = np.array([1.0, 4.2, 1.5, 2.0]) + coeffs = np.array( + [[0.2820735, 0.15236554, -0.04038717, -0.11270988, -0.04532376, + 0.14921817, 0.00257928, 0.0040734, -0.05313807, 0.03486542, + 0.04083064, 0.02105767, -0.04389586, -0.04302812, 0.1048641], + [2.82094529e-01, 7.05702620e-03, 3.20326265e-02, -2.88333917e-02, + 5.33638381e-03, 1.18306258e-02, -2.21964945e-04, 5.54136434e-04, + 1.25108672e-03, -4.69248914e-03, 4.30155475e-04, -1.15585609e-03, + -4.69016480e-04, 1.44523500e-03, 3.96346915e-04], + [0.28549338, 0.0978267, -0.11544838, 0.12525354, -0.00126003, + 0.00320594, 0.04744155, -0.07141446, 0.03211689, 0.04711322, + 0.08064896, 0.00154299, 0.00086506, 0.00162543, -0.00444893], + [0.28208936, -0.13133252, -0.04701012, -0.06303016, -0.0468775, + 0.02348355, 0.03991898, 0.02587433, 0.02645416, 0.00668765, + 0.00890633, 0.02189304, 0.00387415, 0.01665629, -0.01427194]]) + + # coeffs = coeffs / np.max(coeffs) + + box_sd_stg_actor = actor.box(centers=np.array([centers[0]]), scales=1.0) + + big_centers = np.repeat(np.array([centers[0]]), 8, axis=0) + attribute_to_actor(box_sd_stg_actor, big_centers, 'center') + + big_scales = np.repeat(np.array([vals[2]]), 8, axis=0) + attribute_to_actor(box_sd_stg_actor, big_scales, 'scale') + + box_sd_stg_actor.GetShaderProperty().GetFragmentCustomUniforms(). \ + SetUniform1fv("coeffs", 15, coeffs[2]) + + # ========================================================================= + data_tex = np.array( + [[.5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5], + [.5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5], + [.5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5], + [.5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5]]) # *200 + + data = get_cubemap_from_ndarrays(np.array(data_tex)) + + box_sd_stg_actor.SetTexture(data) + # ========================================================================= + + vs_dec = \ + """ + in vec3 center; + in float scale; + + out vec4 vertexMCVSOutput; + out vec3 centerMCVSOutput; + out float scaleVSOutput; + """ + + vs_impl = \ + """ + vertexMCVSOutput = vertexMC; + centerMCVSOutput = center; + scaleVSOutput = scale; + vec3 camPos = -MCVCMatrix[3].xyz * mat3(MCVCMatrix); + """ + + shader_to_actor(box_sd_stg_actor, 'vertex', decl_code=vs_dec, + impl_code=vs_impl) + + fs_vars_dec = \ + """ + in vec4 vertexMCVSOutput; + in vec3 centerMCVSOutput; + in float scaleVSOutput; + uniform samplerCube texture_0; + + uniform mat4 MCVCMatrix; + """ + + sdf_map = \ + """ + + #define PI 3.1415926535898 + + // Clenshaw Legendre normalized + float Pgn(int l, int m, float x) + { + float p0 = 0., p1 = 0., p2 = 0.; + + for (int k = l; k >= 0; k--) + { + float k1 = float(k + 1); + float m1 = float(2 * m) + k1; + float m2 = float(2 * (m + k) + 1); + + p2 = p1; + p1 = p0; + + p0 = 0.; + if (l == m + k) + p0 = 1.; + + float u0 = sqrt( + (m2 * (m2 + 2.0)) / + (k1 * m1) + ); + + float u1 = sqrt( + (k1 * m1 * (m2 + 4.0)) / + ((k1 + 1.0) * (m1 + 1.0) * m2) + ); + + p0 += p1 * u0 * x; + p0 -= u1 * p2; + } + + for (int k = 1; k <= m; k++) + { + p0 *= sqrt( + (1.0 - 0.5/float(k)) * (1.0 - x) * (1.0 + x) + ); + } + + p0 *= sqrt((0.5 * float(m) + 0.25)/PI); + + return p0; + } + + float SH( in int l, in int m, in vec3 s ) + { + vec3 ns = normalize(s); + + if (m < 0) { + m = -m; + } + + // spherical coordinates + float thetax = ns.y; + float phi = atan(ns.z, ns.x)+PI/2.; + + float pl = Pgn(l, m, thetax); + + float r = pow(-1.0, float(m)) * cos(float(m) * phi) * pl; + if (m != 0) { + r *= sqrt(2.0); + } + return r; + } + + vec3 map( in vec3 p ) + { + p = p - centerMCVSOutput; + vec3 p00 = p; + + float r, d; vec3 n, s, res; + + #define SHAPE (vec3(d-abs(r), sign(r),d)) + //#define SHAPE (vec3(d-0.35, -1.0+2.0*clamp(0.5 + 16.0*r,0.0,1.0),d)) + d=length(p00); + n=p00/d; + float sc = scaleVSOutput; + r = coeffs[0]*SH(0, 0, n)*sc; + r += coeffs[1]*SH(2, -2, n)*sc; + r += coeffs[2]*SH(2, -1, n)*sc; + r += coeffs[3]*SH(2, 0, n)*sc; + r += coeffs[4]*SH(2, 1, n)*sc; + r += coeffs[5]*SH(2, 2, n)*sc; + r += coeffs[6]*SH(4, -4, n)*sc; + r += coeffs[7]*SH(4, -3, n)*sc; + r += coeffs[8]*SH(4, -2, n)*sc; + r += coeffs[9]*SH(4, -1, n)*sc; + r += coeffs[10]*SH(4, 0, n)*sc; + r += coeffs[11]*SH(4, 1, n)*sc; + r += coeffs[12]*SH(4, 2, n)*sc; + r += coeffs[13]*SH(4, 3, n)*sc; + r += coeffs[14]*SH(4, 4, n)*sc; + + s = SHAPE; res = s; + return vec3( res.x, 0.5+0.5*res.y, res.z ); + } + """ + + central_diffs_normal = \ + """ + vec3 centralDiffsNormals(in vec3 pos) + { + //vec2 e = vec2(1.0,-1.0)*0.5773*0.0005; + vec2 e = vec2(0.001, -1.0); + return normalize( e.xyy*map( pos + e.xyy ).x + + e.yyx*map( pos + e.yyx ).x + + e.yxy*map( pos + e.yxy ).x + + e.xxx*map( pos + e.xxx ).x ); + } + """ + + cast_ray = \ + """ + vec3 castRay(in vec3 ro, vec3 rd) + { + vec3 res = vec3(1e10,-1.0, 1.0); + + float maxd = 4.0; + float h = 1.0; + float t = 0.0; + vec2 m = vec2(-1.0); + for( int i=0; i<2000; i++ ) + { + if( h<0.01||t>maxd ) break; + vec3 res = map( ro+rd*t ); + h = res.x; + m = res.yz; + t += h*0.1; + } + if( t -0.5 ) + { + vec3 pos = ro + t.y * rd; + + vec3 normal = centralDiffsNormals(pos); + + float occ = clamp( 2.0*t.z, 0.0, 1.0 ); + float sss = pow( clamp( 1.0 + dot(normal, rd), 0.0, 1.0 ), 1.0 ); + + // lights + vec3 lin = 2.5*occ*vec3(1.0,1.0,1.0)*(0.6+0.4*normal.y); + lin += 1.0*sss*vec3(1.0,0.95,0.70)*occ; + + vec3 mater = 0.5*mix( vec3(1.0,1.0,0.0), vec3(1.0,1.0,1.0), t.y); + + // ================================================================ + // get random coefficient from texture + vec4 texData1 = texture(texture_0, vec3(.5, .5, .5)); + fragOutput0 = vec4( texData1.xyz, 1.0); + // ================================================================ + } + else + { + discard; + } + + + """ + + shader_to_actor(box_sd_stg_actor, 'fragment', impl_code=sdf_frag_impl, + block='light') + + show_manager = window.ShowManager(size=(700, 500)) + show_manager.scene.background([255, 255, 255]) + show_manager.scene.add(box_sd_stg_actor) + + from dipy.reconst.shm import sh_to_sf + from dipy.data import get_sphere + + sphere = get_sphere('repulsion724') + + sh_basis = 'descoteaux07' + sh_order = 4 + tensor_sh = coeffs = np.array( + [[[[0.28549338, 0.0978267, -0.11544838, 0.12525354, -0.00126003, + 0.00320594, 0.04744155, -0.07141446, 0.03211689, 0.04711322, + 0.08064896, 0.00154299, 0.00086506, 0.00162543, -0.00444893]]]]) + tensor_sf = sh_to_sf(tensor_sh, sh_order=4, basis_type='descoteaux07', + sphere=sphere) + + odf_actor = actor.odf_slicer(tensor_sf, sphere=sphere, scale=0.5, + colormap='plasma') + show_manager.scene.add(odf_actor) + + show_manager.start() From 5c7269193e9b6837c104e338ac5a5cbfcb1deef5 Mon Sep 17 00:00:00 2001 From: Tania Castillo <31288525+tvcastillod@users.noreply.github.com> Date: Wed, 4 Oct 2023 09:42:41 -0500 Subject: [PATCH 007/118] added file for experimentation with textures --- .../SH-ODF experimental/texture_data_test.py | 264 ++++++++++++++++++ 1 file changed, 264 insertions(+) create mode 100644 docs/experimental/SH-ODF experimental/texture_data_test.py diff --git a/docs/experimental/SH-ODF experimental/texture_data_test.py b/docs/experimental/SH-ODF experimental/texture_data_test.py new file mode 100644 index 000000000..0717d0034 --- /dev/null +++ b/docs/experimental/SH-ODF experimental/texture_data_test.py @@ -0,0 +1,264 @@ +import os + +import numpy as np + +from fury import actor, window +from fury.lib import FloatArray, ImageData, Texture, numpy_support +from fury.shaders import ( + attribute_to_actor, + compose_shader, + import_fury_shader, + shader_to_actor, +) +from fury.utils import set_polydata_tcoords + + +def np_array_to_vtk_img(data): + grid = ImageData() + grid.SetDimensions(data.shape[1], data.shape[0], 1) + nd = data.shape[-1] if data.ndim == 3 else 1 + vtkarr = numpy_support.numpy_to_vtk( + np.flip(data.swapaxes(0, 1), axis=1).reshape((-1, nd), order="F") + ) + vtkarr.SetName("Image") + grid.GetPointData().AddArray(vtkarr) + grid.GetPointData().SetActiveScalars("Image") + grid.GetPointData().Update() + return grid + + +if __name__ == "__main__": + scene = window.Scene() + scene.background((1, 1, 1)) + + centers = np.array([[-3.2, 0.9, 0.4], [-3.5, -0.5, 1], [-2.1, 0, 0.4]]) + # TODO: Add to texure + dirs = np.array([[-0.2, 0.9, 0.4], [-0.5, -0.5, 1], [0.9, 0, 0.4]]) + # TODO: Compare against setting texture coordinates + ids = np.array([1.0, 2.0, 3.0]) + + box_actor = actor.box(centers=centers, directions=dirs) + + rep_centers = np.repeat(centers, 8, axis=0) + rep_directions = np.repeat(dirs, 8, axis=0) + rep_ids = np.repeat(ids, 8, axis=0) + + attribute_to_actor(box_actor, rep_centers, "center") + + attribute_to_actor(box_actor, rep_directions, "direction") + attribute_to_actor(box_actor, rep_ids, "id") + + #-------------------------------------------------------------------------- + centers = np.array( + [[-2.5, -2, 0], [-1, -2, 0], [1, -2, 0]] + ) + scales = [0.5, 0.5, 0.5] + + texture_actor = actor.billboard(centers, colors=(1, 1, 1), scales=scales) + actor_pd = texture_actor.GetMapper().GetInput() + actor_box = box_actor.GetMapper().GetInput() + + uv_vals = np.array( + [ + #[0, 0], [0, 1], [1, 1], [1, 0], + [0, 2/3], [0, 1], [1, 1], [1, 2/3], # Top left color + [0, 1/3], [0, 2/3], [1, 2/3], [1, 1/3], # Top right color + [0, 0], [0, 1/3], [1, 1/3], [1, 0], # Bottom left color + ] + ) + # fmt: on + + num_pnts = uv_vals.shape[0] + + t_coords = FloatArray() + t_coords.SetNumberOfComponents(2) + t_coords.SetNumberOfTuples(num_pnts) + + [t_coords.SetTuple(i, uv_vals[i]) for i in range(num_pnts)] + set_polydata_tcoords(actor_pd, t_coords) + + uv_vals2 = np.array( + [ + [0, 2 / 3], [0, 1], [1, 1], [1, 2 / 3], [0, 2 / 3], [0, 1], [1, 1], [1, 2 / 3], + [0, 1 / 3], [0, 2 / 3], [1, 2 / 3], [1, 1 / 3], [0, 1 / 3], [0, 2 / 3], [1, 2 / 3], [1, 1 / 3], # Top right color + [0, 0], [0, 1 / 3], [1, 1 / 3], [1, 0], [0, 0], [0, 1 / 3], [1, 1 / 3], [1, 0], # Bottom left color + ] + ) + + num_pnts2 = uv_vals2.shape[0] + + t_coords2 = FloatArray() + t_coords2.SetNumberOfComponents(2) + t_coords2.SetNumberOfTuples(num_pnts2) + [t_coords2.SetTuple(i, uv_vals2[i]) for i in range(num_pnts2)] + + set_polydata_tcoords(actor_box, t_coords2) + + #-------------------------------------------------------------------------- + + # We organize the data of color, radius and height of the cylinders in a + # grid of 3x5 which is then encoded as a 2D texture. + # Data has to be multiplied by 255 to be in range 0-255, since inside the + # shader a map is done for the values to be in range 0-1. + # ?: values are divided by 255. + # TODO: Verify color range inside the shader. + arr = ( + np.array( + #[[.5, .5, .5, .5, .5], [.4, .4, .4, .4, .4], [.3, .3, .3, .3, .3]] + [[1, 0, 0, 0.5, 0.5], [0, 1, 0, 0.3, 0.75], [0, 0, 1, 0.1, 1]] + ) + * 255 + ) + # grid = rgb_to_vtk(arr.astype(np.uint8)) + grid = np_array_to_vtk_img(arr.astype(np.uint8)) + + texture = Texture() + texture.SetInputDataObject(grid) + texture.Update() + + box_actor.GetProperty().SetTexture("texture0", texture) + texture_actor.SetTexture(texture) + # box_actor.SetTexture(texture) # Look for actortexture in GLSL + + box_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniformf("n", 5) + + vs_dec = """ + in vec3 center; + in vec3 direction; + in float id; + + out vec4 vertexMCVSOutput; + out vec3 centerMCVSOutput; + out vec3 directionVSOutput; + out float idVSOutput; + """ + + vs_impl = """ + vertexMCVSOutput = vertexMC; + centerMCVSOutput = center; + directionVSOutput = direction; + idVSOutput = id; + """ + + shader_to_actor(box_actor, "vertex", decl_code=vs_dec, impl_code=vs_impl) + + fs_vars_dec = """ + in vec4 vertexMCVSOutput; + in vec3 centerMCVSOutput; + in vec3 directionVSOutput; + in float idVSOutput; + + uniform mat4 MCVCMatrix; + """ + + vec_to_vec_rot_mat = import_fury_shader( + os.path.join("utils", "vec_to_vec_rot_mat.glsl") + ) + + sd_cylinder = import_fury_shader(os.path.join("sdf", "sd_cylinder.frag")) + + sdf_map = """ + float map(in vec3 position) + { + mat4 rot = vec2VecRotMat( + normalize(directionVSOutput), normalize(vec3(0, 1, 0))); + vec3 pos = (rot * vec4(position - centerMCVSOutput, 0.0)).xyz; + + // GET RADIUS AND HEIGHT FROM TEXTURE ----------------------------- + // .7 and .9 corresponds to the 4 and 5 column from the 2D texture + // which have the data of the radius and height respectively. + // idVSOutput is used to identify each element from the actor, + // that is, which row from the 2D texture. + // we subtract .01 from the final y coordinate since the border + // color corresponds to the adjacent tile. + + //vec4 tcolor_0 = texture(texture0, tcoordVCVSOutput); // Read texture color + + //float r = texture(texture0, vec2(.7, 1/idVSOutput-.01)).x; + //float h = texture(texture0, vec2(.9, 1/idVSOutput-.01)).x; + + float i = 1/(n*2); + float r = texture(texture0, vec2(i+3/n, tcoordVCVSOutput.y)).x; + float h = texture(texture0, vec2(i+4/n, tcoordVCVSOutput.y)).x; + // ---------------------------------------------------------------- + return sdCylinder(pos, r, h / 2); + } + """ + + central_diffs_normal = import_fury_shader( + os.path.join("sdf", "central_diffs.frag") + ) + + cast_ray = import_fury_shader( + os.path.join("ray_marching", "cast_ray.frag") + ) + + blinn_phong_model = import_fury_shader( + os.path.join("lighting", "blinn_phong_model.frag") + ) + + fs_dec = compose_shader( + [ + fs_vars_dec, + vec_to_vec_rot_mat, + sd_cylinder, + sdf_map, + central_diffs_normal, + cast_ray, + blinn_phong_model, + ] + ) + + shader_to_actor(box_actor, "fragment", decl_code=fs_dec) + + sdf_cylinder_frag_impl = """ + vec3 point = vertexMCVSOutput.xyz; + + vec4 ro = -MCVCMatrix[3] * MCVCMatrix; + vec3 rd = normalize(point - ro.xyz); + vec3 ld = normalize(ro.xyz - point); + + ro += vec4((point - ro.xyz), 0); + float t = castRay(ro.xyz, rd); + + if(t < 20.0) + { + vec3 position = ro.xyz + t * rd; + vec3 normal = centralDiffsNormals(position, .0001); + float lightAttenuation = dot(ld, normal); + + // GET COLOR FROM TEXTURE ----------------------------------------- + // .1, .3 and .5 corresponds to the 1, 2 and 3 column from the 2D + // texture which have the data of the RGB color. + float data = texture(texture0, vec2(.1, 1/2-.01)).x; + + + //float cR = texture(texture0, vec2(.1, 1/idVSOutput-.01)).x; + //float cG = texture(texture0, vec2(.3, 1/idVSOutput-.01)).x; + //float cB = texture(texture0, vec2(.5, 1/idVSOutput-.01)).x; + + float i = 1/(n*2); + float cR = texture(texture0, vec2(i, tcoordVCVSOutput.y)).x; + float cG = texture(texture0, vec2(i+1/n, tcoordVCVSOutput.y)).x; + float cB = texture(texture0, vec2(i+2/n, tcoordVCVSOutput.y)).x; + vec3 cylinderColor = vec3(cR, cG, cB); + // ---------------------------------------------------------------- + vec3 color = blinnPhongIllumModel( + lightAttenuation, lightColor0, cylinderColor, specularPower, + specularColor, ambientColor); + fragOutput0 = vec4(cylinderColor, opacity); + } + else + { + discard; + } + """ + + shader_to_actor( + box_actor, "fragment", impl_code=sdf_cylinder_frag_impl, block="light", + debug=False) + + scene.add(box_actor) + scene.add(texture_actor) + + window.show(scene) From 67c231c7cd8954c33f9df2554be1a922479cbff2 Mon Sep 17 00:00:00 2001 From: Tania Castillo <31288525+tvcastillod@users.noreply.github.com> Date: Fri, 6 Oct 2023 18:41:13 -0500 Subject: [PATCH 008/118] updated files --- .../texture_coefficients.py | 143 ++++++++++-------- .../SH-ODF experimental/texture_data_test.py | 4 +- 2 files changed, 81 insertions(+), 66 deletions(-) diff --git a/docs/experimental/SH-ODF experimental/texture_coefficients.py b/docs/experimental/SH-ODF experimental/texture_coefficients.py index 525f04daa..18adfeb2c 100644 --- a/docs/experimental/SH-ODF experimental/texture_coefficients.py +++ b/docs/experimental/SH-ODF experimental/texture_coefficients.py @@ -4,43 +4,23 @@ import numpy as np import os -from fury.lib import Texture +from fury.lib import Texture, FloatArray from fury import actor, window from fury.shaders import (attribute_to_actor, compose_shader, import_fury_shader, shader_to_actor) -from fury.utils import rgb_to_vtk - - -# ============================================================================= -def get_cubemap_from_ndarrays(array): - texture = Texture() - texture.CubeMapOn() - arr = np.ones((4, 15, 3)) - arr[:, :, 0] = array - arr[:, :, 1] = array - arr[:, :, 2] = array - print(arr) - grid = rgb_to_vtk(arr.astype(np.uint8)) - for i in range(6): - texture.SetInputDataObject(i, grid) - return texture -# ============================================================================= +from fury.utils import numpy_to_vtk_image_data, set_polydata_tcoords if __name__ == '__main__': - centers = np.array([[0, -1, 0], [1.0, -1, 0], [2.0, -1, 0], [3.0, -1, 0]]) - vecs = np.array([[0, 1, 0], [0, 1, 0], [0, 1, 0], [0, 1, 0]]) - colors = np.array([[0, 0, 1], [0, 1, 0], [1, 0, 0], [0, 1, 0]]) - vals = np.array([1.0, 4.2, 1.5, 2.0]) + centers = np.array([[0, -1, 0], [1.0, -1, 0], [2.0, -1, 0]]) + vecs = np.array([[0, 1, 0], [0, 1, 0], [0, 1, 0]]) + colors = np.array([[0, 0, 1], [0, 1, 0], [1, 0, 0]]) + vals = np.array([.2, .4, .3]) coeffs = np.array( [[0.2820735, 0.15236554, -0.04038717, -0.11270988, -0.04532376, 0.14921817, 0.00257928, 0.0040734, -0.05313807, 0.03486542, 0.04083064, 0.02105767, -0.04389586, -0.04302812, 0.1048641], - [2.82094529e-01, 7.05702620e-03, 3.20326265e-02, -2.88333917e-02, - 5.33638381e-03, 1.18306258e-02, -2.21964945e-04, 5.54136434e-04, - 1.25108672e-03, -4.69248914e-03, 4.30155475e-04, -1.15585609e-03, - -4.69016480e-04, 1.44523500e-03, 3.96346915e-04], [0.28549338, 0.0978267, -0.11544838, 0.12525354, -0.00126003, 0.00320594, 0.04744155, -0.07141446, 0.03211689, 0.04711322, 0.08064896, 0.00154299, 0.00086506, 0.00162543, -0.00444893], @@ -48,29 +28,58 @@ def get_cubemap_from_ndarrays(array): 0.02348355, 0.03991898, 0.02587433, 0.02645416, 0.00668765, 0.00890633, 0.02189304, 0.00387415, 0.01665629, -0.01427194]]) - # coeffs = coeffs / np.max(coeffs) + box_sd_stg_actor = actor.box(centers=centers, scales=1.0) - box_sd_stg_actor = actor.box(centers=np.array([centers[0]]), scales=1.0) - - big_centers = np.repeat(np.array([centers[0]]), 8, axis=0) + big_centers = np.repeat(centers, 8, axis=0) attribute_to_actor(box_sd_stg_actor, big_centers, 'center') - big_scales = np.repeat(np.array([vals[2]]), 8, axis=0) + big_scales = np.repeat(vals, 8, axis=0) attribute_to_actor(box_sd_stg_actor, big_scales, 'scale') - box_sd_stg_actor.GetShaderProperty().GetFragmentCustomUniforms(). \ - SetUniform1fv("coeffs", 15, coeffs[2]) - # ========================================================================= - data_tex = np.array( - [[.5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5], - [.5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5], - [.5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5], - [.5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5]]) # *200 - data = get_cubemap_from_ndarrays(np.array(data_tex)) + actor_box = box_sd_stg_actor.GetMapper().GetInput() + + uv_vals = np.array( + [ + [0, 2 / 3], [0, 1], [1, 1], [1, 2 / 3], [0, 2 / 3], [0, 1], [1, 1], [1, 2 / 3], #glyph1 + [0, 1 / 3], [0, 2 / 3], [1, 2 / 3], [1, 1 / 3], [0, 1 / 3], [0, 2 / 3], [1, 2 / 3], [1, 1 / 3], #glyph2 + [0, 0], [0, 1 / 3], [1, 1 / 3], [1, 0], [0, 0], [0, 1 / 3], [1, 1 / 3], [1, 0], #glyph3 + ] + ) + + num_pnts = uv_vals.shape[0] + + t_coords = FloatArray() + t_coords.SetNumberOfComponents(2) + t_coords.SetNumberOfTuples(num_pnts) + [t_coords.SetTuple(i, uv_vals[i]) for i in range(num_pnts)] + + set_polydata_tcoords(actor_box, t_coords) + + arr = ( + np.array( + [[0.2820735, 0.15236554, -0.04038717, -0.11270988, -0.04532376, + 0.14921817, 0.00257928, 0.0040734, -0.05313807, 0.03486542, + 0.04083064, 0.02105767, -0.04389586, -0.04302812, 0.1048641], + [0.28549338, 0.0978267, -0.11544838, 0.12525354, -0.00126003, + 0.00320594, 0.04744155, -0.07141446, 0.03211689, 0.04711322, + 0.08064896, 0.00154299, 0.00086506, 0.00162543, -0.00444893], + [0.28208936, -0.13133252, -0.04701012, -0.06303016, + -0.0468775, 0.02348355, 0.03991898, 0.02587433, 0.02645416, + 0.00668765, 0.00890633, 0.02189304, 0.00387415, 0.01665629, + -0.01427194]]) + * 255 + ) + grid = numpy_to_vtk_image_data(arr.astype(np.uint8)) - box_sd_stg_actor.SetTexture(data) + texture = Texture() + texture.SetInputDataObject(grid) + texture.Update() + + box_sd_stg_actor.GetProperty().SetTexture("texture0", texture) + box_sd_stg_actor.GetShaderProperty().GetFragmentCustomUniforms()\ + .SetUniformf("k", 15) # number of coefficients per glyph # ========================================================================= vs_dec = \ @@ -186,22 +195,24 @@ def get_cubemap_from_ndarrays(array): d=length(p00); n=p00/d; float sc = scaleVSOutput; - r = coeffs[0]*SH(0, 0, n)*sc; - r += coeffs[1]*SH(2, -2, n)*sc; - r += coeffs[2]*SH(2, -1, n)*sc; - r += coeffs[3]*SH(2, 0, n)*sc; - r += coeffs[4]*SH(2, 1, n)*sc; - r += coeffs[5]*SH(2, 2, n)*sc; - r += coeffs[6]*SH(4, -4, n)*sc; - r += coeffs[7]*SH(4, -3, n)*sc; - r += coeffs[8]*SH(4, -2, n)*sc; - r += coeffs[9]*SH(4, -1, n)*sc; - r += coeffs[10]*SH(4, 0, n)*sc; - r += coeffs[11]*SH(4, 1, n)*sc; - r += coeffs[12]*SH(4, 2, n)*sc; - r += coeffs[13]*SH(4, 3, n)*sc; - r += coeffs[14]*SH(4, 4, n)*sc; - + // ================================================================ + float i = 1/(k*2); + r = texture(texture0, vec2(i, tcoordVCVSOutput.y)).x*SH(0, 0, n)*sc; + r += texture(texture0, vec2(i+1/k, tcoordVCVSOutput.y)).x*SH(2, -2, n)*sc; + r += texture(texture0, vec2(i+2/k, tcoordVCVSOutput.y)).x*SH(2, -1, n)*sc; + r += texture(texture0, vec2(i+3/k, tcoordVCVSOutput.y)).x*SH(2, 0, n)*sc; + r += texture(texture0, vec2(i+4/k, tcoordVCVSOutput.y)).x*SH(2, 1, n)*sc; + r += texture(texture0, vec2(i+5/k, tcoordVCVSOutput.y)).x*SH(2, 2, n)*sc; + r += texture(texture0, vec2(i+6/k, tcoordVCVSOutput.y)).x*SH(4, -4, n)*sc; + r += texture(texture0, vec2(i+7/k, tcoordVCVSOutput.y)).x*SH(4, -3, n)*sc; + r += texture(texture0, vec2(i+8/k, tcoordVCVSOutput.y)).x*SH(4, -2, n)*sc; + r += texture(texture0, vec2(i+9/k, tcoordVCVSOutput.y)).x*SH(4, -1, n)*sc; + r += texture(texture0, vec2(i+10/k, tcoordVCVSOutput.y)).x*SH(4, 0, n)*sc; + r += texture(texture0, vec2(i+11/k, tcoordVCVSOutput.y)).x*SH(4, 1, n)*sc; + r += texture(texture0, vec2(i+12/k, tcoordVCVSOutput.y)).x*SH(4, 2, n)*sc; + r += texture(texture0, vec2(i+13/k, tcoordVCVSOutput.y)).x*SH(4, 3, n)*sc; + r += texture(texture0, vec2(i+14/k, tcoordVCVSOutput.y)).x*SH(4, 4, n)*sc; + // ================================================================ s = SHAPE; res = s; return vec3( res.x, 0.5+0.5*res.y, res.z ); } @@ -251,7 +262,7 @@ def get_cubemap_from_ndarrays(array): fs_dec = compose_shader([fs_vars_dec, sdf_map, central_diffs_normal, cast_ray, blinn_phong_model]) - shader_to_actor(box_sd_stg_actor, 'fragment', decl_code=fs_dec) + shader_to_actor(box_sd_stg_actor, 'fragment', decl_code=fs_dec, debug=False) sdf_frag_impl = \ """ @@ -287,9 +298,7 @@ def get_cubemap_from_ndarrays(array): vec3 mater = 0.5*mix( vec3(1.0,1.0,0.0), vec3(1.0,1.0,1.0), t.y); // ================================================================ - // get random coefficient from texture - vec4 texData1 = texture(texture_0, vec3(.5, .5, .5)); - fragOutput0 = vec4( texData1.xyz, 1.0); + fragOutput0 = vec4( mater, 1.0); // ================================================================ } else @@ -301,7 +310,7 @@ def get_cubemap_from_ndarrays(array): """ shader_to_actor(box_sd_stg_actor, 'fragment', impl_code=sdf_frag_impl, - block='light') + block='picking') show_manager = window.ShowManager(size=(700, 500)) show_manager.scene.background([255, 255, 255]) @@ -315,9 +324,15 @@ def get_cubemap_from_ndarrays(array): sh_basis = 'descoteaux07' sh_order = 4 tensor_sh = coeffs = np.array( - [[[[0.28549338, 0.0978267, -0.11544838, 0.12525354, -0.00126003, + [[[[0.2820735, 0.15236554, -0.04038717, -0.11270988, -0.04532376, + 0.14921817, 0.00257928, 0.0040734, -0.05313807, 0.03486542, + 0.04083064, 0.02105767, -0.04389586, -0.04302812, 0.1048641]]], + [[[0.28549338, 0.0978267, -0.11544838, 0.12525354, -0.00126003, 0.00320594, 0.04744155, -0.07141446, 0.03211689, 0.04711322, - 0.08064896, 0.00154299, 0.00086506, 0.00162543, -0.00444893]]]]) + 0.08064896, 0.00154299, 0.00086506, 0.00162543, -0.00444893]]], + [[[0.28208936, -0.13133252, -0.04701012, -0.06303016, -0.0468775, + 0.02348355, 0.03991898, 0.02587433, 0.02645416, 0.00668765, + 0.00890633, 0.02189304, 0.00387415, 0.01665629, -0.01427194]]]]) tensor_sf = sh_to_sf(tensor_sh, sh_order=4, basis_type='descoteaux07', sphere=sphere) diff --git a/docs/experimental/SH-ODF experimental/texture_data_test.py b/docs/experimental/SH-ODF experimental/texture_data_test.py index 0717d0034..3189e7b71 100644 --- a/docs/experimental/SH-ODF experimental/texture_data_test.py +++ b/docs/experimental/SH-ODF experimental/texture_data_test.py @@ -10,7 +10,7 @@ import_fury_shader, shader_to_actor, ) -from fury.utils import set_polydata_tcoords +from fury.utils import set_polydata_tcoords, numpy_to_vtk_image_data def np_array_to_vtk_img(data): @@ -110,7 +110,7 @@ def np_array_to_vtk_img(data): * 255 ) # grid = rgb_to_vtk(arr.astype(np.uint8)) - grid = np_array_to_vtk_img(arr.astype(np.uint8)) + grid = numpy_to_vtk_image_data(arr.astype(np.uint8)) texture = Texture() texture.SetInputDataObject(grid) From fb1f6e24b98abb66ff30855ec710acb2173cc8c0 Mon Sep 17 00:00:00 2001 From: Tania Castillo <31288525+tvcastillod@users.noreply.github.com> Date: Mon, 9 Oct 2023 23:10:18 -0500 Subject: [PATCH 009/118] passing coefficients through texture with few glyphs --- .../texture_coefficients.py | 85 ++++++++++++++----- 1 file changed, 65 insertions(+), 20 deletions(-) diff --git a/docs/experimental/SH-ODF experimental/texture_coefficients.py b/docs/experimental/SH-ODF experimental/texture_coefficients.py index 18adfeb2c..4856ab648 100644 --- a/docs/experimental/SH-ODF experimental/texture_coefficients.py +++ b/docs/experimental/SH-ODF experimental/texture_coefficients.py @@ -16,7 +16,7 @@ centers = np.array([[0, -1, 0], [1.0, -1, 0], [2.0, -1, 0]]) vecs = np.array([[0, 1, 0], [0, 1, 0], [0, 1, 0]]) colors = np.array([[0, 0, 1], [0, 1, 0], [1, 0, 0]]) - vals = np.array([.2, .4, .3]) + vals = np.array([1.0, 2.0, 2.0]) coeffs = np.array( [[0.2820735, 0.15236554, -0.04038717, -0.11270988, -0.04532376, 0.14921817, 0.00257928, 0.0040734, -0.05313807, 0.03486542, @@ -69,8 +69,14 @@ -0.0468775, 0.02348355, 0.03991898, 0.02587433, 0.02645416, 0.00668765, 0.00890633, 0.02189304, 0.00387415, 0.01665629, -0.01427194]]) - * 255 ) + min = -1 + max = 1 + newmin = 0 + newmax = 1 + arr = (arr - min)*((newmax - newmin) / (max - min)) + newmin + print(arr) + arr *= 255 grid = numpy_to_vtk_image_data(arr.astype(np.uint8)) texture = Texture() @@ -182,6 +188,15 @@ } return r; } + + float coef_norm( in float coef) + { + float min = 0; + float max = 1; + float newmin = -1; + float newmax = 1; + return (coef - min) * ((newmax - newmin) / (max - min)) + newmin; + } vec3 map( in vec3 p ) { @@ -193,25 +208,55 @@ #define SHAPE (vec3(d-abs(r), sign(r),d)) //#define SHAPE (vec3(d-0.35, -1.0+2.0*clamp(0.5 + 16.0*r,0.0,1.0),d)) d=length(p00); - n=p00/d; - float sc = scaleVSOutput; + n=p00/d; // ================================================================ float i = 1/(k*2); - r = texture(texture0, vec2(i, tcoordVCVSOutput.y)).x*SH(0, 0, n)*sc; - r += texture(texture0, vec2(i+1/k, tcoordVCVSOutput.y)).x*SH(2, -2, n)*sc; - r += texture(texture0, vec2(i+2/k, tcoordVCVSOutput.y)).x*SH(2, -1, n)*sc; - r += texture(texture0, vec2(i+3/k, tcoordVCVSOutput.y)).x*SH(2, 0, n)*sc; - r += texture(texture0, vec2(i+4/k, tcoordVCVSOutput.y)).x*SH(2, 1, n)*sc; - r += texture(texture0, vec2(i+5/k, tcoordVCVSOutput.y)).x*SH(2, 2, n)*sc; - r += texture(texture0, vec2(i+6/k, tcoordVCVSOutput.y)).x*SH(4, -4, n)*sc; - r += texture(texture0, vec2(i+7/k, tcoordVCVSOutput.y)).x*SH(4, -3, n)*sc; - r += texture(texture0, vec2(i+8/k, tcoordVCVSOutput.y)).x*SH(4, -2, n)*sc; - r += texture(texture0, vec2(i+9/k, tcoordVCVSOutput.y)).x*SH(4, -1, n)*sc; - r += texture(texture0, vec2(i+10/k, tcoordVCVSOutput.y)).x*SH(4, 0, n)*sc; - r += texture(texture0, vec2(i+11/k, tcoordVCVSOutput.y)).x*SH(4, 1, n)*sc; - r += texture(texture0, vec2(i+12/k, tcoordVCVSOutput.y)).x*SH(4, 2, n)*sc; - r += texture(texture0, vec2(i+13/k, tcoordVCVSOutput.y)).x*SH(4, 3, n)*sc; - r += texture(texture0, vec2(i+14/k, tcoordVCVSOutput.y)).x*SH(4, 4, n)*sc; + float c = texture(texture0, vec2(i, tcoordVCVSOutput.y)).x; + r = coef_norm(c)*SH(0, 0, n); + + c = texture(texture0, vec2(i+1/k, tcoordVCVSOutput.y)).x; + r += coef_norm(c)*SH(2, -2, n); + + c = texture(texture0, vec2(i+2/k, tcoordVCVSOutput.y)).x; + r += coef_norm(c)*SH(2, -1, n); + + c = texture(texture0, vec2(i+3/k, tcoordVCVSOutput.y)).x; + r += coef_norm(c)*SH(2, 0, n); + + c = texture(texture0, vec2(i+4/k, tcoordVCVSOutput.y)).x; + r += coef_norm(c)*SH(2, 1, n); + + c = texture(texture0, vec2(i+5/k, tcoordVCVSOutput.y)).x; + r += coef_norm(c)*SH(2, 2, n); + + c = texture(texture0, vec2(i+6/k, tcoordVCVSOutput.y)).x; + r += coef_norm(c)*SH(4, -4, n); + + c = texture(texture0, vec2(i+7/k, tcoordVCVSOutput.y)).x; + r += coef_norm(c)*SH(4, -3, n); + + c = texture(texture0, vec2(i+8/k, tcoordVCVSOutput.y)).x; + r += coef_norm(c)*SH(4, -2, n); + + c = texture(texture0, vec2(i+9/k, tcoordVCVSOutput.y)).x; + r += coef_norm(c)*SH(4, -1, n); + + c = texture(texture0, vec2(i+10/k, tcoordVCVSOutput.y)).x; + r += coef_norm(c)*SH(4, 0, n); + + c = texture(texture0, vec2(i+11/k, tcoordVCVSOutput.y)).x; + r += coef_norm(c)*SH(4, 1, n); + + c = texture(texture0, vec2(i+12/k, tcoordVCVSOutput.y)).x; + r += coef_norm(c)*SH(4, 2, n); + + c = texture(texture0, vec2(i+13/k, tcoordVCVSOutput.y)).x; + r += coef_norm(c)*SH(4, 3, n); + + c = texture(texture0, vec2(i+14/k, tcoordVCVSOutput.y)).x; + r += coef_norm(c)*SH(4, 4, n); + + r *= scaleVSOutput; // ================================================================ s = SHAPE; res = s; return vec3( res.x, 0.5+0.5*res.y, res.z ); @@ -298,7 +343,7 @@ vec3 mater = 0.5*mix( vec3(1.0,1.0,0.0), vec3(1.0,1.0,1.0), t.y); // ================================================================ - fragOutput0 = vec4( mater, 1.0); + fragOutput0 = vec4( vec3(1,0,0)*lin, 1.0); // ================================================================ } else From 0e0c1d7187ad204870e1909b0b88ddc0ed5d3202 Mon Sep 17 00:00:00 2001 From: Tania Castillo <31288525+tvcastillod@users.noreply.github.com> Date: Fri, 13 Oct 2023 01:12:48 -0500 Subject: [PATCH 010/118] comparison of passing coefficients with uniforms vs texture --- .../texture_coefficients.py | 214 +++++++++++++++--- 1 file changed, 185 insertions(+), 29 deletions(-) diff --git a/docs/experimental/SH-ODF experimental/texture_coefficients.py b/docs/experimental/SH-ODF experimental/texture_coefficients.py index 4856ab648..4f87302fe 100644 --- a/docs/experimental/SH-ODF experimental/texture_coefficients.py +++ b/docs/experimental/SH-ODF experimental/texture_coefficients.py @@ -14,9 +14,11 @@ if __name__ == '__main__': centers = np.array([[0, -1, 0], [1.0, -1, 0], [2.0, -1, 0]]) + centers_2 = np.array([[0, -2, 0], [1.0, -2, 0], [2.0, -2, 0]]) + centers_3 = np.array([[0, -3, 0], [1.0, -3, 0], [2.0, -3, 0]]) vecs = np.array([[0, 1, 0], [0, 1, 0], [0, 1, 0]]) colors = np.array([[0, 0, 1], [0, 1, 0], [1, 0, 0]]) - vals = np.array([1.0, 2.0, 2.0]) + scales = np.array([1.0, 2.0, 2.0]) coeffs = np.array( [[0.2820735, 0.15236554, -0.04038717, -0.11270988, -0.04532376, 0.14921817, 0.00257928, 0.0040734, -0.05313807, 0.03486542, @@ -28,17 +30,34 @@ 0.02348355, 0.03991898, 0.02587433, 0.02645416, 0.00668765, 0.00890633, 0.02189304, 0.00387415, 0.01665629, -0.01427194]]) - box_sd_stg_actor = actor.box(centers=centers, scales=1.0) + box_actor_texture = actor.box(centers=centers, scales=1.0) + box_actor_uniform_1 = actor.box(centers=np.array([centers_2[0]]), scales=1.0) + box_actor_uniform_2 = actor.box(centers=np.array([centers_2[1]]), scales=1.0) + box_actor_uniform_3 = actor.box(centers=np.array([centers_2[2]]), scales=1.0) + box_actor_template = actor.box(centers=centers_3, scales=1.0) big_centers = np.repeat(centers, 8, axis=0) - attribute_to_actor(box_sd_stg_actor, big_centers, 'center') - - big_scales = np.repeat(vals, 8, axis=0) - attribute_to_actor(box_sd_stg_actor, big_scales, 'scale') - - # ========================================================================= - - actor_box = box_sd_stg_actor.GetMapper().GetInput() + attribute_to_actor(box_actor_texture, big_centers, 'center') + attribute_to_actor(box_actor_template, np.repeat(centers_3, 8, axis=0), 'center') + attribute_to_actor(box_actor_uniform_1, np.repeat(np.array([centers_2[0]]), 8, axis=0), 'center') + attribute_to_actor(box_actor_uniform_2, np.repeat(np.array([centers_2[1]]), 8, axis=0), 'center') + attribute_to_actor(box_actor_uniform_3, np.repeat(np.array([centers_2[2]]), 8, axis=0), 'center') + + big_scales = np.repeat(scales, 8, axis=0) + attribute_to_actor(box_actor_texture, big_scales, 'scale') + attribute_to_actor(box_actor_template, big_scales, 'scale') + attribute_to_actor(box_actor_uniform_1, np.repeat(np.array([scales[0]]), 8, axis=0), 'scale') + attribute_to_actor(box_actor_uniform_2, np.repeat(np.array([scales[1]]), 8, axis=0), 'scale') + attribute_to_actor(box_actor_uniform_3, np.repeat(np.array([scales[2]]), 8, axis=0), 'scale') + + box_actor_uniform_1.GetShaderProperty().GetFragmentCustomUniforms(). \ + SetUniform1fv("coeffs", 15, coeffs[0]) + box_actor_uniform_2.GetShaderProperty().GetFragmentCustomUniforms(). \ + SetUniform1fv("coeffs", 15, coeffs[1]) + box_actor_uniform_3.GetShaderProperty().GetFragmentCustomUniforms(). \ + SetUniform1fv("coeffs", 15, coeffs[2]) + + actor_box = box_actor_texture.GetMapper().GetInput() uv_vals = np.array( [ @@ -70,32 +89,39 @@ 0.00668765, 0.00890633, 0.02189304, 0.00387415, 0.01665629, -0.01427194]]) ) - min = -1 - max = 1 + + minmax = np.array([arr.min(axis=1), arr.max(axis=1)]).T + big_minmax = np.repeat(minmax, 8, axis=0) + attribute_to_actor(box_actor_texture, big_minmax, 'minmax') + + min = arr.min(axis=1) + max = arr.max(axis=1) newmin = 0 newmax = 1 - arr = (arr - min)*((newmax - newmin) / (max - min)) + newmin - print(arr) + arr = np.array([(arr[i] - min[i])*((newmax - newmin) / (max[i] - min[i])) + newmin for i in range(arr.shape[0])]) arr *= 255 + print(arr.astype(np.uint8)) grid = numpy_to_vtk_image_data(arr.astype(np.uint8)) texture = Texture() texture.SetInputDataObject(grid) texture.Update() - box_sd_stg_actor.GetProperty().SetTexture("texture0", texture) - box_sd_stg_actor.GetShaderProperty().GetFragmentCustomUniforms()\ - .SetUniformf("k", 15) # number of coefficients per glyph + box_actor_texture.GetProperty().SetTexture("texture0", texture) + box_actor_texture.GetShaderProperty().GetFragmentCustomUniforms()\ + .SetUniformf("k", 15) # number of coefficients per glyph # ========================================================================= vs_dec = \ """ in vec3 center; in float scale; + in vec2 minmax; out vec4 vertexMCVSOutput; out vec3 centerMCVSOutput; out float scaleVSOutput; + out vec2 minmaxVSOutput; """ vs_impl = \ @@ -103,17 +129,22 @@ vertexMCVSOutput = vertexMC; centerMCVSOutput = center; scaleVSOutput = scale; + minmaxVSOutput = minmax; vec3 camPos = -MCVCMatrix[3].xyz * mat3(MCVCMatrix); """ - shader_to_actor(box_sd_stg_actor, 'vertex', decl_code=vs_dec, - impl_code=vs_impl) + shader_to_actor(box_actor_texture, 'vertex', decl_code=vs_dec, impl_code=vs_impl) + shader_to_actor(box_actor_template, 'vertex', decl_code=vs_dec, impl_code=vs_impl) + shader_to_actor(box_actor_uniform_1, 'vertex', decl_code=vs_dec, impl_code=vs_impl) + shader_to_actor(box_actor_uniform_2, 'vertex', decl_code=vs_dec, impl_code=vs_impl) + shader_to_actor(box_actor_uniform_3, 'vertex', decl_code=vs_dec, impl_code=vs_impl) fs_vars_dec = \ """ in vec4 vertexMCVSOutput; in vec3 centerMCVSOutput; in float scaleVSOutput; + in vec2 minmaxVSOutput; uniform samplerCube texture_0; uniform mat4 MCVCMatrix; @@ -193,11 +224,14 @@ { float min = 0; float max = 1; - float newmin = -1; - float newmax = 1; + float newmin = minmaxVSOutput.x;//-0.13133252; + float newmax = minmaxVSOutput.y;//0.28208936; return (coef - min) * ((newmax - newmin) / (max - min)) + newmin; } + """ + map_function_tex = \ + """ vec3 map( in vec3 p ) { p = p - centerMCVSOutput; @@ -263,6 +297,102 @@ } """ + map_function_unif = \ + """ + vec3 map( in vec3 p ) + { + p = p - centerMCVSOutput;vec3 + p00 = p; + float r, d; + vec3 n, s, res; + # define SHAPE (vec3(d-abs(r), sign(r),d)) + d = length(p00); + n = p00 / d; + float + sc = scaleVSOutput; + r = coeffs[0] * SH(0, 0, n) * sc; + r += coeffs[1] * SH(2, -2, n) * sc; + r += coeffs[2] * SH(2, -1, n) * sc; + r += coeffs[3] * SH(2, 0, n) * sc; + r += coeffs[4] * SH(2, 1, n) * sc; + r += coeffs[5] * SH(2, 2, n) * sc; + r += coeffs[6] * SH(4, -4, n) * sc; + r += coeffs[7] * SH(4, -3, n) * sc; + r += coeffs[8] * SH(4, -2, n) * sc; + r += coeffs[9] * SH(4, -1, n) * sc; + r += coeffs[10] * SH(4, 0, n) * sc; + r += coeffs[11] * SH(4, 1, n) * sc; + r += coeffs[12] * SH(4, 2, n) * sc; + r += coeffs[13] * SH(4, 3, n) * sc; + r += coeffs[14] * SH(4, 4, n) * sc; + s = SHAPE; + res = s; + return vec3(res.x, 0.5 + 0.5 * res.y, res.z); + } + """ + + map_function_templ_1 = \ + """ + vec3 map( in vec3 p ) + { + p = p - centerMCVSOutput;vec3 + p00 = p; + float r, d; + vec3 n, s, res; + # define SHAPE (vec3(d-abs(r), sign(r),d)) + d = length(p00); + n = p00 / d; + float + sc = scaleVSOutput; + """ + + coeffs_1 = \ + """ + float coeffs[15] = float[15](0.2820735, 0.15236554, -0.04038717, + -0.11270988, -0.04532376, 0.14921817, 0.00257928, + 0.0040734, -0.05313807, 0.03486542, 0.04083064, 0.02105767, + -0.04389586, -0.04302812, 0.1048641); + """ + + coeffs_2 = \ + """ + float coeffs[15] = float[15](0.28549338, 0.0978267, -0.11544838, + 0.12525354, -0.00126003, 0.00320594, 0.04744155, -0.07141446, + 0.03211689, 0.04711322, 0.08064896, 0.00154299, 0.00086506, 0.00162543, + -0.00444893); + """ + + coeffs_3 = \ + """ + float coeffs[15] = float[15](0.28208936, -0.13133252, -0.04701012, + -0.06303016, -0.0468775, 0.02348355, 0.03991898, 0.02587433, + 0.02645416, 0.00668765, 0.00890633, 0.02189304, 0.00387415, 0.01665629, + -0.01427194); + """ + + map_function_templ_2 = \ + """ + r = coeffs[0] * SH(0, 0, n) * sc; + r += coeffs[1] * SH(2, -2, n) * sc; + r += coeffs[2] * SH(2, -1, n) * sc; + r += coeffs[3] * SH(2, 0, n) * sc; + r += coeffs[4] * SH(2, 1, n) * sc; + r += coeffs[5] * SH(2, 2, n) * sc; + r += coeffs[6] * SH(4, -4, n) * sc; + r += coeffs[7] * SH(4, -3, n) * sc; + r += coeffs[8] * SH(4, -2, n) * sc; + r += coeffs[9] * SH(4, -1, n) * sc; + r += coeffs[10] * SH(4, 0, n) * sc; + r += coeffs[11] * SH(4, 1, n) * sc; + r += coeffs[12] * SH(4, 2, n) * sc; + r += coeffs[13] * SH(4, 3, n) * sc; + r += coeffs[14] * SH(4, 4, n) * sc; + s = SHAPE; + res = s; + return vec3(res.x, 0.5 + 0.5 * res.y, res.z); + } + """ + central_diffs_normal = \ """ vec3 centralDiffsNormals(in vec3 pos) @@ -304,10 +434,29 @@ blinn_phong_model = import_fury_shader(os.path.join( 'lighting', 'blinn_phong_model.frag')) - fs_dec = compose_shader([fs_vars_dec, sdf_map, central_diffs_normal, - cast_ray, blinn_phong_model]) - - shader_to_actor(box_sd_stg_actor, 'fragment', decl_code=fs_dec, debug=False) + fs_dec = compose_shader([fs_vars_dec, sdf_map, map_function_tex, + central_diffs_normal, cast_ray, blinn_phong_model]) + fs_dec_2 = compose_shader([fs_vars_dec, sdf_map, map_function_unif, + central_diffs_normal, cast_ray, + blinn_phong_model]) + fs_dec_t1 = compose_shader([fs_vars_dec, sdf_map, map_function_templ_1, + coeffs_1, map_function_templ_2, + central_diffs_normal, cast_ray, + blinn_phong_model]) + fs_dec_t2 = compose_shader([fs_vars_dec, sdf_map, map_function_templ_1, + coeffs_2, map_function_templ_2, + central_diffs_normal, cast_ray, + blinn_phong_model]) + fs_dec_t3 = compose_shader([fs_vars_dec, sdf_map, map_function_templ_1, + coeffs_3, map_function_templ_2, + central_diffs_normal, cast_ray, + blinn_phong_model]) + + shader_to_actor(box_actor_texture, 'fragment', decl_code=fs_dec, debug=False) + shader_to_actor(box_actor_uniform_1, 'fragment', decl_code=fs_dec_2) + shader_to_actor(box_actor_uniform_2, 'fragment', decl_code=fs_dec_2) + shader_to_actor(box_actor_uniform_3, 'fragment', decl_code=fs_dec_2) + shader_to_actor(box_actor_template, 'fragment', decl_code=fs_dec_t3) sdf_frag_impl = \ """ @@ -343,7 +492,7 @@ vec3 mater = 0.5*mix( vec3(1.0,1.0,0.0), vec3(1.0,1.0,1.0), t.y); // ================================================================ - fragOutput0 = vec4( vec3(1,0,0)*lin, 1.0); + fragOutput0 = vec4( vec3(1,1,0)*lin, 1.0); // ================================================================ } else @@ -354,12 +503,19 @@ """ - shader_to_actor(box_sd_stg_actor, 'fragment', impl_code=sdf_frag_impl, - block='picking') + shader_to_actor(box_actor_texture, 'fragment', impl_code=sdf_frag_impl, block='picking') + shader_to_actor(box_actor_uniform_1, 'fragment', impl_code=sdf_frag_impl, block='light') + shader_to_actor(box_actor_uniform_2, 'fragment', impl_code=sdf_frag_impl, block='light') + shader_to_actor(box_actor_uniform_3, 'fragment', impl_code=sdf_frag_impl, block='light') + shader_to_actor(box_actor_template, 'fragment', impl_code=sdf_frag_impl, block='light') show_manager = window.ShowManager(size=(700, 500)) show_manager.scene.background([255, 255, 255]) - show_manager.scene.add(box_sd_stg_actor) + show_manager.scene.add(box_actor_texture) + show_manager.scene.add(box_actor_uniform_1) + show_manager.scene.add(box_actor_uniform_2) + show_manager.scene.add(box_actor_uniform_3) + show_manager.scene.add(box_actor_template) from dipy.reconst.shm import sh_to_sf from dipy.data import get_sphere From 63e2886e67a057d964165d66ed1b9c65cf51aa06 Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Fri, 13 Oct 2023 13:23:05 -0400 Subject: [PATCH 011/118] Pruning duplicate coeffs. --- .../texture_coefficients.py | 513 +++++++++--------- 1 file changed, 266 insertions(+), 247 deletions(-) diff --git a/docs/experimental/SH-ODF experimental/texture_coefficients.py b/docs/experimental/SH-ODF experimental/texture_coefficients.py index 4856ab648..902e1d001 100644 --- a/docs/experimental/SH-ODF experimental/texture_coefficients.py +++ b/docs/experimental/SH-ODF experimental/texture_coefficients.py @@ -1,52 +1,73 @@ """ -This spript includes TEXTURE experimentation for passing SH coeffients +This script includes TEXTURE experimentation for passing SH coefficients """ -import numpy as np import os -from fury.lib import Texture, FloatArray +import numpy as np +from dipy.data import get_sphere +from dipy.reconst.shm import sh_to_sf from fury import actor, window -from fury.shaders import (attribute_to_actor, compose_shader, - import_fury_shader, shader_to_actor) +from fury.lib import FloatArray, Texture +from fury.shaders import ( + attribute_to_actor, + compose_shader, + import_fury_shader, + shader_to_actor, +) from fury.utils import numpy_to_vtk_image_data, set_polydata_tcoords +if __name__ == "__main__": + show_man = window.ShowManager(size=(1920, 1080)) + show_man.scene.background((1, 1, 1)) + + # fmt: off + coeffs = np.array([ + [ + 0.2820735, 0.15236554, -0.04038717, -0.11270988, -0.04532376, + 0.14921817, 0.00257928, 0.0040734, -0.05313807, 0.03486542, + 0.04083064, 0.02105767, -0.04389586, -0.04302812, 0.1048641 + ], + [ + 0.28549338, 0.0978267, -0.11544838, 0.12525354, -0.00126003, + 0.00320594, 0.04744155, -0.07141446, 0.03211689, 0.04711322, + 0.08064896, 0.00154299, 0.00086506, 0.00162543, -0.00444893 + ], + [ + 0.28208936, -0.13133252, -0.04701012, -0.06303016, -0.0468775, + 0.02348355, 0.03991898, 0.02587433, 0.02645416, 0.00668765, + 0.00890633, 0.02189304, 0.00387415, 0.01665629, -0.01427194 + ] + ]) + # fmt: on -if __name__ == '__main__': centers = np.array([[0, -1, 0], [1.0, -1, 0], [2.0, -1, 0]]) vecs = np.array([[0, 1, 0], [0, 1, 0], [0, 1, 0]]) colors = np.array([[0, 0, 1], [0, 1, 0], [1, 0, 0]]) vals = np.array([1.0, 2.0, 2.0]) - coeffs = np.array( - [[0.2820735, 0.15236554, -0.04038717, -0.11270988, -0.04532376, - 0.14921817, 0.00257928, 0.0040734, -0.05313807, 0.03486542, - 0.04083064, 0.02105767, -0.04389586, -0.04302812, 0.1048641], - [0.28549338, 0.0978267, -0.11544838, 0.12525354, -0.00126003, - 0.00320594, 0.04744155, -0.07141446, 0.03211689, 0.04711322, - 0.08064896, 0.00154299, 0.00086506, 0.00162543, -0.00444893], - [0.28208936, -0.13133252, -0.04701012, -0.06303016, -0.0468775, - 0.02348355, 0.03991898, 0.02587433, 0.02645416, 0.00668765, - 0.00890633, 0.02189304, 0.00387415, 0.01665629, -0.01427194]]) box_sd_stg_actor = actor.box(centers=centers, scales=1.0) big_centers = np.repeat(centers, 8, axis=0) - attribute_to_actor(box_sd_stg_actor, big_centers, 'center') + attribute_to_actor(box_sd_stg_actor, big_centers, "center") big_scales = np.repeat(vals, 8, axis=0) - attribute_to_actor(box_sd_stg_actor, big_scales, 'scale') - - # ========================================================================= + attribute_to_actor(box_sd_stg_actor, big_scales, "scale") actor_box = box_sd_stg_actor.GetMapper().GetInput() + # fmt: off uv_vals = np.array( [ - [0, 2 / 3], [0, 1], [1, 1], [1, 2 / 3], [0, 2 / 3], [0, 1], [1, 1], [1, 2 / 3], #glyph1 - [0, 1 / 3], [0, 2 / 3], [1, 2 / 3], [1, 1 / 3], [0, 1 / 3], [0, 2 / 3], [1, 2 / 3], [1, 1 / 3], #glyph2 - [0, 0], [0, 1 / 3], [1, 1 / 3], [1, 0], [0, 0], [0, 1 / 3], [1, 1 / 3], [1, 0], #glyph3 + [0, 2 / 3], [0, 1], [1, 1], [1, 2 / 3], + [0, 2 / 3], [0, 1], [1, 1], [1, 2 / 3], # glyph1 + [0, 1 / 3], [0, 2 / 3], [1, 2 / 3], [1, 1 / 3], + [0, 1 / 3], [0, 2 / 3], [1, 2 / 3], [1, 1 / 3], # glyph2 + [0, 0], [0, 1 / 3], [1, 1 / 3], [1, 0], + [0, 0], [0, 1 / 3], [1, 1 / 3], [1, 0] # glyph3 ] ) + # fmt: on num_pnts = uv_vals.shape[0] @@ -57,24 +78,31 @@ set_polydata_tcoords(actor_box, t_coords) - arr = ( - np.array( - [[0.2820735, 0.15236554, -0.04038717, -0.11270988, -0.04532376, - 0.14921817, 0.00257928, 0.0040734, -0.05313807, 0.03486542, - 0.04083064, 0.02105767, -0.04389586, -0.04302812, 0.1048641], - [0.28549338, 0.0978267, -0.11544838, 0.12525354, -0.00126003, - 0.00320594, 0.04744155, -0.07141446, 0.03211689, 0.04711322, - 0.08064896, 0.00154299, 0.00086506, 0.00162543, -0.00444893], - [0.28208936, -0.13133252, -0.04701012, -0.06303016, - -0.0468775, 0.02348355, 0.03991898, 0.02587433, 0.02645416, - 0.00668765, 0.00890633, 0.02189304, 0.00387415, 0.01665629, - -0.01427194]]) - ) + # fmt: off + arr = np.array([ + [ + 0.2820735, 0.15236554, -0.04038717, -0.11270988, -0.04532376, + 0.14921817, 0.00257928, 0.0040734, -0.05313807, 0.03486542, + 0.04083064, 0.02105767, -0.04389586, -0.04302812, 0.1048641 + ], + [ + 0.28549338, 0.0978267, -0.11544838, 0.12525354, -0.00126003, + 0.00320594, 0.04744155, -0.07141446, 0.03211689, 0.04711322, + 0.08064896, 0.00154299, 0.00086506, 0.00162543, -0.00444893 + ], + [ + 0.28208936, -0.13133252, -0.04701012, -0.06303016, -0.0468775, + 0.02348355, 0.03991898, 0.02587433, 0.02645416, 0.00668765, + 0.00890633, 0.02189304, 0.00387415, 0.01665629, -0.01427194 + ] + ]) + # fmt: on + min = -1 max = 1 newmin = 0 newmax = 1 - arr = (arr - min)*((newmax - newmin) / (max - min)) + newmin + arr = (arr - min) * ((newmax - newmin) / (max - min)) + newmin print(arr) arr *= 255 grid = numpy_to_vtk_image_data(arr.astype(np.uint8)) @@ -84,200 +112,194 @@ texture.Update() box_sd_stg_actor.GetProperty().SetTexture("texture0", texture) - box_sd_stg_actor.GetShaderProperty().GetFragmentCustomUniforms()\ - .SetUniformf("k", 15) # number of coefficients per glyph - # ========================================================================= - - vs_dec = \ - """ - in vec3 center; - in float scale; - - out vec4 vertexMCVSOutput; - out vec3 centerMCVSOutput; - out float scaleVSOutput; - """ - - vs_impl = \ - """ - vertexMCVSOutput = vertexMC; - centerMCVSOutput = center; - scaleVSOutput = scale; - vec3 camPos = -MCVCMatrix[3].xyz * mat3(MCVCMatrix); - """ - - shader_to_actor(box_sd_stg_actor, 'vertex', decl_code=vs_dec, - impl_code=vs_impl) - - fs_vars_dec = \ - """ - in vec4 vertexMCVSOutput; - in vec3 centerMCVSOutput; - in float scaleVSOutput; - uniform samplerCube texture_0; - - uniform mat4 MCVCMatrix; - """ - - sdf_map = \ - """ - - #define PI 3.1415926535898 - - // Clenshaw Legendre normalized - float Pgn(int l, int m, float x) - { - float p0 = 0., p1 = 0., p2 = 0.; + box_sd_stg_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniformf( + "k", 15 + ) - for (int k = l; k >= 0; k--) - { - float k1 = float(k + 1); - float m1 = float(2 * m) + k1; - float m2 = float(2 * (m + k) + 1); + vs_dec = """ + in vec3 center; + in float scale; - p2 = p1; - p1 = p0; + out vec4 vertexMCVSOutput; + out vec3 centerMCVSOutput; + out float scaleVSOutput; + """ - p0 = 0.; - if (l == m + k) - p0 = 1.; + vs_impl = """ + vertexMCVSOutput = vertexMC; + centerMCVSOutput = center; + scaleVSOutput = scale; + vec3 camPos = -MCVCMatrix[3].xyz * mat3(MCVCMatrix); + """ - float u0 = sqrt( - (m2 * (m2 + 2.0)) / - (k1 * m1) - ); + shader_to_actor( + box_sd_stg_actor, "vertex", decl_code=vs_dec, impl_code=vs_impl + ) - float u1 = sqrt( - (k1 * m1 * (m2 + 4.0)) / - ((k1 + 1.0) * (m1 + 1.0) * m2) - ); + fs_vars_dec = """ + in vec4 vertexMCVSOutput; + in vec3 centerMCVSOutput; + in float scaleVSOutput; + uniform samplerCube texture_0; - p0 += p1 * u0 * x; - p0 -= u1 * p2; - } + uniform mat4 MCVCMatrix; + """ - for (int k = 1; k <= m; k++) - { - p0 *= sqrt( - (1.0 - 0.5/float(k)) * (1.0 - x) * (1.0 + x) - ); - } + sdf_map = """ + #define PI 3.1415926535898 - p0 *= sqrt((0.5 * float(m) + 0.25)/PI); + // Clenshaw Legendre normalized + float Pgn(int l, int m, float x) + { + float p0 = 0., p1 = 0., p2 = 0.; - return p0; - } - - float SH( in int l, in int m, in vec3 s ) + for (int k = l; k >= 0; k--) { - vec3 ns = normalize(s); + float k1 = float(k + 1); + float m1 = float(2 * m) + k1; + float m2 = float(2 * (m + k) + 1); - if (m < 0) { - m = -m; - } + p2 = p1; + p1 = p0; - // spherical coordinates - float thetax = ns.y; - float phi = atan(ns.z, ns.x)+PI/2.; + p0 = 0.; + if (l == m + k) + p0 = 1.; - float pl = Pgn(l, m, thetax); + float u0 = sqrt( + (m2 * (m2 + 2.0)) / + (k1 * m1) + ); - float r = pow(-1.0, float(m)) * cos(float(m) * phi) * pl; - if (m != 0) { - r *= sqrt(2.0); - } - return r; + float u1 = sqrt( + (k1 * m1 * (m2 + 4.0)) / + ((k1 + 1.0) * (m1 + 1.0) * m2) + ); + + p0 += p1 * u0 * x; + p0 -= u1 * p2; } - - float coef_norm( in float coef) + + for (int k = 1; k <= m; k++) { - float min = 0; - float max = 1; - float newmin = -1; - float newmax = 1; - return (coef - min) * ((newmax - newmin) / (max - min)) + newmin; + p0 *= sqrt( + (1.0 - 0.5/float(k)) * (1.0 - x) * (1.0 + x) + ); } - vec3 map( in vec3 p ) - { - p = p - centerMCVSOutput; - vec3 p00 = p; + p0 *= sqrt((0.5 * float(m) + 0.25)/PI); - float r, d; vec3 n, s, res; + return p0; + } - #define SHAPE (vec3(d-abs(r), sign(r),d)) - //#define SHAPE (vec3(d-0.35, -1.0+2.0*clamp(0.5 + 16.0*r,0.0,1.0),d)) - d=length(p00); - n=p00/d; - // ================================================================ - float i = 1/(k*2); - float c = texture(texture0, vec2(i, tcoordVCVSOutput.y)).x; - r = coef_norm(c)*SH(0, 0, n); - - c = texture(texture0, vec2(i+1/k, tcoordVCVSOutput.y)).x; - r += coef_norm(c)*SH(2, -2, n); - - c = texture(texture0, vec2(i+2/k, tcoordVCVSOutput.y)).x; - r += coef_norm(c)*SH(2, -1, n); - - c = texture(texture0, vec2(i+3/k, tcoordVCVSOutput.y)).x; - r += coef_norm(c)*SH(2, 0, n); - - c = texture(texture0, vec2(i+4/k, tcoordVCVSOutput.y)).x; - r += coef_norm(c)*SH(2, 1, n); - - c = texture(texture0, vec2(i+5/k, tcoordVCVSOutput.y)).x; - r += coef_norm(c)*SH(2, 2, n); - - c = texture(texture0, vec2(i+6/k, tcoordVCVSOutput.y)).x; - r += coef_norm(c)*SH(4, -4, n); - - c = texture(texture0, vec2(i+7/k, tcoordVCVSOutput.y)).x; - r += coef_norm(c)*SH(4, -3, n); - - c = texture(texture0, vec2(i+8/k, tcoordVCVSOutput.y)).x; - r += coef_norm(c)*SH(4, -2, n); - - c = texture(texture0, vec2(i+9/k, tcoordVCVSOutput.y)).x; - r += coef_norm(c)*SH(4, -1, n); - - c = texture(texture0, vec2(i+10/k, tcoordVCVSOutput.y)).x; - r += coef_norm(c)*SH(4, 0, n); - - c = texture(texture0, vec2(i+11/k, tcoordVCVSOutput.y)).x; - r += coef_norm(c)*SH(4, 1, n); - - c = texture(texture0, vec2(i+12/k, tcoordVCVSOutput.y)).x; - r += coef_norm(c)*SH(4, 2, n); - - c = texture(texture0, vec2(i+13/k, tcoordVCVSOutput.y)).x; - r += coef_norm(c)*SH(4, 3, n); - - c = texture(texture0, vec2(i+14/k, tcoordVCVSOutput.y)).x; - r += coef_norm(c)*SH(4, 4, n); - - r *= scaleVSOutput; - // ================================================================ - s = SHAPE; res = s; - return vec3( res.x, 0.5+0.5*res.y, res.z ); - } - """ + float SH( in int l, in int m, in vec3 s ) + { + vec3 ns = normalize(s); - central_diffs_normal = \ - """ - vec3 centralDiffsNormals(in vec3 pos) - { - //vec2 e = vec2(1.0,-1.0)*0.5773*0.0005; - vec2 e = vec2(0.001, -1.0); - return normalize( e.xyy*map( pos + e.xyy ).x + - e.yyx*map( pos + e.yyx ).x + - e.yxy*map( pos + e.yxy ).x + - e.xxx*map( pos + e.xxx ).x ); + if (m < 0) { + m = -m; } - """ - cast_ray = \ - """ + // spherical coordinates + float thetax = ns.y; + float phi = atan(ns.z, ns.x)+PI/2.; + + float pl = Pgn(l, m, thetax); + + float r = pow(-1.0, float(m)) * cos(float(m) * phi) * pl; + if (m != 0) { + r *= sqrt(2.0); + } + return r; + } + + float coef_norm( in float coef) + { + float min = 0; + float max = 1; + float newmin = -1; + float newmax = 1; + return (coef - min) * ((newmax - newmin) / (max - min)) + newmin; + } + + vec3 map( in vec3 p ) + { + p = p - centerMCVSOutput; + vec3 p00 = p; + + float r, d; vec3 n, s, res; + + #define SHAPE (vec3(d-abs(r), sign(r),d)) + //#define SHAPE (vec3(d-0.35, -1.0+2.0*clamp(0.5 + 16.0*r,0.0,1.0),d)) + d=length(p00); + n=p00/d; + // ================================================================ + float i = 1/(k*2); + float c = texture(texture0, vec2(i, tcoordVCVSOutput.y)).x; + r = coef_norm(c)*SH(0, 0, n); + + c = texture(texture0, vec2(i+1/k, tcoordVCVSOutput.y)).x; + r += coef_norm(c)*SH(2, -2, n); + + c = texture(texture0, vec2(i+2/k, tcoordVCVSOutput.y)).x; + r += coef_norm(c)*SH(2, -1, n); + + c = texture(texture0, vec2(i+3/k, tcoordVCVSOutput.y)).x; + r += coef_norm(c)*SH(2, 0, n); + + c = texture(texture0, vec2(i+4/k, tcoordVCVSOutput.y)).x; + r += coef_norm(c)*SH(2, 1, n); + + c = texture(texture0, vec2(i+5/k, tcoordVCVSOutput.y)).x; + r += coef_norm(c)*SH(2, 2, n); + + c = texture(texture0, vec2(i+6/k, tcoordVCVSOutput.y)).x; + r += coef_norm(c)*SH(4, -4, n); + + c = texture(texture0, vec2(i+7/k, tcoordVCVSOutput.y)).x; + r += coef_norm(c)*SH(4, -3, n); + + c = texture(texture0, vec2(i+8/k, tcoordVCVSOutput.y)).x; + r += coef_norm(c)*SH(4, -2, n); + + c = texture(texture0, vec2(i+9/k, tcoordVCVSOutput.y)).x; + r += coef_norm(c)*SH(4, -1, n); + + c = texture(texture0, vec2(i+10/k, tcoordVCVSOutput.y)).x; + r += coef_norm(c)*SH(4, 0, n); + + c = texture(texture0, vec2(i+11/k, tcoordVCVSOutput.y)).x; + r += coef_norm(c)*SH(4, 1, n); + + c = texture(texture0, vec2(i+12/k, tcoordVCVSOutput.y)).x; + r += coef_norm(c)*SH(4, 2, n); + + c = texture(texture0, vec2(i+13/k, tcoordVCVSOutput.y)).x; + r += coef_norm(c)*SH(4, 3, n); + + c = texture(texture0, vec2(i+14/k, tcoordVCVSOutput.y)).x; + r += coef_norm(c)*SH(4, 4, n); + + r *= scaleVSOutput; + // ================================================================ + s = SHAPE; res = s; + return vec3( res.x, 0.5+0.5*res.y, res.z ); + } + """ + + central_diffs_normal = """ + vec3 centralDiffsNormals(in vec3 pos) + { + //vec2 e = vec2(1.0,-1.0)*0.5773*0.0005; + vec2 e = vec2(0.001, -1.0); + return normalize( e.xyy*map( pos + e.xyy ).x + + e.yyx*map( pos + e.yyx ).x + + e.yxy*map( pos + e.yxy ).x + + e.xxx*map( pos + e.xxx ).x ); + } + """ + + cast_ray = """ vec3 castRay(in vec3 ro, vec3 rd) { vec3 res = vec3(1e10,-1.0, 1.0); @@ -298,19 +320,24 @@ return res; } + """ - """ - - blinn_phong_model = import_fury_shader(os.path.join( - 'lighting', 'blinn_phong_model.frag')) + blinn_phong_model = import_fury_shader( + os.path.join("lighting", "blinn_phong_model.frag") + ) - fs_dec = compose_shader([fs_vars_dec, sdf_map, central_diffs_normal, - cast_ray, blinn_phong_model]) + # fmt: off + fs_dec = compose_shader([ + fs_vars_dec, sdf_map, central_diffs_normal, cast_ray, + blinn_phong_model + ]) + # fmt: on - shader_to_actor(box_sd_stg_actor, 'fragment', decl_code=fs_dec, debug=False) + shader_to_actor( + box_sd_stg_actor, "fragment", decl_code=fs_dec, debug=False + ) - sdf_frag_impl = \ - """ + sdf_frag_impl = """ vec3 pnt = vertexMCVSOutput.xyz; // Ray Origin @@ -338,9 +365,9 @@ // lights vec3 lin = 2.5*occ*vec3(1.0,1.0,1.0)*(0.6+0.4*normal.y); - lin += 1.0*sss*vec3(1.0,0.95,0.70)*occ; + lin += 1.0*sss*vec3(1.0,0.95,0.70)*occ; - vec3 mater = 0.5*mix( vec3(1.0,1.0,0.0), vec3(1.0,1.0,1.0), t.y); + vec3 mater = 0.5*mix( vec3(1.0,1.0,0.0), vec3(1.0,1.0,1.0), t.y); // ================================================================ fragOutput0 = vec4( vec3(1,0,0)*lin, 1.0); @@ -350,39 +377,31 @@ { discard; } + """ + shader_to_actor( + box_sd_stg_actor, "fragment", impl_code=sdf_frag_impl, block="picking" + ) - """ - - shader_to_actor(box_sd_stg_actor, 'fragment', impl_code=sdf_frag_impl, - block='picking') + show_man.scene.add(box_sd_stg_actor) - show_manager = window.ShowManager(size=(700, 500)) - show_manager.scene.background([255, 255, 255]) - show_manager.scene.add(box_sd_stg_actor) + sphere = get_sphere("repulsion724") - from dipy.reconst.shm import sh_to_sf - from dipy.data import get_sphere + sh_basis = "descoteaux07" + sh_order = 4 - sphere = get_sphere('repulsion724') + sh = np.zeros((3, 1, 1, 15)) + sh[0, 0, 0, :] = coeffs[0, :] + sh[1, 0, 0, :] = coeffs[1, :] + sh[2, 0, 0, :] = coeffs[2, :] - sh_basis = 'descoteaux07' - sh_order = 4 - tensor_sh = coeffs = np.array( - [[[[0.2820735, 0.15236554, -0.04038717, -0.11270988, -0.04532376, - 0.14921817, 0.00257928, 0.0040734, -0.05313807, 0.03486542, - 0.04083064, 0.02105767, -0.04389586, -0.04302812, 0.1048641]]], - [[[0.28549338, 0.0978267, -0.11544838, 0.12525354, -0.00126003, - 0.00320594, 0.04744155, -0.07141446, 0.03211689, 0.04711322, - 0.08064896, 0.00154299, 0.00086506, 0.00162543, -0.00444893]]], - [[[0.28208936, -0.13133252, -0.04701012, -0.06303016, -0.0468775, - 0.02348355, 0.03991898, 0.02587433, 0.02645416, 0.00668765, - 0.00890633, 0.02189304, 0.00387415, 0.01665629, -0.01427194]]]]) - tensor_sf = sh_to_sf(tensor_sh, sh_order=4, basis_type='descoteaux07', - sphere=sphere) + tensor_sf = sh_to_sf( + sh, sh_order=4, basis_type="descoteaux07", sphere=sphere + ) - odf_actor = actor.odf_slicer(tensor_sf, sphere=sphere, scale=0.5, - colormap='plasma') - show_manager.scene.add(odf_actor) + odf_actor = actor.odf_slicer( + tensor_sf, sphere=sphere, scale=0.5, colormap="plasma" + ) + show_man.scene.add(odf_actor) - show_manager.start() + show_man.start() From df3b9caf0210eb9b2412dc06c47a743a958c4442 Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Fri, 13 Oct 2023 14:03:11 -0400 Subject: [PATCH 012/118] Refactoring FS declaration code. --- .../texture_coefficients.py | 84 +++++++------------ 1 file changed, 30 insertions(+), 54 deletions(-) diff --git a/docs/experimental/SH-ODF experimental/texture_coefficients.py b/docs/experimental/SH-ODF experimental/texture_coefficients.py index 902e1d001..70bc2f481 100644 --- a/docs/experimental/SH-ODF experimental/texture_coefficients.py +++ b/docs/experimental/SH-ODF experimental/texture_coefficients.py @@ -41,20 +41,18 @@ ]) # fmt: on - centers = np.array([[0, -1, 0], [1.0, -1, 0], [2.0, -1, 0]]) - vecs = np.array([[0, 1, 0], [0, 1, 0], [0, 1, 0]]) - colors = np.array([[0, 0, 1], [0, 1, 0], [1, 0, 0]]) - vals = np.array([1.0, 2.0, 2.0]) + centers = np.array([[0, -1, 0], [1, -1, 0], [2, -1, 0]]) + scales = np.array([1, 2, 2]) - box_sd_stg_actor = actor.box(centers=centers, scales=1.0) + odf_actor = actor.box(centers=centers, scales=1.0) big_centers = np.repeat(centers, 8, axis=0) - attribute_to_actor(box_sd_stg_actor, big_centers, "center") + attribute_to_actor(odf_actor, big_centers, "center") - big_scales = np.repeat(vals, 8, axis=0) - attribute_to_actor(box_sd_stg_actor, big_scales, "scale") + big_scales = np.repeat(scales, 8, axis=0) + attribute_to_actor(odf_actor, big_scales, "scale") - actor_box = box_sd_stg_actor.GetMapper().GetInput() + odf_actor_pd = odf_actor.GetMapper().GetInput() # fmt: off uv_vals = np.array( @@ -76,43 +74,22 @@ t_coords.SetNumberOfTuples(num_pnts) [t_coords.SetTuple(i, uv_vals[i]) for i in range(num_pnts)] - set_polydata_tcoords(actor_box, t_coords) - - # fmt: off - arr = np.array([ - [ - 0.2820735, 0.15236554, -0.04038717, -0.11270988, -0.04532376, - 0.14921817, 0.00257928, 0.0040734, -0.05313807, 0.03486542, - 0.04083064, 0.02105767, -0.04389586, -0.04302812, 0.1048641 - ], - [ - 0.28549338, 0.0978267, -0.11544838, 0.12525354, -0.00126003, - 0.00320594, 0.04744155, -0.07141446, 0.03211689, 0.04711322, - 0.08064896, 0.00154299, 0.00086506, 0.00162543, -0.00444893 - ], - [ - 0.28208936, -0.13133252, -0.04701012, -0.06303016, -0.0468775, - 0.02348355, 0.03991898, 0.02587433, 0.02645416, 0.00668765, - 0.00890633, 0.02189304, 0.00387415, 0.01665629, -0.01427194 - ] - ]) - # fmt: on + set_polydata_tcoords(odf_actor_pd, t_coords) min = -1 max = 1 newmin = 0 - newmax = 1 - arr = (arr - min) * ((newmax - newmin) / (max - min)) + newmin - print(arr) - arr *= 255 + newmax = 255 + arr = (coeffs - min) * ((newmax - newmin) / (max - min)) + newmin grid = numpy_to_vtk_image_data(arr.astype(np.uint8)) texture = Texture() texture.SetInputDataObject(grid) texture.Update() - box_sd_stg_actor.GetProperty().SetTexture("texture0", texture) - box_sd_stg_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniformf( + odf_actor.GetProperty().SetTexture("texture0", texture) + + odf_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniformf( "k", 15 ) @@ -132,22 +109,22 @@ vec3 camPos = -MCVCMatrix[3].xyz * mat3(MCVCMatrix); """ - shader_to_actor( - box_sd_stg_actor, "vertex", decl_code=vs_dec, impl_code=vs_impl - ) + shader_to_actor(odf_actor, "vertex", decl_code=vs_dec, impl_code=vs_impl) + + fs_defs = "#define PI 3.1415926535898" + + fs_uniforms = """ + uniform mat4 MCVCMatrix; + uniform samplerCube texture_0; + """ - fs_vars_dec = """ + fs_vs_vars = """ in vec4 vertexMCVSOutput; in vec3 centerMCVSOutput; in float scaleVSOutput; - uniform samplerCube texture_0; - - uniform mat4 MCVCMatrix; """ sdf_map = """ - #define PI 3.1415926535898 - // Clenshaw Legendre normalized float Pgn(int l, int m, float x) { @@ -328,14 +305,12 @@ # fmt: off fs_dec = compose_shader([ - fs_vars_dec, sdf_map, central_diffs_normal, cast_ray, - blinn_phong_model + fs_defs, fs_uniforms, fs_vs_vars, sdf_map, central_diffs_normal, + cast_ray, blinn_phong_model ]) # fmt: on - shader_to_actor( - box_sd_stg_actor, "fragment", decl_code=fs_dec, debug=False - ) + shader_to_actor(odf_actor, "fragment", decl_code=fs_dec, debug=False) sdf_frag_impl = """ vec3 pnt = vertexMCVSOutput.xyz; @@ -380,10 +355,10 @@ """ shader_to_actor( - box_sd_stg_actor, "fragment", impl_code=sdf_frag_impl, block="picking" + odf_actor, "fragment", impl_code=sdf_frag_impl, block="picking" ) - show_man.scene.add(box_sd_stg_actor) + show_man.scene.add(odf_actor) sphere = get_sphere("repulsion724") @@ -399,9 +374,10 @@ sh, sh_order=4, basis_type="descoteaux07", sphere=sphere ) - odf_actor = actor.odf_slicer( + odf_slicer_actor = actor.odf_slicer( tensor_sf, sphere=sphere, scale=0.5, colormap="plasma" ) - show_man.scene.add(odf_actor) + + show_man.scene.add(odf_slicer_actor) show_man.start() From 6346117597f60265146d4a965b4933f631642657 Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Fri, 13 Oct 2023 15:00:42 -0400 Subject: [PATCH 013/118] Added temp call to Fury's Central Differences Normals calculation. --- .../texture_coefficients.py | 64 +++++++++++-------- 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/docs/experimental/SH-ODF experimental/texture_coefficients.py b/docs/experimental/SH-ODF experimental/texture_coefficients.py index 70bc2f481..641a577c3 100644 --- a/docs/experimental/SH-ODF experimental/texture_coefficients.py +++ b/docs/experimental/SH-ODF experimental/texture_coefficients.py @@ -113,7 +113,7 @@ fs_defs = "#define PI 3.1415926535898" - fs_uniforms = """ + fs_unifs = """ uniform mat4 MCVCMatrix; uniform samplerCube texture_0; """ @@ -124,6 +124,17 @@ in float scaleVSOutput; """ + coeffs_norm = """ + float coeffsNorm(float coef) + { + float min = 0; + float max = 1; + float newMin = -1; + float newMax = 1; + return (coef - min) * ((newMax - newMin) / (max - min)) + newMin; + } + """ + sdf_map = """ // Clenshaw Legendre normalized float Pgn(int l, int m, float x) @@ -190,15 +201,6 @@ return r; } - float coef_norm( in float coef) - { - float min = 0; - float max = 1; - float newmin = -1; - float newmax = 1; - return (coef - min) * ((newmax - newmin) / (max - min)) + newmin; - } - vec3 map( in vec3 p ) { p = p - centerMCVSOutput; @@ -213,49 +215,49 @@ // ================================================================ float i = 1/(k*2); float c = texture(texture0, vec2(i, tcoordVCVSOutput.y)).x; - r = coef_norm(c)*SH(0, 0, n); + r = coeffsNorm(c)*SH(0, 0, n); c = texture(texture0, vec2(i+1/k, tcoordVCVSOutput.y)).x; - r += coef_norm(c)*SH(2, -2, n); + r += coeffsNorm(c)*SH(2, -2, n); c = texture(texture0, vec2(i+2/k, tcoordVCVSOutput.y)).x; - r += coef_norm(c)*SH(2, -1, n); + r += coeffsNorm(c)*SH(2, -1, n); c = texture(texture0, vec2(i+3/k, tcoordVCVSOutput.y)).x; - r += coef_norm(c)*SH(2, 0, n); + r += coeffsNorm(c)*SH(2, 0, n); c = texture(texture0, vec2(i+4/k, tcoordVCVSOutput.y)).x; - r += coef_norm(c)*SH(2, 1, n); + r += coeffsNorm(c)*SH(2, 1, n); c = texture(texture0, vec2(i+5/k, tcoordVCVSOutput.y)).x; - r += coef_norm(c)*SH(2, 2, n); + r += coeffsNorm(c)*SH(2, 2, n); c = texture(texture0, vec2(i+6/k, tcoordVCVSOutput.y)).x; - r += coef_norm(c)*SH(4, -4, n); + r += coeffsNorm(c)*SH(4, -4, n); c = texture(texture0, vec2(i+7/k, tcoordVCVSOutput.y)).x; - r += coef_norm(c)*SH(4, -3, n); + r += coeffsNorm(c)*SH(4, -3, n); c = texture(texture0, vec2(i+8/k, tcoordVCVSOutput.y)).x; - r += coef_norm(c)*SH(4, -2, n); + r += coeffsNorm(c)*SH(4, -2, n); c = texture(texture0, vec2(i+9/k, tcoordVCVSOutput.y)).x; - r += coef_norm(c)*SH(4, -1, n); + r += coeffsNorm(c)*SH(4, -1, n); c = texture(texture0, vec2(i+10/k, tcoordVCVSOutput.y)).x; - r += coef_norm(c)*SH(4, 0, n); + r += coeffsNorm(c)*SH(4, 0, n); c = texture(texture0, vec2(i+11/k, tcoordVCVSOutput.y)).x; - r += coef_norm(c)*SH(4, 1, n); + r += coeffsNorm(c)*SH(4, 1, n); c = texture(texture0, vec2(i+12/k, tcoordVCVSOutput.y)).x; - r += coef_norm(c)*SH(4, 2, n); + r += coeffsNorm(c)*SH(4, 2, n); c = texture(texture0, vec2(i+13/k, tcoordVCVSOutput.y)).x; - r += coef_norm(c)*SH(4, 3, n); + r += coeffsNorm(c)*SH(4, 3, n); c = texture(texture0, vec2(i+14/k, tcoordVCVSOutput.y)).x; - r += coef_norm(c)*SH(4, 4, n); + r += coeffsNorm(c)*SH(4, 4, n); r *= scaleVSOutput; // ================================================================ @@ -264,7 +266,7 @@ } """ - central_diffs_normal = """ + central_diffs_normals = """ vec3 centralDiffsNormals(in vec3 pos) { //vec2 e = vec2(1.0,-1.0)*0.5773*0.0005; @@ -276,6 +278,12 @@ } """ + """ + central_diffs_normals = import_fury_shader( + os.path.join("sdf", "central_diffs.frag") + ) + """ + cast_ray = """ vec3 castRay(in vec3 ro, vec3 rd) { @@ -305,8 +313,8 @@ # fmt: off fs_dec = compose_shader([ - fs_defs, fs_uniforms, fs_vs_vars, sdf_map, central_diffs_normal, - cast_ray, blinn_phong_model + fs_defs, fs_unifs, fs_vs_vars, coeffs_norm, sdf_map, + central_diffs_normals, cast_ray, blinn_phong_model ]) # fmt: on From 54b2b3a5c111b26482ce0a708c45be6f4669c813 Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Tue, 31 Oct 2023 19:20:49 -0400 Subject: [PATCH 014/118] Added new file with changes. --- .../SH-ODF experimental/raymarched_odf.py | 403 ++++++++++++++++++ .../texture_coefficients.py | 232 +++++----- 2 files changed, 525 insertions(+), 110 deletions(-) create mode 100644 docs/experimental/SH-ODF experimental/raymarched_odf.py diff --git a/docs/experimental/SH-ODF experimental/raymarched_odf.py b/docs/experimental/SH-ODF experimental/raymarched_odf.py new file mode 100644 index 000000000..980afe8b5 --- /dev/null +++ b/docs/experimental/SH-ODF experimental/raymarched_odf.py @@ -0,0 +1,403 @@ +""" +This script includes TEXTURE experimentation for passing SH coefficients +""" +import os + +import numpy as np +from dipy.data import get_sphere +from dipy.reconst.shm import sh_to_sf + +from fury import actor, window +from fury.lib import FloatArray, Texture +from fury.shaders import ( + attribute_to_actor, + compose_shader, + import_fury_shader, + shader_to_actor, +) +from fury.utils import numpy_to_vtk_image_data, set_polydata_tcoords + +if __name__ == "__main__": + show_man = window.ShowManager(size=(1920, 1080)) + show_man.scene.background((1, 1, 1)) + + # fmt: off + coeffs = np.array([ + [ + 0.2820735, 0.15236554, -0.04038717, -0.11270988, -0.04532376, + 0.14921817, 0.00257928, 0.0040734, -0.05313807, 0.03486542, + 0.04083064, 0.02105767, -0.04389586, -0.04302812, 0.1048641 + ], + [ + 0.28549338, 0.0978267, -0.11544838, 0.12525354, -0.00126003, + 0.00320594, 0.04744155, -0.07141446, 0.03211689, 0.04711322, + 0.08064896, 0.00154299, 0.00086506, 0.00162543, -0.00444893 + ], + [ + 0.28208936, -0.13133252, -0.04701012, -0.06303016, -0.0468775, + 0.02348355, 0.03991898, 0.02587433, 0.02645416, 0.00668765, + 0.00890633, 0.02189304, 0.00387415, 0.01665629, -0.01427194 + ] + ]) + # fmt: on + + centers = np.array([[0, -1, 0], [1, -1, 0], [2, -1, 0]]) + scales = np.array([1, 2, 2]) + + odf_actor = actor.box(centers=centers, scales=1.0) + + big_centers = np.repeat(centers, 8, axis=0) + attribute_to_actor(odf_actor, big_centers, "center") + + big_scales = np.repeat(scales, 8, axis=0) + attribute_to_actor(odf_actor, big_scales, "scale") + + odf_actor_pd = odf_actor.GetMapper().GetInput() + + # fmt: off + uv_vals = np.array( + [ + [0, 2 / 3], [0, 1], [1, 1], [1, 2 / 3], + [0, 2 / 3], [0, 1], [1, 1], [1, 2 / 3], # glyph1 + [0, 1 / 3], [0, 2 / 3], [1, 2 / 3], [1, 1 / 3], + [0, 1 / 3], [0, 2 / 3], [1, 2 / 3], [1, 1 / 3], # glyph2 + [0, 0], [0, 1 / 3], [1, 1 / 3], [1, 0], + [0, 0], [0, 1 / 3], [1, 1 / 3], [1, 0] # glyph3 + ] + ) + # fmt: on + + num_pnts = uv_vals.shape[0] + + t_coords = FloatArray() + t_coords.SetNumberOfComponents(2) + t_coords.SetNumberOfTuples(num_pnts) + [t_coords.SetTuple(i, uv_vals[i]) for i in range(num_pnts)] + + set_polydata_tcoords(odf_actor_pd, t_coords) + + min = -1 + max = 1 + newmin = 0 + newmax = 255 + arr = (coeffs - min) * ((newmax - newmin) / (max - min)) + newmin + grid = numpy_to_vtk_image_data(arr.astype(np.uint8)) + + texture = Texture() + texture.SetInputDataObject(grid) + texture.Update() + + odf_actor.GetProperty().SetTexture("texture0", texture) + + # TODO: Set int uniform + odf_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniformf( + "numCoeffs", 15 + ) + + vs_dec = """ + in vec3 center; + in float scale; + + out vec4 vertexMCVSOutput; + out vec3 centerMCVSOutput; + out float scaleVSOutput; + """ + + vs_impl = """ + vertexMCVSOutput = vertexMC; + centerMCVSOutput = center; + scaleVSOutput = scale; + vec3 camPos = -MCVCMatrix[3].xyz * mat3(MCVCMatrix); + """ + + shader_to_actor(odf_actor, "vertex", decl_code=vs_dec, impl_code=vs_impl) + + fs_defs = "#define PI 3.1415926535898" + + fs_unifs = """ + uniform mat4 MCVCMatrix; + uniform samplerCube texture_0; + //uniform int k; + """ + + fs_vs_vars = """ + in vec4 vertexMCVSOutput; + in vec3 centerMCVSOutput; + in float scaleVSOutput; + """ + + coeffs_norm = """ + float coeffsNorm(float coef) + { + float min = 0; + float max = 1; + float newMin = -1; + float newMax = 1; + return (coef - min) * ((newMax - newMin) / (max - min)) + newMin; + } + """ + + # Clenshaw Legendre normalized + legendre_polys = """ + float Pgn(int l, int m, float x) + { + float p0 = 0; + float p1 = 0; + float p2 = 0; + + for (int k = l; k >= 0; k--) + { + float k1 = float(k + 1); + float m1 = float(2 * m) + k1; + float m2 = float(2 * (m + k) + 1); + + p2 = p1; + p1 = p0; + p0 = 0; + + if (l == m + k) + p0 = 1; + + float u0 = sqrt((m2 * (m2 + 2)) / (k1 * m1)); + + float u1 = sqrt((k1 * m1 * (m2 + 4)) / ((k1 + 1) * (m1 + 1) * m2)); + + p0 += p1 * u0 * x; + p0 -= u1 * p2; + } + + for (int k = 1; k <= m; k++) + { + p0 *= sqrt((1 - .5 / float(k)) * (1 - x) * (1 + x)); + } + + p0 *= sqrt((.5 * float(m) + .25) / PI); + + return p0; + } + """ + + spherical_harmonics = """ + float SH(in int l, in int m, in vec3 s) + { + vec3 ns = normalize(s); + + if (m < 0) { + m = -m; + } + + // spherical coordinates + float thetax = ns.y; + float phi = atan(ns.z, ns.x) + PI / 2.; + + float pl = Pgn(l, m, thetax); + + float r = pow(-1, float(m)) * cos(float(m) * phi) * pl; + + /* + if (m != 0) { + r *= sqrt(2); + } + */ + + return r; + } + """ + + sdf_map = """ + vec3 map( in vec3 p ) + { + p = p - centerMCVSOutput; + vec3 p00 = p; + + float r, d; vec3 n, s, res; + + #define SHAPE (vec3(d-abs(r), sign(r),d)) + //#define SHAPE (vec3(d-0.35, -1.0+2.0*clamp(0.5 + 16.0*r,0.0,1.0),d)) + d=length(p00); + n=p00 / d; + // ================================================================ + float i = 1 / (numCoeffs * 2); + + float c = texture(texture0, vec2(i, tcoordVCVSOutput.y)).x; + r = coeffsNorm(c) * SH(0, 0, n); + + c = texture(texture0, vec2(i + 1 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(2, -2, n); + + c = texture(texture0, vec2(i + 2 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(2, -1, n); + + c = texture(texture0, vec2(i + 3 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(2, 0, n); + + c = texture(texture0, vec2(i + 4 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(2, 1, n); + + c = texture(texture0, vec2(i + 5 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(2, 2, n); + + c = texture(texture0, vec2(i + 6 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(4, -4, n); + + c = texture(texture0, vec2(i + 7 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(4, -3, n); + + c = texture(texture0, vec2(i + 8 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(4, -2, n); + + c = texture(texture0, vec2(i + 9 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(4, -1, n); + + c = texture(texture0, vec2(i + 10 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(4, 0, n); + + c = texture(texture0, vec2(i + 11 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(4, 1, n); + + c = texture(texture0, vec2(i + 12 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(4, 2, n); + + c = texture(texture0, vec2(i + 13 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(4, 3, n); + + c = texture(texture0, vec2(i + 14 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(4, 4, n); + + r *= scaleVSOutput; + // ================================================================ + s = SHAPE; + res = s; + return vec3(res.x, .5 + .5 * res.y, res.z); + } + """ + + central_diffs_normals = """ + vec3 centralDiffsNormals(in vec3 pos) + { + //vec2 e = vec2(1.0,-1.0)*0.5773*0.0005; + vec2 e = vec2(.001, -1); + return normalize( + e.xyy * map(pos + e.xyy).x + e.yyx * map(pos + e.yyx).x + + e.yxy * map(pos + e.yxy).x + e.xxx * map(pos + e.xxx).x ); + } + """ + + """ + central_diffs_normals = import_fury_shader( + os.path.join("sdf", "central_diffs.frag") + ) + """ + + cast_ray = """ + vec3 castRay(in vec3 ro, vec3 rd) + { + vec3 res = vec3(1e10, -1, 1); + + float maxd = 4; + float h = 1; + float t = 0; + vec2 m = vec2(-1); + + for(int i = 0; i < 2000; i++) + { + if(h < .01 || t > maxd) + break; + vec3 res = map(ro + rd * t); + h = res.x; + m = res.yz; + t += h * .1; + } + + if(t < maxd && t < res.x) + res = vec3(t, m); + + return res; + } + """ + + blinn_phong_model = import_fury_shader( + os.path.join("lighting", "blinn_phong_model.frag") + ) + + # fmt: off + fs_dec = compose_shader([ + fs_defs, fs_unifs, fs_vs_vars, coeffs_norm, legendre_polys, + spherical_harmonics, sdf_map, central_diffs_normals, cast_ray, + blinn_phong_model + ]) + # fmt: on + + shader_to_actor(odf_actor, "fragment", decl_code=fs_dec, debug=False) + + sdf_frag_impl = """ + vec3 pnt = vertexMCVSOutput.xyz; + + // Ray Origin + // Camera position in world space + vec3 ro = (-MCVCMatrix[3] * MCVCMatrix).xyz; + + // Ray Direction + vec3 rd = normalize(pnt - ro); + + // Light Direction + vec3 ld = normalize(ro - pnt); + + ro += pnt - ro; + + vec3 t = castRay(ro, rd); + + if(t.y > -.5) + { + vec3 pos = ro + t.y * rd; + + vec3 normal = centralDiffsNormals(pos); + + float occ = clamp(2 * t.z, 0, 1); + //float sss = pow(clamp(1 + dot(normal, rd), 0, 1), 1); + float sss = clamp(1 + dot(normal, rd), 0, 1); + + // lights + vec3 lin = 2.5 * occ * vec3(1) * (.6 + .4 * normal.y); + lin += 1 * sss * vec3(1, .95, .7) * occ; + + vec3 mater = .5 * mix(vec3(1, 1, 0), vec3(1), t.y); + + // ================================================================ + fragOutput0 = vec4(vec3(1, 0, 0) * lin, opacity); + // ================================================================ + } + else + { + discard; + } + """ + + shader_to_actor( + odf_actor, "fragment", impl_code=sdf_frag_impl, block="picking" + ) + + show_man.scene.add(odf_actor) + + sphere = get_sphere("repulsion724") + + # sh_basis = "descoteaux07" + sh_basis = "tournier07" + sh_order = 4 + + sh = np.zeros((3, 1, 1, 15)) + sh[0, 0, 0, :] = coeffs[0, :] + sh[1, 0, 0, :] = coeffs[1, :] + sh[2, 0, 0, :] = coeffs[2, :] + + tensor_sf = sh_to_sf( + sh, sh_order=sh_order, basis_type=sh_basis, sphere=sphere + ) + + odf_slicer_actor = actor.odf_slicer( + tensor_sf, sphere=sphere, scale=0.5, colormap="plasma" + ) + + show_man.scene.add(odf_slicer_actor) + + show_man.start() diff --git a/docs/experimental/SH-ODF experimental/texture_coefficients.py b/docs/experimental/SH-ODF experimental/texture_coefficients.py index 641a577c3..980afe8b5 100644 --- a/docs/experimental/SH-ODF experimental/texture_coefficients.py +++ b/docs/experimental/SH-ODF experimental/texture_coefficients.py @@ -89,8 +89,9 @@ odf_actor.GetProperty().SetTexture("texture0", texture) + # TODO: Set int uniform odf_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniformf( - "k", 15 + "numCoeffs", 15 ) vs_dec = """ @@ -116,6 +117,7 @@ fs_unifs = """ uniform mat4 MCVCMatrix; uniform samplerCube texture_0; + //uniform int k; """ fs_vs_vars = """ @@ -135,11 +137,13 @@ } """ - sdf_map = """ - // Clenshaw Legendre normalized + # Clenshaw Legendre normalized + legendre_polys = """ float Pgn(int l, int m, float x) { - float p0 = 0., p1 = 0., p2 = 0.; + float p0 = 0; + float p1 = 0; + float p2 = 0; for (int k = l; k >= 0; k--) { @@ -149,20 +153,14 @@ p2 = p1; p1 = p0; + p0 = 0; - p0 = 0.; if (l == m + k) - p0 = 1.; + p0 = 1; - float u0 = sqrt( - (m2 * (m2 + 2.0)) / - (k1 * m1) - ); + float u0 = sqrt((m2 * (m2 + 2)) / (k1 * m1)); - float u1 = sqrt( - (k1 * m1 * (m2 + 4.0)) / - ((k1 + 1.0) * (m1 + 1.0) * m2) - ); + float u1 = sqrt((k1 * m1 * (m2 + 4)) / ((k1 + 1) * (m1 + 1) * m2)); p0 += p1 * u0 * x; p0 -= u1 * p2; @@ -170,17 +168,17 @@ for (int k = 1; k <= m; k++) { - p0 *= sqrt( - (1.0 - 0.5/float(k)) * (1.0 - x) * (1.0 + x) - ); + p0 *= sqrt((1 - .5 / float(k)) * (1 - x) * (1 + x)); } - p0 *= sqrt((0.5 * float(m) + 0.25)/PI); + p0 *= sqrt((.5 * float(m) + .25) / PI); return p0; } + """ - float SH( in int l, in int m, in vec3 s ) + spherical_harmonics = """ + float SH(in int l, in int m, in vec3 s) { vec3 ns = normalize(s); @@ -190,17 +188,23 @@ // spherical coordinates float thetax = ns.y; - float phi = atan(ns.z, ns.x)+PI/2.; + float phi = atan(ns.z, ns.x) + PI / 2.; float pl = Pgn(l, m, thetax); - float r = pow(-1.0, float(m)) * cos(float(m) * phi) * pl; + float r = pow(-1, float(m)) * cos(float(m) * phi) * pl; + + /* if (m != 0) { - r *= sqrt(2.0); + r *= sqrt(2); } + */ + return r; } + """ + sdf_map = """ vec3 map( in vec3 p ) { p = p - centerMCVSOutput; @@ -211,58 +215,60 @@ #define SHAPE (vec3(d-abs(r), sign(r),d)) //#define SHAPE (vec3(d-0.35, -1.0+2.0*clamp(0.5 + 16.0*r,0.0,1.0),d)) d=length(p00); - n=p00/d; + n=p00 / d; // ================================================================ - float i = 1/(k*2); + float i = 1 / (numCoeffs * 2); + float c = texture(texture0, vec2(i, tcoordVCVSOutput.y)).x; - r = coeffsNorm(c)*SH(0, 0, n); + r = coeffsNorm(c) * SH(0, 0, n); - c = texture(texture0, vec2(i+1/k, tcoordVCVSOutput.y)).x; - r += coeffsNorm(c)*SH(2, -2, n); + c = texture(texture0, vec2(i + 1 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(2, -2, n); - c = texture(texture0, vec2(i+2/k, tcoordVCVSOutput.y)).x; - r += coeffsNorm(c)*SH(2, -1, n); + c = texture(texture0, vec2(i + 2 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(2, -1, n); - c = texture(texture0, vec2(i+3/k, tcoordVCVSOutput.y)).x; - r += coeffsNorm(c)*SH(2, 0, n); + c = texture(texture0, vec2(i + 3 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(2, 0, n); - c = texture(texture0, vec2(i+4/k, tcoordVCVSOutput.y)).x; - r += coeffsNorm(c)*SH(2, 1, n); + c = texture(texture0, vec2(i + 4 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(2, 1, n); - c = texture(texture0, vec2(i+5/k, tcoordVCVSOutput.y)).x; - r += coeffsNorm(c)*SH(2, 2, n); + c = texture(texture0, vec2(i + 5 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(2, 2, n); - c = texture(texture0, vec2(i+6/k, tcoordVCVSOutput.y)).x; - r += coeffsNorm(c)*SH(4, -4, n); + c = texture(texture0, vec2(i + 6 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(4, -4, n); - c = texture(texture0, vec2(i+7/k, tcoordVCVSOutput.y)).x; - r += coeffsNorm(c)*SH(4, -3, n); + c = texture(texture0, vec2(i + 7 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(4, -3, n); - c = texture(texture0, vec2(i+8/k, tcoordVCVSOutput.y)).x; - r += coeffsNorm(c)*SH(4, -2, n); + c = texture(texture0, vec2(i + 8 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(4, -2, n); - c = texture(texture0, vec2(i+9/k, tcoordVCVSOutput.y)).x; - r += coeffsNorm(c)*SH(4, -1, n); + c = texture(texture0, vec2(i + 9 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(4, -1, n); - c = texture(texture0, vec2(i+10/k, tcoordVCVSOutput.y)).x; - r += coeffsNorm(c)*SH(4, 0, n); + c = texture(texture0, vec2(i + 10 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(4, 0, n); - c = texture(texture0, vec2(i+11/k, tcoordVCVSOutput.y)).x; - r += coeffsNorm(c)*SH(4, 1, n); + c = texture(texture0, vec2(i + 11 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(4, 1, n); - c = texture(texture0, vec2(i+12/k, tcoordVCVSOutput.y)).x; - r += coeffsNorm(c)*SH(4, 2, n); + c = texture(texture0, vec2(i + 12 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(4, 2, n); - c = texture(texture0, vec2(i+13/k, tcoordVCVSOutput.y)).x; - r += coeffsNorm(c)*SH(4, 3, n); + c = texture(texture0, vec2(i + 13 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(4, 3, n); - c = texture(texture0, vec2(i+14/k, tcoordVCVSOutput.y)).x; - r += coeffsNorm(c)*SH(4, 4, n); + c = texture(texture0, vec2(i + 14 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(4, 4, n); r *= scaleVSOutput; // ================================================================ - s = SHAPE; res = s; - return vec3( res.x, 0.5+0.5*res.y, res.z ); + s = SHAPE; + res = s; + return vec3(res.x, .5 + .5 * res.y, res.z); } """ @@ -270,11 +276,10 @@ vec3 centralDiffsNormals(in vec3 pos) { //vec2 e = vec2(1.0,-1.0)*0.5773*0.0005; - vec2 e = vec2(0.001, -1.0); - return normalize( e.xyy*map( pos + e.xyy ).x + - e.yyx*map( pos + e.yyx ).x + - e.yxy*map( pos + e.yxy ).x + - e.xxx*map( pos + e.xxx ).x ); + vec2 e = vec2(.001, -1); + return normalize( + e.xyy * map(pos + e.xyy).x + e.yyx * map(pos + e.yyx).x + + e.yxy * map(pos + e.yxy).x + e.xxx * map(pos + e.xxx).x ); } """ @@ -285,26 +290,30 @@ """ cast_ray = """ - vec3 castRay(in vec3 ro, vec3 rd) + vec3 castRay(in vec3 ro, vec3 rd) + { + vec3 res = vec3(1e10, -1, 1); + + float maxd = 4; + float h = 1; + float t = 0; + vec2 m = vec2(-1); + + for(int i = 0; i < 2000; i++) { - vec3 res = vec3(1e10,-1.0, 1.0); - - float maxd = 4.0; - float h = 1.0; - float t = 0.0; - vec2 m = vec2(-1.0); - for( int i=0; i<2000; i++ ) - { - if( h<0.01||t>maxd ) break; - vec3 res = map( ro+rd*t ); - h = res.x; - m = res.yz; - t += h*0.1; - } - if( t maxd) + break; + vec3 res = map(ro + rd * t); + h = res.x; + m = res.yz; + t += h * .1; } + + if(t < maxd && t < res.x) + res = vec3(t, m); + + return res; + } """ blinn_phong_model = import_fury_shader( @@ -313,53 +322,55 @@ # fmt: off fs_dec = compose_shader([ - fs_defs, fs_unifs, fs_vs_vars, coeffs_norm, sdf_map, - central_diffs_normals, cast_ray, blinn_phong_model + fs_defs, fs_unifs, fs_vs_vars, coeffs_norm, legendre_polys, + spherical_harmonics, sdf_map, central_diffs_normals, cast_ray, + blinn_phong_model ]) # fmt: on shader_to_actor(odf_actor, "fragment", decl_code=fs_dec, debug=False) sdf_frag_impl = """ - vec3 pnt = vertexMCVSOutput.xyz; + vec3 pnt = vertexMCVSOutput.xyz; - // Ray Origin - // Camera position in world space - vec3 ro = (-MCVCMatrix[3] * MCVCMatrix).xyz; + // Ray Origin + // Camera position in world space + vec3 ro = (-MCVCMatrix[3] * MCVCMatrix).xyz; - // Ray Direction - vec3 rd = normalize(pnt - ro); + // Ray Direction + vec3 rd = normalize(pnt - ro); - // Light Direction - vec3 ld = normalize(ro - pnt); + // Light Direction + vec3 ld = normalize(ro - pnt); - ro += pnt - ro; + ro += pnt - ro; - vec3 t = castRay(ro, rd); + vec3 t = castRay(ro, rd); - if(t.y > -0.5 ) - { - vec3 pos = ro + t.y * rd; + if(t.y > -.5) + { + vec3 pos = ro + t.y * rd; - vec3 normal = centralDiffsNormals(pos); + vec3 normal = centralDiffsNormals(pos); - float occ = clamp( 2.0*t.z, 0.0, 1.0 ); - float sss = pow( clamp( 1.0 + dot(normal, rd), 0.0, 1.0 ), 1.0 ); + float occ = clamp(2 * t.z, 0, 1); + //float sss = pow(clamp(1 + dot(normal, rd), 0, 1), 1); + float sss = clamp(1 + dot(normal, rd), 0, 1); - // lights - vec3 lin = 2.5*occ*vec3(1.0,1.0,1.0)*(0.6+0.4*normal.y); - lin += 1.0*sss*vec3(1.0,0.95,0.70)*occ; + // lights + vec3 lin = 2.5 * occ * vec3(1) * (.6 + .4 * normal.y); + lin += 1 * sss * vec3(1, .95, .7) * occ; - vec3 mater = 0.5*mix( vec3(1.0,1.0,0.0), vec3(1.0,1.0,1.0), t.y); + vec3 mater = .5 * mix(vec3(1, 1, 0), vec3(1), t.y); - // ================================================================ - fragOutput0 = vec4( vec3(1,0,0)*lin, 1.0); - // ================================================================ - } - else - { - discard; - } + // ================================================================ + fragOutput0 = vec4(vec3(1, 0, 0) * lin, opacity); + // ================================================================ + } + else + { + discard; + } """ shader_to_actor( @@ -370,7 +381,8 @@ sphere = get_sphere("repulsion724") - sh_basis = "descoteaux07" + # sh_basis = "descoteaux07" + sh_basis = "tournier07" sh_order = 4 sh = np.zeros((3, 1, 1, 15)) @@ -379,7 +391,7 @@ sh[2, 0, 0, :] = coeffs[2, :] tensor_sf = sh_to_sf( - sh, sh_order=4, basis_type="descoteaux07", sphere=sphere + sh, sh_order=sh_order, basis_type=sh_basis, sphere=sphere ) odf_slicer_actor = actor.odf_slicer( From 1f455c0cc5d61e218e23ce6dc22087d9421bef4b Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Tue, 31 Oct 2023 19:37:30 -0400 Subject: [PATCH 015/118] Restored texture_coefficients.py --- .../texture_coefficients.py | 306 +++++++++--------- 1 file changed, 149 insertions(+), 157 deletions(-) diff --git a/docs/experimental/SH-ODF experimental/texture_coefficients.py b/docs/experimental/SH-ODF experimental/texture_coefficients.py index 9b3cb8670..4f87302fe 100644 --- a/docs/experimental/SH-ODF experimental/texture_coefficients.py +++ b/docs/experimental/SH-ODF experimental/texture_coefficients.py @@ -1,20 +1,14 @@ """ -This script includes TEXTURE experimentation for passing SH coefficients +This spript includes TEXTURE experimentation for passing SH coeffients """ +import numpy as np import os -import numpy as np -from dipy.data import get_sphere -from dipy.reconst.shm import sh_to_sf +from fury.lib import Texture, FloatArray from fury import actor, window -from fury.lib import FloatArray, Texture -from fury.shaders import ( - attribute_to_actor, - compose_shader, - import_fury_shader, - shader_to_actor, -) +from fury.shaders import (attribute_to_actor, compose_shader, + import_fury_shader, shader_to_actor) from fury.utils import numpy_to_vtk_image_data, set_polydata_tcoords @@ -67,15 +61,11 @@ uv_vals = np.array( [ - [0, 2 / 3], [0, 1], [1, 1], [1, 2 / 3], - [0, 2 / 3], [0, 1], [1, 1], [1, 2 / 3], # glyph1 - [0, 1 / 3], [0, 2 / 3], [1, 2 / 3], [1, 1 / 3], - [0, 1 / 3], [0, 2 / 3], [1, 2 / 3], [1, 1 / 3], # glyph2 - [0, 0], [0, 1 / 3], [1, 1 / 3], [1, 0], - [0, 0], [0, 1 / 3], [1, 1 / 3], [1, 0] # glyph3 + [0, 2 / 3], [0, 1], [1, 1], [1, 2 / 3], [0, 2 / 3], [0, 1], [1, 1], [1, 2 / 3], #glyph1 + [0, 1 / 3], [0, 2 / 3], [1, 2 / 3], [1, 1 / 3], [0, 1 / 3], [0, 2 / 3], [1, 2 / 3], [1, 1 / 3], #glyph2 + [0, 0], [0, 1 / 3], [1, 1 / 3], [1, 0], [0, 0], [0, 1 / 3], [1, 1 / 3], [1, 0], #glyph3 ] ) - # fmt: on num_pnts = uv_vals.shape[0] @@ -84,7 +74,7 @@ t_coords.SetNumberOfTuples(num_pnts) [t_coords.SetTuple(i, uv_vals[i]) for i in range(num_pnts)] - set_polydata_tcoords(odf_actor_pd, t_coords) + set_polydata_tcoords(actor_box, t_coords) arr = ( np.array( @@ -170,52 +160,58 @@ { float p0 = 0., p1 = 0., p2 = 0.; - for (int k = l; k >= 0; k--) - { - float k1 = float(k + 1); - float m1 = float(2 * m) + k1; - float m2 = float(2 * (m + k) + 1); + for (int k = l; k >= 0; k--) + { + float k1 = float(k + 1); + float m1 = float(2 * m) + k1; + float m2 = float(2 * (m + k) + 1); - p2 = p1; - p1 = p0; - p0 = 0; + p2 = p1; + p1 = p0; - if (l == m + k) - p0 = 1; + p0 = 0.; + if (l == m + k) + p0 = 1.; - float u0 = sqrt((m2 * (m2 + 2)) / (k1 * m1)); + float u0 = sqrt( + (m2 * (m2 + 2.0)) / + (k1 * m1) + ); - float u1 = sqrt((k1 * m1 * (m2 + 4)) / ((k1 + 1) * (m1 + 1) * m2)); + float u1 = sqrt( + (k1 * m1 * (m2 + 4.0)) / + ((k1 + 1.0) * (m1 + 1.0) * m2) + ); - p0 += p1 * u0 * x; - p0 -= u1 * p2; - } + p0 += p1 * u0 * x; + p0 -= u1 * p2; + } - for (int k = 1; k <= m; k++) - { - p0 *= sqrt((1 - .5 / float(k)) * (1 - x) * (1 + x)); - } + for (int k = 1; k <= m; k++) + { + p0 *= sqrt( + (1.0 - 0.5/float(k)) * (1.0 - x) * (1.0 + x) + ); + } - p0 *= sqrt((.5 * float(m) + .25) / PI); + p0 *= sqrt((0.5 * float(m) + 0.25)/PI); - return p0; - } - """ + return p0; + } - spherical_harmonics = """ - float SH(in int l, in int m, in vec3 s) - { - vec3 ns = normalize(s); + float SH( in int l, in int m, in vec3 s ) + { + vec3 ns = normalize(s); - if (m < 0) { - m = -m; - } + if (m < 0) { + m = -m; + } - // spherical coordinates - float thetax = ns.y; - float phi = atan(ns.z, ns.x) + PI / 2.; + // spherical coordinates + float thetax = ns.y; + float phi = atan(ns.z, ns.x)+PI/2.; - float pl = Pgn(l, m, thetax); + float pl = Pgn(l, m, thetax); float r = pow(-1.0, float(m)) * cos(float(m) * phi) * pl; if (m != 0) { @@ -223,7 +219,7 @@ } return r; } - + float coef_norm( in float coef) { float min = 0; @@ -241,59 +237,59 @@ p = p - centerMCVSOutput; vec3 p00 = p; - float r, d; vec3 n, s, res; + float r, d; vec3 n, s, res; #define SHAPE (vec3(d-abs(r), sign(r),d)) //#define SHAPE (vec3(d-0.35, -1.0+2.0*clamp(0.5 + 16.0*r,0.0,1.0),d)) d=length(p00); - n=p00/d; + n=p00/d; // ================================================================ float i = 1/(k*2); float c = texture(texture0, vec2(i, tcoordVCVSOutput.y)).x; r = coef_norm(c)*SH(0, 0, n); - + c = texture(texture0, vec2(i+1/k, tcoordVCVSOutput.y)).x; r += coef_norm(c)*SH(2, -2, n); - + c = texture(texture0, vec2(i+2/k, tcoordVCVSOutput.y)).x; r += coef_norm(c)*SH(2, -1, n); - + c = texture(texture0, vec2(i+3/k, tcoordVCVSOutput.y)).x; r += coef_norm(c)*SH(2, 0, n); - + c = texture(texture0, vec2(i+4/k, tcoordVCVSOutput.y)).x; r += coef_norm(c)*SH(2, 1, n); - + c = texture(texture0, vec2(i+5/k, tcoordVCVSOutput.y)).x; r += coef_norm(c)*SH(2, 2, n); - + c = texture(texture0, vec2(i+6/k, tcoordVCVSOutput.y)).x; r += coef_norm(c)*SH(4, -4, n); - + c = texture(texture0, vec2(i+7/k, tcoordVCVSOutput.y)).x; r += coef_norm(c)*SH(4, -3, n); - + c = texture(texture0, vec2(i+8/k, tcoordVCVSOutput.y)).x; r += coef_norm(c)*SH(4, -2, n); - + c = texture(texture0, vec2(i+9/k, tcoordVCVSOutput.y)).x; r += coef_norm(c)*SH(4, -1, n); - + c = texture(texture0, vec2(i+10/k, tcoordVCVSOutput.y)).x; r += coef_norm(c)*SH(4, 0, n); - + c = texture(texture0, vec2(i+11/k, tcoordVCVSOutput.y)).x; r += coef_norm(c)*SH(4, 1, n); - + c = texture(texture0, vec2(i+12/k, tcoordVCVSOutput.y)).x; r += coef_norm(c)*SH(4, 2, n); - + c = texture(texture0, vec2(i+13/k, tcoordVCVSOutput.y)).x; r += coef_norm(c)*SH(4, 3, n); - + c = texture(texture0, vec2(i+14/k, tcoordVCVSOutput.y)).x; r += coef_norm(c)*SH(4, 4, n); - + r *= scaleVSOutput; // ================================================================ s = SHAPE; res = s; @@ -353,8 +349,8 @@ coeffs_1 = \ """ float coeffs[15] = float[15](0.2820735, 0.15236554, -0.04038717, - -0.11270988, -0.04532376, 0.14921817, 0.00257928, - 0.0040734, -0.05313807, 0.03486542, 0.04083064, 0.02105767, + -0.11270988, -0.04532376, 0.14921817, 0.00257928, + 0.0040734, -0.05313807, 0.03486542, 0.04083064, 0.02105767, -0.04389586, -0.04302812, 0.1048641); """ @@ -397,53 +393,46 @@ } """ - central_diffs_normals = """ - vec3 centralDiffsNormals(in vec3 pos) - { - //vec2 e = vec2(1.0,-1.0)*0.5773*0.0005; - vec2 e = vec2(.001, -1); - return normalize( - e.xyy * map(pos + e.xyy).x + e.yyx * map(pos + e.yyx).x + - e.yxy * map(pos + e.yxy).x + e.xxx * map(pos + e.xxx).x ); - } - """ - - """ - central_diffs_normals = import_fury_shader( - os.path.join("sdf", "central_diffs.frag") - ) - """ - - cast_ray = """ - vec3 castRay(in vec3 ro, vec3 rd) - { - vec3 res = vec3(1e10, -1, 1); - - float maxd = 4; - float h = 1; - float t = 0; - vec2 m = vec2(-1); - - for(int i = 0; i < 2000; i++) + central_diffs_normal = \ + """ + vec3 centralDiffsNormals(in vec3 pos) { - if(h < .01 || t > maxd) - break; - vec3 res = map(ro + rd * t); - h = res.x; - m = res.yz; - t += h * .1; + //vec2 e = vec2(1.0,-1.0)*0.5773*0.0005; + vec2 e = vec2(0.001, -1.0); + return normalize( e.xyy*map( pos + e.xyy ).x + + e.yyx*map( pos + e.yyx ).x + + e.yxy*map( pos + e.yxy ).x + + e.xxx*map( pos + e.xxx ).x ); } + """ - if(t < maxd && t < res.x) - res = vec3(t, m); + cast_ray = \ + """ + vec3 castRay(in vec3 ro, vec3 rd) + { + vec3 res = vec3(1e10,-1.0, 1.0); + + float maxd = 4.0; + float h = 1.0; + float t = 0.0; + vec2 m = vec2(-1.0); + for( int i=0; i<2000; i++ ) + { + if( h<0.01||t>maxd ) break; + vec3 res = map( ro+rd*t ); + h = res.x; + m = res.yz; + t += h*0.1; + } + if( t -.5) - { - vec3 pos = ro + t.y * rd; + if(t.y > -0.5 ) + { + vec3 pos = ro + t.y * rd; - vec3 normal = centralDiffsNormals(pos); + vec3 normal = centralDiffsNormals(pos); - float occ = clamp(2 * t.z, 0, 1); - //float sss = pow(clamp(1 + dot(normal, rd), 0, 1), 1); - float sss = clamp(1 + dot(normal, rd), 0, 1); + float occ = clamp( 2.0*t.z, 0.0, 1.0 ); + float sss = pow( clamp( 1.0 + dot(normal, rd), 0.0, 1.0 ), 1.0 ); - // lights - vec3 lin = 2.5 * occ * vec3(1) * (.6 + .4 * normal.y); - lin += 1 * sss * vec3(1, .95, .7) * occ; + // lights + vec3 lin = 2.5*occ*vec3(1.0,1.0,1.0)*(0.6+0.4*normal.y); + lin += 1.0*sss*vec3(1.0,0.95,0.70)*occ; - vec3 mater = .5 * mix(vec3(1, 1, 0), vec3(1), t.y); + vec3 mater = 0.5*mix( vec3(1.0,1.0,0.0), vec3(1.0,1.0,1.0), t.y); // ================================================================ fragOutput0 = vec4( vec3(1,1,0)*lin, 1.0); @@ -528,25 +517,28 @@ show_manager.scene.add(box_actor_uniform_3) show_manager.scene.add(box_actor_template) - sphere = get_sphere("repulsion724") - - # sh_basis = "descoteaux07" - sh_basis = "tournier07" - sh_order = 4 - - sh = np.zeros((3, 1, 1, 15)) - sh[0, 0, 0, :] = coeffs[0, :] - sh[1, 0, 0, :] = coeffs[1, :] - sh[2, 0, 0, :] = coeffs[2, :] + from dipy.reconst.shm import sh_to_sf + from dipy.data import get_sphere - tensor_sf = sh_to_sf( - sh, sh_order=sh_order, basis_type=sh_basis, sphere=sphere - ) + sphere = get_sphere('repulsion724') - odf_slicer_actor = actor.odf_slicer( - tensor_sf, sphere=sphere, scale=0.5, colormap="plasma" - ) - - show_man.scene.add(odf_slicer_actor) - - show_man.start() + sh_basis = 'descoteaux07' + sh_order = 4 + tensor_sh = coeffs = np.array( + [[[[0.2820735, 0.15236554, -0.04038717, -0.11270988, -0.04532376, + 0.14921817, 0.00257928, 0.0040734, -0.05313807, 0.03486542, + 0.04083064, 0.02105767, -0.04389586, -0.04302812, 0.1048641]]], + [[[0.28549338, 0.0978267, -0.11544838, 0.12525354, -0.00126003, + 0.00320594, 0.04744155, -0.07141446, 0.03211689, 0.04711322, + 0.08064896, 0.00154299, 0.00086506, 0.00162543, -0.00444893]]], + [[[0.28208936, -0.13133252, -0.04701012, -0.06303016, -0.0468775, + 0.02348355, 0.03991898, 0.02587433, 0.02645416, 0.00668765, + 0.00890633, 0.02189304, 0.00387415, 0.01665629, -0.01427194]]]]) + tensor_sf = sh_to_sf(tensor_sh, sh_order=4, basis_type='descoteaux07', + sphere=sphere) + + odf_actor = actor.odf_slicer(tensor_sf, sphere=sphere, scale=0.5, + colormap='plasma') + show_manager.scene.add(odf_actor) + + show_manager.start() From ed6d9ab6e2bdce1b52e7cb069e326ff4bd070fa8 Mon Sep 17 00:00:00 2001 From: tvcastillod Date: Tue, 7 Nov 2023 00:20:13 -0500 Subject: [PATCH 016/118] organized files --- .../SH-ODF experimental/raymarched_odf.py | 403 --------- .../texture_coefficients.py | 809 ++++++++---------- 2 files changed, 340 insertions(+), 872 deletions(-) delete mode 100644 docs/experimental/SH-ODF experimental/raymarched_odf.py diff --git a/docs/experimental/SH-ODF experimental/raymarched_odf.py b/docs/experimental/SH-ODF experimental/raymarched_odf.py deleted file mode 100644 index 980afe8b5..000000000 --- a/docs/experimental/SH-ODF experimental/raymarched_odf.py +++ /dev/null @@ -1,403 +0,0 @@ -""" -This script includes TEXTURE experimentation for passing SH coefficients -""" -import os - -import numpy as np -from dipy.data import get_sphere -from dipy.reconst.shm import sh_to_sf - -from fury import actor, window -from fury.lib import FloatArray, Texture -from fury.shaders import ( - attribute_to_actor, - compose_shader, - import_fury_shader, - shader_to_actor, -) -from fury.utils import numpy_to_vtk_image_data, set_polydata_tcoords - -if __name__ == "__main__": - show_man = window.ShowManager(size=(1920, 1080)) - show_man.scene.background((1, 1, 1)) - - # fmt: off - coeffs = np.array([ - [ - 0.2820735, 0.15236554, -0.04038717, -0.11270988, -0.04532376, - 0.14921817, 0.00257928, 0.0040734, -0.05313807, 0.03486542, - 0.04083064, 0.02105767, -0.04389586, -0.04302812, 0.1048641 - ], - [ - 0.28549338, 0.0978267, -0.11544838, 0.12525354, -0.00126003, - 0.00320594, 0.04744155, -0.07141446, 0.03211689, 0.04711322, - 0.08064896, 0.00154299, 0.00086506, 0.00162543, -0.00444893 - ], - [ - 0.28208936, -0.13133252, -0.04701012, -0.06303016, -0.0468775, - 0.02348355, 0.03991898, 0.02587433, 0.02645416, 0.00668765, - 0.00890633, 0.02189304, 0.00387415, 0.01665629, -0.01427194 - ] - ]) - # fmt: on - - centers = np.array([[0, -1, 0], [1, -1, 0], [2, -1, 0]]) - scales = np.array([1, 2, 2]) - - odf_actor = actor.box(centers=centers, scales=1.0) - - big_centers = np.repeat(centers, 8, axis=0) - attribute_to_actor(odf_actor, big_centers, "center") - - big_scales = np.repeat(scales, 8, axis=0) - attribute_to_actor(odf_actor, big_scales, "scale") - - odf_actor_pd = odf_actor.GetMapper().GetInput() - - # fmt: off - uv_vals = np.array( - [ - [0, 2 / 3], [0, 1], [1, 1], [1, 2 / 3], - [0, 2 / 3], [0, 1], [1, 1], [1, 2 / 3], # glyph1 - [0, 1 / 3], [0, 2 / 3], [1, 2 / 3], [1, 1 / 3], - [0, 1 / 3], [0, 2 / 3], [1, 2 / 3], [1, 1 / 3], # glyph2 - [0, 0], [0, 1 / 3], [1, 1 / 3], [1, 0], - [0, 0], [0, 1 / 3], [1, 1 / 3], [1, 0] # glyph3 - ] - ) - # fmt: on - - num_pnts = uv_vals.shape[0] - - t_coords = FloatArray() - t_coords.SetNumberOfComponents(2) - t_coords.SetNumberOfTuples(num_pnts) - [t_coords.SetTuple(i, uv_vals[i]) for i in range(num_pnts)] - - set_polydata_tcoords(odf_actor_pd, t_coords) - - min = -1 - max = 1 - newmin = 0 - newmax = 255 - arr = (coeffs - min) * ((newmax - newmin) / (max - min)) + newmin - grid = numpy_to_vtk_image_data(arr.astype(np.uint8)) - - texture = Texture() - texture.SetInputDataObject(grid) - texture.Update() - - odf_actor.GetProperty().SetTexture("texture0", texture) - - # TODO: Set int uniform - odf_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniformf( - "numCoeffs", 15 - ) - - vs_dec = """ - in vec3 center; - in float scale; - - out vec4 vertexMCVSOutput; - out vec3 centerMCVSOutput; - out float scaleVSOutput; - """ - - vs_impl = """ - vertexMCVSOutput = vertexMC; - centerMCVSOutput = center; - scaleVSOutput = scale; - vec3 camPos = -MCVCMatrix[3].xyz * mat3(MCVCMatrix); - """ - - shader_to_actor(odf_actor, "vertex", decl_code=vs_dec, impl_code=vs_impl) - - fs_defs = "#define PI 3.1415926535898" - - fs_unifs = """ - uniform mat4 MCVCMatrix; - uniform samplerCube texture_0; - //uniform int k; - """ - - fs_vs_vars = """ - in vec4 vertexMCVSOutput; - in vec3 centerMCVSOutput; - in float scaleVSOutput; - """ - - coeffs_norm = """ - float coeffsNorm(float coef) - { - float min = 0; - float max = 1; - float newMin = -1; - float newMax = 1; - return (coef - min) * ((newMax - newMin) / (max - min)) + newMin; - } - """ - - # Clenshaw Legendre normalized - legendre_polys = """ - float Pgn(int l, int m, float x) - { - float p0 = 0; - float p1 = 0; - float p2 = 0; - - for (int k = l; k >= 0; k--) - { - float k1 = float(k + 1); - float m1 = float(2 * m) + k1; - float m2 = float(2 * (m + k) + 1); - - p2 = p1; - p1 = p0; - p0 = 0; - - if (l == m + k) - p0 = 1; - - float u0 = sqrt((m2 * (m2 + 2)) / (k1 * m1)); - - float u1 = sqrt((k1 * m1 * (m2 + 4)) / ((k1 + 1) * (m1 + 1) * m2)); - - p0 += p1 * u0 * x; - p0 -= u1 * p2; - } - - for (int k = 1; k <= m; k++) - { - p0 *= sqrt((1 - .5 / float(k)) * (1 - x) * (1 + x)); - } - - p0 *= sqrt((.5 * float(m) + .25) / PI); - - return p0; - } - """ - - spherical_harmonics = """ - float SH(in int l, in int m, in vec3 s) - { - vec3 ns = normalize(s); - - if (m < 0) { - m = -m; - } - - // spherical coordinates - float thetax = ns.y; - float phi = atan(ns.z, ns.x) + PI / 2.; - - float pl = Pgn(l, m, thetax); - - float r = pow(-1, float(m)) * cos(float(m) * phi) * pl; - - /* - if (m != 0) { - r *= sqrt(2); - } - */ - - return r; - } - """ - - sdf_map = """ - vec3 map( in vec3 p ) - { - p = p - centerMCVSOutput; - vec3 p00 = p; - - float r, d; vec3 n, s, res; - - #define SHAPE (vec3(d-abs(r), sign(r),d)) - //#define SHAPE (vec3(d-0.35, -1.0+2.0*clamp(0.5 + 16.0*r,0.0,1.0),d)) - d=length(p00); - n=p00 / d; - // ================================================================ - float i = 1 / (numCoeffs * 2); - - float c = texture(texture0, vec2(i, tcoordVCVSOutput.y)).x; - r = coeffsNorm(c) * SH(0, 0, n); - - c = texture(texture0, vec2(i + 1 / numCoeffs, tcoordVCVSOutput.y)).x; - r += coeffsNorm(c) * SH(2, -2, n); - - c = texture(texture0, vec2(i + 2 / numCoeffs, tcoordVCVSOutput.y)).x; - r += coeffsNorm(c) * SH(2, -1, n); - - c = texture(texture0, vec2(i + 3 / numCoeffs, tcoordVCVSOutput.y)).x; - r += coeffsNorm(c) * SH(2, 0, n); - - c = texture(texture0, vec2(i + 4 / numCoeffs, tcoordVCVSOutput.y)).x; - r += coeffsNorm(c) * SH(2, 1, n); - - c = texture(texture0, vec2(i + 5 / numCoeffs, tcoordVCVSOutput.y)).x; - r += coeffsNorm(c) * SH(2, 2, n); - - c = texture(texture0, vec2(i + 6 / numCoeffs, tcoordVCVSOutput.y)).x; - r += coeffsNorm(c) * SH(4, -4, n); - - c = texture(texture0, vec2(i + 7 / numCoeffs, tcoordVCVSOutput.y)).x; - r += coeffsNorm(c) * SH(4, -3, n); - - c = texture(texture0, vec2(i + 8 / numCoeffs, tcoordVCVSOutput.y)).x; - r += coeffsNorm(c) * SH(4, -2, n); - - c = texture(texture0, vec2(i + 9 / numCoeffs, tcoordVCVSOutput.y)).x; - r += coeffsNorm(c) * SH(4, -1, n); - - c = texture(texture0, vec2(i + 10 / numCoeffs, tcoordVCVSOutput.y)).x; - r += coeffsNorm(c) * SH(4, 0, n); - - c = texture(texture0, vec2(i + 11 / numCoeffs, tcoordVCVSOutput.y)).x; - r += coeffsNorm(c) * SH(4, 1, n); - - c = texture(texture0, vec2(i + 12 / numCoeffs, tcoordVCVSOutput.y)).x; - r += coeffsNorm(c) * SH(4, 2, n); - - c = texture(texture0, vec2(i + 13 / numCoeffs, tcoordVCVSOutput.y)).x; - r += coeffsNorm(c) * SH(4, 3, n); - - c = texture(texture0, vec2(i + 14 / numCoeffs, tcoordVCVSOutput.y)).x; - r += coeffsNorm(c) * SH(4, 4, n); - - r *= scaleVSOutput; - // ================================================================ - s = SHAPE; - res = s; - return vec3(res.x, .5 + .5 * res.y, res.z); - } - """ - - central_diffs_normals = """ - vec3 centralDiffsNormals(in vec3 pos) - { - //vec2 e = vec2(1.0,-1.0)*0.5773*0.0005; - vec2 e = vec2(.001, -1); - return normalize( - e.xyy * map(pos + e.xyy).x + e.yyx * map(pos + e.yyx).x + - e.yxy * map(pos + e.yxy).x + e.xxx * map(pos + e.xxx).x ); - } - """ - - """ - central_diffs_normals = import_fury_shader( - os.path.join("sdf", "central_diffs.frag") - ) - """ - - cast_ray = """ - vec3 castRay(in vec3 ro, vec3 rd) - { - vec3 res = vec3(1e10, -1, 1); - - float maxd = 4; - float h = 1; - float t = 0; - vec2 m = vec2(-1); - - for(int i = 0; i < 2000; i++) - { - if(h < .01 || t > maxd) - break; - vec3 res = map(ro + rd * t); - h = res.x; - m = res.yz; - t += h * .1; - } - - if(t < maxd && t < res.x) - res = vec3(t, m); - - return res; - } - """ - - blinn_phong_model = import_fury_shader( - os.path.join("lighting", "blinn_phong_model.frag") - ) - - # fmt: off - fs_dec = compose_shader([ - fs_defs, fs_unifs, fs_vs_vars, coeffs_norm, legendre_polys, - spherical_harmonics, sdf_map, central_diffs_normals, cast_ray, - blinn_phong_model - ]) - # fmt: on - - shader_to_actor(odf_actor, "fragment", decl_code=fs_dec, debug=False) - - sdf_frag_impl = """ - vec3 pnt = vertexMCVSOutput.xyz; - - // Ray Origin - // Camera position in world space - vec3 ro = (-MCVCMatrix[3] * MCVCMatrix).xyz; - - // Ray Direction - vec3 rd = normalize(pnt - ro); - - // Light Direction - vec3 ld = normalize(ro - pnt); - - ro += pnt - ro; - - vec3 t = castRay(ro, rd); - - if(t.y > -.5) - { - vec3 pos = ro + t.y * rd; - - vec3 normal = centralDiffsNormals(pos); - - float occ = clamp(2 * t.z, 0, 1); - //float sss = pow(clamp(1 + dot(normal, rd), 0, 1), 1); - float sss = clamp(1 + dot(normal, rd), 0, 1); - - // lights - vec3 lin = 2.5 * occ * vec3(1) * (.6 + .4 * normal.y); - lin += 1 * sss * vec3(1, .95, .7) * occ; - - vec3 mater = .5 * mix(vec3(1, 1, 0), vec3(1), t.y); - - // ================================================================ - fragOutput0 = vec4(vec3(1, 0, 0) * lin, opacity); - // ================================================================ - } - else - { - discard; - } - """ - - shader_to_actor( - odf_actor, "fragment", impl_code=sdf_frag_impl, block="picking" - ) - - show_man.scene.add(odf_actor) - - sphere = get_sphere("repulsion724") - - # sh_basis = "descoteaux07" - sh_basis = "tournier07" - sh_order = 4 - - sh = np.zeros((3, 1, 1, 15)) - sh[0, 0, 0, :] = coeffs[0, :] - sh[1, 0, 0, :] = coeffs[1, :] - sh[2, 0, 0, :] = coeffs[2, :] - - tensor_sf = sh_to_sf( - sh, sh_order=sh_order, basis_type=sh_basis, sphere=sphere - ) - - odf_slicer_actor = actor.odf_slicer( - tensor_sf, sphere=sphere, scale=0.5, colormap="plasma" - ) - - show_man.scene.add(odf_slicer_actor) - - show_man.start() diff --git a/docs/experimental/SH-ODF experimental/texture_coefficients.py b/docs/experimental/SH-ODF experimental/texture_coefficients.py index 4f87302fe..5de728a54 100644 --- a/docs/experimental/SH-ODF experimental/texture_coefficients.py +++ b/docs/experimental/SH-ODF experimental/texture_coefficients.py @@ -1,71 +1,75 @@ """ -This spript includes TEXTURE experimentation for passing SH coeffients +This script includes TEXTURE experimentation for passing SH coefficients """ -import numpy as np import os -from fury.lib import Texture, FloatArray +import numpy as np +from dipy.data import get_sphere +from dipy.reconst.shm import sh_to_sf from fury import actor, window -from fury.shaders import (attribute_to_actor, compose_shader, - import_fury_shader, shader_to_actor) +from fury.lib import FloatArray, Texture +from fury.shaders import ( + attribute_to_actor, + compose_shader, + import_fury_shader, + shader_to_actor, +) from fury.utils import numpy_to_vtk_image_data, set_polydata_tcoords +if __name__ == "__main__": + show_man = window.ShowManager(size=(1920, 1080)) + show_man.scene.background((1, 1, 1)) + + # fmt: off + coeffs = np.array([ + [ + 0.2820735, 0.15236554, -0.04038717, -0.11270988, -0.04532376, + 0.14921817, 0.00257928, 0.0040734, -0.05313807, 0.03486542, + 0.04083064, 0.02105767, -0.04389586, -0.04302812, 0.1048641 + ], + [ + 0.28549338, 0.0978267, -0.11544838, 0.12525354, -0.00126003, + 0.00320594, 0.04744155, -0.07141446, 0.03211689, 0.04711322, + 0.08064896, 0.00154299, 0.00086506, 0.00162543, -0.00444893 + ], + [ + 0.28208936, -0.13133252, -0.04701012, -0.06303016, -0.0468775, + 0.02348355, 0.03991898, 0.02587433, 0.02645416, 0.00668765, + 0.00890633, 0.02189304, 0.00387415, 0.01665629, -0.01427194 + ] + ]) + # fmt: on + + centers = np.array([[0, -1, 0], [1, -1, 0], [2, -1, 0]]) + scales = np.array([1, 2, 2]) -if __name__ == '__main__': - centers = np.array([[0, -1, 0], [1.0, -1, 0], [2.0, -1, 0]]) - centers_2 = np.array([[0, -2, 0], [1.0, -2, 0], [2.0, -2, 0]]) - centers_3 = np.array([[0, -3, 0], [1.0, -3, 0], [2.0, -3, 0]]) - vecs = np.array([[0, 1, 0], [0, 1, 0], [0, 1, 0]]) - colors = np.array([[0, 0, 1], [0, 1, 0], [1, 0, 0]]) - scales = np.array([1.0, 2.0, 2.0]) - coeffs = np.array( - [[0.2820735, 0.15236554, -0.04038717, -0.11270988, -0.04532376, - 0.14921817, 0.00257928, 0.0040734, -0.05313807, 0.03486542, - 0.04083064, 0.02105767, -0.04389586, -0.04302812, 0.1048641], - [0.28549338, 0.0978267, -0.11544838, 0.12525354, -0.00126003, - 0.00320594, 0.04744155, -0.07141446, 0.03211689, 0.04711322, - 0.08064896, 0.00154299, 0.00086506, 0.00162543, -0.00444893], - [0.28208936, -0.13133252, -0.04701012, -0.06303016, -0.0468775, - 0.02348355, 0.03991898, 0.02587433, 0.02645416, 0.00668765, - 0.00890633, 0.02189304, 0.00387415, 0.01665629, -0.01427194]]) - - box_actor_texture = actor.box(centers=centers, scales=1.0) - box_actor_uniform_1 = actor.box(centers=np.array([centers_2[0]]), scales=1.0) - box_actor_uniform_2 = actor.box(centers=np.array([centers_2[1]]), scales=1.0) - box_actor_uniform_3 = actor.box(centers=np.array([centers_2[2]]), scales=1.0) - box_actor_template = actor.box(centers=centers_3, scales=1.0) + odf_actor = actor.box(centers=centers, scales=1.0) big_centers = np.repeat(centers, 8, axis=0) - attribute_to_actor(box_actor_texture, big_centers, 'center') - attribute_to_actor(box_actor_template, np.repeat(centers_3, 8, axis=0), 'center') - attribute_to_actor(box_actor_uniform_1, np.repeat(np.array([centers_2[0]]), 8, axis=0), 'center') - attribute_to_actor(box_actor_uniform_2, np.repeat(np.array([centers_2[1]]), 8, axis=0), 'center') - attribute_to_actor(box_actor_uniform_3, np.repeat(np.array([centers_2[2]]), 8, axis=0), 'center') + attribute_to_actor(odf_actor, big_centers, "center") big_scales = np.repeat(scales, 8, axis=0) - attribute_to_actor(box_actor_texture, big_scales, 'scale') - attribute_to_actor(box_actor_template, big_scales, 'scale') - attribute_to_actor(box_actor_uniform_1, np.repeat(np.array([scales[0]]), 8, axis=0), 'scale') - attribute_to_actor(box_actor_uniform_2, np.repeat(np.array([scales[1]]), 8, axis=0), 'scale') - attribute_to_actor(box_actor_uniform_3, np.repeat(np.array([scales[2]]), 8, axis=0), 'scale') - - box_actor_uniform_1.GetShaderProperty().GetFragmentCustomUniforms(). \ - SetUniform1fv("coeffs", 15, coeffs[0]) - box_actor_uniform_2.GetShaderProperty().GetFragmentCustomUniforms(). \ - SetUniform1fv("coeffs", 15, coeffs[1]) - box_actor_uniform_3.GetShaderProperty().GetFragmentCustomUniforms(). \ - SetUniform1fv("coeffs", 15, coeffs[2]) + attribute_to_actor(odf_actor, big_scales, "scale") + + minmax = np.array([coeffs.min(axis=1), coeffs.max(axis=1)]).T + big_minmax = np.repeat(minmax, 8, axis=0) + attribute_to_actor(odf_actor, big_minmax, 'minmax') - actor_box = box_actor_texture.GetMapper().GetInput() + odf_actor_pd = odf_actor.GetMapper().GetInput() + # fmt: off uv_vals = np.array( [ - [0, 2 / 3], [0, 1], [1, 1], [1, 2 / 3], [0, 2 / 3], [0, 1], [1, 1], [1, 2 / 3], #glyph1 - [0, 1 / 3], [0, 2 / 3], [1, 2 / 3], [1, 1 / 3], [0, 1 / 3], [0, 2 / 3], [1, 2 / 3], [1, 1 / 3], #glyph2 - [0, 0], [0, 1 / 3], [1, 1 / 3], [1, 0], [0, 0], [0, 1 / 3], [1, 1 / 3], [1, 0], #glyph3 + [0, 2 / 3], [0, 1], [1, 1], [1, 2 / 3], + [0, 2 / 3], [0, 1], [1, 1], [1, 2 / 3], # glyph1 + [0, 1 / 3], [0, 2 / 3], [1, 2 / 3], [1, 1 / 3], + [0, 1 / 3], [0, 2 / 3], [1, 2 / 3], [1, 1 / 3], # glyph2 + [0, 0], [0, 1 / 3], [1, 1 / 3], [1, 0], + [0, 0], [0, 1 / 3], [1, 1 / 3], [1, 0] # glyph3 ] ) + # fmt: on num_pnts = uv_vals.shape[0] @@ -74,471 +78,338 @@ t_coords.SetNumberOfTuples(num_pnts) [t_coords.SetTuple(i, uv_vals[i]) for i in range(num_pnts)] - set_polydata_tcoords(actor_box, t_coords) - - arr = ( - np.array( - [[0.2820735, 0.15236554, -0.04038717, -0.11270988, -0.04532376, - 0.14921817, 0.00257928, 0.0040734, -0.05313807, 0.03486542, - 0.04083064, 0.02105767, -0.04389586, -0.04302812, 0.1048641], - [0.28549338, 0.0978267, -0.11544838, 0.12525354, -0.00126003, - 0.00320594, 0.04744155, -0.07141446, 0.03211689, 0.04711322, - 0.08064896, 0.00154299, 0.00086506, 0.00162543, -0.00444893], - [0.28208936, -0.13133252, -0.04701012, -0.06303016, - -0.0468775, 0.02348355, 0.03991898, 0.02587433, 0.02645416, - 0.00668765, 0.00890633, 0.02189304, 0.00387415, 0.01665629, - -0.01427194]]) - ) - - minmax = np.array([arr.min(axis=1), arr.max(axis=1)]).T - big_minmax = np.repeat(minmax, 8, axis=0) - attribute_to_actor(box_actor_texture, big_minmax, 'minmax') + set_polydata_tcoords(odf_actor_pd, t_coords) - min = arr.min(axis=1) - max = arr.max(axis=1) + min = coeffs.min(axis=1) + max = coeffs.max(axis=1) newmin = 0 newmax = 1 - arr = np.array([(arr[i] - min[i])*((newmax - newmin) / (max[i] - min[i])) + newmin for i in range(arr.shape[0])]) + arr = np.array([(coeffs[i] - min[i])*((newmax - newmin) / (max[i] - min[i])) + newmin for i in range(coeffs.shape[0])]) arr *= 255 - print(arr.astype(np.uint8)) grid = numpy_to_vtk_image_data(arr.astype(np.uint8)) texture = Texture() texture.SetInputDataObject(grid) texture.Update() - box_actor_texture.GetProperty().SetTexture("texture0", texture) - box_actor_texture.GetShaderProperty().GetFragmentCustomUniforms()\ - .SetUniformf("k", 15) # number of coefficients per glyph - # ========================================================================= - - vs_dec = \ - """ - in vec3 center; - in float scale; - in vec2 minmax; - - out vec4 vertexMCVSOutput; - out vec3 centerMCVSOutput; - out float scaleVSOutput; - out vec2 minmaxVSOutput; - """ - - vs_impl = \ - """ - vertexMCVSOutput = vertexMC; - centerMCVSOutput = center; - scaleVSOutput = scale; - minmaxVSOutput = minmax; - vec3 camPos = -MCVCMatrix[3].xyz * mat3(MCVCMatrix); - """ - - shader_to_actor(box_actor_texture, 'vertex', decl_code=vs_dec, impl_code=vs_impl) - shader_to_actor(box_actor_template, 'vertex', decl_code=vs_dec, impl_code=vs_impl) - shader_to_actor(box_actor_uniform_1, 'vertex', decl_code=vs_dec, impl_code=vs_impl) - shader_to_actor(box_actor_uniform_2, 'vertex', decl_code=vs_dec, impl_code=vs_impl) - shader_to_actor(box_actor_uniform_3, 'vertex', decl_code=vs_dec, impl_code=vs_impl) - - fs_vars_dec = \ - """ - in vec4 vertexMCVSOutput; - in vec3 centerMCVSOutput; - in float scaleVSOutput; - in vec2 minmaxVSOutput; - uniform samplerCube texture_0; - - uniform mat4 MCVCMatrix; - """ - - sdf_map = \ - """ - - #define PI 3.1415926535898 - - // Clenshaw Legendre normalized - float Pgn(int l, int m, float x) - { - float p0 = 0., p1 = 0., p2 = 0.; + odf_actor.GetProperty().SetTexture("texture0", texture) - for (int k = l; k >= 0; k--) - { - float k1 = float(k + 1); - float m1 = float(2 * m) + k1; - float m2 = float(2 * (m + k) + 1); + # TODO: Set int uniform + odf_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniformf( + "numCoeffs", 15 + ) - p2 = p1; - p1 = p0; + vs_dec = """ + in vec3 center; + in float scale; + in vec2 minmax; - p0 = 0.; - if (l == m + k) - p0 = 1.; + out vec4 vertexMCVSOutput; + out vec3 centerMCVSOutput; + out float scaleVSOutput; + out vec2 minmaxVSOutput; + """ - float u0 = sqrt( - (m2 * (m2 + 2.0)) / - (k1 * m1) - ); + vs_impl = """ + vertexMCVSOutput = vertexMC; + centerMCVSOutput = center; + scaleVSOutput = scale; + minmaxVSOutput = minmax; + vec3 camPos = -MCVCMatrix[3].xyz * mat3(MCVCMatrix); + """ - float u1 = sqrt( - (k1 * m1 * (m2 + 4.0)) / - ((k1 + 1.0) * (m1 + 1.0) * m2) - ); + shader_to_actor(odf_actor, "vertex", decl_code=vs_dec, impl_code=vs_impl) - p0 += p1 * u0 * x; - p0 -= u1 * p2; - } + fs_defs = "#define PI 3.1415926535898" - for (int k = 1; k <= m; k++) - { - p0 *= sqrt( - (1.0 - 0.5/float(k)) * (1.0 - x) * (1.0 + x) - ); - } + fs_unifs = """ + uniform mat4 MCVCMatrix; + uniform samplerCube texture_0; + //uniform int k; + """ - p0 *= sqrt((0.5 * float(m) + 0.25)/PI); + fs_vs_vars = """ + in vec4 vertexMCVSOutput; + in vec3 centerMCVSOutput; + in float scaleVSOutput; + in vec2 minmaxVSOutput; + """ - return p0; - } + coeffs_norm = """ + float coeffsNorm(float coef) + { + float min = 0; + float max = 1; + float newMin = minmaxVSOutput.x; + float newMax = minmaxVSOutput.y; + return (coef - min) * ((newMax - newMin) / (max - min)) + newMin; + } + """ - float SH( in int l, in int m, in vec3 s ) + # Associated Legendre Polynomial + legendre_polys = """ + int factorial(int v) + { + int t = 1; + for(int i = 2; i <= v; i++) { - vec3 ns = normalize(s); + t *= i; + } + return t; + } + + // Adapted from https://patapom.com/blog/SHPortal/ + // "Evaluate an Associated Legendre Polynomial P(l,m,x) at x + // For more, see “Numerical Methods in C: The Art of Scientific Computing”, Cambridge University Press, 1992, pp 252-254" + float P(int l, int m, float x ) + { + float pmm = 1.0; + + float somx2 = sqrt((1.0-x)*(1.0+x)); + float fact = 1.0; + for ( int i=1; i<=m; i++ ) { + pmm *= (-fact) * somx2; + fact += 2.0; + } + + if( l == m ) + return pmm; + + float pmmp1 = x * (2.0*float(m)+1.0) * pmm; + if ( l == m+1 ) + return pmmp1; + + float pll = 0.0; + for ( float ll=float(m+2); ll<=float(l); ll+=1.0 ) { + pll = ( (2.0*ll-1.0)*x*pmmp1-(ll+float(m)-1.0)*pmm ) / (ll-float(m)); + pmm = pmmp1; + pmmp1 = pll; + } - if (m < 0) { - m = -m; - } + return pll; + } - // spherical coordinates - float thetax = ns.y; - float phi = atan(ns.z, ns.x)+PI/2.; - float pl = Pgn(l, m, thetax); + float K(int l, int m) + { + float n = float((2*l+1)*factorial(l - m)); + float d = 4.0 * PI * float(factorial(l + m)); + return sqrt(n/d); + } + """ - float r = pow(-1.0, float(m)) * cos(float(m) * phi) * pl; - if (m != 0) { - r *= sqrt(2.0); - } - return r; - } + spherical_harmonics = """ + float SH(int l, int m, in vec3 s) + { + vec3 ns = normalize(s); + float thetax = ns.y; + float phi = atan(ns.z, ns.x)+PI/2.; + float v = K(l, abs(m)) * P(l, abs(m), thetax); + if(m != 0) + v *= sqrt(2.0); + if(m > 0) + v *= sin(float(m)*phi); + if(m < 0) + v *= cos(float(-m)*phi); - float coef_norm( in float coef) - { - float min = 0; - float max = 1; - float newmin = minmaxVSOutput.x;//-0.13133252; - float newmax = minmaxVSOutput.y;//0.28208936; - return (coef - min) * ((newmax - newmin) / (max - min)) + newmin; - } + return v; + } """ - map_function_tex = \ - """ - vec3 map( in vec3 p ) - { - p = p - centerMCVSOutput; - vec3 p00 = p; - - float r, d; vec3 n, s, res; - - #define SHAPE (vec3(d-abs(r), sign(r),d)) - //#define SHAPE (vec3(d-0.35, -1.0+2.0*clamp(0.5 + 16.0*r,0.0,1.0),d)) - d=length(p00); - n=p00/d; - // ================================================================ - float i = 1/(k*2); - float c = texture(texture0, vec2(i, tcoordVCVSOutput.y)).x; - r = coef_norm(c)*SH(0, 0, n); - - c = texture(texture0, vec2(i+1/k, tcoordVCVSOutput.y)).x; - r += coef_norm(c)*SH(2, -2, n); - - c = texture(texture0, vec2(i+2/k, tcoordVCVSOutput.y)).x; - r += coef_norm(c)*SH(2, -1, n); - - c = texture(texture0, vec2(i+3/k, tcoordVCVSOutput.y)).x; - r += coef_norm(c)*SH(2, 0, n); - - c = texture(texture0, vec2(i+4/k, tcoordVCVSOutput.y)).x; - r += coef_norm(c)*SH(2, 1, n); - - c = texture(texture0, vec2(i+5/k, tcoordVCVSOutput.y)).x; - r += coef_norm(c)*SH(2, 2, n); - - c = texture(texture0, vec2(i+6/k, tcoordVCVSOutput.y)).x; - r += coef_norm(c)*SH(4, -4, n); - - c = texture(texture0, vec2(i+7/k, tcoordVCVSOutput.y)).x; - r += coef_norm(c)*SH(4, -3, n); - - c = texture(texture0, vec2(i+8/k, tcoordVCVSOutput.y)).x; - r += coef_norm(c)*SH(4, -2, n); - - c = texture(texture0, vec2(i+9/k, tcoordVCVSOutput.y)).x; - r += coef_norm(c)*SH(4, -1, n); - - c = texture(texture0, vec2(i+10/k, tcoordVCVSOutput.y)).x; - r += coef_norm(c)*SH(4, 0, n); - - c = texture(texture0, vec2(i+11/k, tcoordVCVSOutput.y)).x; - r += coef_norm(c)*SH(4, 1, n); - - c = texture(texture0, vec2(i+12/k, tcoordVCVSOutput.y)).x; - r += coef_norm(c)*SH(4, 2, n); - - c = texture(texture0, vec2(i+13/k, tcoordVCVSOutput.y)).x; - r += coef_norm(c)*SH(4, 3, n); - - c = texture(texture0, vec2(i+14/k, tcoordVCVSOutput.y)).x; - r += coef_norm(c)*SH(4, 4, n); - - r *= scaleVSOutput; - // ================================================================ - s = SHAPE; res = s; - return vec3( res.x, 0.5+0.5*res.y, res.z ); - } - """ + sdf_map = """ + vec3 map( in vec3 p ) + { + p = p - centerMCVSOutput; + vec3 p00 = p; - map_function_unif = \ - """ - vec3 map( in vec3 p ) - { - p = p - centerMCVSOutput;vec3 - p00 = p; - float r, d; - vec3 n, s, res; - # define SHAPE (vec3(d-abs(r), sign(r),d)) - d = length(p00); - n = p00 / d; - float - sc = scaleVSOutput; - r = coeffs[0] * SH(0, 0, n) * sc; - r += coeffs[1] * SH(2, -2, n) * sc; - r += coeffs[2] * SH(2, -1, n) * sc; - r += coeffs[3] * SH(2, 0, n) * sc; - r += coeffs[4] * SH(2, 1, n) * sc; - r += coeffs[5] * SH(2, 2, n) * sc; - r += coeffs[6] * SH(4, -4, n) * sc; - r += coeffs[7] * SH(4, -3, n) * sc; - r += coeffs[8] * SH(4, -2, n) * sc; - r += coeffs[9] * SH(4, -1, n) * sc; - r += coeffs[10] * SH(4, 0, n) * sc; - r += coeffs[11] * SH(4, 1, n) * sc; - r += coeffs[12] * SH(4, 2, n) * sc; - r += coeffs[13] * SH(4, 3, n) * sc; - r += coeffs[14] * SH(4, 4, n) * sc; - s = SHAPE; - res = s; - return vec3(res.x, 0.5 + 0.5 * res.y, res.z); - } - """ - - map_function_templ_1 = \ - """ - vec3 map( in vec3 p ) - { - p = p - centerMCVSOutput;vec3 - p00 = p; - float r, d; - vec3 n, s, res; - # define SHAPE (vec3(d-abs(r), sign(r),d)) - d = length(p00); - n = p00 / d; - float - sc = scaleVSOutput; - """ - - coeffs_1 = \ - """ - float coeffs[15] = float[15](0.2820735, 0.15236554, -0.04038717, - -0.11270988, -0.04532376, 0.14921817, 0.00257928, - 0.0040734, -0.05313807, 0.03486542, 0.04083064, 0.02105767, - -0.04389586, -0.04302812, 0.1048641); - """ - - coeffs_2 = \ - """ - float coeffs[15] = float[15](0.28549338, 0.0978267, -0.11544838, - 0.12525354, -0.00126003, 0.00320594, 0.04744155, -0.07141446, - 0.03211689, 0.04711322, 0.08064896, 0.00154299, 0.00086506, 0.00162543, - -0.00444893); - """ - - coeffs_3 = \ - """ - float coeffs[15] = float[15](0.28208936, -0.13133252, -0.04701012, - -0.06303016, -0.0468775, 0.02348355, 0.03991898, 0.02587433, - 0.02645416, 0.00668765, 0.00890633, 0.02189304, 0.00387415, 0.01665629, - -0.01427194); - """ - - map_function_templ_2 = \ - """ - r = coeffs[0] * SH(0, 0, n) * sc; - r += coeffs[1] * SH(2, -2, n) * sc; - r += coeffs[2] * SH(2, -1, n) * sc; - r += coeffs[3] * SH(2, 0, n) * sc; - r += coeffs[4] * SH(2, 1, n) * sc; - r += coeffs[5] * SH(2, 2, n) * sc; - r += coeffs[6] * SH(4, -4, n) * sc; - r += coeffs[7] * SH(4, -3, n) * sc; - r += coeffs[8] * SH(4, -2, n) * sc; - r += coeffs[9] * SH(4, -1, n) * sc; - r += coeffs[10] * SH(4, 0, n) * sc; - r += coeffs[11] * SH(4, 1, n) * sc; - r += coeffs[12] * SH(4, 2, n) * sc; - r += coeffs[13] * SH(4, 3, n) * sc; - r += coeffs[14] * SH(4, 4, n) * sc; - s = SHAPE; - res = s; - return vec3(res.x, 0.5 + 0.5 * res.y, res.z); - } - """ - - central_diffs_normal = \ - """ - vec3 centralDiffsNormals(in vec3 pos) - { - //vec2 e = vec2(1.0,-1.0)*0.5773*0.0005; - vec2 e = vec2(0.001, -1.0); - return normalize( e.xyy*map( pos + e.xyy ).x + - e.yyx*map( pos + e.yyx ).x + - e.yxy*map( pos + e.yxy ).x + - e.xxx*map( pos + e.xxx ).x ); - } - """ + float r, d; vec3 n, s, res; - cast_ray = \ - """ - vec3 castRay(in vec3 ro, vec3 rd) - { - vec3 res = vec3(1e10,-1.0, 1.0); - - float maxd = 4.0; - float h = 1.0; - float t = 0.0; - vec2 m = vec2(-1.0); - for( int i=0; i<2000; i++ ) - { - if( h<0.01||t>maxd ) break; - vec3 res = map( ro+rd*t ); - h = res.x; - m = res.yz; - t += h*0.1; - } - if( t -0.5 ) - { - vec3 pos = ro + t.y * rd; + float c = texture(texture0, vec2(i, tcoordVCVSOutput.y)).x; + r = coeffsNorm(c) * SH(0, 0, n); - vec3 normal = centralDiffsNormals(pos); + c = texture(texture0, vec2(i + 1 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(2, -2, n); - float occ = clamp( 2.0*t.z, 0.0, 1.0 ); - float sss = pow( clamp( 1.0 + dot(normal, rd), 0.0, 1.0 ), 1.0 ); + c = texture(texture0, vec2(i + 2 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(2, -1, n); - // lights - vec3 lin = 2.5*occ*vec3(1.0,1.0,1.0)*(0.6+0.4*normal.y); - lin += 1.0*sss*vec3(1.0,0.95,0.70)*occ; + c = texture(texture0, vec2(i + 3 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(2, 0, n); - vec3 mater = 0.5*mix( vec3(1.0,1.0,0.0), vec3(1.0,1.0,1.0), t.y); + c = texture(texture0, vec2(i + 4 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(2, 1, n); - // ================================================================ - fragOutput0 = vec4( vec3(1,1,0)*lin, 1.0); - // ================================================================ - } - else + c = texture(texture0, vec2(i + 5 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(2, 2, n); + + c = texture(texture0, vec2(i + 6 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(4, -4, n); + + c = texture(texture0, vec2(i + 7 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(4, -3, n); + + c = texture(texture0, vec2(i + 8 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(4, -2, n); + + c = texture(texture0, vec2(i + 9 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(4, -1, n); + + c = texture(texture0, vec2(i + 10 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(4, 0, n); + + c = texture(texture0, vec2(i + 11 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(4, 1, n); + + c = texture(texture0, vec2(i + 12 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(4, 2, n); + + c = texture(texture0, vec2(i + 13 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(4, 3, n); + + c = texture(texture0, vec2(i + 14 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(4, 4, n); + + r *= scaleVSOutput; + // ================================================================ + s = SHAPE; + res = s; + return vec3(res.x, .5 + .5 * res.y, res.z); + } + """ + + central_diffs_normals = """ + vec3 centralDiffsNormals(in vec3 pos) + { + //vec2 e = vec2(1.0,-1.0)*0.5773*0.0005; + vec2 e = vec2(.001, -1); + return normalize( + e.xyy * map(pos + e.xyy).x + e.yyx * map(pos + e.yyx).x + + e.yxy * map(pos + e.yxy).x + e.xxx * map(pos + e.xxx).x ); + } + """ + + """ + central_diffs_normals = import_fury_shader( + os.path.join("sdf", "central_diffs.frag") + ) + """ + + cast_ray = """ + vec3 castRay(in vec3 ro, vec3 rd) + { + vec3 res = vec3(1e10, -1, 1); + + float maxd = 4; + float h = 1; + float t = 0; + vec2 m = vec2(-1); + + for(int i = 0; i < 2000; i++) { - discard; + if(h < .01 || t > maxd) + break; + vec3 res = map(ro + rd * t); + h = res.x; + m = res.yz; + t += h * .1; } + if(t < maxd && t < res.x) + res = vec3(t, m); + + return res; + } + """ + + blinn_phong_model = import_fury_shader( + os.path.join("lighting", "blinn_phong_model.frag") + ) + + # fmt: off + fs_dec = compose_shader([ + fs_defs, fs_unifs, fs_vs_vars, coeffs_norm, legendre_polys, + spherical_harmonics, sdf_map, central_diffs_normals, cast_ray, + blinn_phong_model + ]) + # fmt: on + + shader_to_actor(odf_actor, "fragment", decl_code=fs_dec, debug=False) + + sdf_frag_impl = """ + vec3 pnt = vertexMCVSOutput.xyz; + + // Ray Origin + // Camera position in world space + vec3 ro = (-MCVCMatrix[3] * MCVCMatrix).xyz; + + // Ray Direction + vec3 rd = normalize(pnt - ro); + + // Light Direction + vec3 ld = normalize(ro - pnt); + + ro += pnt - ro; + + vec3 t = castRay(ro, rd); + + if(t.y > -.5) + { + vec3 pos = ro + t.y * rd; + + vec3 normal = centralDiffsNormals(pos); + + float occ = clamp(2 * t.z, 0, 1); + //float sss = pow(clamp(1 + dot(normal, rd), 0, 1), 1); + float sss = clamp(1 + dot(normal, rd), 0, 1); - """ + // lights + vec3 lin = 2.5 * occ * vec3(1) * (.6 + .4 * normal.y); + lin += 1 * sss * vec3(1, .95, .7) * occ; - shader_to_actor(box_actor_texture, 'fragment', impl_code=sdf_frag_impl, block='picking') - shader_to_actor(box_actor_uniform_1, 'fragment', impl_code=sdf_frag_impl, block='light') - shader_to_actor(box_actor_uniform_2, 'fragment', impl_code=sdf_frag_impl, block='light') - shader_to_actor(box_actor_uniform_3, 'fragment', impl_code=sdf_frag_impl, block='light') - shader_to_actor(box_actor_template, 'fragment', impl_code=sdf_frag_impl, block='light') + vec3 mater = .5 * mix(vec3(1, 1, 0), vec3(1), t.y); - show_manager = window.ShowManager(size=(700, 500)) - show_manager.scene.background([255, 255, 255]) - show_manager.scene.add(box_actor_texture) - show_manager.scene.add(box_actor_uniform_1) - show_manager.scene.add(box_actor_uniform_2) - show_manager.scene.add(box_actor_uniform_3) - show_manager.scene.add(box_actor_template) + // ================================================================ + fragOutput0 = vec4(vec3(1, 0, 0) * lin, opacity); + // ================================================================ + } + else + { + discard; + } + """ + + shader_to_actor( + odf_actor, "fragment", impl_code=sdf_frag_impl, block="picking" + ) - from dipy.reconst.shm import sh_to_sf - from dipy.data import get_sphere + show_man.scene.add(odf_actor) - sphere = get_sphere('repulsion724') + sphere = get_sphere("repulsion724") - sh_basis = 'descoteaux07' + sh_basis = "descoteaux07" + # sh_basis = "tournier07" sh_order = 4 - tensor_sh = coeffs = np.array( - [[[[0.2820735, 0.15236554, -0.04038717, -0.11270988, -0.04532376, - 0.14921817, 0.00257928, 0.0040734, -0.05313807, 0.03486542, - 0.04083064, 0.02105767, -0.04389586, -0.04302812, 0.1048641]]], - [[[0.28549338, 0.0978267, -0.11544838, 0.12525354, -0.00126003, - 0.00320594, 0.04744155, -0.07141446, 0.03211689, 0.04711322, - 0.08064896, 0.00154299, 0.00086506, 0.00162543, -0.00444893]]], - [[[0.28208936, -0.13133252, -0.04701012, -0.06303016, -0.0468775, - 0.02348355, 0.03991898, 0.02587433, 0.02645416, 0.00668765, - 0.00890633, 0.02189304, 0.00387415, 0.01665629, -0.01427194]]]]) - tensor_sf = sh_to_sf(tensor_sh, sh_order=4, basis_type='descoteaux07', - sphere=sphere) - odf_actor = actor.odf_slicer(tensor_sf, sphere=sphere, scale=0.5, - colormap='plasma') - show_manager.scene.add(odf_actor) + sh = np.zeros((3, 1, 1, 15)) + sh[0, 0, 0, :] = coeffs[0, :] + sh[1, 0, 0, :] = coeffs[1, :] + sh[2, 0, 0, :] = coeffs[2, :] + + tensor_sf = sh_to_sf( + sh, sh_order=sh_order, basis_type=sh_basis, sphere=sphere + ) + + odf_slicer_actor = actor.odf_slicer( + tensor_sf, sphere=sphere, scale=0.5, colormap="plasma" + ) + + show_man.scene.add(odf_slicer_actor) - show_manager.start() + show_man.start() From 31900bba2717bb0da5990a8920f276d3647899b4 Mon Sep 17 00:00:00 2001 From: tvcastillod Date: Fri, 10 Nov 2023 14:21:48 -0500 Subject: [PATCH 017/118] adjusted uv vals --- .../SH-ODF experimental/texture_coefficients.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/experimental/SH-ODF experimental/texture_coefficients.py b/docs/experimental/SH-ODF experimental/texture_coefficients.py index 5de728a54..0e85efaa3 100644 --- a/docs/experimental/SH-ODF experimental/texture_coefficients.py +++ b/docs/experimental/SH-ODF experimental/texture_coefficients.py @@ -68,7 +68,12 @@ [0, 0], [0, 1 / 3], [1, 1 / 3], [1, 0], [0, 0], [0, 1 / 3], [1, 1 / 3], [1, 0] # glyph3 ] - ) + ) + [[0.1, 0.1], [0.1, -0.1], [-0.1, -0.1], [-0.1, 0.1], + [0.1, 0.1], [0.1, -0.1], [-0.1, -0.1], [-0.1, 0.1], + [0.1, 0.1], [0.1, -0.1], [-0.1, -0.1], [-0.1, 0.1], + [0.1, 0.1], [0.1, -0.1], [-0.1, -0.1], [-0.1, 0.1], + [0.1, 0.1], [0.1, -0.1], [-0.1, -0.1], [-0.1, 0.1], + [0.1, 0.1], [0.1, -0.1], [-0.1, -0.1], [-0.1, 0.1]] # fmt: on num_pnts = uv_vals.shape[0] From f747107503dd1c8391d8bdba697417c1985899c5 Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Fri, 17 Nov 2023 16:10:01 -0500 Subject: [PATCH 018/118] Added minor changes. --- .../texture_coefficients.py | 90 +++++++++++-------- 1 file changed, 51 insertions(+), 39 deletions(-) diff --git a/docs/experimental/SH-ODF experimental/texture_coefficients.py b/docs/experimental/SH-ODF experimental/texture_coefficients.py index 0e85efaa3..4bbfd2765 100644 --- a/docs/experimental/SH-ODF experimental/texture_coefficients.py +++ b/docs/experimental/SH-ODF experimental/texture_coefficients.py @@ -51,10 +51,10 @@ big_scales = np.repeat(scales, 8, axis=0) attribute_to_actor(odf_actor, big_scales, "scale") - + minmax = np.array([coeffs.min(axis=1), coeffs.max(axis=1)]).T big_minmax = np.repeat(minmax, 8, axis=0) - attribute_to_actor(odf_actor, big_minmax, 'minmax') + attribute_to_actor(odf_actor, big_minmax, "minmax") odf_actor_pd = odf_actor.GetMapper().GetInput() @@ -68,12 +68,14 @@ [0, 0], [0, 1 / 3], [1, 1 / 3], [1, 0], [0, 0], [0, 1 / 3], [1, 1 / 3], [1, 0] # glyph3 ] - ) + [[0.1, 0.1], [0.1, -0.1], [-0.1, -0.1], [-0.1, 0.1], - [0.1, 0.1], [0.1, -0.1], [-0.1, -0.1], [-0.1, 0.1], - [0.1, 0.1], [0.1, -0.1], [-0.1, -0.1], [-0.1, 0.1], - [0.1, 0.1], [0.1, -0.1], [-0.1, -0.1], [-0.1, 0.1], - [0.1, 0.1], [0.1, -0.1], [-0.1, -0.1], [-0.1, 0.1], - [0.1, 0.1], [0.1, -0.1], [-0.1, -0.1], [-0.1, 0.1]] + ) + [ + [0.1, 0.1], [0.1, -0.1], [-0.1, -0.1], [-0.1, 0.1], + [0.1, 0.1], [0.1, -0.1], [-0.1, -0.1], [-0.1, 0.1], # glyph1 + [0.1, 0.1], [0.1, -0.1], [-0.1, -0.1], [-0.1, 0.1], + [0.1, 0.1], [0.1, -0.1], [-0.1, -0.1], [-0.1, 0.1], # glyph2 + [0.1, 0.1], [0.1, -0.1], [-0.1, -0.1], [-0.1, 0.1], + [0.1, 0.1], [0.1, -0.1], [-0.1, -0.1], [-0.1, 0.1] # glyph3 + ] # fmt: on num_pnts = uv_vals.shape[0] @@ -89,7 +91,13 @@ max = coeffs.max(axis=1) newmin = 0 newmax = 1 - arr = np.array([(coeffs[i] - min[i])*((newmax - newmin) / (max[i] - min[i])) + newmin for i in range(coeffs.shape[0])]) + arr = np.array( + [ + (coeffs[i] - min[i]) * ((newmax - newmin) / (max[i] - min[i])) + + newmin + for i in range(coeffs.shape[0]) + ] + ) arr *= 255 grid = numpy_to_vtk_image_data(arr.astype(np.uint8)) @@ -151,8 +159,8 @@ } """ - # Associated Legendre Polynomial - legendre_polys = """ + # Functions needed to calculate the associated Legendre polynomial + factorial = """ int factorial(int v) { int t = 1; @@ -162,44 +170,48 @@ } return t; } + """ - // Adapted from https://patapom.com/blog/SHPortal/ - // "Evaluate an Associated Legendre Polynomial P(l,m,x) at x - // For more, see “Numerical Methods in C: The Art of Scientific Computing”, Cambridge University Press, 1992, pp 252-254" + # Adapted from https://patapom.com/blog/SHPortal/ + # "Evaluate an Associated Legendre Polynomial P(l,m,x) at x + # For more, see “Numerical Methods in C: The Art of Scientific Computing”, + # Cambridge University Press, 1992, pp 252-254" + legendre_polys = """ float P(int l, int m, float x ) { - float pmm = 1.0; - - float somx2 = sqrt((1.0-x)*(1.0+x)); - float fact = 1.0; - for ( int i=1; i<=m; i++ ) { - pmm *= (-fact) * somx2; - fact += 2.0; + float pmm = 1; + + float somx2 = sqrt((1 - x) * (1 + x)); + float fact = 1; + for (int i=1; i<=m; i++) { + pmm *= -fact * somx2; + fact += 2; } - + if( l == m ) return pmm; - float pmmp1 = x * (2.0*float(m)+1.0) * pmm; - if ( l == m+1 ) + float pmmp1 = x * (2 * m + 1) * pmm; + if(l == m + 1) return pmmp1; - float pll = 0.0; - for ( float ll=float(m+2); ll<=float(l); ll+=1.0 ) { - pll = ( (2.0*ll-1.0)*x*pmmp1-(ll+float(m)-1.0)*pmm ) / (ll-float(m)); + float pll = 0; + for (float ll=m + 2; ll<=l; ll+=1) { + pll = ((2 * ll - 1) * x * pmmp1 - (ll + m - 1) * pmm) / (ll - m); pmm = pmmp1; pmmp1 = pll; } return pll; } + """ - + norm_const = """ float K(int l, int m) { - float n = float((2*l+1)*factorial(l - m)); - float d = 4.0 * PI * float(factorial(l + m)); - return sqrt(n/d); + float n = (2 * l + 1) * factorial(l - m); + float d = 4 * PI * factorial(l + m); + return sqrt(n / d); } """ @@ -208,15 +220,15 @@ { vec3 ns = normalize(s); float thetax = ns.y; - float phi = atan(ns.z, ns.x)+PI/2.; + float phi = atan(ns.z, ns.x) + PI / 2; float v = K(l, abs(m)) * P(l, abs(m), thetax); if(m != 0) - v *= sqrt(2.0); + v *= sqrt(2); if(m > 0) - v *= sin(float(m)*phi); + v *= sin(m * phi); if(m < 0) - v *= cos(float(-m)*phi); - + v *= cos(-m * phi); + return v; } """ @@ -339,9 +351,9 @@ # fmt: off fs_dec = compose_shader([ - fs_defs, fs_unifs, fs_vs_vars, coeffs_norm, legendre_polys, - spherical_harmonics, sdf_map, central_diffs_normals, cast_ray, - blinn_phong_model + fs_defs, fs_unifs, fs_vs_vars, coeffs_norm, factorial, legendre_polys, + norm_const, spherical_harmonics, sdf_map, central_diffs_normals, + cast_ray, blinn_phong_model ]) # fmt: on From d0ab18ce72efdbd0087c0cdda61ca5a231ed8218 Mon Sep 17 00:00:00 2001 From: tvcastillod Date: Sat, 2 Dec 2023 12:48:06 -0500 Subject: [PATCH 019/118] added new file for SH efficient implementation --- .../SH-ODF experimental/eff_sh.py | 3350 +++++++++++++++++ 1 file changed, 3350 insertions(+) create mode 100644 docs/experimental/SH-ODF experimental/eff_sh.py diff --git a/docs/experimental/SH-ODF experimental/eff_sh.py b/docs/experimental/SH-ODF experimental/eff_sh.py new file mode 100644 index 000000000..080bd6933 --- /dev/null +++ b/docs/experimental/SH-ODF experimental/eff_sh.py @@ -0,0 +1,3350 @@ +""" +This script includes TEXTURE experimentation for passing SH coefficients +""" +import os + +import numpy as np +from dipy.data import get_sphere +from dipy.reconst.shm import sh_to_sf + +from fury import actor, window +from fury.lib import FloatArray, Texture +from fury.shaders import ( + attribute_to_actor, + compose_shader, + import_fury_shader, + shader_to_actor, +) +from fury.utils import numpy_to_vtk_image_data, set_polydata_tcoords + +if __name__ == "__main__": + show_man = window.ShowManager(size=(1920, 1080)) + show_man.scene.background((1, 1, 1)) + + # fmt: off + coeffs = np.array([ + [ + 0.2820735, 0.15236554, -0.04038717, -0.11270988, -0.04532376, + 0.14921817, 0.00257928, 0.0040734, -0.05313807, 0.03486542, + 0.04083064, 0.02105767, -0.04389586, -0.04302812, 0.1048641 + ], + [ + 0.28549338, 0.0978267, -0.11544838, 0.12525354, -0.00126003, + 0.00320594, 0.04744155, -0.07141446, 0.03211689, 0.04711322, + 0.08064896, 0.00154299, 0.00086506, 0.00162543, -0.00444893 + ], + [ + 0.28208936, -0.13133252, -0.04701012, -0.06303016, -0.0468775, + 0.02348355, 0.03991898, 0.02587433, 0.02645416, 0.00668765, + 0.00890633, 0.02189304, 0.00387415, 0.01665629, -0.01427194 + ] + ]) + # fmt: on + + centers = np.array([[0, -1, 0], [1, -1, 0], [2, -1, 0]]) + scales = np.array([1, 2, 2]) + + odf_actor = actor.box(centers=centers, scales=1.0) + + big_centers = np.repeat(centers, 8, axis=0) + attribute_to_actor(odf_actor, big_centers, "center") + + big_scales = np.repeat(scales, 8, axis=0) + attribute_to_actor(odf_actor, big_scales, "scale") + + minmax = np.array([coeffs.min(axis=1), coeffs.max(axis=1)]).T + big_minmax = np.repeat(minmax, 8, axis=0) + attribute_to_actor(odf_actor, big_minmax, 'minmax') + + odf_actor_pd = odf_actor.GetMapper().GetInput() + + # fmt: off + uv_vals = np.array( + [ + [0, 2 / 3], [0, 1], [1, 1], [1, 2 / 3], + [0, 2 / 3], [0, 1], [1, 1], [1, 2 / 3], # glyph1 + [0, 1 / 3], [0, 2 / 3], [1, 2 / 3], [1, 1 / 3], + [0, 1 / 3], [0, 2 / 3], [1, 2 / 3], [1, 1 / 3], # glyph2 + [0, 0], [0, 1 / 3], [1, 1 / 3], [1, 0], + [0, 0], [0, 1 / 3], [1, 1 / 3], [1, 0] # glyph3 + ] + ) + [[0.1, 0.1], [0.1, -0.1], [-0.1, -0.1], [-0.1, 0.1], + [0.1, 0.1], [0.1, -0.1], [-0.1, -0.1], [-0.1, 0.1], + [0.1, 0.1], [0.1, -0.1], [-0.1, -0.1], [-0.1, 0.1], + [0.1, 0.1], [0.1, -0.1], [-0.1, -0.1], [-0.1, 0.1], + [0.1, 0.1], [0.1, -0.1], [-0.1, -0.1], [-0.1, 0.1], + [0.1, 0.1], [0.1, -0.1], [-0.1, -0.1], [-0.1, 0.1]] + # fmt: on + + num_pnts = uv_vals.shape[0] + + t_coords = FloatArray() + t_coords.SetNumberOfComponents(2) + t_coords.SetNumberOfTuples(num_pnts) + [t_coords.SetTuple(i, uv_vals[i]) for i in range(num_pnts)] + + set_polydata_tcoords(odf_actor_pd, t_coords) + + min = coeffs.min(axis=1) + max = coeffs.max(axis=1) + newmin = 0 + newmax = 1 + arr = np.array([(coeffs[i] - min[i])*((newmax - newmin) / (max[i] - min[i])) + newmin for i in range(coeffs.shape[0])]) + arr *= 255 + grid = numpy_to_vtk_image_data(arr.astype(np.uint8)) + + texture = Texture() + texture.SetInputDataObject(grid) + texture.Update() + + odf_actor.GetProperty().SetTexture("texture0", texture) + + # TODO: Set int uniform + odf_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniformf( + "numCoeffs", 15 + ) + + vs_dec = """ + in vec3 center; + in float scale; + in vec2 minmax; + + out vec4 vertexMCVSOutput; + out vec3 centerMCVSOutput; + out float scaleVSOutput; + out vec2 minmaxVSOutput; + """ + + vs_impl = """ + vertexMCVSOutput = vertexMC; + centerMCVSOutput = center; + scaleVSOutput = scale; + minmaxVSOutput = minmax; + vec3 camPos = -MCVCMatrix[3].xyz * mat3(MCVCMatrix); + """ + + shader_to_actor(odf_actor, "vertex", decl_code=vs_dec, impl_code=vs_impl) + + fs_defs = "#define PI 3.1415926535898" + + fs_unifs = """ + uniform mat4 MCVCMatrix; + uniform samplerCube texture_0; + //uniform int k; + """ + + fs_vs_vars = """ + in vec4 vertexMCVSOutput; + in vec3 centerMCVSOutput; + in float scaleVSOutput; + in vec2 minmaxVSOutput; + """ + + coeffs_norm = """ + float coeffsNorm(float coef) + { + float min = 0; + float max = 1; + float newMin = minmaxVSOutput.x; + float newMax = minmaxVSOutput.y; + return (coef - min) * ((newMax - newMin) / (max - min)) + newMin; + } + """ + + # Associated Legendre Polynomial + legendre_polys = """ + int factorial(int v) + { + int t = 1; + for(int i = 2; i <= v; i++) + { + t *= i; + } + return t; + } + + // Adapted from https://patapom.com/blog/SHPortal/ + // "Evaluate an Associated Legendre Polynomial P(l,m,x) at x + // For more, see “Numerical Methods in C: The Art of Scientific Computing”, Cambridge University Press, 1992, pp 252-254" + float P(int l, int m, float x ) + { + float pmm = 1.0; + + float somx2 = sqrt((1.0-x)*(1.0+x)); + float fact = 1.0; + for ( int i=1; i<=m; i++ ) { + pmm *= (-fact) * somx2; + fact += 2.0; + } + + if( l == m ) + return pmm; + + float pmmp1 = x * (2.0*float(m)+1.0) * pmm; + if ( l == m+1 ) + return pmmp1; + + float pll = 0.0; + for ( float ll=float(m+2); ll<=float(l); ll+=1.0 ) { + pll = ( (2.0*ll-1.0)*x*pmmp1-(ll+float(m)-1.0)*pmm ) / (ll-float(m)); + pmm = pmmp1; + pmmp1 = pll; + } + + return pll; + } + + + float K(int l, int m) + { + float n = float((2*l+1)*factorial(l - m)); + float d = 4.0 * PI * float(factorial(l + m)); + return sqrt(n/d); + } + """ + + spherical_harmonics = """ + float SH(int l, int m, in vec3 s) + { + vec3 ns = normalize(s); + float thetax = ns.y; + float phi = atan(ns.z, ns.x)+PI/2.; + float v = K(l, abs(m)) * P(l, abs(m), thetax); + if(m != 0) + v *= sqrt(2.0); + if(m > 0) + v *= sin(float(m)*phi); + if(m < 0) + v *= cos(float(-m)*phi); + + return v; + } + """ + + sdf_map = """ + vec3 map( in vec3 p ) + { + p = p - centerMCVSOutput; + vec3 p00 = p; + + float r, d; vec3 n, s, res; + + #define SHAPE (vec3(d-abs(r), sign(r),d)) + //#define SHAPE (vec3(d-0.35, -1.0+2.0*clamp(0.5 + 16.0*r,0.0,1.0),d)) + d=length(p00); + n=p00 / d; + // ================================================================ + float i = 1 / (numCoeffs * 2); + + float c = texture(texture0, vec2(i, tcoordVCVSOutput.y)).x; + r = coeffsNorm(c) * SH(0, 0, n); + + c = texture(texture0, vec2(i + 1 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(2, -2, n); + + c = texture(texture0, vec2(i + 2 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(2, -1, n); + + c = texture(texture0, vec2(i + 3 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(2, 0, n); + + c = texture(texture0, vec2(i + 4 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(2, 1, n); + + c = texture(texture0, vec2(i + 5 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(2, 2, n); + + c = texture(texture0, vec2(i + 6 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(4, -4, n); + + c = texture(texture0, vec2(i + 7 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(4, -3, n); + + c = texture(texture0, vec2(i + 8 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(4, -2, n); + + c = texture(texture0, vec2(i + 9 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(4, -1, n); + + c = texture(texture0, vec2(i + 10 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(4, 0, n); + + c = texture(texture0, vec2(i + 11 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(4, 1, n); + + c = texture(texture0, vec2(i + 12 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(4, 2, n); + + c = texture(texture0, vec2(i + 13 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(4, 3, n); + + c = texture(texture0, vec2(i + 14 / numCoeffs, tcoordVCVSOutput.y)).x; + r += coeffsNorm(c) * SH(4, 4, n); + + r *= scaleVSOutput; + // ================================================================ + s = SHAPE; + res = s; + return vec3(res.x, .5 + .5 * res.y, res.z); + } + """ + + central_diffs_normals = """ + vec3 centralDiffsNormals(in vec3 pos) + { + //vec2 e = vec2(1.0,-1.0)*0.5773*0.0005; + vec2 e = vec2(.001, -1); + return normalize( + e.xyy * map(pos + e.xyy).x + e.yyx * map(pos + e.yyx).x + + e.yxy * map(pos + e.yxy).x + e.xxx * map(pos + e.xxx).x ); + } + """ + + """ + central_diffs_normals = import_fury_shader( + os.path.join("sdf", "central_diffs.frag") + ) + """ + + cast_ray = """ + vec3 castRay(in vec3 ro, vec3 rd) + { + vec3 res = vec3(1e10, -1, 1); + + float maxd = 4; + float h = 1; + float t = 0; + vec2 m = vec2(-1); + + for(int i = 0; i < 2000; i++) + { + if(h < .01 || t > maxd) + break; + vec3 res = map(ro + rd * t); + h = res.x; + m = res.yz; + t += h * .1; + } + + if(t < maxd && t < res.x) + res = vec3(t, m); + + return res; + } + """ + + blinn_phong_model = import_fury_shader( + os.path.join("lighting", "blinn_phong_model.frag") + ) + + common = """ + void eval_sh_2(out float out_shs[6], vec3 point) { + float x, y, z, z2, c0, s0, c1, s1, d, a; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; +} + + +void eval_sh_4(out float out_shs[15], vec3 point) { + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; +} + + +void eval_sh_6(out float out_shs[28], vec3 point) { + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[20] = -c1 * d; + out_shs[22] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[19] = c0 * d; + out_shs[23] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[18] = -c1 * d; + out_shs[24] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[17] = c0 * d; + out_shs[25] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[16] = -c1 * d; + out_shs[26] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[15] = c0 * d; + out_shs[27] = s0 * d; +} + + +void eval_sh_8(out float out_shs[45], vec3 point) { + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[20] = -c1 * d; + out_shs[22] = s1 * d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[35] = -c1 * d; + out_shs[37] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[19] = c0 * d; + out_shs[23] = s0 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[34] = c0 * d; + out_shs[38] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[18] = -c1 * d; + out_shs[24] = s1 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[33] = -c1 * d; + out_shs[39] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[17] = c0 * d; + out_shs[25] = s0 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[32] = c0 * d; + out_shs[40] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[16] = -c1 * d; + out_shs[26] = s1 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[31] = -c1 * d; + out_shs[41] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[15] = c0 * d; + out_shs[27] = s0 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[30] = c0 * d; + out_shs[42] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[29] = -c1 * d; + out_shs[43] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[28] = c0 * d; + out_shs[44] = s0 * d; +} + + +void eval_sh_10(out float out_shs[66], vec3 point) { + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + b = z2 * a - 0.250980392 * b; + a = b - 0.250773994 * a; + d = 233.240148813 * a; + out_shs[55] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[20] = -c1 * d; + out_shs[22] = s1 * d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[35] = -c1 * d; + out_shs[37] = s1 * d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + out_shs[54] = -c1 * d; + out_shs[56] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[19] = c0 * d; + out_shs[23] = s0 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[34] = c0 * d; + out_shs[38] = s0 * d; + b = z2 * a - 0.235294118 * b; + a = b - 0.238390093 * a; + d = 272.365814381 * a; + out_shs[53] = c0 * d; + out_shs[57] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[18] = -c1 * d; + out_shs[24] = s1 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[33] = -c1 * d; + out_shs[39] = s1 * d; + a = z2 * b - 0.215686275 * a; + b = a - 0.222910217 * b; + d = -213.661323441 * b; + out_shs[52] = -c1 * d; + out_shs[58] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[17] = c0 * d; + out_shs[25] = s0 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[32] = c0 * d; + out_shs[40] = s0 * d; + b = z2 * a - 0.188235294 * b; + a = b - 0.20123839 * a; + d = 151.081370682 * a; + out_shs[51] = c0 * d; + out_shs[59] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[16] = -c1 * d; + out_shs[26] = s1 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[31] = -c1 * d; + out_shs[41] = s1 * d; + a = z2 * b - 0.152941176 * a; + b = a - 0.173374613 * b; + d = -95.552248675 * b; + out_shs[50] = -c1 * d; + out_shs[60] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[15] = c0 * d; + out_shs[27] = s0 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[30] = c0 * d; + out_shs[42] = s0 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + out_shs[49] = c0 * d; + out_shs[61] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[29] = -c1 * d; + out_shs[43] = s1 * d; + a = (z2 - 5.88235294e-02) * z; + b = a - 9.90712074e-02 * z; + d = -25.910241313 * b; + out_shs[48] = -c1 * d; + out_shs[62] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[28] = c0 * d; + out_shs[44] = s0 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + out_shs[47] = c0 * d; + out_shs[63] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + out_shs[46] = -c1 * d; + out_shs[64] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + out_shs[45] = c0 * d; + out_shs[65] = s0 * d; +} + + +void eval_sh_12(out float out_shs[91], vec3 point) { + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + b = z2 * a - 0.250980392 * b; + a = b - 0.250773994 * a; + d = 233.240148813 * a; + out_shs[55] = d; + b = z2 * a - 0.250626566 * b; + a = b - 0.250517598 * a; + d = 931.186918633 * a; + out_shs[78] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[20] = -c1 * d; + out_shs[22] = s1 * d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[35] = -c1 * d; + out_shs[37] = s1 * d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + out_shs[54] = -c1 * d; + out_shs[56] = s1 * d; + a = z2 * b - 0.248120301 * a; + b = a - 0.248447205 * b; + d = -1265.233874957 * b; + out_shs[77] = -c1 * d; + out_shs[79] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[19] = c0 * d; + out_shs[23] = s0 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[34] = c0 * d; + out_shs[38] = s0 * d; + b = z2 * a - 0.235294118 * b; + a = b - 0.238390093 * a; + d = 272.365814381 * a; + out_shs[53] = c0 * d; + out_shs[57] = s0 * d; + b = z2 * a - 0.240601504 * b; + a = b - 0.242236025 * a; + d = 1121.509962433 * a; + out_shs[76] = c0 * d; + out_shs[80] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[18] = -c1 * d; + out_shs[24] = s1 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[33] = -c1 * d; + out_shs[39] = s1 * d; + a = z2 * b - 0.215686275 * a; + b = a - 0.222910217 * b; + d = -213.661323441 * b; + out_shs[52] = -c1 * d; + out_shs[58] = s1 * d; + a = z2 * b - 0.228070175 * a; + b = a - 0.231884058 * b; + d = -915.709049803 * b; + out_shs[75] = -c1 * d; + out_shs[81] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[17] = c0 * d; + out_shs[25] = s0 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[32] = c0 * d; + out_shs[40] = s0 * d; + b = z2 * a - 0.188235294 * b; + a = b - 0.20123839 * a; + d = 151.081370682 * a; + out_shs[51] = c0 * d; + out_shs[59] = s0 * d; + b = z2 * a - 0.210526316 * b; + a = b - 0.217391304 * a; + d = 686.781787352 * a; + out_shs[74] = c0 * d; + out_shs[82] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[16] = -c1 * d; + out_shs[26] = s1 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[31] = -c1 * d; + out_shs[41] = s1 * d; + a = z2 * b - 0.152941176 * a; + b = a - 0.173374613 * b; + d = -95.552248675 * b; + out_shs[50] = -c1 * d; + out_shs[60] = s1 * d; + a = z2 * b - 0.187969925 * a; + b = a - 0.198757764 * b; + d = -471.12841933 * b; + out_shs[73] = -c1 * d; + out_shs[83] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[15] = c0 * d; + out_shs[27] = s0 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[30] = c0 * d; + out_shs[42] = s0 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + out_shs[49] = c0 * d; + out_shs[61] = s0 * d; + b = z2 * a - 0.160401003 * b; + a = b - 0.175983437 * a; + d = 293.800188384 * a; + out_shs[72] = c0 * d; + out_shs[84] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[29] = -c1 * d; + out_shs[43] = s1 * d; + a = (z2 - 5.88235294e-02) * z; + b = a - 9.90712074e-02 * z; + d = -25.910241313 * b; + out_shs[48] = -c1 * d; + out_shs[62] = s1 * d; + a = z2 * b - 0.127819549 * a; + b = a - 0.149068323 * b; + d = -165.101452729 * b; + out_shs[71] = -c1 * d; + out_shs[85] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[28] = c0 * d; + out_shs[44] = s0 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + out_shs[47] = c0 * d; + out_shs[63] = s0 * d; + b = z2 * (a - 9.02255639e-02); + a = b - 0.118012422 * a; + d = 82.550726364 * a; + out_shs[70] = c0 * d; + out_shs[86] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + out_shs[46] = -c1 * d; + out_shs[64] = s1 * d; + a = (z2 - 4.76190476e-02) * z; + b = a - 8.2815735e-02 * z; + d = -36.028090689 * b; + out_shs[69] = -c1 * d; + out_shs[87] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + out_shs[45] = c0 * d; + out_shs[65] = s0 * d; + a = z2 - 4.34782609e-02; + d = 13.3042542 * a; + out_shs[68] = c0 * d; + out_shs[88] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.923210529 * z; + out_shs[67] = -c1 * d; + out_shs[89] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.800821996; + out_shs[66] = c0 * d; + out_shs[90] = s0 * d; +} + + +void eval_sh_grad_2(out float out_shs[6], out vec3 out_grads[6], vec3 point) { + float x, y, z, z2, c0, s0, c1, s1, d, a; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + out_grads[2][0] = -c0 * d; + out_grads[4][0] = s0 * d; + out_grads[2][1] = s0 * d; + out_grads[4][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + d = 1.092548431; + out_grads[1][0] = c1 * d; + out_grads[5][0] = s1 * d; + out_grads[1][1] = -s1 * d; + out_grads[5][1] = c1 * d; + d = -1.092548431; + out_grads[2][2] = -c1 * d; + out_grads[4][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; +} + + +void eval_sh_grad_4(out float out_shs[15], out vec3 out_grads[15], vec3 point) { + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + out_grads[2][0] = -c0 * d; + out_grads[4][0] = s0 * d; + out_grads[2][1] = s0 * d; + out_grads[4][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + out_grads[9][0] = -c0 * d; + out_grads[11][0] = s0 * d; + out_grads[9][1] = s0 * d; + out_grads[11][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + d = 1.092548431; + out_grads[1][0] = c1 * d; + out_grads[5][0] = s1 * d; + out_grads[1][1] = -s1 * d; + out_grads[5][1] = c1 * d; + d = -1.092548431; + out_grads[2][2] = -c1 * d; + out_grads[4][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + d = 6.62322287 * a; + out_grads[8][0] = c1 * d; + out_grads[12][0] = s1 * d; + out_grads[8][1] = -s1 * d; + out_grads[12][1] = c1 * d; + d = -14.049977415 * a; + out_grads[9][2] = -c1 * d; + out_grads[11][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + d = -5.310392309 * z; + out_grads[7][0] = -c0 * d; + out_grads[13][0] = s0 * d; + out_grads[7][1] = s0 * d; + out_grads[13][1] = c0 * d; + d = 6.62322287 * z; + out_grads[8][2] = c0 * d; + out_grads[12][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + d = 2.503342942; + out_grads[6][0] = c1 * d; + out_grads[14][0] = s1 * d; + out_grads[6][1] = -s1 * d; + out_grads[14][1] = c1 * d; + d = -1.77013077; + out_grads[7][2] = -c1 * d; + out_grads[13][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; + out_grads[6][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[14][2] = 0.0; +} + + +void eval_sh_grad_6(out float out_shs[28], out vec3 out_grads[28], vec3 point) { + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + out_grads[2][0] = -c0 * d; + out_grads[4][0] = s0 * d; + out_grads[2][1] = s0 * d; + out_grads[4][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + out_grads[9][0] = -c0 * d; + out_grads[11][0] = s0 * d; + out_grads[9][1] = s0 * d; + out_grads[11][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[20] = -c1 * d; + out_shs[22] = s1 * d; + out_grads[20][0] = -c0 * d; + out_grads[22][0] = s0 * d; + out_grads[20][1] = s0 * d; + out_grads[22][1] = c0 * d; + d = 88.106914343 * b; + out_grads[21][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + d = 1.092548431; + out_grads[1][0] = c1 * d; + out_grads[5][0] = s1 * d; + out_grads[1][1] = -s1 * d; + out_grads[5][1] = c1 * d; + d = -1.092548431; + out_grads[2][2] = -c1 * d; + out_grads[4][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + d = 6.62322287 * a; + out_grads[8][0] = c1 * d; + out_grads[12][0] = s1 * d; + out_grads[8][1] = -s1 * d; + out_grads[12][1] = c1 * d; + d = -14.049977415 * a; + out_grads[9][2] = -c1 * d; + out_grads[11][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[19] = c0 * d; + out_shs[23] = s0 * d; + d = 30.399773564 * a; + out_grads[19][0] = c1 * d; + out_grads[23][0] = s1 * d; + out_grads[19][1] = -s1 * d; + out_grads[23][1] = c1 * d; + d = -96.132524816 * a; + out_grads[20][2] = -c1 * d; + out_grads[22][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + d = -5.310392309 * z; + out_grads[7][0] = -c0 * d; + out_grads[13][0] = s0 * d; + out_grads[7][1] = s0 * d; + out_grads[13][1] = c0 * d; + d = 6.62322287 * z; + out_grads[8][2] = c0 * d; + out_grads[12][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[18] = -c1 * d; + out_shs[24] = s1 * d; + d = -30.399773564 * b; + out_grads[18][0] = -c0 * d; + out_grads[24][0] = s0 * d; + out_grads[18][1] = s0 * d; + out_grads[24][1] = c0 * d; + d = 60.799547128 * b; + out_grads[19][2] = c0 * d; + out_grads[23][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + d = 2.503342942; + out_grads[6][0] = c1 * d; + out_grads[14][0] = s1 * d; + out_grads[6][1] = -s1 * d; + out_grads[14][1] = c1 * d; + d = -1.77013077; + out_grads[7][2] = -c1 * d; + out_grads[13][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[17] = c0 * d; + out_shs[25] = s0 * d; + d = 22.200855632 * a; + out_grads[17][0] = c1 * d; + out_grads[25][0] = s1 * d; + out_grads[17][1] = -s1 * d; + out_grads[25][1] = c1 * d; + d = -30.399773564 * a; + out_grads[18][2] = -c1 * d; + out_grads[24][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[16] = -c1 * d; + out_shs[26] = s1 * d; + d = -11.833095811 * z; + out_grads[16][0] = -c0 * d; + out_grads[26][0] = s0 * d; + out_grads[16][1] = s0 * d; + out_grads[26][1] = c0 * d; + d = 11.100427816 * z; + out_grads[17][2] = c0 * d; + out_grads[25][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[15] = c0 * d; + out_shs[27] = s0 * d; + d = 4.099104631; + out_grads[15][0] = c1 * d; + out_grads[27][0] = s1 * d; + out_grads[15][1] = -s1 * d; + out_grads[27][1] = c1 * d; + d = -2.366619162; + out_grads[16][2] = -c1 * d; + out_grads[26][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; + out_grads[6][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[14][2] = 0.0; + out_grads[15][2] = 0.0; + out_grads[21][0] = 0.0; + out_grads[21][1] = 0.0; + out_grads[27][2] = 0.0; +} + + +void eval_sh_grad_8(out float out_shs[45], out vec3 out_grads[45], vec3 point) { + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + out_grads[2][0] = -c0 * d; + out_grads[4][0] = s0 * d; + out_grads[2][1] = s0 * d; + out_grads[4][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + out_grads[9][0] = -c0 * d; + out_grads[11][0] = s0 * d; + out_grads[9][1] = s0 * d; + out_grads[11][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[20] = -c1 * d; + out_shs[22] = s1 * d; + out_grads[20][0] = -c0 * d; + out_grads[22][0] = s0 * d; + out_grads[20][1] = s0 * d; + out_grads[22][1] = c0 * d; + d = 88.106914343 * b; + out_grads[21][2] = d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[35] = -c1 * d; + out_shs[37] = s1 * d; + out_grads[35][0] = -c0 * d; + out_grads[37][0] = s0 * d; + out_grads[35][1] = s0 * d; + out_grads[37][1] = c0 * d; + d = 467.786944906 * b; + out_grads[36][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + d = 1.092548431; + out_grads[1][0] = c1 * d; + out_grads[5][0] = s1 * d; + out_grads[1][1] = -s1 * d; + out_grads[5][1] = c1 * d; + d = -1.092548431; + out_grads[2][2] = -c1 * d; + out_grads[4][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + d = 6.62322287 * a; + out_grads[8][0] = c1 * d; + out_grads[12][0] = s1 * d; + out_grads[8][1] = -s1 * d; + out_grads[12][1] = c1 * d; + d = -14.049977415 * a; + out_grads[9][2] = -c1 * d; + out_grads[11][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[19] = c0 * d; + out_shs[23] = s0 * d; + d = 30.399773564 * a; + out_grads[19][0] = c1 * d; + out_grads[23][0] = s1 * d; + out_grads[19][1] = -s1 * d; + out_grads[23][1] = c1 * d; + d = -96.132524816 * a; + out_grads[20][2] = -c1 * d; + out_grads[22][2] = s1 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[34] = c0 * d; + out_shs[38] = s0 * d; + d = 130.459545912 * a; + out_grads[34][0] = c1 * d; + out_grads[38][0] = s1 * d; + out_grads[34][1] = -s1 * d; + out_grads[38][1] = c1 * d; + d = -545.751435723 * a; + out_grads[35][2] = -c1 * d; + out_grads[37][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + d = -5.310392309 * z; + out_grads[7][0] = -c0 * d; + out_grads[13][0] = s0 * d; + out_grads[7][1] = s0 * d; + out_grads[13][1] = c0 * d; + d = 6.62322287 * z; + out_grads[8][2] = c0 * d; + out_grads[12][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[18] = -c1 * d; + out_shs[24] = s1 * d; + d = -30.399773564 * b; + out_grads[18][0] = -c0 * d; + out_grads[24][0] = s0 * d; + out_grads[18][1] = s0 * d; + out_grads[24][1] = c0 * d; + d = 60.799547128 * b; + out_grads[19][2] = c0 * d; + out_grads[23][2] = s0 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[33] = -c1 * d; + out_shs[39] = s1 * d; + d = -144.52614017 * b; + out_grads[33][0] = -c0 * d; + out_grads[39][0] = s0 * d; + out_grads[33][1] = s0 * d; + out_grads[39][1] = c0 * d; + d = 391.378637737 * b; + out_grads[34][2] = c0 * d; + out_grads[38][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + d = 2.503342942; + out_grads[6][0] = c1 * d; + out_grads[14][0] = s1 * d; + out_grads[6][1] = -s1 * d; + out_grads[14][1] = c1 * d; + d = -1.77013077; + out_grads[7][2] = -c1 * d; + out_grads[13][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[17] = c0 * d; + out_shs[25] = s0 * d; + d = 22.200855632 * a; + out_grads[17][0] = c1 * d; + out_grads[25][0] = s1 * d; + out_grads[17][1] = -s1 * d; + out_grads[25][1] = c1 * d; + d = -30.399773564 * a; + out_grads[18][2] = -c1 * d; + out_grads[24][2] = s1 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[32] = c0 * d; + out_shs[40] = s0 * d; + d = 124.388296437 * a; + out_grads[32][0] = c1 * d; + out_grads[40][0] = s1 * d; + out_grads[32][1] = -s1 * d; + out_grads[40][1] = c1 * d; + d = -240.876900283 * a; + out_grads[33][2] = -c1 * d; + out_grads[39][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[16] = -c1 * d; + out_shs[26] = s1 * d; + d = -11.833095811 * z; + out_grads[16][0] = -c0 * d; + out_grads[26][0] = s0 * d; + out_grads[16][1] = s0 * d; + out_grads[26][1] = c0 * d; + d = 11.100427816 * z; + out_grads[17][2] = c0 * d; + out_grads[25][2] = s0 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[31] = -c1 * d; + out_shs[41] = s1 * d; + d = -86.247765552 * b; + out_grads[31][0] = -c0 * d; + out_grads[41][0] = s0 * d; + out_grads[31][1] = s0 * d; + out_grads[41][1] = c0 * d; + d = 124.388296437 * b; + out_grads[32][2] = c0 * d; + out_grads[40][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[15] = c0 * d; + out_shs[27] = s0 * d; + d = 4.099104631; + out_grads[15][0] = c1 * d; + out_grads[27][0] = s1 * d; + out_grads[15][1] = -s1 * d; + out_grads[27][1] = c1 * d; + d = -2.366619162; + out_grads[16][2] = -c1 * d; + out_grads[26][2] = s1 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[30] = c0 * d; + out_shs[42] = s0 * d; + d = 47.909948945 * a; + out_grads[30][0] = c1 * d; + out_grads[42][0] = s1 * d; + out_grads[30][1] = -s1 * d; + out_grads[42][1] = c1 * d; + d = -51.748659331 * a; + out_grads[31][2] = -c1 * d; + out_grads[41][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[29] = -c1 * d; + out_shs[43] = s1 * d; + d = -20.409946485 * z; + out_grads[29][0] = -c0 * d; + out_grads[43][0] = s0 * d; + out_grads[29][1] = s0 * d; + out_grads[43][1] = c0 * d; + d = 15.969982982 * z; + out_grads[30][2] = c0 * d; + out_grads[42][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[28] = c0 * d; + out_shs[44] = s0 * d; + d = 5.831413281; + out_grads[28][0] = c1 * d; + out_grads[44][0] = s1 * d; + out_grads[28][1] = -s1 * d; + out_grads[44][1] = c1 * d; + d = -2.915706641; + out_grads[29][2] = -c1 * d; + out_grads[43][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; + out_grads[6][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[14][2] = 0.0; + out_grads[15][2] = 0.0; + out_grads[21][0] = 0.0; + out_grads[21][1] = 0.0; + out_grads[27][2] = 0.0; + out_grads[28][2] = 0.0; + out_grads[36][0] = 0.0; + out_grads[36][1] = 0.0; + out_grads[44][2] = 0.0; +} + + +void eval_sh_grad_10(out float out_shs[66], out vec3 out_grads[66], vec3 point) { + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + b = z2 * a - 0.250980392 * b; + a = b - 0.250773994 * a; + d = 233.240148813 * a; + out_shs[55] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + out_grads[2][0] = -c0 * d; + out_grads[4][0] = s0 * d; + out_grads[2][1] = s0 * d; + out_grads[4][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + out_grads[9][0] = -c0 * d; + out_grads[11][0] = s0 * d; + out_grads[9][1] = s0 * d; + out_grads[11][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[20] = -c1 * d; + out_shs[22] = s1 * d; + out_grads[20][0] = -c0 * d; + out_grads[22][0] = s0 * d; + out_grads[20][1] = s0 * d; + out_grads[22][1] = c0 * d; + d = 88.106914343 * b; + out_grads[21][2] = d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[35] = -c1 * d; + out_shs[37] = s1 * d; + out_grads[35][0] = -c0 * d; + out_grads[37][0] = s0 * d; + out_grads[35][1] = s0 * d; + out_grads[37][1] = c0 * d; + d = 467.786944906 * b; + out_grads[36][2] = d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + out_shs[54] = -c1 * d; + out_shs[56] = s1 * d; + out_grads[54][0] = -c0 * d; + out_grads[56][0] = s0 * d; + out_grads[54][1] = s0 * d; + out_grads[56][1] = c0 * d; + d = 2332.401488133 * b; + out_grads[55][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + d = 1.092548431; + out_grads[1][0] = c1 * d; + out_grads[5][0] = s1 * d; + out_grads[1][1] = -s1 * d; + out_grads[5][1] = c1 * d; + d = -1.092548431; + out_grads[2][2] = -c1 * d; + out_grads[4][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + d = 6.62322287 * a; + out_grads[8][0] = c1 * d; + out_grads[12][0] = s1 * d; + out_grads[8][1] = -s1 * d; + out_grads[12][1] = c1 * d; + d = -14.049977415 * a; + out_grads[9][2] = -c1 * d; + out_grads[11][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[19] = c0 * d; + out_shs[23] = s0 * d; + d = 30.399773564 * a; + out_grads[19][0] = c1 * d; + out_grads[23][0] = s1 * d; + out_grads[19][1] = -s1 * d; + out_grads[23][1] = c1 * d; + d = -96.132524816 * a; + out_grads[20][2] = -c1 * d; + out_grads[22][2] = s1 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[34] = c0 * d; + out_shs[38] = s0 * d; + d = 130.459545912 * a; + out_grads[34][0] = c1 * d; + out_grads[38][0] = s1 * d; + out_grads[34][1] = -s1 * d; + out_grads[38][1] = c1 * d; + d = -545.751435723 * a; + out_grads[35][2] = -c1 * d; + out_grads[37][2] = s1 * d; + b = z2 * a - 0.235294118 * b; + a = b - 0.238390093 * a; + d = 272.365814381 * a; + out_shs[53] = c0 * d; + out_shs[57] = s0 * d; + d = 544.731628762 * a; + out_grads[53][0] = c1 * d; + out_grads[57][0] = s1 * d; + out_grads[53][1] = -s1 * d; + out_grads[57][1] = c1 * d; + d = -2830.508572514 * a; + out_grads[54][2] = -c1 * d; + out_grads[56][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + d = -5.310392309 * z; + out_grads[7][0] = -c0 * d; + out_grads[13][0] = s0 * d; + out_grads[7][1] = s0 * d; + out_grads[13][1] = c0 * d; + d = 6.62322287 * z; + out_grads[8][2] = c0 * d; + out_grads[12][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[18] = -c1 * d; + out_shs[24] = s1 * d; + d = -30.399773564 * b; + out_grads[18][0] = -c0 * d; + out_grads[24][0] = s0 * d; + out_grads[18][1] = s0 * d; + out_grads[24][1] = c0 * d; + d = 60.799547128 * b; + out_grads[19][2] = c0 * d; + out_grads[23][2] = s0 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[33] = -c1 * d; + out_shs[39] = s1 * d; + d = -144.52614017 * b; + out_grads[33][0] = -c0 * d; + out_grads[39][0] = s0 * d; + out_grads[33][1] = s0 * d; + out_grads[39][1] = c0 * d; + d = 391.378637737 * b; + out_grads[34][2] = c0 * d; + out_grads[38][2] = s0 * d; + a = z2 * b - 0.215686275 * a; + b = a - 0.222910217 * b; + d = -213.661323441 * b; + out_shs[52] = -c1 * d; + out_shs[58] = s1 * d; + d = -640.983970322 * b; + out_grads[52][0] = -c0 * d; + out_grads[58][0] = s0 * d; + out_grads[52][1] = s0 * d; + out_grads[58][1] = c0 * d; + d = 2178.926515046 * b; + out_grads[53][2] = c0 * d; + out_grads[57][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + d = 2.503342942; + out_grads[6][0] = c1 * d; + out_grads[14][0] = s1 * d; + out_grads[6][1] = -s1 * d; + out_grads[14][1] = c1 * d; + d = -1.77013077; + out_grads[7][2] = -c1 * d; + out_grads[13][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[17] = c0 * d; + out_shs[25] = s0 * d; + d = 22.200855632 * a; + out_grads[17][0] = c1 * d; + out_grads[25][0] = s1 * d; + out_grads[17][1] = -s1 * d; + out_grads[25][1] = c1 * d; + d = -30.399773564 * a; + out_grads[18][2] = -c1 * d; + out_grads[24][2] = s1 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[32] = c0 * d; + out_shs[40] = s0 * d; + d = 124.388296437 * a; + out_grads[32][0] = c1 * d; + out_grads[40][0] = s1 * d; + out_grads[32][1] = -s1 * d; + out_grads[40][1] = c1 * d; + d = -240.876900283 * a; + out_grads[33][2] = -c1 * d; + out_grads[39][2] = s1 * d; + b = z2 * a - 0.188235294 * b; + a = b - 0.20123839 * a; + d = 151.081370682 * a; + out_shs[51] = c0 * d; + out_shs[59] = s0 * d; + d = 604.325482728 * a; + out_grads[51][0] = c1 * d; + out_grads[59][0] = s1 * d; + out_grads[51][1] = -s1 * d; + out_grads[59][1] = c1 * d; + d = -1495.629264084 * a; + out_grads[52][2] = -c1 * d; + out_grads[58][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[16] = -c1 * d; + out_shs[26] = s1 * d; + d = -11.833095811 * z; + out_grads[16][0] = -c0 * d; + out_grads[26][0] = s0 * d; + out_grads[16][1] = s0 * d; + out_grads[26][1] = c0 * d; + d = 11.100427816 * z; + out_grads[17][2] = c0 * d; + out_grads[25][2] = s0 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[31] = -c1 * d; + out_shs[41] = s1 * d; + d = -86.247765552 * b; + out_grads[31][0] = -c0 * d; + out_grads[41][0] = s0 * d; + out_grads[31][1] = s0 * d; + out_grads[41][1] = c0 * d; + d = 124.388296437 * b; + out_grads[32][2] = c0 * d; + out_grads[40][2] = s0 * d; + a = z2 * b - 0.152941176 * a; + b = a - 0.173374613 * b; + d = -95.552248675 * b; + out_shs[50] = -c1 * d; + out_shs[60] = s1 * d; + d = -477.761243376 * b; + out_grads[50][0] = -c0 * d; + out_grads[60][0] = s0 * d; + out_grads[50][1] = s0 * d; + out_grads[60][1] = c0 * d; + d = 906.488224092 * b; + out_grads[51][2] = c0 * d; + out_grads[59][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[15] = c0 * d; + out_shs[27] = s0 * d; + d = 4.099104631; + out_grads[15][0] = c1 * d; + out_grads[27][0] = s1 * d; + out_grads[15][1] = -s1 * d; + out_grads[27][1] = c1 * d; + d = -2.366619162; + out_grads[16][2] = -c1 * d; + out_grads[26][2] = s1 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[30] = c0 * d; + out_shs[42] = s0 * d; + d = 47.909948945 * a; + out_grads[30][0] = c1 * d; + out_grads[42][0] = s1 * d; + out_grads[30][1] = -s1 * d; + out_grads[42][1] = c1 * d; + d = -51.748659331 * a; + out_grads[31][2] = -c1 * d; + out_grads[41][2] = s1 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + out_shs[49] = c0 * d; + out_shs[61] = s0 * d; + d = 320.491985161 * a; + out_grads[49][0] = c1 * d; + out_grads[61][0] = s1 * d; + out_grads[49][1] = -s1 * d; + out_grads[61][1] = c1 * d; + d = -477.761243376 * a; + out_grads[50][2] = -c1 * d; + out_grads[60][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[29] = -c1 * d; + out_shs[43] = s1 * d; + d = -20.409946485 * z; + out_grads[29][0] = -c0 * d; + out_grads[43][0] = s0 * d; + out_grads[29][1] = s0 * d; + out_grads[43][1] = c0 * d; + d = 15.969982982 * z; + out_grads[30][2] = c0 * d; + out_grads[42][2] = s0 * d; + a = (z2 - 5.88235294e-02) * z; + b = a - 9.90712074e-02 * z; + d = -25.910241313 * b; + out_shs[48] = -c1 * d; + out_shs[62] = s1 * d; + d = -181.371689194 * b; + out_grads[48][0] = -c0 * d; + out_grads[62][0] = s0 * d; + out_grads[48][1] = s0 * d; + out_grads[62][1] = c0 * d; + d = 213.661323441 * b; + out_grads[49][2] = c0 * d; + out_grads[61][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[28] = c0 * d; + out_shs[44] = s0 * d; + d = 5.831413281; + out_grads[28][0] = c1 * d; + out_grads[44][0] = s1 * d; + out_grads[28][1] = -s1 * d; + out_grads[44][1] = c1 * d; + d = -2.915706641; + out_grads[29][2] = -c1 * d; + out_grads[43][2] = s1 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + out_shs[47] = c0 * d; + out_shs[63] = s0 * d; + d = 84.622493774 * a; + out_grads[47][0] = c1 * d; + out_grads[63][0] = s1 * d; + out_grads[47][1] = -s1 * d; + out_grads[63][1] = c1 * d; + d = -77.73072394 * a; + out_grads[48][2] = -c1 * d; + out_grads[62][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + out_shs[46] = -c1 * d; + out_shs[64] = s1 * d; + d = -30.887057699 * z; + out_grads[46][0] = -c0 * d; + out_grads[64][0] = s0 * d; + out_grads[46][1] = s0 * d; + out_grads[64][1] = c0 * d; + d = 21.155623443 * z; + out_grads[47][2] = c0 * d; + out_grads[63][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + out_shs[45] = c0 * d; + out_shs[65] = s0 * d; + d = 7.673951182; + out_grads[45][0] = c1 * d; + out_grads[65][0] = s1 * d; + out_grads[45][1] = -s1 * d; + out_grads[65][1] = c1 * d; + d = -3.4318953; + out_grads[46][2] = -c1 * d; + out_grads[64][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; + out_grads[6][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[14][2] = 0.0; + out_grads[15][2] = 0.0; + out_grads[21][0] = 0.0; + out_grads[21][1] = 0.0; + out_grads[27][2] = 0.0; + out_grads[28][2] = 0.0; + out_grads[36][0] = 0.0; + out_grads[36][1] = 0.0; + out_grads[44][2] = 0.0; + out_grads[45][2] = 0.0; + out_grads[55][0] = 0.0; + out_grads[55][1] = 0.0; + out_grads[65][2] = 0.0; +} + + +void eval_sh_grad_12(out float out_shs[91], out vec3 out_grads[91], vec3 point) { + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + b = z2 * a - 0.250980392 * b; + a = b - 0.250773994 * a; + d = 233.240148813 * a; + out_shs[55] = d; + b = z2 * a - 0.250626566 * b; + a = b - 0.250517598 * a; + d = 931.186918633 * a; + out_shs[78] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + out_grads[2][0] = -c0 * d; + out_grads[4][0] = s0 * d; + out_grads[2][1] = s0 * d; + out_grads[4][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + out_grads[9][0] = -c0 * d; + out_grads[11][0] = s0 * d; + out_grads[9][1] = s0 * d; + out_grads[11][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[20] = -c1 * d; + out_shs[22] = s1 * d; + out_grads[20][0] = -c0 * d; + out_grads[22][0] = s0 * d; + out_grads[20][1] = s0 * d; + out_grads[22][1] = c0 * d; + d = 88.106914343 * b; + out_grads[21][2] = d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[35] = -c1 * d; + out_shs[37] = s1 * d; + out_grads[35][0] = -c0 * d; + out_grads[37][0] = s0 * d; + out_grads[35][1] = s0 * d; + out_grads[37][1] = c0 * d; + d = 467.786944906 * b; + out_grads[36][2] = d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + out_shs[54] = -c1 * d; + out_shs[56] = s1 * d; + out_grads[54][0] = -c0 * d; + out_grads[56][0] = s0 * d; + out_grads[54][1] = s0 * d; + out_grads[56][1] = c0 * d; + d = 2332.401488133 * b; + out_grads[55][2] = d; + a = z2 * b - 0.248120301 * a; + b = a - 0.248447205 * b; + d = -1265.233874957 * b; + out_shs[77] = -c1 * d; + out_shs[79] = s1 * d; + out_grads[77][0] = -c0 * d; + out_grads[79][0] = s0 * d; + out_grads[77][1] = s0 * d; + out_grads[79][1] = c0 * d; + d = 11174.243023595 * b; + out_grads[78][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + d = 1.092548431; + out_grads[1][0] = c1 * d; + out_grads[5][0] = s1 * d; + out_grads[1][1] = -s1 * d; + out_grads[5][1] = c1 * d; + d = -1.092548431; + out_grads[2][2] = -c1 * d; + out_grads[4][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + d = 6.62322287 * a; + out_grads[8][0] = c1 * d; + out_grads[12][0] = s1 * d; + out_grads[8][1] = -s1 * d; + out_grads[12][1] = c1 * d; + d = -14.049977415 * a; + out_grads[9][2] = -c1 * d; + out_grads[11][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[19] = c0 * d; + out_shs[23] = s0 * d; + d = 30.399773564 * a; + out_grads[19][0] = c1 * d; + out_grads[23][0] = s1 * d; + out_grads[19][1] = -s1 * d; + out_grads[23][1] = c1 * d; + d = -96.132524816 * a; + out_grads[20][2] = -c1 * d; + out_grads[22][2] = s1 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[34] = c0 * d; + out_shs[38] = s0 * d; + d = 130.459545912 * a; + out_grads[34][0] = c1 * d; + out_grads[38][0] = s1 * d; + out_grads[34][1] = -s1 * d; + out_grads[38][1] = c1 * d; + d = -545.751435723 * a; + out_grads[35][2] = -c1 * d; + out_grads[37][2] = s1 * d; + b = z2 * a - 0.235294118 * b; + a = b - 0.238390093 * a; + d = 272.365814381 * a; + out_shs[53] = c0 * d; + out_shs[57] = s0 * d; + d = 544.731628762 * a; + out_grads[53][0] = c1 * d; + out_grads[57][0] = s1 * d; + out_grads[53][1] = -s1 * d; + out_grads[57][1] = c1 * d; + d = -2830.508572514 * a; + out_grads[54][2] = -c1 * d; + out_grads[56][2] = s1 * d; + b = z2 * a - 0.240601504 * b; + a = b - 0.242236025 * a; + d = 1121.509962433 * a; + out_shs[76] = c0 * d; + out_shs[80] = s0 * d; + d = 2243.019924866 * a; + out_grads[76][0] = c1 * d; + out_grads[80][0] = s1 * d; + out_grads[76][1] = -s1 * d; + out_grads[80][1] = c1 * d; + d = -13917.572624524 * a; + out_grads[77][2] = -c1 * d; + out_grads[79][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + d = -5.310392309 * z; + out_grads[7][0] = -c0 * d; + out_grads[13][0] = s0 * d; + out_grads[7][1] = s0 * d; + out_grads[13][1] = c0 * d; + d = 6.62322287 * z; + out_grads[8][2] = c0 * d; + out_grads[12][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[18] = -c1 * d; + out_shs[24] = s1 * d; + d = -30.399773564 * b; + out_grads[18][0] = -c0 * d; + out_grads[24][0] = s0 * d; + out_grads[18][1] = s0 * d; + out_grads[24][1] = c0 * d; + d = 60.799547128 * b; + out_grads[19][2] = c0 * d; + out_grads[23][2] = s0 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[33] = -c1 * d; + out_shs[39] = s1 * d; + d = -144.52614017 * b; + out_grads[33][0] = -c0 * d; + out_grads[39][0] = s0 * d; + out_grads[33][1] = s0 * d; + out_grads[39][1] = c0 * d; + d = 391.378637737 * b; + out_grads[34][2] = c0 * d; + out_grads[38][2] = s0 * d; + a = z2 * b - 0.215686275 * a; + b = a - 0.222910217 * b; + d = -213.661323441 * b; + out_shs[52] = -c1 * d; + out_shs[58] = s1 * d; + d = -640.983970322 * b; + out_grads[52][0] = -c0 * d; + out_grads[58][0] = s0 * d; + out_grads[52][1] = s0 * d; + out_grads[58][1] = c0 * d; + d = 2178.926515046 * b; + out_grads[53][2] = c0 * d; + out_grads[57][2] = s0 * d; + a = z2 * b - 0.228070175 * a; + b = a - 0.231884058 * b; + d = -915.709049803 * b; + out_shs[75] = -c1 * d; + out_shs[81] = s1 * d; + d = -2747.127149409 * b; + out_grads[75][0] = -c0 * d; + out_grads[81][0] = s0 * d; + out_grads[75][1] = s0 * d; + out_grads[81][1] = c0 * d; + d = 11215.099624332 * b; + out_grads[76][2] = c0 * d; + out_grads[80][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + d = 2.503342942; + out_grads[6][0] = c1 * d; + out_grads[14][0] = s1 * d; + out_grads[6][1] = -s1 * d; + out_grads[14][1] = c1 * d; + d = -1.77013077; + out_grads[7][2] = -c1 * d; + out_grads[13][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[17] = c0 * d; + out_shs[25] = s0 * d; + d = 22.200855632 * a; + out_grads[17][0] = c1 * d; + out_grads[25][0] = s1 * d; + out_grads[17][1] = -s1 * d; + out_grads[25][1] = c1 * d; + d = -30.399773564 * a; + out_grads[18][2] = -c1 * d; + out_grads[24][2] = s1 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[32] = c0 * d; + out_shs[40] = s0 * d; + d = 124.388296437 * a; + out_grads[32][0] = c1 * d; + out_grads[40][0] = s1 * d; + out_grads[32][1] = -s1 * d; + out_grads[40][1] = c1 * d; + d = -240.876900283 * a; + out_grads[33][2] = -c1 * d; + out_grads[39][2] = s1 * d; + b = z2 * a - 0.188235294 * b; + a = b - 0.20123839 * a; + d = 151.081370682 * a; + out_shs[51] = c0 * d; + out_shs[59] = s0 * d; + d = 604.325482728 * a; + out_grads[51][0] = c1 * d; + out_grads[59][0] = s1 * d; + out_grads[51][1] = -s1 * d; + out_grads[59][1] = c1 * d; + d = -1495.629264084 * a; + out_grads[52][2] = -c1 * d; + out_grads[58][2] = s1 * d; + b = z2 * a - 0.210526316 * b; + a = b - 0.217391304 * a; + d = 686.781787352 * a; + out_shs[74] = c0 * d; + out_shs[82] = s0 * d; + d = 2747.127149409 * a; + out_grads[74][0] = c1 * d; + out_grads[82][0] = s1 * d; + out_grads[74][1] = -s1 * d; + out_grads[82][1] = c1 * d; + d = -8241.381448228 * a; + out_grads[75][2] = -c1 * d; + out_grads[81][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[16] = -c1 * d; + out_shs[26] = s1 * d; + d = -11.833095811 * z; + out_grads[16][0] = -c0 * d; + out_grads[26][0] = s0 * d; + out_grads[16][1] = s0 * d; + out_grads[26][1] = c0 * d; + d = 11.100427816 * z; + out_grads[17][2] = c0 * d; + out_grads[25][2] = s0 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[31] = -c1 * d; + out_shs[41] = s1 * d; + d = -86.247765552 * b; + out_grads[31][0] = -c0 * d; + out_grads[41][0] = s0 * d; + out_grads[31][1] = s0 * d; + out_grads[41][1] = c0 * d; + d = 124.388296437 * b; + out_grads[32][2] = c0 * d; + out_grads[40][2] = s0 * d; + a = z2 * b - 0.152941176 * a; + b = a - 0.173374613 * b; + d = -95.552248675 * b; + out_shs[50] = -c1 * d; + out_shs[60] = s1 * d; + d = -477.761243376 * b; + out_grads[50][0] = -c0 * d; + out_grads[60][0] = s0 * d; + out_grads[50][1] = s0 * d; + out_grads[60][1] = c0 * d; + d = 906.488224092 * b; + out_grads[51][2] = c0 * d; + out_grads[59][2] = s0 * d; + a = z2 * b - 0.187969925 * a; + b = a - 0.198757764 * b; + d = -471.12841933 * b; + out_shs[73] = -c1 * d; + out_shs[83] = s1 * d; + d = -2355.642096651 * b; + out_grads[73][0] = -c0 * d; + out_grads[83][0] = s0 * d; + out_grads[73][1] = s0 * d; + out_grads[83][1] = c0 * d; + d = 5494.254298819 * b; + out_grads[74][2] = c0 * d; + out_grads[82][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[15] = c0 * d; + out_shs[27] = s0 * d; + d = 4.099104631; + out_grads[15][0] = c1 * d; + out_grads[27][0] = s1 * d; + out_grads[15][1] = -s1 * d; + out_grads[27][1] = c1 * d; + d = -2.366619162; + out_grads[16][2] = -c1 * d; + out_grads[26][2] = s1 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[30] = c0 * d; + out_shs[42] = s0 * d; + d = 47.909948945 * a; + out_grads[30][0] = c1 * d; + out_grads[42][0] = s1 * d; + out_grads[30][1] = -s1 * d; + out_grads[42][1] = c1 * d; + d = -51.748659331 * a; + out_grads[31][2] = -c1 * d; + out_grads[41][2] = s1 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + out_shs[49] = c0 * d; + out_shs[61] = s0 * d; + d = 320.491985161 * a; + out_grads[49][0] = c1 * d; + out_grads[61][0] = s1 * d; + out_grads[49][1] = -s1 * d; + out_grads[61][1] = c1 * d; + d = -477.761243376 * a; + out_grads[50][2] = -c1 * d; + out_grads[60][2] = s1 * d; + b = z2 * a - 0.160401003 * b; + a = b - 0.175983437 * a; + d = 293.800188384 * a; + out_shs[72] = c0 * d; + out_shs[84] = s0 * d; + d = 1762.801130306 * a; + out_grads[72][0] = c1 * d; + out_grads[84][0] = s1 * d; + out_grads[72][1] = -s1 * d; + out_grads[84][1] = c1 * d; + d = -3297.898935312 * a; + out_grads[73][2] = -c1 * d; + out_grads[83][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[29] = -c1 * d; + out_shs[43] = s1 * d; + d = -20.409946485 * z; + out_grads[29][0] = -c0 * d; + out_grads[43][0] = s0 * d; + out_grads[29][1] = s0 * d; + out_grads[43][1] = c0 * d; + d = 15.969982982 * z; + out_grads[30][2] = c0 * d; + out_grads[42][2] = s0 * d; + a = (z2 - 5.88235294e-02) * z; + b = a - 9.90712074e-02 * z; + d = -25.910241313 * b; + out_shs[48] = -c1 * d; + out_shs[62] = s1 * d; + d = -181.371689194 * b; + out_grads[48][0] = -c0 * d; + out_grads[62][0] = s0 * d; + out_grads[48][1] = s0 * d; + out_grads[62][1] = c0 * d; + d = 213.661323441 * b; + out_grads[49][2] = c0 * d; + out_grads[61][2] = s0 * d; + a = z2 * b - 0.127819549 * a; + b = a - 0.149068323 * b; + d = -165.101452729 * b; + out_shs[71] = -c1 * d; + out_shs[85] = s1 * d; + d = -1155.7101691 * b; + out_grads[71][0] = -c0 * d; + out_grads[85][0] = s0 * d; + out_grads[71][1] = s0 * d; + out_grads[85][1] = c0 * d; + d = 1762.801130306 * b; + out_grads[72][2] = c0 * d; + out_grads[84][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[28] = c0 * d; + out_shs[44] = s0 * d; + d = 5.831413281; + out_grads[28][0] = c1 * d; + out_grads[44][0] = s1 * d; + out_grads[28][1] = -s1 * d; + out_grads[44][1] = c1 * d; + d = -2.915706641; + out_grads[29][2] = -c1 * d; + out_grads[43][2] = s1 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + out_shs[47] = c0 * d; + out_shs[63] = s0 * d; + d = 84.622493774 * a; + out_grads[47][0] = c1 * d; + out_grads[63][0] = s1 * d; + out_grads[47][1] = -s1 * d; + out_grads[63][1] = c1 * d; + d = -77.73072394 * a; + out_grads[48][2] = -c1 * d; + out_grads[62][2] = s1 * d; + b = z2 * (a - 9.02255639e-02); + a = b - 0.118012422 * a; + d = 82.550726364 * a; + out_shs[70] = c0 * d; + out_shs[86] = s0 * d; + d = 660.405810914 * a; + out_grads[70][0] = c1 * d; + out_grads[86][0] = s1 * d; + out_grads[70][1] = -s1 * d; + out_grads[86][1] = c1 * d; + d = -825.507263643 * a; + out_grads[71][2] = -c1 * d; + out_grads[85][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + out_shs[46] = -c1 * d; + out_shs[64] = s1 * d; + d = -30.887057699 * z; + out_grads[46][0] = -c0 * d; + out_grads[64][0] = s0 * d; + out_grads[46][1] = s0 * d; + out_grads[64][1] = c0 * d; + d = 21.155623443 * z; + out_grads[47][2] = c0 * d; + out_grads[63][2] = s0 * d; + a = (z2 - 4.76190476e-02) * z; + b = a - 8.2815735e-02 * z; + d = -36.028090689 * b; + out_shs[69] = -c1 * d; + out_shs[87] = s1 * d; + d = -324.252816204 * b; + out_grads[69][0] = -c0 * d; + out_grads[87][0] = s0 * d; + out_grads[69][1] = s0 * d; + out_grads[87][1] = c0 * d; + d = 330.202905457 * b; + out_grads[70][2] = c0 * d; + out_grads[86][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + out_shs[45] = c0 * d; + out_shs[65] = s0 * d; + d = 7.673951182; + out_grads[45][0] = c1 * d; + out_grads[65][0] = s1 * d; + out_grads[45][1] = -s1 * d; + out_grads[65][1] = c1 * d; + d = -3.4318953; + out_grads[46][2] = -c1 * d; + out_grads[64][2] = s1 * d; + a = z2 - 4.34782609e-02; + d = 13.3042542 * a; + out_shs[68] = c0 * d; + out_shs[88] = s0 * d; + d = 133.042542003 * a; + out_grads[68][0] = c1 * d; + out_grads[88][0] = s1 * d; + out_grads[68][1] = -s1 * d; + out_grads[88][1] = c1 * d; + d = -108.084272068 * a; + out_grads[69][2] = -c1 * d; + out_grads[87][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.923210529 * z; + out_shs[67] = -c1 * d; + out_shs[89] = s1 * d; + d = -43.155315818 * z; + out_grads[67][0] = -c0 * d; + out_grads[89][0] = s0 * d; + out_grads[67][1] = s0 * d; + out_grads[89][1] = c0 * d; + d = 26.608508401 * z; + out_grads[68][2] = c0 * d; + out_grads[88][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.800821996; + out_shs[66] = c0 * d; + out_shs[90] = s0 * d; + d = 9.609863949; + out_grads[66][0] = c1 * d; + out_grads[90][0] = s1 * d; + out_grads[66][1] = -s1 * d; + out_grads[90][1] = c1 * d; + d = -3.923210529; + out_grads[67][2] = -c1 * d; + out_grads[89][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; + out_grads[6][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[14][2] = 0.0; + out_grads[15][2] = 0.0; + out_grads[21][0] = 0.0; + out_grads[21][1] = 0.0; + out_grads[27][2] = 0.0; + out_grads[28][2] = 0.0; + out_grads[36][0] = 0.0; + out_grads[36][1] = 0.0; + out_grads[44][2] = 0.0; + out_grads[45][2] = 0.0; + out_grads[55][0] = 0.0; + out_grads[55][1] = 0.0; + out_grads[65][2] = 0.0; + out_grads[66][2] = 0.0; + out_grads[78][0] = 0.0; + out_grads[78][1] = 0.0; + out_grads[90][2] = 0.0; +} + """ + + new_code = """ + // Supplemental code for "Ray Tracing Spherical Harmonics Glyphs": +// https://momentsingraphics.de/VMV2023.html +// View results of this shader here: https://www.shadertoy.com/view/dlGSDV +// (c) 2023, Christoph Peters +// This work is licensed under a CC0 1.0 Universal License. To the extent +// possible under law, Christoph Peters has waived all copyright and related or +// neighboring rights to the following code. This work is published from +// Germany. https://creativecommons.org/publicdomain/zero/1.0/ + +// The index of the highest used band of the spherical harmonics basis. Must be +// even, at least 2 and at most 12. +#define SH_DEGREE 4 +// The number of spherical harmonics basis functions +#define SH_COUNT (((SH_DEGREE + 1) * (SH_DEGREE + 2)) / 2) +// Degree of polynomials for which we have to find roots +#define MAX_DEGREE (2 * SH_DEGREE + 2) +// If GL_EXT_control_flow_attributes is available, these defines should be +// defined as [[unroll]] and [[loop]] to give reasonable hints to the compiler. +// That avoids register spilling, which makes execution considerably faster. +#ifndef _unroll_ +#define _unroll_ +#endif +#ifndef _loop_ +#define _loop_ +#endif +// When there are fewer intersections/roots than theoretically possible, some +// array entries are set to this value +#define NO_INTERSECTION 3.4e38 +// pi and its reciprocal +#define M_PI 3.141592653589793238462643 +#define M_INV_PI 0.318309886183790671537767526745 + + +// Searches a single root of a polynomial within a given interval. +// \param out_root The location of the found root. +// \param out_end_value The value of the given polynomial at end. +// \param poly Coefficients of the polynomial for which a root should be found. +// Coefficient poly[i] is multiplied by x^i. +// \param begin The beginning of an interval where the polynomial is monotonic. +// \param end The end of said interval. +// \param begin_value The value of the given polynomial at begin. +// \param error_tolerance The error tolerance for the returned root location. +// Typically the error will be much lower but in theory it can be +// bigger. +// return true if a root was found, false if no root exists. +bool newton_bisection(out float out_root, out float out_end_value, + float poly[MAX_DEGREE + 1], float begin, float end, + float begin_value, float error_tolerance) +{ + if (begin == end) { + out_end_value = begin_value; + return false; + } + // Evaluate the polynomial at the end of the interval + out_end_value = poly[MAX_DEGREE]; + _unroll_ + for (int i = MAX_DEGREE - 1; i != -1; --i) + out_end_value = out_end_value * end + poly[i]; + // If the values at both ends have the same non-zero sign, there is no root + if (begin_value * out_end_value > 0.0) + return false; + // Otherwise, we find the root iteratively using Newton bisection (with + // bounded iteration count) + float current = 0.5 * (begin + end); + _loop_ + for (int i = 0; i != 90; ++i) { + // Evaluate the polynomial and its derivative + float value = poly[MAX_DEGREE] * current + poly[MAX_DEGREE - 1]; + float derivative = poly[MAX_DEGREE]; + _unroll_ + for (int j = MAX_DEGREE - 2; j != -1; --j) { + derivative = derivative * current + value; + value = value * current + poly[j]; + } + // Shorten the interval + bool right = begin_value * value > 0.0; + begin = right ? current : begin; + end = right ? end : current; + // Apply Newton's method + float guess = current - value / derivative; + // Pick a guess + float middle = 0.5 * (begin + end); + float next = (guess >= begin && guess <= end) ? guess : middle; + // Move along or terminate + bool done = abs(next - current) < error_tolerance; + current = next; + if (done) + break; + } + out_root = current; + return true; +} + + +// Finds all roots of the given polynomial in the interval [begin, end] and +// writes them to out_roots. Some entries will be NO_INTERSECTION but other +// than that the array is sorted. The last entry is always NO_INTERSECTION. +void find_roots(out float out_roots[MAX_DEGREE + 1], float poly[MAX_DEGREE + 1], float begin, float end) { + float tolerance = (end - begin) * 1.0e-4; + // Construct the quadratic derivative of the polynomial. We divide each + // derivative by the factorial of its order, such that the constant + // coefficient can be copied directly from poly. That is a safeguard + // against overflow and makes it easier to avoid spilling below. The + // factors happen to be binomial coefficients then. + float derivative[MAX_DEGREE + 1]; + derivative[0] = poly[MAX_DEGREE - 2]; + derivative[1] = float(MAX_DEGREE - 1) * poly[MAX_DEGREE - 1]; + derivative[2] = (0.5 * float((MAX_DEGREE - 1) * MAX_DEGREE)) * poly[MAX_DEGREE - 0]; + _unroll_ + for (int i = 3; i != MAX_DEGREE + 1; ++i) + derivative[i] = 0.0; + // Compute its two roots using the quadratic formula + float discriminant = derivative[1] * derivative[1] - 4.0 * derivative[0] * derivative[2]; + if (discriminant >= 0.0) { + float sqrt_discriminant = sqrt(discriminant); + float scaled_root = derivative[1] + ((derivative[1] > 0.0) ? sqrt_discriminant : (-sqrt_discriminant)); + float root_0 = clamp(-2.0 * derivative[0] / scaled_root, begin, end); + float root_1 = clamp(-0.5 * scaled_root / derivative[2], begin, end); + out_roots[MAX_DEGREE - 2] = min(root_0, root_1); + out_roots[MAX_DEGREE - 1] = max(root_0, root_1); + } + else { + // Indicate that the cubic derivative has a single root + out_roots[MAX_DEGREE - 2] = begin; + out_roots[MAX_DEGREE - 1] = begin; + } + // The last entry in the root array is set to end to make it easier to + // iterate over relevant intervals, all untouched roots are set to begin + out_roots[MAX_DEGREE] = end; + _unroll_ + for (int i = 0; i != MAX_DEGREE - 2; ++i) + out_roots[i] = begin; + // Work your way up to derivatives of higher degree until you reach the + // polynomial itself. This implementation may seem peculiar: It always + // treats the derivative as though it had degree MAX_DEGREE and it + // constructs the derivatives in a contrived way. Changing that would + // reduce the number of arithmetic instructions roughly by a factor of two. + // However, it would also cause register spilling, which has a far more + // negative impact on the overall run time. Profiling indicates that the + // current implementation has no spilling whatsoever. + _loop_ + for (int degree = 3; degree != MAX_DEGREE + 1; ++degree) { + // Take the integral of the previous derivative (scaled such that the + // constant coefficient can still be copied directly from poly) + float prev_derivative_order = float(MAX_DEGREE + 1 - degree); + _unroll_ + for (int i = MAX_DEGREE; i != 0; --i) + derivative[i] = derivative[i - 1] * (prev_derivative_order * (1.0 / float(i))); + // Copy the constant coefficient without causing spilling. This part + // would be harder if the derivative were not scaled the way it is. + _unroll_ + for (int i = 0; i != MAX_DEGREE - 2; ++i) + derivative[0] = (degree == MAX_DEGREE - i) ? poly[i] : derivative[0]; + // Determine the value of this derivative at begin + float begin_value = derivative[MAX_DEGREE]; + _unroll_ + for (int i = MAX_DEGREE - 1; i != -1; --i) + begin_value = begin_value * begin + derivative[i]; + // Iterate over the intervals where roots may be found + _unroll_ + for (int i = 0; i != MAX_DEGREE; ++i) { + if (i < MAX_DEGREE - degree) + continue; + float current_begin = out_roots[i]; + float current_end = out_roots[i + 1]; + // Try to find a root + float root; + if (newton_bisection(root, begin_value, derivative, current_begin, current_end, begin_value, tolerance)) + out_roots[i] = root; + else if (degree < MAX_DEGREE) + // Create an empty interval for the next iteration + out_roots[i] = out_roots[i - 1]; + else + out_roots[i] = NO_INTERSECTION; + } + } + // We no longer need this array entry + out_roots[MAX_DEGREE] = NO_INTERSECTION; +} + + +// Evaluates the spherical harmonics basis in bands 0, 2, ..., SH_DEGREE. +// Conventions are as in the following paper. +// M. Descoteaux, E. Angelino, S. Fitzgibbons, and R. Deriche. Regularized, +// fast, and robust analytical q-ball imaging. Magnetic Resonance in Medicine, +// 58(3), 2007. https://doi.org/10.1002/mrm.21277 +// \param out_shs Values of SH basis functions in bands 0, 2, ..., SH_DEGREE in +// this order. +// \param point The point on the unit sphere where the basis should be +// evaluated. +void eval_sh(out float out_shs[SH_COUNT], vec3 point) { +#if SH_DEGREE == 2 + eval_sh_2(out_shs, point); +#elif SH_DEGREE == 4 + eval_sh_4(out_shs, point); +#elif SH_DEGREE == 6 + eval_sh_6(out_shs, point); +#elif SH_DEGREE == 8 + eval_sh_8(out_shs, point); +#elif SH_DEGREE == 10 + eval_sh_10(out_shs, point); +#elif SH_DEGREE == 12 + eval_sh_12(out_shs, point); +#endif +} + + +// Evaluates the gradient of each basis function given by eval_sh() and the +// basis itself +void eval_sh_grad(out float out_shs[SH_COUNT], out vec3 out_grads[SH_COUNT], vec3 point) { +#if SH_DEGREE == 2 + eval_sh_grad_2(out_shs, out_grads, point); +#elif SH_DEGREE == 4 + eval_sh_grad_4(out_shs, out_grads, point); +#elif SH_DEGREE == 6 + eval_sh_grad_6(out_shs, out_grads, point); +#elif SH_DEGREE == 8 + eval_sh_grad_8(out_shs, out_grads, point); +#elif SH_DEGREE == 10 + eval_sh_grad_10(out_shs, out_grads, point); +#elif SH_DEGREE == 12 + eval_sh_grad_12(out_shs, out_grads, point); +#endif +} + + +// Outputs a matrix that turns equidistant samples on the unit circle of a +// homogeneous polynomial into coefficients of that polynomial. +void get_inv_vandermonde(out float v[(SH_DEGREE + 1) * (SH_DEGREE + 1)]) { +#if SH_DEGREE == 2 + v[0*3 + 0] = -0.3333333333; v[0*3 + 1] = 0.6666666667; v[0*3 + 2] = 0.6666666667; + v[1*3 + 0] = -0.0; v[1*3 + 1] = 1.1547005384; v[1*3 + 2] = -1.1547005384; + v[2*3 + 0] = 1.0; v[2*3 + 1] = 0.0; v[2*3 + 2] = 0.0; +#elif SH_DEGREE == 4 + v[0*5 + 0] = 0.2; v[0*5 + 1] = -0.2472135955; v[0*5 + 2] = 0.6472135955; v[0*5 + 3] = 0.6472135955; v[0*5 + 4] = -0.2472135955; + v[1*5 + 0] = 0.0; v[1*5 + 1] = -0.1796111906; v[1*5 + 2] = 1.9919186279; v[1*5 + 3] = -1.9919186279; v[1*5 + 4] = 0.1796111906; + v[2*5 + 0] = -2.0; v[2*5 + 1] = 2.3416407865; v[2*5 + 2] = -0.3416407865; v[2*5 + 3] = -0.3416407865; v[2*5 + 4] = 2.3416407865; + v[3*5 + 0] = -0.0; v[3*5 + 1] = 1.7013016167; v[3*5 + 2] = -1.0514622242; v[3*5 + 3] = 1.0514622242; v[3*5 + 4] = -1.7013016167; + v[4*5 + 0] = 1.0; v[4*5 + 1] = 0.0; v[4*5 + 2] = 0.0; v[4*5 + 3] = 0.0; v[4*5 + 4] = 0.0; +#elif SH_DEGREE == 6 + v[0*7 + 0] = -0.1428571429; v[0*7 + 1] = 0.1585594663; v[0*7 + 2] = -0.2291250674; v[0*7 + 3] = 0.6419941725; v[0*7 + 4] = 0.6419941725; v[0*7 + 5] = -0.2291250674; v[0*7 + 6] = 0.1585594663; + v[1*7 + 0] = -0.0; v[1*7 + 1] = 0.0763582145; v[1*7 + 2] = -0.2873137468; v[1*7 + 3] = 2.8127602518; v[1*7 + 4] = -2.8127602518; v[1*7 + 5] = 0.2873137468; v[1*7 + 6] = -0.0763582145; + v[2*7 + 0] = 3.0; v[2*7 + 1] = -3.2929766145; v[2*7 + 2] = 4.4513463718; v[2*7 + 3] = -1.1583697574; v[2*7 + 4] = -1.1583697574; v[2*7 + 5] = 4.4513463718; v[2*7 + 6] = -3.2929766145; + v[3*7 + 0] = 0.0; v[3*7 + 1] = -1.5858139579; v[3*7 + 2] = 5.5818117995; v[3*7 + 3] = -5.0751495106; v[3*7 + 4] = 5.0751495106; v[3*7 + 5] = -5.5818117995; v[3*7 + 6] = 1.5858139579; + v[4*7 + 0] = -5.0; v[4*7 + 1] = 4.7858935686; v[4*7 + 2] = -1.0200067492; v[4*7 + 3] = 0.2341131806; v[4*7 + 4] = 0.2341131806; v[4*7 + 5] = -1.0200067492; v[4*7 + 6] = 4.7858935686; + v[5*7 + 0] = -0.0; v[5*7 + 1] = 2.3047648710; v[5*7 + 2] = -1.2790480077; v[5*7 + 3] = 1.0257168633; v[5*7 + 4] = -1.0257168633; v[5*7 + 5] = 1.2790480077; v[5*7 + 6] = -2.3047648710; + v[6*7 + 0] = 1.0; v[6*7 + 1] = 0.0; v[6*7 + 2] = 0.0; v[6*7 + 3] = 0.0; v[6*7 + 4] = 0.0; v[6*7 + 5] = 0.0; v[6*7 + 6] = 0.0; +#elif SH_DEGREE == 8 + v[0*9 + 0] = 0.1111111111; v[0*9 + 1] = -0.1182419747; v[0*9 + 2] = 0.1450452544; v[0*9 + 3] = -0.2222222222; v[0*9 + 4] = 0.6398633870; v[0*9 + 5] = 0.6398633870; v[0*9 + 6] = -0.2222222222; v[0*9 + 7] = 0.1450452544; v[0*9 + 8] = -0.1182419747; + v[1*9 + 0] = 0.0; v[1*9 + 1] = -0.0430365592; v[1*9 + 2] = 0.1217074194; v[1*9 + 3] = -0.3849001795; v[1*9 + 4] = 3.6288455938; v[1*9 + 5] = -3.6288455938; v[1*9 + 6] = 0.3849001795; v[1*9 + 7] = -0.1217074194; v[1*9 + 8] = 0.0430365592; + v[2*9 + 0] = -4.0; v[2*9 + 1] = 4.2410470634; v[2*9 + 2] = -5.1195045066; v[2*9 + 3] = 7.3333333333; v[2*9 + 4] = -2.4548758901; v[2*9 + 5] = -2.4548758901; v[2*9 + 6] = 7.3333333333; v[2*9 + 7] = -5.1195045066; v[2*9 + 8] = 4.2410470634; + v[3*9 + 0] = -0.0; v[3*9 + 1] = 1.5436148932; v[3*9 + 2] = -4.2957743433; v[3*9 + 3] = 12.7017059222; v[3*9 + 4] = -13.9222930051; v[3*9 + 5] = 13.9222930051; v[3*9 + 6] = -12.7017059222; v[3*9 + 7] = 4.2957743433; v[3*9 + 8] = -1.5436148932; + v[4*9 + 0] = 14.0; v[4*9 + 1] = -14.3366589404; v[4*9 + 2] = 14.6711193836; v[4*9 + 3] = -6.0; v[4*9 + 4] = 1.6655395568; v[4*9 + 5] = 1.6655395568; v[4*9 + 6] = -6.0; v[4*9 + 7] = 14.6711193836; v[4*9 + 8] = -14.3366589404; + v[5*9 + 0] = 0.0; v[5*9 + 1] = -5.2181171131; v[5*9 + 2] = 12.3105308637; v[5*9 + 3] = -10.3923048454; v[5*9 + 4] = 9.4457442082; v[5*9 + 5] = -9.4457442082; v[5*9 + 6] = 10.3923048454; v[5*9 + 7] = -12.3105308637; v[5*9 + 8] = 5.2181171131; + v[6*9 + 0] = -9.3333333333; v[6*9 + 1] = 8.0330865684; v[6*9 + 2] = -1.8540394597; v[6*9 + 3] = 0.6666666667; v[6*9 + 4] = -0.1790471086; v[6*9 + 5] = -0.1790471086; v[6*9 + 6] = 0.6666666667; v[6*9 + 7] = -1.8540394597; v[6*9 + 8] = 8.0330865684; + v[7*9 + 0] = -0.0; v[7*9 + 1] = 2.9238044002; v[7*9 + 2] = -1.5557238269; v[7*9 + 3] = 1.1547005384; v[7*9 + 4] = -1.0154266119; v[7*9 + 5] = 1.0154266119; v[7*9 + 6] = -1.1547005384; v[7*9 + 7] = 1.5557238269; v[7*9 + 8] = -2.9238044002; + v[8*9 + 0] = 1.0; v[8*9 + 1] = 0.0; v[8*9 + 2] = 0.0; v[8*9 + 3] = 0.0; v[8*9 + 4] = 0.0; v[8*9 + 5] = 0.0; v[8*9 + 6] = 0.0; v[8*9 + 7] = 0.0; v[8*9 + 8] = 0.0; +#elif SH_DEGREE == 10 + v[0*11 + 0] = -0.0909090909; v[0*11 + 1] = 0.0947470106; v[0*11 + 2] = -0.1080638444; v[0*11 + 3] = 0.1388220215; v[0*11 + 4] = -0.2188392043; v[0*11 + 5] = 0.6387885621; v[0*11 + 6] = 0.6387885621; v[0*11 + 7] = -0.2188392043; v[0*11 + 8] = 0.1388220215; v[0*11 + 9] = -0.1080638444; v[0*11 + 10] = 0.0947470106; + v[1*11 + 0] = -0.0; v[1*11 + 1] = 0.0278202324; v[1*11 + 2] = -0.0694484159; v[1*11 + 3] = 0.1602091533; v[1*11 + 4] = -0.4791910159; v[1*11 + 5] = 4.4428720384; v[1*11 + 6] = -4.4428720384; v[1*11 + 7] = 0.4791910159; v[1*11 + 8] = -0.1602091533; v[1*11 + 9] = 0.0694484159; v[1*11 + 10] = -0.0278202324; + v[2*11 + 0] = 5.0; v[2*11 + 1] = -5.2029168239; v[2*11 + 2] = 5.8988796576; v[2*11 + 3] = -7.4503199653; v[2*11 + 4] = 10.9868742757; v[2*11 + 5] = -4.2325171441; v[2*11 + 6] = -4.2325171441; v[2*11 + 7] = 10.9868742757; v[2*11 + 8] = -7.4503199653; v[2*11 + 9] = 5.8988796576; v[2*11 + 10] = -5.2029168239; + v[3*11 + 0] = 0.0; v[3*11 + 1] = -1.5277142200; v[3*11 + 2] = 3.7909797649; v[3*11 + 3] = -8.5981275876; v[3*11 + 4] = 24.0578988657; v[3*11 + 5] = -29.4378033460; v[3*11 + 6] = 29.4378033460; v[3*11 + 7] = -24.0578988657; v[3*11 + 8] = 8.5981275876; v[3*11 + 9] = -3.7909797649; v[3*11 + 10] = 1.5277142200; + v[4*11 + 0] = -30.0; v[4*11 + 1] = 30.8179361182; v[4*11 + 2] = -33.2247539061; v[4*11 + 3] = 35.8884989085; v[4*11 + 4] = -19.5374870834; v[4*11 + 5] = 6.0558059629; v[4*11 + 6] = 6.0558059629; v[4*11 + 7] = -19.5374870834; v[4*11 + 8] = 35.8884989085; v[4*11 + 9] = -33.2247539061; v[4*11 + 10] = 30.8179361182; + v[5*11 + 0] = -0.0; v[5*11 + 1] = 9.0489625020; v[5*11 + 2] = -21.3522528115; v[5*11 + 3] = 41.4175356200; v[5*11 + 4] = -42.7811292411; v[5*11 + 5] = 42.1190556280; v[5*11 + 6] = -42.1190556280; v[5*11 + 7] = 42.7811292411; v[5*11 + 8] = -41.4175356200; v[5*11 + 9] = 21.3522528115; v[5*11 + 10] = -9.0489625020; + v[6*11 + 0] = 42.0; v[6*11 + 1] = -41.1161037573; v[6*11 + 2] = 36.2032364762; v[6*11 + 3] = -16.3373898141; v[6*11 + 4] = 7.4261062994; v[6*11 + 5] = -2.1758492042; v[6*11 + 6] = -2.1758492042; v[6*11 + 7] = 7.4261062994; v[6*11 + 8] = -16.3373898141; v[6*11 + 9] = 36.2032364762; v[6*11 + 10] = -41.1161037573; + v[7*11 + 0] = 0.0; v[7*11 + 1] = -12.0727773496; v[7*11 + 2] = 23.2664073304; v[7*11 + 3] = -18.8543529304; v[7*11 + 4] = 16.2609045881; v[7*11 + 5] = -15.1333636234; v[7*11 + 6] = 15.1333636234; v[7*11 + 7] = -16.2609045881; v[7*11 + 8] = 18.8543529304; v[7*11 + 9] = -23.2664073304; v[7*11 + 10] = 12.0727773496; + v[8*11 + 0] = -15.0; v[8*11 + 1] = 12.0883694702; v[8*11 + 2] = -2.8781222629; v[8*11 + 3] = 1.1465503415; v[8*11 + 4] = -0.5020543475; v[8*11 + 5] = 0.1452567988; v[8*11 + 6] = 0.1452567988; v[8*11 + 7] = -0.5020543475; v[8*11 + 8] = 1.1465503415; v[8*11 + 9] = -2.8781222629; v[8*11 + 10] = 12.0883694702; + v[9*11 + 0] = -0.0; v[9*11 + 1] = 3.5494655329; v[9*11 + 2] = -1.8496568659; v[9*11 + 3] = 1.3231896304; v[9*11 + 4] = -1.0993456751; v[9*11 + 5] = 1.0102832265; v[9*11 + 6] = -1.0102832265; v[9*11 + 7] = 1.0993456751; v[9*11 + 8] = -1.3231896304; v[9*11 + 9] = 1.8496568659; v[9*11 + 10] = -3.5494655329; + v[10*11 + 0] = 1.0; v[10*11 + 1] = 0.0; v[10*11 + 2] = 0.0; v[10*11 + 3] = 0.0; v[10*11 + 4] = 0.0; v[10*11 + 5] = 0.0; v[10*11 + 6] = 0.0; v[10*11 + 7] = 0.0; v[10*11 + 8] = 0.0; v[10*11 + 9] = 0.0; v[10*11 + 10] = 0.0; +#elif SH_DEGREE == 12 + v[0*13 + 0] = 0.0769230769; v[0*13 + 1] = -0.0792252178; v[0*13 + 2] = 0.0868739663; v[0*13 + 3] = -0.1027681661; v[0*13 + 4] = 0.1354125166; v[0*13 + 5] = -0.2169261613; v[0*13 + 6] = 0.6381715239; v[0*13 + 7] = 0.6381715239; v[0*13 + 8] = -0.2169261613; v[0*13 + 9] = 0.1354125166; v[0*13 + 10] = -0.1027681661; v[0*13 + 11] = 0.0868739663; v[0*13 + 12] = -0.0792252178; + v[1*13 + 0] = -0.0; v[1*13 + 1] = -0.0195272624; v[1*13 + 2] = 0.0455949748; v[1*13 + 3] = -0.0910446506; v[1*13 + 4] = 0.1961788986; v[1*13 + 5] = -0.5719872785; v[1*13 + 6] = 5.2558153553; v[1*13 + 7] = -5.2558153553; v[1*13 + 8] = 0.5719872785; v[1*13 + 9] = -0.1961788986; v[1*13 + 10] = 0.0910446506; v[1*13 + 11] = -0.0455949748; v[1*13 + 12] = 0.0195272624; + v[2*13 + 0] = -6.0; v[2*13 + 1] = 6.1747539478; v[2*13 + 2] = -6.7522392818; v[2*13 + 3] = 7.9352584366; v[2*13 + 4] = -10.2779620900; v[2*13 + 5] = 15.4120340799; v[2*13 + 6] = -6.4918450925; v[2*13 + 7] = -6.4918450925; v[2*13 + 8] = 15.4120340799; v[2*13 + 9] = -10.2779620900; v[2*13 + 10] = 7.9352584366; v[2*13 + 11] = -6.7522392818; v[2*13 + 12] = 6.1747539478; + v[3*13 + 0] = -0.0; v[3*13 + 1] = 1.5219401578; v[3*13 + 2] = -3.5438485554; v[3*13 + 3] = 7.0300255289; v[3*13 + 4] = -14.8901987371; v[3*13 + 5] = 40.6381940129; v[3*13 + 6] = -53.4651544987; v[3*13 + 7] = 53.4651544987; v[3*13 + 8] = -40.6381940129; v[3*13 + 9] = 14.8901987371; v[3*13 + 10] = -7.0300255289; v[3*13 + 11] = 3.5438485554; v[3*13 + 12] = -1.5219401578; + v[4*13 + 0] = 55.0; v[4*13 + 1] = -56.2709061445; v[4*13 + 2] = 60.2549306937; v[4*13 + 3] = -67.2511796347; v[4*13 + 4] = 75.2477722397; v[4*13 + 5] = -47.9480941911; v[4*13 + 6] = 15.9674770369; v[4*13 + 7] = 15.9674770369; v[4*13 + 8] = -47.9480941911; v[4*13 + 9] = 75.2477722397; v[4*13 + 10] = -67.2511796347; v[4*13 + 11] = 60.2549306937; v[4*13 + 12] = -56.2709061445; + v[5*13 + 0] = 0.0; v[5*13 + 1] = -13.8695326974; v[5*13 + 2] = 31.6242271914; v[5*13 + 3] = -59.5793462127; v[5*13 + 4] = 109.0152185187; v[5*13 + 5] = -126.4287338180; v[5*13 + 6] = 131.5040045727; v[5*13 + 7] = -131.5040045727; v[5*13 + 8] = 126.4287338180; v[5*13 + 9] = -109.0152185187; v[5*13 + 10] = 59.5793462127; v[5*13 + 11] = -31.6242271914; v[5*13 + 12] = 13.8695326974; + v[6*13 + 0] = -132.0; v[6*13 + 1] = 132.5319409049; v[6*13 + 2] = -132.4780513404; v[6*13 + 3] = 123.5674782081; v[6*13 + 4] = -74.4320682907; v[6*13 + 5] = 38.8801193717; v[6*13 + 6] = -12.0694188537; v[6*13 + 7] = -12.0694188537; v[6*13 + 8] = 38.8801193717; v[6*13 + 9] = -74.4320682907; v[6*13 + 10] = 123.5674782081; v[6*13 + 11] = -132.4780513404; v[6*13 + 12] = 132.5319409049; + v[7*13 + 0] = -0.0; v[7*13 + 1] = 32.6661895777; v[7*13 + 2] = -69.5298450306; v[7*13 + 3] = 109.4712331409; v[7*13 + 4] = -107.8334673306; v[7*13 + 5] = 102.5184492897; v[7*13 + 6] = -99.4006071501; v[7*13 + 7] = 99.4006071501; v[7*13 + 8] = -102.5184492897; v[7*13 + 9] = 107.8334673306; v[7*13 + 10] = -109.4712331409; v[7*13 + 11] = 69.5298450306; v[7*13 + 12] = -32.6661895777; + v[8*13 + 0] = 99.0; v[8*13 + 1] = -93.9113626635; v[8*13 + 2] = 75.3147168618; v[8*13 + 3] = -35.2795800772; v[8*13 + 4] = 18.0521608541; v[8*13 + 5] = -8.8650350126; v[8*13 + 6] = 2.6891000373; v[8*13 + 7] = 2.6891000373; v[8*13 + 8] = -8.8650350126; v[8*13 + 9] = 18.0521608541; v[8*13 + 10] = -35.2795800772; v[8*13 + 11] = 75.3147168618; v[8*13 + 12] = -93.9113626635; + v[9*13 + 0] = 0.0; v[9*13 + 1] = -23.1470719837; v[9*13 + 2] = 39.5282127035; v[9*13 + 3] = -31.2549806126; v[9*13 + 4] = 26.1530700733; v[9*13 + 5] = -23.3751762359; v[9*13 + 6] = 22.1467313083; v[9*13 + 7] = -22.1467313083; v[9*13 + 8] = 23.3751762359; v[9*13 + 9] = -26.1530700733; v[9*13 + 10] = 31.2549806126; v[9*13 + 11] = -39.5282127035; v[9*13 + 12] = 23.1470719837; + v[10*13 + 0] = -22.0; v[10*13 + 1] = 16.9531714429; v[10*13 + 2] = -4.0999479387; v[10*13 + 3] = 1.7021989010; v[10*13 + 4] = -0.8387165175; v[10*13 + 5] = 0.4056079008; v[10*13 + 6] = -0.1223137885; v[10*13 + 7] = -0.1223137885; v[10*13 + 8] = 0.4056079008; v[10*13 + 9] = -0.8387165175; v[10*13 + 10] = 1.7021989010; v[10*13 + 11] = -4.0999479387; v[10*13 + 12] = 16.9531714429; + v[11*13 + 0] = -0.0; v[11*13 + 1] = 4.1785814689; v[11*13 + 2] = -2.1518186743; v[11*13 + 3] = 1.5080166355; v[11*13 + 4] = -1.2150906493; v[11*13 + 5] = 1.0695001374; v[11*13 + 6] = -1.0073446769; v[11*13 + 7] = 1.0073446769; v[11*13 + 8] = -1.0695001374; v[11*13 + 9] = 1.2150906493; v[11*13 + 10] = -1.5080166355; v[11*13 + 11] = 2.1518186743; v[11*13 + 12] = -4.1785814689; + v[12*13 + 0] = 1.0; v[12*13 + 1] = 0.0; v[12*13 + 2] = 0.0; v[12*13 + 3] = 0.0; v[12*13 + 4] = 0.0; v[12*13 + 5] = 0.0; v[12*13 + 6] = 0.0; v[12*13 + 7] = 0.0; v[12*13 + 8] = 0.0; v[12*13 + 9] = 0.0; v[12*13 + 10] = 0.0; v[12*13 + 11] = 0.0; v[12*13 + 12] = 0.0; +#endif +} + + +// Determines all intersections between a ray and a spherical harmonics glyph. +// \param out_ray_params The ray parameters at intersection points. The points +// themselves are at ray_origin + out_ray_params[i] * ray_dir. Some +// entries may be NO_INTERSECTION but other than that the array is +// sorted. +// \param sh_coeffs SH_COUNT spherical harmonic coefficients defining the +// glyph. Their exact meaning is defined by eval_sh(). +// \param ray_origin The origin of the ray, relative to the glyph center. +// \param ray_dir The normalized direction vector of the ray. +void ray_sh_glyph_intersections(out float out_ray_params[MAX_DEGREE], float sh_coeffs[SH_COUNT], vec3 ray_origin, vec3 ray_dir) { + // Determine the direction from the glyph center to the closest point on + // the ray + float dir_dot_origin = dot(ray_dir, ray_origin); + vec3 closest_dir = normalize(ray_origin - dir_dot_origin * ray_dir); + // Evaluate the SH polynomial at SH_DEGREE + 1 points. That is enough to + // know its value everywhere along the ray. + float sh_values[SH_DEGREE + 1]; + _unroll_ + for (int i = 0; i != SH_DEGREE + 1; ++i) { + vec3 point = cos(float(i) * (M_PI / float(SH_DEGREE + 1))) * ray_dir + + sin(float(i) * (M_PI / float(SH_DEGREE + 1))) * closest_dir; + float shs[SH_COUNT]; + eval_sh(shs, point); + sh_values[i] = 0.0; + _unroll_ + for (int j = 0; j != SH_COUNT; ++j) + sh_values[i] += sh_coeffs[j] * shs[j]; + } + // Compute coefficients of the SH polynomial along the ray in the + // coordinate frame given by ray_dir and closest_dir + float radius_poly[SH_DEGREE + 1]; + float inv_vander[(SH_DEGREE + 1) * (SH_DEGREE + 1)]; + get_inv_vandermonde(inv_vander); + _unroll_ + for (int i = 0; i != SH_DEGREE + 1; ++i) { + radius_poly[i] = 0.0; + _unroll_ + for (int j = 0; j != SH_DEGREE + 1; ++j) + radius_poly[i] += inv_vander[i * (SH_DEGREE + 1) + j] * sh_values[j]; + } + // Compute a bounding circle around the glyph in the relevant plane + float radius_max = 0.0; + _unroll_ + for (int i = 0; i != SH_DEGREE + 1; ++i) { + float bound = sqrt(pow(float(i), float(i)) * pow(float(SH_DEGREE - i), float(SH_DEGREE - i)) / pow(float(SH_DEGREE), float(SH_DEGREE))); + // Workaround for buggy compilers where 0^0 is 0 + bound = (i == 0 || i == SH_DEGREE) ? 1.0 : bound; + radius_max += bound * abs(radius_poly[i]); + } + // Figure out the interval, where (if at all) the ray intersects the circle + float closest_dot_origin = dot(closest_dir, ray_origin); + if (radius_max < abs(closest_dot_origin)) { + _unroll_ + for (int i = 0; i != MAX_DEGREE; ++i) + out_ray_params[i] = NO_INTERSECTION; + return; + } + float radius_over_dot = radius_max / closest_dot_origin; + float u_max = sqrt(radius_over_dot * radius_over_dot - 1.0); + // Take the square of radius_poly + float poly[MAX_DEGREE + 1]; + _unroll_ + for (int i = 0; i != MAX_DEGREE + 1; ++i) + poly[i] = 0.0; + _unroll_ + for (int i = 0; i != SH_DEGREE + 1; ++i) + _unroll_ + for (int j = 0; j != SH_DEGREE + 1; ++j) + poly[i + j] += radius_poly[i] * radius_poly[j]; + // Subtract the scaled (2 * SH_DEGREE + 2)-th power of the distance to the + // glyph center + float dot_sq = closest_dot_origin * closest_dot_origin; + float binomial = 1.0; + _unroll_ + for (int i = 0; i != SH_DEGREE + 2; ++i) { + poly[2 * i] -= binomial * dot_sq; + // Update the binomial coefficient using a recurrence relation + binomial *= float(SH_DEGREE + 1 - i) / float(i + 1); + } + // Find roots of the polynomial within the relevant bounds + float roots[MAX_DEGREE + 1]; + find_roots(roots, poly, -u_max, u_max); + // Convert them back to the original coordinate frame (i.e. ray parameters) + _unroll_ + for (int i = 0; i != MAX_DEGREE; ++i) + out_ray_params[i] = (roots[i] != NO_INTERSECTION) + ? (roots[i] * closest_dot_origin - dir_dot_origin) + : NO_INTERSECTION; +} + + +// Provides a normalized normal vector for a spherical harmonics glyph. +// \param sh_coeffs SH_COUNT spherical harmonic coefficients defining the +// glyph. Their exact meaning is defined by eval_sh(). +// \param point A point on the surface of the glyph, relative to its center. +// return A normalized surface normal pointing away from the origin. +vec3 get_sh_glyph_normal(float sh_coeffs[SH_COUNT], vec3 point) { + float shs[SH_COUNT]; + vec3 grads[SH_COUNT]; + float length_inv = inversesqrt(dot(point, point)); + vec3 normalized = point * length_inv; + eval_sh_grad(shs, grads, normalized); + float value = 0.0; + vec3 grad = vec3(0.0); + _unroll_ + for (int i = 0; i != SH_COUNT; ++i) { + value += sh_coeffs[i] * shs[i]; + grad += sh_coeffs[i] * grads[i]; + } + return normalize(point - (value * length_inv) * (grad - dot(grad, normalized) * normalized)); +} + + +// This is the glTF BRDF for dielectric materials, exactly as described here: +// https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#appendix-b-brdf-implementation +// \param incoming The normalized incoming light direction. +// \param outgoing The normalized outgoing light direction. +// \param normal The normalized shading normal. +// \param roughness An artist friendly roughness value between 0 and 1 +// \param base_color The albedo used for the Lambertian diffuse component +// return The BRDF for the given directions. +vec3 gltf_dielectric_brdf(vec3 incoming, vec3 outgoing, vec3 normal, float roughness, vec3 base_color) { + float ni = dot(normal, incoming); + float no = dot(normal, outgoing); + // Early out if incoming or outgoing direction are below the horizon + if (ni <= 0.0 || no <= 0.0) + return vec3(0.0); + // Save some work by not actually computing the half-vector. If the half- + // vector were h, ih = dot(incoming, h) and + // sqrt(nh_ih_2 / ih_2) = dot(normal, h). + float ih_2 = dot(incoming, outgoing) * 0.5 + 0.5; + float sum = ni + no; + float nh_ih_2 = 0.25 * sum * sum; + float ih = sqrt(ih_2); + + // Evaluate the GGX normal distribution function + float roughness_2 = roughness * roughness; + float roughness_4 = roughness_2 * roughness_2; + float roughness_flip = 1.0 - roughness_4; + float denominator = ih_2 - nh_ih_2 * roughness_flip; + float ggx = (roughness_4 * M_INV_PI * ih_2) / (denominator * denominator); + // Evaluate the "visibility" (i.e. masking-shadowing times geometry terms) + float vi = ni + sqrt(roughness_4 + roughness_flip * ni * ni); + float vo = no + sqrt(roughness_4 + roughness_flip * no * no); + float v = 1.0 / (vi * vo); + // That completes the specular BRDF + float specular = v * ggx; + + // The diffuse BRDF is Lambertian + vec3 diffuse = M_INV_PI * base_color; + + // Evaluate the Fresnel term using the Fresnel-Schlick approximation + const float ior = 1.5; + const float f0 = ((1.0 - ior) / (1.0 + ior)) * ((1.0 - ior) / (1.0 + ior)); + float ih_flip = 1.0 - ih; + float ih_flip_2 = ih_flip * ih_flip; + float fresnel = f0 + (1.0 - f0) * ih_flip * ih_flip_2 * ih_flip_2; + + // Mix the two components + return mix(diffuse, vec3(specular), fresnel); +} + + +// Applies the non-linearity that maps linear RGB to sRGB +float linear_to_srgb(float linear) { + return (linear <= 0.0031308) ? (12.92 * linear) : (1.055 * pow(linear, 1.0 / 2.4) - 0.055); +} + +// Inverse of linear_to_srgb() +float srgb_to_linear(float non_linear) { + return (non_linear <= 0.04045) ? ((1.0 / 12.92) * non_linear) : pow(non_linear * (1.0 / 1.055) + 0.055 / 1.055, 2.4); +} + +// Turns a linear RGB color (i.e. rec. 709) into sRGB +vec3 linear_rgb_to_srgb(vec3 linear) { + return vec3(linear_to_srgb(linear.r), linear_to_srgb(linear.g), linear_to_srgb(linear.b)); +} + +// Inverse of linear_rgb_to_srgb() +vec3 srgb_to_linear_rgb(vec3 srgb) { + return vec3(srgb_to_linear(srgb.r), srgb_to_linear(srgb.g), srgb_to_linear(srgb.b)); +} + +// Logarithmic tonemapping operator. Input and output are linear RGB. +vec3 tonemap(vec3 linear) { + float max_channel = max(max(1.0, linear.r), max(linear.g, linear.b)); + return linear * ((1.0 - 0.02 * log2(max_channel)) / max_channel); +} + +vec3 iResolution = vec3(1920, 1080, 1.0); +float iTime = 1.0; +void mainImage(out vec4 out_color, vec2 frag_coord) { + // Define a camera ray for a pinhole camera + vec3 camera_pos = vec3(0.0, -5.0, 0.0); + float aspect = float(iResolution.x) / float(iResolution.y); + float zoom = 0.8; + vec3 right = (aspect / zoom) * vec3(3.0, 0.0, 0.0); + vec3 up = (1.0 / zoom) * vec3(0.0, 0.0, 3.0); + vec3 bottom_left = -0.5 * (right + up); + vec2 uv = frag_coord / vec2(iResolution.xy); + vec3 ray_dir = normalize(bottom_left + uv.x * right + uv.y * up - camera_pos); + // Rotate the camera slowly + float pitch = -0.2 * M_PI; + float yaw = 0.1 * M_PI * iTime; + mat3 rot_z = mat3(cos(yaw), sin(yaw), 0.0, -sin(yaw), cos(yaw), 0.0, 0.0, 0.0, 1.0); + mat3 rot_x = mat3(1.0, 0.0, 0.0, 0.0, cos(pitch), sin(pitch), 0.0, -sin(pitch), cos(pitch)); + camera_pos = rot_z * rot_x * camera_pos; + ray_dir = normalize(rot_z * rot_x * ray_dir); + // Define SH coefficients (measured up to band 8, noise beyond that) + float sh_coeffs[SH_COUNT]; + sh_coeffs[0] = -0.2739740312099; sh_coeffs[1] = 0.2526670396328; sh_coeffs[2] = 1.8922271728516; sh_coeffs[3] = 0.2878578901291; sh_coeffs[4] = -0.5339795947075; sh_coeffs[5] = -0.2620058953762; +#if SH_DEGREE >= 4 + sh_coeffs[6] = 0.1580424904823; sh_coeffs[7] = 0.0329004973173; sh_coeffs[8] = -0.1322413831949; sh_coeffs[9] = -0.1332057565451; sh_coeffs[10] = 1.0894461870193; sh_coeffs[11] = -0.6319401264191; sh_coeffs[12] = -0.0416776277125; sh_coeffs[13] = -1.0772529840469; sh_coeffs[14] = 0.1423762738705; +#endif +#if SH_DEGREE >= 6 + sh_coeffs[15] = 0.7941166162491; sh_coeffs[16] = 0.7490307092667; sh_coeffs[17] = -0.3428381681442; sh_coeffs[18] = 0.1024847552180; sh_coeffs[19] = -0.0219132602215; sh_coeffs[20] = 0.0499043911695; sh_coeffs[21] = 0.2162453681231; sh_coeffs[22] = 0.0921059995890; sh_coeffs[23] = -0.2611238956451; sh_coeffs[24] = 0.2549301385880; sh_coeffs[25] = -0.4534865319729; sh_coeffs[26] = 0.1922748684883; sh_coeffs[27] = -0.6200597286224; +#endif +#if SH_DEGREE >= 8 + sh_coeffs[28] = -0.0532187558711; sh_coeffs[29] = -0.3569841980934; sh_coeffs[30] = 0.0293972902000; sh_coeffs[31] = -0.1977960765362; sh_coeffs[32] = -0.1058669015765; sh_coeffs[33] = 0.2372217923403; sh_coeffs[34] = -0.1856198310852; sh_coeffs[35] = -0.3373193442822; sh_coeffs[36] = -0.0750469490886; sh_coeffs[37] = 0.2146576642990; sh_coeffs[38] = -0.0490148440003; sh_coeffs[39] = 0.1288588196039; sh_coeffs[40] = 0.3173974752426; sh_coeffs[41] = 0.1990085393190; sh_coeffs[42] = -0.1736343950033; sh_coeffs[43] = -0.0482443645597; sh_coeffs[44] = 0.1749017387629; +#endif +#if SH_DEGREE >= 10 + sh_coeffs[45] = -0.0151847425660; sh_coeffs[46] = 0.0418366046081; sh_coeffs[47] = 0.0863263587216; sh_coeffs[48] = -0.0649211244490; sh_coeffs[49] = 0.0126096132283; sh_coeffs[50] = 0.0545089217982; sh_coeffs[51] = -0.0275142164626; sh_coeffs[52] = 0.0399986574832; sh_coeffs[53] = -0.0468244261610; sh_coeffs[54] = -0.1292105653111; sh_coeffs[55] = -0.0786858322658; sh_coeffs[56] = -0.0663828464882; sh_coeffs[57] = 0.0382439706831; sh_coeffs[58] = -0.0041550330365; sh_coeffs[59] = -0.0502800566338; sh_coeffs[60] = -0.0732471630735; sh_coeffs[61] = 0.0181751900972; sh_coeffs[62] = -0.0090119333757; sh_coeffs[63] = -0.0604443282359; sh_coeffs[64] = -0.1469985252752; sh_coeffs[65] = -0.0534046899715; +#endif +#if SH_DEGREE >= 12 + sh_coeffs[66] = -0.0896672753415; sh_coeffs[67] = -0.0130841364808; sh_coeffs[68] = -0.0112942893801; sh_coeffs[69] = 0.0272257498541; sh_coeffs[70] = 0.0626717616331; sh_coeffs[71] = -0.0222197983050; sh_coeffs[72] = -0.0018541504308; sh_coeffs[73] = -0.1653251944056; sh_coeffs[74] = 0.0409697402846; sh_coeffs[75] = 0.0749921454327; sh_coeffs[76] = -0.0282830872616; sh_coeffs[77] = 0.0006909458525; sh_coeffs[78] = 0.0625599842287; sh_coeffs[79] = 0.0812529816082; sh_coeffs[80] = 0.0914693020772; sh_coeffs[81] = -0.1197222726745; sh_coeffs[82] = 0.0376277453183; sh_coeffs[83] = -0.0832617004142; sh_coeffs[84] = -0.0482175038043; sh_coeffs[85] = -0.0839003635737; sh_coeffs[86] = -0.0349423908400; sh_coeffs[87] = 0.1204519568256; sh_coeffs[88] = 0.0783745984003; sh_coeffs[89] = 0.0297401205976; sh_coeffs[90] = -0.0505947662525; +#endif + // Perform the intersection test + float ray_params[MAX_DEGREE]; + ray_sh_glyph_intersections(ray_params, sh_coeffs, camera_pos, ray_dir); + // Identify the first intersection + float first_ray_param = NO_INTERSECTION; + _unroll_ + for (int i = 0; i != MAX_DEGREE; ++i) { + if (ray_params[i] != NO_INTERSECTION && ray_params[i] > 0.0) { + first_ray_param = ray_params[i]; + break; + } + } + // Evaluate shading for a directional light + vec3 color = vec3(1.0); + if (first_ray_param != NO_INTERSECTION) { + vec3 intersection = camera_pos + first_ray_param * ray_dir; + vec3 normal = get_sh_glyph_normal(sh_coeffs, intersection); + vec3 base_color = srgb_to_linear_rgb(abs(normalize(intersection))); + const vec3 incoming = normalize(vec3(1.23, -4.56, 7.89)); + float ambient = 0.04; + float exposure = 4.0; + vec3 outgoing = -ray_dir; + vec3 brdf = gltf_dielectric_brdf(incoming, outgoing, normal, 0.45, base_color); + color = exposure * (brdf * max(0.0, dot(incoming, normal)) + base_color * ambient); + } + out_color = vec4(linear_rgb_to_srgb(tonemap(color)), 1.0); +} + """ + + # fmt: off + fs_dec = compose_shader([ + fs_defs, fs_unifs, fs_vs_vars, coeffs_norm, legendre_polys, + spherical_harmonics, sdf_map, central_diffs_normals, cast_ray, + blinn_phong_model, common, new_code + ]) + # fmt: on + + shader_to_actor(odf_actor, "fragment", decl_code=fs_dec, debug=False) + + sdf_frag_impl = """ + + // ------------------------------------------------------------------------------------------------------------------ + vec3 pnt = vertexMCVSOutput.xyz; + + // Ray Origin + // Camera position in world space + vec3 ro = (-MCVCMatrix[3] * MCVCMatrix).xyz; + + // Ray Direction + vec3 rd = normalize(pnt - ro); + + // Light Direction + vec3 ld = normalize(ro - pnt); + + ro += pnt - ro; + + vec3 t = castRay(ro, rd); + + vec2 frag_coord = gl_FragCoord.xy; + vec3 camera_pos = ro; //vec3(0.0, -5.0, 0.0); + float aspect = float(iResolution.x) / float(iResolution.y); + float zoom = 0.8; + vec3 right = (aspect / zoom) * vec3(3.0, 0.0, 0.0); + vec3 up = (1.0 / zoom) * vec3(0.0, 0.0, 3.0); + vec3 bottom_left = -0.5 * (right + up); + vec2 uv = frag_coord / vec2(iResolution.xy); + vec3 ray_dir = rd; //normalize(bottom_left + uv.x * right + uv.y * up - camera_pos); + // Rotate the camera slowly + float pitch = -0.2 * M_PI; + float yaw = 0.1 * M_PI * iTime; + mat3 rot_z = mat3(cos(yaw), sin(yaw), 0.0, -sin(yaw), cos(yaw), 0.0, 0.0, 0.0, 1.0); + mat3 rot_x = mat3(1.0, 0.0, 0.0, 0.0, cos(pitch), sin(pitch), 0.0, -sin(pitch), cos(pitch)); + camera_pos = rot_z * rot_x * camera_pos; + ray_dir = normalize(rot_z * rot_x * ray_dir); + // Define SH coefficients (measured up to band 8, noise beyond that) + float sh_coeffs[SH_COUNT]; + sh_coeffs[0] = -0.2739740312099; sh_coeffs[1] = 0.2526670396328; sh_coeffs[2] = 1.8922271728516; sh_coeffs[3] = 0.2878578901291; sh_coeffs[4] = -0.5339795947075; sh_coeffs[5] = -0.2620058953762; +#if SH_DEGREE >= 4 + sh_coeffs[6] = 0.1580424904823; sh_coeffs[7] = 0.0329004973173; sh_coeffs[8] = -0.1322413831949; sh_coeffs[9] = -0.1332057565451; sh_coeffs[10] = 1.0894461870193; sh_coeffs[11] = -0.6319401264191; sh_coeffs[12] = -0.0416776277125; sh_coeffs[13] = -1.0772529840469; sh_coeffs[14] = 0.1423762738705; +#endif +#if SH_DEGREE >= 6 + sh_coeffs[15] = 0.7941166162491; sh_coeffs[16] = 0.7490307092667; sh_coeffs[17] = -0.3428381681442; sh_coeffs[18] = 0.1024847552180; sh_coeffs[19] = -0.0219132602215; sh_coeffs[20] = 0.0499043911695; sh_coeffs[21] = 0.2162453681231; sh_coeffs[22] = 0.0921059995890; sh_coeffs[23] = -0.2611238956451; sh_coeffs[24] = 0.2549301385880; sh_coeffs[25] = -0.4534865319729; sh_coeffs[26] = 0.1922748684883; sh_coeffs[27] = -0.6200597286224; +#endif +#if SH_DEGREE >= 8 + sh_coeffs[28] = -0.0532187558711; sh_coeffs[29] = -0.3569841980934; sh_coeffs[30] = 0.0293972902000; sh_coeffs[31] = -0.1977960765362; sh_coeffs[32] = -0.1058669015765; sh_coeffs[33] = 0.2372217923403; sh_coeffs[34] = -0.1856198310852; sh_coeffs[35] = -0.3373193442822; sh_coeffs[36] = -0.0750469490886; sh_coeffs[37] = 0.2146576642990; sh_coeffs[38] = -0.0490148440003; sh_coeffs[39] = 0.1288588196039; sh_coeffs[40] = 0.3173974752426; sh_coeffs[41] = 0.1990085393190; sh_coeffs[42] = -0.1736343950033; sh_coeffs[43] = -0.0482443645597; sh_coeffs[44] = 0.1749017387629; +#endif +#if SH_DEGREE >= 10 + sh_coeffs[45] = -0.0151847425660; sh_coeffs[46] = 0.0418366046081; sh_coeffs[47] = 0.0863263587216; sh_coeffs[48] = -0.0649211244490; sh_coeffs[49] = 0.0126096132283; sh_coeffs[50] = 0.0545089217982; sh_coeffs[51] = -0.0275142164626; sh_coeffs[52] = 0.0399986574832; sh_coeffs[53] = -0.0468244261610; sh_coeffs[54] = -0.1292105653111; sh_coeffs[55] = -0.0786858322658; sh_coeffs[56] = -0.0663828464882; sh_coeffs[57] = 0.0382439706831; sh_coeffs[58] = -0.0041550330365; sh_coeffs[59] = -0.0502800566338; sh_coeffs[60] = -0.0732471630735; sh_coeffs[61] = 0.0181751900972; sh_coeffs[62] = -0.0090119333757; sh_coeffs[63] = -0.0604443282359; sh_coeffs[64] = -0.1469985252752; sh_coeffs[65] = -0.0534046899715; +#endif +#if SH_DEGREE >= 12 + sh_coeffs[66] = -0.0896672753415; sh_coeffs[67] = -0.0130841364808; sh_coeffs[68] = -0.0112942893801; sh_coeffs[69] = 0.0272257498541; sh_coeffs[70] = 0.0626717616331; sh_coeffs[71] = -0.0222197983050; sh_coeffs[72] = -0.0018541504308; sh_coeffs[73] = -0.1653251944056; sh_coeffs[74] = 0.0409697402846; sh_coeffs[75] = 0.0749921454327; sh_coeffs[76] = -0.0282830872616; sh_coeffs[77] = 0.0006909458525; sh_coeffs[78] = 0.0625599842287; sh_coeffs[79] = 0.0812529816082; sh_coeffs[80] = 0.0914693020772; sh_coeffs[81] = -0.1197222726745; sh_coeffs[82] = 0.0376277453183; sh_coeffs[83] = -0.0832617004142; sh_coeffs[84] = -0.0482175038043; sh_coeffs[85] = -0.0839003635737; sh_coeffs[86] = -0.0349423908400; sh_coeffs[87] = 0.1204519568256; sh_coeffs[88] = 0.0783745984003; sh_coeffs[89] = 0.0297401205976; sh_coeffs[90] = -0.0505947662525; +#endif + // Perform the intersection test + float ray_params[MAX_DEGREE]; + ray_sh_glyph_intersections(ray_params, sh_coeffs, camera_pos, ray_dir); + // Identify the first intersection + float first_ray_param = NO_INTERSECTION; + _unroll_ + for (int i = 0; i != MAX_DEGREE; ++i) { + if (ray_params[i] != NO_INTERSECTION && ray_params[i] > 0.0) { + first_ray_param = ray_params[i]; + break; + } + } + // Evaluate shading for a directional light + vec3 color = vec3(1.0); + if (first_ray_param != NO_INTERSECTION) { + vec3 intersection = camera_pos + first_ray_param * ray_dir; + vec3 normal = get_sh_glyph_normal(sh_coeffs, intersection); + vec3 base_color = srgb_to_linear_rgb(abs(normalize(intersection))); + const vec3 incoming = normalize(vec3(1.23, -4.56, 7.89)); + float ambient = 0.04; + float exposure = 4.0; + vec3 outgoing = -ray_dir; + vec3 brdf = gltf_dielectric_brdf(incoming, outgoing, normal, 0.45, base_color); + color = exposure * (brdf * max(0.0, dot(incoming, normal)) + base_color * ambient); + } + vec4 out_color = vec4(linear_rgb_to_srgb(tonemap(color)), 1.0); + fragOutput0 = out_color; + + """ + + shader_to_actor( + odf_actor, "fragment", impl_code=sdf_frag_impl, block="picking" + ) + + show_man.scene.add(odf_actor) + + sphere = get_sphere("repulsion724") + + sh_basis = "descoteaux07" + # sh_basis = "tournier07" + sh_order = 4 + + sh = np.zeros((3, 1, 1, 15)) + sh[0, 0, 0, :] = coeffs[0, :] + sh[1, 0, 0, :] = coeffs[1, :] + sh[2, 0, 0, :] = coeffs[2, :] + + tensor_sf = sh_to_sf( + sh, sh_order=sh_order, basis_type=sh_basis, sphere=sphere + ) + + odf_slicer_actor = actor.odf_slicer( + tensor_sf, sphere=sphere, scale=0.5, colormap="plasma" + ) + + show_man.scene.add(odf_slicer_actor) + + show_man.start() From feee339d4f75d71e5722256e79cf84baa51e9048 Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Mon, 4 Dec 2023 13:39:22 -0500 Subject: [PATCH 020/118] Minor changes in shader code. --- .../SH-ODF experimental/texture_coefficients.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/docs/experimental/SH-ODF experimental/texture_coefficients.py b/docs/experimental/SH-ODF experimental/texture_coefficients.py index 4bbfd2765..7a841da6a 100644 --- a/docs/experimental/SH-ODF experimental/texture_coefficients.py +++ b/docs/experimental/SH-ODF experimental/texture_coefficients.py @@ -362,14 +362,10 @@ sdf_frag_impl = """ vec3 pnt = vertexMCVSOutput.xyz; - // Ray Origin - // Camera position in world space vec3 ro = (-MCVCMatrix[3] * MCVCMatrix).xyz; - // Ray Direction vec3 rd = normalize(pnt - ro); - // Light Direction vec3 ld = normalize(ro - pnt); ro += pnt - ro; @@ -386,15 +382,12 @@ //float sss = pow(clamp(1 + dot(normal, rd), 0, 1), 1); float sss = clamp(1 + dot(normal, rd), 0, 1); - // lights vec3 lin = 2.5 * occ * vec3(1) * (.6 + .4 * normal.y); lin += 1 * sss * vec3(1, .95, .7) * occ; vec3 mater = .5 * mix(vec3(1, 1, 0), vec3(1), t.y); - // ================================================================ fragOutput0 = vec4(vec3(1, 0, 0) * lin, opacity); - // ================================================================ } else { From f3c349093b0537c796a264f17ea625208b354a8a Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Mon, 4 Dec 2023 16:11:02 -0500 Subject: [PATCH 021/118] Added first version of Peters' paper. --- .../SH-ODF experimental/ray_traced_1.py | 759 ++++++++++++++++++ .../spherical_harmonics/eval_sh_10.frag | 175 ++++ .../spherical_harmonics/eval_sh_12.frag | 238 ++++++ .../spherical_harmonics/eval_sh_2.frag | 23 + .../spherical_harmonics/eval_sh_4.frag | 46 ++ .../spherical_harmonics/eval_sh_6.frag | 79 ++ .../spherical_harmonics/eval_sh_8.frag | 122 +++ .../spherical_harmonics/eval_sh_grad_10.frag | 430 ++++++++++ .../spherical_harmonics/eval_sh_grad_12.frag | 591 ++++++++++++++ .../spherical_harmonics/eval_sh_grad_2.frag | 46 ++ .../spherical_harmonics/eval_sh_grad_4.frag | 103 +++ .../spherical_harmonics/eval_sh_grad_6.frag | 186 +++++ .../spherical_harmonics/eval_sh_grad_8.frag | 295 +++++++ 13 files changed, 3093 insertions(+) create mode 100644 docs/experimental/SH-ODF experimental/ray_traced_1.py create mode 100644 fury/shaders/spherical_harmonics/eval_sh_10.frag create mode 100644 fury/shaders/spherical_harmonics/eval_sh_12.frag create mode 100644 fury/shaders/spherical_harmonics/eval_sh_2.frag create mode 100644 fury/shaders/spherical_harmonics/eval_sh_4.frag create mode 100644 fury/shaders/spherical_harmonics/eval_sh_6.frag create mode 100644 fury/shaders/spherical_harmonics/eval_sh_8.frag create mode 100644 fury/shaders/spherical_harmonics/eval_sh_grad_10.frag create mode 100644 fury/shaders/spherical_harmonics/eval_sh_grad_12.frag create mode 100644 fury/shaders/spherical_harmonics/eval_sh_grad_2.frag create mode 100644 fury/shaders/spherical_harmonics/eval_sh_grad_4.frag create mode 100644 fury/shaders/spherical_harmonics/eval_sh_grad_6.frag create mode 100644 fury/shaders/spherical_harmonics/eval_sh_grad_8.frag diff --git a/docs/experimental/SH-ODF experimental/ray_traced_1.py b/docs/experimental/SH-ODF experimental/ray_traced_1.py new file mode 100644 index 000000000..3ea3cd8fe --- /dev/null +++ b/docs/experimental/SH-ODF experimental/ray_traced_1.py @@ -0,0 +1,759 @@ +""" +This script includes TEXTURE experimentation for passing SH coefficients +""" +import os + +import numpy as np + +from fury import actor, window +from fury.shaders import ( + attribute_to_actor, + compose_shader, + import_fury_shader, + shader_to_actor, +) + +if __name__ == "__main__": + show_man = window.ShowManager(size=(1280, 720)) + show_man.scene.background((1, 1, 1)) + + centers = np.array([[0, 0, 0]]) + scales = np.array([1]) + + odf_actor = actor.box(centers=centers, scales=4) + + big_centers = np.repeat(centers, 8, axis=0) + attribute_to_actor(odf_actor, big_centers, "center") + + big_scales = np.repeat(scales, 8, axis=0) + attribute_to_actor(odf_actor, big_scales, "scale") + + vs_dec = """ + in vec3 center; + in float scale; + + out vec4 vertexMCVSOutput; + out vec3 centerMCVSOutput; + out float scaleVSOutput; + """ + + vs_impl = """ + vertexMCVSOutput = vertexMC; + centerMCVSOutput = center; + scaleVSOutput = scale; + vec3 camPos = -MCVCMatrix[3].xyz * mat3(MCVCMatrix); + """ + + shader_to_actor(odf_actor, "vertex", decl_code=vs_dec, impl_code=vs_impl) + + fs_defs = """ + #define SH_DEGREE 4 + #define SH_COUNT (((SH_DEGREE + 1) * (SH_DEGREE + 2)) / 2) + #define MAX_DEGREE (2 * SH_DEGREE + 2) + #define NO_INTERSECTION 3.4e38 + #define M_PI 3.141592653589793238462643 + #define M_INV_PI 0.318309886183790671537767526745 + """ + + fs_unifs = """ + uniform mat4 MCVCMatrix; + """ + + fs_vs_vars = """ + in vec4 vertexMCVSOutput; + in vec3 centerMCVSOutput; + in float scaleVSOutput; + """ + + eval_sh_2 = import_fury_shader( + os.path.join("spherical_harmonics", "eval_sh_2.frag") + ) + + eval_sh_4 = import_fury_shader( + os.path.join("spherical_harmonics", "eval_sh_4.frag") + ) + + eval_sh_6 = import_fury_shader( + os.path.join("spherical_harmonics", "eval_sh_6.frag") + ) + + eval_sh_8 = import_fury_shader( + os.path.join("spherical_harmonics", "eval_sh_8.frag") + ) + + eval_sh_10 = import_fury_shader( + os.path.join("spherical_harmonics", "eval_sh_10.frag") + ) + + eval_sh_12 = import_fury_shader( + os.path.join("spherical_harmonics", "eval_sh_12.frag") + ) + + eval_sh_grad_2 = import_fury_shader( + os.path.join("spherical_harmonics", "eval_sh_grad_2.frag") + ) + + eval_sh_grad_4 = import_fury_shader( + os.path.join("spherical_harmonics", "eval_sh_grad_4.frag") + ) + + eval_sh_grad_6 = import_fury_shader( + os.path.join("spherical_harmonics", "eval_sh_grad_6.frag") + ) + + eval_sh_grad_8 = import_fury_shader( + os.path.join("spherical_harmonics", "eval_sh_grad_8.frag") + ) + + eval_sh_grad_10 = import_fury_shader( + os.path.join("spherical_harmonics", "eval_sh_grad_10.frag") + ) + + eval_sh_grad_12 = import_fury_shader( + os.path.join("spherical_harmonics", "eval_sh_grad_12.frag") + ) + + new_code = """ + // Supplemental code for "Ray Tracing Spherical Harmonics Glyphs": +// https://momentsingraphics.de/VMV2023.html +// View results of this shader here: https://www.shadertoy.com/view/dlGSDV +// (c) 2023, Christoph Peters +// This work is licensed under a CC0 1.0 Universal License. To the extent +// possible under law, Christoph Peters has waived all copyright and related or +// neighboring rights to the following code. This work is published from +// Germany. https://creativecommons.org/publicdomain/zero/1.0/ + +// The index of the highest used band of the spherical harmonics basis. Must be +// even, at least 2 and at most 12. +#define SH_DEGREE 4 +// The number of spherical harmonics basis functions +#define SH_COUNT (((SH_DEGREE + 1) * (SH_DEGREE + 2)) / 2) +// Degree of polynomials for which we have to find roots +#define MAX_DEGREE (2 * SH_DEGREE + 2) +// If GL_EXT_control_flow_attributes is available, these defines should be +// defined as [[unroll]] and [[loop]] to give reasonable hints to the compiler. +// That avoids register spilling, which makes execution considerably faster. +#ifndef _unroll_ +#define _unroll_ +#endif +#ifndef _loop_ +#define _loop_ +#endif +// When there are fewer intersections/roots than theoretically possible, some +// array entries are set to this value +#define NO_INTERSECTION 3.4e38 +// pi and its reciprocal +#define M_PI 3.141592653589793238462643 +#define M_INV_PI 0.318309886183790671537767526745 + + +// Searches a single root of a polynomial within a given interval. +// \param out_root The location of the found root. +// \param out_end_value The value of the given polynomial at end. +// \param poly Coefficients of the polynomial for which a root should be found. +// Coefficient poly[i] is multiplied by x^i. +// \param begin The beginning of an interval where the polynomial is monotonic. +// \param end The end of said interval. +// \param begin_value The value of the given polynomial at begin. +// \param error_tolerance The error tolerance for the returned root location. +// Typically the error will be much lower but in theory it can be +// bigger. +// return true if a root was found, false if no root exists. +bool newton_bisection(out float out_root, out float out_end_value, + float poly[MAX_DEGREE + 1], float begin, float end, + float begin_value, float error_tolerance) +{ + if (begin == end) { + out_end_value = begin_value; + return false; + } + // Evaluate the polynomial at the end of the interval + out_end_value = poly[MAX_DEGREE]; + _unroll_ + for (int i = MAX_DEGREE - 1; i != -1; --i) + out_end_value = out_end_value * end + poly[i]; + // If the values at both ends have the same non-zero sign, there is no root + if (begin_value * out_end_value > 0.0) + return false; + // Otherwise, we find the root iteratively using Newton bisection (with + // bounded iteration count) + float current = 0.5 * (begin + end); + _loop_ + for (int i = 0; i != 90; ++i) { + // Evaluate the polynomial and its derivative + float value = poly[MAX_DEGREE] * current + poly[MAX_DEGREE - 1]; + float derivative = poly[MAX_DEGREE]; + _unroll_ + for (int j = MAX_DEGREE - 2; j != -1; --j) { + derivative = derivative * current + value; + value = value * current + poly[j]; + } + // Shorten the interval + bool right = begin_value * value > 0.0; + begin = right ? current : begin; + end = right ? end : current; + // Apply Newton's method + float guess = current - value / derivative; + // Pick a guess + float middle = 0.5 * (begin + end); + float next = (guess >= begin && guess <= end) ? guess : middle; + // Move along or terminate + bool done = abs(next - current) < error_tolerance; + current = next; + if (done) + break; + } + out_root = current; + return true; +} + + +// Finds all roots of the given polynomial in the interval [begin, end] and +// writes them to out_roots. Some entries will be NO_INTERSECTION but other +// than that the array is sorted. The last entry is always NO_INTERSECTION. +void find_roots(out float out_roots[MAX_DEGREE + 1], float poly[MAX_DEGREE + 1], float begin, float end) { + float tolerance = (end - begin) * 1.0e-4; + // Construct the quadratic derivative of the polynomial. We divide each + // derivative by the factorial of its order, such that the constant + // coefficient can be copied directly from poly. That is a safeguard + // against overflow and makes it easier to avoid spilling below. The + // factors happen to be binomial coefficients then. + float derivative[MAX_DEGREE + 1]; + derivative[0] = poly[MAX_DEGREE - 2]; + derivative[1] = float(MAX_DEGREE - 1) * poly[MAX_DEGREE - 1]; + derivative[2] = (0.5 * float((MAX_DEGREE - 1) * MAX_DEGREE)) * poly[MAX_DEGREE - 0]; + _unroll_ + for (int i = 3; i != MAX_DEGREE + 1; ++i) + derivative[i] = 0.0; + // Compute its two roots using the quadratic formula + float discriminant = derivative[1] * derivative[1] - 4.0 * derivative[0] * derivative[2]; + if (discriminant >= 0.0) { + float sqrt_discriminant = sqrt(discriminant); + float scaled_root = derivative[1] + ((derivative[1] > 0.0) ? sqrt_discriminant : (-sqrt_discriminant)); + float root_0 = clamp(-2.0 * derivative[0] / scaled_root, begin, end); + float root_1 = clamp(-0.5 * scaled_root / derivative[2], begin, end); + out_roots[MAX_DEGREE - 2] = min(root_0, root_1); + out_roots[MAX_DEGREE - 1] = max(root_0, root_1); + } + else { + // Indicate that the cubic derivative has a single root + out_roots[MAX_DEGREE - 2] = begin; + out_roots[MAX_DEGREE - 1] = begin; + } + // The last entry in the root array is set to end to make it easier to + // iterate over relevant intervals, all untouched roots are set to begin + out_roots[MAX_DEGREE] = end; + _unroll_ + for (int i = 0; i != MAX_DEGREE - 2; ++i) + out_roots[i] = begin; + // Work your way up to derivatives of higher degree until you reach the + // polynomial itself. This implementation may seem peculiar: It always + // treats the derivative as though it had degree MAX_DEGREE and it + // constructs the derivatives in a contrived way. Changing that would + // reduce the number of arithmetic instructions roughly by a factor of two. + // However, it would also cause register spilling, which has a far more + // negative impact on the overall run time. Profiling indicates that the + // current implementation has no spilling whatsoever. + _loop_ + for (int degree = 3; degree != MAX_DEGREE + 1; ++degree) { + // Take the integral of the previous derivative (scaled such that the + // constant coefficient can still be copied directly from poly) + float prev_derivative_order = float(MAX_DEGREE + 1 - degree); + _unroll_ + for (int i = MAX_DEGREE; i != 0; --i) + derivative[i] = derivative[i - 1] * (prev_derivative_order * (1.0 / float(i))); + // Copy the constant coefficient without causing spilling. This part + // would be harder if the derivative were not scaled the way it is. + _unroll_ + for (int i = 0; i != MAX_DEGREE - 2; ++i) + derivative[0] = (degree == MAX_DEGREE - i) ? poly[i] : derivative[0]; + // Determine the value of this derivative at begin + float begin_value = derivative[MAX_DEGREE]; + _unroll_ + for (int i = MAX_DEGREE - 1; i != -1; --i) + begin_value = begin_value * begin + derivative[i]; + // Iterate over the intervals where roots may be found + _unroll_ + for (int i = 0; i != MAX_DEGREE; ++i) { + if (i < MAX_DEGREE - degree) + continue; + float current_begin = out_roots[i]; + float current_end = out_roots[i + 1]; + // Try to find a root + float root; + if (newton_bisection(root, begin_value, derivative, current_begin, current_end, begin_value, tolerance)) + out_roots[i] = root; + else if (degree < MAX_DEGREE) + // Create an empty interval for the next iteration + out_roots[i] = out_roots[i - 1]; + else + out_roots[i] = NO_INTERSECTION; + } + } + // We no longer need this array entry + out_roots[MAX_DEGREE] = NO_INTERSECTION; +} + + +// Evaluates the spherical harmonics basis in bands 0, 2, ..., SH_DEGREE. +// Conventions are as in the following paper. +// M. Descoteaux, E. Angelino, S. Fitzgibbons, and R. Deriche. Regularized, +// fast, and robust analytical q-ball imaging. Magnetic Resonance in Medicine, +// 58(3), 2007. https://doi.org/10.1002/mrm.21277 +// \param out_shs Values of SH basis functions in bands 0, 2, ..., SH_DEGREE in +// this order. +// \param point The point on the unit sphere where the basis should be +// evaluated. +void eval_sh(out float out_shs[SH_COUNT], vec3 point) { +#if SH_DEGREE == 2 + eval_sh_2(out_shs, point); +#elif SH_DEGREE == 4 + eval_sh_4(out_shs, point); +#elif SH_DEGREE == 6 + eval_sh_6(out_shs, point); +#elif SH_DEGREE == 8 + eval_sh_8(out_shs, point); +#elif SH_DEGREE == 10 + eval_sh_10(out_shs, point); +#elif SH_DEGREE == 12 + eval_sh_12(out_shs, point); +#endif +} + + +// Evaluates the gradient of each basis function given by eval_sh() and the +// basis itself +void eval_sh_grad(out float out_shs[SH_COUNT], out vec3 out_grads[SH_COUNT], vec3 point) { +#if SH_DEGREE == 2 + eval_sh_grad_2(out_shs, out_grads, point); +#elif SH_DEGREE == 4 + eval_sh_grad_4(out_shs, out_grads, point); +#elif SH_DEGREE == 6 + eval_sh_grad_6(out_shs, out_grads, point); +#elif SH_DEGREE == 8 + eval_sh_grad_8(out_shs, out_grads, point); +#elif SH_DEGREE == 10 + eval_sh_grad_10(out_shs, out_grads, point); +#elif SH_DEGREE == 12 + eval_sh_grad_12(out_shs, out_grads, point); +#endif +} + + +// Outputs a matrix that turns equidistant samples on the unit circle of a +// homogeneous polynomial into coefficients of that polynomial. +void get_inv_vandermonde(out float v[(SH_DEGREE + 1) * (SH_DEGREE + 1)]) { +#if SH_DEGREE == 2 + v[0*3 + 0] = -0.3333333333; v[0*3 + 1] = 0.6666666667; v[0*3 + 2] = 0.6666666667; + v[1*3 + 0] = -0.0; v[1*3 + 1] = 1.1547005384; v[1*3 + 2] = -1.1547005384; + v[2*3 + 0] = 1.0; v[2*3 + 1] = 0.0; v[2*3 + 2] = 0.0; +#elif SH_DEGREE == 4 + v[0*5 + 0] = 0.2; v[0*5 + 1] = -0.2472135955; v[0*5 + 2] = 0.6472135955; v[0*5 + 3] = 0.6472135955; v[0*5 + 4] = -0.2472135955; + v[1*5 + 0] = 0.0; v[1*5 + 1] = -0.1796111906; v[1*5 + 2] = 1.9919186279; v[1*5 + 3] = -1.9919186279; v[1*5 + 4] = 0.1796111906; + v[2*5 + 0] = -2.0; v[2*5 + 1] = 2.3416407865; v[2*5 + 2] = -0.3416407865; v[2*5 + 3] = -0.3416407865; v[2*5 + 4] = 2.3416407865; + v[3*5 + 0] = -0.0; v[3*5 + 1] = 1.7013016167; v[3*5 + 2] = -1.0514622242; v[3*5 + 3] = 1.0514622242; v[3*5 + 4] = -1.7013016167; + v[4*5 + 0] = 1.0; v[4*5 + 1] = 0.0; v[4*5 + 2] = 0.0; v[4*5 + 3] = 0.0; v[4*5 + 4] = 0.0; +#elif SH_DEGREE == 6 + v[0*7 + 0] = -0.1428571429; v[0*7 + 1] = 0.1585594663; v[0*7 + 2] = -0.2291250674; v[0*7 + 3] = 0.6419941725; v[0*7 + 4] = 0.6419941725; v[0*7 + 5] = -0.2291250674; v[0*7 + 6] = 0.1585594663; + v[1*7 + 0] = -0.0; v[1*7 + 1] = 0.0763582145; v[1*7 + 2] = -0.2873137468; v[1*7 + 3] = 2.8127602518; v[1*7 + 4] = -2.8127602518; v[1*7 + 5] = 0.2873137468; v[1*7 + 6] = -0.0763582145; + v[2*7 + 0] = 3.0; v[2*7 + 1] = -3.2929766145; v[2*7 + 2] = 4.4513463718; v[2*7 + 3] = -1.1583697574; v[2*7 + 4] = -1.1583697574; v[2*7 + 5] = 4.4513463718; v[2*7 + 6] = -3.2929766145; + v[3*7 + 0] = 0.0; v[3*7 + 1] = -1.5858139579; v[3*7 + 2] = 5.5818117995; v[3*7 + 3] = -5.0751495106; v[3*7 + 4] = 5.0751495106; v[3*7 + 5] = -5.5818117995; v[3*7 + 6] = 1.5858139579; + v[4*7 + 0] = -5.0; v[4*7 + 1] = 4.7858935686; v[4*7 + 2] = -1.0200067492; v[4*7 + 3] = 0.2341131806; v[4*7 + 4] = 0.2341131806; v[4*7 + 5] = -1.0200067492; v[4*7 + 6] = 4.7858935686; + v[5*7 + 0] = -0.0; v[5*7 + 1] = 2.3047648710; v[5*7 + 2] = -1.2790480077; v[5*7 + 3] = 1.0257168633; v[5*7 + 4] = -1.0257168633; v[5*7 + 5] = 1.2790480077; v[5*7 + 6] = -2.3047648710; + v[6*7 + 0] = 1.0; v[6*7 + 1] = 0.0; v[6*7 + 2] = 0.0; v[6*7 + 3] = 0.0; v[6*7 + 4] = 0.0; v[6*7 + 5] = 0.0; v[6*7 + 6] = 0.0; +#elif SH_DEGREE == 8 + v[0*9 + 0] = 0.1111111111; v[0*9 + 1] = -0.1182419747; v[0*9 + 2] = 0.1450452544; v[0*9 + 3] = -0.2222222222; v[0*9 + 4] = 0.6398633870; v[0*9 + 5] = 0.6398633870; v[0*9 + 6] = -0.2222222222; v[0*9 + 7] = 0.1450452544; v[0*9 + 8] = -0.1182419747; + v[1*9 + 0] = 0.0; v[1*9 + 1] = -0.0430365592; v[1*9 + 2] = 0.1217074194; v[1*9 + 3] = -0.3849001795; v[1*9 + 4] = 3.6288455938; v[1*9 + 5] = -3.6288455938; v[1*9 + 6] = 0.3849001795; v[1*9 + 7] = -0.1217074194; v[1*9 + 8] = 0.0430365592; + v[2*9 + 0] = -4.0; v[2*9 + 1] = 4.2410470634; v[2*9 + 2] = -5.1195045066; v[2*9 + 3] = 7.3333333333; v[2*9 + 4] = -2.4548758901; v[2*9 + 5] = -2.4548758901; v[2*9 + 6] = 7.3333333333; v[2*9 + 7] = -5.1195045066; v[2*9 + 8] = 4.2410470634; + v[3*9 + 0] = -0.0; v[3*9 + 1] = 1.5436148932; v[3*9 + 2] = -4.2957743433; v[3*9 + 3] = 12.7017059222; v[3*9 + 4] = -13.9222930051; v[3*9 + 5] = 13.9222930051; v[3*9 + 6] = -12.7017059222; v[3*9 + 7] = 4.2957743433; v[3*9 + 8] = -1.5436148932; + v[4*9 + 0] = 14.0; v[4*9 + 1] = -14.3366589404; v[4*9 + 2] = 14.6711193836; v[4*9 + 3] = -6.0; v[4*9 + 4] = 1.6655395568; v[4*9 + 5] = 1.6655395568; v[4*9 + 6] = -6.0; v[4*9 + 7] = 14.6711193836; v[4*9 + 8] = -14.3366589404; + v[5*9 + 0] = 0.0; v[5*9 + 1] = -5.2181171131; v[5*9 + 2] = 12.3105308637; v[5*9 + 3] = -10.3923048454; v[5*9 + 4] = 9.4457442082; v[5*9 + 5] = -9.4457442082; v[5*9 + 6] = 10.3923048454; v[5*9 + 7] = -12.3105308637; v[5*9 + 8] = 5.2181171131; + v[6*9 + 0] = -9.3333333333; v[6*9 + 1] = 8.0330865684; v[6*9 + 2] = -1.8540394597; v[6*9 + 3] = 0.6666666667; v[6*9 + 4] = -0.1790471086; v[6*9 + 5] = -0.1790471086; v[6*9 + 6] = 0.6666666667; v[6*9 + 7] = -1.8540394597; v[6*9 + 8] = 8.0330865684; + v[7*9 + 0] = -0.0; v[7*9 + 1] = 2.9238044002; v[7*9 + 2] = -1.5557238269; v[7*9 + 3] = 1.1547005384; v[7*9 + 4] = -1.0154266119; v[7*9 + 5] = 1.0154266119; v[7*9 + 6] = -1.1547005384; v[7*9 + 7] = 1.5557238269; v[7*9 + 8] = -2.9238044002; + v[8*9 + 0] = 1.0; v[8*9 + 1] = 0.0; v[8*9 + 2] = 0.0; v[8*9 + 3] = 0.0; v[8*9 + 4] = 0.0; v[8*9 + 5] = 0.0; v[8*9 + 6] = 0.0; v[8*9 + 7] = 0.0; v[8*9 + 8] = 0.0; +#elif SH_DEGREE == 10 + v[0*11 + 0] = -0.0909090909; v[0*11 + 1] = 0.0947470106; v[0*11 + 2] = -0.1080638444; v[0*11 + 3] = 0.1388220215; v[0*11 + 4] = -0.2188392043; v[0*11 + 5] = 0.6387885621; v[0*11 + 6] = 0.6387885621; v[0*11 + 7] = -0.2188392043; v[0*11 + 8] = 0.1388220215; v[0*11 + 9] = -0.1080638444; v[0*11 + 10] = 0.0947470106; + v[1*11 + 0] = -0.0; v[1*11 + 1] = 0.0278202324; v[1*11 + 2] = -0.0694484159; v[1*11 + 3] = 0.1602091533; v[1*11 + 4] = -0.4791910159; v[1*11 + 5] = 4.4428720384; v[1*11 + 6] = -4.4428720384; v[1*11 + 7] = 0.4791910159; v[1*11 + 8] = -0.1602091533; v[1*11 + 9] = 0.0694484159; v[1*11 + 10] = -0.0278202324; + v[2*11 + 0] = 5.0; v[2*11 + 1] = -5.2029168239; v[2*11 + 2] = 5.8988796576; v[2*11 + 3] = -7.4503199653; v[2*11 + 4] = 10.9868742757; v[2*11 + 5] = -4.2325171441; v[2*11 + 6] = -4.2325171441; v[2*11 + 7] = 10.9868742757; v[2*11 + 8] = -7.4503199653; v[2*11 + 9] = 5.8988796576; v[2*11 + 10] = -5.2029168239; + v[3*11 + 0] = 0.0; v[3*11 + 1] = -1.5277142200; v[3*11 + 2] = 3.7909797649; v[3*11 + 3] = -8.5981275876; v[3*11 + 4] = 24.0578988657; v[3*11 + 5] = -29.4378033460; v[3*11 + 6] = 29.4378033460; v[3*11 + 7] = -24.0578988657; v[3*11 + 8] = 8.5981275876; v[3*11 + 9] = -3.7909797649; v[3*11 + 10] = 1.5277142200; + v[4*11 + 0] = -30.0; v[4*11 + 1] = 30.8179361182; v[4*11 + 2] = -33.2247539061; v[4*11 + 3] = 35.8884989085; v[4*11 + 4] = -19.5374870834; v[4*11 + 5] = 6.0558059629; v[4*11 + 6] = 6.0558059629; v[4*11 + 7] = -19.5374870834; v[4*11 + 8] = 35.8884989085; v[4*11 + 9] = -33.2247539061; v[4*11 + 10] = 30.8179361182; + v[5*11 + 0] = -0.0; v[5*11 + 1] = 9.0489625020; v[5*11 + 2] = -21.3522528115; v[5*11 + 3] = 41.4175356200; v[5*11 + 4] = -42.7811292411; v[5*11 + 5] = 42.1190556280; v[5*11 + 6] = -42.1190556280; v[5*11 + 7] = 42.7811292411; v[5*11 + 8] = -41.4175356200; v[5*11 + 9] = 21.3522528115; v[5*11 + 10] = -9.0489625020; + v[6*11 + 0] = 42.0; v[6*11 + 1] = -41.1161037573; v[6*11 + 2] = 36.2032364762; v[6*11 + 3] = -16.3373898141; v[6*11 + 4] = 7.4261062994; v[6*11 + 5] = -2.1758492042; v[6*11 + 6] = -2.1758492042; v[6*11 + 7] = 7.4261062994; v[6*11 + 8] = -16.3373898141; v[6*11 + 9] = 36.2032364762; v[6*11 + 10] = -41.1161037573; + v[7*11 + 0] = 0.0; v[7*11 + 1] = -12.0727773496; v[7*11 + 2] = 23.2664073304; v[7*11 + 3] = -18.8543529304; v[7*11 + 4] = 16.2609045881; v[7*11 + 5] = -15.1333636234; v[7*11 + 6] = 15.1333636234; v[7*11 + 7] = -16.2609045881; v[7*11 + 8] = 18.8543529304; v[7*11 + 9] = -23.2664073304; v[7*11 + 10] = 12.0727773496; + v[8*11 + 0] = -15.0; v[8*11 + 1] = 12.0883694702; v[8*11 + 2] = -2.8781222629; v[8*11 + 3] = 1.1465503415; v[8*11 + 4] = -0.5020543475; v[8*11 + 5] = 0.1452567988; v[8*11 + 6] = 0.1452567988; v[8*11 + 7] = -0.5020543475; v[8*11 + 8] = 1.1465503415; v[8*11 + 9] = -2.8781222629; v[8*11 + 10] = 12.0883694702; + v[9*11 + 0] = -0.0; v[9*11 + 1] = 3.5494655329; v[9*11 + 2] = -1.8496568659; v[9*11 + 3] = 1.3231896304; v[9*11 + 4] = -1.0993456751; v[9*11 + 5] = 1.0102832265; v[9*11 + 6] = -1.0102832265; v[9*11 + 7] = 1.0993456751; v[9*11 + 8] = -1.3231896304; v[9*11 + 9] = 1.8496568659; v[9*11 + 10] = -3.5494655329; + v[10*11 + 0] = 1.0; v[10*11 + 1] = 0.0; v[10*11 + 2] = 0.0; v[10*11 + 3] = 0.0; v[10*11 + 4] = 0.0; v[10*11 + 5] = 0.0; v[10*11 + 6] = 0.0; v[10*11 + 7] = 0.0; v[10*11 + 8] = 0.0; v[10*11 + 9] = 0.0; v[10*11 + 10] = 0.0; +#elif SH_DEGREE == 12 + v[0*13 + 0] = 0.0769230769; v[0*13 + 1] = -0.0792252178; v[0*13 + 2] = 0.0868739663; v[0*13 + 3] = -0.1027681661; v[0*13 + 4] = 0.1354125166; v[0*13 + 5] = -0.2169261613; v[0*13 + 6] = 0.6381715239; v[0*13 + 7] = 0.6381715239; v[0*13 + 8] = -0.2169261613; v[0*13 + 9] = 0.1354125166; v[0*13 + 10] = -0.1027681661; v[0*13 + 11] = 0.0868739663; v[0*13 + 12] = -0.0792252178; + v[1*13 + 0] = -0.0; v[1*13 + 1] = -0.0195272624; v[1*13 + 2] = 0.0455949748; v[1*13 + 3] = -0.0910446506; v[1*13 + 4] = 0.1961788986; v[1*13 + 5] = -0.5719872785; v[1*13 + 6] = 5.2558153553; v[1*13 + 7] = -5.2558153553; v[1*13 + 8] = 0.5719872785; v[1*13 + 9] = -0.1961788986; v[1*13 + 10] = 0.0910446506; v[1*13 + 11] = -0.0455949748; v[1*13 + 12] = 0.0195272624; + v[2*13 + 0] = -6.0; v[2*13 + 1] = 6.1747539478; v[2*13 + 2] = -6.7522392818; v[2*13 + 3] = 7.9352584366; v[2*13 + 4] = -10.2779620900; v[2*13 + 5] = 15.4120340799; v[2*13 + 6] = -6.4918450925; v[2*13 + 7] = -6.4918450925; v[2*13 + 8] = 15.4120340799; v[2*13 + 9] = -10.2779620900; v[2*13 + 10] = 7.9352584366; v[2*13 + 11] = -6.7522392818; v[2*13 + 12] = 6.1747539478; + v[3*13 + 0] = -0.0; v[3*13 + 1] = 1.5219401578; v[3*13 + 2] = -3.5438485554; v[3*13 + 3] = 7.0300255289; v[3*13 + 4] = -14.8901987371; v[3*13 + 5] = 40.6381940129; v[3*13 + 6] = -53.4651544987; v[3*13 + 7] = 53.4651544987; v[3*13 + 8] = -40.6381940129; v[3*13 + 9] = 14.8901987371; v[3*13 + 10] = -7.0300255289; v[3*13 + 11] = 3.5438485554; v[3*13 + 12] = -1.5219401578; + v[4*13 + 0] = 55.0; v[4*13 + 1] = -56.2709061445; v[4*13 + 2] = 60.2549306937; v[4*13 + 3] = -67.2511796347; v[4*13 + 4] = 75.2477722397; v[4*13 + 5] = -47.9480941911; v[4*13 + 6] = 15.9674770369; v[4*13 + 7] = 15.9674770369; v[4*13 + 8] = -47.9480941911; v[4*13 + 9] = 75.2477722397; v[4*13 + 10] = -67.2511796347; v[4*13 + 11] = 60.2549306937; v[4*13 + 12] = -56.2709061445; + v[5*13 + 0] = 0.0; v[5*13 + 1] = -13.8695326974; v[5*13 + 2] = 31.6242271914; v[5*13 + 3] = -59.5793462127; v[5*13 + 4] = 109.0152185187; v[5*13 + 5] = -126.4287338180; v[5*13 + 6] = 131.5040045727; v[5*13 + 7] = -131.5040045727; v[5*13 + 8] = 126.4287338180; v[5*13 + 9] = -109.0152185187; v[5*13 + 10] = 59.5793462127; v[5*13 + 11] = -31.6242271914; v[5*13 + 12] = 13.8695326974; + v[6*13 + 0] = -132.0; v[6*13 + 1] = 132.5319409049; v[6*13 + 2] = -132.4780513404; v[6*13 + 3] = 123.5674782081; v[6*13 + 4] = -74.4320682907; v[6*13 + 5] = 38.8801193717; v[6*13 + 6] = -12.0694188537; v[6*13 + 7] = -12.0694188537; v[6*13 + 8] = 38.8801193717; v[6*13 + 9] = -74.4320682907; v[6*13 + 10] = 123.5674782081; v[6*13 + 11] = -132.4780513404; v[6*13 + 12] = 132.5319409049; + v[7*13 + 0] = -0.0; v[7*13 + 1] = 32.6661895777; v[7*13 + 2] = -69.5298450306; v[7*13 + 3] = 109.4712331409; v[7*13 + 4] = -107.8334673306; v[7*13 + 5] = 102.5184492897; v[7*13 + 6] = -99.4006071501; v[7*13 + 7] = 99.4006071501; v[7*13 + 8] = -102.5184492897; v[7*13 + 9] = 107.8334673306; v[7*13 + 10] = -109.4712331409; v[7*13 + 11] = 69.5298450306; v[7*13 + 12] = -32.6661895777; + v[8*13 + 0] = 99.0; v[8*13 + 1] = -93.9113626635; v[8*13 + 2] = 75.3147168618; v[8*13 + 3] = -35.2795800772; v[8*13 + 4] = 18.0521608541; v[8*13 + 5] = -8.8650350126; v[8*13 + 6] = 2.6891000373; v[8*13 + 7] = 2.6891000373; v[8*13 + 8] = -8.8650350126; v[8*13 + 9] = 18.0521608541; v[8*13 + 10] = -35.2795800772; v[8*13 + 11] = 75.3147168618; v[8*13 + 12] = -93.9113626635; + v[9*13 + 0] = 0.0; v[9*13 + 1] = -23.1470719837; v[9*13 + 2] = 39.5282127035; v[9*13 + 3] = -31.2549806126; v[9*13 + 4] = 26.1530700733; v[9*13 + 5] = -23.3751762359; v[9*13 + 6] = 22.1467313083; v[9*13 + 7] = -22.1467313083; v[9*13 + 8] = 23.3751762359; v[9*13 + 9] = -26.1530700733; v[9*13 + 10] = 31.2549806126; v[9*13 + 11] = -39.5282127035; v[9*13 + 12] = 23.1470719837; + v[10*13 + 0] = -22.0; v[10*13 + 1] = 16.9531714429; v[10*13 + 2] = -4.0999479387; v[10*13 + 3] = 1.7021989010; v[10*13 + 4] = -0.8387165175; v[10*13 + 5] = 0.4056079008; v[10*13 + 6] = -0.1223137885; v[10*13 + 7] = -0.1223137885; v[10*13 + 8] = 0.4056079008; v[10*13 + 9] = -0.8387165175; v[10*13 + 10] = 1.7021989010; v[10*13 + 11] = -4.0999479387; v[10*13 + 12] = 16.9531714429; + v[11*13 + 0] = -0.0; v[11*13 + 1] = 4.1785814689; v[11*13 + 2] = -2.1518186743; v[11*13 + 3] = 1.5080166355; v[11*13 + 4] = -1.2150906493; v[11*13 + 5] = 1.0695001374; v[11*13 + 6] = -1.0073446769; v[11*13 + 7] = 1.0073446769; v[11*13 + 8] = -1.0695001374; v[11*13 + 9] = 1.2150906493; v[11*13 + 10] = -1.5080166355; v[11*13 + 11] = 2.1518186743; v[11*13 + 12] = -4.1785814689; + v[12*13 + 0] = 1.0; v[12*13 + 1] = 0.0; v[12*13 + 2] = 0.0; v[12*13 + 3] = 0.0; v[12*13 + 4] = 0.0; v[12*13 + 5] = 0.0; v[12*13 + 6] = 0.0; v[12*13 + 7] = 0.0; v[12*13 + 8] = 0.0; v[12*13 + 9] = 0.0; v[12*13 + 10] = 0.0; v[12*13 + 11] = 0.0; v[12*13 + 12] = 0.0; +#endif +} + + +// Determines all intersections between a ray and a spherical harmonics glyph. +// \param out_ray_params The ray parameters at intersection points. The points +// themselves are at ray_origin + out_ray_params[i] * ray_dir. Some +// entries may be NO_INTERSECTION but other than that the array is +// sorted. +// \param sh_coeffs SH_COUNT spherical harmonic coefficients defining the +// glyph. Their exact meaning is defined by eval_sh(). +// \param ray_origin The origin of the ray, relative to the glyph center. +// \param ray_dir The normalized direction vector of the ray. +void ray_sh_glyph_intersections(out float out_ray_params[MAX_DEGREE], float sh_coeffs[SH_COUNT], vec3 ray_origin, vec3 ray_dir) { + // Determine the direction from the glyph center to the closest point on + // the ray + float dir_dot_origin = dot(ray_dir, ray_origin); + vec3 closest_dir = normalize(ray_origin - dir_dot_origin * ray_dir); + // Evaluate the SH polynomial at SH_DEGREE + 1 points. That is enough to + // know its value everywhere along the ray. + float sh_values[SH_DEGREE + 1]; + _unroll_ + for (int i = 0; i != SH_DEGREE + 1; ++i) { + vec3 point = cos(float(i) * (M_PI / float(SH_DEGREE + 1))) * ray_dir + + sin(float(i) * (M_PI / float(SH_DEGREE + 1))) * closest_dir; + float shs[SH_COUNT]; + eval_sh(shs, point); + sh_values[i] = 0.0; + _unroll_ + for (int j = 0; j != SH_COUNT; ++j) + sh_values[i] += sh_coeffs[j] * shs[j]; + } + // Compute coefficients of the SH polynomial along the ray in the + // coordinate frame given by ray_dir and closest_dir + float radius_poly[SH_DEGREE + 1]; + float inv_vander[(SH_DEGREE + 1) * (SH_DEGREE + 1)]; + get_inv_vandermonde(inv_vander); + _unroll_ + for (int i = 0; i != SH_DEGREE + 1; ++i) { + radius_poly[i] = 0.0; + _unroll_ + for (int j = 0; j != SH_DEGREE + 1; ++j) + radius_poly[i] += inv_vander[i * (SH_DEGREE + 1) + j] * sh_values[j]; + } + // Compute a bounding circle around the glyph in the relevant plane + float radius_max = 0.0; + _unroll_ + for (int i = 0; i != SH_DEGREE + 1; ++i) { + float bound = sqrt(pow(float(i), float(i)) * pow(float(SH_DEGREE - i), float(SH_DEGREE - i)) / pow(float(SH_DEGREE), float(SH_DEGREE))); + // Workaround for buggy compilers where 0^0 is 0 + bound = (i == 0 || i == SH_DEGREE) ? 1.0 : bound; + radius_max += bound * abs(radius_poly[i]); + } + // Figure out the interval, where (if at all) the ray intersects the circle + float closest_dot_origin = dot(closest_dir, ray_origin); + if (radius_max < abs(closest_dot_origin)) { + _unroll_ + for (int i = 0; i != MAX_DEGREE; ++i) + out_ray_params[i] = NO_INTERSECTION; + return; + } + float radius_over_dot = radius_max / closest_dot_origin; + float u_max = sqrt(radius_over_dot * radius_over_dot - 1.0); + // Take the square of radius_poly + float poly[MAX_DEGREE + 1]; + _unroll_ + for (int i = 0; i != MAX_DEGREE + 1; ++i) + poly[i] = 0.0; + _unroll_ + for (int i = 0; i != SH_DEGREE + 1; ++i) + _unroll_ + for (int j = 0; j != SH_DEGREE + 1; ++j) + poly[i + j] += radius_poly[i] * radius_poly[j]; + // Subtract the scaled (2 * SH_DEGREE + 2)-th power of the distance to the + // glyph center + float dot_sq = closest_dot_origin * closest_dot_origin; + float binomial = 1.0; + _unroll_ + for (int i = 0; i != SH_DEGREE + 2; ++i) { + poly[2 * i] -= binomial * dot_sq; + // Update the binomial coefficient using a recurrence relation + binomial *= float(SH_DEGREE + 1 - i) / float(i + 1); + } + // Find roots of the polynomial within the relevant bounds + float roots[MAX_DEGREE + 1]; + find_roots(roots, poly, -u_max, u_max); + // Convert them back to the original coordinate frame (i.e. ray parameters) + _unroll_ + for (int i = 0; i != MAX_DEGREE; ++i) + out_ray_params[i] = (roots[i] != NO_INTERSECTION) + ? (roots[i] * closest_dot_origin - dir_dot_origin) + : NO_INTERSECTION; +} + + +// Provides a normalized normal vector for a spherical harmonics glyph. +// \param sh_coeffs SH_COUNT spherical harmonic coefficients defining the +// glyph. Their exact meaning is defined by eval_sh(). +// \param point A point on the surface of the glyph, relative to its center. +// return A normalized surface normal pointing away from the origin. +vec3 get_sh_glyph_normal(float sh_coeffs[SH_COUNT], vec3 point) { + float shs[SH_COUNT]; + vec3 grads[SH_COUNT]; + float length_inv = inversesqrt(dot(point, point)); + vec3 normalized = point * length_inv; + eval_sh_grad(shs, grads, normalized); + float value = 0.0; + vec3 grad = vec3(0.0); + _unroll_ + for (int i = 0; i != SH_COUNT; ++i) { + value += sh_coeffs[i] * shs[i]; + grad += sh_coeffs[i] * grads[i]; + } + return normalize(point - (value * length_inv) * (grad - dot(grad, normalized) * normalized)); +} + + +// This is the glTF BRDF for dielectric materials, exactly as described here: +// https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#appendix-b-brdf-implementation +// \param incoming The normalized incoming light direction. +// \param outgoing The normalized outgoing light direction. +// \param normal The normalized shading normal. +// \param roughness An artist friendly roughness value between 0 and 1 +// \param base_color The albedo used for the Lambertian diffuse component +// return The BRDF for the given directions. +vec3 gltf_dielectric_brdf(vec3 incoming, vec3 outgoing, vec3 normal, float roughness, vec3 base_color) { + float ni = dot(normal, incoming); + float no = dot(normal, outgoing); + // Early out if incoming or outgoing direction are below the horizon + if (ni <= 0.0 || no <= 0.0) + return vec3(0.0); + // Save some work by not actually computing the half-vector. If the half- + // vector were h, ih = dot(incoming, h) and + // sqrt(nh_ih_2 / ih_2) = dot(normal, h). + float ih_2 = dot(incoming, outgoing) * 0.5 + 0.5; + float sum = ni + no; + float nh_ih_2 = 0.25 * sum * sum; + float ih = sqrt(ih_2); + + // Evaluate the GGX normal distribution function + float roughness_2 = roughness * roughness; + float roughness_4 = roughness_2 * roughness_2; + float roughness_flip = 1.0 - roughness_4; + float denominator = ih_2 - nh_ih_2 * roughness_flip; + float ggx = (roughness_4 * M_INV_PI * ih_2) / (denominator * denominator); + // Evaluate the "visibility" (i.e. masking-shadowing times geometry terms) + float vi = ni + sqrt(roughness_4 + roughness_flip * ni * ni); + float vo = no + sqrt(roughness_4 + roughness_flip * no * no); + float v = 1.0 / (vi * vo); + // That completes the specular BRDF + float specular = v * ggx; + + // The diffuse BRDF is Lambertian + vec3 diffuse = M_INV_PI * base_color; + + // Evaluate the Fresnel term using the Fresnel-Schlick approximation + const float ior = 1.5; + const float f0 = ((1.0 - ior) / (1.0 + ior)) * ((1.0 - ior) / (1.0 + ior)); + float ih_flip = 1.0 - ih; + float ih_flip_2 = ih_flip * ih_flip; + float fresnel = f0 + (1.0 - f0) * ih_flip * ih_flip_2 * ih_flip_2; + + // Mix the two components + return mix(diffuse, vec3(specular), fresnel); +} + + +// Applies the non-linearity that maps linear RGB to sRGB +float linear_to_srgb(float linear) { + return (linear <= 0.0031308) ? (12.92 * linear) : (1.055 * pow(linear, 1.0 / 2.4) - 0.055); +} + +// Inverse of linear_to_srgb() +float srgb_to_linear(float non_linear) { + return (non_linear <= 0.04045) ? ((1.0 / 12.92) * non_linear) : pow(non_linear * (1.0 / 1.055) + 0.055 / 1.055, 2.4); +} + +// Turns a linear RGB color (i.e. rec. 709) into sRGB +vec3 linear_rgb_to_srgb(vec3 linear) { + return vec3(linear_to_srgb(linear.r), linear_to_srgb(linear.g), linear_to_srgb(linear.b)); +} + +// Inverse of linear_rgb_to_srgb() +vec3 srgb_to_linear_rgb(vec3 srgb) { + return vec3(srgb_to_linear(srgb.r), srgb_to_linear(srgb.g), srgb_to_linear(srgb.b)); +} + +// Logarithmic tonemapping operator. Input and output are linear RGB. +vec3 tonemap(vec3 linear) { + float max_channel = max(max(1.0, linear.r), max(linear.g, linear.b)); + return linear * ((1.0 - 0.02 * log2(max_channel)) / max_channel); +} + +vec3 iResolution = vec3(1920, 1080, 1.0); +float iTime = 1.0; +void mainImage(out vec4 out_color, vec2 frag_coord) { + // Define a camera ray for a pinhole camera + vec3 camera_pos = vec3(0.0, -5.0, 0.0); + float aspect = float(iResolution.x) / float(iResolution.y); + float zoom = 0.8; + vec3 right = (aspect / zoom) * vec3(3.0, 0.0, 0.0); + vec3 up = (1.0 / zoom) * vec3(0.0, 0.0, 3.0); + vec3 bottom_left = -0.5 * (right + up); + vec2 uv = frag_coord / vec2(iResolution.xy); + vec3 ray_dir = normalize(bottom_left + uv.x * right + uv.y * up - camera_pos); + // Rotate the camera slowly + float pitch = -0.2 * M_PI; + float yaw = 0.1 * M_PI * iTime; + mat3 rot_z = mat3(cos(yaw), sin(yaw), 0.0, -sin(yaw), cos(yaw), 0.0, 0.0, 0.0, 1.0); + mat3 rot_x = mat3(1.0, 0.0, 0.0, 0.0, cos(pitch), sin(pitch), 0.0, -sin(pitch), cos(pitch)); + camera_pos = rot_z * rot_x * camera_pos; + ray_dir = normalize(rot_z * rot_x * ray_dir); + // Define SH coefficients (measured up to band 8, noise beyond that) + float sh_coeffs[SH_COUNT]; + sh_coeffs[0] = -0.2739740312099; sh_coeffs[1] = 0.2526670396328; sh_coeffs[2] = 1.8922271728516; sh_coeffs[3] = 0.2878578901291; sh_coeffs[4] = -0.5339795947075; sh_coeffs[5] = -0.2620058953762; +#if SH_DEGREE >= 4 + sh_coeffs[6] = 0.1580424904823; sh_coeffs[7] = 0.0329004973173; sh_coeffs[8] = -0.1322413831949; sh_coeffs[9] = -0.1332057565451; sh_coeffs[10] = 1.0894461870193; sh_coeffs[11] = -0.6319401264191; sh_coeffs[12] = -0.0416776277125; sh_coeffs[13] = -1.0772529840469; sh_coeffs[14] = 0.1423762738705; +#endif +#if SH_DEGREE >= 6 + sh_coeffs[15] = 0.7941166162491; sh_coeffs[16] = 0.7490307092667; sh_coeffs[17] = -0.3428381681442; sh_coeffs[18] = 0.1024847552180; sh_coeffs[19] = -0.0219132602215; sh_coeffs[20] = 0.0499043911695; sh_coeffs[21] = 0.2162453681231; sh_coeffs[22] = 0.0921059995890; sh_coeffs[23] = -0.2611238956451; sh_coeffs[24] = 0.2549301385880; sh_coeffs[25] = -0.4534865319729; sh_coeffs[26] = 0.1922748684883; sh_coeffs[27] = -0.6200597286224; +#endif +#if SH_DEGREE >= 8 + sh_coeffs[28] = -0.0532187558711; sh_coeffs[29] = -0.3569841980934; sh_coeffs[30] = 0.0293972902000; sh_coeffs[31] = -0.1977960765362; sh_coeffs[32] = -0.1058669015765; sh_coeffs[33] = 0.2372217923403; sh_coeffs[34] = -0.1856198310852; sh_coeffs[35] = -0.3373193442822; sh_coeffs[36] = -0.0750469490886; sh_coeffs[37] = 0.2146576642990; sh_coeffs[38] = -0.0490148440003; sh_coeffs[39] = 0.1288588196039; sh_coeffs[40] = 0.3173974752426; sh_coeffs[41] = 0.1990085393190; sh_coeffs[42] = -0.1736343950033; sh_coeffs[43] = -0.0482443645597; sh_coeffs[44] = 0.1749017387629; +#endif +#if SH_DEGREE >= 10 + sh_coeffs[45] = -0.0151847425660; sh_coeffs[46] = 0.0418366046081; sh_coeffs[47] = 0.0863263587216; sh_coeffs[48] = -0.0649211244490; sh_coeffs[49] = 0.0126096132283; sh_coeffs[50] = 0.0545089217982; sh_coeffs[51] = -0.0275142164626; sh_coeffs[52] = 0.0399986574832; sh_coeffs[53] = -0.0468244261610; sh_coeffs[54] = -0.1292105653111; sh_coeffs[55] = -0.0786858322658; sh_coeffs[56] = -0.0663828464882; sh_coeffs[57] = 0.0382439706831; sh_coeffs[58] = -0.0041550330365; sh_coeffs[59] = -0.0502800566338; sh_coeffs[60] = -0.0732471630735; sh_coeffs[61] = 0.0181751900972; sh_coeffs[62] = -0.0090119333757; sh_coeffs[63] = -0.0604443282359; sh_coeffs[64] = -0.1469985252752; sh_coeffs[65] = -0.0534046899715; +#endif +#if SH_DEGREE >= 12 + sh_coeffs[66] = -0.0896672753415; sh_coeffs[67] = -0.0130841364808; sh_coeffs[68] = -0.0112942893801; sh_coeffs[69] = 0.0272257498541; sh_coeffs[70] = 0.0626717616331; sh_coeffs[71] = -0.0222197983050; sh_coeffs[72] = -0.0018541504308; sh_coeffs[73] = -0.1653251944056; sh_coeffs[74] = 0.0409697402846; sh_coeffs[75] = 0.0749921454327; sh_coeffs[76] = -0.0282830872616; sh_coeffs[77] = 0.0006909458525; sh_coeffs[78] = 0.0625599842287; sh_coeffs[79] = 0.0812529816082; sh_coeffs[80] = 0.0914693020772; sh_coeffs[81] = -0.1197222726745; sh_coeffs[82] = 0.0376277453183; sh_coeffs[83] = -0.0832617004142; sh_coeffs[84] = -0.0482175038043; sh_coeffs[85] = -0.0839003635737; sh_coeffs[86] = -0.0349423908400; sh_coeffs[87] = 0.1204519568256; sh_coeffs[88] = 0.0783745984003; sh_coeffs[89] = 0.0297401205976; sh_coeffs[90] = -0.0505947662525; +#endif + // Perform the intersection test + float ray_params[MAX_DEGREE]; + ray_sh_glyph_intersections(ray_params, sh_coeffs, camera_pos, ray_dir); + // Identify the first intersection + float first_ray_param = NO_INTERSECTION; + _unroll_ + for (int i = 0; i != MAX_DEGREE; ++i) { + if (ray_params[i] != NO_INTERSECTION && ray_params[i] > 0.0) { + first_ray_param = ray_params[i]; + break; + } + } + // Evaluate shading for a directional light + vec3 color = vec3(1.0); + if (first_ray_param != NO_INTERSECTION) { + vec3 intersection = camera_pos + first_ray_param * ray_dir; + vec3 normal = get_sh_glyph_normal(sh_coeffs, intersection); + vec3 base_color = srgb_to_linear_rgb(abs(normalize(intersection))); + const vec3 incoming = normalize(vec3(1.23, -4.56, 7.89)); + float ambient = 0.04; + float exposure = 4.0; + vec3 outgoing = -ray_dir; + vec3 brdf = gltf_dielectric_brdf(incoming, outgoing, normal, 0.45, base_color); + color = exposure * (brdf * max(0.0, dot(incoming, normal)) + base_color * ambient); + } + out_color = vec4(linear_rgb_to_srgb(tonemap(color)), 1.0); +} + """ + + # fmt: off + fs_dec = compose_shader([ + fs_defs, fs_unifs, fs_vs_vars, eval_sh_2, eval_sh_4, eval_sh_6, + eval_sh_8, eval_sh_10, eval_sh_12, eval_sh_grad_2, eval_sh_grad_4, + eval_sh_grad_6, eval_sh_grad_8, eval_sh_grad_10, eval_sh_grad_12, + new_code + ]) + # fmt: on + + shader_to_actor(odf_actor, "fragment", decl_code=fs_dec, debug=False) + + sdf_frag_impl = """ + + // ------------------------------------------------------------------------------------------------------------------ + vec3 pnt = vertexMCVSOutput.xyz; + + // Ray Origin + // Camera position in world space + vec3 ro = (-MCVCMatrix[3] * MCVCMatrix).xyz; + + // Ray Direction + vec3 rd = normalize(pnt - ro); + + // Light Direction + vec3 ld = normalize(ro - pnt); + + ro += pnt - ro; + + //vec3 t = castRay(ro, rd); + + vec2 frag_coord = gl_FragCoord.xy; + vec3 camera_pos = ro; //vec3(0.0, -5.0, 0.0); + float aspect = float(iResolution.x) / float(iResolution.y); + float zoom = .8; + vec3 right = (aspect / zoom) * vec3(3.0, 0.0, 0.0); + vec3 up = (1.0 / zoom) * vec3(0.0, 0.0, 3.0); + vec3 bottom_left = -0.5 * (right + up); + vec2 uv = frag_coord / vec2(iResolution.xy); + vec3 ray_dir = rd; //normalize(bottom_left + uv.x * right + uv.y * up - camera_pos); + // Rotate the camera slowly + float pitch = -0.2 * M_PI; + float yaw = 0.1 * M_PI * iTime; + mat3 rot_z = mat3(cos(yaw), sin(yaw), 0.0, -sin(yaw), cos(yaw), 0.0, 0.0, 0.0, 1.0); + mat3 rot_x = mat3(1.0, 0.0, 0.0, 0.0, cos(pitch), sin(pitch), 0.0, -sin(pitch), cos(pitch)); + camera_pos = rot_z * rot_x * camera_pos; + ray_dir = normalize(rot_z * rot_x * ray_dir); + // Define SH coefficients (measured up to band 8, noise beyond that) + float sh_coeffs[SH_COUNT]; + sh_coeffs[0] = -0.2739740312099; sh_coeffs[1] = 0.2526670396328; sh_coeffs[2] = 1.8922271728516; sh_coeffs[3] = 0.2878578901291; sh_coeffs[4] = -0.5339795947075; sh_coeffs[5] = -0.2620058953762; +#if SH_DEGREE >= 4 + sh_coeffs[6] = 0.1580424904823; sh_coeffs[7] = 0.0329004973173; sh_coeffs[8] = -0.1322413831949; sh_coeffs[9] = -0.1332057565451; sh_coeffs[10] = 1.0894461870193; sh_coeffs[11] = -0.6319401264191; sh_coeffs[12] = -0.0416776277125; sh_coeffs[13] = -1.0772529840469; sh_coeffs[14] = 0.1423762738705; +#endif +#if SH_DEGREE >= 6 + sh_coeffs[15] = 0.7941166162491; sh_coeffs[16] = 0.7490307092667; sh_coeffs[17] = -0.3428381681442; sh_coeffs[18] = 0.1024847552180; sh_coeffs[19] = -0.0219132602215; sh_coeffs[20] = 0.0499043911695; sh_coeffs[21] = 0.2162453681231; sh_coeffs[22] = 0.0921059995890; sh_coeffs[23] = -0.2611238956451; sh_coeffs[24] = 0.2549301385880; sh_coeffs[25] = -0.4534865319729; sh_coeffs[26] = 0.1922748684883; sh_coeffs[27] = -0.6200597286224; +#endif +#if SH_DEGREE >= 8 + sh_coeffs[28] = -0.0532187558711; sh_coeffs[29] = -0.3569841980934; sh_coeffs[30] = 0.0293972902000; sh_coeffs[31] = -0.1977960765362; sh_coeffs[32] = -0.1058669015765; sh_coeffs[33] = 0.2372217923403; sh_coeffs[34] = -0.1856198310852; sh_coeffs[35] = -0.3373193442822; sh_coeffs[36] = -0.0750469490886; sh_coeffs[37] = 0.2146576642990; sh_coeffs[38] = -0.0490148440003; sh_coeffs[39] = 0.1288588196039; sh_coeffs[40] = 0.3173974752426; sh_coeffs[41] = 0.1990085393190; sh_coeffs[42] = -0.1736343950033; sh_coeffs[43] = -0.0482443645597; sh_coeffs[44] = 0.1749017387629; +#endif +#if SH_DEGREE >= 10 + sh_coeffs[45] = -0.0151847425660; sh_coeffs[46] = 0.0418366046081; sh_coeffs[47] = 0.0863263587216; sh_coeffs[48] = -0.0649211244490; sh_coeffs[49] = 0.0126096132283; sh_coeffs[50] = 0.0545089217982; sh_coeffs[51] = -0.0275142164626; sh_coeffs[52] = 0.0399986574832; sh_coeffs[53] = -0.0468244261610; sh_coeffs[54] = -0.1292105653111; sh_coeffs[55] = -0.0786858322658; sh_coeffs[56] = -0.0663828464882; sh_coeffs[57] = 0.0382439706831; sh_coeffs[58] = -0.0041550330365; sh_coeffs[59] = -0.0502800566338; sh_coeffs[60] = -0.0732471630735; sh_coeffs[61] = 0.0181751900972; sh_coeffs[62] = -0.0090119333757; sh_coeffs[63] = -0.0604443282359; sh_coeffs[64] = -0.1469985252752; sh_coeffs[65] = -0.0534046899715; +#endif +#if SH_DEGREE >= 12 + sh_coeffs[66] = -0.0896672753415; sh_coeffs[67] = -0.0130841364808; sh_coeffs[68] = -0.0112942893801; sh_coeffs[69] = 0.0272257498541; sh_coeffs[70] = 0.0626717616331; sh_coeffs[71] = -0.0222197983050; sh_coeffs[72] = -0.0018541504308; sh_coeffs[73] = -0.1653251944056; sh_coeffs[74] = 0.0409697402846; sh_coeffs[75] = 0.0749921454327; sh_coeffs[76] = -0.0282830872616; sh_coeffs[77] = 0.0006909458525; sh_coeffs[78] = 0.0625599842287; sh_coeffs[79] = 0.0812529816082; sh_coeffs[80] = 0.0914693020772; sh_coeffs[81] = -0.1197222726745; sh_coeffs[82] = 0.0376277453183; sh_coeffs[83] = -0.0832617004142; sh_coeffs[84] = -0.0482175038043; sh_coeffs[85] = -0.0839003635737; sh_coeffs[86] = -0.0349423908400; sh_coeffs[87] = 0.1204519568256; sh_coeffs[88] = 0.0783745984003; sh_coeffs[89] = 0.0297401205976; sh_coeffs[90] = -0.0505947662525; +#endif + // Perform the intersection test + float ray_params[MAX_DEGREE]; + ray_sh_glyph_intersections(ray_params, sh_coeffs, camera_pos, ray_dir); + // Identify the first intersection + float first_ray_param = NO_INTERSECTION; + _unroll_ + for (int i = 0; i != MAX_DEGREE; ++i) { + if (ray_params[i] != NO_INTERSECTION && ray_params[i] > 0.0) { + first_ray_param = ray_params[i]; + break; + } + } + // Evaluate shading for a directional light + vec3 color = vec3(1.0); + if (first_ray_param != NO_INTERSECTION) { + vec3 intersection = camera_pos + first_ray_param * ray_dir; + vec3 normal = get_sh_glyph_normal(sh_coeffs, intersection); + vec3 base_color = srgb_to_linear_rgb(abs(normalize(intersection))); + const vec3 incoming = normalize(vec3(1.23, -4.56, 7.89)); + float ambient = 0.04; + float exposure = 4.0; + vec3 outgoing = -ray_dir; + vec3 brdf = gltf_dielectric_brdf(incoming, outgoing, normal, 0.45, base_color); + color = exposure * (brdf * max(0.0, dot(incoming, normal)) + base_color * ambient); + } + vec4 out_color = vec4(linear_rgb_to_srgb(tonemap(color)), 1.0); + fragOutput0 = out_color; + + """ + + shader_to_actor( + odf_actor, "fragment", impl_code=sdf_frag_impl, block="picking" + ) + + show_man.scene.add(odf_actor) + + show_man.start() diff --git a/fury/shaders/spherical_harmonics/eval_sh_10.frag b/fury/shaders/spherical_harmonics/eval_sh_10.frag new file mode 100644 index 000000000..178033cae --- /dev/null +++ b/fury/shaders/spherical_harmonics/eval_sh_10.frag @@ -0,0 +1,175 @@ +void eval_sh_10(out float out_shs[66], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + b = z2 * a - 0.250980392 * b; + a = b - 0.250773994 * a; + d = 233.240148813 * a; + out_shs[55] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[20] = -c1 * d; + out_shs[22] = s1 * d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[35] = -c1 * d; + out_shs[37] = s1 * d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + out_shs[54] = -c1 * d; + out_shs[56] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[19] = c0 * d; + out_shs[23] = s0 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[34] = c0 * d; + out_shs[38] = s0 * d; + b = z2 * a - 0.235294118 * b; + a = b - 0.238390093 * a; + d = 272.365814381 * a; + out_shs[53] = c0 * d; + out_shs[57] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[18] = -c1 * d; + out_shs[24] = s1 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[33] = -c1 * d; + out_shs[39] = s1 * d; + a = z2 * b - 0.215686275 * a; + b = a - 0.222910217 * b; + d = -213.661323441 * b; + out_shs[52] = -c1 * d; + out_shs[58] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[17] = c0 * d; + out_shs[25] = s0 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[32] = c0 * d; + out_shs[40] = s0 * d; + b = z2 * a - 0.188235294 * b; + a = b - 0.20123839 * a; + d = 151.081370682 * a; + out_shs[51] = c0 * d; + out_shs[59] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[16] = -c1 * d; + out_shs[26] = s1 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[31] = -c1 * d; + out_shs[41] = s1 * d; + a = z2 * b - 0.152941176 * a; + b = a - 0.173374613 * b; + d = -95.552248675 * b; + out_shs[50] = -c1 * d; + out_shs[60] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[15] = c0 * d; + out_shs[27] = s0 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[30] = c0 * d; + out_shs[42] = s0 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + out_shs[49] = c0 * d; + out_shs[61] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[29] = -c1 * d; + out_shs[43] = s1 * d; + a = (z2 - 5.88235294e-02) * z; + b = a - 9.90712074e-02 * z; + d = -25.910241313 * b; + out_shs[48] = -c1 * d; + out_shs[62] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[28] = c0 * d; + out_shs[44] = s0 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + out_shs[47] = c0 * d; + out_shs[63] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + out_shs[46] = -c1 * d; + out_shs[64] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + out_shs[45] = c0 * d; + out_shs[65] = s0 * d; +} diff --git a/fury/shaders/spherical_harmonics/eval_sh_12.frag b/fury/shaders/spherical_harmonics/eval_sh_12.frag new file mode 100644 index 000000000..f1a6d85e9 --- /dev/null +++ b/fury/shaders/spherical_harmonics/eval_sh_12.frag @@ -0,0 +1,238 @@ +void eval_sh_12(out float out_shs[91], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + b = z2 * a - 0.250980392 * b; + a = b - 0.250773994 * a; + d = 233.240148813 * a; + out_shs[55] = d; + b = z2 * a - 0.250626566 * b; + a = b - 0.250517598 * a; + d = 931.186918633 * a; + out_shs[78] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[20] = -c1 * d; + out_shs[22] = s1 * d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[35] = -c1 * d; + out_shs[37] = s1 * d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + out_shs[54] = -c1 * d; + out_shs[56] = s1 * d; + a = z2 * b - 0.248120301 * a; + b = a - 0.248447205 * b; + d = -1265.233874957 * b; + out_shs[77] = -c1 * d; + out_shs[79] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[19] = c0 * d; + out_shs[23] = s0 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[34] = c0 * d; + out_shs[38] = s0 * d; + b = z2 * a - 0.235294118 * b; + a = b - 0.238390093 * a; + d = 272.365814381 * a; + out_shs[53] = c0 * d; + out_shs[57] = s0 * d; + b = z2 * a - 0.240601504 * b; + a = b - 0.242236025 * a; + d = 1121.509962433 * a; + out_shs[76] = c0 * d; + out_shs[80] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[18] = -c1 * d; + out_shs[24] = s1 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[33] = -c1 * d; + out_shs[39] = s1 * d; + a = z2 * b - 0.215686275 * a; + b = a - 0.222910217 * b; + d = -213.661323441 * b; + out_shs[52] = -c1 * d; + out_shs[58] = s1 * d; + a = z2 * b - 0.228070175 * a; + b = a - 0.231884058 * b; + d = -915.709049803 * b; + out_shs[75] = -c1 * d; + out_shs[81] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[17] = c0 * d; + out_shs[25] = s0 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[32] = c0 * d; + out_shs[40] = s0 * d; + b = z2 * a - 0.188235294 * b; + a = b - 0.20123839 * a; + d = 151.081370682 * a; + out_shs[51] = c0 * d; + out_shs[59] = s0 * d; + b = z2 * a - 0.210526316 * b; + a = b - 0.217391304 * a; + d = 686.781787352 * a; + out_shs[74] = c0 * d; + out_shs[82] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[16] = -c1 * d; + out_shs[26] = s1 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[31] = -c1 * d; + out_shs[41] = s1 * d; + a = z2 * b - 0.152941176 * a; + b = a - 0.173374613 * b; + d = -95.552248675 * b; + out_shs[50] = -c1 * d; + out_shs[60] = s1 * d; + a = z2 * b - 0.187969925 * a; + b = a - 0.198757764 * b; + d = -471.12841933 * b; + out_shs[73] = -c1 * d; + out_shs[83] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[15] = c0 * d; + out_shs[27] = s0 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[30] = c0 * d; + out_shs[42] = s0 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + out_shs[49] = c0 * d; + out_shs[61] = s0 * d; + b = z2 * a - 0.160401003 * b; + a = b - 0.175983437 * a; + d = 293.800188384 * a; + out_shs[72] = c0 * d; + out_shs[84] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[29] = -c1 * d; + out_shs[43] = s1 * d; + a = (z2 - 5.88235294e-02) * z; + b = a - 9.90712074e-02 * z; + d = -25.910241313 * b; + out_shs[48] = -c1 * d; + out_shs[62] = s1 * d; + a = z2 * b - 0.127819549 * a; + b = a - 0.149068323 * b; + d = -165.101452729 * b; + out_shs[71] = -c1 * d; + out_shs[85] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[28] = c0 * d; + out_shs[44] = s0 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + out_shs[47] = c0 * d; + out_shs[63] = s0 * d; + b = z2 * (a - 9.02255639e-02); + a = b - 0.118012422 * a; + d = 82.550726364 * a; + out_shs[70] = c0 * d; + out_shs[86] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + out_shs[46] = -c1 * d; + out_shs[64] = s1 * d; + a = (z2 - 4.76190476e-02) * z; + b = a - 8.2815735e-02 * z; + d = -36.028090689 * b; + out_shs[69] = -c1 * d; + out_shs[87] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + out_shs[45] = c0 * d; + out_shs[65] = s0 * d; + a = z2 - 4.34782609e-02; + d = 13.3042542 * a; + out_shs[68] = c0 * d; + out_shs[88] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.923210529 * z; + out_shs[67] = -c1 * d; + out_shs[89] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.800821996; + out_shs[66] = c0 * d; + out_shs[90] = s0 * d; +} diff --git a/fury/shaders/spherical_harmonics/eval_sh_2.frag b/fury/shaders/spherical_harmonics/eval_sh_2.frag new file mode 100644 index 000000000..c15510b74 --- /dev/null +++ b/fury/shaders/spherical_harmonics/eval_sh_2.frag @@ -0,0 +1,23 @@ +void eval_sh_2(out float out_shs[6], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; +} diff --git a/fury/shaders/spherical_harmonics/eval_sh_4.frag b/fury/shaders/spherical_harmonics/eval_sh_4.frag new file mode 100644 index 000000000..975fac054 --- /dev/null +++ b/fury/shaders/spherical_harmonics/eval_sh_4.frag @@ -0,0 +1,46 @@ +void eval_sh_4(out float out_shs[15], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; +} diff --git a/fury/shaders/spherical_harmonics/eval_sh_6.frag b/fury/shaders/spherical_harmonics/eval_sh_6.frag new file mode 100644 index 000000000..6cbd1bcf1 --- /dev/null +++ b/fury/shaders/spherical_harmonics/eval_sh_6.frag @@ -0,0 +1,79 @@ +void eval_sh_6(out float out_shs[28], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[20] = -c1 * d; + out_shs[22] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[19] = c0 * d; + out_shs[23] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[18] = -c1 * d; + out_shs[24] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[17] = c0 * d; + out_shs[25] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[16] = -c1 * d; + out_shs[26] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[15] = c0 * d; + out_shs[27] = s0 * d; +} diff --git a/fury/shaders/spherical_harmonics/eval_sh_8.frag b/fury/shaders/spherical_harmonics/eval_sh_8.frag new file mode 100644 index 000000000..6e79b2b16 --- /dev/null +++ b/fury/shaders/spherical_harmonics/eval_sh_8.frag @@ -0,0 +1,122 @@ +void eval_sh_8(out float out_shs[45], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[20] = -c1 * d; + out_shs[22] = s1 * d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[35] = -c1 * d; + out_shs[37] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[19] = c0 * d; + out_shs[23] = s0 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[34] = c0 * d; + out_shs[38] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[18] = -c1 * d; + out_shs[24] = s1 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[33] = -c1 * d; + out_shs[39] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[17] = c0 * d; + out_shs[25] = s0 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[32] = c0 * d; + out_shs[40] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[16] = -c1 * d; + out_shs[26] = s1 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[31] = -c1 * d; + out_shs[41] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[15] = c0 * d; + out_shs[27] = s0 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[30] = c0 * d; + out_shs[42] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[29] = -c1 * d; + out_shs[43] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[28] = c0 * d; + out_shs[44] = s0 * d; +} diff --git a/fury/shaders/spherical_harmonics/eval_sh_grad_10.frag b/fury/shaders/spherical_harmonics/eval_sh_grad_10.frag new file mode 100644 index 000000000..9d5feea39 --- /dev/null +++ b/fury/shaders/spherical_harmonics/eval_sh_grad_10.frag @@ -0,0 +1,430 @@ +void eval_sh_grad_10(out float out_shs[66], out vec3 out_grads[66], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + b = z2 * a - 0.250980392 * b; + a = b - 0.250773994 * a; + d = 233.240148813 * a; + out_shs[55] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + out_grads[2][0] = -c0 * d; + out_grads[4][0] = s0 * d; + out_grads[2][1] = s0 * d; + out_grads[4][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + out_grads[9][0] = -c0 * d; + out_grads[11][0] = s0 * d; + out_grads[9][1] = s0 * d; + out_grads[11][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[20] = -c1 * d; + out_shs[22] = s1 * d; + out_grads[20][0] = -c0 * d; + out_grads[22][0] = s0 * d; + out_grads[20][1] = s0 * d; + out_grads[22][1] = c0 * d; + d = 88.106914343 * b; + out_grads[21][2] = d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[35] = -c1 * d; + out_shs[37] = s1 * d; + out_grads[35][0] = -c0 * d; + out_grads[37][0] = s0 * d; + out_grads[35][1] = s0 * d; + out_grads[37][1] = c0 * d; + d = 467.786944906 * b; + out_grads[36][2] = d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + out_shs[54] = -c1 * d; + out_shs[56] = s1 * d; + out_grads[54][0] = -c0 * d; + out_grads[56][0] = s0 * d; + out_grads[54][1] = s0 * d; + out_grads[56][1] = c0 * d; + d = 2332.401488133 * b; + out_grads[55][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + d = 1.092548431; + out_grads[1][0] = c1 * d; + out_grads[5][0] = s1 * d; + out_grads[1][1] = -s1 * d; + out_grads[5][1] = c1 * d; + d = -1.092548431; + out_grads[2][2] = -c1 * d; + out_grads[4][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + d = 6.62322287 * a; + out_grads[8][0] = c1 * d; + out_grads[12][0] = s1 * d; + out_grads[8][1] = -s1 * d; + out_grads[12][1] = c1 * d; + d = -14.049977415 * a; + out_grads[9][2] = -c1 * d; + out_grads[11][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[19] = c0 * d; + out_shs[23] = s0 * d; + d = 30.399773564 * a; + out_grads[19][0] = c1 * d; + out_grads[23][0] = s1 * d; + out_grads[19][1] = -s1 * d; + out_grads[23][1] = c1 * d; + d = -96.132524816 * a; + out_grads[20][2] = -c1 * d; + out_grads[22][2] = s1 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[34] = c0 * d; + out_shs[38] = s0 * d; + d = 130.459545912 * a; + out_grads[34][0] = c1 * d; + out_grads[38][0] = s1 * d; + out_grads[34][1] = -s1 * d; + out_grads[38][1] = c1 * d; + d = -545.751435723 * a; + out_grads[35][2] = -c1 * d; + out_grads[37][2] = s1 * d; + b = z2 * a - 0.235294118 * b; + a = b - 0.238390093 * a; + d = 272.365814381 * a; + out_shs[53] = c0 * d; + out_shs[57] = s0 * d; + d = 544.731628762 * a; + out_grads[53][0] = c1 * d; + out_grads[57][0] = s1 * d; + out_grads[53][1] = -s1 * d; + out_grads[57][1] = c1 * d; + d = -2830.508572514 * a; + out_grads[54][2] = -c1 * d; + out_grads[56][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + d = -5.310392309 * z; + out_grads[7][0] = -c0 * d; + out_grads[13][0] = s0 * d; + out_grads[7][1] = s0 * d; + out_grads[13][1] = c0 * d; + d = 6.62322287 * z; + out_grads[8][2] = c0 * d; + out_grads[12][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[18] = -c1 * d; + out_shs[24] = s1 * d; + d = -30.399773564 * b; + out_grads[18][0] = -c0 * d; + out_grads[24][0] = s0 * d; + out_grads[18][1] = s0 * d; + out_grads[24][1] = c0 * d; + d = 60.799547128 * b; + out_grads[19][2] = c0 * d; + out_grads[23][2] = s0 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[33] = -c1 * d; + out_shs[39] = s1 * d; + d = -144.52614017 * b; + out_grads[33][0] = -c0 * d; + out_grads[39][0] = s0 * d; + out_grads[33][1] = s0 * d; + out_grads[39][1] = c0 * d; + d = 391.378637737 * b; + out_grads[34][2] = c0 * d; + out_grads[38][2] = s0 * d; + a = z2 * b - 0.215686275 * a; + b = a - 0.222910217 * b; + d = -213.661323441 * b; + out_shs[52] = -c1 * d; + out_shs[58] = s1 * d; + d = -640.983970322 * b; + out_grads[52][0] = -c0 * d; + out_grads[58][0] = s0 * d; + out_grads[52][1] = s0 * d; + out_grads[58][1] = c0 * d; + d = 2178.926515046 * b; + out_grads[53][2] = c0 * d; + out_grads[57][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + d = 2.503342942; + out_grads[6][0] = c1 * d; + out_grads[14][0] = s1 * d; + out_grads[6][1] = -s1 * d; + out_grads[14][1] = c1 * d; + d = -1.77013077; + out_grads[7][2] = -c1 * d; + out_grads[13][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[17] = c0 * d; + out_shs[25] = s0 * d; + d = 22.200855632 * a; + out_grads[17][0] = c1 * d; + out_grads[25][0] = s1 * d; + out_grads[17][1] = -s1 * d; + out_grads[25][1] = c1 * d; + d = -30.399773564 * a; + out_grads[18][2] = -c1 * d; + out_grads[24][2] = s1 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[32] = c0 * d; + out_shs[40] = s0 * d; + d = 124.388296437 * a; + out_grads[32][0] = c1 * d; + out_grads[40][0] = s1 * d; + out_grads[32][1] = -s1 * d; + out_grads[40][1] = c1 * d; + d = -240.876900283 * a; + out_grads[33][2] = -c1 * d; + out_grads[39][2] = s1 * d; + b = z2 * a - 0.188235294 * b; + a = b - 0.20123839 * a; + d = 151.081370682 * a; + out_shs[51] = c0 * d; + out_shs[59] = s0 * d; + d = 604.325482728 * a; + out_grads[51][0] = c1 * d; + out_grads[59][0] = s1 * d; + out_grads[51][1] = -s1 * d; + out_grads[59][1] = c1 * d; + d = -1495.629264084 * a; + out_grads[52][2] = -c1 * d; + out_grads[58][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[16] = -c1 * d; + out_shs[26] = s1 * d; + d = -11.833095811 * z; + out_grads[16][0] = -c0 * d; + out_grads[26][0] = s0 * d; + out_grads[16][1] = s0 * d; + out_grads[26][1] = c0 * d; + d = 11.100427816 * z; + out_grads[17][2] = c0 * d; + out_grads[25][2] = s0 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[31] = -c1 * d; + out_shs[41] = s1 * d; + d = -86.247765552 * b; + out_grads[31][0] = -c0 * d; + out_grads[41][0] = s0 * d; + out_grads[31][1] = s0 * d; + out_grads[41][1] = c0 * d; + d = 124.388296437 * b; + out_grads[32][2] = c0 * d; + out_grads[40][2] = s0 * d; + a = z2 * b - 0.152941176 * a; + b = a - 0.173374613 * b; + d = -95.552248675 * b; + out_shs[50] = -c1 * d; + out_shs[60] = s1 * d; + d = -477.761243376 * b; + out_grads[50][0] = -c0 * d; + out_grads[60][0] = s0 * d; + out_grads[50][1] = s0 * d; + out_grads[60][1] = c0 * d; + d = 906.488224092 * b; + out_grads[51][2] = c0 * d; + out_grads[59][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[15] = c0 * d; + out_shs[27] = s0 * d; + d = 4.099104631; + out_grads[15][0] = c1 * d; + out_grads[27][0] = s1 * d; + out_grads[15][1] = -s1 * d; + out_grads[27][1] = c1 * d; + d = -2.366619162; + out_grads[16][2] = -c1 * d; + out_grads[26][2] = s1 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[30] = c0 * d; + out_shs[42] = s0 * d; + d = 47.909948945 * a; + out_grads[30][0] = c1 * d; + out_grads[42][0] = s1 * d; + out_grads[30][1] = -s1 * d; + out_grads[42][1] = c1 * d; + d = -51.748659331 * a; + out_grads[31][2] = -c1 * d; + out_grads[41][2] = s1 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + out_shs[49] = c0 * d; + out_shs[61] = s0 * d; + d = 320.491985161 * a; + out_grads[49][0] = c1 * d; + out_grads[61][0] = s1 * d; + out_grads[49][1] = -s1 * d; + out_grads[61][1] = c1 * d; + d = -477.761243376 * a; + out_grads[50][2] = -c1 * d; + out_grads[60][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[29] = -c1 * d; + out_shs[43] = s1 * d; + d = -20.409946485 * z; + out_grads[29][0] = -c0 * d; + out_grads[43][0] = s0 * d; + out_grads[29][1] = s0 * d; + out_grads[43][1] = c0 * d; + d = 15.969982982 * z; + out_grads[30][2] = c0 * d; + out_grads[42][2] = s0 * d; + a = (z2 - 5.88235294e-02) * z; + b = a - 9.90712074e-02 * z; + d = -25.910241313 * b; + out_shs[48] = -c1 * d; + out_shs[62] = s1 * d; + d = -181.371689194 * b; + out_grads[48][0] = -c0 * d; + out_grads[62][0] = s0 * d; + out_grads[48][1] = s0 * d; + out_grads[62][1] = c0 * d; + d = 213.661323441 * b; + out_grads[49][2] = c0 * d; + out_grads[61][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[28] = c0 * d; + out_shs[44] = s0 * d; + d = 5.831413281; + out_grads[28][0] = c1 * d; + out_grads[44][0] = s1 * d; + out_grads[28][1] = -s1 * d; + out_grads[44][1] = c1 * d; + d = -2.915706641; + out_grads[29][2] = -c1 * d; + out_grads[43][2] = s1 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + out_shs[47] = c0 * d; + out_shs[63] = s0 * d; + d = 84.622493774 * a; + out_grads[47][0] = c1 * d; + out_grads[63][0] = s1 * d; + out_grads[47][1] = -s1 * d; + out_grads[63][1] = c1 * d; + d = -77.73072394 * a; + out_grads[48][2] = -c1 * d; + out_grads[62][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + out_shs[46] = -c1 * d; + out_shs[64] = s1 * d; + d = -30.887057699 * z; + out_grads[46][0] = -c0 * d; + out_grads[64][0] = s0 * d; + out_grads[46][1] = s0 * d; + out_grads[64][1] = c0 * d; + d = 21.155623443 * z; + out_grads[47][2] = c0 * d; + out_grads[63][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + out_shs[45] = c0 * d; + out_shs[65] = s0 * d; + d = 7.673951182; + out_grads[45][0] = c1 * d; + out_grads[65][0] = s1 * d; + out_grads[45][1] = -s1 * d; + out_grads[65][1] = c1 * d; + d = -3.4318953; + out_grads[46][2] = -c1 * d; + out_grads[64][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; + out_grads[6][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[14][2] = 0.0; + out_grads[15][2] = 0.0; + out_grads[21][0] = 0.0; + out_grads[21][1] = 0.0; + out_grads[27][2] = 0.0; + out_grads[28][2] = 0.0; + out_grads[36][0] = 0.0; + out_grads[36][1] = 0.0; + out_grads[44][2] = 0.0; + out_grads[45][2] = 0.0; + out_grads[55][0] = 0.0; + out_grads[55][1] = 0.0; + out_grads[65][2] = 0.0; +} diff --git a/fury/shaders/spherical_harmonics/eval_sh_grad_12.frag b/fury/shaders/spherical_harmonics/eval_sh_grad_12.frag new file mode 100644 index 000000000..f7ff069bc --- /dev/null +++ b/fury/shaders/spherical_harmonics/eval_sh_grad_12.frag @@ -0,0 +1,591 @@ +void eval_sh_grad_12(out float out_shs[91], out vec3 out_grads[91], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + b = z2 * a - 0.250980392 * b; + a = b - 0.250773994 * a; + d = 233.240148813 * a; + out_shs[55] = d; + b = z2 * a - 0.250626566 * b; + a = b - 0.250517598 * a; + d = 931.186918633 * a; + out_shs[78] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + out_grads[2][0] = -c0 * d; + out_grads[4][0] = s0 * d; + out_grads[2][1] = s0 * d; + out_grads[4][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + out_grads[9][0] = -c0 * d; + out_grads[11][0] = s0 * d; + out_grads[9][1] = s0 * d; + out_grads[11][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[20] = -c1 * d; + out_shs[22] = s1 * d; + out_grads[20][0] = -c0 * d; + out_grads[22][0] = s0 * d; + out_grads[20][1] = s0 * d; + out_grads[22][1] = c0 * d; + d = 88.106914343 * b; + out_grads[21][2] = d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[35] = -c1 * d; + out_shs[37] = s1 * d; + out_grads[35][0] = -c0 * d; + out_grads[37][0] = s0 * d; + out_grads[35][1] = s0 * d; + out_grads[37][1] = c0 * d; + d = 467.786944906 * b; + out_grads[36][2] = d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + out_shs[54] = -c1 * d; + out_shs[56] = s1 * d; + out_grads[54][0] = -c0 * d; + out_grads[56][0] = s0 * d; + out_grads[54][1] = s0 * d; + out_grads[56][1] = c0 * d; + d = 2332.401488133 * b; + out_grads[55][2] = d; + a = z2 * b - 0.248120301 * a; + b = a - 0.248447205 * b; + d = -1265.233874957 * b; + out_shs[77] = -c1 * d; + out_shs[79] = s1 * d; + out_grads[77][0] = -c0 * d; + out_grads[79][0] = s0 * d; + out_grads[77][1] = s0 * d; + out_grads[79][1] = c0 * d; + d = 11174.243023595 * b; + out_grads[78][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + d = 1.092548431; + out_grads[1][0] = c1 * d; + out_grads[5][0] = s1 * d; + out_grads[1][1] = -s1 * d; + out_grads[5][1] = c1 * d; + d = -1.092548431; + out_grads[2][2] = -c1 * d; + out_grads[4][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + d = 6.62322287 * a; + out_grads[8][0] = c1 * d; + out_grads[12][0] = s1 * d; + out_grads[8][1] = -s1 * d; + out_grads[12][1] = c1 * d; + d = -14.049977415 * a; + out_grads[9][2] = -c1 * d; + out_grads[11][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[19] = c0 * d; + out_shs[23] = s0 * d; + d = 30.399773564 * a; + out_grads[19][0] = c1 * d; + out_grads[23][0] = s1 * d; + out_grads[19][1] = -s1 * d; + out_grads[23][1] = c1 * d; + d = -96.132524816 * a; + out_grads[20][2] = -c1 * d; + out_grads[22][2] = s1 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[34] = c0 * d; + out_shs[38] = s0 * d; + d = 130.459545912 * a; + out_grads[34][0] = c1 * d; + out_grads[38][0] = s1 * d; + out_grads[34][1] = -s1 * d; + out_grads[38][1] = c1 * d; + d = -545.751435723 * a; + out_grads[35][2] = -c1 * d; + out_grads[37][2] = s1 * d; + b = z2 * a - 0.235294118 * b; + a = b - 0.238390093 * a; + d = 272.365814381 * a; + out_shs[53] = c0 * d; + out_shs[57] = s0 * d; + d = 544.731628762 * a; + out_grads[53][0] = c1 * d; + out_grads[57][0] = s1 * d; + out_grads[53][1] = -s1 * d; + out_grads[57][1] = c1 * d; + d = -2830.508572514 * a; + out_grads[54][2] = -c1 * d; + out_grads[56][2] = s1 * d; + b = z2 * a - 0.240601504 * b; + a = b - 0.242236025 * a; + d = 1121.509962433 * a; + out_shs[76] = c0 * d; + out_shs[80] = s0 * d; + d = 2243.019924866 * a; + out_grads[76][0] = c1 * d; + out_grads[80][0] = s1 * d; + out_grads[76][1] = -s1 * d; + out_grads[80][1] = c1 * d; + d = -13917.572624524 * a; + out_grads[77][2] = -c1 * d; + out_grads[79][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + d = -5.310392309 * z; + out_grads[7][0] = -c0 * d; + out_grads[13][0] = s0 * d; + out_grads[7][1] = s0 * d; + out_grads[13][1] = c0 * d; + d = 6.62322287 * z; + out_grads[8][2] = c0 * d; + out_grads[12][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[18] = -c1 * d; + out_shs[24] = s1 * d; + d = -30.399773564 * b; + out_grads[18][0] = -c0 * d; + out_grads[24][0] = s0 * d; + out_grads[18][1] = s0 * d; + out_grads[24][1] = c0 * d; + d = 60.799547128 * b; + out_grads[19][2] = c0 * d; + out_grads[23][2] = s0 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[33] = -c1 * d; + out_shs[39] = s1 * d; + d = -144.52614017 * b; + out_grads[33][0] = -c0 * d; + out_grads[39][0] = s0 * d; + out_grads[33][1] = s0 * d; + out_grads[39][1] = c0 * d; + d = 391.378637737 * b; + out_grads[34][2] = c0 * d; + out_grads[38][2] = s0 * d; + a = z2 * b - 0.215686275 * a; + b = a - 0.222910217 * b; + d = -213.661323441 * b; + out_shs[52] = -c1 * d; + out_shs[58] = s1 * d; + d = -640.983970322 * b; + out_grads[52][0] = -c0 * d; + out_grads[58][0] = s0 * d; + out_grads[52][1] = s0 * d; + out_grads[58][1] = c0 * d; + d = 2178.926515046 * b; + out_grads[53][2] = c0 * d; + out_grads[57][2] = s0 * d; + a = z2 * b - 0.228070175 * a; + b = a - 0.231884058 * b; + d = -915.709049803 * b; + out_shs[75] = -c1 * d; + out_shs[81] = s1 * d; + d = -2747.127149409 * b; + out_grads[75][0] = -c0 * d; + out_grads[81][0] = s0 * d; + out_grads[75][1] = s0 * d; + out_grads[81][1] = c0 * d; + d = 11215.099624332 * b; + out_grads[76][2] = c0 * d; + out_grads[80][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + d = 2.503342942; + out_grads[6][0] = c1 * d; + out_grads[14][0] = s1 * d; + out_grads[6][1] = -s1 * d; + out_grads[14][1] = c1 * d; + d = -1.77013077; + out_grads[7][2] = -c1 * d; + out_grads[13][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[17] = c0 * d; + out_shs[25] = s0 * d; + d = 22.200855632 * a; + out_grads[17][0] = c1 * d; + out_grads[25][0] = s1 * d; + out_grads[17][1] = -s1 * d; + out_grads[25][1] = c1 * d; + d = -30.399773564 * a; + out_grads[18][2] = -c1 * d; + out_grads[24][2] = s1 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[32] = c0 * d; + out_shs[40] = s0 * d; + d = 124.388296437 * a; + out_grads[32][0] = c1 * d; + out_grads[40][0] = s1 * d; + out_grads[32][1] = -s1 * d; + out_grads[40][1] = c1 * d; + d = -240.876900283 * a; + out_grads[33][2] = -c1 * d; + out_grads[39][2] = s1 * d; + b = z2 * a - 0.188235294 * b; + a = b - 0.20123839 * a; + d = 151.081370682 * a; + out_shs[51] = c0 * d; + out_shs[59] = s0 * d; + d = 604.325482728 * a; + out_grads[51][0] = c1 * d; + out_grads[59][0] = s1 * d; + out_grads[51][1] = -s1 * d; + out_grads[59][1] = c1 * d; + d = -1495.629264084 * a; + out_grads[52][2] = -c1 * d; + out_grads[58][2] = s1 * d; + b = z2 * a - 0.210526316 * b; + a = b - 0.217391304 * a; + d = 686.781787352 * a; + out_shs[74] = c0 * d; + out_shs[82] = s0 * d; + d = 2747.127149409 * a; + out_grads[74][0] = c1 * d; + out_grads[82][0] = s1 * d; + out_grads[74][1] = -s1 * d; + out_grads[82][1] = c1 * d; + d = -8241.381448228 * a; + out_grads[75][2] = -c1 * d; + out_grads[81][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[16] = -c1 * d; + out_shs[26] = s1 * d; + d = -11.833095811 * z; + out_grads[16][0] = -c0 * d; + out_grads[26][0] = s0 * d; + out_grads[16][1] = s0 * d; + out_grads[26][1] = c0 * d; + d = 11.100427816 * z; + out_grads[17][2] = c0 * d; + out_grads[25][2] = s0 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[31] = -c1 * d; + out_shs[41] = s1 * d; + d = -86.247765552 * b; + out_grads[31][0] = -c0 * d; + out_grads[41][0] = s0 * d; + out_grads[31][1] = s0 * d; + out_grads[41][1] = c0 * d; + d = 124.388296437 * b; + out_grads[32][2] = c0 * d; + out_grads[40][2] = s0 * d; + a = z2 * b - 0.152941176 * a; + b = a - 0.173374613 * b; + d = -95.552248675 * b; + out_shs[50] = -c1 * d; + out_shs[60] = s1 * d; + d = -477.761243376 * b; + out_grads[50][0] = -c0 * d; + out_grads[60][0] = s0 * d; + out_grads[50][1] = s0 * d; + out_grads[60][1] = c0 * d; + d = 906.488224092 * b; + out_grads[51][2] = c0 * d; + out_grads[59][2] = s0 * d; + a = z2 * b - 0.187969925 * a; + b = a - 0.198757764 * b; + d = -471.12841933 * b; + out_shs[73] = -c1 * d; + out_shs[83] = s1 * d; + d = -2355.642096651 * b; + out_grads[73][0] = -c0 * d; + out_grads[83][0] = s0 * d; + out_grads[73][1] = s0 * d; + out_grads[83][1] = c0 * d; + d = 5494.254298819 * b; + out_grads[74][2] = c0 * d; + out_grads[82][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[15] = c0 * d; + out_shs[27] = s0 * d; + d = 4.099104631; + out_grads[15][0] = c1 * d; + out_grads[27][0] = s1 * d; + out_grads[15][1] = -s1 * d; + out_grads[27][1] = c1 * d; + d = -2.366619162; + out_grads[16][2] = -c1 * d; + out_grads[26][2] = s1 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[30] = c0 * d; + out_shs[42] = s0 * d; + d = 47.909948945 * a; + out_grads[30][0] = c1 * d; + out_grads[42][0] = s1 * d; + out_grads[30][1] = -s1 * d; + out_grads[42][1] = c1 * d; + d = -51.748659331 * a; + out_grads[31][2] = -c1 * d; + out_grads[41][2] = s1 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + out_shs[49] = c0 * d; + out_shs[61] = s0 * d; + d = 320.491985161 * a; + out_grads[49][0] = c1 * d; + out_grads[61][0] = s1 * d; + out_grads[49][1] = -s1 * d; + out_grads[61][1] = c1 * d; + d = -477.761243376 * a; + out_grads[50][2] = -c1 * d; + out_grads[60][2] = s1 * d; + b = z2 * a - 0.160401003 * b; + a = b - 0.175983437 * a; + d = 293.800188384 * a; + out_shs[72] = c0 * d; + out_shs[84] = s0 * d; + d = 1762.801130306 * a; + out_grads[72][0] = c1 * d; + out_grads[84][0] = s1 * d; + out_grads[72][1] = -s1 * d; + out_grads[84][1] = c1 * d; + d = -3297.898935312 * a; + out_grads[73][2] = -c1 * d; + out_grads[83][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[29] = -c1 * d; + out_shs[43] = s1 * d; + d = -20.409946485 * z; + out_grads[29][0] = -c0 * d; + out_grads[43][0] = s0 * d; + out_grads[29][1] = s0 * d; + out_grads[43][1] = c0 * d; + d = 15.969982982 * z; + out_grads[30][2] = c0 * d; + out_grads[42][2] = s0 * d; + a = (z2 - 5.88235294e-02) * z; + b = a - 9.90712074e-02 * z; + d = -25.910241313 * b; + out_shs[48] = -c1 * d; + out_shs[62] = s1 * d; + d = -181.371689194 * b; + out_grads[48][0] = -c0 * d; + out_grads[62][0] = s0 * d; + out_grads[48][1] = s0 * d; + out_grads[62][1] = c0 * d; + d = 213.661323441 * b; + out_grads[49][2] = c0 * d; + out_grads[61][2] = s0 * d; + a = z2 * b - 0.127819549 * a; + b = a - 0.149068323 * b; + d = -165.101452729 * b; + out_shs[71] = -c1 * d; + out_shs[85] = s1 * d; + d = -1155.7101691 * b; + out_grads[71][0] = -c0 * d; + out_grads[85][0] = s0 * d; + out_grads[71][1] = s0 * d; + out_grads[85][1] = c0 * d; + d = 1762.801130306 * b; + out_grads[72][2] = c0 * d; + out_grads[84][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[28] = c0 * d; + out_shs[44] = s0 * d; + d = 5.831413281; + out_grads[28][0] = c1 * d; + out_grads[44][0] = s1 * d; + out_grads[28][1] = -s1 * d; + out_grads[44][1] = c1 * d; + d = -2.915706641; + out_grads[29][2] = -c1 * d; + out_grads[43][2] = s1 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + out_shs[47] = c0 * d; + out_shs[63] = s0 * d; + d = 84.622493774 * a; + out_grads[47][0] = c1 * d; + out_grads[63][0] = s1 * d; + out_grads[47][1] = -s1 * d; + out_grads[63][1] = c1 * d; + d = -77.73072394 * a; + out_grads[48][2] = -c1 * d; + out_grads[62][2] = s1 * d; + b = z2 * (a - 9.02255639e-02); + a = b - 0.118012422 * a; + d = 82.550726364 * a; + out_shs[70] = c0 * d; + out_shs[86] = s0 * d; + d = 660.405810914 * a; + out_grads[70][0] = c1 * d; + out_grads[86][0] = s1 * d; + out_grads[70][1] = -s1 * d; + out_grads[86][1] = c1 * d; + d = -825.507263643 * a; + out_grads[71][2] = -c1 * d; + out_grads[85][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + out_shs[46] = -c1 * d; + out_shs[64] = s1 * d; + d = -30.887057699 * z; + out_grads[46][0] = -c0 * d; + out_grads[64][0] = s0 * d; + out_grads[46][1] = s0 * d; + out_grads[64][1] = c0 * d; + d = 21.155623443 * z; + out_grads[47][2] = c0 * d; + out_grads[63][2] = s0 * d; + a = (z2 - 4.76190476e-02) * z; + b = a - 8.2815735e-02 * z; + d = -36.028090689 * b; + out_shs[69] = -c1 * d; + out_shs[87] = s1 * d; + d = -324.252816204 * b; + out_grads[69][0] = -c0 * d; + out_grads[87][0] = s0 * d; + out_grads[69][1] = s0 * d; + out_grads[87][1] = c0 * d; + d = 330.202905457 * b; + out_grads[70][2] = c0 * d; + out_grads[86][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + out_shs[45] = c0 * d; + out_shs[65] = s0 * d; + d = 7.673951182; + out_grads[45][0] = c1 * d; + out_grads[65][0] = s1 * d; + out_grads[45][1] = -s1 * d; + out_grads[65][1] = c1 * d; + d = -3.4318953; + out_grads[46][2] = -c1 * d; + out_grads[64][2] = s1 * d; + a = z2 - 4.34782609e-02; + d = 13.3042542 * a; + out_shs[68] = c0 * d; + out_shs[88] = s0 * d; + d = 133.042542003 * a; + out_grads[68][0] = c1 * d; + out_grads[88][0] = s1 * d; + out_grads[68][1] = -s1 * d; + out_grads[88][1] = c1 * d; + d = -108.084272068 * a; + out_grads[69][2] = -c1 * d; + out_grads[87][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.923210529 * z; + out_shs[67] = -c1 * d; + out_shs[89] = s1 * d; + d = -43.155315818 * z; + out_grads[67][0] = -c0 * d; + out_grads[89][0] = s0 * d; + out_grads[67][1] = s0 * d; + out_grads[89][1] = c0 * d; + d = 26.608508401 * z; + out_grads[68][2] = c0 * d; + out_grads[88][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.800821996; + out_shs[66] = c0 * d; + out_shs[90] = s0 * d; + d = 9.609863949; + out_grads[66][0] = c1 * d; + out_grads[90][0] = s1 * d; + out_grads[66][1] = -s1 * d; + out_grads[90][1] = c1 * d; + d = -3.923210529; + out_grads[67][2] = -c1 * d; + out_grads[89][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; + out_grads[6][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[14][2] = 0.0; + out_grads[15][2] = 0.0; + out_grads[21][0] = 0.0; + out_grads[21][1] = 0.0; + out_grads[27][2] = 0.0; + out_grads[28][2] = 0.0; + out_grads[36][0] = 0.0; + out_grads[36][1] = 0.0; + out_grads[44][2] = 0.0; + out_grads[45][2] = 0.0; + out_grads[55][0] = 0.0; + out_grads[55][1] = 0.0; + out_grads[65][2] = 0.0; + out_grads[66][2] = 0.0; + out_grads[78][0] = 0.0; + out_grads[78][1] = 0.0; + out_grads[90][2] = 0.0; +} diff --git a/fury/shaders/spherical_harmonics/eval_sh_grad_2.frag b/fury/shaders/spherical_harmonics/eval_sh_grad_2.frag new file mode 100644 index 000000000..7004bd528 --- /dev/null +++ b/fury/shaders/spherical_harmonics/eval_sh_grad_2.frag @@ -0,0 +1,46 @@ +void eval_sh_grad_2(out float out_shs[6], out vec3 out_grads[6], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + out_grads[2][0] = -c0 * d; + out_grads[4][0] = s0 * d; + out_grads[2][1] = s0 * d; + out_grads[4][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + d = 1.092548431; + out_grads[1][0] = c1 * d; + out_grads[5][0] = s1 * d; + out_grads[1][1] = -s1 * d; + out_grads[5][1] = c1 * d; + d = -1.092548431; + out_grads[2][2] = -c1 * d; + out_grads[4][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; +} diff --git a/fury/shaders/spherical_harmonics/eval_sh_grad_4.frag b/fury/shaders/spherical_harmonics/eval_sh_grad_4.frag new file mode 100644 index 000000000..715302f39 --- /dev/null +++ b/fury/shaders/spherical_harmonics/eval_sh_grad_4.frag @@ -0,0 +1,103 @@ +void eval_sh_grad_4(out float out_shs[15], out vec3 out_grads[15], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + out_grads[2][0] = -c0 * d; + out_grads[4][0] = s0 * d; + out_grads[2][1] = s0 * d; + out_grads[4][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + out_grads[9][0] = -c0 * d; + out_grads[11][0] = s0 * d; + out_grads[9][1] = s0 * d; + out_grads[11][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + d = 1.092548431; + out_grads[1][0] = c1 * d; + out_grads[5][0] = s1 * d; + out_grads[1][1] = -s1 * d; + out_grads[5][1] = c1 * d; + d = -1.092548431; + out_grads[2][2] = -c1 * d; + out_grads[4][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + d = 6.62322287 * a; + out_grads[8][0] = c1 * d; + out_grads[12][0] = s1 * d; + out_grads[8][1] = -s1 * d; + out_grads[12][1] = c1 * d; + d = -14.049977415 * a; + out_grads[9][2] = -c1 * d; + out_grads[11][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + d = -5.310392309 * z; + out_grads[7][0] = -c0 * d; + out_grads[13][0] = s0 * d; + out_grads[7][1] = s0 * d; + out_grads[13][1] = c0 * d; + d = 6.62322287 * z; + out_grads[8][2] = c0 * d; + out_grads[12][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + d = 2.503342942; + out_grads[6][0] = c1 * d; + out_grads[14][0] = s1 * d; + out_grads[6][1] = -s1 * d; + out_grads[14][1] = c1 * d; + d = -1.77013077; + out_grads[7][2] = -c1 * d; + out_grads[13][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; + out_grads[6][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[14][2] = 0.0; +} diff --git a/fury/shaders/spherical_harmonics/eval_sh_grad_6.frag b/fury/shaders/spherical_harmonics/eval_sh_grad_6.frag new file mode 100644 index 000000000..fa240c3a5 --- /dev/null +++ b/fury/shaders/spherical_harmonics/eval_sh_grad_6.frag @@ -0,0 +1,186 @@ +void eval_sh_grad_6(out float out_shs[28], out vec3 out_grads[28], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + out_grads[2][0] = -c0 * d; + out_grads[4][0] = s0 * d; + out_grads[2][1] = s0 * d; + out_grads[4][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + out_grads[9][0] = -c0 * d; + out_grads[11][0] = s0 * d; + out_grads[9][1] = s0 * d; + out_grads[11][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[20] = -c1 * d; + out_shs[22] = s1 * d; + out_grads[20][0] = -c0 * d; + out_grads[22][0] = s0 * d; + out_grads[20][1] = s0 * d; + out_grads[22][1] = c0 * d; + d = 88.106914343 * b; + out_grads[21][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + d = 1.092548431; + out_grads[1][0] = c1 * d; + out_grads[5][0] = s1 * d; + out_grads[1][1] = -s1 * d; + out_grads[5][1] = c1 * d; + d = -1.092548431; + out_grads[2][2] = -c1 * d; + out_grads[4][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + d = 6.62322287 * a; + out_grads[8][0] = c1 * d; + out_grads[12][0] = s1 * d; + out_grads[8][1] = -s1 * d; + out_grads[12][1] = c1 * d; + d = -14.049977415 * a; + out_grads[9][2] = -c1 * d; + out_grads[11][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[19] = c0 * d; + out_shs[23] = s0 * d; + d = 30.399773564 * a; + out_grads[19][0] = c1 * d; + out_grads[23][0] = s1 * d; + out_grads[19][1] = -s1 * d; + out_grads[23][1] = c1 * d; + d = -96.132524816 * a; + out_grads[20][2] = -c1 * d; + out_grads[22][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + d = -5.310392309 * z; + out_grads[7][0] = -c0 * d; + out_grads[13][0] = s0 * d; + out_grads[7][1] = s0 * d; + out_grads[13][1] = c0 * d; + d = 6.62322287 * z; + out_grads[8][2] = c0 * d; + out_grads[12][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[18] = -c1 * d; + out_shs[24] = s1 * d; + d = -30.399773564 * b; + out_grads[18][0] = -c0 * d; + out_grads[24][0] = s0 * d; + out_grads[18][1] = s0 * d; + out_grads[24][1] = c0 * d; + d = 60.799547128 * b; + out_grads[19][2] = c0 * d; + out_grads[23][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + d = 2.503342942; + out_grads[6][0] = c1 * d; + out_grads[14][0] = s1 * d; + out_grads[6][1] = -s1 * d; + out_grads[14][1] = c1 * d; + d = -1.77013077; + out_grads[7][2] = -c1 * d; + out_grads[13][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[17] = c0 * d; + out_shs[25] = s0 * d; + d = 22.200855632 * a; + out_grads[17][0] = c1 * d; + out_grads[25][0] = s1 * d; + out_grads[17][1] = -s1 * d; + out_grads[25][1] = c1 * d; + d = -30.399773564 * a; + out_grads[18][2] = -c1 * d; + out_grads[24][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[16] = -c1 * d; + out_shs[26] = s1 * d; + d = -11.833095811 * z; + out_grads[16][0] = -c0 * d; + out_grads[26][0] = s0 * d; + out_grads[16][1] = s0 * d; + out_grads[26][1] = c0 * d; + d = 11.100427816 * z; + out_grads[17][2] = c0 * d; + out_grads[25][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[15] = c0 * d; + out_shs[27] = s0 * d; + d = 4.099104631; + out_grads[15][0] = c1 * d; + out_grads[27][0] = s1 * d; + out_grads[15][1] = -s1 * d; + out_grads[27][1] = c1 * d; + d = -2.366619162; + out_grads[16][2] = -c1 * d; + out_grads[26][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; + out_grads[6][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[14][2] = 0.0; + out_grads[15][2] = 0.0; + out_grads[21][0] = 0.0; + out_grads[21][1] = 0.0; + out_grads[27][2] = 0.0; +} diff --git a/fury/shaders/spherical_harmonics/eval_sh_grad_8.frag b/fury/shaders/spherical_harmonics/eval_sh_grad_8.frag new file mode 100644 index 000000000..b0a40d0a7 --- /dev/null +++ b/fury/shaders/spherical_harmonics/eval_sh_grad_8.frag @@ -0,0 +1,295 @@ +void eval_sh_grad_8(out float out_shs[45], out vec3 out_grads[45], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + out_grads[2][0] = -c0 * d; + out_grads[4][0] = s0 * d; + out_grads[2][1] = s0 * d; + out_grads[4][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + out_grads[9][0] = -c0 * d; + out_grads[11][0] = s0 * d; + out_grads[9][1] = s0 * d; + out_grads[11][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[20] = -c1 * d; + out_shs[22] = s1 * d; + out_grads[20][0] = -c0 * d; + out_grads[22][0] = s0 * d; + out_grads[20][1] = s0 * d; + out_grads[22][1] = c0 * d; + d = 88.106914343 * b; + out_grads[21][2] = d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[35] = -c1 * d; + out_shs[37] = s1 * d; + out_grads[35][0] = -c0 * d; + out_grads[37][0] = s0 * d; + out_grads[35][1] = s0 * d; + out_grads[37][1] = c0 * d; + d = 467.786944906 * b; + out_grads[36][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + d = 1.092548431; + out_grads[1][0] = c1 * d; + out_grads[5][0] = s1 * d; + out_grads[1][1] = -s1 * d; + out_grads[5][1] = c1 * d; + d = -1.092548431; + out_grads[2][2] = -c1 * d; + out_grads[4][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + d = 6.62322287 * a; + out_grads[8][0] = c1 * d; + out_grads[12][0] = s1 * d; + out_grads[8][1] = -s1 * d; + out_grads[12][1] = c1 * d; + d = -14.049977415 * a; + out_grads[9][2] = -c1 * d; + out_grads[11][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[19] = c0 * d; + out_shs[23] = s0 * d; + d = 30.399773564 * a; + out_grads[19][0] = c1 * d; + out_grads[23][0] = s1 * d; + out_grads[19][1] = -s1 * d; + out_grads[23][1] = c1 * d; + d = -96.132524816 * a; + out_grads[20][2] = -c1 * d; + out_grads[22][2] = s1 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[34] = c0 * d; + out_shs[38] = s0 * d; + d = 130.459545912 * a; + out_grads[34][0] = c1 * d; + out_grads[38][0] = s1 * d; + out_grads[34][1] = -s1 * d; + out_grads[38][1] = c1 * d; + d = -545.751435723 * a; + out_grads[35][2] = -c1 * d; + out_grads[37][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + d = -5.310392309 * z; + out_grads[7][0] = -c0 * d; + out_grads[13][0] = s0 * d; + out_grads[7][1] = s0 * d; + out_grads[13][1] = c0 * d; + d = 6.62322287 * z; + out_grads[8][2] = c0 * d; + out_grads[12][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[18] = -c1 * d; + out_shs[24] = s1 * d; + d = -30.399773564 * b; + out_grads[18][0] = -c0 * d; + out_grads[24][0] = s0 * d; + out_grads[18][1] = s0 * d; + out_grads[24][1] = c0 * d; + d = 60.799547128 * b; + out_grads[19][2] = c0 * d; + out_grads[23][2] = s0 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[33] = -c1 * d; + out_shs[39] = s1 * d; + d = -144.52614017 * b; + out_grads[33][0] = -c0 * d; + out_grads[39][0] = s0 * d; + out_grads[33][1] = s0 * d; + out_grads[39][1] = c0 * d; + d = 391.378637737 * b; + out_grads[34][2] = c0 * d; + out_grads[38][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + d = 2.503342942; + out_grads[6][0] = c1 * d; + out_grads[14][0] = s1 * d; + out_grads[6][1] = -s1 * d; + out_grads[14][1] = c1 * d; + d = -1.77013077; + out_grads[7][2] = -c1 * d; + out_grads[13][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[17] = c0 * d; + out_shs[25] = s0 * d; + d = 22.200855632 * a; + out_grads[17][0] = c1 * d; + out_grads[25][0] = s1 * d; + out_grads[17][1] = -s1 * d; + out_grads[25][1] = c1 * d; + d = -30.399773564 * a; + out_grads[18][2] = -c1 * d; + out_grads[24][2] = s1 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[32] = c0 * d; + out_shs[40] = s0 * d; + d = 124.388296437 * a; + out_grads[32][0] = c1 * d; + out_grads[40][0] = s1 * d; + out_grads[32][1] = -s1 * d; + out_grads[40][1] = c1 * d; + d = -240.876900283 * a; + out_grads[33][2] = -c1 * d; + out_grads[39][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[16] = -c1 * d; + out_shs[26] = s1 * d; + d = -11.833095811 * z; + out_grads[16][0] = -c0 * d; + out_grads[26][0] = s0 * d; + out_grads[16][1] = s0 * d; + out_grads[26][1] = c0 * d; + d = 11.100427816 * z; + out_grads[17][2] = c0 * d; + out_grads[25][2] = s0 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[31] = -c1 * d; + out_shs[41] = s1 * d; + d = -86.247765552 * b; + out_grads[31][0] = -c0 * d; + out_grads[41][0] = s0 * d; + out_grads[31][1] = s0 * d; + out_grads[41][1] = c0 * d; + d = 124.388296437 * b; + out_grads[32][2] = c0 * d; + out_grads[40][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[15] = c0 * d; + out_shs[27] = s0 * d; + d = 4.099104631; + out_grads[15][0] = c1 * d; + out_grads[27][0] = s1 * d; + out_grads[15][1] = -s1 * d; + out_grads[27][1] = c1 * d; + d = -2.366619162; + out_grads[16][2] = -c1 * d; + out_grads[26][2] = s1 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[30] = c0 * d; + out_shs[42] = s0 * d; + d = 47.909948945 * a; + out_grads[30][0] = c1 * d; + out_grads[42][0] = s1 * d; + out_grads[30][1] = -s1 * d; + out_grads[42][1] = c1 * d; + d = -51.748659331 * a; + out_grads[31][2] = -c1 * d; + out_grads[41][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[29] = -c1 * d; + out_shs[43] = s1 * d; + d = -20.409946485 * z; + out_grads[29][0] = -c0 * d; + out_grads[43][0] = s0 * d; + out_grads[29][1] = s0 * d; + out_grads[43][1] = c0 * d; + d = 15.969982982 * z; + out_grads[30][2] = c0 * d; + out_grads[42][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[28] = c0 * d; + out_shs[44] = s0 * d; + d = 5.831413281; + out_grads[28][0] = c1 * d; + out_grads[44][0] = s1 * d; + out_grads[28][1] = -s1 * d; + out_grads[44][1] = c1 * d; + d = -2.915706641; + out_grads[29][2] = -c1 * d; + out_grads[43][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; + out_grads[6][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[14][2] = 0.0; + out_grads[15][2] = 0.0; + out_grads[21][0] = 0.0; + out_grads[21][1] = 0.0; + out_grads[27][2] = 0.0; + out_grads[28][2] = 0.0; + out_grads[36][0] = 0.0; + out_grads[36][1] = 0.0; + out_grads[44][2] = 0.0; +} From 2f93d36879df686ebe66b620b5324bb8d63e9e9d Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Mon, 4 Dec 2023 17:25:58 -0500 Subject: [PATCH 022/118] Added difinitions for constants. --- .../SH-ODF experimental/ray_traced_1.py | 80 +++++++++---------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/docs/experimental/SH-ODF experimental/ray_traced_1.py b/docs/experimental/SH-ODF experimental/ray_traced_1.py index 3ea3cd8fe..a2e0adfb0 100644 --- a/docs/experimental/SH-ODF experimental/ray_traced_1.py +++ b/docs/experimental/SH-ODF experimental/ray_traced_1.py @@ -1,5 +1,12 @@ """ -This script includes TEXTURE experimentation for passing SH coefficients +Fury's implementation of "Ray Tracing Spherical Harmonics Glyphs": +https://momentsingraphics.de/VMV2023.html +The fragment shader is based on: https://www.shadertoy.com/view/dlGSDV +(c) 2023, Christoph Peters +This work is licensed under a CC0 1.0 Universal License. To the extent +possible under law, Christoph Peters has waived all copyright and related or +neighboring rights to the following code. This work is published from +Germany. https://creativecommons.org/publicdomain/zero/1.0/ """ import os @@ -46,11 +53,35 @@ shader_to_actor(odf_actor, "vertex", decl_code=vs_dec, impl_code=vs_impl) - fs_defs = """ - #define SH_DEGREE 4 - #define SH_COUNT (((SH_DEGREE + 1) * (SH_DEGREE + 2)) / 2) - #define MAX_DEGREE (2 * SH_DEGREE + 2) - #define NO_INTERSECTION 3.4e38 + # The index of the highest used band of the spherical harmonics basis. Must + # be even, at least 2 and at most 12. + def_sh_degree = "#define SH_DEGREE 4" + + # The number of spherical harmonics basis functions + def_sh_count = "#define SH_COUNT (((SH_DEGREE + 1) * (SH_DEGREE + 2)) / 2)" + + # Degree of polynomials for which we have to find roots + def_max_degree = "#define MAX_DEGREE (2 * SH_DEGREE + 2)" + + # If GL_EXT_control_flow_attributes is available, these defines should be + # defined as [[unroll]] and [[loop]] to give reasonable hints to the + # compiler. That avoids register spilling, which makes execution + # considerably faster. + def_gl_ext_control_flow_attributes = """ + #ifndef _unroll_ + #define _unroll_ + #endif + #ifndef _loop_ + #define _loop_ + #endif + """ + + # When there are fewer intersections/roots than theoretically possible, + # some array entries are set to this value + def_no_intersection = "#define NO_INTERSECTION 3.4e38" + + # pi and its reciprocal + def_pis = """ #define M_PI 3.141592653589793238462643 #define M_INV_PI 0.318309886183790671537767526745 """ @@ -114,39 +145,6 @@ ) new_code = """ - // Supplemental code for "Ray Tracing Spherical Harmonics Glyphs": -// https://momentsingraphics.de/VMV2023.html -// View results of this shader here: https://www.shadertoy.com/view/dlGSDV -// (c) 2023, Christoph Peters -// This work is licensed under a CC0 1.0 Universal License. To the extent -// possible under law, Christoph Peters has waived all copyright and related or -// neighboring rights to the following code. This work is published from -// Germany. https://creativecommons.org/publicdomain/zero/1.0/ - -// The index of the highest used band of the spherical harmonics basis. Must be -// even, at least 2 and at most 12. -#define SH_DEGREE 4 -// The number of spherical harmonics basis functions -#define SH_COUNT (((SH_DEGREE + 1) * (SH_DEGREE + 2)) / 2) -// Degree of polynomials for which we have to find roots -#define MAX_DEGREE (2 * SH_DEGREE + 2) -// If GL_EXT_control_flow_attributes is available, these defines should be -// defined as [[unroll]] and [[loop]] to give reasonable hints to the compiler. -// That avoids register spilling, which makes execution considerably faster. -#ifndef _unroll_ -#define _unroll_ -#endif -#ifndef _loop_ -#define _loop_ -#endif -// When there are fewer intersections/roots than theoretically possible, some -// array entries are set to this value -#define NO_INTERSECTION 3.4e38 -// pi and its reciprocal -#define M_PI 3.141592653589793238462643 -#define M_INV_PI 0.318309886183790671537767526745 - - // Searches a single root of a polynomial within a given interval. // \param out_root The location of the found root. // \param out_end_value The value of the given polynomial at end. @@ -658,7 +656,9 @@ # fmt: off fs_dec = compose_shader([ - fs_defs, fs_unifs, fs_vs_vars, eval_sh_2, eval_sh_4, eval_sh_6, + def_sh_degree, def_sh_count, def_max_degree, + def_gl_ext_control_flow_attributes, def_no_intersection, + def_pis, fs_unifs, fs_vs_vars, eval_sh_2, eval_sh_4, eval_sh_6, eval_sh_8, eval_sh_10, eval_sh_12, eval_sh_grad_2, eval_sh_grad_4, eval_sh_grad_6, eval_sh_grad_8, eval_sh_grad_10, eval_sh_grad_12, new_code From 80f568239de2b5affdf553f9e080ec895dcdf91f Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Tue, 5 Dec 2023 12:53:28 -0500 Subject: [PATCH 023/118] Added first functions of main shaders. --- .../SH-ODF experimental/ray_traced_1.py | 404 +++--------------- fury/shaders/spherical_harmonics/eval_sh.frag | 16 + .../spherical_harmonics/eval_sh_grad.frag | 16 + .../spherical_harmonics/find_roots.frag | 82 ++++ .../get_inv_vandermonde.frag | 58 +++ .../spherical_harmonics/newton_bisection.frag | 47 ++ .../ray_sh_glyph_intersections.frag | 81 ++++ 7 files changed, 363 insertions(+), 341 deletions(-) create mode 100644 fury/shaders/spherical_harmonics/eval_sh.frag create mode 100644 fury/shaders/spherical_harmonics/eval_sh_grad.frag create mode 100644 fury/shaders/spherical_harmonics/find_roots.frag create mode 100644 fury/shaders/spherical_harmonics/get_inv_vandermonde.frag create mode 100644 fury/shaders/spherical_harmonics/newton_bisection.frag create mode 100644 fury/shaders/spherical_harmonics/ray_sh_glyph_intersections.frag diff --git a/docs/experimental/SH-ODF experimental/ray_traced_1.py b/docs/experimental/SH-ODF experimental/ray_traced_1.py index a2e0adfb0..9239ba910 100644 --- a/docs/experimental/SH-ODF experimental/ray_traced_1.py +++ b/docs/experimental/SH-ODF experimental/ray_traced_1.py @@ -144,352 +144,73 @@ os.path.join("spherical_harmonics", "eval_sh_grad_12.frag") ) - new_code = """ -// Searches a single root of a polynomial within a given interval. -// \param out_root The location of the found root. -// \param out_end_value The value of the given polynomial at end. -// \param poly Coefficients of the polynomial for which a root should be found. -// Coefficient poly[i] is multiplied by x^i. -// \param begin The beginning of an interval where the polynomial is monotonic. -// \param end The end of said interval. -// \param begin_value The value of the given polynomial at begin. -// \param error_tolerance The error tolerance for the returned root location. -// Typically the error will be much lower but in theory it can be -// bigger. -// return true if a root was found, false if no root exists. -bool newton_bisection(out float out_root, out float out_end_value, - float poly[MAX_DEGREE + 1], float begin, float end, - float begin_value, float error_tolerance) -{ - if (begin == end) { - out_end_value = begin_value; - return false; - } - // Evaluate the polynomial at the end of the interval - out_end_value = poly[MAX_DEGREE]; - _unroll_ - for (int i = MAX_DEGREE - 1; i != -1; --i) - out_end_value = out_end_value * end + poly[i]; - // If the values at both ends have the same non-zero sign, there is no root - if (begin_value * out_end_value > 0.0) - return false; - // Otherwise, we find the root iteratively using Newton bisection (with - // bounded iteration count) - float current = 0.5 * (begin + end); - _loop_ - for (int i = 0; i != 90; ++i) { - // Evaluate the polynomial and its derivative - float value = poly[MAX_DEGREE] * current + poly[MAX_DEGREE - 1]; - float derivative = poly[MAX_DEGREE]; - _unroll_ - for (int j = MAX_DEGREE - 2; j != -1; --j) { - derivative = derivative * current + value; - value = value * current + poly[j]; - } - // Shorten the interval - bool right = begin_value * value > 0.0; - begin = right ? current : begin; - end = right ? end : current; - // Apply Newton's method - float guess = current - value / derivative; - // Pick a guess - float middle = 0.5 * (begin + end); - float next = (guess >= begin && guess <= end) ? guess : middle; - // Move along or terminate - bool done = abs(next - current) < error_tolerance; - current = next; - if (done) - break; - } - out_root = current; - return true; -} - - -// Finds all roots of the given polynomial in the interval [begin, end] and -// writes them to out_roots. Some entries will be NO_INTERSECTION but other -// than that the array is sorted. The last entry is always NO_INTERSECTION. -void find_roots(out float out_roots[MAX_DEGREE + 1], float poly[MAX_DEGREE + 1], float begin, float end) { - float tolerance = (end - begin) * 1.0e-4; - // Construct the quadratic derivative of the polynomial. We divide each - // derivative by the factorial of its order, such that the constant - // coefficient can be copied directly from poly. That is a safeguard - // against overflow and makes it easier to avoid spilling below. The - // factors happen to be binomial coefficients then. - float derivative[MAX_DEGREE + 1]; - derivative[0] = poly[MAX_DEGREE - 2]; - derivative[1] = float(MAX_DEGREE - 1) * poly[MAX_DEGREE - 1]; - derivative[2] = (0.5 * float((MAX_DEGREE - 1) * MAX_DEGREE)) * poly[MAX_DEGREE - 0]; - _unroll_ - for (int i = 3; i != MAX_DEGREE + 1; ++i) - derivative[i] = 0.0; - // Compute its two roots using the quadratic formula - float discriminant = derivative[1] * derivative[1] - 4.0 * derivative[0] * derivative[2]; - if (discriminant >= 0.0) { - float sqrt_discriminant = sqrt(discriminant); - float scaled_root = derivative[1] + ((derivative[1] > 0.0) ? sqrt_discriminant : (-sqrt_discriminant)); - float root_0 = clamp(-2.0 * derivative[0] / scaled_root, begin, end); - float root_1 = clamp(-0.5 * scaled_root / derivative[2], begin, end); - out_roots[MAX_DEGREE - 2] = min(root_0, root_1); - out_roots[MAX_DEGREE - 1] = max(root_0, root_1); - } - else { - // Indicate that the cubic derivative has a single root - out_roots[MAX_DEGREE - 2] = begin; - out_roots[MAX_DEGREE - 1] = begin; - } - // The last entry in the root array is set to end to make it easier to - // iterate over relevant intervals, all untouched roots are set to begin - out_roots[MAX_DEGREE] = end; - _unroll_ - for (int i = 0; i != MAX_DEGREE - 2; ++i) - out_roots[i] = begin; - // Work your way up to derivatives of higher degree until you reach the - // polynomial itself. This implementation may seem peculiar: It always - // treats the derivative as though it had degree MAX_DEGREE and it - // constructs the derivatives in a contrived way. Changing that would - // reduce the number of arithmetic instructions roughly by a factor of two. - // However, it would also cause register spilling, which has a far more - // negative impact on the overall run time. Profiling indicates that the - // current implementation has no spilling whatsoever. - _loop_ - for (int degree = 3; degree != MAX_DEGREE + 1; ++degree) { - // Take the integral of the previous derivative (scaled such that the - // constant coefficient can still be copied directly from poly) - float prev_derivative_order = float(MAX_DEGREE + 1 - degree); - _unroll_ - for (int i = MAX_DEGREE; i != 0; --i) - derivative[i] = derivative[i - 1] * (prev_derivative_order * (1.0 / float(i))); - // Copy the constant coefficient without causing spilling. This part - // would be harder if the derivative were not scaled the way it is. - _unroll_ - for (int i = 0; i != MAX_DEGREE - 2; ++i) - derivative[0] = (degree == MAX_DEGREE - i) ? poly[i] : derivative[0]; - // Determine the value of this derivative at begin - float begin_value = derivative[MAX_DEGREE]; - _unroll_ - for (int i = MAX_DEGREE - 1; i != -1; --i) - begin_value = begin_value * begin + derivative[i]; - // Iterate over the intervals where roots may be found - _unroll_ - for (int i = 0; i != MAX_DEGREE; ++i) { - if (i < MAX_DEGREE - degree) - continue; - float current_begin = out_roots[i]; - float current_end = out_roots[i + 1]; - // Try to find a root - float root; - if (newton_bisection(root, begin_value, derivative, current_begin, current_end, begin_value, tolerance)) - out_roots[i] = root; - else if (degree < MAX_DEGREE) - // Create an empty interval for the next iteration - out_roots[i] = out_roots[i - 1]; - else - out_roots[i] = NO_INTERSECTION; - } - } - // We no longer need this array entry - out_roots[MAX_DEGREE] = NO_INTERSECTION; -} - - -// Evaluates the spherical harmonics basis in bands 0, 2, ..., SH_DEGREE. -// Conventions are as in the following paper. -// M. Descoteaux, E. Angelino, S. Fitzgibbons, and R. Deriche. Regularized, -// fast, and robust analytical q-ball imaging. Magnetic Resonance in Medicine, -// 58(3), 2007. https://doi.org/10.1002/mrm.21277 -// \param out_shs Values of SH basis functions in bands 0, 2, ..., SH_DEGREE in -// this order. -// \param point The point on the unit sphere where the basis should be -// evaluated. -void eval_sh(out float out_shs[SH_COUNT], vec3 point) { -#if SH_DEGREE == 2 - eval_sh_2(out_shs, point); -#elif SH_DEGREE == 4 - eval_sh_4(out_shs, point); -#elif SH_DEGREE == 6 - eval_sh_6(out_shs, point); -#elif SH_DEGREE == 8 - eval_sh_8(out_shs, point); -#elif SH_DEGREE == 10 - eval_sh_10(out_shs, point); -#elif SH_DEGREE == 12 - eval_sh_12(out_shs, point); -#endif -} - - -// Evaluates the gradient of each basis function given by eval_sh() and the -// basis itself -void eval_sh_grad(out float out_shs[SH_COUNT], out vec3 out_grads[SH_COUNT], vec3 point) { -#if SH_DEGREE == 2 - eval_sh_grad_2(out_shs, out_grads, point); -#elif SH_DEGREE == 4 - eval_sh_grad_4(out_shs, out_grads, point); -#elif SH_DEGREE == 6 - eval_sh_grad_6(out_shs, out_grads, point); -#elif SH_DEGREE == 8 - eval_sh_grad_8(out_shs, out_grads, point); -#elif SH_DEGREE == 10 - eval_sh_grad_10(out_shs, out_grads, point); -#elif SH_DEGREE == 12 - eval_sh_grad_12(out_shs, out_grads, point); -#endif -} + # Searches a single root of a polynomial within a given interval. + # param out_root The location of the found root. + # param out_end_value The value of the given polynomial at end. + # param poly Coefficients of the polynomial for which a root should be + # found. + # Coefficient poly[i] is multiplied by x^i. + # param begin The beginning of an interval where the polynomial is + # monotonic. + # param end The end of said interval. + # param begin_value The value of the given polynomial at begin. + # param error_tolerance The error tolerance for the returned root + # location. + # Typically the error will be much lower but in theory it can be + # bigger. + # + # return true if a root was found, false if no root exists. + newton_bisection = import_fury_shader( + os.path.join("spherical_harmonics", "newton_bisection.frag") + ) + # Finds all roots of the given polynomial in the interval [begin, end] and + # writes them to out_roots. Some entries will be NO_INTERSECTION but other + # than that the array is sorted. The last entry is always NO_INTERSECTION. + find_roots = import_fury_shader( + os.path.join("spherical_harmonics", "find_roots.frag") + ) -// Outputs a matrix that turns equidistant samples on the unit circle of a -// homogeneous polynomial into coefficients of that polynomial. -void get_inv_vandermonde(out float v[(SH_DEGREE + 1) * (SH_DEGREE + 1)]) { -#if SH_DEGREE == 2 - v[0*3 + 0] = -0.3333333333; v[0*3 + 1] = 0.6666666667; v[0*3 + 2] = 0.6666666667; - v[1*3 + 0] = -0.0; v[1*3 + 1] = 1.1547005384; v[1*3 + 2] = -1.1547005384; - v[2*3 + 0] = 1.0; v[2*3 + 1] = 0.0; v[2*3 + 2] = 0.0; -#elif SH_DEGREE == 4 - v[0*5 + 0] = 0.2; v[0*5 + 1] = -0.2472135955; v[0*5 + 2] = 0.6472135955; v[0*5 + 3] = 0.6472135955; v[0*5 + 4] = -0.2472135955; - v[1*5 + 0] = 0.0; v[1*5 + 1] = -0.1796111906; v[1*5 + 2] = 1.9919186279; v[1*5 + 3] = -1.9919186279; v[1*5 + 4] = 0.1796111906; - v[2*5 + 0] = -2.0; v[2*5 + 1] = 2.3416407865; v[2*5 + 2] = -0.3416407865; v[2*5 + 3] = -0.3416407865; v[2*5 + 4] = 2.3416407865; - v[3*5 + 0] = -0.0; v[3*5 + 1] = 1.7013016167; v[3*5 + 2] = -1.0514622242; v[3*5 + 3] = 1.0514622242; v[3*5 + 4] = -1.7013016167; - v[4*5 + 0] = 1.0; v[4*5 + 1] = 0.0; v[4*5 + 2] = 0.0; v[4*5 + 3] = 0.0; v[4*5 + 4] = 0.0; -#elif SH_DEGREE == 6 - v[0*7 + 0] = -0.1428571429; v[0*7 + 1] = 0.1585594663; v[0*7 + 2] = -0.2291250674; v[0*7 + 3] = 0.6419941725; v[0*7 + 4] = 0.6419941725; v[0*7 + 5] = -0.2291250674; v[0*7 + 6] = 0.1585594663; - v[1*7 + 0] = -0.0; v[1*7 + 1] = 0.0763582145; v[1*7 + 2] = -0.2873137468; v[1*7 + 3] = 2.8127602518; v[1*7 + 4] = -2.8127602518; v[1*7 + 5] = 0.2873137468; v[1*7 + 6] = -0.0763582145; - v[2*7 + 0] = 3.0; v[2*7 + 1] = -3.2929766145; v[2*7 + 2] = 4.4513463718; v[2*7 + 3] = -1.1583697574; v[2*7 + 4] = -1.1583697574; v[2*7 + 5] = 4.4513463718; v[2*7 + 6] = -3.2929766145; - v[3*7 + 0] = 0.0; v[3*7 + 1] = -1.5858139579; v[3*7 + 2] = 5.5818117995; v[3*7 + 3] = -5.0751495106; v[3*7 + 4] = 5.0751495106; v[3*7 + 5] = -5.5818117995; v[3*7 + 6] = 1.5858139579; - v[4*7 + 0] = -5.0; v[4*7 + 1] = 4.7858935686; v[4*7 + 2] = -1.0200067492; v[4*7 + 3] = 0.2341131806; v[4*7 + 4] = 0.2341131806; v[4*7 + 5] = -1.0200067492; v[4*7 + 6] = 4.7858935686; - v[5*7 + 0] = -0.0; v[5*7 + 1] = 2.3047648710; v[5*7 + 2] = -1.2790480077; v[5*7 + 3] = 1.0257168633; v[5*7 + 4] = -1.0257168633; v[5*7 + 5] = 1.2790480077; v[5*7 + 6] = -2.3047648710; - v[6*7 + 0] = 1.0; v[6*7 + 1] = 0.0; v[6*7 + 2] = 0.0; v[6*7 + 3] = 0.0; v[6*7 + 4] = 0.0; v[6*7 + 5] = 0.0; v[6*7 + 6] = 0.0; -#elif SH_DEGREE == 8 - v[0*9 + 0] = 0.1111111111; v[0*9 + 1] = -0.1182419747; v[0*9 + 2] = 0.1450452544; v[0*9 + 3] = -0.2222222222; v[0*9 + 4] = 0.6398633870; v[0*9 + 5] = 0.6398633870; v[0*9 + 6] = -0.2222222222; v[0*9 + 7] = 0.1450452544; v[0*9 + 8] = -0.1182419747; - v[1*9 + 0] = 0.0; v[1*9 + 1] = -0.0430365592; v[1*9 + 2] = 0.1217074194; v[1*9 + 3] = -0.3849001795; v[1*9 + 4] = 3.6288455938; v[1*9 + 5] = -3.6288455938; v[1*9 + 6] = 0.3849001795; v[1*9 + 7] = -0.1217074194; v[1*9 + 8] = 0.0430365592; - v[2*9 + 0] = -4.0; v[2*9 + 1] = 4.2410470634; v[2*9 + 2] = -5.1195045066; v[2*9 + 3] = 7.3333333333; v[2*9 + 4] = -2.4548758901; v[2*9 + 5] = -2.4548758901; v[2*9 + 6] = 7.3333333333; v[2*9 + 7] = -5.1195045066; v[2*9 + 8] = 4.2410470634; - v[3*9 + 0] = -0.0; v[3*9 + 1] = 1.5436148932; v[3*9 + 2] = -4.2957743433; v[3*9 + 3] = 12.7017059222; v[3*9 + 4] = -13.9222930051; v[3*9 + 5] = 13.9222930051; v[3*9 + 6] = -12.7017059222; v[3*9 + 7] = 4.2957743433; v[3*9 + 8] = -1.5436148932; - v[4*9 + 0] = 14.0; v[4*9 + 1] = -14.3366589404; v[4*9 + 2] = 14.6711193836; v[4*9 + 3] = -6.0; v[4*9 + 4] = 1.6655395568; v[4*9 + 5] = 1.6655395568; v[4*9 + 6] = -6.0; v[4*9 + 7] = 14.6711193836; v[4*9 + 8] = -14.3366589404; - v[5*9 + 0] = 0.0; v[5*9 + 1] = -5.2181171131; v[5*9 + 2] = 12.3105308637; v[5*9 + 3] = -10.3923048454; v[5*9 + 4] = 9.4457442082; v[5*9 + 5] = -9.4457442082; v[5*9 + 6] = 10.3923048454; v[5*9 + 7] = -12.3105308637; v[5*9 + 8] = 5.2181171131; - v[6*9 + 0] = -9.3333333333; v[6*9 + 1] = 8.0330865684; v[6*9 + 2] = -1.8540394597; v[6*9 + 3] = 0.6666666667; v[6*9 + 4] = -0.1790471086; v[6*9 + 5] = -0.1790471086; v[6*9 + 6] = 0.6666666667; v[6*9 + 7] = -1.8540394597; v[6*9 + 8] = 8.0330865684; - v[7*9 + 0] = -0.0; v[7*9 + 1] = 2.9238044002; v[7*9 + 2] = -1.5557238269; v[7*9 + 3] = 1.1547005384; v[7*9 + 4] = -1.0154266119; v[7*9 + 5] = 1.0154266119; v[7*9 + 6] = -1.1547005384; v[7*9 + 7] = 1.5557238269; v[7*9 + 8] = -2.9238044002; - v[8*9 + 0] = 1.0; v[8*9 + 1] = 0.0; v[8*9 + 2] = 0.0; v[8*9 + 3] = 0.0; v[8*9 + 4] = 0.0; v[8*9 + 5] = 0.0; v[8*9 + 6] = 0.0; v[8*9 + 7] = 0.0; v[8*9 + 8] = 0.0; -#elif SH_DEGREE == 10 - v[0*11 + 0] = -0.0909090909; v[0*11 + 1] = 0.0947470106; v[0*11 + 2] = -0.1080638444; v[0*11 + 3] = 0.1388220215; v[0*11 + 4] = -0.2188392043; v[0*11 + 5] = 0.6387885621; v[0*11 + 6] = 0.6387885621; v[0*11 + 7] = -0.2188392043; v[0*11 + 8] = 0.1388220215; v[0*11 + 9] = -0.1080638444; v[0*11 + 10] = 0.0947470106; - v[1*11 + 0] = -0.0; v[1*11 + 1] = 0.0278202324; v[1*11 + 2] = -0.0694484159; v[1*11 + 3] = 0.1602091533; v[1*11 + 4] = -0.4791910159; v[1*11 + 5] = 4.4428720384; v[1*11 + 6] = -4.4428720384; v[1*11 + 7] = 0.4791910159; v[1*11 + 8] = -0.1602091533; v[1*11 + 9] = 0.0694484159; v[1*11 + 10] = -0.0278202324; - v[2*11 + 0] = 5.0; v[2*11 + 1] = -5.2029168239; v[2*11 + 2] = 5.8988796576; v[2*11 + 3] = -7.4503199653; v[2*11 + 4] = 10.9868742757; v[2*11 + 5] = -4.2325171441; v[2*11 + 6] = -4.2325171441; v[2*11 + 7] = 10.9868742757; v[2*11 + 8] = -7.4503199653; v[2*11 + 9] = 5.8988796576; v[2*11 + 10] = -5.2029168239; - v[3*11 + 0] = 0.0; v[3*11 + 1] = -1.5277142200; v[3*11 + 2] = 3.7909797649; v[3*11 + 3] = -8.5981275876; v[3*11 + 4] = 24.0578988657; v[3*11 + 5] = -29.4378033460; v[3*11 + 6] = 29.4378033460; v[3*11 + 7] = -24.0578988657; v[3*11 + 8] = 8.5981275876; v[3*11 + 9] = -3.7909797649; v[3*11 + 10] = 1.5277142200; - v[4*11 + 0] = -30.0; v[4*11 + 1] = 30.8179361182; v[4*11 + 2] = -33.2247539061; v[4*11 + 3] = 35.8884989085; v[4*11 + 4] = -19.5374870834; v[4*11 + 5] = 6.0558059629; v[4*11 + 6] = 6.0558059629; v[4*11 + 7] = -19.5374870834; v[4*11 + 8] = 35.8884989085; v[4*11 + 9] = -33.2247539061; v[4*11 + 10] = 30.8179361182; - v[5*11 + 0] = -0.0; v[5*11 + 1] = 9.0489625020; v[5*11 + 2] = -21.3522528115; v[5*11 + 3] = 41.4175356200; v[5*11 + 4] = -42.7811292411; v[5*11 + 5] = 42.1190556280; v[5*11 + 6] = -42.1190556280; v[5*11 + 7] = 42.7811292411; v[5*11 + 8] = -41.4175356200; v[5*11 + 9] = 21.3522528115; v[5*11 + 10] = -9.0489625020; - v[6*11 + 0] = 42.0; v[6*11 + 1] = -41.1161037573; v[6*11 + 2] = 36.2032364762; v[6*11 + 3] = -16.3373898141; v[6*11 + 4] = 7.4261062994; v[6*11 + 5] = -2.1758492042; v[6*11 + 6] = -2.1758492042; v[6*11 + 7] = 7.4261062994; v[6*11 + 8] = -16.3373898141; v[6*11 + 9] = 36.2032364762; v[6*11 + 10] = -41.1161037573; - v[7*11 + 0] = 0.0; v[7*11 + 1] = -12.0727773496; v[7*11 + 2] = 23.2664073304; v[7*11 + 3] = -18.8543529304; v[7*11 + 4] = 16.2609045881; v[7*11 + 5] = -15.1333636234; v[7*11 + 6] = 15.1333636234; v[7*11 + 7] = -16.2609045881; v[7*11 + 8] = 18.8543529304; v[7*11 + 9] = -23.2664073304; v[7*11 + 10] = 12.0727773496; - v[8*11 + 0] = -15.0; v[8*11 + 1] = 12.0883694702; v[8*11 + 2] = -2.8781222629; v[8*11 + 3] = 1.1465503415; v[8*11 + 4] = -0.5020543475; v[8*11 + 5] = 0.1452567988; v[8*11 + 6] = 0.1452567988; v[8*11 + 7] = -0.5020543475; v[8*11 + 8] = 1.1465503415; v[8*11 + 9] = -2.8781222629; v[8*11 + 10] = 12.0883694702; - v[9*11 + 0] = -0.0; v[9*11 + 1] = 3.5494655329; v[9*11 + 2] = -1.8496568659; v[9*11 + 3] = 1.3231896304; v[9*11 + 4] = -1.0993456751; v[9*11 + 5] = 1.0102832265; v[9*11 + 6] = -1.0102832265; v[9*11 + 7] = 1.0993456751; v[9*11 + 8] = -1.3231896304; v[9*11 + 9] = 1.8496568659; v[9*11 + 10] = -3.5494655329; - v[10*11 + 0] = 1.0; v[10*11 + 1] = 0.0; v[10*11 + 2] = 0.0; v[10*11 + 3] = 0.0; v[10*11 + 4] = 0.0; v[10*11 + 5] = 0.0; v[10*11 + 6] = 0.0; v[10*11 + 7] = 0.0; v[10*11 + 8] = 0.0; v[10*11 + 9] = 0.0; v[10*11 + 10] = 0.0; -#elif SH_DEGREE == 12 - v[0*13 + 0] = 0.0769230769; v[0*13 + 1] = -0.0792252178; v[0*13 + 2] = 0.0868739663; v[0*13 + 3] = -0.1027681661; v[0*13 + 4] = 0.1354125166; v[0*13 + 5] = -0.2169261613; v[0*13 + 6] = 0.6381715239; v[0*13 + 7] = 0.6381715239; v[0*13 + 8] = -0.2169261613; v[0*13 + 9] = 0.1354125166; v[0*13 + 10] = -0.1027681661; v[0*13 + 11] = 0.0868739663; v[0*13 + 12] = -0.0792252178; - v[1*13 + 0] = -0.0; v[1*13 + 1] = -0.0195272624; v[1*13 + 2] = 0.0455949748; v[1*13 + 3] = -0.0910446506; v[1*13 + 4] = 0.1961788986; v[1*13 + 5] = -0.5719872785; v[1*13 + 6] = 5.2558153553; v[1*13 + 7] = -5.2558153553; v[1*13 + 8] = 0.5719872785; v[1*13 + 9] = -0.1961788986; v[1*13 + 10] = 0.0910446506; v[1*13 + 11] = -0.0455949748; v[1*13 + 12] = 0.0195272624; - v[2*13 + 0] = -6.0; v[2*13 + 1] = 6.1747539478; v[2*13 + 2] = -6.7522392818; v[2*13 + 3] = 7.9352584366; v[2*13 + 4] = -10.2779620900; v[2*13 + 5] = 15.4120340799; v[2*13 + 6] = -6.4918450925; v[2*13 + 7] = -6.4918450925; v[2*13 + 8] = 15.4120340799; v[2*13 + 9] = -10.2779620900; v[2*13 + 10] = 7.9352584366; v[2*13 + 11] = -6.7522392818; v[2*13 + 12] = 6.1747539478; - v[3*13 + 0] = -0.0; v[3*13 + 1] = 1.5219401578; v[3*13 + 2] = -3.5438485554; v[3*13 + 3] = 7.0300255289; v[3*13 + 4] = -14.8901987371; v[3*13 + 5] = 40.6381940129; v[3*13 + 6] = -53.4651544987; v[3*13 + 7] = 53.4651544987; v[3*13 + 8] = -40.6381940129; v[3*13 + 9] = 14.8901987371; v[3*13 + 10] = -7.0300255289; v[3*13 + 11] = 3.5438485554; v[3*13 + 12] = -1.5219401578; - v[4*13 + 0] = 55.0; v[4*13 + 1] = -56.2709061445; v[4*13 + 2] = 60.2549306937; v[4*13 + 3] = -67.2511796347; v[4*13 + 4] = 75.2477722397; v[4*13 + 5] = -47.9480941911; v[4*13 + 6] = 15.9674770369; v[4*13 + 7] = 15.9674770369; v[4*13 + 8] = -47.9480941911; v[4*13 + 9] = 75.2477722397; v[4*13 + 10] = -67.2511796347; v[4*13 + 11] = 60.2549306937; v[4*13 + 12] = -56.2709061445; - v[5*13 + 0] = 0.0; v[5*13 + 1] = -13.8695326974; v[5*13 + 2] = 31.6242271914; v[5*13 + 3] = -59.5793462127; v[5*13 + 4] = 109.0152185187; v[5*13 + 5] = -126.4287338180; v[5*13 + 6] = 131.5040045727; v[5*13 + 7] = -131.5040045727; v[5*13 + 8] = 126.4287338180; v[5*13 + 9] = -109.0152185187; v[5*13 + 10] = 59.5793462127; v[5*13 + 11] = -31.6242271914; v[5*13 + 12] = 13.8695326974; - v[6*13 + 0] = -132.0; v[6*13 + 1] = 132.5319409049; v[6*13 + 2] = -132.4780513404; v[6*13 + 3] = 123.5674782081; v[6*13 + 4] = -74.4320682907; v[6*13 + 5] = 38.8801193717; v[6*13 + 6] = -12.0694188537; v[6*13 + 7] = -12.0694188537; v[6*13 + 8] = 38.8801193717; v[6*13 + 9] = -74.4320682907; v[6*13 + 10] = 123.5674782081; v[6*13 + 11] = -132.4780513404; v[6*13 + 12] = 132.5319409049; - v[7*13 + 0] = -0.0; v[7*13 + 1] = 32.6661895777; v[7*13 + 2] = -69.5298450306; v[7*13 + 3] = 109.4712331409; v[7*13 + 4] = -107.8334673306; v[7*13 + 5] = 102.5184492897; v[7*13 + 6] = -99.4006071501; v[7*13 + 7] = 99.4006071501; v[7*13 + 8] = -102.5184492897; v[7*13 + 9] = 107.8334673306; v[7*13 + 10] = -109.4712331409; v[7*13 + 11] = 69.5298450306; v[7*13 + 12] = -32.6661895777; - v[8*13 + 0] = 99.0; v[8*13 + 1] = -93.9113626635; v[8*13 + 2] = 75.3147168618; v[8*13 + 3] = -35.2795800772; v[8*13 + 4] = 18.0521608541; v[8*13 + 5] = -8.8650350126; v[8*13 + 6] = 2.6891000373; v[8*13 + 7] = 2.6891000373; v[8*13 + 8] = -8.8650350126; v[8*13 + 9] = 18.0521608541; v[8*13 + 10] = -35.2795800772; v[8*13 + 11] = 75.3147168618; v[8*13 + 12] = -93.9113626635; - v[9*13 + 0] = 0.0; v[9*13 + 1] = -23.1470719837; v[9*13 + 2] = 39.5282127035; v[9*13 + 3] = -31.2549806126; v[9*13 + 4] = 26.1530700733; v[9*13 + 5] = -23.3751762359; v[9*13 + 6] = 22.1467313083; v[9*13 + 7] = -22.1467313083; v[9*13 + 8] = 23.3751762359; v[9*13 + 9] = -26.1530700733; v[9*13 + 10] = 31.2549806126; v[9*13 + 11] = -39.5282127035; v[9*13 + 12] = 23.1470719837; - v[10*13 + 0] = -22.0; v[10*13 + 1] = 16.9531714429; v[10*13 + 2] = -4.0999479387; v[10*13 + 3] = 1.7021989010; v[10*13 + 4] = -0.8387165175; v[10*13 + 5] = 0.4056079008; v[10*13 + 6] = -0.1223137885; v[10*13 + 7] = -0.1223137885; v[10*13 + 8] = 0.4056079008; v[10*13 + 9] = -0.8387165175; v[10*13 + 10] = 1.7021989010; v[10*13 + 11] = -4.0999479387; v[10*13 + 12] = 16.9531714429; - v[11*13 + 0] = -0.0; v[11*13 + 1] = 4.1785814689; v[11*13 + 2] = -2.1518186743; v[11*13 + 3] = 1.5080166355; v[11*13 + 4] = -1.2150906493; v[11*13 + 5] = 1.0695001374; v[11*13 + 6] = -1.0073446769; v[11*13 + 7] = 1.0073446769; v[11*13 + 8] = -1.0695001374; v[11*13 + 9] = 1.2150906493; v[11*13 + 10] = -1.5080166355; v[11*13 + 11] = 2.1518186743; v[11*13 + 12] = -4.1785814689; - v[12*13 + 0] = 1.0; v[12*13 + 1] = 0.0; v[12*13 + 2] = 0.0; v[12*13 + 3] = 0.0; v[12*13 + 4] = 0.0; v[12*13 + 5] = 0.0; v[12*13 + 6] = 0.0; v[12*13 + 7] = 0.0; v[12*13 + 8] = 0.0; v[12*13 + 9] = 0.0; v[12*13 + 10] = 0.0; v[12*13 + 11] = 0.0; v[12*13 + 12] = 0.0; -#endif -} + # Evaluates the spherical harmonics basis in bands 0, 2, ..., SH_DEGREE. + # Conventions are as in the following paper. + # M. Descoteaux, E. Angelino, S. Fitzgibbons, and R. Deriche. Regularized, + # fast, and robust analytical q-ball imaging. Magnetic Resonance in + # Medicine, 58(3), 2007. https://doi.org/10.1002/mrm.21277 + # param out_shs Values of SH basis functions in bands 0, 2, ..., + # SH_DEGREE in this order. + # param point The point on the unit sphere where the basis should be + # evaluated. + eval_sh = import_fury_shader( + os.path.join("spherical_harmonics", "eval_sh.frag") + ) + # Evaluates the gradient of each basis function given by eval_sh() and the + # basis itself + eval_sh_grad = import_fury_shader( + os.path.join("spherical_harmonics", "eval_sh_grad.frag") + ) -// Determines all intersections between a ray and a spherical harmonics glyph. -// \param out_ray_params The ray parameters at intersection points. The points -// themselves are at ray_origin + out_ray_params[i] * ray_dir. Some -// entries may be NO_INTERSECTION but other than that the array is -// sorted. -// \param sh_coeffs SH_COUNT spherical harmonic coefficients defining the -// glyph. Their exact meaning is defined by eval_sh(). -// \param ray_origin The origin of the ray, relative to the glyph center. -// \param ray_dir The normalized direction vector of the ray. -void ray_sh_glyph_intersections(out float out_ray_params[MAX_DEGREE], float sh_coeffs[SH_COUNT], vec3 ray_origin, vec3 ray_dir) { - // Determine the direction from the glyph center to the closest point on - // the ray - float dir_dot_origin = dot(ray_dir, ray_origin); - vec3 closest_dir = normalize(ray_origin - dir_dot_origin * ray_dir); - // Evaluate the SH polynomial at SH_DEGREE + 1 points. That is enough to - // know its value everywhere along the ray. - float sh_values[SH_DEGREE + 1]; - _unroll_ - for (int i = 0; i != SH_DEGREE + 1; ++i) { - vec3 point = cos(float(i) * (M_PI / float(SH_DEGREE + 1))) * ray_dir - + sin(float(i) * (M_PI / float(SH_DEGREE + 1))) * closest_dir; - float shs[SH_COUNT]; - eval_sh(shs, point); - sh_values[i] = 0.0; - _unroll_ - for (int j = 0; j != SH_COUNT; ++j) - sh_values[i] += sh_coeffs[j] * shs[j]; - } - // Compute coefficients of the SH polynomial along the ray in the - // coordinate frame given by ray_dir and closest_dir - float radius_poly[SH_DEGREE + 1]; - float inv_vander[(SH_DEGREE + 1) * (SH_DEGREE + 1)]; - get_inv_vandermonde(inv_vander); - _unroll_ - for (int i = 0; i != SH_DEGREE + 1; ++i) { - radius_poly[i] = 0.0; - _unroll_ - for (int j = 0; j != SH_DEGREE + 1; ++j) - radius_poly[i] += inv_vander[i * (SH_DEGREE + 1) + j] * sh_values[j]; - } - // Compute a bounding circle around the glyph in the relevant plane - float radius_max = 0.0; - _unroll_ - for (int i = 0; i != SH_DEGREE + 1; ++i) { - float bound = sqrt(pow(float(i), float(i)) * pow(float(SH_DEGREE - i), float(SH_DEGREE - i)) / pow(float(SH_DEGREE), float(SH_DEGREE))); - // Workaround for buggy compilers where 0^0 is 0 - bound = (i == 0 || i == SH_DEGREE) ? 1.0 : bound; - radius_max += bound * abs(radius_poly[i]); - } - // Figure out the interval, where (if at all) the ray intersects the circle - float closest_dot_origin = dot(closest_dir, ray_origin); - if (radius_max < abs(closest_dot_origin)) { - _unroll_ - for (int i = 0; i != MAX_DEGREE; ++i) - out_ray_params[i] = NO_INTERSECTION; - return; - } - float radius_over_dot = radius_max / closest_dot_origin; - float u_max = sqrt(radius_over_dot * radius_over_dot - 1.0); - // Take the square of radius_poly - float poly[MAX_DEGREE + 1]; - _unroll_ - for (int i = 0; i != MAX_DEGREE + 1; ++i) - poly[i] = 0.0; - _unroll_ - for (int i = 0; i != SH_DEGREE + 1; ++i) - _unroll_ - for (int j = 0; j != SH_DEGREE + 1; ++j) - poly[i + j] += radius_poly[i] * radius_poly[j]; - // Subtract the scaled (2 * SH_DEGREE + 2)-th power of the distance to the - // glyph center - float dot_sq = closest_dot_origin * closest_dot_origin; - float binomial = 1.0; - _unroll_ - for (int i = 0; i != SH_DEGREE + 2; ++i) { - poly[2 * i] -= binomial * dot_sq; - // Update the binomial coefficient using a recurrence relation - binomial *= float(SH_DEGREE + 1 - i) / float(i + 1); - } - // Find roots of the polynomial within the relevant bounds - float roots[MAX_DEGREE + 1]; - find_roots(roots, poly, -u_max, u_max); - // Convert them back to the original coordinate frame (i.e. ray parameters) - _unroll_ - for (int i = 0; i != MAX_DEGREE; ++i) - out_ray_params[i] = (roots[i] != NO_INTERSECTION) - ? (roots[i] * closest_dot_origin - dir_dot_origin) - : NO_INTERSECTION; -} + # Outputs a matrix that turns equidistant samples on the unit circle of a + # homogeneous polynomial into coefficients of that polynomial. + get_inv_vandermonde = import_fury_shader( + os.path.join("spherical_harmonics", "get_inv_vandermonde.frag") + ) + # Determines all intersections between a ray and a spherical harmonics + # glyph. + # param out_ray_params The ray parameters at intersection points. The + # points themselves are at ray_origin + out_ray_params[i] * ray_dir. + # Some entries may be NO_INTERSECTION but other than that the array + # is sorted. + # param sh_coeffs SH_COUNT spherical harmonic coefficients defining the + # glyph. Their exact meaning is defined by eval_sh(). + # param ray_origin The origin of the ray, relative to the glyph center. + # param ray_dir The normalized direction vector of the ray. + ray_sh_glyph_intersections = import_fury_shader( + os.path.join("spherical_harmonics", "ray_sh_glyph_intersections.frag") + ) + new_code = """ // Provides a normalized normal vector for a spherical harmonics glyph. // \param sh_coeffs SH_COUNT spherical harmonic coefficients defining the // glyph. Their exact meaning is defined by eval_sh(). @@ -661,7 +382,8 @@ def_pis, fs_unifs, fs_vs_vars, eval_sh_2, eval_sh_4, eval_sh_6, eval_sh_8, eval_sh_10, eval_sh_12, eval_sh_grad_2, eval_sh_grad_4, eval_sh_grad_6, eval_sh_grad_8, eval_sh_grad_10, eval_sh_grad_12, - new_code + newton_bisection, find_roots, eval_sh, eval_sh_grad, + get_inv_vandermonde, ray_sh_glyph_intersections, new_code ]) # fmt: on diff --git a/fury/shaders/spherical_harmonics/eval_sh.frag b/fury/shaders/spherical_harmonics/eval_sh.frag new file mode 100644 index 000000000..e3810af25 --- /dev/null +++ b/fury/shaders/spherical_harmonics/eval_sh.frag @@ -0,0 +1,16 @@ +void eval_sh(out float out_shs[SH_COUNT], vec3 point) +{ + #if SH_DEGREE == 2 + eval_sh_2(out_shs, point); + #elif SH_DEGREE == 4 + eval_sh_4(out_shs, point); + #elif SH_DEGREE == 6 + eval_sh_6(out_shs, point); + #elif SH_DEGREE == 8 + eval_sh_8(out_shs, point); + #elif SH_DEGREE == 10 + eval_sh_10(out_shs, point); + #elif SH_DEGREE == 12 + eval_sh_12(out_shs, point); + #endif +} diff --git a/fury/shaders/spherical_harmonics/eval_sh_grad.frag b/fury/shaders/spherical_harmonics/eval_sh_grad.frag new file mode 100644 index 000000000..c318dbd6c --- /dev/null +++ b/fury/shaders/spherical_harmonics/eval_sh_grad.frag @@ -0,0 +1,16 @@ +void eval_sh_grad(out float out_shs[SH_COUNT], out vec3 out_grads[SH_COUNT], vec3 point) +{ + #if SH_DEGREE == 2 + eval_sh_grad_2(out_shs, out_grads, point); + #elif SH_DEGREE == 4 + eval_sh_grad_4(out_shs, out_grads, point); + #elif SH_DEGREE == 6 + eval_sh_grad_6(out_shs, out_grads, point); + #elif SH_DEGREE == 8 + eval_sh_grad_8(out_shs, out_grads, point); + #elif SH_DEGREE == 10 + eval_sh_grad_10(out_shs, out_grads, point); + #elif SH_DEGREE == 12 + eval_sh_grad_12(out_shs, out_grads, point); + #endif +} diff --git a/fury/shaders/spherical_harmonics/find_roots.frag b/fury/shaders/spherical_harmonics/find_roots.frag new file mode 100644 index 000000000..e5b80f7a4 --- /dev/null +++ b/fury/shaders/spherical_harmonics/find_roots.frag @@ -0,0 +1,82 @@ +void find_roots(out float out_roots[MAX_DEGREE + 1], float poly[MAX_DEGREE + 1], float begin, float end) { + float tolerance = (end - begin) * 1.0e-4; + // Construct the quadratic derivative of the polynomial. We divide each + // derivative by the factorial of its order, such that the constant + // coefficient can be copied directly from poly. That is a safeguard + // against overflow and makes it easier to avoid spilling below. The + // factors happen to be binomial coefficients then. + float derivative[MAX_DEGREE + 1]; + derivative[0] = poly[MAX_DEGREE - 2]; + derivative[1] = float(MAX_DEGREE - 1) * poly[MAX_DEGREE - 1]; + derivative[2] = (0.5 * float((MAX_DEGREE - 1) * MAX_DEGREE)) * poly[MAX_DEGREE - 0]; + _unroll_ + for (int i = 3; i != MAX_DEGREE + 1; ++i) + derivative[i] = 0.0; + // Compute its two roots using the quadratic formula + float discriminant = derivative[1] * derivative[1] - 4.0 * derivative[0] * derivative[2]; + if (discriminant >= 0.0) { + float sqrt_discriminant = sqrt(discriminant); + float scaled_root = derivative[1] + ((derivative[1] > 0.0) ? sqrt_discriminant : (-sqrt_discriminant)); + float root_0 = clamp(-2.0 * derivative[0] / scaled_root, begin, end); + float root_1 = clamp(-0.5 * scaled_root / derivative[2], begin, end); + out_roots[MAX_DEGREE - 2] = min(root_0, root_1); + out_roots[MAX_DEGREE - 1] = max(root_0, root_1); + } + else { + // Indicate that the cubic derivative has a single root + out_roots[MAX_DEGREE - 2] = begin; + out_roots[MAX_DEGREE - 1] = begin; + } + // The last entry in the root array is set to end to make it easier to + // iterate over relevant intervals, all untouched roots are set to begin + out_roots[MAX_DEGREE] = end; + _unroll_ + for (int i = 0; i != MAX_DEGREE - 2; ++i) + out_roots[i] = begin; + // Work your way up to derivatives of higher degree until you reach the + // polynomial itself. This implementation may seem peculiar: It always + // treats the derivative as though it had degree MAX_DEGREE and it + // constructs the derivatives in a contrived way. Changing that would + // reduce the number of arithmetic instructions roughly by a factor of two. + // However, it would also cause register spilling, which has a far more + // negative impact on the overall run time. Profiling indicates that the + // current implementation has no spilling whatsoever. + _loop_ + for (int degree = 3; degree != MAX_DEGREE + 1; ++degree) { + // Take the integral of the previous derivative (scaled such that the + // constant coefficient can still be copied directly from poly) + float prev_derivative_order = float(MAX_DEGREE + 1 - degree); + _unroll_ + for (int i = MAX_DEGREE; i != 0; --i) + derivative[i] = derivative[i - 1] * (prev_derivative_order * (1.0 / float(i))); + // Copy the constant coefficient without causing spilling. This part + // would be harder if the derivative were not scaled the way it is. + _unroll_ + for (int i = 0; i != MAX_DEGREE - 2; ++i) + derivative[0] = (degree == MAX_DEGREE - i) ? poly[i] : derivative[0]; + // Determine the value of this derivative at begin + float begin_value = derivative[MAX_DEGREE]; + _unroll_ + for (int i = MAX_DEGREE - 1; i != -1; --i) + begin_value = begin_value * begin + derivative[i]; + // Iterate over the intervals where roots may be found + _unroll_ + for (int i = 0; i != MAX_DEGREE; ++i) { + if (i < MAX_DEGREE - degree) + continue; + float current_begin = out_roots[i]; + float current_end = out_roots[i + 1]; + // Try to find a root + float root; + if (newton_bisection(root, begin_value, derivative, current_begin, current_end, begin_value, tolerance)) + out_roots[i] = root; + else if (degree < MAX_DEGREE) + // Create an empty interval for the next iteration + out_roots[i] = out_roots[i - 1]; + else + out_roots[i] = NO_INTERSECTION; + } + } + // We no longer need this array entry + out_roots[MAX_DEGREE] = NO_INTERSECTION; +} diff --git a/fury/shaders/spherical_harmonics/get_inv_vandermonde.frag b/fury/shaders/spherical_harmonics/get_inv_vandermonde.frag new file mode 100644 index 000000000..4c7f521c0 --- /dev/null +++ b/fury/shaders/spherical_harmonics/get_inv_vandermonde.frag @@ -0,0 +1,58 @@ +void get_inv_vandermonde(out float v[(SH_DEGREE + 1) * (SH_DEGREE + 1)]) +{ + #if SH_DEGREE == 2 + v[0*3 + 0] = -0.3333333333; v[0*3 + 1] = 0.6666666667; v[0*3 + 2] = 0.6666666667; + v[1*3 + 0] = -0.0; v[1*3 + 1] = 1.1547005384; v[1*3 + 2] = -1.1547005384; + v[2*3 + 0] = 1.0; v[2*3 + 1] = 0.0; v[2*3 + 2] = 0.0; + #elif SH_DEGREE == 4 + v[0*5 + 0] = 0.2; v[0*5 + 1] = -0.2472135955; v[0*5 + 2] = 0.6472135955; v[0*5 + 3] = 0.6472135955; v[0*5 + 4] = -0.2472135955; + v[1*5 + 0] = 0.0; v[1*5 + 1] = -0.1796111906; v[1*5 + 2] = 1.9919186279; v[1*5 + 3] = -1.9919186279; v[1*5 + 4] = 0.1796111906; + v[2*5 + 0] = -2.0; v[2*5 + 1] = 2.3416407865; v[2*5 + 2] = -0.3416407865; v[2*5 + 3] = -0.3416407865; v[2*5 + 4] = 2.3416407865; + v[3*5 + 0] = -0.0; v[3*5 + 1] = 1.7013016167; v[3*5 + 2] = -1.0514622242; v[3*5 + 3] = 1.0514622242; v[3*5 + 4] = -1.7013016167; + v[4*5 + 0] = 1.0; v[4*5 + 1] = 0.0; v[4*5 + 2] = 0.0; v[4*5 + 3] = 0.0; v[4*5 + 4] = 0.0; + #elif SH_DEGREE == 6 + v[0*7 + 0] = -0.1428571429; v[0*7 + 1] = 0.1585594663; v[0*7 + 2] = -0.2291250674; v[0*7 + 3] = 0.6419941725; v[0*7 + 4] = 0.6419941725; v[0*7 + 5] = -0.2291250674; v[0*7 + 6] = 0.1585594663; + v[1*7 + 0] = -0.0; v[1*7 + 1] = 0.0763582145; v[1*7 + 2] = -0.2873137468; v[1*7 + 3] = 2.8127602518; v[1*7 + 4] = -2.8127602518; v[1*7 + 5] = 0.2873137468; v[1*7 + 6] = -0.0763582145; + v[2*7 + 0] = 3.0; v[2*7 + 1] = -3.2929766145; v[2*7 + 2] = 4.4513463718; v[2*7 + 3] = -1.1583697574; v[2*7 + 4] = -1.1583697574; v[2*7 + 5] = 4.4513463718; v[2*7 + 6] = -3.2929766145; + v[3*7 + 0] = 0.0; v[3*7 + 1] = -1.5858139579; v[3*7 + 2] = 5.5818117995; v[3*7 + 3] = -5.0751495106; v[3*7 + 4] = 5.0751495106; v[3*7 + 5] = -5.5818117995; v[3*7 + 6] = 1.5858139579; + v[4*7 + 0] = -5.0; v[4*7 + 1] = 4.7858935686; v[4*7 + 2] = -1.0200067492; v[4*7 + 3] = 0.2341131806; v[4*7 + 4] = 0.2341131806; v[4*7 + 5] = -1.0200067492; v[4*7 + 6] = 4.7858935686; + v[5*7 + 0] = -0.0; v[5*7 + 1] = 2.3047648710; v[5*7 + 2] = -1.2790480077; v[5*7 + 3] = 1.0257168633; v[5*7 + 4] = -1.0257168633; v[5*7 + 5] = 1.2790480077; v[5*7 + 6] = -2.3047648710; + v[6*7 + 0] = 1.0; v[6*7 + 1] = 0.0; v[6*7 + 2] = 0.0; v[6*7 + 3] = 0.0; v[6*7 + 4] = 0.0; v[6*7 + 5] = 0.0; v[6*7 + 6] = 0.0; + #elif SH_DEGREE == 8 + v[0*9 + 0] = 0.1111111111; v[0*9 + 1] = -0.1182419747; v[0*9 + 2] = 0.1450452544; v[0*9 + 3] = -0.2222222222; v[0*9 + 4] = 0.6398633870; v[0*9 + 5] = 0.6398633870; v[0*9 + 6] = -0.2222222222; v[0*9 + 7] = 0.1450452544; v[0*9 + 8] = -0.1182419747; + v[1*9 + 0] = 0.0; v[1*9 + 1] = -0.0430365592; v[1*9 + 2] = 0.1217074194; v[1*9 + 3] = -0.3849001795; v[1*9 + 4] = 3.6288455938; v[1*9 + 5] = -3.6288455938; v[1*9 + 6] = 0.3849001795; v[1*9 + 7] = -0.1217074194; v[1*9 + 8] = 0.0430365592; + v[2*9 + 0] = -4.0; v[2*9 + 1] = 4.2410470634; v[2*9 + 2] = -5.1195045066; v[2*9 + 3] = 7.3333333333; v[2*9 + 4] = -2.4548758901; v[2*9 + 5] = -2.4548758901; v[2*9 + 6] = 7.3333333333; v[2*9 + 7] = -5.1195045066; v[2*9 + 8] = 4.2410470634; + v[3*9 + 0] = -0.0; v[3*9 + 1] = 1.5436148932; v[3*9 + 2] = -4.2957743433; v[3*9 + 3] = 12.7017059222; v[3*9 + 4] = -13.9222930051; v[3*9 + 5] = 13.9222930051; v[3*9 + 6] = -12.7017059222; v[3*9 + 7] = 4.2957743433; v[3*9 + 8] = -1.5436148932; + v[4*9 + 0] = 14.0; v[4*9 + 1] = -14.3366589404; v[4*9 + 2] = 14.6711193836; v[4*9 + 3] = -6.0; v[4*9 + 4] = 1.6655395568; v[4*9 + 5] = 1.6655395568; v[4*9 + 6] = -6.0; v[4*9 + 7] = 14.6711193836; v[4*9 + 8] = -14.3366589404; + v[5*9 + 0] = 0.0; v[5*9 + 1] = -5.2181171131; v[5*9 + 2] = 12.3105308637; v[5*9 + 3] = -10.3923048454; v[5*9 + 4] = 9.4457442082; v[5*9 + 5] = -9.4457442082; v[5*9 + 6] = 10.3923048454; v[5*9 + 7] = -12.3105308637; v[5*9 + 8] = 5.2181171131; + v[6*9 + 0] = -9.3333333333; v[6*9 + 1] = 8.0330865684; v[6*9 + 2] = -1.8540394597; v[6*9 + 3] = 0.6666666667; v[6*9 + 4] = -0.1790471086; v[6*9 + 5] = -0.1790471086; v[6*9 + 6] = 0.6666666667; v[6*9 + 7] = -1.8540394597; v[6*9 + 8] = 8.0330865684; + v[7*9 + 0] = -0.0; v[7*9 + 1] = 2.9238044002; v[7*9 + 2] = -1.5557238269; v[7*9 + 3] = 1.1547005384; v[7*9 + 4] = -1.0154266119; v[7*9 + 5] = 1.0154266119; v[7*9 + 6] = -1.1547005384; v[7*9 + 7] = 1.5557238269; v[7*9 + 8] = -2.9238044002; + v[8*9 + 0] = 1.0; v[8*9 + 1] = 0.0; v[8*9 + 2] = 0.0; v[8*9 + 3] = 0.0; v[8*9 + 4] = 0.0; v[8*9 + 5] = 0.0; v[8*9 + 6] = 0.0; v[8*9 + 7] = 0.0; v[8*9 + 8] = 0.0; + #elif SH_DEGREE == 10 + v[0*11 + 0] = -0.0909090909; v[0*11 + 1] = 0.0947470106; v[0*11 + 2] = -0.1080638444; v[0*11 + 3] = 0.1388220215; v[0*11 + 4] = -0.2188392043; v[0*11 + 5] = 0.6387885621; v[0*11 + 6] = 0.6387885621; v[0*11 + 7] = -0.2188392043; v[0*11 + 8] = 0.1388220215; v[0*11 + 9] = -0.1080638444; v[0*11 + 10] = 0.0947470106; + v[1*11 + 0] = -0.0; v[1*11 + 1] = 0.0278202324; v[1*11 + 2] = -0.0694484159; v[1*11 + 3] = 0.1602091533; v[1*11 + 4] = -0.4791910159; v[1*11 + 5] = 4.4428720384; v[1*11 + 6] = -4.4428720384; v[1*11 + 7] = 0.4791910159; v[1*11 + 8] = -0.1602091533; v[1*11 + 9] = 0.0694484159; v[1*11 + 10] = -0.0278202324; + v[2*11 + 0] = 5.0; v[2*11 + 1] = -5.2029168239; v[2*11 + 2] = 5.8988796576; v[2*11 + 3] = -7.4503199653; v[2*11 + 4] = 10.9868742757; v[2*11 + 5] = -4.2325171441; v[2*11 + 6] = -4.2325171441; v[2*11 + 7] = 10.9868742757; v[2*11 + 8] = -7.4503199653; v[2*11 + 9] = 5.8988796576; v[2*11 + 10] = -5.2029168239; + v[3*11 + 0] = 0.0; v[3*11 + 1] = -1.5277142200; v[3*11 + 2] = 3.7909797649; v[3*11 + 3] = -8.5981275876; v[3*11 + 4] = 24.0578988657; v[3*11 + 5] = -29.4378033460; v[3*11 + 6] = 29.4378033460; v[3*11 + 7] = -24.0578988657; v[3*11 + 8] = 8.5981275876; v[3*11 + 9] = -3.7909797649; v[3*11 + 10] = 1.5277142200; + v[4*11 + 0] = -30.0; v[4*11 + 1] = 30.8179361182; v[4*11 + 2] = -33.2247539061; v[4*11 + 3] = 35.8884989085; v[4*11 + 4] = -19.5374870834; v[4*11 + 5] = 6.0558059629; v[4*11 + 6] = 6.0558059629; v[4*11 + 7] = -19.5374870834; v[4*11 + 8] = 35.8884989085; v[4*11 + 9] = -33.2247539061; v[4*11 + 10] = 30.8179361182; + v[5*11 + 0] = -0.0; v[5*11 + 1] = 9.0489625020; v[5*11 + 2] = -21.3522528115; v[5*11 + 3] = 41.4175356200; v[5*11 + 4] = -42.7811292411; v[5*11 + 5] = 42.1190556280; v[5*11 + 6] = -42.1190556280; v[5*11 + 7] = 42.7811292411; v[5*11 + 8] = -41.4175356200; v[5*11 + 9] = 21.3522528115; v[5*11 + 10] = -9.0489625020; + v[6*11 + 0] = 42.0; v[6*11 + 1] = -41.1161037573; v[6*11 + 2] = 36.2032364762; v[6*11 + 3] = -16.3373898141; v[6*11 + 4] = 7.4261062994; v[6*11 + 5] = -2.1758492042; v[6*11 + 6] = -2.1758492042; v[6*11 + 7] = 7.4261062994; v[6*11 + 8] = -16.3373898141; v[6*11 + 9] = 36.2032364762; v[6*11 + 10] = -41.1161037573; + v[7*11 + 0] = 0.0; v[7*11 + 1] = -12.0727773496; v[7*11 + 2] = 23.2664073304; v[7*11 + 3] = -18.8543529304; v[7*11 + 4] = 16.2609045881; v[7*11 + 5] = -15.1333636234; v[7*11 + 6] = 15.1333636234; v[7*11 + 7] = -16.2609045881; v[7*11 + 8] = 18.8543529304; v[7*11 + 9] = -23.2664073304; v[7*11 + 10] = 12.0727773496; + v[8*11 + 0] = -15.0; v[8*11 + 1] = 12.0883694702; v[8*11 + 2] = -2.8781222629; v[8*11 + 3] = 1.1465503415; v[8*11 + 4] = -0.5020543475; v[8*11 + 5] = 0.1452567988; v[8*11 + 6] = 0.1452567988; v[8*11 + 7] = -0.5020543475; v[8*11 + 8] = 1.1465503415; v[8*11 + 9] = -2.8781222629; v[8*11 + 10] = 12.0883694702; + v[9*11 + 0] = -0.0; v[9*11 + 1] = 3.5494655329; v[9*11 + 2] = -1.8496568659; v[9*11 + 3] = 1.3231896304; v[9*11 + 4] = -1.0993456751; v[9*11 + 5] = 1.0102832265; v[9*11 + 6] = -1.0102832265; v[9*11 + 7] = 1.0993456751; v[9*11 + 8] = -1.3231896304; v[9*11 + 9] = 1.8496568659; v[9*11 + 10] = -3.5494655329; + v[10*11 + 0] = 1.0; v[10*11 + 1] = 0.0; v[10*11 + 2] = 0.0; v[10*11 + 3] = 0.0; v[10*11 + 4] = 0.0; v[10*11 + 5] = 0.0; v[10*11 + 6] = 0.0; v[10*11 + 7] = 0.0; v[10*11 + 8] = 0.0; v[10*11 + 9] = 0.0; v[10*11 + 10] = 0.0; + #elif SH_DEGREE == 12 + v[0*13 + 0] = 0.0769230769; v[0*13 + 1] = -0.0792252178; v[0*13 + 2] = 0.0868739663; v[0*13 + 3] = -0.1027681661; v[0*13 + 4] = 0.1354125166; v[0*13 + 5] = -0.2169261613; v[0*13 + 6] = 0.6381715239; v[0*13 + 7] = 0.6381715239; v[0*13 + 8] = -0.2169261613; v[0*13 + 9] = 0.1354125166; v[0*13 + 10] = -0.1027681661; v[0*13 + 11] = 0.0868739663; v[0*13 + 12] = -0.0792252178; + v[1*13 + 0] = -0.0; v[1*13 + 1] = -0.0195272624; v[1*13 + 2] = 0.0455949748; v[1*13 + 3] = -0.0910446506; v[1*13 + 4] = 0.1961788986; v[1*13 + 5] = -0.5719872785; v[1*13 + 6] = 5.2558153553; v[1*13 + 7] = -5.2558153553; v[1*13 + 8] = 0.5719872785; v[1*13 + 9] = -0.1961788986; v[1*13 + 10] = 0.0910446506; v[1*13 + 11] = -0.0455949748; v[1*13 + 12] = 0.0195272624; + v[2*13 + 0] = -6.0; v[2*13 + 1] = 6.1747539478; v[2*13 + 2] = -6.7522392818; v[2*13 + 3] = 7.9352584366; v[2*13 + 4] = -10.2779620900; v[2*13 + 5] = 15.4120340799; v[2*13 + 6] = -6.4918450925; v[2*13 + 7] = -6.4918450925; v[2*13 + 8] = 15.4120340799; v[2*13 + 9] = -10.2779620900; v[2*13 + 10] = 7.9352584366; v[2*13 + 11] = -6.7522392818; v[2*13 + 12] = 6.1747539478; + v[3*13 + 0] = -0.0; v[3*13 + 1] = 1.5219401578; v[3*13 + 2] = -3.5438485554; v[3*13 + 3] = 7.0300255289; v[3*13 + 4] = -14.8901987371; v[3*13 + 5] = 40.6381940129; v[3*13 + 6] = -53.4651544987; v[3*13 + 7] = 53.4651544987; v[3*13 + 8] = -40.6381940129; v[3*13 + 9] = 14.8901987371; v[3*13 + 10] = -7.0300255289; v[3*13 + 11] = 3.5438485554; v[3*13 + 12] = -1.5219401578; + v[4*13 + 0] = 55.0; v[4*13 + 1] = -56.2709061445; v[4*13 + 2] = 60.2549306937; v[4*13 + 3] = -67.2511796347; v[4*13 + 4] = 75.2477722397; v[4*13 + 5] = -47.9480941911; v[4*13 + 6] = 15.9674770369; v[4*13 + 7] = 15.9674770369; v[4*13 + 8] = -47.9480941911; v[4*13 + 9] = 75.2477722397; v[4*13 + 10] = -67.2511796347; v[4*13 + 11] = 60.2549306937; v[4*13 + 12] = -56.2709061445; + v[5*13 + 0] = 0.0; v[5*13 + 1] = -13.8695326974; v[5*13 + 2] = 31.6242271914; v[5*13 + 3] = -59.5793462127; v[5*13 + 4] = 109.0152185187; v[5*13 + 5] = -126.4287338180; v[5*13 + 6] = 131.5040045727; v[5*13 + 7] = -131.5040045727; v[5*13 + 8] = 126.4287338180; v[5*13 + 9] = -109.0152185187; v[5*13 + 10] = 59.5793462127; v[5*13 + 11] = -31.6242271914; v[5*13 + 12] = 13.8695326974; + v[6*13 + 0] = -132.0; v[6*13 + 1] = 132.5319409049; v[6*13 + 2] = -132.4780513404; v[6*13 + 3] = 123.5674782081; v[6*13 + 4] = -74.4320682907; v[6*13 + 5] = 38.8801193717; v[6*13 + 6] = -12.0694188537; v[6*13 + 7] = -12.0694188537; v[6*13 + 8] = 38.8801193717; v[6*13 + 9] = -74.4320682907; v[6*13 + 10] = 123.5674782081; v[6*13 + 11] = -132.4780513404; v[6*13 + 12] = 132.5319409049; + v[7*13 + 0] = -0.0; v[7*13 + 1] = 32.6661895777; v[7*13 + 2] = -69.5298450306; v[7*13 + 3] = 109.4712331409; v[7*13 + 4] = -107.8334673306; v[7*13 + 5] = 102.5184492897; v[7*13 + 6] = -99.4006071501; v[7*13 + 7] = 99.4006071501; v[7*13 + 8] = -102.5184492897; v[7*13 + 9] = 107.8334673306; v[7*13 + 10] = -109.4712331409; v[7*13 + 11] = 69.5298450306; v[7*13 + 12] = -32.6661895777; + v[8*13 + 0] = 99.0; v[8*13 + 1] = -93.9113626635; v[8*13 + 2] = 75.3147168618; v[8*13 + 3] = -35.2795800772; v[8*13 + 4] = 18.0521608541; v[8*13 + 5] = -8.8650350126; v[8*13 + 6] = 2.6891000373; v[8*13 + 7] = 2.6891000373; v[8*13 + 8] = -8.8650350126; v[8*13 + 9] = 18.0521608541; v[8*13 + 10] = -35.2795800772; v[8*13 + 11] = 75.3147168618; v[8*13 + 12] = -93.9113626635; + v[9*13 + 0] = 0.0; v[9*13 + 1] = -23.1470719837; v[9*13 + 2] = 39.5282127035; v[9*13 + 3] = -31.2549806126; v[9*13 + 4] = 26.1530700733; v[9*13 + 5] = -23.3751762359; v[9*13 + 6] = 22.1467313083; v[9*13 + 7] = -22.1467313083; v[9*13 + 8] = 23.3751762359; v[9*13 + 9] = -26.1530700733; v[9*13 + 10] = 31.2549806126; v[9*13 + 11] = -39.5282127035; v[9*13 + 12] = 23.1470719837; + v[10*13 + 0] = -22.0; v[10*13 + 1] = 16.9531714429; v[10*13 + 2] = -4.0999479387; v[10*13 + 3] = 1.7021989010; v[10*13 + 4] = -0.8387165175; v[10*13 + 5] = 0.4056079008; v[10*13 + 6] = -0.1223137885; v[10*13 + 7] = -0.1223137885; v[10*13 + 8] = 0.4056079008; v[10*13 + 9] = -0.8387165175; v[10*13 + 10] = 1.7021989010; v[10*13 + 11] = -4.0999479387; v[10*13 + 12] = 16.9531714429; + v[11*13 + 0] = -0.0; v[11*13 + 1] = 4.1785814689; v[11*13 + 2] = -2.1518186743; v[11*13 + 3] = 1.5080166355; v[11*13 + 4] = -1.2150906493; v[11*13 + 5] = 1.0695001374; v[11*13 + 6] = -1.0073446769; v[11*13 + 7] = 1.0073446769; v[11*13 + 8] = -1.0695001374; v[11*13 + 9] = 1.2150906493; v[11*13 + 10] = -1.5080166355; v[11*13 + 11] = 2.1518186743; v[11*13 + 12] = -4.1785814689; + v[12*13 + 0] = 1.0; v[12*13 + 1] = 0.0; v[12*13 + 2] = 0.0; v[12*13 + 3] = 0.0; v[12*13 + 4] = 0.0; v[12*13 + 5] = 0.0; v[12*13 + 6] = 0.0; v[12*13 + 7] = 0.0; v[12*13 + 8] = 0.0; v[12*13 + 9] = 0.0; v[12*13 + 10] = 0.0; v[12*13 + 11] = 0.0; v[12*13 + 12] = 0.0; + #endif +} diff --git a/fury/shaders/spherical_harmonics/newton_bisection.frag b/fury/shaders/spherical_harmonics/newton_bisection.frag new file mode 100644 index 000000000..3f4b7f81f --- /dev/null +++ b/fury/shaders/spherical_harmonics/newton_bisection.frag @@ -0,0 +1,47 @@ +bool newton_bisection(out float out_root, out float out_end_value, + float poly[MAX_DEGREE + 1], float begin, float end, + float begin_value, float error_tolerance) +{ + if (begin == end) { + out_end_value = begin_value; + return false; + } + // Evaluate the polynomial at the end of the interval + out_end_value = poly[MAX_DEGREE]; + _unroll_ + for (int i = MAX_DEGREE - 1; i != -1; --i) + out_end_value = out_end_value * end + poly[i]; + // If the values at both ends have the same non-zero sign, there is no root + if (begin_value * out_end_value > 0.0) + return false; + // Otherwise, we find the root iteratively using Newton bisection (with + // bounded iteration count) + float current = 0.5 * (begin + end); + _loop_ + for (int i = 0; i != 90; ++i) { + // Evaluate the polynomial and its derivative + float value = poly[MAX_DEGREE] * current + poly[MAX_DEGREE - 1]; + float derivative = poly[MAX_DEGREE]; + _unroll_ + for (int j = MAX_DEGREE - 2; j != -1; --j) { + derivative = derivative * current + value; + value = value * current + poly[j]; + } + // Shorten the interval + bool right = begin_value * value > 0.0; + begin = right ? current : begin; + end = right ? end : current; + // Apply Newton's method + float guess = current - value / derivative; + // Pick a guess + float middle = 0.5 * (begin + end); + float next = (guess >= begin && guess <= end) ? guess : middle; + // Move along or terminate + bool done = abs(next - current) < error_tolerance; + current = next; + if (done) + break; + } + out_root = current; + return true; +} diff --git a/fury/shaders/spherical_harmonics/ray_sh_glyph_intersections.frag b/fury/shaders/spherical_harmonics/ray_sh_glyph_intersections.frag new file mode 100644 index 000000000..a47dbbfc4 --- /dev/null +++ b/fury/shaders/spherical_harmonics/ray_sh_glyph_intersections.frag @@ -0,0 +1,81 @@ +void ray_sh_glyph_intersections(out float out_ray_params[MAX_DEGREE], float sh_coeffs[SH_COUNT], vec3 ray_origin, vec3 ray_dir) +{ + // Determine the direction from the glyph center to the closest point on + // the ray + float dir_dot_origin = dot(ray_dir, ray_origin); + vec3 closest_dir = normalize(ray_origin - dir_dot_origin * ray_dir); + // Evaluate the SH polynomial at SH_DEGREE + 1 points. That is enough to + // know its value everywhere along the ray. + float sh_values[SH_DEGREE + 1]; + _unroll_ + for (int i = 0; i != SH_DEGREE + 1; ++i) { + vec3 point = cos(float(i) * (M_PI / float(SH_DEGREE + 1))) * ray_dir + + sin(float(i) * (M_PI / float(SH_DEGREE + 1))) * closest_dir; + float shs[SH_COUNT]; + eval_sh(shs, point); + sh_values[i] = 0.0; + _unroll_ + for (int j = 0; j != SH_COUNT; ++j) + sh_values[i] += sh_coeffs[j] * shs[j]; + } + // Compute coefficients of the SH polynomial along the ray in the + // coordinate frame given by ray_dir and closest_dir + float radius_poly[SH_DEGREE + 1]; + float inv_vander[(SH_DEGREE + 1) * (SH_DEGREE + 1)]; + get_inv_vandermonde(inv_vander); + _unroll_ + for (int i = 0; i != SH_DEGREE + 1; ++i) { + radius_poly[i] = 0.0; + _unroll_ + for (int j = 0; j != SH_DEGREE + 1; ++j) + radius_poly[i] += inv_vander[i * (SH_DEGREE + 1) + j] * sh_values[j]; + } + // Compute a bounding circle around the glyph in the relevant plane + float radius_max = 0.0; + _unroll_ + for (int i = 0; i != SH_DEGREE + 1; ++i) { + float bound = sqrt(pow(float(i), float(i)) * pow(float(SH_DEGREE - i), float(SH_DEGREE - i)) / pow(float(SH_DEGREE), float(SH_DEGREE))); + // Workaround for buggy compilers where 0^0 is 0 + bound = (i == 0 || i == SH_DEGREE) ? 1.0 : bound; + radius_max += bound * abs(radius_poly[i]); + } + // Figure out the interval, where (if at all) the ray intersects the circle + float closest_dot_origin = dot(closest_dir, ray_origin); + if (radius_max < abs(closest_dot_origin)) { + _unroll_ + for (int i = 0; i != MAX_DEGREE; ++i) + out_ray_params[i] = NO_INTERSECTION; + return; + } + float radius_over_dot = radius_max / closest_dot_origin; + float u_max = sqrt(radius_over_dot * radius_over_dot - 1.0); + // Take the square of radius_poly + float poly[MAX_DEGREE + 1]; + _unroll_ + for (int i = 0; i != MAX_DEGREE + 1; ++i) + poly[i] = 0.0; + _unroll_ + for (int i = 0; i != SH_DEGREE + 1; ++i) + _unroll_ + for (int j = 0; j != SH_DEGREE + 1; ++j) + poly[i + j] += radius_poly[i] * radius_poly[j]; + // Subtract the scaled (2 * SH_DEGREE + 2)-th power of the distance to the + // glyph center + float dot_sq = closest_dot_origin * closest_dot_origin; + float binomial = 1.0; + _unroll_ + for (int i = 0; i != SH_DEGREE + 2; ++i) { + poly[2 * i] -= binomial * dot_sq; + // Update the binomial coefficient using a recurrence relation + binomial *= float(SH_DEGREE + 1 - i) / float(i + 1); + } + // Find roots of the polynomial within the relevant bounds + float roots[MAX_DEGREE + 1]; + find_roots(roots, poly, -u_max, u_max); + // Convert them back to the original coordinate frame (i.e. ray parameters) + _unroll_ + for (int i = 0; i != MAX_DEGREE; ++i) + out_ray_params[i] = (roots[i] != NO_INTERSECTION) + ? (roots[i] * closest_dot_origin - dir_dot_origin) + : NO_INTERSECTION; +} From ec6982085011cebb6fa7978b4b5c8e111b72e8ce Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Tue, 5 Dec 2023 14:50:15 -0500 Subject: [PATCH 024/118] All functions added. --- .../SH-ODF experimental/ray_traced_1.py | 144 ++++++------------ .../get_sh_glyph_normal.frag | 16 ++ .../gltf_dielectric_brdf.frag | 41 +++++ .../linear_rgb_to_srgb.frag | 4 + .../spherical_harmonics/linear_to_srgb.frag | 4 + .../spherical_harmonics/srgb_to_linear.frag | 4 + .../srgb_to_linear_rgb.frag | 4 + fury/shaders/spherical_harmonics/tonemap.frag | 5 + 8 files changed, 125 insertions(+), 97 deletions(-) create mode 100644 fury/shaders/spherical_harmonics/get_sh_glyph_normal.frag create mode 100644 fury/shaders/spherical_harmonics/gltf_dielectric_brdf.frag create mode 100644 fury/shaders/spherical_harmonics/linear_rgb_to_srgb.frag create mode 100644 fury/shaders/spherical_harmonics/linear_to_srgb.frag create mode 100644 fury/shaders/spherical_harmonics/srgb_to_linear.frag create mode 100644 fury/shaders/spherical_harmonics/srgb_to_linear_rgb.frag create mode 100644 fury/shaders/spherical_harmonics/tonemap.frag diff --git a/docs/experimental/SH-ODF experimental/ray_traced_1.py b/docs/experimental/SH-ODF experimental/ray_traced_1.py index 9239ba910..2e0f6ed20 100644 --- a/docs/experimental/SH-ODF experimental/ray_traced_1.py +++ b/docs/experimental/SH-ODF experimental/ray_traced_1.py @@ -210,105 +210,57 @@ os.path.join("spherical_harmonics", "ray_sh_glyph_intersections.frag") ) - new_code = """ -// Provides a normalized normal vector for a spherical harmonics glyph. -// \param sh_coeffs SH_COUNT spherical harmonic coefficients defining the -// glyph. Their exact meaning is defined by eval_sh(). -// \param point A point on the surface of the glyph, relative to its center. -// return A normalized surface normal pointing away from the origin. -vec3 get_sh_glyph_normal(float sh_coeffs[SH_COUNT], vec3 point) { - float shs[SH_COUNT]; - vec3 grads[SH_COUNT]; - float length_inv = inversesqrt(dot(point, point)); - vec3 normalized = point * length_inv; - eval_sh_grad(shs, grads, normalized); - float value = 0.0; - vec3 grad = vec3(0.0); - _unroll_ - for (int i = 0; i != SH_COUNT; ++i) { - value += sh_coeffs[i] * shs[i]; - grad += sh_coeffs[i] * grads[i]; - } - return normalize(point - (value * length_inv) * (grad - dot(grad, normalized) * normalized)); -} - - -// This is the glTF BRDF for dielectric materials, exactly as described here: -// https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#appendix-b-brdf-implementation -// \param incoming The normalized incoming light direction. -// \param outgoing The normalized outgoing light direction. -// \param normal The normalized shading normal. -// \param roughness An artist friendly roughness value between 0 and 1 -// \param base_color The albedo used for the Lambertian diffuse component -// return The BRDF for the given directions. -vec3 gltf_dielectric_brdf(vec3 incoming, vec3 outgoing, vec3 normal, float roughness, vec3 base_color) { - float ni = dot(normal, incoming); - float no = dot(normal, outgoing); - // Early out if incoming or outgoing direction are below the horizon - if (ni <= 0.0 || no <= 0.0) - return vec3(0.0); - // Save some work by not actually computing the half-vector. If the half- - // vector were h, ih = dot(incoming, h) and - // sqrt(nh_ih_2 / ih_2) = dot(normal, h). - float ih_2 = dot(incoming, outgoing) * 0.5 + 0.5; - float sum = ni + no; - float nh_ih_2 = 0.25 * sum * sum; - float ih = sqrt(ih_2); - - // Evaluate the GGX normal distribution function - float roughness_2 = roughness * roughness; - float roughness_4 = roughness_2 * roughness_2; - float roughness_flip = 1.0 - roughness_4; - float denominator = ih_2 - nh_ih_2 * roughness_flip; - float ggx = (roughness_4 * M_INV_PI * ih_2) / (denominator * denominator); - // Evaluate the "visibility" (i.e. masking-shadowing times geometry terms) - float vi = ni + sqrt(roughness_4 + roughness_flip * ni * ni); - float vo = no + sqrt(roughness_4 + roughness_flip * no * no); - float v = 1.0 / (vi * vo); - // That completes the specular BRDF - float specular = v * ggx; - - // The diffuse BRDF is Lambertian - vec3 diffuse = M_INV_PI * base_color; - - // Evaluate the Fresnel term using the Fresnel-Schlick approximation - const float ior = 1.5; - const float f0 = ((1.0 - ior) / (1.0 + ior)) * ((1.0 - ior) / (1.0 + ior)); - float ih_flip = 1.0 - ih; - float ih_flip_2 = ih_flip * ih_flip; - float fresnel = f0 + (1.0 - f0) * ih_flip * ih_flip_2 * ih_flip_2; - - // Mix the two components - return mix(diffuse, vec3(specular), fresnel); -} + # Provides a normalized normal vector for a spherical harmonics glyph. + # param sh_coeffs SH_COUNT spherical harmonic coefficients defining the + # glyph. Their exact meaning is defined by eval_sh(). + # param point A point on the surface of the glyph, relative to its + # center. + # + # return A normalized surface normal pointing away from the origin. + get_sh_glyph_normal = import_fury_shader( + os.path.join("spherical_harmonics", "get_sh_glyph_normal.frag") + ) + # This is the glTF BRDF for dielectric materials, exactly as described + # here: + # https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#appendix-b-brdf-implementation + # param incoming The normalized incoming light direction. + # param outgoing The normalized outgoing light direction. + # param normal The normalized shading normal. + # param roughness An artist friendly roughness value between 0 and 1. + # param base_color The albedo used for the Lambertian diffuse component. + # + # return The BRDF for the given directions. + gltf_dielectric_brdf = import_fury_shader( + os.path.join("spherical_harmonics", "gltf_dielectric_brdf.frag") + ) -// Applies the non-linearity that maps linear RGB to sRGB -float linear_to_srgb(float linear) { - return (linear <= 0.0031308) ? (12.92 * linear) : (1.055 * pow(linear, 1.0 / 2.4) - 0.055); -} + # Applies the non-linearity that maps linear RGB to sRGB + linear_to_srgb = import_fury_shader( + os.path.join("spherical_harmonics", "linear_to_srgb.frag") + ) -// Inverse of linear_to_srgb() -float srgb_to_linear(float non_linear) { - return (non_linear <= 0.04045) ? ((1.0 / 12.92) * non_linear) : pow(non_linear * (1.0 / 1.055) + 0.055 / 1.055, 2.4); -} + # Inverse of linear_to_srgb() + srgb_to_linear = import_fury_shader( + os.path.join("spherical_harmonics", "srgb_to_linear.frag") + ) -// Turns a linear RGB color (i.e. rec. 709) into sRGB -vec3 linear_rgb_to_srgb(vec3 linear) { - return vec3(linear_to_srgb(linear.r), linear_to_srgb(linear.g), linear_to_srgb(linear.b)); -} + # Turns a linear RGB color (i.e. rec. 709) into sRGB + linear_rgb_to_srgb = import_fury_shader( + os.path.join("spherical_harmonics", "linear_rgb_to_srgb.frag") + ) -// Inverse of linear_rgb_to_srgb() -vec3 srgb_to_linear_rgb(vec3 srgb) { - return vec3(srgb_to_linear(srgb.r), srgb_to_linear(srgb.g), srgb_to_linear(srgb.b)); -} + # Inverse of linear_rgb_to_srgb() + srgb_to_linear_rgb = import_fury_shader( + os.path.join("spherical_harmonics", "srgb_to_linear_rgb.frag") + ) -// Logarithmic tonemapping operator. Input and output are linear RGB. -vec3 tonemap(vec3 linear) { - float max_channel = max(max(1.0, linear.r), max(linear.g, linear.b)); - return linear * ((1.0 - 0.02 * log2(max_channel)) / max_channel); -} + # Logarithmic tonemapping operator. Input and output are linear RGB. + tonemap = import_fury_shader( + os.path.join("spherical_harmonics", "tonemap.frag") + ) + new_code = """ vec3 iResolution = vec3(1920, 1080, 1.0); float iTime = 1.0; void mainImage(out vec4 out_color, vec2 frag_coord) { @@ -383,15 +335,15 @@ eval_sh_8, eval_sh_10, eval_sh_12, eval_sh_grad_2, eval_sh_grad_4, eval_sh_grad_6, eval_sh_grad_8, eval_sh_grad_10, eval_sh_grad_12, newton_bisection, find_roots, eval_sh, eval_sh_grad, - get_inv_vandermonde, ray_sh_glyph_intersections, new_code + get_inv_vandermonde, ray_sh_glyph_intersections, get_sh_glyph_normal, + gltf_dielectric_brdf, linear_to_srgb, srgb_to_linear, + linear_rgb_to_srgb, srgb_to_linear_rgb, tonemap, new_code ]) # fmt: on shader_to_actor(odf_actor, "fragment", decl_code=fs_dec, debug=False) sdf_frag_impl = """ - - // ------------------------------------------------------------------------------------------------------------------ vec3 pnt = vertexMCVSOutput.xyz; // Ray Origin @@ -406,8 +358,6 @@ ro += pnt - ro; - //vec3 t = castRay(ro, rd); - vec2 frag_coord = gl_FragCoord.xy; vec3 camera_pos = ro; //vec3(0.0, -5.0, 0.0); float aspect = float(iResolution.x) / float(iResolution.y); diff --git a/fury/shaders/spherical_harmonics/get_sh_glyph_normal.frag b/fury/shaders/spherical_harmonics/get_sh_glyph_normal.frag new file mode 100644 index 000000000..4831fb8b4 --- /dev/null +++ b/fury/shaders/spherical_harmonics/get_sh_glyph_normal.frag @@ -0,0 +1,16 @@ +vec3 get_sh_glyph_normal(float sh_coeffs[SH_COUNT], vec3 point) +{ + float shs[SH_COUNT]; + vec3 grads[SH_COUNT]; + float length_inv = inversesqrt(dot(point, point)); + vec3 normalized = point * length_inv; + eval_sh_grad(shs, grads, normalized); + float value = 0.0; + vec3 grad = vec3(0.0); + _unroll_ + for (int i = 0; i != SH_COUNT; ++i) { + value += sh_coeffs[i] * shs[i]; + grad += sh_coeffs[i] * grads[i]; + } + return normalize(point - (value * length_inv) * (grad - dot(grad, normalized) * normalized)); +} diff --git a/fury/shaders/spherical_harmonics/gltf_dielectric_brdf.frag b/fury/shaders/spherical_harmonics/gltf_dielectric_brdf.frag new file mode 100644 index 000000000..465ab2266 --- /dev/null +++ b/fury/shaders/spherical_harmonics/gltf_dielectric_brdf.frag @@ -0,0 +1,41 @@ +vec3 gltf_dielectric_brdf(vec3 incoming, vec3 outgoing, vec3 normal, float roughness, vec3 base_color) +{ + float ni = dot(normal, incoming); + float no = dot(normal, outgoing); + // Early out if incoming or outgoing direction are below the horizon + if (ni <= 0.0 || no <= 0.0) + return vec3(0.0); + // Save some work by not actually computing the half-vector. If the half- + // vector were h, ih = dot(incoming, h) and + // sqrt(nh_ih_2 / ih_2) = dot(normal, h). + float ih_2 = dot(incoming, outgoing) * 0.5 + 0.5; + float sum = ni + no; + float nh_ih_2 = 0.25 * sum * sum; + float ih = sqrt(ih_2); + + // Evaluate the GGX normal distribution function + float roughness_2 = roughness * roughness; + float roughness_4 = roughness_2 * roughness_2; + float roughness_flip = 1.0 - roughness_4; + float denominator = ih_2 - nh_ih_2 * roughness_flip; + float ggx = (roughness_4 * M_INV_PI * ih_2) / (denominator * denominator); + // Evaluate the "visibility" (i.e. masking-shadowing times geometry terms) + float vi = ni + sqrt(roughness_4 + roughness_flip * ni * ni); + float vo = no + sqrt(roughness_4 + roughness_flip * no * no); + float v = 1.0 / (vi * vo); + // That completes the specular BRDF + float specular = v * ggx; + + // The diffuse BRDF is Lambertian + vec3 diffuse = M_INV_PI * base_color; + + // Evaluate the Fresnel term using the Fresnel-Schlick approximation + const float ior = 1.5; + const float f0 = ((1.0 - ior) / (1.0 + ior)) * ((1.0 - ior) / (1.0 + ior)); + float ih_flip = 1.0 - ih; + float ih_flip_2 = ih_flip * ih_flip; + float fresnel = f0 + (1.0 - f0) * ih_flip * ih_flip_2 * ih_flip_2; + + // Mix the two components + return mix(diffuse, vec3(specular), fresnel); +} diff --git a/fury/shaders/spherical_harmonics/linear_rgb_to_srgb.frag b/fury/shaders/spherical_harmonics/linear_rgb_to_srgb.frag new file mode 100644 index 000000000..d1c72c83b --- /dev/null +++ b/fury/shaders/spherical_harmonics/linear_rgb_to_srgb.frag @@ -0,0 +1,4 @@ +vec3 linear_rgb_to_srgb(vec3 linear) +{ + return vec3(linear_to_srgb(linear.r), linear_to_srgb(linear.g), linear_to_srgb(linear.b)); +} diff --git a/fury/shaders/spherical_harmonics/linear_to_srgb.frag b/fury/shaders/spherical_harmonics/linear_to_srgb.frag new file mode 100644 index 000000000..ac686853c --- /dev/null +++ b/fury/shaders/spherical_harmonics/linear_to_srgb.frag @@ -0,0 +1,4 @@ +float linear_to_srgb(float linear) +{ + return (linear <= 0.0031308) ? (12.92 * linear) : (1.055 * pow(linear, 1.0 / 2.4) - 0.055); +} diff --git a/fury/shaders/spherical_harmonics/srgb_to_linear.frag b/fury/shaders/spherical_harmonics/srgb_to_linear.frag new file mode 100644 index 000000000..78c765c20 --- /dev/null +++ b/fury/shaders/spherical_harmonics/srgb_to_linear.frag @@ -0,0 +1,4 @@ +float srgb_to_linear(float non_linear) +{ + return (non_linear <= 0.04045) ? ((1.0 / 12.92) * non_linear) : pow(non_linear * (1.0 / 1.055) + 0.055 / 1.055, 2.4); +} diff --git a/fury/shaders/spherical_harmonics/srgb_to_linear_rgb.frag b/fury/shaders/spherical_harmonics/srgb_to_linear_rgb.frag new file mode 100644 index 000000000..e4c2ef22a --- /dev/null +++ b/fury/shaders/spherical_harmonics/srgb_to_linear_rgb.frag @@ -0,0 +1,4 @@ +vec3 srgb_to_linear_rgb(vec3 srgb) +{ + return vec3(srgb_to_linear(srgb.r), srgb_to_linear(srgb.g), srgb_to_linear(srgb.b)); +} diff --git a/fury/shaders/spherical_harmonics/tonemap.frag b/fury/shaders/spherical_harmonics/tonemap.frag new file mode 100644 index 000000000..dd6cdcacb --- /dev/null +++ b/fury/shaders/spherical_harmonics/tonemap.frag @@ -0,0 +1,5 @@ +vec3 tonemap(vec3 linear) +{ + float max_channel = max(max(1.0, linear.r), max(linear.g, linear.b)); + return linear * ((1.0 - 0.02 * log2(max_channel)) / max_channel); +} From c94cb7ac4c2a94b6b93b100307944266403f6c20 Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Tue, 5 Dec 2023 15:41:08 -0500 Subject: [PATCH 025/118] clear --- .../SH-ODF experimental/ray_traced_1.py | 87 ++----------------- 1 file changed, 7 insertions(+), 80 deletions(-) diff --git a/docs/experimental/SH-ODF experimental/ray_traced_1.py b/docs/experimental/SH-ODF experimental/ray_traced_1.py index 2e0f6ed20..818f73950 100644 --- a/docs/experimental/SH-ODF experimental/ray_traced_1.py +++ b/docs/experimental/SH-ODF experimental/ray_traced_1.py @@ -25,9 +25,9 @@ show_man.scene.background((1, 1, 1)) centers = np.array([[0, 0, 0]]) - scales = np.array([1]) + scales = np.array([4]) - odf_actor = actor.box(centers=centers, scales=4) + odf_actor = actor.box(centers=centers, scales=scales) big_centers = np.repeat(centers, 8, axis=0) attribute_to_actor(odf_actor, big_centers, "center") @@ -260,73 +260,6 @@ os.path.join("spherical_harmonics", "tonemap.frag") ) - new_code = """ -vec3 iResolution = vec3(1920, 1080, 1.0); -float iTime = 1.0; -void mainImage(out vec4 out_color, vec2 frag_coord) { - // Define a camera ray for a pinhole camera - vec3 camera_pos = vec3(0.0, -5.0, 0.0); - float aspect = float(iResolution.x) / float(iResolution.y); - float zoom = 0.8; - vec3 right = (aspect / zoom) * vec3(3.0, 0.0, 0.0); - vec3 up = (1.0 / zoom) * vec3(0.0, 0.0, 3.0); - vec3 bottom_left = -0.5 * (right + up); - vec2 uv = frag_coord / vec2(iResolution.xy); - vec3 ray_dir = normalize(bottom_left + uv.x * right + uv.y * up - camera_pos); - // Rotate the camera slowly - float pitch = -0.2 * M_PI; - float yaw = 0.1 * M_PI * iTime; - mat3 rot_z = mat3(cos(yaw), sin(yaw), 0.0, -sin(yaw), cos(yaw), 0.0, 0.0, 0.0, 1.0); - mat3 rot_x = mat3(1.0, 0.0, 0.0, 0.0, cos(pitch), sin(pitch), 0.0, -sin(pitch), cos(pitch)); - camera_pos = rot_z * rot_x * camera_pos; - ray_dir = normalize(rot_z * rot_x * ray_dir); - // Define SH coefficients (measured up to band 8, noise beyond that) - float sh_coeffs[SH_COUNT]; - sh_coeffs[0] = -0.2739740312099; sh_coeffs[1] = 0.2526670396328; sh_coeffs[2] = 1.8922271728516; sh_coeffs[3] = 0.2878578901291; sh_coeffs[4] = -0.5339795947075; sh_coeffs[5] = -0.2620058953762; -#if SH_DEGREE >= 4 - sh_coeffs[6] = 0.1580424904823; sh_coeffs[7] = 0.0329004973173; sh_coeffs[8] = -0.1322413831949; sh_coeffs[9] = -0.1332057565451; sh_coeffs[10] = 1.0894461870193; sh_coeffs[11] = -0.6319401264191; sh_coeffs[12] = -0.0416776277125; sh_coeffs[13] = -1.0772529840469; sh_coeffs[14] = 0.1423762738705; -#endif -#if SH_DEGREE >= 6 - sh_coeffs[15] = 0.7941166162491; sh_coeffs[16] = 0.7490307092667; sh_coeffs[17] = -0.3428381681442; sh_coeffs[18] = 0.1024847552180; sh_coeffs[19] = -0.0219132602215; sh_coeffs[20] = 0.0499043911695; sh_coeffs[21] = 0.2162453681231; sh_coeffs[22] = 0.0921059995890; sh_coeffs[23] = -0.2611238956451; sh_coeffs[24] = 0.2549301385880; sh_coeffs[25] = -0.4534865319729; sh_coeffs[26] = 0.1922748684883; sh_coeffs[27] = -0.6200597286224; -#endif -#if SH_DEGREE >= 8 - sh_coeffs[28] = -0.0532187558711; sh_coeffs[29] = -0.3569841980934; sh_coeffs[30] = 0.0293972902000; sh_coeffs[31] = -0.1977960765362; sh_coeffs[32] = -0.1058669015765; sh_coeffs[33] = 0.2372217923403; sh_coeffs[34] = -0.1856198310852; sh_coeffs[35] = -0.3373193442822; sh_coeffs[36] = -0.0750469490886; sh_coeffs[37] = 0.2146576642990; sh_coeffs[38] = -0.0490148440003; sh_coeffs[39] = 0.1288588196039; sh_coeffs[40] = 0.3173974752426; sh_coeffs[41] = 0.1990085393190; sh_coeffs[42] = -0.1736343950033; sh_coeffs[43] = -0.0482443645597; sh_coeffs[44] = 0.1749017387629; -#endif -#if SH_DEGREE >= 10 - sh_coeffs[45] = -0.0151847425660; sh_coeffs[46] = 0.0418366046081; sh_coeffs[47] = 0.0863263587216; sh_coeffs[48] = -0.0649211244490; sh_coeffs[49] = 0.0126096132283; sh_coeffs[50] = 0.0545089217982; sh_coeffs[51] = -0.0275142164626; sh_coeffs[52] = 0.0399986574832; sh_coeffs[53] = -0.0468244261610; sh_coeffs[54] = -0.1292105653111; sh_coeffs[55] = -0.0786858322658; sh_coeffs[56] = -0.0663828464882; sh_coeffs[57] = 0.0382439706831; sh_coeffs[58] = -0.0041550330365; sh_coeffs[59] = -0.0502800566338; sh_coeffs[60] = -0.0732471630735; sh_coeffs[61] = 0.0181751900972; sh_coeffs[62] = -0.0090119333757; sh_coeffs[63] = -0.0604443282359; sh_coeffs[64] = -0.1469985252752; sh_coeffs[65] = -0.0534046899715; -#endif -#if SH_DEGREE >= 12 - sh_coeffs[66] = -0.0896672753415; sh_coeffs[67] = -0.0130841364808; sh_coeffs[68] = -0.0112942893801; sh_coeffs[69] = 0.0272257498541; sh_coeffs[70] = 0.0626717616331; sh_coeffs[71] = -0.0222197983050; sh_coeffs[72] = -0.0018541504308; sh_coeffs[73] = -0.1653251944056; sh_coeffs[74] = 0.0409697402846; sh_coeffs[75] = 0.0749921454327; sh_coeffs[76] = -0.0282830872616; sh_coeffs[77] = 0.0006909458525; sh_coeffs[78] = 0.0625599842287; sh_coeffs[79] = 0.0812529816082; sh_coeffs[80] = 0.0914693020772; sh_coeffs[81] = -0.1197222726745; sh_coeffs[82] = 0.0376277453183; sh_coeffs[83] = -0.0832617004142; sh_coeffs[84] = -0.0482175038043; sh_coeffs[85] = -0.0839003635737; sh_coeffs[86] = -0.0349423908400; sh_coeffs[87] = 0.1204519568256; sh_coeffs[88] = 0.0783745984003; sh_coeffs[89] = 0.0297401205976; sh_coeffs[90] = -0.0505947662525; -#endif - // Perform the intersection test - float ray_params[MAX_DEGREE]; - ray_sh_glyph_intersections(ray_params, sh_coeffs, camera_pos, ray_dir); - // Identify the first intersection - float first_ray_param = NO_INTERSECTION; - _unroll_ - for (int i = 0; i != MAX_DEGREE; ++i) { - if (ray_params[i] != NO_INTERSECTION && ray_params[i] > 0.0) { - first_ray_param = ray_params[i]; - break; - } - } - // Evaluate shading for a directional light - vec3 color = vec3(1.0); - if (first_ray_param != NO_INTERSECTION) { - vec3 intersection = camera_pos + first_ray_param * ray_dir; - vec3 normal = get_sh_glyph_normal(sh_coeffs, intersection); - vec3 base_color = srgb_to_linear_rgb(abs(normalize(intersection))); - const vec3 incoming = normalize(vec3(1.23, -4.56, 7.89)); - float ambient = 0.04; - float exposure = 4.0; - vec3 outgoing = -ray_dir; - vec3 brdf = gltf_dielectric_brdf(incoming, outgoing, normal, 0.45, base_color); - color = exposure * (brdf * max(0.0, dot(incoming, normal)) + base_color * ambient); - } - out_color = vec4(linear_rgb_to_srgb(tonemap(color)), 1.0); -} - """ - # fmt: off fs_dec = compose_shader([ def_sh_degree, def_sh_count, def_max_degree, @@ -337,7 +270,7 @@ newton_bisection, find_roots, eval_sh, eval_sh_grad, get_inv_vandermonde, ray_sh_glyph_intersections, get_sh_glyph_normal, gltf_dielectric_brdf, linear_to_srgb, srgb_to_linear, - linear_rgb_to_srgb, srgb_to_linear_rgb, tonemap, new_code + linear_rgb_to_srgb, srgb_to_linear_rgb, tonemap ]) # fmt: on @@ -360,20 +293,14 @@ vec2 frag_coord = gl_FragCoord.xy; vec3 camera_pos = ro; //vec3(0.0, -5.0, 0.0); - float aspect = float(iResolution.x) / float(iResolution.y); - float zoom = .8; + //float aspect = float(iResolution.x) / float(iResolution.y); + float aspect = 1; + float zoom = .5; vec3 right = (aspect / zoom) * vec3(3.0, 0.0, 0.0); vec3 up = (1.0 / zoom) * vec3(0.0, 0.0, 3.0); vec3 bottom_left = -0.5 * (right + up); - vec2 uv = frag_coord / vec2(iResolution.xy); + //vec2 uv = frag_coord / vec2(iResolution.xy); vec3 ray_dir = rd; //normalize(bottom_left + uv.x * right + uv.y * up - camera_pos); - // Rotate the camera slowly - float pitch = -0.2 * M_PI; - float yaw = 0.1 * M_PI * iTime; - mat3 rot_z = mat3(cos(yaw), sin(yaw), 0.0, -sin(yaw), cos(yaw), 0.0, 0.0, 0.0, 1.0); - mat3 rot_x = mat3(1.0, 0.0, 0.0, 0.0, cos(pitch), sin(pitch), 0.0, -sin(pitch), cos(pitch)); - camera_pos = rot_z * rot_x * camera_pos; - ray_dir = normalize(rot_z * rot_x * ray_dir); // Define SH coefficients (measured up to band 8, noise beyond that) float sh_coeffs[SH_COUNT]; sh_coeffs[0] = -0.2739740312099; sh_coeffs[1] = 0.2526670396328; sh_coeffs[2] = 1.8922271728516; sh_coeffs[3] = 0.2878578901291; sh_coeffs[4] = -0.5339795947075; sh_coeffs[5] = -0.2620058953762; From d255964822a7f9a96546cd75dafb578f19befcdc Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Tue, 5 Dec 2023 15:43:10 -0500 Subject: [PATCH 026/118] Removed rotation code and resolution dependent code. --- docs/experimental/SH-ODF experimental/ray_traced_1.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/experimental/SH-ODF experimental/ray_traced_1.py b/docs/experimental/SH-ODF experimental/ray_traced_1.py index 818f73950..e712d6728 100644 --- a/docs/experimental/SH-ODF experimental/ray_traced_1.py +++ b/docs/experimental/SH-ODF experimental/ray_traced_1.py @@ -295,7 +295,7 @@ vec3 camera_pos = ro; //vec3(0.0, -5.0, 0.0); //float aspect = float(iResolution.x) / float(iResolution.y); float aspect = 1; - float zoom = .5; + float zoom = .8; vec3 right = (aspect / zoom) * vec3(3.0, 0.0, 0.0); vec3 up = (1.0 / zoom) * vec3(0.0, 0.0, 3.0); vec3 bottom_left = -0.5 * (right + up); From 99908e5279e760e21a95eb3ed3757e080ccaa123 Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Tue, 5 Dec 2023 16:30:18 -0500 Subject: [PATCH 027/118] Renamed folder spherical_harmonics as rt_odfs. --- .../SH-ODF experimental/ray_traced_1.py | 70 +++++++------------ .../eval_sh.frag | 0 .../eval_sh_10.frag | 0 .../eval_sh_12.frag | 0 .../eval_sh_2.frag | 0 .../eval_sh_4.frag | 0 .../eval_sh_6.frag | 0 .../eval_sh_8.frag | 0 .../eval_sh_grad.frag | 0 .../eval_sh_grad_10.frag | 0 .../eval_sh_grad_12.frag | 0 .../eval_sh_grad_2.frag | 0 .../eval_sh_grad_4.frag | 0 .../eval_sh_grad_6.frag | 0 .../eval_sh_grad_8.frag | 0 .../find_roots.frag | 0 .../get_inv_vandermonde.frag | 0 .../get_sh_glyph_normal.frag | 0 .../gltf_dielectric_brdf.frag | 0 .../linear_rgb_to_srgb.frag | 0 .../linear_to_srgb.frag | 0 .../newton_bisection.frag | 0 .../ray_sh_glyph_intersections.frag | 0 .../srgb_to_linear.frag | 0 .../srgb_to_linear_rgb.frag | 0 .../tonemap.frag | 0 26 files changed, 26 insertions(+), 44 deletions(-) rename fury/shaders/{spherical_harmonics => rt_odfs}/eval_sh.frag (100%) rename fury/shaders/{spherical_harmonics => rt_odfs}/eval_sh_10.frag (100%) rename fury/shaders/{spherical_harmonics => rt_odfs}/eval_sh_12.frag (100%) rename fury/shaders/{spherical_harmonics => rt_odfs}/eval_sh_2.frag (100%) rename fury/shaders/{spherical_harmonics => rt_odfs}/eval_sh_4.frag (100%) rename fury/shaders/{spherical_harmonics => rt_odfs}/eval_sh_6.frag (100%) rename fury/shaders/{spherical_harmonics => rt_odfs}/eval_sh_8.frag (100%) rename fury/shaders/{spherical_harmonics => rt_odfs}/eval_sh_grad.frag (100%) rename fury/shaders/{spherical_harmonics => rt_odfs}/eval_sh_grad_10.frag (100%) rename fury/shaders/{spherical_harmonics => rt_odfs}/eval_sh_grad_12.frag (100%) rename fury/shaders/{spherical_harmonics => rt_odfs}/eval_sh_grad_2.frag (100%) rename fury/shaders/{spherical_harmonics => rt_odfs}/eval_sh_grad_4.frag (100%) rename fury/shaders/{spherical_harmonics => rt_odfs}/eval_sh_grad_6.frag (100%) rename fury/shaders/{spherical_harmonics => rt_odfs}/eval_sh_grad_8.frag (100%) rename fury/shaders/{spherical_harmonics => rt_odfs}/find_roots.frag (100%) rename fury/shaders/{spherical_harmonics => rt_odfs}/get_inv_vandermonde.frag (100%) rename fury/shaders/{spherical_harmonics => rt_odfs}/get_sh_glyph_normal.frag (100%) rename fury/shaders/{spherical_harmonics => rt_odfs}/gltf_dielectric_brdf.frag (100%) rename fury/shaders/{spherical_harmonics => rt_odfs}/linear_rgb_to_srgb.frag (100%) rename fury/shaders/{spherical_harmonics => rt_odfs}/linear_to_srgb.frag (100%) rename fury/shaders/{spherical_harmonics => rt_odfs}/newton_bisection.frag (100%) rename fury/shaders/{spherical_harmonics => rt_odfs}/ray_sh_glyph_intersections.frag (100%) rename fury/shaders/{spherical_harmonics => rt_odfs}/srgb_to_linear.frag (100%) rename fury/shaders/{spherical_harmonics => rt_odfs}/srgb_to_linear_rgb.frag (100%) rename fury/shaders/{spherical_harmonics => rt_odfs}/tonemap.frag (100%) diff --git a/docs/experimental/SH-ODF experimental/ray_traced_1.py b/docs/experimental/SH-ODF experimental/ray_traced_1.py index e712d6728..7c33154e1 100644 --- a/docs/experimental/SH-ODF experimental/ray_traced_1.py +++ b/docs/experimental/SH-ODF experimental/ray_traced_1.py @@ -96,52 +96,40 @@ in float scaleVSOutput; """ - eval_sh_2 = import_fury_shader( - os.path.join("spherical_harmonics", "eval_sh_2.frag") - ) + eval_sh_2 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_2.frag")) - eval_sh_4 = import_fury_shader( - os.path.join("spherical_harmonics", "eval_sh_4.frag") - ) + eval_sh_4 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_4.frag")) - eval_sh_6 = import_fury_shader( - os.path.join("spherical_harmonics", "eval_sh_6.frag") - ) + eval_sh_6 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_6.frag")) - eval_sh_8 = import_fury_shader( - os.path.join("spherical_harmonics", "eval_sh_8.frag") - ) + eval_sh_8 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_8.frag")) - eval_sh_10 = import_fury_shader( - os.path.join("spherical_harmonics", "eval_sh_10.frag") - ) + eval_sh_10 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_10.frag")) - eval_sh_12 = import_fury_shader( - os.path.join("spherical_harmonics", "eval_sh_12.frag") - ) + eval_sh_12 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_12.frag")) eval_sh_grad_2 = import_fury_shader( - os.path.join("spherical_harmonics", "eval_sh_grad_2.frag") + os.path.join("rt_odfs", "eval_sh_grad_2.frag") ) eval_sh_grad_4 = import_fury_shader( - os.path.join("spherical_harmonics", "eval_sh_grad_4.frag") + os.path.join("rt_odfs", "eval_sh_grad_4.frag") ) eval_sh_grad_6 = import_fury_shader( - os.path.join("spherical_harmonics", "eval_sh_grad_6.frag") + os.path.join("rt_odfs", "eval_sh_grad_6.frag") ) eval_sh_grad_8 = import_fury_shader( - os.path.join("spherical_harmonics", "eval_sh_grad_8.frag") + os.path.join("rt_odfs", "eval_sh_grad_8.frag") ) eval_sh_grad_10 = import_fury_shader( - os.path.join("spherical_harmonics", "eval_sh_grad_10.frag") + os.path.join("rt_odfs", "eval_sh_grad_10.frag") ) eval_sh_grad_12 = import_fury_shader( - os.path.join("spherical_harmonics", "eval_sh_grad_12.frag") + os.path.join("rt_odfs", "eval_sh_grad_12.frag") ) # Searches a single root of a polynomial within a given interval. @@ -161,15 +149,13 @@ # # return true if a root was found, false if no root exists. newton_bisection = import_fury_shader( - os.path.join("spherical_harmonics", "newton_bisection.frag") + os.path.join("rt_odfs", "newton_bisection.frag") ) # Finds all roots of the given polynomial in the interval [begin, end] and # writes them to out_roots. Some entries will be NO_INTERSECTION but other # than that the array is sorted. The last entry is always NO_INTERSECTION. - find_roots = import_fury_shader( - os.path.join("spherical_harmonics", "find_roots.frag") - ) + find_roots = import_fury_shader(os.path.join("rt_odfs", "find_roots.frag")) # Evaluates the spherical harmonics basis in bands 0, 2, ..., SH_DEGREE. # Conventions are as in the following paper. @@ -180,20 +166,18 @@ # SH_DEGREE in this order. # param point The point on the unit sphere where the basis should be # evaluated. - eval_sh = import_fury_shader( - os.path.join("spherical_harmonics", "eval_sh.frag") - ) + eval_sh = import_fury_shader(os.path.join("rt_odfs", "eval_sh.frag")) # Evaluates the gradient of each basis function given by eval_sh() and the # basis itself eval_sh_grad = import_fury_shader( - os.path.join("spherical_harmonics", "eval_sh_grad.frag") + os.path.join("rt_odfs", "eval_sh_grad.frag") ) # Outputs a matrix that turns equidistant samples on the unit circle of a # homogeneous polynomial into coefficients of that polynomial. get_inv_vandermonde = import_fury_shader( - os.path.join("spherical_harmonics", "get_inv_vandermonde.frag") + os.path.join("rt_odfs", "get_inv_vandermonde.frag") ) # Determines all intersections between a ray and a spherical harmonics @@ -207,7 +191,7 @@ # param ray_origin The origin of the ray, relative to the glyph center. # param ray_dir The normalized direction vector of the ray. ray_sh_glyph_intersections = import_fury_shader( - os.path.join("spherical_harmonics", "ray_sh_glyph_intersections.frag") + os.path.join("rt_odfs", "ray_sh_glyph_intersections.frag") ) # Provides a normalized normal vector for a spherical harmonics glyph. @@ -218,7 +202,7 @@ # # return A normalized surface normal pointing away from the origin. get_sh_glyph_normal = import_fury_shader( - os.path.join("spherical_harmonics", "get_sh_glyph_normal.frag") + os.path.join("rt_odfs", "get_sh_glyph_normal.frag") ) # This is the glTF BRDF for dielectric materials, exactly as described @@ -232,33 +216,31 @@ # # return The BRDF for the given directions. gltf_dielectric_brdf = import_fury_shader( - os.path.join("spherical_harmonics", "gltf_dielectric_brdf.frag") + os.path.join("rt_odfs", "gltf_dielectric_brdf.frag") ) # Applies the non-linearity that maps linear RGB to sRGB linear_to_srgb = import_fury_shader( - os.path.join("spherical_harmonics", "linear_to_srgb.frag") + os.path.join("rt_odfs", "linear_to_srgb.frag") ) # Inverse of linear_to_srgb() srgb_to_linear = import_fury_shader( - os.path.join("spherical_harmonics", "srgb_to_linear.frag") + os.path.join("rt_odfs", "srgb_to_linear.frag") ) # Turns a linear RGB color (i.e. rec. 709) into sRGB linear_rgb_to_srgb = import_fury_shader( - os.path.join("spherical_harmonics", "linear_rgb_to_srgb.frag") + os.path.join("rt_odfs", "linear_rgb_to_srgb.frag") ) # Inverse of linear_rgb_to_srgb() srgb_to_linear_rgb = import_fury_shader( - os.path.join("spherical_harmonics", "srgb_to_linear_rgb.frag") + os.path.join("rt_odfs", "srgb_to_linear_rgb.frag") ) # Logarithmic tonemapping operator. Input and output are linear RGB. - tonemap = import_fury_shader( - os.path.join("spherical_harmonics", "tonemap.frag") - ) + tonemap = import_fury_shader(os.path.join("rt_odfs", "tonemap.frag")) # fmt: off fs_dec = compose_shader([ @@ -274,7 +256,7 @@ ]) # fmt: on - shader_to_actor(odf_actor, "fragment", decl_code=fs_dec, debug=False) + shader_to_actor(odf_actor, "fragment", decl_code=fs_dec) sdf_frag_impl = """ vec3 pnt = vertexMCVSOutput.xyz; diff --git a/fury/shaders/spherical_harmonics/eval_sh.frag b/fury/shaders/rt_odfs/eval_sh.frag similarity index 100% rename from fury/shaders/spherical_harmonics/eval_sh.frag rename to fury/shaders/rt_odfs/eval_sh.frag diff --git a/fury/shaders/spherical_harmonics/eval_sh_10.frag b/fury/shaders/rt_odfs/eval_sh_10.frag similarity index 100% rename from fury/shaders/spherical_harmonics/eval_sh_10.frag rename to fury/shaders/rt_odfs/eval_sh_10.frag diff --git a/fury/shaders/spherical_harmonics/eval_sh_12.frag b/fury/shaders/rt_odfs/eval_sh_12.frag similarity index 100% rename from fury/shaders/spherical_harmonics/eval_sh_12.frag rename to fury/shaders/rt_odfs/eval_sh_12.frag diff --git a/fury/shaders/spherical_harmonics/eval_sh_2.frag b/fury/shaders/rt_odfs/eval_sh_2.frag similarity index 100% rename from fury/shaders/spherical_harmonics/eval_sh_2.frag rename to fury/shaders/rt_odfs/eval_sh_2.frag diff --git a/fury/shaders/spherical_harmonics/eval_sh_4.frag b/fury/shaders/rt_odfs/eval_sh_4.frag similarity index 100% rename from fury/shaders/spherical_harmonics/eval_sh_4.frag rename to fury/shaders/rt_odfs/eval_sh_4.frag diff --git a/fury/shaders/spherical_harmonics/eval_sh_6.frag b/fury/shaders/rt_odfs/eval_sh_6.frag similarity index 100% rename from fury/shaders/spherical_harmonics/eval_sh_6.frag rename to fury/shaders/rt_odfs/eval_sh_6.frag diff --git a/fury/shaders/spherical_harmonics/eval_sh_8.frag b/fury/shaders/rt_odfs/eval_sh_8.frag similarity index 100% rename from fury/shaders/spherical_harmonics/eval_sh_8.frag rename to fury/shaders/rt_odfs/eval_sh_8.frag diff --git a/fury/shaders/spherical_harmonics/eval_sh_grad.frag b/fury/shaders/rt_odfs/eval_sh_grad.frag similarity index 100% rename from fury/shaders/spherical_harmonics/eval_sh_grad.frag rename to fury/shaders/rt_odfs/eval_sh_grad.frag diff --git a/fury/shaders/spherical_harmonics/eval_sh_grad_10.frag b/fury/shaders/rt_odfs/eval_sh_grad_10.frag similarity index 100% rename from fury/shaders/spherical_harmonics/eval_sh_grad_10.frag rename to fury/shaders/rt_odfs/eval_sh_grad_10.frag diff --git a/fury/shaders/spherical_harmonics/eval_sh_grad_12.frag b/fury/shaders/rt_odfs/eval_sh_grad_12.frag similarity index 100% rename from fury/shaders/spherical_harmonics/eval_sh_grad_12.frag rename to fury/shaders/rt_odfs/eval_sh_grad_12.frag diff --git a/fury/shaders/spherical_harmonics/eval_sh_grad_2.frag b/fury/shaders/rt_odfs/eval_sh_grad_2.frag similarity index 100% rename from fury/shaders/spherical_harmonics/eval_sh_grad_2.frag rename to fury/shaders/rt_odfs/eval_sh_grad_2.frag diff --git a/fury/shaders/spherical_harmonics/eval_sh_grad_4.frag b/fury/shaders/rt_odfs/eval_sh_grad_4.frag similarity index 100% rename from fury/shaders/spherical_harmonics/eval_sh_grad_4.frag rename to fury/shaders/rt_odfs/eval_sh_grad_4.frag diff --git a/fury/shaders/spherical_harmonics/eval_sh_grad_6.frag b/fury/shaders/rt_odfs/eval_sh_grad_6.frag similarity index 100% rename from fury/shaders/spherical_harmonics/eval_sh_grad_6.frag rename to fury/shaders/rt_odfs/eval_sh_grad_6.frag diff --git a/fury/shaders/spherical_harmonics/eval_sh_grad_8.frag b/fury/shaders/rt_odfs/eval_sh_grad_8.frag similarity index 100% rename from fury/shaders/spherical_harmonics/eval_sh_grad_8.frag rename to fury/shaders/rt_odfs/eval_sh_grad_8.frag diff --git a/fury/shaders/spherical_harmonics/find_roots.frag b/fury/shaders/rt_odfs/find_roots.frag similarity index 100% rename from fury/shaders/spherical_harmonics/find_roots.frag rename to fury/shaders/rt_odfs/find_roots.frag diff --git a/fury/shaders/spherical_harmonics/get_inv_vandermonde.frag b/fury/shaders/rt_odfs/get_inv_vandermonde.frag similarity index 100% rename from fury/shaders/spherical_harmonics/get_inv_vandermonde.frag rename to fury/shaders/rt_odfs/get_inv_vandermonde.frag diff --git a/fury/shaders/spherical_harmonics/get_sh_glyph_normal.frag b/fury/shaders/rt_odfs/get_sh_glyph_normal.frag similarity index 100% rename from fury/shaders/spherical_harmonics/get_sh_glyph_normal.frag rename to fury/shaders/rt_odfs/get_sh_glyph_normal.frag diff --git a/fury/shaders/spherical_harmonics/gltf_dielectric_brdf.frag b/fury/shaders/rt_odfs/gltf_dielectric_brdf.frag similarity index 100% rename from fury/shaders/spherical_harmonics/gltf_dielectric_brdf.frag rename to fury/shaders/rt_odfs/gltf_dielectric_brdf.frag diff --git a/fury/shaders/spherical_harmonics/linear_rgb_to_srgb.frag b/fury/shaders/rt_odfs/linear_rgb_to_srgb.frag similarity index 100% rename from fury/shaders/spherical_harmonics/linear_rgb_to_srgb.frag rename to fury/shaders/rt_odfs/linear_rgb_to_srgb.frag diff --git a/fury/shaders/spherical_harmonics/linear_to_srgb.frag b/fury/shaders/rt_odfs/linear_to_srgb.frag similarity index 100% rename from fury/shaders/spherical_harmonics/linear_to_srgb.frag rename to fury/shaders/rt_odfs/linear_to_srgb.frag diff --git a/fury/shaders/spherical_harmonics/newton_bisection.frag b/fury/shaders/rt_odfs/newton_bisection.frag similarity index 100% rename from fury/shaders/spherical_harmonics/newton_bisection.frag rename to fury/shaders/rt_odfs/newton_bisection.frag diff --git a/fury/shaders/spherical_harmonics/ray_sh_glyph_intersections.frag b/fury/shaders/rt_odfs/ray_sh_glyph_intersections.frag similarity index 100% rename from fury/shaders/spherical_harmonics/ray_sh_glyph_intersections.frag rename to fury/shaders/rt_odfs/ray_sh_glyph_intersections.frag diff --git a/fury/shaders/spherical_harmonics/srgb_to_linear.frag b/fury/shaders/rt_odfs/srgb_to_linear.frag similarity index 100% rename from fury/shaders/spherical_harmonics/srgb_to_linear.frag rename to fury/shaders/rt_odfs/srgb_to_linear.frag diff --git a/fury/shaders/spherical_harmonics/srgb_to_linear_rgb.frag b/fury/shaders/rt_odfs/srgb_to_linear_rgb.frag similarity index 100% rename from fury/shaders/spherical_harmonics/srgb_to_linear_rgb.frag rename to fury/shaders/rt_odfs/srgb_to_linear_rgb.frag diff --git a/fury/shaders/spherical_harmonics/tonemap.frag b/fury/shaders/rt_odfs/tonemap.frag similarity index 100% rename from fury/shaders/spherical_harmonics/tonemap.frag rename to fury/shaders/rt_odfs/tonemap.frag From 2dfde0b62cbd8e7f97b0bdf4df2fa4da22fddf38 Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Wed, 6 Dec 2023 16:25:41 -0500 Subject: [PATCH 028/118] Organized main code. --- .../SH-ODF experimental/ray_traced_1.py | 166 ++++++++++++------ 1 file changed, 117 insertions(+), 49 deletions(-) diff --git a/docs/experimental/SH-ODF experimental/ray_traced_1.py b/docs/experimental/SH-ODF experimental/ray_traced_1.py index 7c33154e1..9dd6707da 100644 --- a/docs/experimental/SH-ODF experimental/ray_traced_1.py +++ b/docs/experimental/SH-ODF experimental/ray_traced_1.py @@ -69,10 +69,10 @@ # considerably faster. def_gl_ext_control_flow_attributes = """ #ifndef _unroll_ - #define _unroll_ + #define _unroll_ #endif #ifndef _loop_ - #define _loop_ + #define _loop_ #endif """ @@ -258,53 +258,108 @@ shader_to_actor(odf_actor, "fragment", decl_code=fs_dec) - sdf_frag_impl = """ - vec3 pnt = vertexMCVSOutput.xyz; + point_from_vs = "vec3 pnt = vertexMCVSOutput.xyz;" - // Ray Origin - // Camera position in world space + # Ray origin is the camera position in world space + ray_origin = """ vec3 ro = (-MCVCMatrix[3] * MCVCMatrix).xyz; + //vec3 camera_pos = vec3(0.0, -5.0, 0.0); + //vec3 camera_pos = ro; + """ - // Ray Direction + # TODO: Check aspect for automatic scaling + # Ray direction is the normalized difference between the fragment and the + # camera position/ray origin + ray_direction = """ vec3 rd = normalize(pnt - ro); - - // Light Direction - vec3 ld = normalize(ro - pnt); - - ro += pnt - ro; - - vec2 frag_coord = gl_FragCoord.xy; - vec3 camera_pos = ro; //vec3(0.0, -5.0, 0.0); //float aspect = float(iResolution.x) / float(iResolution.y); - float aspect = 1; - float zoom = .8; - vec3 right = (aspect / zoom) * vec3(3.0, 0.0, 0.0); - vec3 up = (1.0 / zoom) * vec3(0.0, 0.0, 3.0); - vec3 bottom_left = -0.5 * (right + up); + //float aspect = 1; + //float zoom = .8; + //vec3 right = (aspect / zoom) * vec3(3.0, 0.0, 0.0); + //vec3 up = (1.0 / zoom) * vec3(0.0, 0.0, 3.0); + //vec3 bottom_left = -0.5 * (right + up); + //vec2 frag_coord = gl_FragCoord.xy; //vec2 uv = frag_coord / vec2(iResolution.xy); - vec3 ray_dir = rd; //normalize(bottom_left + uv.x * right + uv.y * up - camera_pos); - // Define SH coefficients (measured up to band 8, noise beyond that) + //vec3 ray_dir = normalize(bottom_left + uv.x * right + uv.y * up - camera_pos); + //vec3 ray_dir = rd; + """ + + # Light direction in a retroreflective model is the normalized difference + # between the camera position/ray origin and the fragment + light_direction = "vec3 ld = normalize(ro - pnt);" + + # Define SH coefficients (measured up to band 8, noise beyond that) + sh_coeffs = """ float sh_coeffs[SH_COUNT]; - sh_coeffs[0] = -0.2739740312099; sh_coeffs[1] = 0.2526670396328; sh_coeffs[2] = 1.8922271728516; sh_coeffs[3] = 0.2878578901291; sh_coeffs[4] = -0.5339795947075; sh_coeffs[5] = -0.2620058953762; -#if SH_DEGREE >= 4 - sh_coeffs[6] = 0.1580424904823; sh_coeffs[7] = 0.0329004973173; sh_coeffs[8] = -0.1322413831949; sh_coeffs[9] = -0.1332057565451; sh_coeffs[10] = 1.0894461870193; sh_coeffs[11] = -0.6319401264191; sh_coeffs[12] = -0.0416776277125; sh_coeffs[13] = -1.0772529840469; sh_coeffs[14] = 0.1423762738705; -#endif -#if SH_DEGREE >= 6 - sh_coeffs[15] = 0.7941166162491; sh_coeffs[16] = 0.7490307092667; sh_coeffs[17] = -0.3428381681442; sh_coeffs[18] = 0.1024847552180; sh_coeffs[19] = -0.0219132602215; sh_coeffs[20] = 0.0499043911695; sh_coeffs[21] = 0.2162453681231; sh_coeffs[22] = 0.0921059995890; sh_coeffs[23] = -0.2611238956451; sh_coeffs[24] = 0.2549301385880; sh_coeffs[25] = -0.4534865319729; sh_coeffs[26] = 0.1922748684883; sh_coeffs[27] = -0.6200597286224; -#endif -#if SH_DEGREE >= 8 - sh_coeffs[28] = -0.0532187558711; sh_coeffs[29] = -0.3569841980934; sh_coeffs[30] = 0.0293972902000; sh_coeffs[31] = -0.1977960765362; sh_coeffs[32] = -0.1058669015765; sh_coeffs[33] = 0.2372217923403; sh_coeffs[34] = -0.1856198310852; sh_coeffs[35] = -0.3373193442822; sh_coeffs[36] = -0.0750469490886; sh_coeffs[37] = 0.2146576642990; sh_coeffs[38] = -0.0490148440003; sh_coeffs[39] = 0.1288588196039; sh_coeffs[40] = 0.3173974752426; sh_coeffs[41] = 0.1990085393190; sh_coeffs[42] = -0.1736343950033; sh_coeffs[43] = -0.0482443645597; sh_coeffs[44] = 0.1749017387629; -#endif -#if SH_DEGREE >= 10 - sh_coeffs[45] = -0.0151847425660; sh_coeffs[46] = 0.0418366046081; sh_coeffs[47] = 0.0863263587216; sh_coeffs[48] = -0.0649211244490; sh_coeffs[49] = 0.0126096132283; sh_coeffs[50] = 0.0545089217982; sh_coeffs[51] = -0.0275142164626; sh_coeffs[52] = 0.0399986574832; sh_coeffs[53] = -0.0468244261610; sh_coeffs[54] = -0.1292105653111; sh_coeffs[55] = -0.0786858322658; sh_coeffs[56] = -0.0663828464882; sh_coeffs[57] = 0.0382439706831; sh_coeffs[58] = -0.0041550330365; sh_coeffs[59] = -0.0502800566338; sh_coeffs[60] = -0.0732471630735; sh_coeffs[61] = 0.0181751900972; sh_coeffs[62] = -0.0090119333757; sh_coeffs[63] = -0.0604443282359; sh_coeffs[64] = -0.1469985252752; sh_coeffs[65] = -0.0534046899715; -#endif -#if SH_DEGREE >= 12 - sh_coeffs[66] = -0.0896672753415; sh_coeffs[67] = -0.0130841364808; sh_coeffs[68] = -0.0112942893801; sh_coeffs[69] = 0.0272257498541; sh_coeffs[70] = 0.0626717616331; sh_coeffs[71] = -0.0222197983050; sh_coeffs[72] = -0.0018541504308; sh_coeffs[73] = -0.1653251944056; sh_coeffs[74] = 0.0409697402846; sh_coeffs[75] = 0.0749921454327; sh_coeffs[76] = -0.0282830872616; sh_coeffs[77] = 0.0006909458525; sh_coeffs[78] = 0.0625599842287; sh_coeffs[79] = 0.0812529816082; sh_coeffs[80] = 0.0914693020772; sh_coeffs[81] = -0.1197222726745; sh_coeffs[82] = 0.0376277453183; sh_coeffs[83] = -0.0832617004142; sh_coeffs[84] = -0.0482175038043; sh_coeffs[85] = -0.0839003635737; sh_coeffs[86] = -0.0349423908400; sh_coeffs[87] = 0.1204519568256; sh_coeffs[88] = 0.0783745984003; sh_coeffs[89] = 0.0297401205976; sh_coeffs[90] = -0.0505947662525; -#endif - // Perform the intersection test + sh_coeffs[0] = -0.2739740312099; sh_coeffs[1] = 0.2526670396328; + sh_coeffs[2] = 1.8922271728516; sh_coeffs[3] = 0.2878578901291; + sh_coeffs[4] = -0.5339795947075; sh_coeffs[5] = -0.2620058953762; + #if SH_DEGREE >= 4 + sh_coeffs[6] = 0.1580424904823; sh_coeffs[7] = 0.0329004973173; + sh_coeffs[8] = -0.1322413831949; sh_coeffs[9] = -0.1332057565451; + sh_coeffs[10] = 1.0894461870193; sh_coeffs[11] = -0.6319401264191; + sh_coeffs[12] = -0.0416776277125; sh_coeffs[13] = -1.0772529840469; + sh_coeffs[14] = 0.1423762738705; + #endif + #if SH_DEGREE >= 6 + sh_coeffs[15] = 0.7941166162491; sh_coeffs[16] = 0.7490307092667; + sh_coeffs[17] = -0.3428381681442; sh_coeffs[18] = 0.1024847552180; + sh_coeffs[19] = -0.0219132602215; sh_coeffs[20] = 0.0499043911695; + sh_coeffs[21] = 0.2162453681231; sh_coeffs[22] = 0.0921059995890; + sh_coeffs[23] = -0.2611238956451; sh_coeffs[24] = 0.2549301385880; + sh_coeffs[25] = -0.4534865319729; sh_coeffs[26] = 0.1922748684883; + sh_coeffs[27] = -0.6200597286224; + #endif + #if SH_DEGREE >= 8 + sh_coeffs[28] = -0.0532187558711; sh_coeffs[29] = -0.3569841980934; + sh_coeffs[30] = 0.0293972902000; sh_coeffs[31] = -0.1977960765362; + sh_coeffs[32] = -0.1058669015765; sh_coeffs[33] = 0.2372217923403; + sh_coeffs[34] = -0.1856198310852; sh_coeffs[35] = -0.3373193442822; + sh_coeffs[36] = -0.0750469490886; sh_coeffs[37] = 0.2146576642990; + sh_coeffs[38] = -0.0490148440003; sh_coeffs[39] = 0.1288588196039; + sh_coeffs[40] = 0.3173974752426; sh_coeffs[41] = 0.1990085393190; + sh_coeffs[42] = -0.1736343950033; sh_coeffs[43] = -0.0482443645597; + sh_coeffs[44] = 0.1749017387629; + #endif + #if SH_DEGREE >= 10 + sh_coeffs[45] = -0.0151847425660; sh_coeffs[46] = 0.0418366046081; + sh_coeffs[47] = 0.0863263587216; sh_coeffs[48] = -0.0649211244490; + sh_coeffs[49] = 0.0126096132283; sh_coeffs[50] = 0.0545089217982; + sh_coeffs[51] = -0.0275142164626; sh_coeffs[52] = 0.0399986574832; + sh_coeffs[53] = -0.0468244261610; sh_coeffs[54] = -0.1292105653111; + sh_coeffs[55] = -0.0786858322658; sh_coeffs[56] = -0.0663828464882; + sh_coeffs[57] = 0.0382439706831; sh_coeffs[58] = -0.0041550330365; + sh_coeffs[59] = -0.0502800566338; sh_coeffs[60] = -0.0732471630735; + sh_coeffs[61] = 0.0181751900972; sh_coeffs[62] = -0.0090119333757; + sh_coeffs[63] = -0.0604443282359; sh_coeffs[64] = -0.1469985252752; + sh_coeffs[65] = -0.0534046899715; + #endif + #if SH_DEGREE >= 12 + sh_coeffs[66] = -0.0896672753415; sh_coeffs[67] = -0.0130841364808; + sh_coeffs[68] = -0.0112942893801; sh_coeffs[69] = 0.0272257498541; + sh_coeffs[70] = 0.0626717616331; sh_coeffs[71] = -0.0222197983050; + sh_coeffs[72] = -0.0018541504308; sh_coeffs[73] = -0.1653251944056; + sh_coeffs[74] = 0.0409697402846; sh_coeffs[75] = 0.0749921454327; + sh_coeffs[76] = -0.0282830872616; sh_coeffs[77] = 0.0006909458525; + sh_coeffs[78] = 0.0625599842287; sh_coeffs[79] = 0.0812529816082; + sh_coeffs[80] = 0.0914693020772; sh_coeffs[81] = -0.1197222726745; + sh_coeffs[82] = 0.0376277453183; sh_coeffs[83] = -0.0832617004142; + sh_coeffs[84] = -0.0482175038043; sh_coeffs[85] = -0.0839003635737; + sh_coeffs[86] = -0.0349423908400; sh_coeffs[87] = 0.1204519568256; + sh_coeffs[88] = 0.0783745984003; sh_coeffs[89] = 0.0297401205976; + sh_coeffs[90] = -0.0505947662525; + #endif + """ + + # Perform the intersection test + intersection_test = """ float ray_params[MAX_DEGREE]; - ray_sh_glyph_intersections(ray_params, sh_coeffs, camera_pos, ray_dir); - // Identify the first intersection + //ray_sh_glyph_intersections(ray_params, sh_coeffs, camera_pos, ray_dir); + ray_sh_glyph_intersections(ray_params, sh_coeffs, ro, rd); + """ + + # Identify the first intersection + first_intersection = """ float first_ray_param = NO_INTERSECTION; _unroll_ for (int i = 0; i != MAX_DEGREE; ++i) { @@ -313,27 +368,40 @@ break; } } - // Evaluate shading for a directional light + """ + + # Evaluate shading for a directional light + directional_light = """ vec3 color = vec3(1.0); if (first_ray_param != NO_INTERSECTION) { - vec3 intersection = camera_pos + first_ray_param * ray_dir; + //vec3 intersection = camera_pos + first_ray_param * ray_dir; + vec3 intersection = ro + first_ray_param * rd; vec3 normal = get_sh_glyph_normal(sh_coeffs, intersection); vec3 base_color = srgb_to_linear_rgb(abs(normalize(intersection))); const vec3 incoming = normalize(vec3(1.23, -4.56, 7.89)); float ambient = 0.04; float exposure = 4.0; - vec3 outgoing = -ray_dir; + //vec3 outgoing = -ray_dir; + vec3 outgoing = -rd; vec3 brdf = gltf_dielectric_brdf(incoming, outgoing, normal, 0.45, base_color); color = exposure * (brdf * max(0.0, dot(incoming, normal)) + base_color * ambient); } - vec4 out_color = vec4(linear_rgb_to_srgb(tonemap(color)), 1.0); - fragOutput0 = out_color; + """ + frag_output = """ + //vec4 out_color = vec4(linear_rgb_to_srgb(tonemap(color)), 1.0); + vec3 out_color = linear_rgb_to_srgb(tonemap(color)); + fragOutput0 = vec4(out_color, opacity); """ - shader_to_actor( - odf_actor, "fragment", impl_code=sdf_frag_impl, block="picking" - ) + # fmt: off + fs_impl = compose_shader([ + point_from_vs, ray_origin, ray_direction, light_direction, sh_coeffs, + intersection_test, first_intersection, directional_light, frag_output + ]) + # fmt: on + + shader_to_actor(odf_actor, "fragment", impl_code=fs_impl, block="light") show_man.scene.add(odf_actor) From 4057e411168ea62128f5454828b4b350632d57d9 Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Tue, 19 Dec 2023 11:35:06 -0500 Subject: [PATCH 029/118] Created ray_traced_3.py to simplify ray_traced_1.py content. Removed BRDF functions. --- .../SH-ODF experimental/ray_traced_3.py | 389 ++++++++++++++++++ 1 file changed, 389 insertions(+) create mode 100644 docs/experimental/SH-ODF experimental/ray_traced_3.py diff --git a/docs/experimental/SH-ODF experimental/ray_traced_3.py b/docs/experimental/SH-ODF experimental/ray_traced_3.py new file mode 100644 index 000000000..1b3716e53 --- /dev/null +++ b/docs/experimental/SH-ODF experimental/ray_traced_3.py @@ -0,0 +1,389 @@ +""" +Fury's simplified version of the script ray_traced_1.py. +""" +import os + +import numpy as np + +from fury import actor, window +from fury.shaders import ( + attribute_to_actor, + compose_shader, + import_fury_shader, + shader_to_actor, +) + +if __name__ == "__main__": + show_man = window.ShowManager(size=(1280, 720)) + show_man.scene.background((1, 1, 1)) + + centers = np.array([[0, 0, 0]]) + scales = np.array([4]) + + odf_actor = actor.box(centers=centers, scales=scales) + + big_centers = np.repeat(centers, 8, axis=0) + attribute_to_actor(odf_actor, big_centers, "center") + + big_scales = np.repeat(scales, 8, axis=0) + attribute_to_actor(odf_actor, big_scales, "scale") + + vs_dec = """ + in vec3 center; + in float scale; + + out vec4 vertexMCVSOutput; + out vec3 centerMCVSOutput; + out float scaleVSOutput; + """ + + vs_impl = """ + vertexMCVSOutput = vertexMC; + centerMCVSOutput = center; + scaleVSOutput = scale; + vec3 camPos = -MCVCMatrix[3].xyz * mat3(MCVCMatrix); + """ + + shader_to_actor(odf_actor, "vertex", decl_code=vs_dec, impl_code=vs_impl) + + # The index of the highest used band of the spherical harmonics basis. Must + # be even, at least 2 and at most 12. + def_sh_degree = "#define SH_DEGREE 4" + + # The number of spherical harmonics basis functions + def_sh_count = "#define SH_COUNT (((SH_DEGREE + 1) * (SH_DEGREE + 2)) / 2)" + + # Degree of polynomials for which we have to find roots + def_max_degree = "#define MAX_DEGREE (2 * SH_DEGREE + 2)" + + # If GL_EXT_control_flow_attributes is available, these defines should be + # defined as [[unroll]] and [[loop]] to give reasonable hints to the + # compiler. That avoids register spilling, which makes execution + # considerably faster. + def_gl_ext_control_flow_attributes = """ + #ifndef _unroll_ + #define _unroll_ + #endif + #ifndef _loop_ + #define _loop_ + #endif + """ + + # When there are fewer intersections/roots than theoretically possible, + # some array entries are set to this value + def_no_intersection = "#define NO_INTERSECTION 3.4e38" + + # pi and its reciprocal + def_pis = """ + #define M_PI 3.141592653589793238462643 + #define M_INV_PI 0.318309886183790671537767526745 + """ + + fs_unifs = """ + uniform mat4 MCVCMatrix; + """ + + fs_vs_vars = """ + in vec4 vertexMCVSOutput; + in vec3 centerMCVSOutput; + in float scaleVSOutput; + """ + + eval_sh_2 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_2.frag")) + + eval_sh_4 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_4.frag")) + + eval_sh_6 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_6.frag")) + + eval_sh_8 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_8.frag")) + + eval_sh_10 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_10.frag")) + + eval_sh_12 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_12.frag")) + + eval_sh_grad_2 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_2.frag") + ) + + eval_sh_grad_4 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_4.frag") + ) + + eval_sh_grad_6 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_6.frag") + ) + + eval_sh_grad_8 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_8.frag") + ) + + eval_sh_grad_10 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_10.frag") + ) + + eval_sh_grad_12 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_12.frag") + ) + + # Searches a single root of a polynomial within a given interval. + # param out_root The location of the found root. + # param out_end_value The value of the given polynomial at end. + # param poly Coefficients of the polynomial for which a root should be + # found. + # Coefficient poly[i] is multiplied by x^i. + # param begin The beginning of an interval where the polynomial is + # monotonic. + # param end The end of said interval. + # param begin_value The value of the given polynomial at begin. + # param error_tolerance The error tolerance for the returned root + # location. + # Typically the error will be much lower but in theory it can be + # bigger. + # + # return true if a root was found, false if no root exists. + newton_bisection = import_fury_shader( + os.path.join("rt_odfs", "newton_bisection.frag") + ) + + # Finds all roots of the given polynomial in the interval [begin, end] and + # writes them to out_roots. Some entries will be NO_INTERSECTION but other + # than that the array is sorted. The last entry is always NO_INTERSECTION. + find_roots = import_fury_shader(os.path.join("rt_odfs", "find_roots.frag")) + + # Evaluates the spherical harmonics basis in bands 0, 2, ..., SH_DEGREE. + # Conventions are as in the following paper. + # M. Descoteaux, E. Angelino, S. Fitzgibbons, and R. Deriche. Regularized, + # fast, and robust analytical q-ball imaging. Magnetic Resonance in + # Medicine, 58(3), 2007. https://doi.org/10.1002/mrm.21277 + # param out_shs Values of SH basis functions in bands 0, 2, ..., + # SH_DEGREE in this order. + # param point The point on the unit sphere where the basis should be + # evaluated. + eval_sh = import_fury_shader(os.path.join("rt_odfs", "eval_sh.frag")) + + # Evaluates the gradient of each basis function given by eval_sh() and the + # basis itself + eval_sh_grad = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad.frag") + ) + + # Outputs a matrix that turns equidistant samples on the unit circle of a + # homogeneous polynomial into coefficients of that polynomial. + get_inv_vandermonde = import_fury_shader( + os.path.join("rt_odfs", "get_inv_vandermonde.frag") + ) + + # Determines all intersections between a ray and a spherical harmonics + # glyph. + # param out_ray_params The ray parameters at intersection points. The + # points themselves are at ray_origin + out_ray_params[i] * ray_dir. + # Some entries may be NO_INTERSECTION but other than that the array + # is sorted. + # param sh_coeffs SH_COUNT spherical harmonic coefficients defining the + # glyph. Their exact meaning is defined by eval_sh(). + # param ray_origin The origin of the ray, relative to the glyph center. + # param ray_dir The normalized direction vector of the ray. + ray_sh_glyph_intersections = import_fury_shader( + os.path.join("rt_odfs", "ray_sh_glyph_intersections.frag") + ) + + # Provides a normalized normal vector for a spherical harmonics glyph. + # param sh_coeffs SH_COUNT spherical harmonic coefficients defining the + # glyph. Their exact meaning is defined by eval_sh(). + # param point A point on the surface of the glyph, relative to its + # center. + # + # return A normalized surface normal pointing away from the origin. + get_sh_glyph_normal = import_fury_shader( + os.path.join("rt_odfs", "get_sh_glyph_normal.frag") + ) + + # Applies the non-linearity that maps linear RGB to sRGB + linear_to_srgb = import_fury_shader( + os.path.join("rt_odfs", "linear_to_srgb.frag") + ) + + # Inverse of linear_to_srgb() + srgb_to_linear = import_fury_shader( + os.path.join("rt_odfs", "srgb_to_linear.frag") + ) + + # Turns a linear RGB color (i.e. rec. 709) into sRGB + linear_rgb_to_srgb = import_fury_shader( + os.path.join("rt_odfs", "linear_rgb_to_srgb.frag") + ) + + # Inverse of linear_rgb_to_srgb() + srgb_to_linear_rgb = import_fury_shader( + os.path.join("rt_odfs", "srgb_to_linear_rgb.frag") + ) + + # Logarithmic tonemapping operator. Input and output are linear RGB. + tonemap = import_fury_shader(os.path.join("rt_odfs", "tonemap.frag")) + + # Blinn-Phong illumination model + blinn_phong_model = import_fury_shader( + os.path.join("lighting", "blinn_phong_model.frag") + ) + + # fmt: off + fs_dec = compose_shader([ + def_sh_degree, def_sh_count, def_max_degree, + def_gl_ext_control_flow_attributes, def_no_intersection, + def_pis, fs_unifs, fs_vs_vars, eval_sh_2, eval_sh_4, eval_sh_6, + eval_sh_8, eval_sh_10, eval_sh_12, eval_sh_grad_2, eval_sh_grad_4, + eval_sh_grad_6, eval_sh_grad_8, eval_sh_grad_10, eval_sh_grad_12, + newton_bisection, find_roots, eval_sh, eval_sh_grad, + get_inv_vandermonde, ray_sh_glyph_intersections, get_sh_glyph_normal, + blinn_phong_model, linear_to_srgb, srgb_to_linear, linear_rgb_to_srgb, + srgb_to_linear_rgb, tonemap + ]) + # fmt: on + + shader_to_actor(odf_actor, "fragment", decl_code=fs_dec) + + point_from_vs = "vec3 pnt = vertexMCVSOutput.xyz;" + + # Ray origin is the camera position in world space + ray_origin = """ + vec3 ro = (-MCVCMatrix[3] * MCVCMatrix).xyz; + //vec3 camera_pos = vec3(0.0, -5.0, 0.0); + //vec3 camera_pos = ro; + """ + + # TODO: Check aspect for automatic scaling + # Ray direction is the normalized difference between the fragment and the + # camera position/ray origin + ray_direction = """ + vec3 rd = normalize(pnt - ro); + //float aspect = float(iResolution.x) / float(iResolution.y); + //float aspect = 1; + //float zoom = .8; + //vec3 right = (aspect / zoom) * vec3(3.0, 0.0, 0.0); + //vec3 up = (1.0 / zoom) * vec3(0.0, 0.0, 3.0); + //vec3 bottom_left = -0.5 * (right + up); + //vec2 frag_coord = gl_FragCoord.xy; + //vec2 uv = frag_coord / vec2(iResolution.xy); + //vec3 ray_dir = normalize(bottom_left + uv.x * right + uv.y * up - camera_pos); + //vec3 ray_dir = rd; + """ + + # Light direction in a retroreflective model is the normalized difference + # between the camera position/ray origin and the fragment + light_direction = "vec3 ld = normalize(ro - pnt);" + + # Define SH coefficients (measured up to band 8, noise beyond that) + sh_coeffs = """ + float sh_coeffs[SH_COUNT]; + sh_coeffs[0] = -0.2739740312099; sh_coeffs[1] = 0.2526670396328; + sh_coeffs[2] = 1.8922271728516; sh_coeffs[3] = 0.2878578901291; + sh_coeffs[4] = -0.5339795947075; sh_coeffs[5] = -0.2620058953762; + #if SH_DEGREE >= 4 + sh_coeffs[6] = 0.1580424904823; sh_coeffs[7] = 0.0329004973173; + sh_coeffs[8] = -0.1322413831949; sh_coeffs[9] = -0.1332057565451; + sh_coeffs[10] = 1.0894461870193; sh_coeffs[11] = -0.6319401264191; + sh_coeffs[12] = -0.0416776277125; sh_coeffs[13] = -1.0772529840469; + sh_coeffs[14] = 0.1423762738705; + #endif + #if SH_DEGREE >= 6 + sh_coeffs[15] = 0.7941166162491; sh_coeffs[16] = 0.7490307092667; + sh_coeffs[17] = -0.3428381681442; sh_coeffs[18] = 0.1024847552180; + sh_coeffs[19] = -0.0219132602215; sh_coeffs[20] = 0.0499043911695; + sh_coeffs[21] = 0.2162453681231; sh_coeffs[22] = 0.0921059995890; + sh_coeffs[23] = -0.2611238956451; sh_coeffs[24] = 0.2549301385880; + sh_coeffs[25] = -0.4534865319729; sh_coeffs[26] = 0.1922748684883; + sh_coeffs[27] = -0.6200597286224; + #endif + #if SH_DEGREE >= 8 + sh_coeffs[28] = -0.0532187558711; sh_coeffs[29] = -0.3569841980934; + sh_coeffs[30] = 0.0293972902000; sh_coeffs[31] = -0.1977960765362; + sh_coeffs[32] = -0.1058669015765; sh_coeffs[33] = 0.2372217923403; + sh_coeffs[34] = -0.1856198310852; sh_coeffs[35] = -0.3373193442822; + sh_coeffs[36] = -0.0750469490886; sh_coeffs[37] = 0.2146576642990; + sh_coeffs[38] = -0.0490148440003; sh_coeffs[39] = 0.1288588196039; + sh_coeffs[40] = 0.3173974752426; sh_coeffs[41] = 0.1990085393190; + sh_coeffs[42] = -0.1736343950033; sh_coeffs[43] = -0.0482443645597; + sh_coeffs[44] = 0.1749017387629; + #endif + #if SH_DEGREE >= 10 + sh_coeffs[45] = -0.0151847425660; sh_coeffs[46] = 0.0418366046081; + sh_coeffs[47] = 0.0863263587216; sh_coeffs[48] = -0.0649211244490; + sh_coeffs[49] = 0.0126096132283; sh_coeffs[50] = 0.0545089217982; + sh_coeffs[51] = -0.0275142164626; sh_coeffs[52] = 0.0399986574832; + sh_coeffs[53] = -0.0468244261610; sh_coeffs[54] = -0.1292105653111; + sh_coeffs[55] = -0.0786858322658; sh_coeffs[56] = -0.0663828464882; + sh_coeffs[57] = 0.0382439706831; sh_coeffs[58] = -0.0041550330365; + sh_coeffs[59] = -0.0502800566338; sh_coeffs[60] = -0.0732471630735; + sh_coeffs[61] = 0.0181751900972; sh_coeffs[62] = -0.0090119333757; + sh_coeffs[63] = -0.0604443282359; sh_coeffs[64] = -0.1469985252752; + sh_coeffs[65] = -0.0534046899715; + #endif + #if SH_DEGREE >= 12 + sh_coeffs[66] = -0.0896672753415; sh_coeffs[67] = -0.0130841364808; + sh_coeffs[68] = -0.0112942893801; sh_coeffs[69] = 0.0272257498541; + sh_coeffs[70] = 0.0626717616331; sh_coeffs[71] = -0.0222197983050; + sh_coeffs[72] = -0.0018541504308; sh_coeffs[73] = -0.1653251944056; + sh_coeffs[74] = 0.0409697402846; sh_coeffs[75] = 0.0749921454327; + sh_coeffs[76] = -0.0282830872616; sh_coeffs[77] = 0.0006909458525; + sh_coeffs[78] = 0.0625599842287; sh_coeffs[79] = 0.0812529816082; + sh_coeffs[80] = 0.0914693020772; sh_coeffs[81] = -0.1197222726745; + sh_coeffs[82] = 0.0376277453183; sh_coeffs[83] = -0.0832617004142; + sh_coeffs[84] = -0.0482175038043; sh_coeffs[85] = -0.0839003635737; + sh_coeffs[86] = -0.0349423908400; sh_coeffs[87] = 0.1204519568256; + sh_coeffs[88] = 0.0783745984003; sh_coeffs[89] = 0.0297401205976; + sh_coeffs[90] = -0.0505947662525; + #endif + """ + + # Perform the intersection test + intersection_test = """ + float ray_params[MAX_DEGREE]; + ray_sh_glyph_intersections(ray_params, sh_coeffs, ro, rd); + """ + + # Identify the first intersection + first_intersection = """ + float first_ray_param = NO_INTERSECTION; + _unroll_ + for (int i = 0; i != MAX_DEGREE; ++i) { + if (ray_params[i] != NO_INTERSECTION && ray_params[i] > 0.0) { + first_ray_param = ray_params[i]; + break; + } + } + """ + + # Evaluate shading for a directional light + directional_light = """ + vec3 color = vec3(1.0); + if (first_ray_param != NO_INTERSECTION) { + vec3 intersection = ro + first_ray_param * rd; + vec3 normal = get_sh_glyph_normal(sh_coeffs, intersection); + vec3 colorDir = srgb_to_linear_rgb(abs(normalize(intersection))); + float attenuation = dot(ld, normal); + color = blinnPhongIllumModel( + //attenuation, lightColor0, diffuseColor, specularPower, + attenuation, lightColor0, colorDir, specularPower, + specularColor, ambientColor); + } + """ + + frag_output = """ + //vec4 out_color = vec4(linear_rgb_to_srgb(tonemap(color)), 1.0); + vec3 out_color = linear_rgb_to_srgb(tonemap(color)); + fragOutput0 = vec4(out_color, opacity); + //fragOutput0 = vec4(color, opacity); + """ + + # fmt: off + fs_impl = compose_shader([ + point_from_vs, ray_origin, ray_direction, light_direction, sh_coeffs, + intersection_test, first_intersection, directional_light, frag_output + ]) + # fmt: on + + shader_to_actor(odf_actor, "fragment", impl_code=fs_impl, block="light") + + show_man.scene.add(odf_actor) + + show_man.start() From a3ac4548fd773156ddf545a12b4225fbcd452baa Mon Sep 17 00:00:00 2001 From: tvcastillod Date: Tue, 19 Dec 2023 13:35:39 -0500 Subject: [PATCH 030/118] added SH efficient implementation to the base impl with texture --- .../SH-ODF experimental/ray_traced_2.py | 422 ++++++++++++++++++ 1 file changed, 422 insertions(+) create mode 100644 docs/experimental/SH-ODF experimental/ray_traced_2.py diff --git a/docs/experimental/SH-ODF experimental/ray_traced_2.py b/docs/experimental/SH-ODF experimental/ray_traced_2.py new file mode 100644 index 000000000..a95a958f2 --- /dev/null +++ b/docs/experimental/SH-ODF experimental/ray_traced_2.py @@ -0,0 +1,422 @@ +""" +Fury's implementation of "Ray Tracing Spherical Harmonics Glyphs": +https://momentsingraphics.de/VMV2023.html +The fragment shader is based on: https://www.shadertoy.com/view/dlGSDV +(c) 2023, Christoph Peters +This work is licensed under a CC0 1.0 Universal License. To the extent +possible under law, Christoph Peters has waived all copyright and related or +neighboring rights to the following code. This work is published from +Germany. https://creativecommons.org/publicdomain/zero/1.0/ +""" +import os + +import numpy as np + +from fury import actor, window +from fury.lib import FloatArray, Texture +from fury.shaders import ( + attribute_to_actor, + compose_shader, + import_fury_shader, + shader_to_actor, +) +from fury.utils import numpy_to_vtk_image_data, set_polydata_tcoords + + +def uv_calculations(n): + uvs = [] + for i in range (0,n): + a = (n-(i+1))/n + b = (n-i)/n + #glyph_coord [0, a], [0, b], [1, b], [1, a] + uvs.extend([[.1, a+.1], [.1, b-.1], [.9, b-.1], [.9, a+.1], + [.1, a+.1], [.1, b-.1], [.9, b-.1], [.9, a+.1]]) + return uvs + +if __name__ == "__main__": + show_man = window.ShowManager(size=(1920, 1080)) + show_man.scene.background((1, 1, 1)) + + # fmt: off + coeffs = np.array([ + [ + 0.2820735, 0.15236554, -0.04038717, -0.11270988, -0.04532376, + 0.14921817, 0.00257928, 0.0040734, -0.05313807, 0.03486542, + 0.04083064, 0.02105767, -0.04389586, -0.04302812, 0.1048641 + ], + [ + 0.28549338, 0.0978267, -0.11544838, 0.12525354, -0.00126003, + 0.00320594, 0.04744155, -0.07141446, 0.03211689, 0.04711322, + 0.08064896, 0.00154299, 0.00086506, 0.00162543, -0.00444893 + ], + [ + 0.28208936, -0.13133252, -0.04701012, -0.06303016, -0.0468775, + 0.02348355, 0.03991898, 0.02587433, 0.02645416, 0.00668765, + 0.00890633, 0.02189304, 0.00387415, 0.01665629, -0.01427194 + ] + ]) + # fmt: on + + centers = np.array([[0, -1, 0], [1, -1, 0], [2, -1, 0]]) + + odf_actor = actor.box(centers=centers, scales=1.0) + + big_centers = np.repeat(centers, 8, axis=0) + attribute_to_actor(odf_actor, big_centers, "center") + + minmax = np.array([coeffs.min(axis=1), coeffs.max(axis=1)]).T + big_minmax = np.repeat(minmax, 8, axis=0) + attribute_to_actor(odf_actor, big_minmax, "minmax") + + odf_actor_pd = odf_actor.GetMapper().GetInput() + + # fmt: off + uv_vals = np.array(uv_calculations(3)) + # fmt: on + + num_pnts = uv_vals.shape[0] + + t_coords = FloatArray() + t_coords.SetNumberOfComponents(2) + t_coords.SetNumberOfTuples(num_pnts) + [t_coords.SetTuple(i, uv_vals[i]) for i in range(num_pnts)] + + set_polydata_tcoords(odf_actor_pd, t_coords) + + min = coeffs.min(axis=1) + max = coeffs.max(axis=1) + newmin = 0 + newmax = 1 + arr = np.array( + [ + (coeffs[i] - min[i]) * ((newmax - newmin) / (max[i] - min[i])) + + newmin + for i in range(coeffs.shape[0]) + ] + ) + arr *= 255 + grid = numpy_to_vtk_image_data(arr.astype(np.uint8)) + + texture = Texture() + texture.SetInputDataObject(grid) + texture.Update() + + odf_actor.GetProperty().SetTexture("texture0", texture) + + # TODO: Set int uniform + odf_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniformf( + "numCoeffs", 15 + ) + + vs_dec = """ + in vec3 center; + in vec2 minmax; + + out vec4 vertexMCVSOutput; + out vec3 centerMCVSOutput; + out vec2 minmaxVSOutput; + """ + + vs_impl = """ + vertexMCVSOutput = vertexMC; + centerMCVSOutput = center; + minmaxVSOutput = minmax; + vec3 camPos = -MCVCMatrix[3].xyz * mat3(MCVCMatrix); + """ + + shader_to_actor(odf_actor, "vertex", decl_code=vs_dec, impl_code=vs_impl) + + # The index of the highest used band of the spherical harmonics basis. Must + # be even, at least 2 and at most 12. + def_sh_degree = "#define SH_DEGREE 4" + + # The number of spherical harmonics basis functions + def_sh_count = "#define SH_COUNT (((SH_DEGREE + 1) * (SH_DEGREE + 2)) / 2)" + + # Degree of polynomials for which we have to find roots + def_max_degree = "#define MAX_DEGREE (2 * SH_DEGREE + 2)" + + # If GL_EXT_control_flow_attributes is available, these defines should be + # defined as [[unroll]] and [[loop]] to give reasonable hints to the + # compiler. That avoids register spilling, which makes execution + # considerably faster. + def_gl_ext_control_flow_attributes = """ + #ifndef _unroll_ + #define _unroll_ + #endif + #ifndef _loop_ + #define _loop_ + #endif + """ + + # When there are fewer intersections/roots than theoretically possible, + # some array entries are set to this value + def_no_intersection = "#define NO_INTERSECTION 3.4e38" + + # pi and its reciprocal + def_pis = """ + #define M_PI 3.141592653589793238462643 + #define M_INV_PI 0.318309886183790671537767526745 + """ + + fs_unifs = """ + uniform mat4 MCVCMatrix; + """ + + fs_vs_vars = """ + in vec4 vertexMCVSOutput; + in vec3 centerMCVSOutput; + in vec2 minmaxVSOutput; + """ + + coeffs_norm = """ + float coeffsNorm(float coef) + { + float min = 0; + float max = 1; + float newMin = minmaxVSOutput.x; + float newMax = minmaxVSOutput.y; + return (coef - min) * ((newMax - newMin) / (max - min)) + newMin; + } + """ + + eval_sh_2 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_2.frag")) + + eval_sh_4 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_4.frag")) + + eval_sh_6 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_6.frag")) + + eval_sh_8 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_8.frag")) + + eval_sh_10 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_10.frag")) + + eval_sh_12 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_12.frag")) + + eval_sh_grad_2 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_2.frag") + ) + + eval_sh_grad_4 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_4.frag") + ) + + eval_sh_grad_6 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_6.frag") + ) + + eval_sh_grad_8 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_8.frag") + ) + + eval_sh_grad_10 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_10.frag") + ) + + eval_sh_grad_12 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_12.frag") + ) + + # Searches a single root of a polynomial within a given interval. + # param out_root The location of the found root. + # param out_end_value The value of the given polynomial at end. + # param poly Coefficients of the polynomial for which a root should be + # found. + # Coefficient poly[i] is multiplied by x^i. + # param begin The beginning of an interval where the polynomial is + # monotonic. + # param end The end of said interval. + # param begin_value The value of the given polynomial at begin. + # param error_tolerance The error tolerance for the returned root + # location. + # Typically the error will be much lower but in theory it can be + # bigger. + # + # return true if a root was found, false if no root exists. + newton_bisection = import_fury_shader( + os.path.join("rt_odfs", "newton_bisection.frag") + ) + + # Finds all roots of the given polynomial in the interval [begin, end] and + # writes them to out_roots. Some entries will be NO_INTERSECTION but other + # than that the array is sorted. The last entry is always NO_INTERSECTION. + find_roots = import_fury_shader(os.path.join("rt_odfs", "find_roots.frag")) + + # Evaluates the spherical harmonics basis in bands 0, 2, ..., SH_DEGREE. + # Conventions are as in the following paper. + # M. Descoteaux, E. Angelino, S. Fitzgibbons, and R. Deriche. Regularized, + # fast, and robust analytical q-ball imaging. Magnetic Resonance in + # Medicine, 58(3), 2007. https://doi.org/10.1002/mrm.21277 + # param out_shs Values of SH basis functions in bands 0, 2, ..., + # SH_DEGREE in this order. + # param point The point on the unit sphere where the basis should be + # evaluated. + eval_sh = import_fury_shader(os.path.join("rt_odfs", "eval_sh.frag")) + + # Evaluates the gradient of each basis function given by eval_sh() and the + # basis itself + eval_sh_grad = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad.frag") + ) + + # Outputs a matrix that turns equidistant samples on the unit circle of a + # homogeneous polynomial into coefficients of that polynomial. + get_inv_vandermonde = import_fury_shader( + os.path.join("rt_odfs", "get_inv_vandermonde.frag") + ) + + # Determines all intersections between a ray and a spherical harmonics + # glyph. + # param out_ray_params The ray parameters at intersection points. The + # points themselves are at ray_origin + out_ray_params[i] * ray_dir. + # Some entries may be NO_INTERSECTION but other than that the array + # is sorted. + # param sh_coeffs SH_COUNT spherical harmonic coefficients defining the + # glyph. Their exact meaning is defined by eval_sh(). + # param ray_origin The origin of the ray, relative to the glyph center. + # param ray_dir The normalized direction vector of the ray. + ray_sh_glyph_intersections = import_fury_shader( + os.path.join("rt_odfs", "ray_sh_glyph_intersections.frag") + ) + + # Provides a normalized normal vector for a spherical harmonics glyph. + # param sh_coeffs SH_COUNT spherical harmonic coefficients defining the + # glyph. Their exact meaning is defined by eval_sh(). + # param point A point on the surface of the glyph, relative to its + # center. + # + # return A normalized surface normal pointing away from the origin. + get_sh_glyph_normal = import_fury_shader( + os.path.join("rt_odfs", "get_sh_glyph_normal.frag") + ) + + # This is the glTF BRDF for dielectric materials, exactly as described + # here: + # https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#appendix-b-brdf-implementation + # param incoming The normalized incoming light direction. + # param outgoing The normalized outgoing light direction. + # param normal The normalized shading normal. + # param roughness An artist friendly roughness value between 0 and 1. + # param base_color The albedo used for the Lambertian diffuse component. + # + # return The BRDF for the given directions. + gltf_dielectric_brdf = import_fury_shader( + os.path.join("rt_odfs", "gltf_dielectric_brdf.frag") + ) + + # Applies the non-linearity that maps linear RGB to sRGB + linear_to_srgb = import_fury_shader( + os.path.join("rt_odfs", "linear_to_srgb.frag") + ) + + # Inverse of linear_to_srgb() + srgb_to_linear = import_fury_shader( + os.path.join("rt_odfs", "srgb_to_linear.frag") + ) + + # Turns a linear RGB color (i.e. rec. 709) into sRGB + linear_rgb_to_srgb = import_fury_shader( + os.path.join("rt_odfs", "linear_rgb_to_srgb.frag") + ) + + # Inverse of linear_rgb_to_srgb() + srgb_to_linear_rgb = import_fury_shader( + os.path.join("rt_odfs", "srgb_to_linear_rgb.frag") + ) + + # Logarithmic tonemapping operator. Input and output are linear RGB. + tonemap = import_fury_shader(os.path.join("rt_odfs", "tonemap.frag")) + + # fmt: off + fs_dec = compose_shader([ + def_sh_degree, def_sh_count, def_max_degree, + def_gl_ext_control_flow_attributes, def_no_intersection, + def_pis, fs_unifs, fs_vs_vars, coeffs_norm, eval_sh_2, eval_sh_4, eval_sh_6, + eval_sh_8, eval_sh_10, eval_sh_12, eval_sh_grad_2, eval_sh_grad_4, + eval_sh_grad_6, eval_sh_grad_8, eval_sh_grad_10, eval_sh_grad_12, + newton_bisection, find_roots, eval_sh, eval_sh_grad, + get_inv_vandermonde, ray_sh_glyph_intersections, get_sh_glyph_normal, + gltf_dielectric_brdf, linear_to_srgb, srgb_to_linear, + linear_rgb_to_srgb, srgb_to_linear_rgb, tonemap + ]) + # fmt: on + + shader_to_actor(odf_actor, "fragment", decl_code=fs_dec) + + point_from_vs = "vec3 pnt = vertexMCVSOutput.xyz;" + + # Ray origin is the camera position in world space + ray_origin = """ + vec3 ro = (-MCVCMatrix[3] * MCVCMatrix).xyz; + """ + + # TODO: Check aspect for automatic scaling + # Ray direction is the normalized difference between the fragment and the + # camera position/ray origin + ray_direction = """ + vec3 rd = normalize(pnt - ro); + """ + + # Light direction in a retroreflective model is the normalized difference + # between the camera position/ray origin and the fragment + light_direction = "vec3 ld = normalize(ro - pnt);" + + # Define SH coefficients (measured up to band 8, noise beyond that) + sh_coeffs = """ + float i = 1 / (numCoeffs * 2); + float sh_coeffs[SH_COUNT]; + for(int j=0; j 0.0) { + first_ray_param = ray_params[i]; + break; + } + } + """ + + # Evaluate shading for a directional light + directional_light = """ + vec3 color = vec3(0.5); + if (first_ray_param != NO_INTERSECTION) { + vec3 intersection = ro - centerMCVSOutput + first_ray_param * rd; + vec3 normal = get_sh_glyph_normal(sh_coeffs, intersection); + vec3 base_color = srgb_to_linear_rgb(abs(normalize(intersection))); + const vec3 incoming = normalize(vec3(1.23, -4.56, 7.89)); + float ambient = 0.04; + float exposure = 4.0; + vec3 outgoing = -rd; + vec3 brdf = gltf_dielectric_brdf(incoming, outgoing, normal, 0.45, base_color); + color = exposure * (brdf * max(0.0, dot(incoming, normal)) + base_color * ambient); + } + """ + + frag_output = """ + //vec4 out_color = vec4(linear_rgb_to_srgb(tonemap(color)), 1.0); + vec3 out_color = linear_rgb_to_srgb(tonemap(color)); + fragOutput0 = vec4(out_color, opacity); + """ + + # fmt: off + fs_impl = compose_shader([ + point_from_vs, ray_origin, ray_direction, light_direction, sh_coeffs, + intersection_test, first_intersection, directional_light, frag_output + ]) + # fmt: on + + shader_to_actor(odf_actor, "fragment", impl_code=fs_impl, block="picking") + show_man.scene.add(odf_actor) + + show_man.start() From b973e658e4f9d47fe047683966ef0f1f651ce37f Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Tue, 19 Dec 2023 13:48:55 -0500 Subject: [PATCH 031/118] Added minor changes to base Ray Tracing implementation (ray_traced_1.py). --- .../SH-ODF experimental/ray_traced_1.py | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/docs/experimental/SH-ODF experimental/ray_traced_1.py b/docs/experimental/SH-ODF experimental/ray_traced_1.py index 9dd6707da..29ecf894f 100644 --- a/docs/experimental/SH-ODF experimental/ray_traced_1.py +++ b/docs/experimental/SH-ODF experimental/ray_traced_1.py @@ -41,6 +41,7 @@ out vec4 vertexMCVSOutput; out vec3 centerMCVSOutput; + out vec3 camPosMCVSOutput; out float scaleVSOutput; """ @@ -48,7 +49,7 @@ vertexMCVSOutput = vertexMC; centerMCVSOutput = center; scaleVSOutput = scale; - vec3 camPos = -MCVCMatrix[3].xyz * mat3(MCVCMatrix); + camPosMCVSOutput = -MCVCMatrix[3].xyz * mat3(MCVCMatrix); """ shader_to_actor(odf_actor, "vertex", decl_code=vs_dec, impl_code=vs_impl) @@ -86,13 +87,10 @@ #define M_INV_PI 0.318309886183790671537767526745 """ - fs_unifs = """ - uniform mat4 MCVCMatrix; - """ - fs_vs_vars = """ in vec4 vertexMCVSOutput; in vec3 centerMCVSOutput; + in vec3 camPosMCVSOutput; in float scaleVSOutput; """ @@ -246,13 +244,13 @@ fs_dec = compose_shader([ def_sh_degree, def_sh_count, def_max_degree, def_gl_ext_control_flow_attributes, def_no_intersection, - def_pis, fs_unifs, fs_vs_vars, eval_sh_2, eval_sh_4, eval_sh_6, - eval_sh_8, eval_sh_10, eval_sh_12, eval_sh_grad_2, eval_sh_grad_4, - eval_sh_grad_6, eval_sh_grad_8, eval_sh_grad_10, eval_sh_grad_12, - newton_bisection, find_roots, eval_sh, eval_sh_grad, - get_inv_vandermonde, ray_sh_glyph_intersections, get_sh_glyph_normal, - gltf_dielectric_brdf, linear_to_srgb, srgb_to_linear, - linear_rgb_to_srgb, srgb_to_linear_rgb, tonemap + def_pis, fs_vs_vars, eval_sh_2, eval_sh_4, eval_sh_6, eval_sh_8, + eval_sh_10, eval_sh_12, eval_sh_grad_2, eval_sh_grad_4, eval_sh_grad_6, + eval_sh_grad_8, eval_sh_grad_10, eval_sh_grad_12, newton_bisection, + find_roots, eval_sh, eval_sh_grad, get_inv_vandermonde, + ray_sh_glyph_intersections, get_sh_glyph_normal, gltf_dielectric_brdf, + linear_to_srgb, srgb_to_linear, linear_rgb_to_srgb, srgb_to_linear_rgb, + tonemap ]) # fmt: on @@ -262,7 +260,7 @@ # Ray origin is the camera position in world space ray_origin = """ - vec3 ro = (-MCVCMatrix[3] * MCVCMatrix).xyz; + vec3 ro = camPosMCVSOutput; //vec3 camera_pos = vec3(0.0, -5.0, 0.0); //vec3 camera_pos = ro; """ From 02915dc00f929a1dff5b85b583fce27f1544fcd8 Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Tue, 19 Dec 2023 13:49:52 -0500 Subject: [PATCH 032/118] Minor changes on ray_traced_3.py. --- .../SH-ODF experimental/ray_traced_3.py | 46 +++++++++++-------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/docs/experimental/SH-ODF experimental/ray_traced_3.py b/docs/experimental/SH-ODF experimental/ray_traced_3.py index 1b3716e53..5ca2e3e74 100644 --- a/docs/experimental/SH-ODF experimental/ray_traced_3.py +++ b/docs/experimental/SH-ODF experimental/ray_traced_3.py @@ -34,6 +34,7 @@ out vec4 vertexMCVSOutput; out vec3 centerMCVSOutput; + out vec3 camPosMCVSOutput; out float scaleVSOutput; """ @@ -41,7 +42,7 @@ vertexMCVSOutput = vertexMC; centerMCVSOutput = center; scaleVSOutput = scale; - vec3 camPos = -MCVCMatrix[3].xyz * mat3(MCVCMatrix); + camPosMCVSOutput = -MCVCMatrix[3].xyz * mat3(MCVCMatrix); """ shader_to_actor(odf_actor, "vertex", decl_code=vs_dec, impl_code=vs_impl) @@ -79,13 +80,10 @@ #define M_INV_PI 0.318309886183790671537767526745 """ - fs_unifs = """ - uniform mat4 MCVCMatrix; - """ - fs_vs_vars = """ in vec4 vertexMCVSOutput; in vec3 centerMCVSOutput; + in vec3 camPosMCVSOutput; in float scaleVSOutput; """ @@ -230,13 +228,13 @@ fs_dec = compose_shader([ def_sh_degree, def_sh_count, def_max_degree, def_gl_ext_control_flow_attributes, def_no_intersection, - def_pis, fs_unifs, fs_vs_vars, eval_sh_2, eval_sh_4, eval_sh_6, - eval_sh_8, eval_sh_10, eval_sh_12, eval_sh_grad_2, eval_sh_grad_4, - eval_sh_grad_6, eval_sh_grad_8, eval_sh_grad_10, eval_sh_grad_12, - newton_bisection, find_roots, eval_sh, eval_sh_grad, - get_inv_vandermonde, ray_sh_glyph_intersections, get_sh_glyph_normal, - blinn_phong_model, linear_to_srgb, srgb_to_linear, linear_rgb_to_srgb, - srgb_to_linear_rgb, tonemap + def_pis, fs_vs_vars, eval_sh_2, eval_sh_4, eval_sh_6, eval_sh_8, + eval_sh_10, eval_sh_12, eval_sh_grad_2, eval_sh_grad_4, eval_sh_grad_6, + eval_sh_grad_8, eval_sh_grad_10, eval_sh_grad_12, newton_bisection, + find_roots, eval_sh, eval_sh_grad, get_inv_vandermonde, + ray_sh_glyph_intersections, get_sh_glyph_normal, blinn_phong_model, + linear_to_srgb, srgb_to_linear, linear_rgb_to_srgb, srgb_to_linear_rgb, + tonemap ]) # fmt: on @@ -246,9 +244,7 @@ # Ray origin is the camera position in world space ray_origin = """ - vec3 ro = (-MCVCMatrix[3] * MCVCMatrix).xyz; - //vec3 camera_pos = vec3(0.0, -5.0, 0.0); - //vec3 camera_pos = ro; + vec3 ro = camPosMCVSOutput; """ # TODO: Check aspect for automatic scaling @@ -256,16 +252,26 @@ # camera position/ray origin ray_direction = """ vec3 rd = normalize(pnt - ro); + /* //float aspect = float(iResolution.x) / float(iResolution.y); - //float aspect = 1; - //float zoom = .8; - //vec3 right = (aspect / zoom) * vec3(3.0, 0.0, 0.0); - //vec3 up = (1.0 / zoom) * vec3(0.0, 0.0, 3.0); - //vec3 bottom_left = -0.5 * (right + up); + float aspect = 1; + float zoom = .4; + //vec3 right = (aspect / zoom) * vec3(3., .0, .0); + vec3 right = vec3(MCVCMatrix[0][0], MCVCMatrix[1][0], MCVCMatrix[2][0]); + right *= aspect / zoom; + //vec3 up = (1 / zoom) * vec3(.0, .0, 3.); + vec3 up = vec3(MCVCMatrix[0][1], MCVCMatrix[1][1], MCVCMatrix[2][1]); + up *= 1 / zoom; + //vec3 bottom_left = -.5 * (right + up); + vec3 bottom_left = .0 * (right + up); //vec2 frag_coord = gl_FragCoord.xy; + vec2 frag_coord = pnt.xy; //vec2 uv = frag_coord / vec2(iResolution.xy); + vec2 uv = frag_coord / vec2(scaleVSOutput); //vec3 ray_dir = normalize(bottom_left + uv.x * right + uv.y * up - camera_pos); + vec3 rd = normalize(bottom_left + uv.x * right + uv.y * up - ro); //vec3 ray_dir = rd; + */ """ # Light direction in a retroreflective model is the normalized difference From 4880e4543806d052292ced72942212ff3b3c1f30 Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Tue, 19 Dec 2023 14:08:17 -0500 Subject: [PATCH 033/118] Minor changes in ray_traced_1.py --- docs/experimental/SH-ODF experimental/ray_traced_1.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/experimental/SH-ODF experimental/ray_traced_1.py b/docs/experimental/SH-ODF experimental/ray_traced_1.py index 29ecf894f..db819cac6 100644 --- a/docs/experimental/SH-ODF experimental/ray_traced_1.py +++ b/docs/experimental/SH-ODF experimental/ray_traced_1.py @@ -243,9 +243,9 @@ # fmt: off fs_dec = compose_shader([ def_sh_degree, def_sh_count, def_max_degree, - def_gl_ext_control_flow_attributes, def_no_intersection, - def_pis, fs_vs_vars, eval_sh_2, eval_sh_4, eval_sh_6, eval_sh_8, - eval_sh_10, eval_sh_12, eval_sh_grad_2, eval_sh_grad_4, eval_sh_grad_6, + def_gl_ext_control_flow_attributes, def_no_intersection, def_pis, + fs_vs_vars, eval_sh_2, eval_sh_4, eval_sh_6, eval_sh_8, eval_sh_10, + eval_sh_12, eval_sh_grad_2, eval_sh_grad_4, eval_sh_grad_6, eval_sh_grad_8, eval_sh_grad_10, eval_sh_grad_12, newton_bisection, find_roots, eval_sh, eval_sh_grad, get_inv_vandermonde, ray_sh_glyph_intersections, get_sh_glyph_normal, gltf_dielectric_brdf, From cc483cd866dfc96a9fc4e4b5a22e281d1ffde0e8 Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Tue, 19 Dec 2023 15:13:28 -0500 Subject: [PATCH 034/118] Forwarded camera right and up vectors. --- .../SH-ODF experimental/ray_traced_3.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/docs/experimental/SH-ODF experimental/ray_traced_3.py b/docs/experimental/SH-ODF experimental/ray_traced_3.py index 5ca2e3e74..5bef8329f 100644 --- a/docs/experimental/SH-ODF experimental/ray_traced_3.py +++ b/docs/experimental/SH-ODF experimental/ray_traced_3.py @@ -35,6 +35,8 @@ out vec4 vertexMCVSOutput; out vec3 centerMCVSOutput; out vec3 camPosMCVSOutput; + out vec3 camRightMCVSOutput; + out vec3 camUpMCVSOutput; out float scaleVSOutput; """ @@ -43,6 +45,10 @@ centerMCVSOutput = center; scaleVSOutput = scale; camPosMCVSOutput = -MCVCMatrix[3].xyz * mat3(MCVCMatrix); + camRightMCVSOutput = vec3( + MCVCMatrix[0][0], MCVCMatrix[1][0], MCVCMatrix[2][0]); + camUpMCVSOutput = vec3( + MCVCMatrix[0][1], MCVCMatrix[1][1], MCVCMatrix[2][1]); """ shader_to_actor(odf_actor, "vertex", decl_code=vs_dec, impl_code=vs_impl) @@ -84,6 +90,8 @@ in vec4 vertexMCVSOutput; in vec3 centerMCVSOutput; in vec3 camPosMCVSOutput; + in vec3 camRightMCVSOutput; + in vec3 camUpMCVSOutput; in float scaleVSOutput; """ @@ -251,27 +259,24 @@ # Ray direction is the normalized difference between the fragment and the # camera position/ray origin ray_direction = """ - vec3 rd = normalize(pnt - ro); - /* + //vec3 rd = normalize(pnt - ro); //float aspect = float(iResolution.x) / float(iResolution.y); float aspect = 1; float zoom = .4; //vec3 right = (aspect / zoom) * vec3(3., .0, .0); - vec3 right = vec3(MCVCMatrix[0][0], MCVCMatrix[1][0], MCVCMatrix[2][0]); - right *= aspect / zoom; + vec3 right = (aspect / zoom) * camRightMCVSOutput; //vec3 up = (1 / zoom) * vec3(.0, .0, 3.); - vec3 up = vec3(MCVCMatrix[0][1], MCVCMatrix[1][1], MCVCMatrix[2][1]); - up *= 1 / zoom; + vec3 up = (1 / zoom) * camUpMCVSOutput; //vec3 bottom_left = -.5 * (right + up); vec3 bottom_left = .0 * (right + up); //vec2 frag_coord = gl_FragCoord.xy; + // TODO: Use 3D point instead vec2 frag_coord = pnt.xy; //vec2 uv = frag_coord / vec2(iResolution.xy); vec2 uv = frag_coord / vec2(scaleVSOutput); //vec3 ray_dir = normalize(bottom_left + uv.x * right + uv.y * up - camera_pos); vec3 rd = normalize(bottom_left + uv.x * right + uv.y * up - ro); //vec3 ray_dir = rd; - */ """ # Light direction in a retroreflective model is the normalized difference From a9a6ffda0ec35e3cb877cda1c5bf8af694b649ce Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Fri, 22 Dec 2023 12:09:50 -0500 Subject: [PATCH 035/118] Used 3D point as frag_coord for uv mapping. --- docs/experimental/SH-ODF experimental/ray_traced_3.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/experimental/SH-ODF experimental/ray_traced_3.py b/docs/experimental/SH-ODF experimental/ray_traced_3.py index 5bef8329f..bed6c66d8 100644 --- a/docs/experimental/SH-ODF experimental/ray_traced_3.py +++ b/docs/experimental/SH-ODF experimental/ray_traced_3.py @@ -271,12 +271,14 @@ vec3 bottom_left = .0 * (right + up); //vec2 frag_coord = gl_FragCoord.xy; // TODO: Use 3D point instead - vec2 frag_coord = pnt.xy; + //vec2 frag_coord = pnt.xy; + vec3 frag_coord = pnt; //vec2 uv = frag_coord / vec2(iResolution.xy); - vec2 uv = frag_coord / vec2(scaleVSOutput); + //vec2 uv = frag_coord / vec2(scaleVSOutput); + vec3 uv = frag_coord / vec3(scaleVSOutput); //vec3 ray_dir = normalize(bottom_left + uv.x * right + uv.y * up - camera_pos); - vec3 rd = normalize(bottom_left + uv.x * right + uv.y * up - ro); - //vec3 ray_dir = rd; + //vec3 rd = normalize(bottom_left + uv.x * right + uv.y * up - ro); + vec3 rd = normalize(bottom_left + uv.x * right + uv.y * up + uv.z - ro); """ # Light direction in a retroreflective model is the normalized difference From ae9e554fdedea98a810cac07a7881b0ef8e8be46 Mon Sep 17 00:00:00 2001 From: tvcastillod Date: Thu, 25 Jan 2024 23:36:15 -0500 Subject: [PATCH 036/118] Tournier first implementation --- .../SH-ODF experimental/ray_traced_2.py | 4 +- .../texture_coefficients.py | 4 +- fury/shaders/rt_odfs/eval_sh_2 copy.frag | 23 ++++++++++ fury/shaders/rt_odfs/eval_sh_4 copy.frag | 46 +++++++++++++++++++ 4 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 fury/shaders/rt_odfs/eval_sh_2 copy.frag create mode 100644 fury/shaders/rt_odfs/eval_sh_4 copy.frag diff --git a/docs/experimental/SH-ODF experimental/ray_traced_2.py b/docs/experimental/SH-ODF experimental/ray_traced_2.py index a95a958f2..ba483e649 100644 --- a/docs/experimental/SH-ODF experimental/ray_traced_2.py +++ b/docs/experimental/SH-ODF experimental/ray_traced_2.py @@ -180,9 +180,9 @@ def uv_calculations(n): } """ - eval_sh_2 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_2.frag")) + eval_sh_2 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_2 copy.frag")) - eval_sh_4 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_4.frag")) + eval_sh_4 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_4 copy.frag")) eval_sh_6 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_6.frag")) diff --git a/docs/experimental/SH-ODF experimental/texture_coefficients.py b/docs/experimental/SH-ODF experimental/texture_coefficients.py index 7a841da6a..ba8e9d245 100644 --- a/docs/experimental/SH-ODF experimental/texture_coefficients.py +++ b/docs/experimental/SH-ODF experimental/texture_coefficients.py @@ -404,7 +404,7 @@ sphere = get_sphere("repulsion724") sh_basis = "descoteaux07" - # sh_basis = "tournier07" + sh_basis = "tournier07" sh_order = 4 sh = np.zeros((3, 1, 1, 15)) @@ -413,7 +413,7 @@ sh[2, 0, 0, :] = coeffs[2, :] tensor_sf = sh_to_sf( - sh, sh_order=sh_order, basis_type=sh_basis, sphere=sphere + sh, sh_order=sh_order, basis_type=sh_basis, sphere=sphere, legacy=False ) odf_slicer_actor = actor.odf_slicer( diff --git a/fury/shaders/rt_odfs/eval_sh_2 copy.frag b/fury/shaders/rt_odfs/eval_sh_2 copy.frag new file mode 100644 index 000000000..a70493a22 --- /dev/null +++ b/fury/shaders/rt_odfs/eval_sh_2 copy.frag @@ -0,0 +1,23 @@ +void eval_sh_2(out float out_shs[6], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; +} diff --git a/fury/shaders/rt_odfs/eval_sh_4 copy.frag b/fury/shaders/rt_odfs/eval_sh_4 copy.frag new file mode 100644 index 000000000..d9c41d2ea --- /dev/null +++ b/fury/shaders/rt_odfs/eval_sh_4 copy.frag @@ -0,0 +1,46 @@ +void eval_sh_4(out float out_shs[15], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = -c1 * d; + out_shs[2] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = -c1 * d; + out_shs[7] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; +} From f87a985ef0e526b2c196f1988986751ae77503e9 Mon Sep 17 00:00:00 2001 From: tvcastillod Date: Fri, 26 Jan 2024 11:19:05 -0500 Subject: [PATCH 037/118] updated files --- .../SH-ODF experimental/ray_traced_2.py | 4 +- .../SH-ODF experimental/ray_traced_4.py | 422 ++++++++++++++++++ 2 files changed, 424 insertions(+), 2 deletions(-) create mode 100644 docs/experimental/SH-ODF experimental/ray_traced_4.py diff --git a/docs/experimental/SH-ODF experimental/ray_traced_2.py b/docs/experimental/SH-ODF experimental/ray_traced_2.py index ba483e649..a95a958f2 100644 --- a/docs/experimental/SH-ODF experimental/ray_traced_2.py +++ b/docs/experimental/SH-ODF experimental/ray_traced_2.py @@ -180,9 +180,9 @@ def uv_calculations(n): } """ - eval_sh_2 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_2 copy.frag")) + eval_sh_2 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_2.frag")) - eval_sh_4 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_4 copy.frag")) + eval_sh_4 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_4.frag")) eval_sh_6 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_6.frag")) diff --git a/docs/experimental/SH-ODF experimental/ray_traced_4.py b/docs/experimental/SH-ODF experimental/ray_traced_4.py new file mode 100644 index 000000000..ba483e649 --- /dev/null +++ b/docs/experimental/SH-ODF experimental/ray_traced_4.py @@ -0,0 +1,422 @@ +""" +Fury's implementation of "Ray Tracing Spherical Harmonics Glyphs": +https://momentsingraphics.de/VMV2023.html +The fragment shader is based on: https://www.shadertoy.com/view/dlGSDV +(c) 2023, Christoph Peters +This work is licensed under a CC0 1.0 Universal License. To the extent +possible under law, Christoph Peters has waived all copyright and related or +neighboring rights to the following code. This work is published from +Germany. https://creativecommons.org/publicdomain/zero/1.0/ +""" +import os + +import numpy as np + +from fury import actor, window +from fury.lib import FloatArray, Texture +from fury.shaders import ( + attribute_to_actor, + compose_shader, + import_fury_shader, + shader_to_actor, +) +from fury.utils import numpy_to_vtk_image_data, set_polydata_tcoords + + +def uv_calculations(n): + uvs = [] + for i in range (0,n): + a = (n-(i+1))/n + b = (n-i)/n + #glyph_coord [0, a], [0, b], [1, b], [1, a] + uvs.extend([[.1, a+.1], [.1, b-.1], [.9, b-.1], [.9, a+.1], + [.1, a+.1], [.1, b-.1], [.9, b-.1], [.9, a+.1]]) + return uvs + +if __name__ == "__main__": + show_man = window.ShowManager(size=(1920, 1080)) + show_man.scene.background((1, 1, 1)) + + # fmt: off + coeffs = np.array([ + [ + 0.2820735, 0.15236554, -0.04038717, -0.11270988, -0.04532376, + 0.14921817, 0.00257928, 0.0040734, -0.05313807, 0.03486542, + 0.04083064, 0.02105767, -0.04389586, -0.04302812, 0.1048641 + ], + [ + 0.28549338, 0.0978267, -0.11544838, 0.12525354, -0.00126003, + 0.00320594, 0.04744155, -0.07141446, 0.03211689, 0.04711322, + 0.08064896, 0.00154299, 0.00086506, 0.00162543, -0.00444893 + ], + [ + 0.28208936, -0.13133252, -0.04701012, -0.06303016, -0.0468775, + 0.02348355, 0.03991898, 0.02587433, 0.02645416, 0.00668765, + 0.00890633, 0.02189304, 0.00387415, 0.01665629, -0.01427194 + ] + ]) + # fmt: on + + centers = np.array([[0, -1, 0], [1, -1, 0], [2, -1, 0]]) + + odf_actor = actor.box(centers=centers, scales=1.0) + + big_centers = np.repeat(centers, 8, axis=0) + attribute_to_actor(odf_actor, big_centers, "center") + + minmax = np.array([coeffs.min(axis=1), coeffs.max(axis=1)]).T + big_minmax = np.repeat(minmax, 8, axis=0) + attribute_to_actor(odf_actor, big_minmax, "minmax") + + odf_actor_pd = odf_actor.GetMapper().GetInput() + + # fmt: off + uv_vals = np.array(uv_calculations(3)) + # fmt: on + + num_pnts = uv_vals.shape[0] + + t_coords = FloatArray() + t_coords.SetNumberOfComponents(2) + t_coords.SetNumberOfTuples(num_pnts) + [t_coords.SetTuple(i, uv_vals[i]) for i in range(num_pnts)] + + set_polydata_tcoords(odf_actor_pd, t_coords) + + min = coeffs.min(axis=1) + max = coeffs.max(axis=1) + newmin = 0 + newmax = 1 + arr = np.array( + [ + (coeffs[i] - min[i]) * ((newmax - newmin) / (max[i] - min[i])) + + newmin + for i in range(coeffs.shape[0]) + ] + ) + arr *= 255 + grid = numpy_to_vtk_image_data(arr.astype(np.uint8)) + + texture = Texture() + texture.SetInputDataObject(grid) + texture.Update() + + odf_actor.GetProperty().SetTexture("texture0", texture) + + # TODO: Set int uniform + odf_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniformf( + "numCoeffs", 15 + ) + + vs_dec = """ + in vec3 center; + in vec2 minmax; + + out vec4 vertexMCVSOutput; + out vec3 centerMCVSOutput; + out vec2 minmaxVSOutput; + """ + + vs_impl = """ + vertexMCVSOutput = vertexMC; + centerMCVSOutput = center; + minmaxVSOutput = minmax; + vec3 camPos = -MCVCMatrix[3].xyz * mat3(MCVCMatrix); + """ + + shader_to_actor(odf_actor, "vertex", decl_code=vs_dec, impl_code=vs_impl) + + # The index of the highest used band of the spherical harmonics basis. Must + # be even, at least 2 and at most 12. + def_sh_degree = "#define SH_DEGREE 4" + + # The number of spherical harmonics basis functions + def_sh_count = "#define SH_COUNT (((SH_DEGREE + 1) * (SH_DEGREE + 2)) / 2)" + + # Degree of polynomials for which we have to find roots + def_max_degree = "#define MAX_DEGREE (2 * SH_DEGREE + 2)" + + # If GL_EXT_control_flow_attributes is available, these defines should be + # defined as [[unroll]] and [[loop]] to give reasonable hints to the + # compiler. That avoids register spilling, which makes execution + # considerably faster. + def_gl_ext_control_flow_attributes = """ + #ifndef _unroll_ + #define _unroll_ + #endif + #ifndef _loop_ + #define _loop_ + #endif + """ + + # When there are fewer intersections/roots than theoretically possible, + # some array entries are set to this value + def_no_intersection = "#define NO_INTERSECTION 3.4e38" + + # pi and its reciprocal + def_pis = """ + #define M_PI 3.141592653589793238462643 + #define M_INV_PI 0.318309886183790671537767526745 + """ + + fs_unifs = """ + uniform mat4 MCVCMatrix; + """ + + fs_vs_vars = """ + in vec4 vertexMCVSOutput; + in vec3 centerMCVSOutput; + in vec2 minmaxVSOutput; + """ + + coeffs_norm = """ + float coeffsNorm(float coef) + { + float min = 0; + float max = 1; + float newMin = minmaxVSOutput.x; + float newMax = minmaxVSOutput.y; + return (coef - min) * ((newMax - newMin) / (max - min)) + newMin; + } + """ + + eval_sh_2 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_2 copy.frag")) + + eval_sh_4 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_4 copy.frag")) + + eval_sh_6 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_6.frag")) + + eval_sh_8 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_8.frag")) + + eval_sh_10 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_10.frag")) + + eval_sh_12 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_12.frag")) + + eval_sh_grad_2 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_2.frag") + ) + + eval_sh_grad_4 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_4.frag") + ) + + eval_sh_grad_6 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_6.frag") + ) + + eval_sh_grad_8 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_8.frag") + ) + + eval_sh_grad_10 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_10.frag") + ) + + eval_sh_grad_12 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_12.frag") + ) + + # Searches a single root of a polynomial within a given interval. + # param out_root The location of the found root. + # param out_end_value The value of the given polynomial at end. + # param poly Coefficients of the polynomial for which a root should be + # found. + # Coefficient poly[i] is multiplied by x^i. + # param begin The beginning of an interval where the polynomial is + # monotonic. + # param end The end of said interval. + # param begin_value The value of the given polynomial at begin. + # param error_tolerance The error tolerance for the returned root + # location. + # Typically the error will be much lower but in theory it can be + # bigger. + # + # return true if a root was found, false if no root exists. + newton_bisection = import_fury_shader( + os.path.join("rt_odfs", "newton_bisection.frag") + ) + + # Finds all roots of the given polynomial in the interval [begin, end] and + # writes them to out_roots. Some entries will be NO_INTERSECTION but other + # than that the array is sorted. The last entry is always NO_INTERSECTION. + find_roots = import_fury_shader(os.path.join("rt_odfs", "find_roots.frag")) + + # Evaluates the spherical harmonics basis in bands 0, 2, ..., SH_DEGREE. + # Conventions are as in the following paper. + # M. Descoteaux, E. Angelino, S. Fitzgibbons, and R. Deriche. Regularized, + # fast, and robust analytical q-ball imaging. Magnetic Resonance in + # Medicine, 58(3), 2007. https://doi.org/10.1002/mrm.21277 + # param out_shs Values of SH basis functions in bands 0, 2, ..., + # SH_DEGREE in this order. + # param point The point on the unit sphere where the basis should be + # evaluated. + eval_sh = import_fury_shader(os.path.join("rt_odfs", "eval_sh.frag")) + + # Evaluates the gradient of each basis function given by eval_sh() and the + # basis itself + eval_sh_grad = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad.frag") + ) + + # Outputs a matrix that turns equidistant samples on the unit circle of a + # homogeneous polynomial into coefficients of that polynomial. + get_inv_vandermonde = import_fury_shader( + os.path.join("rt_odfs", "get_inv_vandermonde.frag") + ) + + # Determines all intersections between a ray and a spherical harmonics + # glyph. + # param out_ray_params The ray parameters at intersection points. The + # points themselves are at ray_origin + out_ray_params[i] * ray_dir. + # Some entries may be NO_INTERSECTION but other than that the array + # is sorted. + # param sh_coeffs SH_COUNT spherical harmonic coefficients defining the + # glyph. Their exact meaning is defined by eval_sh(). + # param ray_origin The origin of the ray, relative to the glyph center. + # param ray_dir The normalized direction vector of the ray. + ray_sh_glyph_intersections = import_fury_shader( + os.path.join("rt_odfs", "ray_sh_glyph_intersections.frag") + ) + + # Provides a normalized normal vector for a spherical harmonics glyph. + # param sh_coeffs SH_COUNT spherical harmonic coefficients defining the + # glyph. Their exact meaning is defined by eval_sh(). + # param point A point on the surface of the glyph, relative to its + # center. + # + # return A normalized surface normal pointing away from the origin. + get_sh_glyph_normal = import_fury_shader( + os.path.join("rt_odfs", "get_sh_glyph_normal.frag") + ) + + # This is the glTF BRDF for dielectric materials, exactly as described + # here: + # https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#appendix-b-brdf-implementation + # param incoming The normalized incoming light direction. + # param outgoing The normalized outgoing light direction. + # param normal The normalized shading normal. + # param roughness An artist friendly roughness value between 0 and 1. + # param base_color The albedo used for the Lambertian diffuse component. + # + # return The BRDF for the given directions. + gltf_dielectric_brdf = import_fury_shader( + os.path.join("rt_odfs", "gltf_dielectric_brdf.frag") + ) + + # Applies the non-linearity that maps linear RGB to sRGB + linear_to_srgb = import_fury_shader( + os.path.join("rt_odfs", "linear_to_srgb.frag") + ) + + # Inverse of linear_to_srgb() + srgb_to_linear = import_fury_shader( + os.path.join("rt_odfs", "srgb_to_linear.frag") + ) + + # Turns a linear RGB color (i.e. rec. 709) into sRGB + linear_rgb_to_srgb = import_fury_shader( + os.path.join("rt_odfs", "linear_rgb_to_srgb.frag") + ) + + # Inverse of linear_rgb_to_srgb() + srgb_to_linear_rgb = import_fury_shader( + os.path.join("rt_odfs", "srgb_to_linear_rgb.frag") + ) + + # Logarithmic tonemapping operator. Input and output are linear RGB. + tonemap = import_fury_shader(os.path.join("rt_odfs", "tonemap.frag")) + + # fmt: off + fs_dec = compose_shader([ + def_sh_degree, def_sh_count, def_max_degree, + def_gl_ext_control_flow_attributes, def_no_intersection, + def_pis, fs_unifs, fs_vs_vars, coeffs_norm, eval_sh_2, eval_sh_4, eval_sh_6, + eval_sh_8, eval_sh_10, eval_sh_12, eval_sh_grad_2, eval_sh_grad_4, + eval_sh_grad_6, eval_sh_grad_8, eval_sh_grad_10, eval_sh_grad_12, + newton_bisection, find_roots, eval_sh, eval_sh_grad, + get_inv_vandermonde, ray_sh_glyph_intersections, get_sh_glyph_normal, + gltf_dielectric_brdf, linear_to_srgb, srgb_to_linear, + linear_rgb_to_srgb, srgb_to_linear_rgb, tonemap + ]) + # fmt: on + + shader_to_actor(odf_actor, "fragment", decl_code=fs_dec) + + point_from_vs = "vec3 pnt = vertexMCVSOutput.xyz;" + + # Ray origin is the camera position in world space + ray_origin = """ + vec3 ro = (-MCVCMatrix[3] * MCVCMatrix).xyz; + """ + + # TODO: Check aspect for automatic scaling + # Ray direction is the normalized difference between the fragment and the + # camera position/ray origin + ray_direction = """ + vec3 rd = normalize(pnt - ro); + """ + + # Light direction in a retroreflective model is the normalized difference + # between the camera position/ray origin and the fragment + light_direction = "vec3 ld = normalize(ro - pnt);" + + # Define SH coefficients (measured up to band 8, noise beyond that) + sh_coeffs = """ + float i = 1 / (numCoeffs * 2); + float sh_coeffs[SH_COUNT]; + for(int j=0; j 0.0) { + first_ray_param = ray_params[i]; + break; + } + } + """ + + # Evaluate shading for a directional light + directional_light = """ + vec3 color = vec3(0.5); + if (first_ray_param != NO_INTERSECTION) { + vec3 intersection = ro - centerMCVSOutput + first_ray_param * rd; + vec3 normal = get_sh_glyph_normal(sh_coeffs, intersection); + vec3 base_color = srgb_to_linear_rgb(abs(normalize(intersection))); + const vec3 incoming = normalize(vec3(1.23, -4.56, 7.89)); + float ambient = 0.04; + float exposure = 4.0; + vec3 outgoing = -rd; + vec3 brdf = gltf_dielectric_brdf(incoming, outgoing, normal, 0.45, base_color); + color = exposure * (brdf * max(0.0, dot(incoming, normal)) + base_color * ambient); + } + """ + + frag_output = """ + //vec4 out_color = vec4(linear_rgb_to_srgb(tonemap(color)), 1.0); + vec3 out_color = linear_rgb_to_srgb(tonemap(color)); + fragOutput0 = vec4(out_color, opacity); + """ + + # fmt: off + fs_impl = compose_shader([ + point_from_vs, ray_origin, ray_direction, light_direction, sh_coeffs, + intersection_test, first_intersection, directional_light, frag_output + ]) + # fmt: on + + shader_to_actor(odf_actor, "fragment", impl_code=fs_impl, block="picking") + show_man.scene.add(odf_actor) + + show_man.start() From 1598f0e2090c539f08fc98cd50c0eab0fe935597 Mon Sep 17 00:00:00 2001 From: tvcastillod Date: Tue, 6 Feb 2024 10:07:53 -0500 Subject: [PATCH 038/118] added Tournier impl --- .../SH-ODF experimental/ray_traced_4.py | 43 +- .../SH-ODF experimental/ray_traced_5.py | 456 ++++++++++++++++++ fury/shaders/rt_odfs/eval_sh_10 copy.frag | 175 +++++++ fury/shaders/rt_odfs/eval_sh_12 copy.frag | 238 +++++++++ fury/shaders/rt_odfs/eval_sh_4 copy.frag | 4 +- fury/shaders/rt_odfs/eval_sh_6 copy.frag | 79 +++ fury/shaders/rt_odfs/eval_sh_8 copy.frag | 122 +++++ 7 files changed, 1108 insertions(+), 9 deletions(-) create mode 100644 docs/experimental/SH-ODF experimental/ray_traced_5.py create mode 100644 fury/shaders/rt_odfs/eval_sh_10 copy.frag create mode 100644 fury/shaders/rt_odfs/eval_sh_12 copy.frag create mode 100644 fury/shaders/rt_odfs/eval_sh_6 copy.frag create mode 100644 fury/shaders/rt_odfs/eval_sh_8 copy.frag diff --git a/docs/experimental/SH-ODF experimental/ray_traced_4.py b/docs/experimental/SH-ODF experimental/ray_traced_4.py index ba483e649..dea01d305 100644 --- a/docs/experimental/SH-ODF experimental/ray_traced_4.py +++ b/docs/experimental/SH-ODF experimental/ray_traced_4.py @@ -11,6 +11,8 @@ import os import numpy as np +from dipy.data import get_sphere +from dipy.reconst.shm import sh_to_sf from fury import actor, window from fury.lib import FloatArray, Texture @@ -53,11 +55,15 @@ def uv_calculations(n): 0.28208936, -0.13133252, -0.04701012, -0.06303016, -0.0468775, 0.02348355, 0.03991898, 0.02587433, 0.02645416, 0.00668765, 0.00890633, 0.02189304, 0.00387415, 0.01665629, -0.01427194 + ], + [ 2.82094529e-01, 7.05702620e-03, 3.20326265e-02, -2.88333917e-02, 5.33638381e-03, + 1.18306258e-02, -2.21964945e-04, 5.54136434e-04, 1.25108672e-03, -4.69248914e-03, + 4.30155475e-04, -1.15585609e-03, -4.69016480e-04, 1.44523500e-03, 3.96346915e-04 ] - ]) + ])*1.5 # fmt: on - centers = np.array([[0, -1, 0], [1, -1, 0], [2, -1, 0]]) + centers = np.array([[0, -1, 0], [1, -1, 0], [2, -1, 0], [3, -1, 0]]) odf_actor = actor.box(centers=centers, scales=1.0) @@ -71,7 +77,7 @@ def uv_calculations(n): odf_actor_pd = odf_actor.GetMapper().GetInput() # fmt: off - uv_vals = np.array(uv_calculations(3)) + uv_vals = np.array(uv_calculations(4)) # fmt: on num_pnts = uv_vals.shape[0] @@ -184,13 +190,13 @@ def uv_calculations(n): eval_sh_4 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_4 copy.frag")) - eval_sh_6 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_6.frag")) + eval_sh_6 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_6 copy.frag")) - eval_sh_8 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_8.frag")) + eval_sh_8 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_8 copy.frag")) - eval_sh_10 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_10.frag")) + eval_sh_10 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_10 copy.frag")) - eval_sh_12 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_12.frag")) + eval_sh_12 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_12 copy.frag")) eval_sh_grad_2 = import_fury_shader( os.path.join("rt_odfs", "eval_sh_grad_2.frag") @@ -400,6 +406,8 @@ def uv_calculations(n): vec3 outgoing = -rd; vec3 brdf = gltf_dielectric_brdf(incoming, outgoing, normal, 0.45, base_color); color = exposure * (brdf * max(0.0, dot(incoming, normal)) + base_color * ambient); + } else { + discard; } """ @@ -419,4 +427,25 @@ def uv_calculations(n): shader_to_actor(odf_actor, "fragment", impl_code=fs_impl, block="picking") show_man.scene.add(odf_actor) + sphere = get_sphere("repulsion724") + + sh_basis = "tournier07" + sh_order = 4 + + sh = np.zeros((4, 1, 1, 15)) + sh[0, 0, 0, :] = coeffs[0, :] + sh[1, 0, 0, :] = coeffs[1, :] + sh[2, 0, 0, :] = coeffs[2, :] + sh[3, 0, 0, :] = coeffs[3, :] + + tensor_sf = sh_to_sf( + sh, sh_order=sh_order, basis_type=sh_basis, sphere=sphere, legacy=False + ) + + odf_slicer_actor = actor.odf_slicer( + tensor_sf, sphere=sphere, scale=0.5, colormap="plasma" + ) + + show_man.scene.add(odf_slicer_actor) + show_man.start() diff --git a/docs/experimental/SH-ODF experimental/ray_traced_5.py b/docs/experimental/SH-ODF experimental/ray_traced_5.py new file mode 100644 index 000000000..dd30f9ee1 --- /dev/null +++ b/docs/experimental/SH-ODF experimental/ray_traced_5.py @@ -0,0 +1,456 @@ +""" +Fury's implementation of "Ray Tracing Spherical Harmonics Glyphs": +https://momentsingraphics.de/VMV2023.html +The fragment shader is based on: https://www.shadertoy.com/view/dlGSDV +(c) 2023, Christoph Peters +This work is licensed under a CC0 1.0 Universal License. To the extent +possible under law, Christoph Peters has waived all copyright and related or +neighboring rights to the following code. This work is published from +Germany. https://creativecommons.org/publicdomain/zero/1.0/ +""" +import os + +import numpy as np +from dipy.data import get_sphere +from dipy.reconst.shm import sh_to_sf + +from fury import actor, window +from fury.lib import FloatArray, Texture +from fury.shaders import ( + attribute_to_actor, + compose_shader, + import_fury_shader, + shader_to_actor, +) +from fury.utils import numpy_to_vtk_image_data, set_polydata_tcoords + + +def uv_calculations(n): + uvs = [] + for i in range (0,n): + a = (n-(i+1))/n + b = (n-i)/n + #glyph_coord [0, a], [0, b], [1, b], [1, a] + uvs.extend([[.01, a+.01], [.01, b-.01], [.99, b-.01], [.99, a+.01], + [.01, a+.01], [.01, b-.01], [.99, b-.01], [.99, a+.01]]) + return uvs + +if __name__ == "__main__": + show_man = window.ShowManager(size=(1920, 1080)) + show_man.scene.background((1, 1, 1)) + + # fmt: off + coeffs = np.array([ + [ + -0.2739740312099, 0.2526670396328, 1.8922271728516, 0.2878578901291, -0.5339795947075, + -0.2620058953762, 0.1580424904823, 0.0329004973173, -0.1322413831949, -0.1332057565451, + 1.0894461870193, -0.6319401264191, -0.0416776277125, -1.0772529840469, 0.1423762738705, + 0.7941166162491, 0.7490307092667, -0.3428381681442, 0.1024847552180, -0.0219132602215, + 0.0499043911695, 0.2162453681231, 0.0921059995890, -0.2611238956451, 0.2549301385880, + -0.4534865319729, 0.1922748684883, -0.6200597286224 + ] + ]) + + """ + , -0.0532187558711, -0.3569841980934, + 0.0293972902000, -0.1977960765362, -0.1058669015765, 0.2372217923403, -0.1856198310852, + -0.3373193442822, -0.0750469490886, 0.2146576642990, -0.0490148440003, 0.1288588196039, + 0.3173974752426, 0.1990085393190, -0.1736343950033, -0.0482443645597, 0.1749017387629, + -0.0151847425660, 0.0418366046081, 0.0863263587216, -0.0649211244490, 0.0126096132283, + 0.0545089217982, -0.0275142164626, 0.0399986574832, -0.0468244261610, -0.1292105653111, + -0.0786858322658, -0.0663828464882, 0.0382439706831, -0.0041550330365, -0.0502800566338, + -0.0732471630735, 0.0181751900972, -0.0090119333757, -0.0604443282359, -0.1469985252752, + -0.0534046899715, -0.0896672753415, -0.0130841364808, -0.0112942893801, 0.0272257498541, + 0.0626717616331, -0.0222197983050, -0.0018541504308, -0.1653251944056, 0.0409697402846, + 0.0749921454327, -0.0282830872616, 0.0006909458525, 0.0625599842287, 0.0812529816082, + 0.0914693020772, -0.1197222726745, 0.0376277453183, -0.0832617004142, -0.0482175038043, + -0.0839003635737, -0.0349423908400, 0.1204519568256, 0.0783745984003, 0.0297401205976, + -0.0505947662525 + """ + + centers = np.array([[0, -2.5, 0]]) + + odf_actor = actor.box(centers=centers, scales=4) + + big_centers = np.repeat(centers, 8, axis=0) + attribute_to_actor(odf_actor, big_centers, "center") + + minmax = np.array([coeffs.min(axis=1), coeffs.max(axis=1)]).T + big_minmax = np.repeat(minmax, 8, axis=0) + attribute_to_actor(odf_actor, big_minmax, "minmax") + + odf_actor_pd = odf_actor.GetMapper().GetInput() + + # fmt: off + uv_vals = np.array(uv_calculations(1)) + # fmt: on + + num_pnts = uv_vals.shape[0] + + t_coords = FloatArray() + t_coords.SetNumberOfComponents(2) + t_coords.SetNumberOfTuples(num_pnts) + [t_coords.SetTuple(i, uv_vals[i]) for i in range(num_pnts)] + + set_polydata_tcoords(odf_actor_pd, t_coords) + + min = coeffs.min(axis=1) + max = coeffs.max(axis=1) + newmin = 0 + newmax = 1 + arr = np.array( + [ + (coeffs[i] - min[i]) * ((newmax - newmin) / (max[i] - min[i])) + + newmin + for i in range(coeffs.shape[0]) + ] + ) + arr *= 255 + grid = numpy_to_vtk_image_data(arr.astype(np.uint8)) + + texture = Texture() + texture.SetInputDataObject(grid) + texture.Update() + + odf_actor.GetProperty().SetTexture("texture0", texture) + + # TODO: Set int uniform + odf_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniformf( + "numCoeffs", 28 + ) + + vs_dec = """ + in vec3 center; + in vec2 minmax; + + out vec4 vertexMCVSOutput; + out vec3 centerMCVSOutput; + out vec2 minmaxVSOutput; + """ + + vs_impl = """ + vertexMCVSOutput = vertexMC; + centerMCVSOutput = center; + minmaxVSOutput = minmax; + vec3 camPos = -MCVCMatrix[3].xyz * mat3(MCVCMatrix); + """ + + shader_to_actor(odf_actor, "vertex", decl_code=vs_dec, impl_code=vs_impl) + + # The index of the highest used band of the spherical harmonics basis. Must + # be even, at least 2 and at most 12. + def_sh_degree = "#define SH_DEGREE 6" + + # The number of spherical harmonics basis functions + def_sh_count = "#define SH_COUNT (((SH_DEGREE + 1) * (SH_DEGREE + 2)) / 2)" + + # Degree of polynomials for which we have to find roots + def_max_degree = "#define MAX_DEGREE (2 * SH_DEGREE + 2)" + + # If GL_EXT_control_flow_attributes is available, these defines should be + # defined as [[unroll]] and [[loop]] to give reasonable hints to the + # compiler. That avoids register spilling, which makes execution + # considerably faster. + def_gl_ext_control_flow_attributes = """ + #ifndef _unroll_ + #define _unroll_ + #endif + #ifndef _loop_ + #define _loop_ + #endif + """ + + # When there are fewer intersections/roots than theoretically possible, + # some array entries are set to this value + def_no_intersection = "#define NO_INTERSECTION 3.4e38" + + # pi and its reciprocal + def_pis = """ + #define M_PI 3.141592653589793238462643 + #define M_INV_PI 0.318309886183790671537767526745 + """ + + fs_unifs = """ + uniform mat4 MCVCMatrix; + """ + + fs_vs_vars = """ + in vec4 vertexMCVSOutput; + in vec3 centerMCVSOutput; + in vec2 minmaxVSOutput; + """ + + coeffs_norm = """ + float coeffsNorm(float coef) + { + float min = 0; + float max = 1; + float newMin = minmaxVSOutput.x; + float newMax = minmaxVSOutput.y; + return (coef - min) * ((newMax - newMin) / (max - min)) + newMin; + } + """ + + eval_sh_2 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_2.frag")) + + eval_sh_4 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_4.frag")) + + eval_sh_6 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_6.frag")) + + eval_sh_8 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_8.frag")) + + eval_sh_10 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_10.frag")) + + eval_sh_12 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_12.frag")) + + eval_sh_grad_2 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_2.frag") + ) + + eval_sh_grad_4 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_4.frag") + ) + + eval_sh_grad_6 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_6.frag") + ) + + eval_sh_grad_8 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_8.frag") + ) + + eval_sh_grad_10 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_10.frag") + ) + + eval_sh_grad_12 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_12.frag") + ) + + # Searches a single root of a polynomial within a given interval. + # param out_root The location of the found root. + # param out_end_value The value of the given polynomial at end. + # param poly Coefficients of the polynomial for which a root should be + # found. + # Coefficient poly[i] is multiplied by x^i. + # param begin The beginning of an interval where the polynomial is + # monotonic. + # param end The end of said interval. + # param begin_value The value of the given polynomial at begin. + # param error_tolerance The error tolerance for the returned root + # location. + # Typically the error will be much lower but in theory it can be + # bigger. + # + # return true if a root was found, false if no root exists. + newton_bisection = import_fury_shader( + os.path.join("rt_odfs", "newton_bisection.frag") + ) + + # Finds all roots of the given polynomial in the interval [begin, end] and + # writes them to out_roots. Some entries will be NO_INTERSECTION but other + # than that the array is sorted. The last entry is always NO_INTERSECTION. + find_roots = import_fury_shader(os.path.join("rt_odfs", "find_roots.frag")) + + # Evaluates the spherical harmonics basis in bands 0, 2, ..., SH_DEGREE. + # Conventions are as in the following paper. + # M. Descoteaux, E. Angelino, S. Fitzgibbons, and R. Deriche. Regularized, + # fast, and robust analytical q-ball imaging. Magnetic Resonance in + # Medicine, 58(3), 2007. https://doi.org/10.1002/mrm.21277 + # param out_shs Values of SH basis functions in bands 0, 2, ..., + # SH_DEGREE in this order. + # param point The point on the unit sphere where the basis should be + # evaluated. + eval_sh = import_fury_shader(os.path.join("rt_odfs", "eval_sh.frag")) + + # Evaluates the gradient of each basis function given by eval_sh() and the + # basis itself + eval_sh_grad = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad.frag") + ) + + # Outputs a matrix that turns equidistant samples on the unit circle of a + # homogeneous polynomial into coefficients of that polynomial. + get_inv_vandermonde = import_fury_shader( + os.path.join("rt_odfs", "get_inv_vandermonde.frag") + ) + + # Determines all intersections between a ray and a spherical harmonics + # glyph. + # param out_ray_params The ray parameters at intersection points. The + # points themselves are at ray_origin + out_ray_params[i] * ray_dir. + # Some entries may be NO_INTERSECTION but other than that the array + # is sorted. + # param sh_coeffs SH_COUNT spherical harmonic coefficients defining the + # glyph. Their exact meaning is defined by eval_sh(). + # param ray_origin The origin of the ray, relative to the glyph center. + # param ray_dir The normalized direction vector of the ray. + ray_sh_glyph_intersections = import_fury_shader( + os.path.join("rt_odfs", "ray_sh_glyph_intersections.frag") + ) + + # Provides a normalized normal vector for a spherical harmonics glyph. + # param sh_coeffs SH_COUNT spherical harmonic coefficients defining the + # glyph. Their exact meaning is defined by eval_sh(). + # param point A point on the surface of the glyph, relative to its + # center. + # + # return A normalized surface normal pointing away from the origin. + get_sh_glyph_normal = import_fury_shader( + os.path.join("rt_odfs", "get_sh_glyph_normal.frag") + ) + + # This is the glTF BRDF for dielectric materials, exactly as described + # here: + # https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#appendix-b-brdf-implementation + # param incoming The normalized incoming light direction. + # param outgoing The normalized outgoing light direction. + # param normal The normalized shading normal. + # param roughness An artist friendly roughness value between 0 and 1. + # param base_color The albedo used for the Lambertian diffuse component. + # + # return The BRDF for the given directions. + gltf_dielectric_brdf = import_fury_shader( + os.path.join("rt_odfs", "gltf_dielectric_brdf.frag") + ) + + # Applies the non-linearity that maps linear RGB to sRGB + linear_to_srgb = import_fury_shader( + os.path.join("rt_odfs", "linear_to_srgb.frag") + ) + + # Inverse of linear_to_srgb() + srgb_to_linear = import_fury_shader( + os.path.join("rt_odfs", "srgb_to_linear.frag") + ) + + # Turns a linear RGB color (i.e. rec. 709) into sRGB + linear_rgb_to_srgb = import_fury_shader( + os.path.join("rt_odfs", "linear_rgb_to_srgb.frag") + ) + + # Inverse of linear_rgb_to_srgb() + srgb_to_linear_rgb = import_fury_shader( + os.path.join("rt_odfs", "srgb_to_linear_rgb.frag") + ) + + # Logarithmic tonemapping operator. Input and output are linear RGB. + tonemap = import_fury_shader(os.path.join("rt_odfs", "tonemap.frag")) + + # fmt: off + fs_dec = compose_shader([ + def_sh_degree, def_sh_count, def_max_degree, + def_gl_ext_control_flow_attributes, def_no_intersection, + def_pis, fs_unifs, fs_vs_vars, coeffs_norm, eval_sh_2, eval_sh_4, eval_sh_6, + eval_sh_8, eval_sh_10, eval_sh_12, eval_sh_grad_2, eval_sh_grad_4, + eval_sh_grad_6, eval_sh_grad_8, eval_sh_grad_10, eval_sh_grad_12, + newton_bisection, find_roots, eval_sh, eval_sh_grad, + get_inv_vandermonde, ray_sh_glyph_intersections, get_sh_glyph_normal, + gltf_dielectric_brdf, linear_to_srgb, srgb_to_linear, + linear_rgb_to_srgb, srgb_to_linear_rgb, tonemap + ]) + # fmt: on + + shader_to_actor(odf_actor, "fragment", decl_code=fs_dec) + + point_from_vs = "vec3 pnt = vertexMCVSOutput.xyz;" + + # Ray origin is the camera position in world space + ray_origin = """ + vec3 ro = (-MCVCMatrix[3] * MCVCMatrix).xyz; + """ + + # TODO: Check aspect for automatic scaling + # Ray direction is the normalized difference between the fragment and the + # camera position/ray origin + ray_direction = """ + vec3 rd = normalize(pnt - ro); + """ + + # Light direction in a retroreflective model is the normalized difference + # between the camera position/ray origin and the fragment + light_direction = "vec3 ld = normalize(ro - pnt);" + + # Define SH coefficients (measured up to band 8, noise beyond that) + sh_coeffs = """ + float i = 1 / (numCoeffs * 2); + float sh_coeffs[SH_COUNT]; + for(int j=0; j 0.0) { + first_ray_param = ray_params[i]; + break; + } + } + """ + + # Evaluate shading for a directional light + directional_light = """ + vec3 color = vec3(0.5); + if (first_ray_param != NO_INTERSECTION) { + vec3 intersection = ro - centerMCVSOutput + first_ray_param * rd; + vec3 normal = get_sh_glyph_normal(sh_coeffs, intersection); + vec3 base_color = srgb_to_linear_rgb(abs(normalize(intersection))); + const vec3 incoming = normalize(vec3(1.23, -4.56, 7.89)); + float ambient = 0.04; + float exposure = 4.0; + vec3 outgoing = -rd; + vec3 brdf = gltf_dielectric_brdf(incoming, outgoing, normal, 0.45, base_color); + color = exposure * (brdf * max(0.0, dot(incoming, normal)) + base_color * ambient); + } else { + discard; + } + """ + + frag_output = """ + //vec4 out_color = vec4(linear_rgb_to_srgb(tonemap(color)), 1.0); + vec3 out_color = linear_rgb_to_srgb(tonemap(color)); + fragOutput0 = vec4(out_color, opacity); + """ + + # fmt: off + fs_impl = compose_shader([ + point_from_vs, ray_origin, ray_direction, light_direction, sh_coeffs, + intersection_test, first_intersection, directional_light, frag_output + ]) + # fmt: on + + shader_to_actor(odf_actor, "fragment", impl_code=fs_impl, block="picking") + show_man.scene.add(odf_actor) + #''' + sphere = get_sphere("repulsion724") + + sh_basis = "descoteaux07" + #sh_basis = "tournier07" + sh_order = 6 + + n = int((sh_order / 2) + 1) + sz = 2 * n ** 2 - n + sh = np.zeros((1, 1, 1, sz)) + sh[0, 0, 0, :] = coeffs[0, :sz] + + tensor_sf = sh_to_sf( + sh, sh_order=sh_order, basis_type=sh_basis, sphere=sphere, legacy=False + ) + + odf_slicer_actor = actor.odf_slicer( + tensor_sf, sphere=sphere, scale=1, colormap="plasma" + ) + + show_man.scene.add(odf_slicer_actor) + #''' + show_man.start() diff --git a/fury/shaders/rt_odfs/eval_sh_10 copy.frag b/fury/shaders/rt_odfs/eval_sh_10 copy.frag new file mode 100644 index 000000000..bac867d98 --- /dev/null +++ b/fury/shaders/rt_odfs/eval_sh_10 copy.frag @@ -0,0 +1,175 @@ +void eval_sh_10(out float out_shs[66], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + b = z2 * a - 0.250980392 * b; + a = b - 0.250773994 * a; + d = 233.240148813 * a; + out_shs[55] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[22] = c1 * d; + out_shs[20] = s1 * d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[37] = c1 * d; + out_shs[35] = s1 * d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + out_shs[56] = c1 * d; + out_shs[54] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[23] = c0 * d; + out_shs[19] = s0 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[38] = c0 * d; + out_shs[34] = s0 * d; + b = z2 * a - 0.235294118 * b; + a = b - 0.238390093 * a; + d = 272.365814381 * a; + out_shs[57] = c0 * d; + out_shs[53] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[24] = c1 * d; + out_shs[18] = s1 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[39] = c1 * d; + out_shs[33] = s1 * d; + a = z2 * b - 0.215686275 * a; + b = a - 0.222910217 * b; + d = -213.661323441 * b; + out_shs[58] = c1 * d; + out_shs[52] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[25] = c0 * d; + out_shs[17] = s0 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[40] = c0 * d; + out_shs[32] = s0 * d; + b = z2 * a - 0.188235294 * b; + a = b - 0.20123839 * a; + d = 151.081370682 * a; + out_shs[59] = c0 * d; + out_shs[51] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[26] = c1 * d; + out_shs[16] = s1 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[41] = c1 * d; + out_shs[31] = s1 * d; + a = z2 * b - 0.152941176 * a; + b = a - 0.173374613 * b; + d = -95.552248675 * b; + out_shs[60] = c1 * d; + out_shs[50] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[27] = c0 * d; + out_shs[15] = s0 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[42] = c0 * d; + out_shs[30] = s0 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + out_shs[61] = c0 * d; + out_shs[49] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[43] = c1 * d; + out_shs[29] = s1 * d; + a = (z2 - 5.88235294e-02) * z; + b = a - 9.90712074e-02 * z; + d = -25.910241313 * b; + out_shs[62] = c1 * d; + out_shs[48] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[44] = c0 * d; + out_shs[28] = s0 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + out_shs[63] = c0 * d; + out_shs[47] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + out_shs[64] = c1 * d; + out_shs[46] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + out_shs[65] = c0 * d; + out_shs[45] = s0 * d; +} diff --git a/fury/shaders/rt_odfs/eval_sh_12 copy.frag b/fury/shaders/rt_odfs/eval_sh_12 copy.frag new file mode 100644 index 000000000..3bad86fd4 --- /dev/null +++ b/fury/shaders/rt_odfs/eval_sh_12 copy.frag @@ -0,0 +1,238 @@ +void eval_sh_12(out float out_shs[91], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + b = z2 * a - 0.250980392 * b; + a = b - 0.250773994 * a; + d = 233.240148813 * a; + out_shs[55] = d; + b = z2 * a - 0.250626566 * b; + a = b - 0.250517598 * a; + d = 931.186918633 * a; + out_shs[78] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[22] = c1 * d; + out_shs[20] = s1 * d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[37] = c1 * d; + out_shs[35] = s1 * d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + out_shs[56] = c1 * d; + out_shs[54] = s1 * d; + a = z2 * b - 0.248120301 * a; + b = a - 0.248447205 * b; + d = -1265.233874957 * b; + out_shs[79] = c1 * d; + out_shs[77] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[23] = c0 * d; + out_shs[19] = s0 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[38] = c0 * d; + out_shs[34] = s0 * d; + b = z2 * a - 0.235294118 * b; + a = b - 0.238390093 * a; + d = 272.365814381 * a; + out_shs[57] = c0 * d; + out_shs[53] = s0 * d; + b = z2 * a - 0.240601504 * b; + a = b - 0.242236025 * a; + d = 1121.509962433 * a; + out_shs[80] = c0 * d; + out_shs[76] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[24] = c1 * d; + out_shs[18] = s1 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[39] = c1 * d; + out_shs[33] = s1 * d; + a = z2 * b - 0.215686275 * a; + b = a - 0.222910217 * b; + d = -213.661323441 * b; + out_shs[58] = c1 * d; + out_shs[52] = s1 * d; + a = z2 * b - 0.228070175 * a; + b = a - 0.231884058 * b; + d = -915.709049803 * b; + out_shs[81] = c1 * d; + out_shs[75] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[25] = c0 * d; + out_shs[17] = s0 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[40] = c0 * d; + out_shs[32] = s0 * d; + b = z2 * a - 0.188235294 * b; + a = b - 0.20123839 * a; + d = 151.081370682 * a; + out_shs[59] = c0 * d; + out_shs[51] = s0 * d; + b = z2 * a - 0.210526316 * b; + a = b - 0.217391304 * a; + d = 686.781787352 * a; + out_shs[82] = c0 * d; + out_shs[74] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[26] = c1 * d; + out_shs[16] = s1 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[41] = c1 * d; + out_shs[31] = s1 * d; + a = z2 * b - 0.152941176 * a; + b = a - 0.173374613 * b; + d = -95.552248675 * b; + out_shs[60] = c1 * d; + out_shs[50] = s1 * d; + a = z2 * b - 0.187969925 * a; + b = a - 0.198757764 * b; + d = -471.12841933 * b; + out_shs[83] = c1 * d; + out_shs[73] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[27] = c0 * d; + out_shs[15] = s0 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[42] = c0 * d; + out_shs[30] = s0 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + out_shs[61] = c0 * d; + out_shs[49] = s0 * d; + b = z2 * a - 0.160401003 * b; + a = b - 0.175983437 * a; + d = 293.800188384 * a; + out_shs[84] = c0 * d; + out_shs[72] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[43] = c1 * d; + out_shs[29] = s1 * d; + a = (z2 - 5.88235294e-02) * z; + b = a - 9.90712074e-02 * z; + d = -25.910241313 * b; + out_shs[62] = c1 * d; + out_shs[48] = s1 * d; + a = z2 * b - 0.127819549 * a; + b = a - 0.149068323 * b; + d = -165.101452729 * b; + out_shs[85] = c1 * d; + out_shs[71] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[44] = c0 * d; + out_shs[28] = s0 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + out_shs[63] = c0 * d; + out_shs[47] = s0 * d; + b = z2 * (a - 9.02255639e-02); + a = b - 0.118012422 * a; + d = 82.550726364 * a; + out_shs[86] = c0 * d; + out_shs[70] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + out_shs[64] = c1 * d; + out_shs[46] = s1 * d; + a = (z2 - 4.76190476e-02) * z; + b = a - 8.2815735e-02 * z; + d = -36.028090689 * b; + out_shs[87] = c1 * d; + out_shs[69] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + out_shs[65] = c0 * d; + out_shs[45] = s0 * d; + a = z2 - 4.34782609e-02; + d = 13.3042542 * a; + out_shs[88] = c0 * d; + out_shs[68] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.923210529 * z; + out_shs[89] = c1 * d; + out_shs[67] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.800821996; + out_shs[90] = c0 * d; + out_shs[66] = s0 * d; +} diff --git a/fury/shaders/rt_odfs/eval_sh_4 copy.frag b/fury/shaders/rt_odfs/eval_sh_4 copy.frag index d9c41d2ea..15335ccad 100644 --- a/fury/shaders/rt_odfs/eval_sh_4 copy.frag +++ b/fury/shaders/rt_odfs/eval_sh_4 copy.frag @@ -17,7 +17,7 @@ void eval_sh_4(out float out_shs[15], vec3 point) c1 = x; s1 = y; d = -1.092548431 * z; - out_shs[4] = -c1 * d; + out_shs[4] = c1 * d; out_shs[2] = s1 * d; a = (z2 - 0.2) * z; b = a - 0.228571429 * z; @@ -36,7 +36,7 @@ void eval_sh_4(out float out_shs[15], vec3 point) c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -1.77013077 * z; - out_shs[13] = -c1 * d; + out_shs[13] = c1 * d; out_shs[7] = s1 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; diff --git a/fury/shaders/rt_odfs/eval_sh_6 copy.frag b/fury/shaders/rt_odfs/eval_sh_6 copy.frag new file mode 100644 index 000000000..1051361dd --- /dev/null +++ b/fury/shaders/rt_odfs/eval_sh_6 copy.frag @@ -0,0 +1,79 @@ +void eval_sh_6(out float out_shs[28], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[22] = c1 * d; + out_shs[20] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[23] = c0 * d; + out_shs[19] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[24] = c1 * d; + out_shs[18] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[25] = c0 * d; + out_shs[17] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[26] = c1 * d; + out_shs[16] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[27] = c0 * d; + out_shs[15] = s0 * d; +} diff --git a/fury/shaders/rt_odfs/eval_sh_8 copy.frag b/fury/shaders/rt_odfs/eval_sh_8 copy.frag new file mode 100644 index 000000000..93c32e613 --- /dev/null +++ b/fury/shaders/rt_odfs/eval_sh_8 copy.frag @@ -0,0 +1,122 @@ +void eval_sh_8(out float out_shs[45], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[22] = c1 * d; + out_shs[20] = s1 * d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[37] = c1 * d; + out_shs[35] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[23] = c0 * d; + out_shs[19] = s0 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[38] = c0 * d; + out_shs[34] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[24] = c1 * d; + out_shs[18] = s1 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[39] = c1 * d; + out_shs[33] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[25] = c0 * d; + out_shs[17] = s0 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[40] = c0 * d; + out_shs[32] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[26] = c1 * d; + out_shs[16] = s1 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[41] = c1 * d; + out_shs[31] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[27] = c0 * d; + out_shs[15] = s0 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[42] = c0 * d; + out_shs[30] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[43] = c1 * d; + out_shs[29] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[44] = c0 * d; + out_shs[28] = s0 * d; +} From d5a387be4bb531e768acce552f77ced04e055eda Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Tue, 6 Feb 2024 11:36:16 -0500 Subject: [PATCH 039/118] Improved description of ray_traced_3.py --- docs/experimental/SH-ODF experimental/ray_traced_3.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/experimental/SH-ODF experimental/ray_traced_3.py b/docs/experimental/SH-ODF experimental/ray_traced_3.py index bed6c66d8..5e9a2aebd 100644 --- a/docs/experimental/SH-ODF experimental/ray_traced_3.py +++ b/docs/experimental/SH-ODF experimental/ray_traced_3.py @@ -1,6 +1,11 @@ """ Fury's simplified version of the script ray_traced_1.py. + - Simplified color calculation. + - Simplified lighting. +Improved scalability. + - Using scale from python properties. """ + import os import numpy as np From dd7ab4ce6d56191c2037a8553a8ca9b3a6f4dfd7 Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Thu, 8 Feb 2024 17:48:13 -0500 Subject: [PATCH 040/118] Prep for new ray_traced file. --- .../SH-ODF experimental/ray_traced_3.py | 25 ++++++------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/docs/experimental/SH-ODF experimental/ray_traced_3.py b/docs/experimental/SH-ODF experimental/ray_traced_3.py index 5e9a2aebd..4bfde2dcf 100644 --- a/docs/experimental/SH-ODF experimental/ray_traced_3.py +++ b/docs/experimental/SH-ODF experimental/ray_traced_3.py @@ -264,26 +264,17 @@ # Ray direction is the normalized difference between the fragment and the # camera position/ray origin ray_direction = """ - //vec3 rd = normalize(pnt - ro); + vec3 rd = normalize(pnt - ro); //float aspect = float(iResolution.x) / float(iResolution.y); - float aspect = 1; - float zoom = .4; - //vec3 right = (aspect / zoom) * vec3(3., .0, .0); - vec3 right = (aspect / zoom) * camRightMCVSOutput; - //vec3 up = (1 / zoom) * vec3(.0, .0, 3.); - vec3 up = (1 / zoom) * camUpMCVSOutput; - //vec3 bottom_left = -.5 * (right + up); - vec3 bottom_left = .0 * (right + up); + //float aspect = 1; + //float zoom = .8; + //vec3 right = (aspect / zoom) * vec3(3.0, 0.0, 0.0); + //vec3 up = (1.0 / zoom) * vec3(0.0, 0.0, 3.0); + //vec3 bottom_left = -0.5 * (right + up); //vec2 frag_coord = gl_FragCoord.xy; - // TODO: Use 3D point instead - //vec2 frag_coord = pnt.xy; - vec3 frag_coord = pnt; //vec2 uv = frag_coord / vec2(iResolution.xy); - //vec2 uv = frag_coord / vec2(scaleVSOutput); - vec3 uv = frag_coord / vec3(scaleVSOutput); //vec3 ray_dir = normalize(bottom_left + uv.x * right + uv.y * up - camera_pos); - //vec3 rd = normalize(bottom_left + uv.x * right + uv.y * up - ro); - vec3 rd = normalize(bottom_left + uv.x * right + uv.y * up + uv.z - ro); + //vec3 ray_dir = rd; """ # Light direction in a retroreflective model is the normalized difference @@ -373,7 +364,7 @@ # Evaluate shading for a directional light directional_light = """ - vec3 color = vec3(1.0); + vec3 color = vec3(1.); if (first_ray_param != NO_INTERSECTION) { vec3 intersection = ro + first_ray_param * rd; vec3 normal = get_sh_glyph_normal(sh_coeffs, intersection); From a3c861df92e84bd6096c10ed7e1ddb84ba44e3e3 Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Thu, 8 Feb 2024 18:37:07 -0500 Subject: [PATCH 041/118] Minor changes to ray_traced3.py --- docs/experimental/SH-ODF experimental/ray_traced_3.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/docs/experimental/SH-ODF experimental/ray_traced_3.py b/docs/experimental/SH-ODF experimental/ray_traced_3.py index 4bfde2dcf..0d865aa6e 100644 --- a/docs/experimental/SH-ODF experimental/ray_traced_3.py +++ b/docs/experimental/SH-ODF experimental/ray_traced_3.py @@ -2,8 +2,6 @@ Fury's simplified version of the script ray_traced_1.py. - Simplified color calculation. - Simplified lighting. -Improved scalability. - - Using scale from python properties. """ import os @@ -256,9 +254,7 @@ point_from_vs = "vec3 pnt = vertexMCVSOutput.xyz;" # Ray origin is the camera position in world space - ray_origin = """ - vec3 ro = camPosMCVSOutput; - """ + ray_origin = "vec3 ro = camPosMCVSOutput;" # TODO: Check aspect for automatic scaling # Ray direction is the normalized difference between the fragment and the From 6a1516a8054fe17d1be820e27386f0ce2591a558 Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Thu, 8 Feb 2024 18:37:57 -0500 Subject: [PATCH 042/118] Created ray_traced_6.py to fix scalability. --- .../SH-ODF experimental/ray_traced_6.py | 454 ++++++++++++++++++ 1 file changed, 454 insertions(+) create mode 100644 docs/experimental/SH-ODF experimental/ray_traced_6.py diff --git a/docs/experimental/SH-ODF experimental/ray_traced_6.py b/docs/experimental/SH-ODF experimental/ray_traced_6.py new file mode 100644 index 000000000..e546a51c2 --- /dev/null +++ b/docs/experimental/SH-ODF experimental/ray_traced_6.py @@ -0,0 +1,454 @@ +""" +Fury's improved version of the script ray_traced_2.py. + - Improved scalability using scale from python properties. +""" + +import os + +import numpy as np + +from fury import actor, window +from fury.lib import FloatArray, Texture +from fury.shaders import ( + attribute_to_actor, + compose_shader, + import_fury_shader, + shader_to_actor, +) +from fury.utils import numpy_to_vtk_image_data, set_polydata_tcoords + + +def uv_calculations(n): + uvs = [] + for i in range(0, n): + a = (n - (i + 1)) / n + b = (n - i) / n + # glyph_coord [0, a], [0, b], [1, b], [1, a] + uvs.extend( + [ + [0.1, a + 0.1], + [0.1, b - 0.1], + [0.9, b - 0.1], + [0.9, a + 0.1], + [0.1, a + 0.1], + [0.1, b - 0.1], + [0.9, b - 0.1], + [0.9, a + 0.1], + ] + ) + return uvs + + +if __name__ == "__main__": + show_man = window.ShowManager(size=(1280, 720)) + show_man.scene.background((1, 1, 1)) + + # fmt: off + coeffs = np.array([ + [ + 0.2820735, 0.15236554, -0.04038717, -0.11270988, -0.04532376, + 0.14921817, 0.00257928, 0.0040734, -0.05313807, 0.03486542, + 0.04083064, 0.02105767, -0.04389586, -0.04302812, 0.1048641 + ], + [ + 0.28549338, 0.0978267, -0.11544838, 0.12525354, -0.00126003, + 0.00320594, 0.04744155, -0.07141446, 0.03211689, 0.04711322, + 0.08064896, 0.00154299, 0.00086506, 0.00162543, -0.00444893 + ], + [ + 0.28208936, -0.13133252, -0.04701012, -0.06303016, -0.0468775, + 0.02348355, 0.03991898, 0.02587433, 0.02645416, 0.00668765, + 0.00890633, 0.02189304, 0.00387415, 0.01665629, -0.01427194 + ] + ]) + # fmt: on + + centers = np.array([[-1, 1, 0], [0, 0, 0], [2, -2, 0]]) + scales = np.array([0.5, 1, 2]) + + odf_actor = actor.box(centers=centers, scales=scales) + + big_centers = np.repeat(centers, 8, axis=0) + attribute_to_actor(odf_actor, big_centers, "center") + + big_scales = np.repeat(scales, 8, axis=0) + attribute_to_actor(odf_actor, big_scales, "scale") + + minmax = np.array([coeffs.min(axis=1), coeffs.max(axis=1)]).T + big_minmax = np.repeat(minmax, 8, axis=0) + attribute_to_actor(odf_actor, big_minmax, "minmax") + + odf_actor_pd = odf_actor.GetMapper().GetInput() + + uv_vals = np.array(uv_calculations(3)) + + num_pnts = uv_vals.shape[0] + + t_coords = FloatArray() + t_coords.SetNumberOfComponents(2) + t_coords.SetNumberOfTuples(num_pnts) + [t_coords.SetTuple(i, uv_vals[i]) for i in range(num_pnts)] + + set_polydata_tcoords(odf_actor_pd, t_coords) + + min = coeffs.min(axis=1) + max = coeffs.max(axis=1) + newmin = 0 + newmax = 1 + arr = np.array( + [ + (coeffs[i] - min[i]) * ((newmax - newmin) / (max[i] - min[i])) + + newmin + for i in range(coeffs.shape[0]) + ] + ) + arr *= 255 + grid = numpy_to_vtk_image_data(arr.astype(np.uint8)) + + texture = Texture() + texture.SetInputDataObject(grid) + texture.Update() + + odf_actor.GetProperty().SetTexture("texture0", texture) + + # TODO: Set int uniform + odf_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniformf( + "numCoeffs", 15 + ) + + vs_dec = """ + in vec3 center; + in vec2 minmax; + in float scale; + + out vec4 vertexMCVSOutput; + out vec3 centerMCVSOutput; + out vec2 minmaxVSOutput; + out vec3 camPosMCVSOutput; + out vec3 camRightMCVSOutput; + out vec3 camUpMCVSOutput; + out float scaleVSOutput; + """ + + vs_impl = """ + vertexMCVSOutput = vertexMC; + centerMCVSOutput = center; + minmaxVSOutput = minmax; + scaleVSOutput = scale; + camPosMCVSOutput = -MCVCMatrix[3].xyz * mat3(MCVCMatrix); + camRightMCVSOutput = vec3( + MCVCMatrix[0][0], MCVCMatrix[1][0], MCVCMatrix[2][0]); + camUpMCVSOutput = vec3( + MCVCMatrix[0][1], MCVCMatrix[1][1], MCVCMatrix[2][1]); + """ + + shader_to_actor(odf_actor, "vertex", decl_code=vs_dec, impl_code=vs_impl) + + # The index of the highest used band of the spherical harmonics basis. Must + # be even, at least 2 and at most 12. + def_sh_degree = "#define SH_DEGREE 4" + + # The number of spherical harmonics basis functions + def_sh_count = "#define SH_COUNT (((SH_DEGREE + 1) * (SH_DEGREE + 2)) / 2)" + + # Degree of polynomials for which we have to find roots + def_max_degree = "#define MAX_DEGREE (2 * SH_DEGREE + 2)" + + # If GL_EXT_control_flow_attributes is available, these defines should be + # defined as [[unroll]] and [[loop]] to give reasonable hints to the + # compiler. That avoids register spilling, which makes execution + # considerably faster. + def_gl_ext_control_flow_attributes = """ + #ifndef _unroll_ + #define _unroll_ + #endif + #ifndef _loop_ + #define _loop_ + #endif + """ + + # When there are fewer intersections/roots than theoretically possible, + # some array entries are set to this value + def_no_intersection = "#define NO_INTERSECTION 3.4e38" + + # pi and its reciprocal + def_pis = """ + #define M_PI 3.141592653589793238462643 + #define M_INV_PI 0.318309886183790671537767526745 + """ + + fs_vs_vars = """ + in vec4 vertexMCVSOutput; + in vec3 centerMCVSOutput; + in vec2 minmaxVSOutput; + in vec3 camPosMCVSOutput; + in vec3 camRightMCVSOutput; + in vec3 camUpMCVSOutput; + in float scaleVSOutput; + """ + + coeffs_norm = """ + float coeffsNorm(float coef) + { + float min = 0; + float max = 1; + float newMin = minmaxVSOutput.x; + float newMax = minmaxVSOutput.y; + return (coef - min) * ((newMax - newMin) / (max - min)) + newMin; + } + """ + + eval_sh_2 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_2.frag")) + + eval_sh_4 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_4.frag")) + + eval_sh_6 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_6.frag")) + + eval_sh_8 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_8.frag")) + + eval_sh_10 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_10.frag")) + + eval_sh_12 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_12.frag")) + + eval_sh_grad_2 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_2.frag") + ) + + eval_sh_grad_4 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_4.frag") + ) + + eval_sh_grad_6 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_6.frag") + ) + + eval_sh_grad_8 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_8.frag") + ) + + eval_sh_grad_10 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_10.frag") + ) + + eval_sh_grad_12 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_12.frag") + ) + + # Searches a single root of a polynomial within a given interval. + # param out_root The location of the found root. + # param out_end_value The value of the given polynomial at end. + # param poly Coefficients of the polynomial for which a root should be + # found. + # Coefficient poly[i] is multiplied by x^i. + # param begin The beginning of an interval where the polynomial is + # monotonic. + # param end The end of said interval. + # param begin_value The value of the given polynomial at begin. + # param error_tolerance The error tolerance for the returned root + # location. + # Typically the error will be much lower but in theory it can be + # bigger. + # + # return true if a root was found, false if no root exists. + newton_bisection = import_fury_shader( + os.path.join("rt_odfs", "newton_bisection.frag") + ) + + # Finds all roots of the given polynomial in the interval [begin, end] and + # writes them to out_roots. Some entries will be NO_INTERSECTION but other + # than that the array is sorted. The last entry is always NO_INTERSECTION. + find_roots = import_fury_shader(os.path.join("rt_odfs", "find_roots.frag")) + + # Evaluates the spherical harmonics basis in bands 0, 2, ..., SH_DEGREE. + # Conventions are as in the following paper. + # M. Descoteaux, E. Angelino, S. Fitzgibbons, and R. Deriche. Regularized, + # fast, and robust analytical q-ball imaging. Magnetic Resonance in + # Medicine, 58(3), 2007. https://doi.org/10.1002/mrm.21277 + # param out_shs Values of SH basis functions in bands 0, 2, ..., + # SH_DEGREE in this order. + # param point The point on the unit sphere where the basis should be + # evaluated. + eval_sh = import_fury_shader(os.path.join("rt_odfs", "eval_sh.frag")) + + # Evaluates the gradient of each basis function given by eval_sh() and the + # basis itself + eval_sh_grad = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad.frag") + ) + + # Outputs a matrix that turns equidistant samples on the unit circle of a + # homogeneous polynomial into coefficients of that polynomial. + get_inv_vandermonde = import_fury_shader( + os.path.join("rt_odfs", "get_inv_vandermonde.frag") + ) + + # Determines all intersections between a ray and a spherical harmonics + # glyph. + # param out_ray_params The ray parameters at intersection points. The + # points themselves are at ray_origin + out_ray_params[i] * ray_dir. + # Some entries may be NO_INTERSECTION but other than that the array + # is sorted. + # param sh_coeffs SH_COUNT spherical harmonic coefficients defining the + # glyph. Their exact meaning is defined by eval_sh(). + # param ray_origin The origin of the ray, relative to the glyph center. + # param ray_dir The normalized direction vector of the ray. + ray_sh_glyph_intersections = import_fury_shader( + os.path.join("rt_odfs", "ray_sh_glyph_intersections.frag") + ) + + # Provides a normalized normal vector for a spherical harmonics glyph. + # param sh_coeffs SH_COUNT spherical harmonic coefficients defining the + # glyph. Their exact meaning is defined by eval_sh(). + # param point A point on the surface of the glyph, relative to its + # center. + # + # return A normalized surface normal pointing away from the origin. + get_sh_glyph_normal = import_fury_shader( + os.path.join("rt_odfs", "get_sh_glyph_normal.frag") + ) + + # Applies the non-linearity that maps linear RGB to sRGB + linear_to_srgb = import_fury_shader( + os.path.join("rt_odfs", "linear_to_srgb.frag") + ) + + # Inverse of linear_to_srgb() + srgb_to_linear = import_fury_shader( + os.path.join("rt_odfs", "srgb_to_linear.frag") + ) + + # Turns a linear RGB color (i.e. rec. 709) into sRGB + linear_rgb_to_srgb = import_fury_shader( + os.path.join("rt_odfs", "linear_rgb_to_srgb.frag") + ) + + # Inverse of linear_rgb_to_srgb() + srgb_to_linear_rgb = import_fury_shader( + os.path.join("rt_odfs", "srgb_to_linear_rgb.frag") + ) + + # Logarithmic tonemapping operator. Input and output are linear RGB. + tonemap = import_fury_shader(os.path.join("rt_odfs", "tonemap.frag")) + + # Blinn-Phong illumination model + blinn_phong_model = import_fury_shader( + os.path.join("lighting", "blinn_phong_model.frag") + ) + + # fmt: off + fs_dec = compose_shader([ + def_sh_degree, def_sh_count, def_max_degree, + def_gl_ext_control_flow_attributes, def_no_intersection, + def_pis, fs_vs_vars, coeffs_norm, eval_sh_2, eval_sh_4, eval_sh_6, + eval_sh_8, eval_sh_10, eval_sh_12, eval_sh_grad_2, eval_sh_grad_4, + eval_sh_grad_6, eval_sh_grad_8, eval_sh_grad_10, eval_sh_grad_12, + newton_bisection, find_roots, eval_sh, eval_sh_grad, + get_inv_vandermonde, ray_sh_glyph_intersections, get_sh_glyph_normal, + blinn_phong_model, linear_to_srgb, srgb_to_linear, linear_rgb_to_srgb, + srgb_to_linear_rgb, tonemap + ]) + # fmt: on + + shader_to_actor(odf_actor, "fragment", decl_code=fs_dec) + + point_from_vs = "vec3 pnt = vertexMCVSOutput.xyz;" + + # Ray origin is the camera position in world space + ray_origin = "vec3 ro = camPosMCVSOutput;" + + # TODO: Check aspect for automatic scaling + # Ray direction is the normalized difference between the fragment and the + # camera position/ray origin + ray_direction = """ + vec3 rd = normalize(pnt - ro); + /* + //float aspect = float(iResolution.x) / float(iResolution.y); + float aspect = 1.; + float zoom = 1.; + //vec3 right = (aspect / zoom) * vec3(3., .0, .0); + vec3 right = (aspect / zoom) * camRightMCVSOutput; + //vec3 up = (1. / zoom) * vec3(.0, .0, 3.); + vec3 up = (1. / zoom) * camUpMCVSOutput; + //vec3 bottom_left = -.5 * (right + up); + //vec3 bottom_left = .0 * (right + up); + vec3 bottom_left = vec3(.0); + //vec2 frag_coord = gl_FragCoord.xy; + // TODO: Use 3D point instead + vec2 frag_coord = pnt.xy; + //vec3 frag_coord = pnt; + //vec2 uv = frag_coord / vec2(iResolution.xy); + vec2 uv = frag_coord / vec2(scaleVSOutput); + //vec2 uv = frag_coord / vec2(1. / scaleVSOutput); + //vec2 uv = frag_coord; + //vec3 uv = frag_coord / vec3(scaleVSOutput); + //vec3 ray_dir = normalize(bottom_left + uv.x * right + uv.y * up - camera_pos); + vec3 rd = normalize(bottom_left + uv.x * right + uv.y * up - ro); + //vec3 rd = normalize(bottom_left + uv.x * right + uv.y * up + uv.z - ro); + */ + """ + + # Light direction in a retroreflective model is the normalized difference + # between the camera position/ray origin and the fragment + light_direction = "vec3 ld = normalize(ro - pnt);" + + # Define SH coefficients (measured up to band 8, noise beyond that) + sh_coeffs = """ + float i = 1 / (numCoeffs * 2); + float sh_coeffs[SH_COUNT]; + for(int j=0; j 0.0) { + first_ray_param = ray_params[i]; + break; + } + } + """ + + # Evaluate shading for a directional light + directional_light = """ + vec3 color = vec3(0.5); + if (first_ray_param != NO_INTERSECTION) { + //vec3 intersection = ro + first_ray_param * rd; + vec3 intersection = ro - centerMCVSOutput + first_ray_param * rd; + vec3 normal = get_sh_glyph_normal(sh_coeffs, intersection); + vec3 colorDir = srgb_to_linear_rgb(abs(normalize(intersection))); + float attenuation = dot(ld, normal); + color = blinnPhongIllumModel( + //attenuation, lightColor0, diffuseColor, specularPower, + attenuation, lightColor0, colorDir, specularPower, + specularColor, ambientColor); + } + """ + + frag_output = """ + //vec4 out_color = vec4(linear_rgb_to_srgb(tonemap(color)), 1.0); + vec3 out_color = linear_rgb_to_srgb(tonemap(color)); + fragOutput0 = vec4(out_color, opacity); + //fragOutput0 = vec4(color, opacity); + """ + + # fmt: off + fs_impl = compose_shader([ + point_from_vs, ray_origin, ray_direction, light_direction, sh_coeffs, + intersection_test, first_intersection, directional_light, frag_output + ]) + # fmt: on + + shader_to_actor(odf_actor, "fragment", impl_code=fs_impl, block="picking") + show_man.scene.add(odf_actor) + + show_man.start() From 1fac9adccfae96d07843a8b113b4b4763a3feb35 Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Fri, 9 Feb 2024 11:56:25 -0500 Subject: [PATCH 043/118] Minor changes to ray_traced_6.py --- .../SH-ODF experimental/ray_traced_6.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/docs/experimental/SH-ODF experimental/ray_traced_6.py b/docs/experimental/SH-ODF experimental/ray_traced_6.py index e546a51c2..be8851dab 100644 --- a/docs/experimental/SH-ODF experimental/ray_traced_6.py +++ b/docs/experimental/SH-ODF experimental/ray_traced_6.py @@ -178,6 +178,8 @@ def uv_calculations(n): """ fs_vs_vars = """ + //uniform float numCoeffs; + in vec4 vertexMCVSOutput; in vec3 centerMCVSOutput; in vec2 minmaxVSOutput; @@ -360,8 +362,7 @@ def uv_calculations(n): # Ray direction is the normalized difference between the fragment and the # camera position/ray origin ray_direction = """ - vec3 rd = normalize(pnt - ro); - /* + //vec3 rd = normalize(pnt - ro); //float aspect = float(iResolution.x) / float(iResolution.y); float aspect = 1.; float zoom = 1.; @@ -371,7 +372,8 @@ def uv_calculations(n): vec3 up = (1. / zoom) * camUpMCVSOutput; //vec3 bottom_left = -.5 * (right + up); //vec3 bottom_left = .0 * (right + up); - vec3 bottom_left = vec3(.0); + //vec3 bottom_left = vec3(.0); + vec3 bottom_left = centerMCVSOutput; //vec2 frag_coord = gl_FragCoord.xy; // TODO: Use 3D point instead vec2 frag_coord = pnt.xy; @@ -384,7 +386,6 @@ def uv_calculations(n): //vec3 ray_dir = normalize(bottom_left + uv.x * right + uv.y * up - camera_pos); vec3 rd = normalize(bottom_left + uv.x * right + uv.y * up - ro); //vec3 rd = normalize(bottom_left + uv.x * right + uv.y * up + uv.z - ro); - */ """ # Light direction in a retroreflective model is the normalized difference @@ -422,8 +423,8 @@ def uv_calculations(n): directional_light = """ vec3 color = vec3(0.5); if (first_ray_param != NO_INTERSECTION) { - //vec3 intersection = ro + first_ray_param * rd; - vec3 intersection = ro - centerMCVSOutput + first_ray_param * rd; + vec3 intersection = ro + first_ray_param * rd; + //vec3 intersection = ro - centerMCVSOutput + first_ray_param * rd; vec3 normal = get_sh_glyph_normal(sh_coeffs, intersection); vec3 colorDir = srgb_to_linear_rgb(abs(normalize(intersection))); float attenuation = dot(ld, normal); From 305b84822338fb9c2f463e121a8d5252b98829b9 Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Fri, 9 Feb 2024 12:28:12 -0500 Subject: [PATCH 044/118] Added README and renamed ray_traced files. --- .../SH-ODF experimental/README.md | 30 +++++++++++ .../{ray_traced_1.py => ray_traced_1.0.py} | 3 ++ .../{ray_traced_2.py => ray_traced_2.0.py} | 37 +++++++++---- .../{ray_traced_3.py => ray_traced_3.0.py} | 0 .../{ray_traced_4.py => ray_traced_5.0.py} | 54 +++++++++++++------ .../{ray_traced_5.py => ray_traced_5.5.py} | 0 .../{ray_traced_6.py => ray_traced_6.0.py} | 0 7 files changed, 99 insertions(+), 25 deletions(-) create mode 100644 docs/experimental/SH-ODF experimental/README.md rename docs/experimental/SH-ODF experimental/{ray_traced_1.py => ray_traced_1.0.py} (99%) rename docs/experimental/SH-ODF experimental/{ray_traced_2.py => ray_traced_2.0.py} (95%) rename docs/experimental/SH-ODF experimental/{ray_traced_3.py => ray_traced_3.0.py} (100%) rename docs/experimental/SH-ODF experimental/{ray_traced_4.py => ray_traced_5.0.py} (93%) rename docs/experimental/SH-ODF experimental/{ray_traced_5.py => ray_traced_5.5.py} (100%) rename docs/experimental/SH-ODF experimental/{ray_traced_6.py => ray_traced_6.0.py} (100%) diff --git a/docs/experimental/SH-ODF experimental/README.md b/docs/experimental/SH-ODF experimental/README.md new file mode 100644 index 000000000..b823cb6d4 --- /dev/null +++ b/docs/experimental/SH-ODF experimental/README.md @@ -0,0 +1,30 @@ +# Ray Traced ODF glyphs + +This folder includes Fury's implementation of "Ray Tracing Spherical Harmonics Glyphs": +https://momentsingraphics.de/VMV2023.html + +The fragment shader is based on: https://www.shadertoy.com/view/dlGSDV +(c) 2023, Christoph Peters + +His work is licensed under a CC0 1.0 Universal License. To the extent +possible under law, Christoph Peters has waived all copyright and related or +neighboring rights to the following code. This work is published from +Germany. https://creativecommons.org/publicdomain/zero/1.0/ + +## Base implementation + +The original paper implementation can be found in: + - [ray_traced_1.0.py](ray_traced_1.0.py) for a single glyph + - [ray_traced_2.0.py](ray_traced_2.0.py) for multiple glyphs. + +> **Note:** We keep these files as they are for comparison purposes. + +## FURY's implementation + +To better understand the base approach and being able to build on top on it we need a simplified yet functional version of it. + +- [ray_traced_3.0.py](ray_traced_3.0.py) simplifies the illumination model getting rid of additional parameters and adding compatibility with VTK's default lighting model. Here is a comparison between the simplified version and the original one: + +| BRDF lighting ([ray_traced_1.0.py](ray_traced_1.0.py)) | Blinn-Phong lighting ([ray_traced_3.0.py](ray_traced_3.0.py)) | +|---|---| +||| diff --git a/docs/experimental/SH-ODF experimental/ray_traced_1.py b/docs/experimental/SH-ODF experimental/ray_traced_1.0.py similarity index 99% rename from docs/experimental/SH-ODF experimental/ray_traced_1.py rename to docs/experimental/SH-ODF experimental/ray_traced_1.0.py index db819cac6..ce72df391 100644 --- a/docs/experimental/SH-ODF experimental/ray_traced_1.py +++ b/docs/experimental/SH-ODF experimental/ray_traced_1.0.py @@ -7,7 +7,10 @@ possible under law, Christoph Peters has waived all copyright and related or neighboring rights to the following code. This work is published from Germany. https://creativecommons.org/publicdomain/zero/1.0/ + +This script includes the original implementation as seen in shadertoy.com. """ + import os import numpy as np diff --git a/docs/experimental/SH-ODF experimental/ray_traced_2.py b/docs/experimental/SH-ODF experimental/ray_traced_2.0.py similarity index 95% rename from docs/experimental/SH-ODF experimental/ray_traced_2.py rename to docs/experimental/SH-ODF experimental/ray_traced_2.0.py index a95a958f2..e436e5df3 100644 --- a/docs/experimental/SH-ODF experimental/ray_traced_2.py +++ b/docs/experimental/SH-ODF experimental/ray_traced_2.0.py @@ -7,7 +7,11 @@ possible under law, Christoph Peters has waived all copyright and related or neighboring rights to the following code. This work is published from Germany. https://creativecommons.org/publicdomain/zero/1.0/ + +This script extends the original implementation by passing glyph information +through a texture. """ + import os import numpy as np @@ -25,16 +29,27 @@ def uv_calculations(n): uvs = [] - for i in range (0,n): - a = (n-(i+1))/n - b = (n-i)/n - #glyph_coord [0, a], [0, b], [1, b], [1, a] - uvs.extend([[.1, a+.1], [.1, b-.1], [.9, b-.1], [.9, a+.1], - [.1, a+.1], [.1, b-.1], [.9, b-.1], [.9, a+.1]]) + for i in range(0, n): + a = (n - (i + 1)) / n + b = (n - i) / n + # glyph_coord [0, a], [0, b], [1, b], [1, a] + uvs.extend( + [ + [0.1, a + 0.1], + [0.1, b - 0.1], + [0.9, b - 0.1], + [0.9, a + 0.1], + [0.1, a + 0.1], + [0.1, b - 0.1], + [0.9, b - 0.1], + [0.9, a + 0.1], + ] + ) return uvs + if __name__ == "__main__": - show_man = window.ShowManager(size=(1920, 1080)) + show_man = window.ShowManager(size=(1280, 720)) show_man.scene.background((1, 1, 1)) # fmt: off @@ -168,7 +183,7 @@ def uv_calculations(n): in vec3 centerMCVSOutput; in vec2 minmaxVSOutput; """ - + coeffs_norm = """ float coeffsNorm(float coef) { @@ -368,7 +383,7 @@ def uv_calculations(n): sh_coeffs[j] = coeffsNorm(texture(texture0, vec2(i + j / numCoeffs, tcoordVCVSOutput.y)).x); } """ - + # Perform the intersection test intersection_test = """ float ray_params[MAX_DEGREE]; @@ -389,7 +404,7 @@ def uv_calculations(n): # Evaluate shading for a directional light directional_light = """ - vec3 color = vec3(0.5); + vec3 color = vec3(1.0); if (first_ray_param != NO_INTERSECTION) { vec3 intersection = ro - centerMCVSOutput + first_ray_param * rd; vec3 normal = get_sh_glyph_normal(sh_coeffs, intersection); @@ -400,6 +415,8 @@ def uv_calculations(n): vec3 outgoing = -rd; vec3 brdf = gltf_dielectric_brdf(incoming, outgoing, normal, 0.45, base_color); color = exposure * (brdf * max(0.0, dot(incoming, normal)) + base_color * ambient); + } else { + discard; } """ diff --git a/docs/experimental/SH-ODF experimental/ray_traced_3.py b/docs/experimental/SH-ODF experimental/ray_traced_3.0.py similarity index 100% rename from docs/experimental/SH-ODF experimental/ray_traced_3.py rename to docs/experimental/SH-ODF experimental/ray_traced_3.0.py diff --git a/docs/experimental/SH-ODF experimental/ray_traced_4.py b/docs/experimental/SH-ODF experimental/ray_traced_5.0.py similarity index 93% rename from docs/experimental/SH-ODF experimental/ray_traced_4.py rename to docs/experimental/SH-ODF experimental/ray_traced_5.0.py index dea01d305..0cf64c752 100644 --- a/docs/experimental/SH-ODF experimental/ray_traced_4.py +++ b/docs/experimental/SH-ODF experimental/ray_traced_5.0.py @@ -8,6 +8,7 @@ neighboring rights to the following code. This work is published from Germany. https://creativecommons.org/publicdomain/zero/1.0/ """ + import os import numpy as np @@ -27,14 +28,25 @@ def uv_calculations(n): uvs = [] - for i in range (0,n): - a = (n-(i+1))/n - b = (n-i)/n - #glyph_coord [0, a], [0, b], [1, b], [1, a] - uvs.extend([[.1, a+.1], [.1, b-.1], [.9, b-.1], [.9, a+.1], - [.1, a+.1], [.1, b-.1], [.9, b-.1], [.9, a+.1]]) + for i in range(0, n): + a = (n - (i + 1)) / n + b = (n - i) / n + # glyph_coord [0, a], [0, b], [1, b], [1, a] + uvs.extend( + [ + [0.1, a + 0.1], + [0.1, b - 0.1], + [0.9, b - 0.1], + [0.9, a + 0.1], + [0.1, a + 0.1], + [0.1, b - 0.1], + [0.9, b - 0.1], + [0.9, a + 0.1], + ] + ) return uvs + if __name__ == "__main__": show_man = window.ShowManager(size=(1920, 1080)) show_man.scene.background((1, 1, 1)) @@ -174,7 +186,7 @@ def uv_calculations(n): in vec3 centerMCVSOutput; in vec2 minmaxVSOutput; """ - + coeffs_norm = """ float coeffsNorm(float coef) { @@ -186,17 +198,29 @@ def uv_calculations(n): } """ - eval_sh_2 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_2 copy.frag")) + eval_sh_2 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_2 copy.frag") + ) - eval_sh_4 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_4 copy.frag")) + eval_sh_4 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_4 copy.frag") + ) - eval_sh_6 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_6 copy.frag")) + eval_sh_6 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_6 copy.frag") + ) - eval_sh_8 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_8 copy.frag")) + eval_sh_8 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_8 copy.frag") + ) - eval_sh_10 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_10 copy.frag")) + eval_sh_10 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_10 copy.frag") + ) - eval_sh_12 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_12 copy.frag")) + eval_sh_12 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_12 copy.frag") + ) eval_sh_grad_2 = import_fury_shader( os.path.join("rt_odfs", "eval_sh_grad_2.frag") @@ -374,7 +398,7 @@ def uv_calculations(n): sh_coeffs[j] = coeffsNorm(texture(texture0, vec2(i + j / numCoeffs, tcoordVCVSOutput.y)).x); } """ - + # Perform the intersection test intersection_test = """ float ray_params[MAX_DEGREE]; @@ -395,7 +419,7 @@ def uv_calculations(n): # Evaluate shading for a directional light directional_light = """ - vec3 color = vec3(0.5); + vec3 color = vec3(1.0); if (first_ray_param != NO_INTERSECTION) { vec3 intersection = ro - centerMCVSOutput + first_ray_param * rd; vec3 normal = get_sh_glyph_normal(sh_coeffs, intersection); diff --git a/docs/experimental/SH-ODF experimental/ray_traced_5.py b/docs/experimental/SH-ODF experimental/ray_traced_5.5.py similarity index 100% rename from docs/experimental/SH-ODF experimental/ray_traced_5.py rename to docs/experimental/SH-ODF experimental/ray_traced_5.5.py diff --git a/docs/experimental/SH-ODF experimental/ray_traced_6.py b/docs/experimental/SH-ODF experimental/ray_traced_6.0.py similarity index 100% rename from docs/experimental/SH-ODF experimental/ray_traced_6.py rename to docs/experimental/SH-ODF experimental/ray_traced_6.0.py From 6b682d3fe99243661d97b8c2a88975fb207f250e Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Fri, 9 Feb 2024 12:55:02 -0500 Subject: [PATCH 045/118] Added ray_traced_4.0.py as an analogous version of ray_traced_2.0.py. Updated README. --- .../SH-ODF experimental/README.md | 10 +- .../SH-ODF experimental/ray_traced_3.0.py | 2 +- .../SH-ODF experimental/ray_traced_4.0.py | 427 ++++++++++++++++++ 3 files changed, 436 insertions(+), 3 deletions(-) create mode 100644 docs/experimental/SH-ODF experimental/ray_traced_4.0.py diff --git a/docs/experimental/SH-ODF experimental/README.md b/docs/experimental/SH-ODF experimental/README.md index b823cb6d4..44efa162e 100644 --- a/docs/experimental/SH-ODF experimental/README.md +++ b/docs/experimental/SH-ODF experimental/README.md @@ -15,7 +15,7 @@ Germany. https://creativecommons.org/publicdomain/zero/1.0/ The original paper implementation can be found in: - [ray_traced_1.0.py](ray_traced_1.0.py) for a single glyph - - [ray_traced_2.0.py](ray_traced_2.0.py) for multiple glyphs. + - [ray_traced_2.0.py](ray_traced_2.0.py) for multiple glyphs. > **Note:** We keep these files as they are for comparison purposes. @@ -23,8 +23,14 @@ The original paper implementation can be found in: To better understand the base approach and being able to build on top on it we need a simplified yet functional version of it. -- [ray_traced_3.0.py](ray_traced_3.0.py) simplifies the illumination model getting rid of additional parameters and adding compatibility with VTK's default lighting model. Here is a comparison between the simplified version and the original one: + - [ray_traced_3.0.py](ray_traced_3.0.py) simplifies the illumination model getting rid of additional parameters and adding compatibility with VTK's default lighting model. Here is a comparison between the simplified version and the original one: | BRDF lighting ([ray_traced_1.0.py](ray_traced_1.0.py)) | Blinn-Phong lighting ([ray_traced_3.0.py](ray_traced_3.0.py)) | |---|---| ||| + + - [ray_traced_4.0.py](ray_traced_4.0.py) is an analogous version of [ray_traced_2.0.py](ray_traced_2.0.py) but with the simplified illumination model introduced in [ray_traced_3.0.py](ray_traced_3.0.py). Here is a comparison between the simplified version and the original one: + +| BRDF lighting ([ray_traced_2.0.py](ray_traced_2.0.py)) | Blinn-Phong lighting ([ray_traced_4.0.py](ray_traced_4.0.py)) | +|---|---| +||| diff --git a/docs/experimental/SH-ODF experimental/ray_traced_3.0.py b/docs/experimental/SH-ODF experimental/ray_traced_3.0.py index 0d865aa6e..03814b404 100644 --- a/docs/experimental/SH-ODF experimental/ray_traced_3.0.py +++ b/docs/experimental/SH-ODF experimental/ray_traced_3.0.py @@ -1,5 +1,5 @@ """ -Fury's simplified version of the script ray_traced_1.py. +Fury's simplified version of the script ray_traced_1.0.py. - Simplified color calculation. - Simplified lighting. """ diff --git a/docs/experimental/SH-ODF experimental/ray_traced_4.0.py b/docs/experimental/SH-ODF experimental/ray_traced_4.0.py new file mode 100644 index 000000000..94ff36696 --- /dev/null +++ b/docs/experimental/SH-ODF experimental/ray_traced_4.0.py @@ -0,0 +1,427 @@ +""" +Fury's simplified version of the script ray_traced_2.0.py. + - Simplified color calculation. + - Simplified lighting. +""" + +import os + +import numpy as np + +from fury import actor, window +from fury.lib import FloatArray, Texture +from fury.shaders import ( + attribute_to_actor, + compose_shader, + import_fury_shader, + shader_to_actor, +) +from fury.utils import numpy_to_vtk_image_data, set_polydata_tcoords + + +def uv_calculations(n): + uvs = [] + for i in range(0, n): + a = (n - (i + 1)) / n + b = (n - i) / n + # glyph_coord [0, a], [0, b], [1, b], [1, a] + uvs.extend( + [ + [0.1, a + 0.1], + [0.1, b - 0.1], + [0.9, b - 0.1], + [0.9, a + 0.1], + [0.1, a + 0.1], + [0.1, b - 0.1], + [0.9, b - 0.1], + [0.9, a + 0.1], + ] + ) + return uvs + + +if __name__ == "__main__": + show_man = window.ShowManager(size=(1280, 720)) + show_man.scene.background((1, 1, 1)) + + # fmt: off + coeffs = np.array([ + [ + 0.2820735, 0.15236554, -0.04038717, -0.11270988, -0.04532376, + 0.14921817, 0.00257928, 0.0040734, -0.05313807, 0.03486542, + 0.04083064, 0.02105767, -0.04389586, -0.04302812, 0.1048641 + ], + [ + 0.28549338, 0.0978267, -0.11544838, 0.12525354, -0.00126003, + 0.00320594, 0.04744155, -0.07141446, 0.03211689, 0.04711322, + 0.08064896, 0.00154299, 0.00086506, 0.00162543, -0.00444893 + ], + [ + 0.28208936, -0.13133252, -0.04701012, -0.06303016, -0.0468775, + 0.02348355, 0.03991898, 0.02587433, 0.02645416, 0.00668765, + 0.00890633, 0.02189304, 0.00387415, 0.01665629, -0.01427194 + ] + ]) + # fmt: on + + centers = np.array([[0, -1, 0], [1, -1, 0], [2, -1, 0]]) + + odf_actor = actor.box(centers=centers, scales=1.0) + + big_centers = np.repeat(centers, 8, axis=0) + attribute_to_actor(odf_actor, big_centers, "center") + + minmax = np.array([coeffs.min(axis=1), coeffs.max(axis=1)]).T + big_minmax = np.repeat(minmax, 8, axis=0) + attribute_to_actor(odf_actor, big_minmax, "minmax") + + odf_actor_pd = odf_actor.GetMapper().GetInput() + + # fmt: off + uv_vals = np.array(uv_calculations(3)) + # fmt: on + + num_pnts = uv_vals.shape[0] + + t_coords = FloatArray() + t_coords.SetNumberOfComponents(2) + t_coords.SetNumberOfTuples(num_pnts) + [t_coords.SetTuple(i, uv_vals[i]) for i in range(num_pnts)] + + set_polydata_tcoords(odf_actor_pd, t_coords) + + min = coeffs.min(axis=1) + max = coeffs.max(axis=1) + newmin = 0 + newmax = 1 + arr = np.array( + [ + (coeffs[i] - min[i]) * ((newmax - newmin) / (max[i] - min[i])) + + newmin + for i in range(coeffs.shape[0]) + ] + ) + arr *= 255 + grid = numpy_to_vtk_image_data(arr.astype(np.uint8)) + + texture = Texture() + texture.SetInputDataObject(grid) + texture.Update() + + odf_actor.GetProperty().SetTexture("texture0", texture) + + # TODO: Set int uniform + odf_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniformf( + "numCoeffs", 15 + ) + + vs_dec = """ + in vec3 center; + in vec2 minmax; + + out vec4 vertexMCVSOutput; + out vec3 centerMCVSOutput; + out vec2 minmaxVSOutput; + out vec3 camPosMCVSOutput; + out vec3 camRightMCVSOutput; + out vec3 camUpMCVSOutput; + """ + + vs_impl = """ + vertexMCVSOutput = vertexMC; + centerMCVSOutput = center; + minmaxVSOutput = minmax; + camPosMCVSOutput = -MCVCMatrix[3].xyz * mat3(MCVCMatrix); + camRightMCVSOutput = vec3( + MCVCMatrix[0][0], MCVCMatrix[1][0], MCVCMatrix[2][0]); + camUpMCVSOutput = vec3( + MCVCMatrix[0][1], MCVCMatrix[1][1], MCVCMatrix[2][1]); + """ + + shader_to_actor(odf_actor, "vertex", decl_code=vs_dec, impl_code=vs_impl) + + # The index of the highest used band of the spherical harmonics basis. Must + # be even, at least 2 and at most 12. + def_sh_degree = "#define SH_DEGREE 4" + + # The number of spherical harmonics basis functions + def_sh_count = "#define SH_COUNT (((SH_DEGREE + 1) * (SH_DEGREE + 2)) / 2)" + + # Degree of polynomials for which we have to find roots + def_max_degree = "#define MAX_DEGREE (2 * SH_DEGREE + 2)" + + # If GL_EXT_control_flow_attributes is available, these defines should be + # defined as [[unroll]] and [[loop]] to give reasonable hints to the + # compiler. That avoids register spilling, which makes execution + # considerably faster. + def_gl_ext_control_flow_attributes = """ + #ifndef _unroll_ + #define _unroll_ + #endif + #ifndef _loop_ + #define _loop_ + #endif + """ + + # When there are fewer intersections/roots than theoretically possible, + # some array entries are set to this value + def_no_intersection = "#define NO_INTERSECTION 3.4e38" + + # pi and its reciprocal + def_pis = """ + #define M_PI 3.141592653589793238462643 + #define M_INV_PI 0.318309886183790671537767526745 + """ + + fs_vs_vars = """ + in vec4 vertexMCVSOutput; + in vec3 centerMCVSOutput; + in vec2 minmaxVSOutput; + in vec3 camPosMCVSOutput; + in vec3 camRightMCVSOutput; + in vec3 camUpMCVSOutput; + """ + + coeffs_norm = """ + float coeffsNorm(float coef) + { + float min = 0; + float max = 1; + float newMin = minmaxVSOutput.x; + float newMax = minmaxVSOutput.y; + return (coef - min) * ((newMax - newMin) / (max - min)) + newMin; + } + """ + + eval_sh_2 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_2.frag")) + + eval_sh_4 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_4.frag")) + + eval_sh_6 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_6.frag")) + + eval_sh_8 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_8.frag")) + + eval_sh_10 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_10.frag")) + + eval_sh_12 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_12.frag")) + + eval_sh_grad_2 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_2.frag") + ) + + eval_sh_grad_4 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_4.frag") + ) + + eval_sh_grad_6 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_6.frag") + ) + + eval_sh_grad_8 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_8.frag") + ) + + eval_sh_grad_10 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_10.frag") + ) + + eval_sh_grad_12 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_12.frag") + ) + + # Searches a single root of a polynomial within a given interval. + # param out_root The location of the found root. + # param out_end_value The value of the given polynomial at end. + # param poly Coefficients of the polynomial for which a root should be + # found. + # Coefficient poly[i] is multiplied by x^i. + # param begin The beginning of an interval where the polynomial is + # monotonic. + # param end The end of said interval. + # param begin_value The value of the given polynomial at begin. + # param error_tolerance The error tolerance for the returned root + # location. + # Typically the error will be much lower but in theory it can be + # bigger. + # + # return true if a root was found, false if no root exists. + newton_bisection = import_fury_shader( + os.path.join("rt_odfs", "newton_bisection.frag") + ) + + # Finds all roots of the given polynomial in the interval [begin, end] and + # writes them to out_roots. Some entries will be NO_INTERSECTION but other + # than that the array is sorted. The last entry is always NO_INTERSECTION. + find_roots = import_fury_shader(os.path.join("rt_odfs", "find_roots.frag")) + + # Evaluates the spherical harmonics basis in bands 0, 2, ..., SH_DEGREE. + # Conventions are as in the following paper. + # M. Descoteaux, E. Angelino, S. Fitzgibbons, and R. Deriche. Regularized, + # fast, and robust analytical q-ball imaging. Magnetic Resonance in + # Medicine, 58(3), 2007. https://doi.org/10.1002/mrm.21277 + # param out_shs Values of SH basis functions in bands 0, 2, ..., + # SH_DEGREE in this order. + # param point The point on the unit sphere where the basis should be + # evaluated. + eval_sh = import_fury_shader(os.path.join("rt_odfs", "eval_sh.frag")) + + # Evaluates the gradient of each basis function given by eval_sh() and the + # basis itself + eval_sh_grad = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad.frag") + ) + + # Outputs a matrix that turns equidistant samples on the unit circle of a + # homogeneous polynomial into coefficients of that polynomial. + get_inv_vandermonde = import_fury_shader( + os.path.join("rt_odfs", "get_inv_vandermonde.frag") + ) + + # Determines all intersections between a ray and a spherical harmonics + # glyph. + # param out_ray_params The ray parameters at intersection points. The + # points themselves are at ray_origin + out_ray_params[i] * ray_dir. + # Some entries may be NO_INTERSECTION but other than that the array + # is sorted. + # param sh_coeffs SH_COUNT spherical harmonic coefficients defining the + # glyph. Their exact meaning is defined by eval_sh(). + # param ray_origin The origin of the ray, relative to the glyph center. + # param ray_dir The normalized direction vector of the ray. + ray_sh_glyph_intersections = import_fury_shader( + os.path.join("rt_odfs", "ray_sh_glyph_intersections.frag") + ) + + # Provides a normalized normal vector for a spherical harmonics glyph. + # param sh_coeffs SH_COUNT spherical harmonic coefficients defining the + # glyph. Their exact meaning is defined by eval_sh(). + # param point A point on the surface of the glyph, relative to its + # center. + # + # return A normalized surface normal pointing away from the origin. + get_sh_glyph_normal = import_fury_shader( + os.path.join("rt_odfs", "get_sh_glyph_normal.frag") + ) + + # Applies the non-linearity that maps linear RGB to sRGB + linear_to_srgb = import_fury_shader( + os.path.join("rt_odfs", "linear_to_srgb.frag") + ) + + # Inverse of linear_to_srgb() + srgb_to_linear = import_fury_shader( + os.path.join("rt_odfs", "srgb_to_linear.frag") + ) + + # Turns a linear RGB color (i.e. rec. 709) into sRGB + linear_rgb_to_srgb = import_fury_shader( + os.path.join("rt_odfs", "linear_rgb_to_srgb.frag") + ) + + # Inverse of linear_rgb_to_srgb() + srgb_to_linear_rgb = import_fury_shader( + os.path.join("rt_odfs", "srgb_to_linear_rgb.frag") + ) + + # Logarithmic tonemapping operator. Input and output are linear RGB. + tonemap = import_fury_shader(os.path.join("rt_odfs", "tonemap.frag")) + + # Blinn-Phong illumination model + blinn_phong_model = import_fury_shader( + os.path.join("lighting", "blinn_phong_model.frag") + ) + + # fmt: off + fs_dec = compose_shader([ + def_sh_degree, def_sh_count, def_max_degree, + def_gl_ext_control_flow_attributes, def_no_intersection, + def_pis, fs_vs_vars, coeffs_norm, eval_sh_2, eval_sh_4, eval_sh_6, + eval_sh_8, eval_sh_10, eval_sh_12, eval_sh_grad_2, eval_sh_grad_4, + eval_sh_grad_6, eval_sh_grad_8, eval_sh_grad_10, eval_sh_grad_12, + newton_bisection, find_roots, eval_sh, eval_sh_grad, + get_inv_vandermonde, ray_sh_glyph_intersections, get_sh_glyph_normal, + blinn_phong_model, linear_to_srgb, srgb_to_linear, + linear_rgb_to_srgb, srgb_to_linear_rgb, tonemap + ]) + # fmt: on + + shader_to_actor(odf_actor, "fragment", decl_code=fs_dec) + + point_from_vs = "vec3 pnt = vertexMCVSOutput.xyz;" + + # Ray origin is the camera position in world space + ray_origin = "vec3 ro = camPosMCVSOutput;" + + # TODO: Check aspect for automatic scaling + # Ray direction is the normalized difference between the fragment and the + # camera position/ray origin + ray_direction = """ + vec3 rd = normalize(pnt - ro); + """ + + # Light direction in a retroreflective model is the normalized difference + # between the camera position/ray origin and the fragment + light_direction = "vec3 ld = normalize(ro - pnt);" + + # Define SH coefficients (measured up to band 8, noise beyond that) + sh_coeffs = """ + float i = 1 / (numCoeffs * 2); + float sh_coeffs[SH_COUNT]; + for(int j=0; j 0.0) { + first_ray_param = ray_params[i]; + break; + } + } + """ + + # Evaluate shading for a directional light + directional_light = """ + vec3 color = vec3(1.); + if (first_ray_param != NO_INTERSECTION) { + //vec3 intersection = ro + first_ray_param * rd; + vec3 intersection = ro - centerMCVSOutput + first_ray_param * rd; + vec3 normal = get_sh_glyph_normal(sh_coeffs, intersection); + vec3 colorDir = srgb_to_linear_rgb(abs(normalize(intersection))); + float attenuation = dot(ld, normal); + color = blinnPhongIllumModel( + //attenuation, lightColor0, diffuseColor, specularPower, + attenuation, lightColor0, colorDir, specularPower, + specularColor, ambientColor); + } else { + discard; + } + """ + + frag_output = """ + //vec4 out_color = vec4(linear_rgb_to_srgb(tonemap(color)), 1.0); + vec3 out_color = linear_rgb_to_srgb(tonemap(color)); + fragOutput0 = vec4(out_color, opacity); + //fragOutput0 = vec4(color, opacity); + """ + + # fmt: off + fs_impl = compose_shader([ + point_from_vs, ray_origin, ray_direction, light_direction, sh_coeffs, + intersection_test, first_intersection, directional_light, frag_output + ]) + # fmt: on + + shader_to_actor(odf_actor, "fragment", impl_code=fs_impl, block="picking") + show_man.scene.add(odf_actor) + + show_man.start() From f960c5b7452f8326253a802e8933856bb5e4139c Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Fri, 9 Feb 2024 12:57:35 -0500 Subject: [PATCH 046/118] Removed ray_traced_6.0.py from PR. --- .../SH-ODF experimental/ray_traced_6.0.py | 455 ------------------ 1 file changed, 455 deletions(-) delete mode 100644 docs/experimental/SH-ODF experimental/ray_traced_6.0.py diff --git a/docs/experimental/SH-ODF experimental/ray_traced_6.0.py b/docs/experimental/SH-ODF experimental/ray_traced_6.0.py deleted file mode 100644 index be8851dab..000000000 --- a/docs/experimental/SH-ODF experimental/ray_traced_6.0.py +++ /dev/null @@ -1,455 +0,0 @@ -""" -Fury's improved version of the script ray_traced_2.py. - - Improved scalability using scale from python properties. -""" - -import os - -import numpy as np - -from fury import actor, window -from fury.lib import FloatArray, Texture -from fury.shaders import ( - attribute_to_actor, - compose_shader, - import_fury_shader, - shader_to_actor, -) -from fury.utils import numpy_to_vtk_image_data, set_polydata_tcoords - - -def uv_calculations(n): - uvs = [] - for i in range(0, n): - a = (n - (i + 1)) / n - b = (n - i) / n - # glyph_coord [0, a], [0, b], [1, b], [1, a] - uvs.extend( - [ - [0.1, a + 0.1], - [0.1, b - 0.1], - [0.9, b - 0.1], - [0.9, a + 0.1], - [0.1, a + 0.1], - [0.1, b - 0.1], - [0.9, b - 0.1], - [0.9, a + 0.1], - ] - ) - return uvs - - -if __name__ == "__main__": - show_man = window.ShowManager(size=(1280, 720)) - show_man.scene.background((1, 1, 1)) - - # fmt: off - coeffs = np.array([ - [ - 0.2820735, 0.15236554, -0.04038717, -0.11270988, -0.04532376, - 0.14921817, 0.00257928, 0.0040734, -0.05313807, 0.03486542, - 0.04083064, 0.02105767, -0.04389586, -0.04302812, 0.1048641 - ], - [ - 0.28549338, 0.0978267, -0.11544838, 0.12525354, -0.00126003, - 0.00320594, 0.04744155, -0.07141446, 0.03211689, 0.04711322, - 0.08064896, 0.00154299, 0.00086506, 0.00162543, -0.00444893 - ], - [ - 0.28208936, -0.13133252, -0.04701012, -0.06303016, -0.0468775, - 0.02348355, 0.03991898, 0.02587433, 0.02645416, 0.00668765, - 0.00890633, 0.02189304, 0.00387415, 0.01665629, -0.01427194 - ] - ]) - # fmt: on - - centers = np.array([[-1, 1, 0], [0, 0, 0], [2, -2, 0]]) - scales = np.array([0.5, 1, 2]) - - odf_actor = actor.box(centers=centers, scales=scales) - - big_centers = np.repeat(centers, 8, axis=0) - attribute_to_actor(odf_actor, big_centers, "center") - - big_scales = np.repeat(scales, 8, axis=0) - attribute_to_actor(odf_actor, big_scales, "scale") - - minmax = np.array([coeffs.min(axis=1), coeffs.max(axis=1)]).T - big_minmax = np.repeat(minmax, 8, axis=0) - attribute_to_actor(odf_actor, big_minmax, "minmax") - - odf_actor_pd = odf_actor.GetMapper().GetInput() - - uv_vals = np.array(uv_calculations(3)) - - num_pnts = uv_vals.shape[0] - - t_coords = FloatArray() - t_coords.SetNumberOfComponents(2) - t_coords.SetNumberOfTuples(num_pnts) - [t_coords.SetTuple(i, uv_vals[i]) for i in range(num_pnts)] - - set_polydata_tcoords(odf_actor_pd, t_coords) - - min = coeffs.min(axis=1) - max = coeffs.max(axis=1) - newmin = 0 - newmax = 1 - arr = np.array( - [ - (coeffs[i] - min[i]) * ((newmax - newmin) / (max[i] - min[i])) - + newmin - for i in range(coeffs.shape[0]) - ] - ) - arr *= 255 - grid = numpy_to_vtk_image_data(arr.astype(np.uint8)) - - texture = Texture() - texture.SetInputDataObject(grid) - texture.Update() - - odf_actor.GetProperty().SetTexture("texture0", texture) - - # TODO: Set int uniform - odf_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniformf( - "numCoeffs", 15 - ) - - vs_dec = """ - in vec3 center; - in vec2 minmax; - in float scale; - - out vec4 vertexMCVSOutput; - out vec3 centerMCVSOutput; - out vec2 minmaxVSOutput; - out vec3 camPosMCVSOutput; - out vec3 camRightMCVSOutput; - out vec3 camUpMCVSOutput; - out float scaleVSOutput; - """ - - vs_impl = """ - vertexMCVSOutput = vertexMC; - centerMCVSOutput = center; - minmaxVSOutput = minmax; - scaleVSOutput = scale; - camPosMCVSOutput = -MCVCMatrix[3].xyz * mat3(MCVCMatrix); - camRightMCVSOutput = vec3( - MCVCMatrix[0][0], MCVCMatrix[1][0], MCVCMatrix[2][0]); - camUpMCVSOutput = vec3( - MCVCMatrix[0][1], MCVCMatrix[1][1], MCVCMatrix[2][1]); - """ - - shader_to_actor(odf_actor, "vertex", decl_code=vs_dec, impl_code=vs_impl) - - # The index of the highest used band of the spherical harmonics basis. Must - # be even, at least 2 and at most 12. - def_sh_degree = "#define SH_DEGREE 4" - - # The number of spherical harmonics basis functions - def_sh_count = "#define SH_COUNT (((SH_DEGREE + 1) * (SH_DEGREE + 2)) / 2)" - - # Degree of polynomials for which we have to find roots - def_max_degree = "#define MAX_DEGREE (2 * SH_DEGREE + 2)" - - # If GL_EXT_control_flow_attributes is available, these defines should be - # defined as [[unroll]] and [[loop]] to give reasonable hints to the - # compiler. That avoids register spilling, which makes execution - # considerably faster. - def_gl_ext_control_flow_attributes = """ - #ifndef _unroll_ - #define _unroll_ - #endif - #ifndef _loop_ - #define _loop_ - #endif - """ - - # When there are fewer intersections/roots than theoretically possible, - # some array entries are set to this value - def_no_intersection = "#define NO_INTERSECTION 3.4e38" - - # pi and its reciprocal - def_pis = """ - #define M_PI 3.141592653589793238462643 - #define M_INV_PI 0.318309886183790671537767526745 - """ - - fs_vs_vars = """ - //uniform float numCoeffs; - - in vec4 vertexMCVSOutput; - in vec3 centerMCVSOutput; - in vec2 minmaxVSOutput; - in vec3 camPosMCVSOutput; - in vec3 camRightMCVSOutput; - in vec3 camUpMCVSOutput; - in float scaleVSOutput; - """ - - coeffs_norm = """ - float coeffsNorm(float coef) - { - float min = 0; - float max = 1; - float newMin = minmaxVSOutput.x; - float newMax = minmaxVSOutput.y; - return (coef - min) * ((newMax - newMin) / (max - min)) + newMin; - } - """ - - eval_sh_2 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_2.frag")) - - eval_sh_4 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_4.frag")) - - eval_sh_6 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_6.frag")) - - eval_sh_8 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_8.frag")) - - eval_sh_10 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_10.frag")) - - eval_sh_12 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_12.frag")) - - eval_sh_grad_2 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_2.frag") - ) - - eval_sh_grad_4 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_4.frag") - ) - - eval_sh_grad_6 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_6.frag") - ) - - eval_sh_grad_8 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_8.frag") - ) - - eval_sh_grad_10 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_10.frag") - ) - - eval_sh_grad_12 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_12.frag") - ) - - # Searches a single root of a polynomial within a given interval. - # param out_root The location of the found root. - # param out_end_value The value of the given polynomial at end. - # param poly Coefficients of the polynomial for which a root should be - # found. - # Coefficient poly[i] is multiplied by x^i. - # param begin The beginning of an interval where the polynomial is - # monotonic. - # param end The end of said interval. - # param begin_value The value of the given polynomial at begin. - # param error_tolerance The error tolerance for the returned root - # location. - # Typically the error will be much lower but in theory it can be - # bigger. - # - # return true if a root was found, false if no root exists. - newton_bisection = import_fury_shader( - os.path.join("rt_odfs", "newton_bisection.frag") - ) - - # Finds all roots of the given polynomial in the interval [begin, end] and - # writes them to out_roots. Some entries will be NO_INTERSECTION but other - # than that the array is sorted. The last entry is always NO_INTERSECTION. - find_roots = import_fury_shader(os.path.join("rt_odfs", "find_roots.frag")) - - # Evaluates the spherical harmonics basis in bands 0, 2, ..., SH_DEGREE. - # Conventions are as in the following paper. - # M. Descoteaux, E. Angelino, S. Fitzgibbons, and R. Deriche. Regularized, - # fast, and robust analytical q-ball imaging. Magnetic Resonance in - # Medicine, 58(3), 2007. https://doi.org/10.1002/mrm.21277 - # param out_shs Values of SH basis functions in bands 0, 2, ..., - # SH_DEGREE in this order. - # param point The point on the unit sphere where the basis should be - # evaluated. - eval_sh = import_fury_shader(os.path.join("rt_odfs", "eval_sh.frag")) - - # Evaluates the gradient of each basis function given by eval_sh() and the - # basis itself - eval_sh_grad = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad.frag") - ) - - # Outputs a matrix that turns equidistant samples on the unit circle of a - # homogeneous polynomial into coefficients of that polynomial. - get_inv_vandermonde = import_fury_shader( - os.path.join("rt_odfs", "get_inv_vandermonde.frag") - ) - - # Determines all intersections between a ray and a spherical harmonics - # glyph. - # param out_ray_params The ray parameters at intersection points. The - # points themselves are at ray_origin + out_ray_params[i] * ray_dir. - # Some entries may be NO_INTERSECTION but other than that the array - # is sorted. - # param sh_coeffs SH_COUNT spherical harmonic coefficients defining the - # glyph. Their exact meaning is defined by eval_sh(). - # param ray_origin The origin of the ray, relative to the glyph center. - # param ray_dir The normalized direction vector of the ray. - ray_sh_glyph_intersections = import_fury_shader( - os.path.join("rt_odfs", "ray_sh_glyph_intersections.frag") - ) - - # Provides a normalized normal vector for a spherical harmonics glyph. - # param sh_coeffs SH_COUNT spherical harmonic coefficients defining the - # glyph. Their exact meaning is defined by eval_sh(). - # param point A point on the surface of the glyph, relative to its - # center. - # - # return A normalized surface normal pointing away from the origin. - get_sh_glyph_normal = import_fury_shader( - os.path.join("rt_odfs", "get_sh_glyph_normal.frag") - ) - - # Applies the non-linearity that maps linear RGB to sRGB - linear_to_srgb = import_fury_shader( - os.path.join("rt_odfs", "linear_to_srgb.frag") - ) - - # Inverse of linear_to_srgb() - srgb_to_linear = import_fury_shader( - os.path.join("rt_odfs", "srgb_to_linear.frag") - ) - - # Turns a linear RGB color (i.e. rec. 709) into sRGB - linear_rgb_to_srgb = import_fury_shader( - os.path.join("rt_odfs", "linear_rgb_to_srgb.frag") - ) - - # Inverse of linear_rgb_to_srgb() - srgb_to_linear_rgb = import_fury_shader( - os.path.join("rt_odfs", "srgb_to_linear_rgb.frag") - ) - - # Logarithmic tonemapping operator. Input and output are linear RGB. - tonemap = import_fury_shader(os.path.join("rt_odfs", "tonemap.frag")) - - # Blinn-Phong illumination model - blinn_phong_model = import_fury_shader( - os.path.join("lighting", "blinn_phong_model.frag") - ) - - # fmt: off - fs_dec = compose_shader([ - def_sh_degree, def_sh_count, def_max_degree, - def_gl_ext_control_flow_attributes, def_no_intersection, - def_pis, fs_vs_vars, coeffs_norm, eval_sh_2, eval_sh_4, eval_sh_6, - eval_sh_8, eval_sh_10, eval_sh_12, eval_sh_grad_2, eval_sh_grad_4, - eval_sh_grad_6, eval_sh_grad_8, eval_sh_grad_10, eval_sh_grad_12, - newton_bisection, find_roots, eval_sh, eval_sh_grad, - get_inv_vandermonde, ray_sh_glyph_intersections, get_sh_glyph_normal, - blinn_phong_model, linear_to_srgb, srgb_to_linear, linear_rgb_to_srgb, - srgb_to_linear_rgb, tonemap - ]) - # fmt: on - - shader_to_actor(odf_actor, "fragment", decl_code=fs_dec) - - point_from_vs = "vec3 pnt = vertexMCVSOutput.xyz;" - - # Ray origin is the camera position in world space - ray_origin = "vec3 ro = camPosMCVSOutput;" - - # TODO: Check aspect for automatic scaling - # Ray direction is the normalized difference between the fragment and the - # camera position/ray origin - ray_direction = """ - //vec3 rd = normalize(pnt - ro); - //float aspect = float(iResolution.x) / float(iResolution.y); - float aspect = 1.; - float zoom = 1.; - //vec3 right = (aspect / zoom) * vec3(3., .0, .0); - vec3 right = (aspect / zoom) * camRightMCVSOutput; - //vec3 up = (1. / zoom) * vec3(.0, .0, 3.); - vec3 up = (1. / zoom) * camUpMCVSOutput; - //vec3 bottom_left = -.5 * (right + up); - //vec3 bottom_left = .0 * (right + up); - //vec3 bottom_left = vec3(.0); - vec3 bottom_left = centerMCVSOutput; - //vec2 frag_coord = gl_FragCoord.xy; - // TODO: Use 3D point instead - vec2 frag_coord = pnt.xy; - //vec3 frag_coord = pnt; - //vec2 uv = frag_coord / vec2(iResolution.xy); - vec2 uv = frag_coord / vec2(scaleVSOutput); - //vec2 uv = frag_coord / vec2(1. / scaleVSOutput); - //vec2 uv = frag_coord; - //vec3 uv = frag_coord / vec3(scaleVSOutput); - //vec3 ray_dir = normalize(bottom_left + uv.x * right + uv.y * up - camera_pos); - vec3 rd = normalize(bottom_left + uv.x * right + uv.y * up - ro); - //vec3 rd = normalize(bottom_left + uv.x * right + uv.y * up + uv.z - ro); - """ - - # Light direction in a retroreflective model is the normalized difference - # between the camera position/ray origin and the fragment - light_direction = "vec3 ld = normalize(ro - pnt);" - - # Define SH coefficients (measured up to band 8, noise beyond that) - sh_coeffs = """ - float i = 1 / (numCoeffs * 2); - float sh_coeffs[SH_COUNT]; - for(int j=0; j 0.0) { - first_ray_param = ray_params[i]; - break; - } - } - """ - - # Evaluate shading for a directional light - directional_light = """ - vec3 color = vec3(0.5); - if (first_ray_param != NO_INTERSECTION) { - vec3 intersection = ro + first_ray_param * rd; - //vec3 intersection = ro - centerMCVSOutput + first_ray_param * rd; - vec3 normal = get_sh_glyph_normal(sh_coeffs, intersection); - vec3 colorDir = srgb_to_linear_rgb(abs(normalize(intersection))); - float attenuation = dot(ld, normal); - color = blinnPhongIllumModel( - //attenuation, lightColor0, diffuseColor, specularPower, - attenuation, lightColor0, colorDir, specularPower, - specularColor, ambientColor); - } - """ - - frag_output = """ - //vec4 out_color = vec4(linear_rgb_to_srgb(tonemap(color)), 1.0); - vec3 out_color = linear_rgb_to_srgb(tonemap(color)); - fragOutput0 = vec4(out_color, opacity); - //fragOutput0 = vec4(color, opacity); - """ - - # fmt: off - fs_impl = compose_shader([ - point_from_vs, ray_origin, ray_direction, light_direction, sh_coeffs, - intersection_test, first_intersection, directional_light, frag_output - ]) - # fmt: on - - shader_to_actor(odf_actor, "fragment", impl_code=fs_impl, block="picking") - show_man.scene.add(odf_actor) - - show_man.start() From c95e43536be27692d8cde8a88169ca13d923c403 Mon Sep 17 00:00:00 2001 From: tvcastillod Date: Wed, 14 Feb 2024 00:07:49 -0500 Subject: [PATCH 047/118] implementation with a slice --- .../SH-ODF experimental/ray_traced_6.0.py | 475 ++++++++++++++++++ 1 file changed, 475 insertions(+) create mode 100644 docs/experimental/SH-ODF experimental/ray_traced_6.0.py diff --git a/docs/experimental/SH-ODF experimental/ray_traced_6.0.py b/docs/experimental/SH-ODF experimental/ray_traced_6.0.py new file mode 100644 index 000000000..c9ae42313 --- /dev/null +++ b/docs/experimental/SH-ODF experimental/ray_traced_6.0.py @@ -0,0 +1,475 @@ +""" +Fury's implementation of "Ray Tracing Spherical Harmonics Glyphs": +https://momentsingraphics.de/VMV2023.html +The fragment shader is based on: https://www.shadertoy.com/view/dlGSDV +(c) 2023, Christoph Peters +This work is licensed under a CC0 1.0 Universal License. To the extent +possible under law, Christoph Peters has waived all copyright and related or +neighboring rights to the following code. This work is published from +Germany. https://creativecommons.org/publicdomain/zero/1.0/ +""" + +import os + +import numpy as np +from dipy.data import get_sphere +from dipy.reconst.shm import sh_to_sf, sf_to_sh + +from dipy.io.image import load_nifti, save_nifti + +from fury import actor, window +from fury.lib import FloatArray, Texture +from fury.shaders import ( + attribute_to_actor, + compose_shader, + import_fury_shader, + shader_to_actor, +) +from fury.utils import numpy_to_vtk_image_data, set_polydata_tcoords + +import itertools + +import numpy as np + +from dipy.io.image import load_nifti + +from fury import window, actor, ui +from fury.actor import _fa, _color_fa +from fury.data import fetch_viz_dmri, read_viz_dmri +from fury.primitive import prim_sphere + + + +#scene = window.Scene() +#scene.background([255, 255, 255]) + +#showm = window.ShowManager(scene, size=(600, 600)) + + + +#tensors = actor.ellipsoid(centers=centers, colors=colors, axes=evecs, +# lengths=evals, scales=.6) +#showm.scene.add(tensors) +#showm.start() + +def uv_calculations(n): + uvs = [] + for i in range(0, n): + a = (n - (i + 1)) / n + b = (n - i) / n + # glyph_coord [0, a], [0, b], [1, b], [1, a] + uvs.extend( + [ + [0.001, a + 0.001], + [0.001, b - 0.001], + [0.999, b - 0.001], + [0.999, a + 0.001], + [0.001, a + 0.001], + [0.001, b - 0.001], + [0.999, b - 0.001], + [0.999, a + 0.001], + ] + ) + return uvs + + + +if __name__ == "__main__": + show_man = window.ShowManager(size=(1920, 1080)) + show_man.scene.background((1, 1, 1)) + + # fmt: off + coeffs, affine = load_nifti("docs\experimental\SH-ODF experimental\data\coeffs_odf.nii.gz") + + valid_mask = np.abs(coeffs).max(axis=(-1)) > 0 + indices = np.nonzero(valid_mask) + + centers = np.asarray(indices).T + + x, y, z, s = coeffs.shape + coeffs = coeffs[:, :, :].reshape((x * y * z, s)) + + coeffs = np.array(coeffs)*.15 + coeffs = coeffs[:270,:] + + max_val = coeffs.max(axis=1) + coeffs = np.dot(np.abs(np.diag(1/max_val)), coeffs) * .7 + centers = centers[:270] + + odf_actor = actor.box(centers=centers, scales=1.0) + + big_centers = np.repeat(centers, 8, axis=0) + attribute_to_actor(odf_actor, big_centers, "center") + + minmax = np.array([coeffs.min(axis=1), coeffs.max(axis=1)]).T + big_minmax = np.repeat(minmax, 8, axis=0) + attribute_to_actor(odf_actor, big_minmax, "minmax") + + odf_actor_pd = odf_actor.GetMapper().GetInput() + + # fmt: off + uv_vals = np.array(uv_calculations(270)) + # fmt: on + + num_pnts = uv_vals.shape[0] + + t_coords = FloatArray() + t_coords.SetNumberOfComponents(2) + t_coords.SetNumberOfTuples(num_pnts) + [t_coords.SetTuple(i, uv_vals[i]) for i in range(num_pnts)] + + set_polydata_tcoords(odf_actor_pd, t_coords) + + min = coeffs.min(axis=1) + max = coeffs.max(axis=1) + newmin = 0 + newmax = 1 + arr = np.array( + [ + (coeffs[i] - min[i]) * ((newmax - newmin) / (max[i] - min[i])) + + newmin + for i in range(coeffs.shape[0]) + ] + ) + arr *= 255 + grid = numpy_to_vtk_image_data(arr.astype(np.uint8)) + print(grid) + + texture = Texture() + texture.SetInputDataObject(grid) + texture.Update() + + odf_actor.GetProperty().SetTexture("texture0", texture) + + # TODO: Set int uniform + odf_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniformf( + "numCoeffs", 15 + ) + + vs_dec = """ + in vec3 center; + in vec2 minmax; + + out vec4 vertexMCVSOutput; + out vec3 centerMCVSOutput; + out vec2 minmaxVSOutput; + """ + + vs_impl = """ + vertexMCVSOutput = vertexMC; + centerMCVSOutput = center; + minmaxVSOutput = minmax; + vec3 camPos = -MCVCMatrix[3].xyz * mat3(MCVCMatrix); + """ + + shader_to_actor(odf_actor, "vertex", decl_code=vs_dec, impl_code=vs_impl) + + # The index of the highest used band of the spherical harmonics basis. Must + # be even, at least 2 and at most 12. + def_sh_degree = "#define SH_DEGREE 4" + + # The number of spherical harmonics basis functions + def_sh_count = "#define SH_COUNT (((SH_DEGREE + 1) * (SH_DEGREE + 2)) / 2)" + + # Degree of polynomials for which we have to find roots + def_max_degree = "#define MAX_DEGREE (2 * SH_DEGREE + 2)" + + # If GL_EXT_control_flow_attributes is available, these defines should be + # defined as [[unroll]] and [[loop]] to give reasonable hints to the + # compiler. That avoids register spilling, which makes execution + # considerably faster. + def_gl_ext_control_flow_attributes = """ + #ifndef _unroll_ + #define _unroll_ + #endif + #ifndef _loop_ + #define _loop_ + #endif + """ + + # When there are fewer intersections/roots than theoretically possible, + # some array entries are set to this value + def_no_intersection = "#define NO_INTERSECTION 3.4e38" + + # pi and its reciprocal + def_pis = """ + #define M_PI 3.141592653589793238462643 + #define M_INV_PI 0.318309886183790671537767526745 + """ + + fs_unifs = """ + uniform mat4 MCVCMatrix; + """ + + fs_vs_vars = """ + in vec4 vertexMCVSOutput; + in vec3 centerMCVSOutput; + in vec2 minmaxVSOutput; + """ + + coeffs_norm = """ + float coeffsNorm(float coef) + { + float min = 0; + float max = 1; + float newMin = minmaxVSOutput.x; + float newMax = minmaxVSOutput.y; + return (coef - min) * ((newMax - newMin) / (max - min)) + newMin; + } + """ + + eval_sh_2 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_2.frag") + ) + + eval_sh_4 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_4.frag") + ) + + eval_sh_6 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_6.frag") + ) + + eval_sh_8 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_8.frag") + ) + + eval_sh_10 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_10.frag") + ) + + eval_sh_12 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_12.frag") + ) + + eval_sh_grad_2 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_2.frag") + ) + + eval_sh_grad_4 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_4.frag") + ) + + eval_sh_grad_6 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_6.frag") + ) + + eval_sh_grad_8 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_8.frag") + ) + + eval_sh_grad_10 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_10.frag") + ) + + eval_sh_grad_12 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_12.frag") + ) + + # Searches a single root of a polynomial within a given interval. + # param out_root The location of the found root. + # param out_end_value The value of the given polynomial at end. + # param poly Coefficients of the polynomial for which a root should be + # found. + # Coefficient poly[i] is multiplied by x^i. + # param begin The beginning of an interval where the polynomial is + # monotonic. + # param end The end of said interval. + # param begin_value The value of the given polynomial at begin. + # param error_tolerance The error tolerance for the returned root + # location. + # Typically the error will be much lower but in theory it can be + # bigger. + # + # return true if a root was found, false if no root exists. + newton_bisection = import_fury_shader( + os.path.join("rt_odfs", "newton_bisection.frag") + ) + + # Finds all roots of the given polynomial in the interval [begin, end] and + # writes them to out_roots. Some entries will be NO_INTERSECTION but other + # than that the array is sorted. The last entry is always NO_INTERSECTION. + find_roots = import_fury_shader(os.path.join("rt_odfs", "find_roots.frag")) + + # Evaluates the spherical harmonics basis in bands 0, 2, ..., SH_DEGREE. + # Conventions are as in the following paper. + # M. Descoteaux, E. Angelino, S. Fitzgibbons, and R. Deriche. Regularized, + # fast, and robust analytical q-ball imaging. Magnetic Resonance in + # Medicine, 58(3), 2007. https://doi.org/10.1002/mrm.21277 + # param out_shs Values of SH basis functions in bands 0, 2, ..., + # SH_DEGREE in this order. + # param point The point on the unit sphere where the basis should be + # evaluated. + eval_sh = import_fury_shader(os.path.join("rt_odfs", "eval_sh.frag")) + + # Evaluates the gradient of each basis function given by eval_sh() and the + # basis itself + eval_sh_grad = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad.frag") + ) + + # Outputs a matrix that turns equidistant samples on the unit circle of a + # homogeneous polynomial into coefficients of that polynomial. + get_inv_vandermonde = import_fury_shader( + os.path.join("rt_odfs", "get_inv_vandermonde.frag") + ) + + # Determines all intersections between a ray and a spherical harmonics + # glyph. + # param out_ray_params The ray parameters at intersection points. The + # points themselves are at ray_origin + out_ray_params[i] * ray_dir. + # Some entries may be NO_INTERSECTION but other than that the array + # is sorted. + # param sh_coeffs SH_COUNT spherical harmonic coefficients defining the + # glyph. Their exact meaning is defined by eval_sh(). + # param ray_origin The origin of the ray, relative to the glyph center. + # param ray_dir The normalized direction vector of the ray. + ray_sh_glyph_intersections = import_fury_shader( + os.path.join("rt_odfs", "ray_sh_glyph_intersections.frag") + ) + + # Provides a normalized normal vector for a spherical harmonics glyph. + # param sh_coeffs SH_COUNT spherical harmonic coefficients defining the + # glyph. Their exact meaning is defined by eval_sh(). + # param point A point on the surface of the glyph, relative to its + # center. + # + # return A normalized surface normal pointing away from the origin. + get_sh_glyph_normal = import_fury_shader( + os.path.join("rt_odfs", "get_sh_glyph_normal.frag") + ) + + # This is the glTF BRDF for dielectric materials, exactly as described + # here: + # https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#appendix-b-brdf-implementation + # param incoming The normalized incoming light direction. + # param outgoing The normalized outgoing light direction. + # param normal The normalized shading normal. + # param roughness An artist friendly roughness value between 0 and 1. + # param base_color The albedo used for the Lambertian diffuse component. + # + # return The BRDF for the given directions. + gltf_dielectric_brdf = import_fury_shader( + os.path.join("rt_odfs", "gltf_dielectric_brdf.frag") + ) + + # Applies the non-linearity that maps linear RGB to sRGB + linear_to_srgb = import_fury_shader( + os.path.join("rt_odfs", "linear_to_srgb.frag") + ) + + # Inverse of linear_to_srgb() + srgb_to_linear = import_fury_shader( + os.path.join("rt_odfs", "srgb_to_linear.frag") + ) + + # Turns a linear RGB color (i.e. rec. 709) into sRGB + linear_rgb_to_srgb = import_fury_shader( + os.path.join("rt_odfs", "linear_rgb_to_srgb.frag") + ) + + # Inverse of linear_rgb_to_srgb() + srgb_to_linear_rgb = import_fury_shader( + os.path.join("rt_odfs", "srgb_to_linear_rgb.frag") + ) + + # Logarithmic tonemapping operator. Input and output are linear RGB. + tonemap = import_fury_shader(os.path.join("rt_odfs", "tonemap.frag")) + + # fmt: off + fs_dec = compose_shader([ + def_sh_degree, def_sh_count, def_max_degree, + def_gl_ext_control_flow_attributes, def_no_intersection, + def_pis, fs_unifs, fs_vs_vars, coeffs_norm, eval_sh_2, eval_sh_4, eval_sh_6, + eval_sh_8, eval_sh_10, eval_sh_12, eval_sh_grad_2, eval_sh_grad_4, + eval_sh_grad_6, eval_sh_grad_8, eval_sh_grad_10, eval_sh_grad_12, + newton_bisection, find_roots, eval_sh, eval_sh_grad, + get_inv_vandermonde, ray_sh_glyph_intersections, get_sh_glyph_normal, + gltf_dielectric_brdf, linear_to_srgb, srgb_to_linear, + linear_rgb_to_srgb, srgb_to_linear_rgb, tonemap + ]) + # fmt: on + + shader_to_actor(odf_actor, "fragment", decl_code=fs_dec) + + point_from_vs = "vec3 pnt = vertexMCVSOutput.xyz;" + + # Ray origin is the camera position in world space + ray_origin = """ + vec3 ro = (-MCVCMatrix[3] * MCVCMatrix).xyz; + """ + + # TODO: Check aspect for automatic scaling + # Ray direction is the normalized difference between the fragment and the + # camera position/ray origin + ray_direction = """ + vec3 rd = normalize(pnt - ro); + """ + + # Light direction in a retroreflective model is the normalized difference + # between the camera position/ray origin and the fragment + light_direction = "vec3 ld = normalize(ro - pnt);" + + # Define SH coefficients (measured up to band 8, noise beyond that) + sh_coeffs = """ + float i = 1 / (numCoeffs * 2); + float sh_coeffs[SH_COUNT]; + for(int j=0; j 0.0) { + first_ray_param = ray_params[i]; + break; + } + } + """ + + # Evaluate shading for a directional light + directional_light = """ + vec3 color = vec3(1.0); + if (first_ray_param != NO_INTERSECTION) { + vec3 intersection = ro - centerMCVSOutput + first_ray_param * rd; + vec3 normal = get_sh_glyph_normal(sh_coeffs, intersection); + vec3 base_color = srgb_to_linear_rgb(abs(normalize(intersection))); + const vec3 incoming = normalize(vec3(1.23, -4.56, 7.89)); + float ambient = 0.04; + float exposure = 4.0; + vec3 outgoing = -rd; + vec3 brdf = gltf_dielectric_brdf(incoming, outgoing, normal, 0.45, base_color); + color = exposure * (brdf * max(0.0, dot(incoming, normal)) + base_color * ambient); + } else { + discard; + } + """ + + frag_output = """ + //vec4 out_color = vec4(linear_rgb_to_srgb(tonemap(color)), 1.0); + vec3 out_color = linear_rgb_to_srgb(tonemap(color)); + fragOutput0 = vec4(out_color, opacity); + """ + + # fmt: off + fs_impl = compose_shader([ + point_from_vs, ray_origin, ray_direction, light_direction, sh_coeffs, + intersection_test, first_intersection, directional_light, frag_output + ]) + # fmt: on + + shader_to_actor(odf_actor, "fragment", impl_code=fs_impl, block="picking") + show_man.scene.add(odf_actor) + + show_man.start() + From 07252e0266510e815b21e7e0da5f4ed8d3bdc8b6 Mon Sep 17 00:00:00 2001 From: tvcastillod Date: Wed, 14 Feb 2024 13:08:34 -0500 Subject: [PATCH 048/118] made adjustments on odf slice example --- .../SH-ODF experimental/ray_traced_6.0.py | 32 ++++++------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/docs/experimental/SH-ODF experimental/ray_traced_6.0.py b/docs/experimental/SH-ODF experimental/ray_traced_6.0.py index c9ae42313..e5a4ced8d 100644 --- a/docs/experimental/SH-ODF experimental/ray_traced_6.0.py +++ b/docs/experimental/SH-ODF experimental/ray_traced_6.0.py @@ -38,20 +38,6 @@ from fury.data import fetch_viz_dmri, read_viz_dmri from fury.primitive import prim_sphere - - -#scene = window.Scene() -#scene.background([255, 255, 255]) - -#showm = window.ShowManager(scene, size=(600, 600)) - - - -#tensors = actor.ellipsoid(centers=centers, colors=colors, axes=evecs, -# lengths=evals, scales=.6) -#showm.scene.add(tensors) -#showm.start() - def uv_calculations(n): uvs = [] for i in range(0, n): @@ -79,7 +65,9 @@ def uv_calculations(n): show_man.scene.background((1, 1, 1)) # fmt: off - coeffs, affine = load_nifti("docs\experimental\SH-ODF experimental\data\coeffs_odf.nii.gz") + coeffs, affine = load_nifti("docs\experimental\SH-ODF experimental\data\odf_slice_2.nii.gz") + print(coeffs) + print(coeffs.shape) valid_mask = np.abs(coeffs).max(axis=(-1)) > 0 indices = np.nonzero(valid_mask) @@ -88,15 +76,16 @@ def uv_calculations(n): x, y, z, s = coeffs.shape coeffs = coeffs[:, :, :].reshape((x * y * z, s)) + n_glyphs = coeffs.shape[0] + print(n_glyphs) - coeffs = np.array(coeffs)*.15 - coeffs = coeffs[:270,:] + coeffs = np.array(coeffs) * 1.6 - max_val = coeffs.max(axis=1) - coeffs = np.dot(np.abs(np.diag(1/max_val)), coeffs) * .7 - centers = centers[:270] + max_val = coeffs.min(axis=1) + #coeffs = np.dot(np.abs(np.diag(1/max_val)), coeffs) odf_actor = actor.box(centers=centers, scales=1.0) + odf_actor.GetMapper().SetVBOShiftScaleMethod(False) big_centers = np.repeat(centers, 8, axis=0) attribute_to_actor(odf_actor, big_centers, "center") @@ -108,7 +97,7 @@ def uv_calculations(n): odf_actor_pd = odf_actor.GetMapper().GetInput() # fmt: off - uv_vals = np.array(uv_calculations(270)) + uv_vals = np.array(uv_calculations(900)) # fmt: on num_pnts = uv_vals.shape[0] @@ -133,7 +122,6 @@ def uv_calculations(n): ) arr *= 255 grid = numpy_to_vtk_image_data(arr.astype(np.uint8)) - print(grid) texture = Texture() texture.SetInputDataObject(grid) From 2d41c300f9ecbeff8c7ea29e57fdf2f1ccaf3eaa Mon Sep 17 00:00:00 2001 From: tvcastillod Date: Wed, 14 Feb 2024 13:16:43 -0500 Subject: [PATCH 049/118] updated README --- docs/experimental/SH-ODF experimental/README.md | 2 ++ docs/experimental/SH-ODF experimental/ray_traced_6.0.py | 5 +---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/docs/experimental/SH-ODF experimental/README.md b/docs/experimental/SH-ODF experimental/README.md index 44efa162e..b5772cde9 100644 --- a/docs/experimental/SH-ODF experimental/README.md +++ b/docs/experimental/SH-ODF experimental/README.md @@ -34,3 +34,5 @@ To better understand the base approach and being able to build on top on it we n | BRDF lighting ([ray_traced_2.0.py](ray_traced_2.0.py)) | Blinn-Phong lighting ([ray_traced_4.0.py](ray_traced_4.0.py)) | |---|---| ||| + +- [ray_traced_6.0.py](ray_traced_6.0.py) An example with more data (a slice) using 'descoteaux07' basis and 4th order SH. diff --git a/docs/experimental/SH-ODF experimental/ray_traced_6.0.py b/docs/experimental/SH-ODF experimental/ray_traced_6.0.py index e5a4ced8d..2a89535dd 100644 --- a/docs/experimental/SH-ODF experimental/ray_traced_6.0.py +++ b/docs/experimental/SH-ODF experimental/ray_traced_6.0.py @@ -66,8 +66,6 @@ def uv_calculations(n): # fmt: off coeffs, affine = load_nifti("docs\experimental\SH-ODF experimental\data\odf_slice_2.nii.gz") - print(coeffs) - print(coeffs.shape) valid_mask = np.abs(coeffs).max(axis=(-1)) > 0 indices = np.nonzero(valid_mask) @@ -77,7 +75,6 @@ def uv_calculations(n): x, y, z, s = coeffs.shape coeffs = coeffs[:, :, :].reshape((x * y * z, s)) n_glyphs = coeffs.shape[0] - print(n_glyphs) coeffs = np.array(coeffs) * 1.6 @@ -97,7 +94,7 @@ def uv_calculations(n): odf_actor_pd = odf_actor.GetMapper().GetInput() # fmt: off - uv_vals = np.array(uv_calculations(900)) + uv_vals = np.array(uv_calculations(n_glyphs)) # fmt: on num_pnts = uv_vals.shape[0] From 175d03d8e202944988fac12784dae5d92d511ae9 Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Thu, 15 Feb 2024 16:46:29 -0500 Subject: [PATCH 050/118] Removed unused black tags. --- docs/experimental/SH-ODF experimental/ray_traced_2.0.py | 2 -- docs/experimental/SH-ODF experimental/ray_traced_4.0.py | 2 -- 2 files changed, 4 deletions(-) diff --git a/docs/experimental/SH-ODF experimental/ray_traced_2.0.py b/docs/experimental/SH-ODF experimental/ray_traced_2.0.py index e436e5df3..3468a4572 100644 --- a/docs/experimental/SH-ODF experimental/ray_traced_2.0.py +++ b/docs/experimental/SH-ODF experimental/ray_traced_2.0.py @@ -85,9 +85,7 @@ def uv_calculations(n): odf_actor_pd = odf_actor.GetMapper().GetInput() - # fmt: off uv_vals = np.array(uv_calculations(3)) - # fmt: on num_pnts = uv_vals.shape[0] diff --git a/docs/experimental/SH-ODF experimental/ray_traced_4.0.py b/docs/experimental/SH-ODF experimental/ray_traced_4.0.py index 94ff36696..92980d85f 100644 --- a/docs/experimental/SH-ODF experimental/ray_traced_4.0.py +++ b/docs/experimental/SH-ODF experimental/ray_traced_4.0.py @@ -77,9 +77,7 @@ def uv_calculations(n): odf_actor_pd = odf_actor.GetMapper().GetInput() - # fmt: off uv_vals = np.array(uv_calculations(3)) - # fmt: on num_pnts = uv_vals.shape[0] From dc18604e7700537aed9333f34af358e822fb7576 Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Thu, 15 Feb 2024 17:44:12 -0500 Subject: [PATCH 051/118] Minor changes in several ray_traced experiments. --- .../SH-ODF experimental/ray_traced_2.0.py | 32 ++++++++----------- .../SH-ODF experimental/ray_traced_3.0.py | 6 ++-- .../SH-ODF experimental/ray_traced_4.0.py | 20 ++++++------ 3 files changed, 25 insertions(+), 33 deletions(-) diff --git a/docs/experimental/SH-ODF experimental/ray_traced_2.0.py b/docs/experimental/SH-ODF experimental/ray_traced_2.0.py index 3468a4572..ebbdeb1fe 100644 --- a/docs/experimental/SH-ODF experimental/ray_traced_2.0.py +++ b/docs/experimental/SH-ODF experimental/ray_traced_2.0.py @@ -128,13 +128,14 @@ def uv_calculations(n): out vec4 vertexMCVSOutput; out vec3 centerMCVSOutput; out vec2 minmaxVSOutput; + out vec3 camPosMCVSOutput; """ vs_impl = """ vertexMCVSOutput = vertexMC; centerMCVSOutput = center; minmaxVSOutput = minmax; - vec3 camPos = -MCVCMatrix[3].xyz * mat3(MCVCMatrix); + camPosMCVSOutput = -MCVCMatrix[3].xyz * mat3(MCVCMatrix); """ shader_to_actor(odf_actor, "vertex", decl_code=vs_dec, impl_code=vs_impl) @@ -172,14 +173,11 @@ def uv_calculations(n): #define M_INV_PI 0.318309886183790671537767526745 """ - fs_unifs = """ - uniform mat4 MCVCMatrix; - """ - fs_vs_vars = """ in vec4 vertexMCVSOutput; in vec3 centerMCVSOutput; in vec2 minmaxVSOutput; + in vec3 camPosMCVSOutput; """ coeffs_norm = """ @@ -342,14 +340,14 @@ def uv_calculations(n): # fmt: off fs_dec = compose_shader([ def_sh_degree, def_sh_count, def_max_degree, - def_gl_ext_control_flow_attributes, def_no_intersection, - def_pis, fs_unifs, fs_vs_vars, coeffs_norm, eval_sh_2, eval_sh_4, eval_sh_6, - eval_sh_8, eval_sh_10, eval_sh_12, eval_sh_grad_2, eval_sh_grad_4, - eval_sh_grad_6, eval_sh_grad_8, eval_sh_grad_10, eval_sh_grad_12, - newton_bisection, find_roots, eval_sh, eval_sh_grad, - get_inv_vandermonde, ray_sh_glyph_intersections, get_sh_glyph_normal, - gltf_dielectric_brdf, linear_to_srgb, srgb_to_linear, - linear_rgb_to_srgb, srgb_to_linear_rgb, tonemap + def_gl_ext_control_flow_attributes, def_no_intersection, def_pis, + fs_vs_vars, coeffs_norm, eval_sh_2, eval_sh_4, eval_sh_6, eval_sh_8, + eval_sh_10, eval_sh_12, eval_sh_grad_2, eval_sh_grad_4, eval_sh_grad_6, + eval_sh_grad_8, eval_sh_grad_10, eval_sh_grad_12, newton_bisection, + find_roots, eval_sh, eval_sh_grad, get_inv_vandermonde, + ray_sh_glyph_intersections, get_sh_glyph_normal, gltf_dielectric_brdf, + linear_to_srgb, srgb_to_linear, linear_rgb_to_srgb, srgb_to_linear_rgb, + tonemap ]) # fmt: on @@ -358,16 +356,12 @@ def uv_calculations(n): point_from_vs = "vec3 pnt = vertexMCVSOutput.xyz;" # Ray origin is the camera position in world space - ray_origin = """ - vec3 ro = (-MCVCMatrix[3] * MCVCMatrix).xyz; - """ + ray_origin = "vec3 ro = camPosMCVSOutput;" # TODO: Check aspect for automatic scaling # Ray direction is the normalized difference between the fragment and the # camera position/ray origin - ray_direction = """ - vec3 rd = normalize(pnt - ro); - """ + ray_direction = "vec3 rd = normalize(pnt - ro);" # Light direction in a retroreflective model is the normalized difference # between the camera position/ray origin and the fragment diff --git a/docs/experimental/SH-ODF experimental/ray_traced_3.0.py b/docs/experimental/SH-ODF experimental/ray_traced_3.0.py index 03814b404..b12b1e8e8 100644 --- a/docs/experimental/SH-ODF experimental/ray_traced_3.0.py +++ b/docs/experimental/SH-ODF experimental/ray_traced_3.0.py @@ -238,9 +238,9 @@ # fmt: off fs_dec = compose_shader([ def_sh_degree, def_sh_count, def_max_degree, - def_gl_ext_control_flow_attributes, def_no_intersection, - def_pis, fs_vs_vars, eval_sh_2, eval_sh_4, eval_sh_6, eval_sh_8, - eval_sh_10, eval_sh_12, eval_sh_grad_2, eval_sh_grad_4, eval_sh_grad_6, + def_gl_ext_control_flow_attributes, def_no_intersection, def_pis, + fs_vs_vars, eval_sh_2, eval_sh_4, eval_sh_6, eval_sh_8, eval_sh_10, + eval_sh_12, eval_sh_grad_2, eval_sh_grad_4, eval_sh_grad_6, eval_sh_grad_8, eval_sh_grad_10, eval_sh_grad_12, newton_bisection, find_roots, eval_sh, eval_sh_grad, get_inv_vandermonde, ray_sh_glyph_intersections, get_sh_glyph_normal, blinn_phong_model, diff --git a/docs/experimental/SH-ODF experimental/ray_traced_4.0.py b/docs/experimental/SH-ODF experimental/ray_traced_4.0.py index 92980d85f..119c64624 100644 --- a/docs/experimental/SH-ODF experimental/ray_traced_4.0.py +++ b/docs/experimental/SH-ODF experimental/ray_traced_4.0.py @@ -331,14 +331,14 @@ def uv_calculations(n): # fmt: off fs_dec = compose_shader([ def_sh_degree, def_sh_count, def_max_degree, - def_gl_ext_control_flow_attributes, def_no_intersection, - def_pis, fs_vs_vars, coeffs_norm, eval_sh_2, eval_sh_4, eval_sh_6, - eval_sh_8, eval_sh_10, eval_sh_12, eval_sh_grad_2, eval_sh_grad_4, - eval_sh_grad_6, eval_sh_grad_8, eval_sh_grad_10, eval_sh_grad_12, - newton_bisection, find_roots, eval_sh, eval_sh_grad, - get_inv_vandermonde, ray_sh_glyph_intersections, get_sh_glyph_normal, - blinn_phong_model, linear_to_srgb, srgb_to_linear, - linear_rgb_to_srgb, srgb_to_linear_rgb, tonemap + def_gl_ext_control_flow_attributes, def_no_intersection, def_pis, + fs_vs_vars, coeffs_norm, eval_sh_2, eval_sh_4, eval_sh_6, eval_sh_8, + eval_sh_10, eval_sh_12, eval_sh_grad_2, eval_sh_grad_4, eval_sh_grad_6, + eval_sh_grad_8, eval_sh_grad_10, eval_sh_grad_12, newton_bisection, + find_roots, eval_sh, eval_sh_grad, get_inv_vandermonde, + ray_sh_glyph_intersections, get_sh_glyph_normal, blinn_phong_model, + linear_to_srgb, srgb_to_linear, linear_rgb_to_srgb, srgb_to_linear_rgb, + tonemap ]) # fmt: on @@ -352,9 +352,7 @@ def uv_calculations(n): # TODO: Check aspect for automatic scaling # Ray direction is the normalized difference between the fragment and the # camera position/ray origin - ray_direction = """ - vec3 rd = normalize(pnt - ro); - """ + ray_direction = "vec3 rd = normalize(pnt - ro);" # Light direction in a retroreflective model is the normalized difference # between the camera position/ray origin and the fragment From 10c185dd5e6966531cc023406d93ff42d7609738 Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Thu, 15 Feb 2024 17:46:32 -0500 Subject: [PATCH 052/118] Improved multiplatform compatibility of ray_traced_6.0.py. Changed illumination model. --- .../SH-ODF experimental/ray_traced_6.0.py | 150 +++++++----------- 1 file changed, 55 insertions(+), 95 deletions(-) diff --git a/docs/experimental/SH-ODF experimental/ray_traced_6.0.py b/docs/experimental/SH-ODF experimental/ray_traced_6.0.py index 2a89535dd..99bef4ec5 100644 --- a/docs/experimental/SH-ODF experimental/ray_traced_6.0.py +++ b/docs/experimental/SH-ODF experimental/ray_traced_6.0.py @@ -1,21 +1,11 @@ """ -Fury's implementation of "Ray Tracing Spherical Harmonics Glyphs": -https://momentsingraphics.de/VMV2023.html -The fragment shader is based on: https://www.shadertoy.com/view/dlGSDV -(c) 2023, Christoph Peters -This work is licensed under a CC0 1.0 Universal License. To the extent -possible under law, Christoph Peters has waived all copyright and related or -neighboring rights to the following code. This work is published from -Germany. https://creativecommons.org/publicdomain/zero/1.0/ """ import os import numpy as np -from dipy.data import get_sphere -from dipy.reconst.shm import sh_to_sf, sf_to_sh - -from dipy.io.image import load_nifti, save_nifti +from dipy.data.fetcher import dipy_home +from dipy.io.image import load_nifti from fury import actor, window from fury.lib import FloatArray, Texture @@ -27,16 +17,6 @@ ) from fury.utils import numpy_to_vtk_image_data, set_polydata_tcoords -import itertools - -import numpy as np - -from dipy.io.image import load_nifti - -from fury import window, actor, ui -from fury.actor import _fa, _color_fa -from fury.data import fetch_viz_dmri, read_viz_dmri -from fury.primitive import prim_sphere def uv_calculations(n): uvs = [] @@ -59,43 +39,43 @@ def uv_calculations(n): return uvs - if __name__ == "__main__": - show_man = window.ShowManager(size=(1920, 1080)) + show_man = window.ShowManager(size=(1280, 720)) show_man.scene.background((1, 1, 1)) - # fmt: off - coeffs, affine = load_nifti("docs\experimental\SH-ODF experimental\data\odf_slice_2.nii.gz") - + dataset_dir = os.path.join(dipy_home, "stanford_hardi") + + coeffs, affine = load_nifti( + os.path.join(dataset_dir, "odf_slice_2.nii.gz") + ) + valid_mask = np.abs(coeffs).max(axis=(-1)) > 0 indices = np.nonzero(valid_mask) centers = np.asarray(indices).T - + x, y, z, s = coeffs.shape coeffs = coeffs[:, :, :].reshape((x * y * z, s)) n_glyphs = coeffs.shape[0] coeffs = np.array(coeffs) * 1.6 - + max_val = coeffs.min(axis=1) - #coeffs = np.dot(np.abs(np.diag(1/max_val)), coeffs) - - odf_actor = actor.box(centers=centers, scales=1.0) + # coeffs = np.dot(np.abs(np.diag(1/max_val)), coeffs) + + odf_actor = actor.box(centers=centers, scales=1) odf_actor.GetMapper().SetVBOShiftScaleMethod(False) big_centers = np.repeat(centers, 8, axis=0) attribute_to_actor(odf_actor, big_centers, "center") - + minmax = np.array([coeffs.min(axis=1), coeffs.max(axis=1)]).T big_minmax = np.repeat(minmax, 8, axis=0) attribute_to_actor(odf_actor, big_minmax, "minmax") odf_actor_pd = odf_actor.GetMapper().GetInput() - # fmt: off uv_vals = np.array(uv_calculations(n_glyphs)) - # fmt: on num_pnts = uv_vals.shape[0] @@ -138,13 +118,20 @@ def uv_calculations(n): out vec4 vertexMCVSOutput; out vec3 centerMCVSOutput; out vec2 minmaxVSOutput; + out vec3 camPosMCVSOutput; + out vec3 camRightMCVSOutput; + out vec3 camUpMCVSOutput; """ vs_impl = """ vertexMCVSOutput = vertexMC; centerMCVSOutput = center; minmaxVSOutput = minmax; - vec3 camPos = -MCVCMatrix[3].xyz * mat3(MCVCMatrix); + camPosMCVSOutput = -MCVCMatrix[3].xyz * mat3(MCVCMatrix); + camRightMCVSOutput = vec3( + MCVCMatrix[0][0], MCVCMatrix[1][0], MCVCMatrix[2][0]); + camUpMCVSOutput = vec3( + MCVCMatrix[0][1], MCVCMatrix[1][1], MCVCMatrix[2][1]); """ shader_to_actor(odf_actor, "vertex", decl_code=vs_dec, impl_code=vs_impl) @@ -182,14 +169,13 @@ def uv_calculations(n): #define M_INV_PI 0.318309886183790671537767526745 """ - fs_unifs = """ - uniform mat4 MCVCMatrix; - """ - fs_vs_vars = """ in vec4 vertexMCVSOutput; in vec3 centerMCVSOutput; in vec2 minmaxVSOutput; + in vec3 camPosMCVSOutput; + in vec3 camRightMCVSOutput; + in vec3 camUpMCVSOutput; """ coeffs_norm = """ @@ -203,29 +189,17 @@ def uv_calculations(n): } """ - eval_sh_2 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_2.frag") - ) + eval_sh_2 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_2.frag")) - eval_sh_4 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_4.frag") - ) + eval_sh_4 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_4.frag")) - eval_sh_6 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_6.frag") - ) + eval_sh_6 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_6.frag")) - eval_sh_8 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_8.frag") - ) + eval_sh_8 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_8.frag")) - eval_sh_10 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_10.frag") - ) + eval_sh_10 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_10.frag")) - eval_sh_12 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_12.frag") - ) + eval_sh_12 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_12.frag")) eval_sh_grad_2 = import_fury_shader( os.path.join("rt_odfs", "eval_sh_grad_2.frag") @@ -324,20 +298,6 @@ def uv_calculations(n): os.path.join("rt_odfs", "get_sh_glyph_normal.frag") ) - # This is the glTF BRDF for dielectric materials, exactly as described - # here: - # https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#appendix-b-brdf-implementation - # param incoming The normalized incoming light direction. - # param outgoing The normalized outgoing light direction. - # param normal The normalized shading normal. - # param roughness An artist friendly roughness value between 0 and 1. - # param base_color The albedo used for the Lambertian diffuse component. - # - # return The BRDF for the given directions. - gltf_dielectric_brdf = import_fury_shader( - os.path.join("rt_odfs", "gltf_dielectric_brdf.frag") - ) - # Applies the non-linearity that maps linear RGB to sRGB linear_to_srgb = import_fury_shader( os.path.join("rt_odfs", "linear_to_srgb.frag") @@ -361,17 +321,22 @@ def uv_calculations(n): # Logarithmic tonemapping operator. Input and output are linear RGB. tonemap = import_fury_shader(os.path.join("rt_odfs", "tonemap.frag")) + # Blinn-Phong illumination model + blinn_phong_model = import_fury_shader( + os.path.join("lighting", "blinn_phong_model.frag") + ) + # fmt: off fs_dec = compose_shader([ def_sh_degree, def_sh_count, def_max_degree, - def_gl_ext_control_flow_attributes, def_no_intersection, - def_pis, fs_unifs, fs_vs_vars, coeffs_norm, eval_sh_2, eval_sh_4, eval_sh_6, - eval_sh_8, eval_sh_10, eval_sh_12, eval_sh_grad_2, eval_sh_grad_4, - eval_sh_grad_6, eval_sh_grad_8, eval_sh_grad_10, eval_sh_grad_12, - newton_bisection, find_roots, eval_sh, eval_sh_grad, - get_inv_vandermonde, ray_sh_glyph_intersections, get_sh_glyph_normal, - gltf_dielectric_brdf, linear_to_srgb, srgb_to_linear, - linear_rgb_to_srgb, srgb_to_linear_rgb, tonemap + def_gl_ext_control_flow_attributes, def_no_intersection, def_pis, + fs_vs_vars, coeffs_norm, eval_sh_2, eval_sh_4, eval_sh_6, eval_sh_8, + eval_sh_10, eval_sh_12, eval_sh_grad_2, eval_sh_grad_4, eval_sh_grad_6, + eval_sh_grad_8, eval_sh_grad_10, eval_sh_grad_12, newton_bisection, + find_roots, eval_sh, eval_sh_grad, get_inv_vandermonde, + ray_sh_glyph_intersections, get_sh_glyph_normal, blinn_phong_model, + linear_to_srgb, srgb_to_linear, linear_rgb_to_srgb, srgb_to_linear_rgb, + tonemap ]) # fmt: on @@ -380,16 +345,12 @@ def uv_calculations(n): point_from_vs = "vec3 pnt = vertexMCVSOutput.xyz;" # Ray origin is the camera position in world space - ray_origin = """ - vec3 ro = (-MCVCMatrix[3] * MCVCMatrix).xyz; - """ + ray_origin = "vec3 ro = camPosMCVSOutput;" # TODO: Check aspect for automatic scaling # Ray direction is the normalized difference between the fragment and the # camera position/ray origin - ray_direction = """ - vec3 rd = normalize(pnt - ro); - """ + ray_direction = "vec3 rd = normalize(pnt - ro);" # Light direction in a retroreflective model is the normalized difference # between the camera position/ray origin and the fragment @@ -424,17 +385,16 @@ def uv_calculations(n): # Evaluate shading for a directional light directional_light = """ - vec3 color = vec3(1.0); + vec3 color = vec3(1.); if (first_ray_param != NO_INTERSECTION) { vec3 intersection = ro - centerMCVSOutput + first_ray_param * rd; vec3 normal = get_sh_glyph_normal(sh_coeffs, intersection); - vec3 base_color = srgb_to_linear_rgb(abs(normalize(intersection))); - const vec3 incoming = normalize(vec3(1.23, -4.56, 7.89)); - float ambient = 0.04; - float exposure = 4.0; - vec3 outgoing = -rd; - vec3 brdf = gltf_dielectric_brdf(incoming, outgoing, normal, 0.45, base_color); - color = exposure * (brdf * max(0.0, dot(incoming, normal)) + base_color * ambient); + vec3 colorDir = srgb_to_linear_rgb(abs(normalize(intersection))); + float attenuation = dot(ld, normal); + color = blinnPhongIllumModel( + //attenuation, lightColor0, diffuseColor, specularPower, + attenuation, lightColor0, colorDir, specularPower, + specularColor, ambientColor); } else { discard; } @@ -444,6 +404,7 @@ def uv_calculations(n): //vec4 out_color = vec4(linear_rgb_to_srgb(tonemap(color)), 1.0); vec3 out_color = linear_rgb_to_srgb(tonemap(color)); fragOutput0 = vec4(out_color, opacity); + //fragOutput0 = vec4(color, opacity); """ # fmt: off @@ -457,4 +418,3 @@ def uv_calculations(n): show_man.scene.add(odf_actor) show_man.start() - From fdd25cf701ed65b38605683424246d4e9c2c7de6 Mon Sep 17 00:00:00 2001 From: tvcastillod Date: Thu, 15 Feb 2024 18:44:53 -0500 Subject: [PATCH 053/118] fixed scaling --- docs/experimental/SH-ODF experimental/ray_traced_6.0.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/docs/experimental/SH-ODF experimental/ray_traced_6.0.py b/docs/experimental/SH-ODF experimental/ray_traced_6.0.py index 2a89535dd..997910262 100644 --- a/docs/experimental/SH-ODF experimental/ray_traced_6.0.py +++ b/docs/experimental/SH-ODF experimental/ray_traced_6.0.py @@ -75,11 +75,10 @@ def uv_calculations(n): x, y, z, s = coeffs.shape coeffs = coeffs[:, :, :].reshape((x * y * z, s)) n_glyphs = coeffs.shape[0] - - coeffs = np.array(coeffs) * 1.6 max_val = coeffs.min(axis=1) - #coeffs = np.dot(np.abs(np.diag(1/max_val)), coeffs) + total = np.sum(abs(coeffs), axis=1) + coeffs = np.dot(np.diag(1/total), coeffs) * 1.7 odf_actor = actor.box(centers=centers, scales=1.0) odf_actor.GetMapper().SetVBOShiftScaleMethod(False) @@ -452,7 +451,7 @@ def uv_calculations(n): intersection_test, first_intersection, directional_light, frag_output ]) # fmt: on - + show_man.scene.background([0,0,0]) shader_to_actor(odf_actor, "fragment", impl_code=fs_impl, block="picking") show_man.scene.add(odf_actor) From f73d7d09c2378729a618eb230fbfd9ad707d2652 Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Fri, 16 Feb 2024 21:22:33 -0500 Subject: [PATCH 054/118] Fixed merge. --- .../SH-ODF experimental/ray_traced_6.0.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/docs/experimental/SH-ODF experimental/ray_traced_6.0.py b/docs/experimental/SH-ODF experimental/ray_traced_6.0.py index 690686182..6c2bdc723 100644 --- a/docs/experimental/SH-ODF experimental/ray_traced_6.0.py +++ b/docs/experimental/SH-ODF experimental/ray_traced_6.0.py @@ -41,7 +41,6 @@ def uv_calculations(n): if __name__ == "__main__": show_man = window.ShowManager(size=(1280, 720)) - show_man.scene.background((1, 1, 1)) dataset_dir = os.path.join(dipy_home, "stanford_hardi") @@ -58,13 +57,11 @@ def uv_calculations(n): coeffs = coeffs[:, :, :].reshape((x * y * z, s)) n_glyphs = coeffs.shape[0] - coeffs = np.array(coeffs) * 1.6 - - max_val = coeffs.min(axis=1) - #coeffs = np.dot(np.abs(np.diag(1/max_val)), coeffs) + total = np.sum(abs(coeffs), axis=1) + coeffs = np.dot(np.diag(1 / total), coeffs) * 1.7 - odf_actor = actor.box(centers=centers, scales=1.0) + odf_actor = actor.box(centers=centers, scales=1) odf_actor.GetMapper().SetVBOShiftScaleMethod(False) big_centers = np.repeat(centers, 8, axis=0) @@ -414,7 +411,7 @@ def uv_calculations(n): intersection_test, first_intersection, directional_light, frag_output ]) # fmt: on - show_man.scene.background([0,0,0]) + shader_to_actor(odf_actor, "fragment", impl_code=fs_impl, block="picking") show_man.scene.add(odf_actor) From a7724d723c4d70dd8223a604a60e705027ee4ad2 Mon Sep 17 00:00:00 2001 From: tvcastillod Date: Fri, 23 Feb 2024 09:29:11 -0500 Subject: [PATCH 055/118] added odf actor implementation --- .../SH-ODF experimental/odf_example.py | 31 + fury/actor.py | 48 ++ fury/actors/odf.py | 428 +++++++++++++ .../rt_odfs/descoteaux/eval_sh_10.frag | 175 ++++++ .../rt_odfs/descoteaux/eval_sh_12.frag | 238 +++++++ .../shaders/rt_odfs/descoteaux/eval_sh_2.frag | 23 + .../shaders/rt_odfs/descoteaux/eval_sh_4.frag | 46 ++ .../shaders/rt_odfs/descoteaux/eval_sh_6.frag | 79 +++ .../shaders/rt_odfs/descoteaux/eval_sh_8.frag | 122 ++++ fury/shaders/rt_odfs/eval_sh.frag | 16 + fury/shaders/rt_odfs/eval_sh_grad.frag | 16 + fury/shaders/rt_odfs/eval_sh_grad_10.frag | 430 +++++++++++++ fury/shaders/rt_odfs/eval_sh_grad_12.frag | 591 ++++++++++++++++++ fury/shaders/rt_odfs/eval_sh_grad_2.frag | 46 ++ fury/shaders/rt_odfs/eval_sh_grad_4.frag | 103 +++ fury/shaders/rt_odfs/eval_sh_grad_6.frag | 186 ++++++ fury/shaders/rt_odfs/eval_sh_grad_8.frag | 295 +++++++++ fury/shaders/rt_odfs/find_roots.frag | 82 +++ fury/shaders/rt_odfs/get_inv_vandermonde.frag | 58 ++ fury/shaders/rt_odfs/get_sh_glyph_normal.frag | 16 + .../shaders/rt_odfs/gltf_dielectric_brdf.frag | 41 ++ fury/shaders/rt_odfs/linear_rgb_to_srgb.frag | 4 + fury/shaders/rt_odfs/linear_to_srgb.frag | 4 + fury/shaders/rt_odfs/newton_bisection.frag | 47 ++ .../rt_odfs/ray_sh_glyph_intersections.frag | 81 +++ fury/shaders/rt_odfs/srgb_to_linear.frag | 4 + fury/shaders/rt_odfs/srgb_to_linear_rgb.frag | 4 + fury/shaders/rt_odfs/tonemap.frag | 5 + fury/shaders/rt_odfs/tournier/eval_sh_10.frag | 175 ++++++ fury/shaders/rt_odfs/tournier/eval_sh_12.frag | 238 +++++++ fury/shaders/rt_odfs/tournier/eval_sh_2.frag | 23 + fury/shaders/rt_odfs/tournier/eval_sh_4.frag | 46 ++ fury/shaders/rt_odfs/tournier/eval_sh_6.frag | 79 +++ fury/shaders/rt_odfs/tournier/eval_sh_8.frag | 122 ++++ fury/shaders/utils/minmax_norm.glsl | 4 + 35 files changed, 3906 insertions(+) create mode 100644 docs/experimental/SH-ODF experimental/odf_example.py create mode 100644 fury/actors/odf.py create mode 100644 fury/shaders/rt_odfs/descoteaux/eval_sh_10.frag create mode 100644 fury/shaders/rt_odfs/descoteaux/eval_sh_12.frag create mode 100644 fury/shaders/rt_odfs/descoteaux/eval_sh_2.frag create mode 100644 fury/shaders/rt_odfs/descoteaux/eval_sh_4.frag create mode 100644 fury/shaders/rt_odfs/descoteaux/eval_sh_6.frag create mode 100644 fury/shaders/rt_odfs/descoteaux/eval_sh_8.frag create mode 100644 fury/shaders/rt_odfs/eval_sh.frag create mode 100644 fury/shaders/rt_odfs/eval_sh_grad.frag create mode 100644 fury/shaders/rt_odfs/eval_sh_grad_10.frag create mode 100644 fury/shaders/rt_odfs/eval_sh_grad_12.frag create mode 100644 fury/shaders/rt_odfs/eval_sh_grad_2.frag create mode 100644 fury/shaders/rt_odfs/eval_sh_grad_4.frag create mode 100644 fury/shaders/rt_odfs/eval_sh_grad_6.frag create mode 100644 fury/shaders/rt_odfs/eval_sh_grad_8.frag create mode 100644 fury/shaders/rt_odfs/find_roots.frag create mode 100644 fury/shaders/rt_odfs/get_inv_vandermonde.frag create mode 100644 fury/shaders/rt_odfs/get_sh_glyph_normal.frag create mode 100644 fury/shaders/rt_odfs/gltf_dielectric_brdf.frag create mode 100644 fury/shaders/rt_odfs/linear_rgb_to_srgb.frag create mode 100644 fury/shaders/rt_odfs/linear_to_srgb.frag create mode 100644 fury/shaders/rt_odfs/newton_bisection.frag create mode 100644 fury/shaders/rt_odfs/ray_sh_glyph_intersections.frag create mode 100644 fury/shaders/rt_odfs/srgb_to_linear.frag create mode 100644 fury/shaders/rt_odfs/srgb_to_linear_rgb.frag create mode 100644 fury/shaders/rt_odfs/tonemap.frag create mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_10.frag create mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_12.frag create mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_2.frag create mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_4.frag create mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_6.frag create mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_8.frag create mode 100644 fury/shaders/utils/minmax_norm.glsl diff --git a/docs/experimental/SH-ODF experimental/odf_example.py b/docs/experimental/SH-ODF experimental/odf_example.py new file mode 100644 index 000000000..3b6c60469 --- /dev/null +++ b/docs/experimental/SH-ODF experimental/odf_example.py @@ -0,0 +1,31 @@ +import os + +import numpy as np +from dipy.data.fetcher import dipy_home +from dipy.io.image import load_nifti + +from fury import actor, window + +if __name__ == "__main__": + show_man = window.ShowManager(size=(1280, 720)) + + dataset_dir = os.path.join(dipy_home, "stanford_hardi") + + coeffs, affine = load_nifti("docs\experimental\SH-ODF experimental\coefs_odf.nii") + + valid_mask = np.abs(coeffs).max(axis=(-1)) > 0 + indices = np.nonzero(valid_mask) + + centers = np.asarray(indices).T + + x, y, z, s = coeffs.shape + coeffs = coeffs[:, :, :].reshape((x * y * z, s)) + n_glyphs = coeffs.shape[0] + + max_val = coeffs.min(axis=1) + total = np.sum(abs(coeffs), axis=1) + coeffs = np.dot(np.diag(1 / total), coeffs) * 1.7 + + odf_actor = actor.odf(centers=centers, coeffs=coeffs) + show_man.scene.add(odf_actor) + show_man.start() \ No newline at end of file diff --git a/fury/actor.py b/fury/actor.py index b8a4b440b..ae71bb95e 100644 --- a/fury/actor.py +++ b/fury/actor.py @@ -11,6 +11,7 @@ from fury.actors.odf_slicer import OdfSlicerActor from fury.actors.peak import PeakActor from fury.actors.tensor import tensor_ellipsoid +from fury.actors.odf import sh_odf from fury.colormap import colormap_lookup_table from fury.deprecator import deprecate_with_version, deprecated_params from fury.io import load_image @@ -3868,3 +3869,50 @@ def ellipsoid( return tensor_ellipsoid(centers, axes, lengths, colors, scales, opacity) + +def odf( + centers, + coeffs, + basis_type='descoteaux', + scales=1.0, + opacity=1.0 +): + """ + VTK actor for visualizing ODFs given an array of spherical harmonics (SH) + coefficients. + + Parameters + ---------- + centers : ndarray(N, 3) + ODFs positions. + coeffs : ndarray + 2D ODFs array in SH coefficients. + basis_type: str, optional + Type of basis (descoteaux, tournier) + 'descoteaux' for the default ``descoteaux07`` DYPY basis. + 'tournier' for the default ``tournier07` DYPY basis. + scales : float or ndarray (N, ) + ODFs size. + opacity : float + Takes values from 0 (fully transparent) to 1 (opaque). + + Returns + ------- + odf: Actor + + """ + + if not isinstance(centers, np.ndarray): + centers = np.array(centers) + if centers.ndim == 1: + centers = np.array([centers]) + + if not isinstance(scales, np.ndarray): + scales = np.array(scales) + if scales.size == 1: + scales = np.repeat(scales, centers.shape[0]) + elif scales.size != centers.shape[0]: + scales = np.concatenate( + (scales, np.ones(centers.shape[0] - scales.shape[0])), axis=None) + + return sh_odf(centers, coeffs, basis_type, scales, opacity) \ No newline at end of file diff --git a/fury/actors/odf.py b/fury/actors/odf.py new file mode 100644 index 000000000..a6d991033 --- /dev/null +++ b/fury/actors/odf.py @@ -0,0 +1,428 @@ +import os + +import numpy as np + +from fury import actor +from fury.lib import FloatArray, Texture +from fury.shaders import ( + attribute_to_actor, + compose_shader, + import_fury_shader, + shader_to_actor, +) +from fury.utils import numpy_to_vtk_image_data, set_polydata_tcoords + +def uv_calculations(n): + uvs = [] + for i in range(0, n): + a = (n - (i + 1)) / n + b = (n - i) / n + uvs.extend( + [ + [0.001, a + 0.001], + [0.001, b - 0.001], + [0.999, b - 0.001], + [0.999, a + 0.001], + [0.001, a + 0.001], + [0.001, b - 0.001], + [0.999, b - 0.001], + [0.999, a + 0.001], + ] + ) + return uvs + +def minmax_norm(data): + + min = data.min(axis=1) + max = data.max(axis=1) + return np.array([(data[i] - min[i]) / (max[i] - min[i]) + for i in range(data.shape[0])]) + + +def sh_odf(centers, coeffs, basis_type, scales, opacity): + """ + Visualize one or many ODFs with different features. + + Parameters + ---------- + centers : ndarray(N, 3) + ODFs positions. + coeffs : ndarray + 2D ODFs array in SH coefficients. + basis_type: str, optional + Type of basis (descoteaux, tournier) + 'descoteaux' for the default ``descoteaux07`` DYPY basis. + 'tournier' for the default ``tournier07` DYPY basis. + scales : float or ndarray (N, ) + ODFs size. + opacity : float + Takes values from 0 (fully transparent) to 1 (opaque). + + Returns + ------- + box_actor: Actor + + """ + odf_actor = actor.box(centers=centers, scales=scales) + odf_actor.GetMapper().SetVBOShiftScaleMethod(False) + odf_actor.GetProperty().SetOpacity(opacity) + + big_centers = np.repeat(centers, 8, axis=0) + attribute_to_actor(odf_actor, big_centers, "center") + + minmax = np.array([coeffs.min(axis=1), coeffs.max(axis=1)]).T + big_minmax = np.repeat(minmax, 8, axis=0) + attribute_to_actor(odf_actor, big_minmax, "minmax") + + # The coefficient data is stored in a texture to be passed to the shaders. + + # Data is normalized to a range of 0 to 1. + arr = minmax_norm(coeffs) + # Data is turned into values within the RGB color range, and then coverted + # into a vtk image data. + arr *= 255 + grid = numpy_to_vtk_image_data(arr.astype(np.uint8)) + + # Vtk image data is associated to a texture. + texture = Texture() + texture.SetInputDataObject(grid) + texture.Update() + + # Texture is associated with the actor + odf_actor.GetProperty().SetTexture("texture0", texture) + + + odf_actor_pd = odf_actor.GetMapper().GetInput() + + n_glyphs = coeffs.shape[0] + # Coordinates to locate the data of each glyph in the texture. + uv_vals = np.array(uv_calculations(n_glyphs)) + num_pnts = uv_vals.shape[0] + + t_coords = FloatArray() + t_coords.SetNumberOfComponents(2) + t_coords.SetNumberOfTuples(num_pnts) + [t_coords.SetTuple(i, uv_vals[i]) for i in range(num_pnts)] + + set_polydata_tcoords(odf_actor_pd, t_coords) + + # The number of coefficients is associated to the order of the SH + odf_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniformf( + "numCoeffs", 15 + ) + + # Start of shader implementation + + vs_dec = \ + """ + in vec3 center; + in vec2 minmax; + + out vec4 vertexMCVSOutput; + out vec3 centerMCVSOutput; + out vec2 minmaxVSOutput; + out vec3 camPosMCVSOutput; + out vec3 camRightMCVSOutput; + out vec3 camUpMCVSOutput; + """ + + vs_impl = \ + """ + vertexMCVSOutput = vertexMC; + centerMCVSOutput = center; + minmaxVSOutput = minmax; + camPosMCVSOutput = -MCVCMatrix[3].xyz * mat3(MCVCMatrix); + camRightMCVSOutput = vec3( + MCVCMatrix[0][0], MCVCMatrix[1][0], MCVCMatrix[2][0]); + camUpMCVSOutput = vec3( + MCVCMatrix[0][1], MCVCMatrix[1][1], MCVCMatrix[2][1]); + """ + + shader_to_actor(odf_actor, "vertex", decl_code=vs_dec, impl_code=vs_impl) + + # The index of the highest used band of the spherical harmonics basis. Must + # be even, at least 2 and at most 12. + def_sh_degree = "#define SH_DEGREE 4" + + # The number of spherical harmonics basis functions + def_sh_count = "#define SH_COUNT (((SH_DEGREE + 1) * (SH_DEGREE + 2)) / 2)" + + # Degree of polynomials for which we have to find roots + def_max_degree = "#define MAX_DEGREE (2 * SH_DEGREE + 2)" + + # If GL_EXT_control_flow_attributes is available, these defines should be + # defined as [[unroll]] and [[loop]] to give reasonable hints to the + # compiler. That avoids register spilling, which makes execution + # considerably faster. + def_gl_ext_control_flow_attributes = \ + """ + #ifndef _unroll_ + #define _unroll_ + #endif + #ifndef _loop_ + #define _loop_ + #endif + """ + + # When there are fewer intersections/roots than theoretically possible, + # some array entries are set to this value + def_no_intersection = "#define NO_INTERSECTION 3.4e38" + + # pi and its reciprocal + def_pis = \ + """ + #define M_PI 3.141592653589793238462643 + #define M_INV_PI 0.318309886183790671537767526745 + """ + + fs_vs_vars = \ + """ + in vec4 vertexMCVSOutput; + in vec3 centerMCVSOutput; + in vec2 minmaxVSOutput; + in vec3 camPosMCVSOutput; + in vec3 camRightMCVSOutput; + in vec3 camUpMCVSOutput; + """ + + coeffs_norm = import_fury_shader(os.path.join("utils", "minmax_norm.glsl")) + + eval_sh_2 = import_fury_shader( + os.path.join("rt_odfs", basis_type, "eval_sh_2.frag")) + + eval_sh_4 = import_fury_shader( + os.path.join("rt_odfs", basis_type, "eval_sh_4.frag")) + + eval_sh_6 = import_fury_shader( + os.path.join("rt_odfs", basis_type, "eval_sh_6.frag")) + + eval_sh_8 = import_fury_shader( + os.path.join("rt_odfs", basis_type, "eval_sh_8.frag")) + + eval_sh_10 = import_fury_shader( + os.path.join("rt_odfs", basis_type, "eval_sh_10.frag")) + + eval_sh_12 = import_fury_shader( + os.path.join("rt_odfs", basis_type, "eval_sh_12.frag")) + + eval_sh_grad_2 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_2.frag") + ) + + eval_sh_grad_4 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_4.frag") + ) + + eval_sh_grad_6 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_6.frag") + ) + + eval_sh_grad_8 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_8.frag") + ) + + eval_sh_grad_10 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_10.frag") + ) + + eval_sh_grad_12 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_12.frag") + ) + + # Searches a single root of a polynomial within a given interval. + # param out_root The location of the found root. + # param out_end_value The value of the given polynomial at end. + # param poly Coefficients of the polynomial for which a root should be + # found. + # Coefficient poly[i] is multiplied by x^i. + # param begin The beginning of an interval where the polynomial is + # monotonic. + # param end The end of said interval. + # param begin_value The value of the given polynomial at begin. + # param error_tolerance The error tolerance for the returned root + # location. + # Typically the error will be much lower but in theory it can be + # bigger. + # + # return true if a root was found, false if no root exists. + newton_bisection = import_fury_shader( + os.path.join("rt_odfs", "newton_bisection.frag") + ) + + # Finds all roots of the given polynomial in the interval [begin, end] and + # writes them to out_roots. Some entries will be NO_INTERSECTION but other + # than that the array is sorted. The last entry is always NO_INTERSECTION. + find_roots = import_fury_shader(os.path.join("rt_odfs", "find_roots.frag")) + + # Evaluates the spherical harmonics basis in bands 0, 2, ..., SH_DEGREE. + # Conventions are as in the following paper. + # M. Descoteaux, E. Angelino, S. Fitzgibbons, and R. Deriche. Regularized, + # fast, and robust analytical q-ball imaging. Magnetic Resonance in + # Medicine, 58(3), 2007. https://doi.org/10.1002/mrm.21277 + # param out_shs Values of SH basis functions in bands 0, 2, ..., + # SH_DEGREE in this order. + # param point The point on the unit sphere where the basis should be + # evaluated. + eval_sh = import_fury_shader(os.path.join("rt_odfs", "eval_sh.frag")) + + # Evaluates the gradient of each basis function given by eval_sh() and the + # basis itself + eval_sh_grad = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad.frag") + ) + + # Outputs a matrix that turns equidistant samples on the unit circle of a + # homogeneous polynomial into coefficients of that polynomial. + get_inv_vandermonde = import_fury_shader( + os.path.join("rt_odfs", "get_inv_vandermonde.frag") + ) + + # Determines all intersections between a ray and a spherical harmonics + # glyph. + # param out_ray_params The ray parameters at intersection points. The + # points themselves are at ray_origin + out_ray_params[i] * ray_dir. + # Some entries may be NO_INTERSECTION but other than that the array + # is sorted. + # param sh_coeffs SH_COUNT spherical harmonic coefficients defining the + # glyph. Their exact meaning is defined by eval_sh(). + # param ray_origin The origin of the ray, relative to the glyph center. + # param ray_dir The normalized direction vector of the ray. + ray_sh_glyph_intersections = import_fury_shader( + os.path.join("rt_odfs", "ray_sh_glyph_intersections.frag") + ) + + # Provides a normalized normal vector for a spherical harmonics glyph. + # param sh_coeffs SH_COUNT spherical harmonic coefficients defining the + # glyph. Their exact meaning is defined by eval_sh(). + # param point A point on the surface of the glyph, relative to its + # center. + # + # return A normalized surface normal pointing away from the origin. + get_sh_glyph_normal = import_fury_shader( + os.path.join("rt_odfs", "get_sh_glyph_normal.frag") + ) + + # Applies the non-linearity that maps linear RGB to sRGB + linear_to_srgb = import_fury_shader( + os.path.join("rt_odfs", "linear_to_srgb.frag") + ) + + # Inverse of linear_to_srgb() + srgb_to_linear = import_fury_shader( + os.path.join("rt_odfs", "srgb_to_linear.frag") + ) + + # Turns a linear RGB color (i.e. rec. 709) into sRGB + linear_rgb_to_srgb = import_fury_shader( + os.path.join("rt_odfs", "linear_rgb_to_srgb.frag") + ) + + # Inverse of linear_rgb_to_srgb() + srgb_to_linear_rgb = import_fury_shader( + os.path.join("rt_odfs", "srgb_to_linear_rgb.frag") + ) + + # Logarithmic tonemapping operator. Input and output are linear RGB. + tonemap = import_fury_shader(os.path.join("rt_odfs", "tonemap.frag")) + + # Blinn-Phong illumination model + blinn_phong_model = import_fury_shader( + os.path.join("lighting", "blinn_phong_model.frag") + ) + + # fmt: off + fs_dec = compose_shader([ + def_sh_degree, def_sh_count, def_max_degree, + def_gl_ext_control_flow_attributes, def_no_intersection, def_pis, + fs_vs_vars, coeffs_norm, eval_sh_2, eval_sh_4, eval_sh_6, eval_sh_8, + eval_sh_10, eval_sh_12, eval_sh_grad_2, eval_sh_grad_4, eval_sh_grad_6, + eval_sh_grad_8, eval_sh_grad_10, eval_sh_grad_12, newton_bisection, + find_roots, eval_sh, eval_sh_grad, get_inv_vandermonde, + ray_sh_glyph_intersections, get_sh_glyph_normal, blinn_phong_model, + linear_to_srgb, srgb_to_linear, linear_rgb_to_srgb, srgb_to_linear_rgb, + tonemap + ]) + # fmt: on + + shader_to_actor(odf_actor, "fragment", decl_code=fs_dec) + + point_from_vs = "vec3 pnt = vertexMCVSOutput.xyz;" + + # Ray origin is the camera position in world space + ray_origin = "vec3 ro = camPosMCVSOutput;" + + # TODO: Check aspect for automatic scaling + # Ray direction is the normalized difference between the fragment and the + # camera position/ray origin + ray_direction = "vec3 rd = normalize(pnt - ro);" + + # Light direction in a retroreflective model is the normalized difference + # between the camera position/ray origin and the fragment + light_direction = "vec3 ld = normalize(ro - pnt);" + + # Define SH coefficients (measured up to band 8, noise beyond that) + sh_coeffs = \ + """ + float i = 1 / (numCoeffs * 2); + float sh_coeffs[SH_COUNT]; + for(int j=0; j 0.0) { + first_ray_param = ray_params[i]; + break; + } + } + """ + + # Evaluate shading for a directional light + directional_light = \ + """ + vec3 color = vec3(1.); + if (first_ray_param != NO_INTERSECTION) { + vec3 intersection = ro - centerMCVSOutput + first_ray_param * rd; + vec3 normal = get_sh_glyph_normal(sh_coeffs, intersection); + vec3 colorDir = srgb_to_linear_rgb(abs(normalize(intersection))); + float attenuation = dot(ld, normal); + color = blinnPhongIllumModel( + //attenuation, lightColor0, diffuseColor, specularPower, + attenuation, lightColor0, colorDir, specularPower, + specularColor, ambientColor); + } else { + discard; + } + """ + + frag_output = \ + """ + vec3 out_color = linear_rgb_to_srgb(tonemap(color)); + fragOutput0 = vec4(out_color, opacity); + """ + + fs_impl = compose_shader([ + point_from_vs, ray_origin, ray_direction, light_direction, sh_coeffs, + intersection_test, first_intersection, directional_light, frag_output + ]) + + shader_to_actor(odf_actor, "fragment", impl_code=fs_impl, block="picking") + + return odf_actor \ No newline at end of file diff --git a/fury/shaders/rt_odfs/descoteaux/eval_sh_10.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_10.frag new file mode 100644 index 000000000..178033cae --- /dev/null +++ b/fury/shaders/rt_odfs/descoteaux/eval_sh_10.frag @@ -0,0 +1,175 @@ +void eval_sh_10(out float out_shs[66], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + b = z2 * a - 0.250980392 * b; + a = b - 0.250773994 * a; + d = 233.240148813 * a; + out_shs[55] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[20] = -c1 * d; + out_shs[22] = s1 * d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[35] = -c1 * d; + out_shs[37] = s1 * d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + out_shs[54] = -c1 * d; + out_shs[56] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[19] = c0 * d; + out_shs[23] = s0 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[34] = c0 * d; + out_shs[38] = s0 * d; + b = z2 * a - 0.235294118 * b; + a = b - 0.238390093 * a; + d = 272.365814381 * a; + out_shs[53] = c0 * d; + out_shs[57] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[18] = -c1 * d; + out_shs[24] = s1 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[33] = -c1 * d; + out_shs[39] = s1 * d; + a = z2 * b - 0.215686275 * a; + b = a - 0.222910217 * b; + d = -213.661323441 * b; + out_shs[52] = -c1 * d; + out_shs[58] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[17] = c0 * d; + out_shs[25] = s0 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[32] = c0 * d; + out_shs[40] = s0 * d; + b = z2 * a - 0.188235294 * b; + a = b - 0.20123839 * a; + d = 151.081370682 * a; + out_shs[51] = c0 * d; + out_shs[59] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[16] = -c1 * d; + out_shs[26] = s1 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[31] = -c1 * d; + out_shs[41] = s1 * d; + a = z2 * b - 0.152941176 * a; + b = a - 0.173374613 * b; + d = -95.552248675 * b; + out_shs[50] = -c1 * d; + out_shs[60] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[15] = c0 * d; + out_shs[27] = s0 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[30] = c0 * d; + out_shs[42] = s0 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + out_shs[49] = c0 * d; + out_shs[61] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[29] = -c1 * d; + out_shs[43] = s1 * d; + a = (z2 - 5.88235294e-02) * z; + b = a - 9.90712074e-02 * z; + d = -25.910241313 * b; + out_shs[48] = -c1 * d; + out_shs[62] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[28] = c0 * d; + out_shs[44] = s0 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + out_shs[47] = c0 * d; + out_shs[63] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + out_shs[46] = -c1 * d; + out_shs[64] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + out_shs[45] = c0 * d; + out_shs[65] = s0 * d; +} diff --git a/fury/shaders/rt_odfs/descoteaux/eval_sh_12.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_12.frag new file mode 100644 index 000000000..f1a6d85e9 --- /dev/null +++ b/fury/shaders/rt_odfs/descoteaux/eval_sh_12.frag @@ -0,0 +1,238 @@ +void eval_sh_12(out float out_shs[91], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + b = z2 * a - 0.250980392 * b; + a = b - 0.250773994 * a; + d = 233.240148813 * a; + out_shs[55] = d; + b = z2 * a - 0.250626566 * b; + a = b - 0.250517598 * a; + d = 931.186918633 * a; + out_shs[78] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[20] = -c1 * d; + out_shs[22] = s1 * d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[35] = -c1 * d; + out_shs[37] = s1 * d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + out_shs[54] = -c1 * d; + out_shs[56] = s1 * d; + a = z2 * b - 0.248120301 * a; + b = a - 0.248447205 * b; + d = -1265.233874957 * b; + out_shs[77] = -c1 * d; + out_shs[79] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[19] = c0 * d; + out_shs[23] = s0 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[34] = c0 * d; + out_shs[38] = s0 * d; + b = z2 * a - 0.235294118 * b; + a = b - 0.238390093 * a; + d = 272.365814381 * a; + out_shs[53] = c0 * d; + out_shs[57] = s0 * d; + b = z2 * a - 0.240601504 * b; + a = b - 0.242236025 * a; + d = 1121.509962433 * a; + out_shs[76] = c0 * d; + out_shs[80] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[18] = -c1 * d; + out_shs[24] = s1 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[33] = -c1 * d; + out_shs[39] = s1 * d; + a = z2 * b - 0.215686275 * a; + b = a - 0.222910217 * b; + d = -213.661323441 * b; + out_shs[52] = -c1 * d; + out_shs[58] = s1 * d; + a = z2 * b - 0.228070175 * a; + b = a - 0.231884058 * b; + d = -915.709049803 * b; + out_shs[75] = -c1 * d; + out_shs[81] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[17] = c0 * d; + out_shs[25] = s0 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[32] = c0 * d; + out_shs[40] = s0 * d; + b = z2 * a - 0.188235294 * b; + a = b - 0.20123839 * a; + d = 151.081370682 * a; + out_shs[51] = c0 * d; + out_shs[59] = s0 * d; + b = z2 * a - 0.210526316 * b; + a = b - 0.217391304 * a; + d = 686.781787352 * a; + out_shs[74] = c0 * d; + out_shs[82] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[16] = -c1 * d; + out_shs[26] = s1 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[31] = -c1 * d; + out_shs[41] = s1 * d; + a = z2 * b - 0.152941176 * a; + b = a - 0.173374613 * b; + d = -95.552248675 * b; + out_shs[50] = -c1 * d; + out_shs[60] = s1 * d; + a = z2 * b - 0.187969925 * a; + b = a - 0.198757764 * b; + d = -471.12841933 * b; + out_shs[73] = -c1 * d; + out_shs[83] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[15] = c0 * d; + out_shs[27] = s0 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[30] = c0 * d; + out_shs[42] = s0 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + out_shs[49] = c0 * d; + out_shs[61] = s0 * d; + b = z2 * a - 0.160401003 * b; + a = b - 0.175983437 * a; + d = 293.800188384 * a; + out_shs[72] = c0 * d; + out_shs[84] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[29] = -c1 * d; + out_shs[43] = s1 * d; + a = (z2 - 5.88235294e-02) * z; + b = a - 9.90712074e-02 * z; + d = -25.910241313 * b; + out_shs[48] = -c1 * d; + out_shs[62] = s1 * d; + a = z2 * b - 0.127819549 * a; + b = a - 0.149068323 * b; + d = -165.101452729 * b; + out_shs[71] = -c1 * d; + out_shs[85] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[28] = c0 * d; + out_shs[44] = s0 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + out_shs[47] = c0 * d; + out_shs[63] = s0 * d; + b = z2 * (a - 9.02255639e-02); + a = b - 0.118012422 * a; + d = 82.550726364 * a; + out_shs[70] = c0 * d; + out_shs[86] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + out_shs[46] = -c1 * d; + out_shs[64] = s1 * d; + a = (z2 - 4.76190476e-02) * z; + b = a - 8.2815735e-02 * z; + d = -36.028090689 * b; + out_shs[69] = -c1 * d; + out_shs[87] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + out_shs[45] = c0 * d; + out_shs[65] = s0 * d; + a = z2 - 4.34782609e-02; + d = 13.3042542 * a; + out_shs[68] = c0 * d; + out_shs[88] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.923210529 * z; + out_shs[67] = -c1 * d; + out_shs[89] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.800821996; + out_shs[66] = c0 * d; + out_shs[90] = s0 * d; +} diff --git a/fury/shaders/rt_odfs/descoteaux/eval_sh_2.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_2.frag new file mode 100644 index 000000000..c15510b74 --- /dev/null +++ b/fury/shaders/rt_odfs/descoteaux/eval_sh_2.frag @@ -0,0 +1,23 @@ +void eval_sh_2(out float out_shs[6], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; +} diff --git a/fury/shaders/rt_odfs/descoteaux/eval_sh_4.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_4.frag new file mode 100644 index 000000000..975fac054 --- /dev/null +++ b/fury/shaders/rt_odfs/descoteaux/eval_sh_4.frag @@ -0,0 +1,46 @@ +void eval_sh_4(out float out_shs[15], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; +} diff --git a/fury/shaders/rt_odfs/descoteaux/eval_sh_6.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_6.frag new file mode 100644 index 000000000..6cbd1bcf1 --- /dev/null +++ b/fury/shaders/rt_odfs/descoteaux/eval_sh_6.frag @@ -0,0 +1,79 @@ +void eval_sh_6(out float out_shs[28], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[20] = -c1 * d; + out_shs[22] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[19] = c0 * d; + out_shs[23] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[18] = -c1 * d; + out_shs[24] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[17] = c0 * d; + out_shs[25] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[16] = -c1 * d; + out_shs[26] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[15] = c0 * d; + out_shs[27] = s0 * d; +} diff --git a/fury/shaders/rt_odfs/descoteaux/eval_sh_8.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_8.frag new file mode 100644 index 000000000..6e79b2b16 --- /dev/null +++ b/fury/shaders/rt_odfs/descoteaux/eval_sh_8.frag @@ -0,0 +1,122 @@ +void eval_sh_8(out float out_shs[45], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[20] = -c1 * d; + out_shs[22] = s1 * d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[35] = -c1 * d; + out_shs[37] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[19] = c0 * d; + out_shs[23] = s0 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[34] = c0 * d; + out_shs[38] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[18] = -c1 * d; + out_shs[24] = s1 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[33] = -c1 * d; + out_shs[39] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[17] = c0 * d; + out_shs[25] = s0 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[32] = c0 * d; + out_shs[40] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[16] = -c1 * d; + out_shs[26] = s1 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[31] = -c1 * d; + out_shs[41] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[15] = c0 * d; + out_shs[27] = s0 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[30] = c0 * d; + out_shs[42] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[29] = -c1 * d; + out_shs[43] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[28] = c0 * d; + out_shs[44] = s0 * d; +} diff --git a/fury/shaders/rt_odfs/eval_sh.frag b/fury/shaders/rt_odfs/eval_sh.frag new file mode 100644 index 000000000..e3810af25 --- /dev/null +++ b/fury/shaders/rt_odfs/eval_sh.frag @@ -0,0 +1,16 @@ +void eval_sh(out float out_shs[SH_COUNT], vec3 point) +{ + #if SH_DEGREE == 2 + eval_sh_2(out_shs, point); + #elif SH_DEGREE == 4 + eval_sh_4(out_shs, point); + #elif SH_DEGREE == 6 + eval_sh_6(out_shs, point); + #elif SH_DEGREE == 8 + eval_sh_8(out_shs, point); + #elif SH_DEGREE == 10 + eval_sh_10(out_shs, point); + #elif SH_DEGREE == 12 + eval_sh_12(out_shs, point); + #endif +} diff --git a/fury/shaders/rt_odfs/eval_sh_grad.frag b/fury/shaders/rt_odfs/eval_sh_grad.frag new file mode 100644 index 000000000..c318dbd6c --- /dev/null +++ b/fury/shaders/rt_odfs/eval_sh_grad.frag @@ -0,0 +1,16 @@ +void eval_sh_grad(out float out_shs[SH_COUNT], out vec3 out_grads[SH_COUNT], vec3 point) +{ + #if SH_DEGREE == 2 + eval_sh_grad_2(out_shs, out_grads, point); + #elif SH_DEGREE == 4 + eval_sh_grad_4(out_shs, out_grads, point); + #elif SH_DEGREE == 6 + eval_sh_grad_6(out_shs, out_grads, point); + #elif SH_DEGREE == 8 + eval_sh_grad_8(out_shs, out_grads, point); + #elif SH_DEGREE == 10 + eval_sh_grad_10(out_shs, out_grads, point); + #elif SH_DEGREE == 12 + eval_sh_grad_12(out_shs, out_grads, point); + #endif +} diff --git a/fury/shaders/rt_odfs/eval_sh_grad_10.frag b/fury/shaders/rt_odfs/eval_sh_grad_10.frag new file mode 100644 index 000000000..9d5feea39 --- /dev/null +++ b/fury/shaders/rt_odfs/eval_sh_grad_10.frag @@ -0,0 +1,430 @@ +void eval_sh_grad_10(out float out_shs[66], out vec3 out_grads[66], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + b = z2 * a - 0.250980392 * b; + a = b - 0.250773994 * a; + d = 233.240148813 * a; + out_shs[55] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + out_grads[2][0] = -c0 * d; + out_grads[4][0] = s0 * d; + out_grads[2][1] = s0 * d; + out_grads[4][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + out_grads[9][0] = -c0 * d; + out_grads[11][0] = s0 * d; + out_grads[9][1] = s0 * d; + out_grads[11][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[20] = -c1 * d; + out_shs[22] = s1 * d; + out_grads[20][0] = -c0 * d; + out_grads[22][0] = s0 * d; + out_grads[20][1] = s0 * d; + out_grads[22][1] = c0 * d; + d = 88.106914343 * b; + out_grads[21][2] = d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[35] = -c1 * d; + out_shs[37] = s1 * d; + out_grads[35][0] = -c0 * d; + out_grads[37][0] = s0 * d; + out_grads[35][1] = s0 * d; + out_grads[37][1] = c0 * d; + d = 467.786944906 * b; + out_grads[36][2] = d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + out_shs[54] = -c1 * d; + out_shs[56] = s1 * d; + out_grads[54][0] = -c0 * d; + out_grads[56][0] = s0 * d; + out_grads[54][1] = s0 * d; + out_grads[56][1] = c0 * d; + d = 2332.401488133 * b; + out_grads[55][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + d = 1.092548431; + out_grads[1][0] = c1 * d; + out_grads[5][0] = s1 * d; + out_grads[1][1] = -s1 * d; + out_grads[5][1] = c1 * d; + d = -1.092548431; + out_grads[2][2] = -c1 * d; + out_grads[4][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + d = 6.62322287 * a; + out_grads[8][0] = c1 * d; + out_grads[12][0] = s1 * d; + out_grads[8][1] = -s1 * d; + out_grads[12][1] = c1 * d; + d = -14.049977415 * a; + out_grads[9][2] = -c1 * d; + out_grads[11][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[19] = c0 * d; + out_shs[23] = s0 * d; + d = 30.399773564 * a; + out_grads[19][0] = c1 * d; + out_grads[23][0] = s1 * d; + out_grads[19][1] = -s1 * d; + out_grads[23][1] = c1 * d; + d = -96.132524816 * a; + out_grads[20][2] = -c1 * d; + out_grads[22][2] = s1 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[34] = c0 * d; + out_shs[38] = s0 * d; + d = 130.459545912 * a; + out_grads[34][0] = c1 * d; + out_grads[38][0] = s1 * d; + out_grads[34][1] = -s1 * d; + out_grads[38][1] = c1 * d; + d = -545.751435723 * a; + out_grads[35][2] = -c1 * d; + out_grads[37][2] = s1 * d; + b = z2 * a - 0.235294118 * b; + a = b - 0.238390093 * a; + d = 272.365814381 * a; + out_shs[53] = c0 * d; + out_shs[57] = s0 * d; + d = 544.731628762 * a; + out_grads[53][0] = c1 * d; + out_grads[57][0] = s1 * d; + out_grads[53][1] = -s1 * d; + out_grads[57][1] = c1 * d; + d = -2830.508572514 * a; + out_grads[54][2] = -c1 * d; + out_grads[56][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + d = -5.310392309 * z; + out_grads[7][0] = -c0 * d; + out_grads[13][0] = s0 * d; + out_grads[7][1] = s0 * d; + out_grads[13][1] = c0 * d; + d = 6.62322287 * z; + out_grads[8][2] = c0 * d; + out_grads[12][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[18] = -c1 * d; + out_shs[24] = s1 * d; + d = -30.399773564 * b; + out_grads[18][0] = -c0 * d; + out_grads[24][0] = s0 * d; + out_grads[18][1] = s0 * d; + out_grads[24][1] = c0 * d; + d = 60.799547128 * b; + out_grads[19][2] = c0 * d; + out_grads[23][2] = s0 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[33] = -c1 * d; + out_shs[39] = s1 * d; + d = -144.52614017 * b; + out_grads[33][0] = -c0 * d; + out_grads[39][0] = s0 * d; + out_grads[33][1] = s0 * d; + out_grads[39][1] = c0 * d; + d = 391.378637737 * b; + out_grads[34][2] = c0 * d; + out_grads[38][2] = s0 * d; + a = z2 * b - 0.215686275 * a; + b = a - 0.222910217 * b; + d = -213.661323441 * b; + out_shs[52] = -c1 * d; + out_shs[58] = s1 * d; + d = -640.983970322 * b; + out_grads[52][0] = -c0 * d; + out_grads[58][0] = s0 * d; + out_grads[52][1] = s0 * d; + out_grads[58][1] = c0 * d; + d = 2178.926515046 * b; + out_grads[53][2] = c0 * d; + out_grads[57][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + d = 2.503342942; + out_grads[6][0] = c1 * d; + out_grads[14][0] = s1 * d; + out_grads[6][1] = -s1 * d; + out_grads[14][1] = c1 * d; + d = -1.77013077; + out_grads[7][2] = -c1 * d; + out_grads[13][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[17] = c0 * d; + out_shs[25] = s0 * d; + d = 22.200855632 * a; + out_grads[17][0] = c1 * d; + out_grads[25][0] = s1 * d; + out_grads[17][1] = -s1 * d; + out_grads[25][1] = c1 * d; + d = -30.399773564 * a; + out_grads[18][2] = -c1 * d; + out_grads[24][2] = s1 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[32] = c0 * d; + out_shs[40] = s0 * d; + d = 124.388296437 * a; + out_grads[32][0] = c1 * d; + out_grads[40][0] = s1 * d; + out_grads[32][1] = -s1 * d; + out_grads[40][1] = c1 * d; + d = -240.876900283 * a; + out_grads[33][2] = -c1 * d; + out_grads[39][2] = s1 * d; + b = z2 * a - 0.188235294 * b; + a = b - 0.20123839 * a; + d = 151.081370682 * a; + out_shs[51] = c0 * d; + out_shs[59] = s0 * d; + d = 604.325482728 * a; + out_grads[51][0] = c1 * d; + out_grads[59][0] = s1 * d; + out_grads[51][1] = -s1 * d; + out_grads[59][1] = c1 * d; + d = -1495.629264084 * a; + out_grads[52][2] = -c1 * d; + out_grads[58][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[16] = -c1 * d; + out_shs[26] = s1 * d; + d = -11.833095811 * z; + out_grads[16][0] = -c0 * d; + out_grads[26][0] = s0 * d; + out_grads[16][1] = s0 * d; + out_grads[26][1] = c0 * d; + d = 11.100427816 * z; + out_grads[17][2] = c0 * d; + out_grads[25][2] = s0 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[31] = -c1 * d; + out_shs[41] = s1 * d; + d = -86.247765552 * b; + out_grads[31][0] = -c0 * d; + out_grads[41][0] = s0 * d; + out_grads[31][1] = s0 * d; + out_grads[41][1] = c0 * d; + d = 124.388296437 * b; + out_grads[32][2] = c0 * d; + out_grads[40][2] = s0 * d; + a = z2 * b - 0.152941176 * a; + b = a - 0.173374613 * b; + d = -95.552248675 * b; + out_shs[50] = -c1 * d; + out_shs[60] = s1 * d; + d = -477.761243376 * b; + out_grads[50][0] = -c0 * d; + out_grads[60][0] = s0 * d; + out_grads[50][1] = s0 * d; + out_grads[60][1] = c0 * d; + d = 906.488224092 * b; + out_grads[51][2] = c0 * d; + out_grads[59][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[15] = c0 * d; + out_shs[27] = s0 * d; + d = 4.099104631; + out_grads[15][0] = c1 * d; + out_grads[27][0] = s1 * d; + out_grads[15][1] = -s1 * d; + out_grads[27][1] = c1 * d; + d = -2.366619162; + out_grads[16][2] = -c1 * d; + out_grads[26][2] = s1 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[30] = c0 * d; + out_shs[42] = s0 * d; + d = 47.909948945 * a; + out_grads[30][0] = c1 * d; + out_grads[42][0] = s1 * d; + out_grads[30][1] = -s1 * d; + out_grads[42][1] = c1 * d; + d = -51.748659331 * a; + out_grads[31][2] = -c1 * d; + out_grads[41][2] = s1 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + out_shs[49] = c0 * d; + out_shs[61] = s0 * d; + d = 320.491985161 * a; + out_grads[49][0] = c1 * d; + out_grads[61][0] = s1 * d; + out_grads[49][1] = -s1 * d; + out_grads[61][1] = c1 * d; + d = -477.761243376 * a; + out_grads[50][2] = -c1 * d; + out_grads[60][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[29] = -c1 * d; + out_shs[43] = s1 * d; + d = -20.409946485 * z; + out_grads[29][0] = -c0 * d; + out_grads[43][0] = s0 * d; + out_grads[29][1] = s0 * d; + out_grads[43][1] = c0 * d; + d = 15.969982982 * z; + out_grads[30][2] = c0 * d; + out_grads[42][2] = s0 * d; + a = (z2 - 5.88235294e-02) * z; + b = a - 9.90712074e-02 * z; + d = -25.910241313 * b; + out_shs[48] = -c1 * d; + out_shs[62] = s1 * d; + d = -181.371689194 * b; + out_grads[48][0] = -c0 * d; + out_grads[62][0] = s0 * d; + out_grads[48][1] = s0 * d; + out_grads[62][1] = c0 * d; + d = 213.661323441 * b; + out_grads[49][2] = c0 * d; + out_grads[61][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[28] = c0 * d; + out_shs[44] = s0 * d; + d = 5.831413281; + out_grads[28][0] = c1 * d; + out_grads[44][0] = s1 * d; + out_grads[28][1] = -s1 * d; + out_grads[44][1] = c1 * d; + d = -2.915706641; + out_grads[29][2] = -c1 * d; + out_grads[43][2] = s1 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + out_shs[47] = c0 * d; + out_shs[63] = s0 * d; + d = 84.622493774 * a; + out_grads[47][0] = c1 * d; + out_grads[63][0] = s1 * d; + out_grads[47][1] = -s1 * d; + out_grads[63][1] = c1 * d; + d = -77.73072394 * a; + out_grads[48][2] = -c1 * d; + out_grads[62][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + out_shs[46] = -c1 * d; + out_shs[64] = s1 * d; + d = -30.887057699 * z; + out_grads[46][0] = -c0 * d; + out_grads[64][0] = s0 * d; + out_grads[46][1] = s0 * d; + out_grads[64][1] = c0 * d; + d = 21.155623443 * z; + out_grads[47][2] = c0 * d; + out_grads[63][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + out_shs[45] = c0 * d; + out_shs[65] = s0 * d; + d = 7.673951182; + out_grads[45][0] = c1 * d; + out_grads[65][0] = s1 * d; + out_grads[45][1] = -s1 * d; + out_grads[65][1] = c1 * d; + d = -3.4318953; + out_grads[46][2] = -c1 * d; + out_grads[64][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; + out_grads[6][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[14][2] = 0.0; + out_grads[15][2] = 0.0; + out_grads[21][0] = 0.0; + out_grads[21][1] = 0.0; + out_grads[27][2] = 0.0; + out_grads[28][2] = 0.0; + out_grads[36][0] = 0.0; + out_grads[36][1] = 0.0; + out_grads[44][2] = 0.0; + out_grads[45][2] = 0.0; + out_grads[55][0] = 0.0; + out_grads[55][1] = 0.0; + out_grads[65][2] = 0.0; +} diff --git a/fury/shaders/rt_odfs/eval_sh_grad_12.frag b/fury/shaders/rt_odfs/eval_sh_grad_12.frag new file mode 100644 index 000000000..f7ff069bc --- /dev/null +++ b/fury/shaders/rt_odfs/eval_sh_grad_12.frag @@ -0,0 +1,591 @@ +void eval_sh_grad_12(out float out_shs[91], out vec3 out_grads[91], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + b = z2 * a - 0.250980392 * b; + a = b - 0.250773994 * a; + d = 233.240148813 * a; + out_shs[55] = d; + b = z2 * a - 0.250626566 * b; + a = b - 0.250517598 * a; + d = 931.186918633 * a; + out_shs[78] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + out_grads[2][0] = -c0 * d; + out_grads[4][0] = s0 * d; + out_grads[2][1] = s0 * d; + out_grads[4][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + out_grads[9][0] = -c0 * d; + out_grads[11][0] = s0 * d; + out_grads[9][1] = s0 * d; + out_grads[11][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[20] = -c1 * d; + out_shs[22] = s1 * d; + out_grads[20][0] = -c0 * d; + out_grads[22][0] = s0 * d; + out_grads[20][1] = s0 * d; + out_grads[22][1] = c0 * d; + d = 88.106914343 * b; + out_grads[21][2] = d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[35] = -c1 * d; + out_shs[37] = s1 * d; + out_grads[35][0] = -c0 * d; + out_grads[37][0] = s0 * d; + out_grads[35][1] = s0 * d; + out_grads[37][1] = c0 * d; + d = 467.786944906 * b; + out_grads[36][2] = d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + out_shs[54] = -c1 * d; + out_shs[56] = s1 * d; + out_grads[54][0] = -c0 * d; + out_grads[56][0] = s0 * d; + out_grads[54][1] = s0 * d; + out_grads[56][1] = c0 * d; + d = 2332.401488133 * b; + out_grads[55][2] = d; + a = z2 * b - 0.248120301 * a; + b = a - 0.248447205 * b; + d = -1265.233874957 * b; + out_shs[77] = -c1 * d; + out_shs[79] = s1 * d; + out_grads[77][0] = -c0 * d; + out_grads[79][0] = s0 * d; + out_grads[77][1] = s0 * d; + out_grads[79][1] = c0 * d; + d = 11174.243023595 * b; + out_grads[78][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + d = 1.092548431; + out_grads[1][0] = c1 * d; + out_grads[5][0] = s1 * d; + out_grads[1][1] = -s1 * d; + out_grads[5][1] = c1 * d; + d = -1.092548431; + out_grads[2][2] = -c1 * d; + out_grads[4][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + d = 6.62322287 * a; + out_grads[8][0] = c1 * d; + out_grads[12][0] = s1 * d; + out_grads[8][1] = -s1 * d; + out_grads[12][1] = c1 * d; + d = -14.049977415 * a; + out_grads[9][2] = -c1 * d; + out_grads[11][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[19] = c0 * d; + out_shs[23] = s0 * d; + d = 30.399773564 * a; + out_grads[19][0] = c1 * d; + out_grads[23][0] = s1 * d; + out_grads[19][1] = -s1 * d; + out_grads[23][1] = c1 * d; + d = -96.132524816 * a; + out_grads[20][2] = -c1 * d; + out_grads[22][2] = s1 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[34] = c0 * d; + out_shs[38] = s0 * d; + d = 130.459545912 * a; + out_grads[34][0] = c1 * d; + out_grads[38][0] = s1 * d; + out_grads[34][1] = -s1 * d; + out_grads[38][1] = c1 * d; + d = -545.751435723 * a; + out_grads[35][2] = -c1 * d; + out_grads[37][2] = s1 * d; + b = z2 * a - 0.235294118 * b; + a = b - 0.238390093 * a; + d = 272.365814381 * a; + out_shs[53] = c0 * d; + out_shs[57] = s0 * d; + d = 544.731628762 * a; + out_grads[53][0] = c1 * d; + out_grads[57][0] = s1 * d; + out_grads[53][1] = -s1 * d; + out_grads[57][1] = c1 * d; + d = -2830.508572514 * a; + out_grads[54][2] = -c1 * d; + out_grads[56][2] = s1 * d; + b = z2 * a - 0.240601504 * b; + a = b - 0.242236025 * a; + d = 1121.509962433 * a; + out_shs[76] = c0 * d; + out_shs[80] = s0 * d; + d = 2243.019924866 * a; + out_grads[76][0] = c1 * d; + out_grads[80][0] = s1 * d; + out_grads[76][1] = -s1 * d; + out_grads[80][1] = c1 * d; + d = -13917.572624524 * a; + out_grads[77][2] = -c1 * d; + out_grads[79][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + d = -5.310392309 * z; + out_grads[7][0] = -c0 * d; + out_grads[13][0] = s0 * d; + out_grads[7][1] = s0 * d; + out_grads[13][1] = c0 * d; + d = 6.62322287 * z; + out_grads[8][2] = c0 * d; + out_grads[12][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[18] = -c1 * d; + out_shs[24] = s1 * d; + d = -30.399773564 * b; + out_grads[18][0] = -c0 * d; + out_grads[24][0] = s0 * d; + out_grads[18][1] = s0 * d; + out_grads[24][1] = c0 * d; + d = 60.799547128 * b; + out_grads[19][2] = c0 * d; + out_grads[23][2] = s0 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[33] = -c1 * d; + out_shs[39] = s1 * d; + d = -144.52614017 * b; + out_grads[33][0] = -c0 * d; + out_grads[39][0] = s0 * d; + out_grads[33][1] = s0 * d; + out_grads[39][1] = c0 * d; + d = 391.378637737 * b; + out_grads[34][2] = c0 * d; + out_grads[38][2] = s0 * d; + a = z2 * b - 0.215686275 * a; + b = a - 0.222910217 * b; + d = -213.661323441 * b; + out_shs[52] = -c1 * d; + out_shs[58] = s1 * d; + d = -640.983970322 * b; + out_grads[52][0] = -c0 * d; + out_grads[58][0] = s0 * d; + out_grads[52][1] = s0 * d; + out_grads[58][1] = c0 * d; + d = 2178.926515046 * b; + out_grads[53][2] = c0 * d; + out_grads[57][2] = s0 * d; + a = z2 * b - 0.228070175 * a; + b = a - 0.231884058 * b; + d = -915.709049803 * b; + out_shs[75] = -c1 * d; + out_shs[81] = s1 * d; + d = -2747.127149409 * b; + out_grads[75][0] = -c0 * d; + out_grads[81][0] = s0 * d; + out_grads[75][1] = s0 * d; + out_grads[81][1] = c0 * d; + d = 11215.099624332 * b; + out_grads[76][2] = c0 * d; + out_grads[80][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + d = 2.503342942; + out_grads[6][0] = c1 * d; + out_grads[14][0] = s1 * d; + out_grads[6][1] = -s1 * d; + out_grads[14][1] = c1 * d; + d = -1.77013077; + out_grads[7][2] = -c1 * d; + out_grads[13][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[17] = c0 * d; + out_shs[25] = s0 * d; + d = 22.200855632 * a; + out_grads[17][0] = c1 * d; + out_grads[25][0] = s1 * d; + out_grads[17][1] = -s1 * d; + out_grads[25][1] = c1 * d; + d = -30.399773564 * a; + out_grads[18][2] = -c1 * d; + out_grads[24][2] = s1 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[32] = c0 * d; + out_shs[40] = s0 * d; + d = 124.388296437 * a; + out_grads[32][0] = c1 * d; + out_grads[40][0] = s1 * d; + out_grads[32][1] = -s1 * d; + out_grads[40][1] = c1 * d; + d = -240.876900283 * a; + out_grads[33][2] = -c1 * d; + out_grads[39][2] = s1 * d; + b = z2 * a - 0.188235294 * b; + a = b - 0.20123839 * a; + d = 151.081370682 * a; + out_shs[51] = c0 * d; + out_shs[59] = s0 * d; + d = 604.325482728 * a; + out_grads[51][0] = c1 * d; + out_grads[59][0] = s1 * d; + out_grads[51][1] = -s1 * d; + out_grads[59][1] = c1 * d; + d = -1495.629264084 * a; + out_grads[52][2] = -c1 * d; + out_grads[58][2] = s1 * d; + b = z2 * a - 0.210526316 * b; + a = b - 0.217391304 * a; + d = 686.781787352 * a; + out_shs[74] = c0 * d; + out_shs[82] = s0 * d; + d = 2747.127149409 * a; + out_grads[74][0] = c1 * d; + out_grads[82][0] = s1 * d; + out_grads[74][1] = -s1 * d; + out_grads[82][1] = c1 * d; + d = -8241.381448228 * a; + out_grads[75][2] = -c1 * d; + out_grads[81][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[16] = -c1 * d; + out_shs[26] = s1 * d; + d = -11.833095811 * z; + out_grads[16][0] = -c0 * d; + out_grads[26][0] = s0 * d; + out_grads[16][1] = s0 * d; + out_grads[26][1] = c0 * d; + d = 11.100427816 * z; + out_grads[17][2] = c0 * d; + out_grads[25][2] = s0 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[31] = -c1 * d; + out_shs[41] = s1 * d; + d = -86.247765552 * b; + out_grads[31][0] = -c0 * d; + out_grads[41][0] = s0 * d; + out_grads[31][1] = s0 * d; + out_grads[41][1] = c0 * d; + d = 124.388296437 * b; + out_grads[32][2] = c0 * d; + out_grads[40][2] = s0 * d; + a = z2 * b - 0.152941176 * a; + b = a - 0.173374613 * b; + d = -95.552248675 * b; + out_shs[50] = -c1 * d; + out_shs[60] = s1 * d; + d = -477.761243376 * b; + out_grads[50][0] = -c0 * d; + out_grads[60][0] = s0 * d; + out_grads[50][1] = s0 * d; + out_grads[60][1] = c0 * d; + d = 906.488224092 * b; + out_grads[51][2] = c0 * d; + out_grads[59][2] = s0 * d; + a = z2 * b - 0.187969925 * a; + b = a - 0.198757764 * b; + d = -471.12841933 * b; + out_shs[73] = -c1 * d; + out_shs[83] = s1 * d; + d = -2355.642096651 * b; + out_grads[73][0] = -c0 * d; + out_grads[83][0] = s0 * d; + out_grads[73][1] = s0 * d; + out_grads[83][1] = c0 * d; + d = 5494.254298819 * b; + out_grads[74][2] = c0 * d; + out_grads[82][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[15] = c0 * d; + out_shs[27] = s0 * d; + d = 4.099104631; + out_grads[15][0] = c1 * d; + out_grads[27][0] = s1 * d; + out_grads[15][1] = -s1 * d; + out_grads[27][1] = c1 * d; + d = -2.366619162; + out_grads[16][2] = -c1 * d; + out_grads[26][2] = s1 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[30] = c0 * d; + out_shs[42] = s0 * d; + d = 47.909948945 * a; + out_grads[30][0] = c1 * d; + out_grads[42][0] = s1 * d; + out_grads[30][1] = -s1 * d; + out_grads[42][1] = c1 * d; + d = -51.748659331 * a; + out_grads[31][2] = -c1 * d; + out_grads[41][2] = s1 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + out_shs[49] = c0 * d; + out_shs[61] = s0 * d; + d = 320.491985161 * a; + out_grads[49][0] = c1 * d; + out_grads[61][0] = s1 * d; + out_grads[49][1] = -s1 * d; + out_grads[61][1] = c1 * d; + d = -477.761243376 * a; + out_grads[50][2] = -c1 * d; + out_grads[60][2] = s1 * d; + b = z2 * a - 0.160401003 * b; + a = b - 0.175983437 * a; + d = 293.800188384 * a; + out_shs[72] = c0 * d; + out_shs[84] = s0 * d; + d = 1762.801130306 * a; + out_grads[72][0] = c1 * d; + out_grads[84][0] = s1 * d; + out_grads[72][1] = -s1 * d; + out_grads[84][1] = c1 * d; + d = -3297.898935312 * a; + out_grads[73][2] = -c1 * d; + out_grads[83][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[29] = -c1 * d; + out_shs[43] = s1 * d; + d = -20.409946485 * z; + out_grads[29][0] = -c0 * d; + out_grads[43][0] = s0 * d; + out_grads[29][1] = s0 * d; + out_grads[43][1] = c0 * d; + d = 15.969982982 * z; + out_grads[30][2] = c0 * d; + out_grads[42][2] = s0 * d; + a = (z2 - 5.88235294e-02) * z; + b = a - 9.90712074e-02 * z; + d = -25.910241313 * b; + out_shs[48] = -c1 * d; + out_shs[62] = s1 * d; + d = -181.371689194 * b; + out_grads[48][0] = -c0 * d; + out_grads[62][0] = s0 * d; + out_grads[48][1] = s0 * d; + out_grads[62][1] = c0 * d; + d = 213.661323441 * b; + out_grads[49][2] = c0 * d; + out_grads[61][2] = s0 * d; + a = z2 * b - 0.127819549 * a; + b = a - 0.149068323 * b; + d = -165.101452729 * b; + out_shs[71] = -c1 * d; + out_shs[85] = s1 * d; + d = -1155.7101691 * b; + out_grads[71][0] = -c0 * d; + out_grads[85][0] = s0 * d; + out_grads[71][1] = s0 * d; + out_grads[85][1] = c0 * d; + d = 1762.801130306 * b; + out_grads[72][2] = c0 * d; + out_grads[84][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[28] = c0 * d; + out_shs[44] = s0 * d; + d = 5.831413281; + out_grads[28][0] = c1 * d; + out_grads[44][0] = s1 * d; + out_grads[28][1] = -s1 * d; + out_grads[44][1] = c1 * d; + d = -2.915706641; + out_grads[29][2] = -c1 * d; + out_grads[43][2] = s1 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + out_shs[47] = c0 * d; + out_shs[63] = s0 * d; + d = 84.622493774 * a; + out_grads[47][0] = c1 * d; + out_grads[63][0] = s1 * d; + out_grads[47][1] = -s1 * d; + out_grads[63][1] = c1 * d; + d = -77.73072394 * a; + out_grads[48][2] = -c1 * d; + out_grads[62][2] = s1 * d; + b = z2 * (a - 9.02255639e-02); + a = b - 0.118012422 * a; + d = 82.550726364 * a; + out_shs[70] = c0 * d; + out_shs[86] = s0 * d; + d = 660.405810914 * a; + out_grads[70][0] = c1 * d; + out_grads[86][0] = s1 * d; + out_grads[70][1] = -s1 * d; + out_grads[86][1] = c1 * d; + d = -825.507263643 * a; + out_grads[71][2] = -c1 * d; + out_grads[85][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + out_shs[46] = -c1 * d; + out_shs[64] = s1 * d; + d = -30.887057699 * z; + out_grads[46][0] = -c0 * d; + out_grads[64][0] = s0 * d; + out_grads[46][1] = s0 * d; + out_grads[64][1] = c0 * d; + d = 21.155623443 * z; + out_grads[47][2] = c0 * d; + out_grads[63][2] = s0 * d; + a = (z2 - 4.76190476e-02) * z; + b = a - 8.2815735e-02 * z; + d = -36.028090689 * b; + out_shs[69] = -c1 * d; + out_shs[87] = s1 * d; + d = -324.252816204 * b; + out_grads[69][0] = -c0 * d; + out_grads[87][0] = s0 * d; + out_grads[69][1] = s0 * d; + out_grads[87][1] = c0 * d; + d = 330.202905457 * b; + out_grads[70][2] = c0 * d; + out_grads[86][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + out_shs[45] = c0 * d; + out_shs[65] = s0 * d; + d = 7.673951182; + out_grads[45][0] = c1 * d; + out_grads[65][0] = s1 * d; + out_grads[45][1] = -s1 * d; + out_grads[65][1] = c1 * d; + d = -3.4318953; + out_grads[46][2] = -c1 * d; + out_grads[64][2] = s1 * d; + a = z2 - 4.34782609e-02; + d = 13.3042542 * a; + out_shs[68] = c0 * d; + out_shs[88] = s0 * d; + d = 133.042542003 * a; + out_grads[68][0] = c1 * d; + out_grads[88][0] = s1 * d; + out_grads[68][1] = -s1 * d; + out_grads[88][1] = c1 * d; + d = -108.084272068 * a; + out_grads[69][2] = -c1 * d; + out_grads[87][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.923210529 * z; + out_shs[67] = -c1 * d; + out_shs[89] = s1 * d; + d = -43.155315818 * z; + out_grads[67][0] = -c0 * d; + out_grads[89][0] = s0 * d; + out_grads[67][1] = s0 * d; + out_grads[89][1] = c0 * d; + d = 26.608508401 * z; + out_grads[68][2] = c0 * d; + out_grads[88][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.800821996; + out_shs[66] = c0 * d; + out_shs[90] = s0 * d; + d = 9.609863949; + out_grads[66][0] = c1 * d; + out_grads[90][0] = s1 * d; + out_grads[66][1] = -s1 * d; + out_grads[90][1] = c1 * d; + d = -3.923210529; + out_grads[67][2] = -c1 * d; + out_grads[89][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; + out_grads[6][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[14][2] = 0.0; + out_grads[15][2] = 0.0; + out_grads[21][0] = 0.0; + out_grads[21][1] = 0.0; + out_grads[27][2] = 0.0; + out_grads[28][2] = 0.0; + out_grads[36][0] = 0.0; + out_grads[36][1] = 0.0; + out_grads[44][2] = 0.0; + out_grads[45][2] = 0.0; + out_grads[55][0] = 0.0; + out_grads[55][1] = 0.0; + out_grads[65][2] = 0.0; + out_grads[66][2] = 0.0; + out_grads[78][0] = 0.0; + out_grads[78][1] = 0.0; + out_grads[90][2] = 0.0; +} diff --git a/fury/shaders/rt_odfs/eval_sh_grad_2.frag b/fury/shaders/rt_odfs/eval_sh_grad_2.frag new file mode 100644 index 000000000..7004bd528 --- /dev/null +++ b/fury/shaders/rt_odfs/eval_sh_grad_2.frag @@ -0,0 +1,46 @@ +void eval_sh_grad_2(out float out_shs[6], out vec3 out_grads[6], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + out_grads[2][0] = -c0 * d; + out_grads[4][0] = s0 * d; + out_grads[2][1] = s0 * d; + out_grads[4][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + d = 1.092548431; + out_grads[1][0] = c1 * d; + out_grads[5][0] = s1 * d; + out_grads[1][1] = -s1 * d; + out_grads[5][1] = c1 * d; + d = -1.092548431; + out_grads[2][2] = -c1 * d; + out_grads[4][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; +} diff --git a/fury/shaders/rt_odfs/eval_sh_grad_4.frag b/fury/shaders/rt_odfs/eval_sh_grad_4.frag new file mode 100644 index 000000000..715302f39 --- /dev/null +++ b/fury/shaders/rt_odfs/eval_sh_grad_4.frag @@ -0,0 +1,103 @@ +void eval_sh_grad_4(out float out_shs[15], out vec3 out_grads[15], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + out_grads[2][0] = -c0 * d; + out_grads[4][0] = s0 * d; + out_grads[2][1] = s0 * d; + out_grads[4][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + out_grads[9][0] = -c0 * d; + out_grads[11][0] = s0 * d; + out_grads[9][1] = s0 * d; + out_grads[11][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + d = 1.092548431; + out_grads[1][0] = c1 * d; + out_grads[5][0] = s1 * d; + out_grads[1][1] = -s1 * d; + out_grads[5][1] = c1 * d; + d = -1.092548431; + out_grads[2][2] = -c1 * d; + out_grads[4][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + d = 6.62322287 * a; + out_grads[8][0] = c1 * d; + out_grads[12][0] = s1 * d; + out_grads[8][1] = -s1 * d; + out_grads[12][1] = c1 * d; + d = -14.049977415 * a; + out_grads[9][2] = -c1 * d; + out_grads[11][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + d = -5.310392309 * z; + out_grads[7][0] = -c0 * d; + out_grads[13][0] = s0 * d; + out_grads[7][1] = s0 * d; + out_grads[13][1] = c0 * d; + d = 6.62322287 * z; + out_grads[8][2] = c0 * d; + out_grads[12][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + d = 2.503342942; + out_grads[6][0] = c1 * d; + out_grads[14][0] = s1 * d; + out_grads[6][1] = -s1 * d; + out_grads[14][1] = c1 * d; + d = -1.77013077; + out_grads[7][2] = -c1 * d; + out_grads[13][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; + out_grads[6][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[14][2] = 0.0; +} diff --git a/fury/shaders/rt_odfs/eval_sh_grad_6.frag b/fury/shaders/rt_odfs/eval_sh_grad_6.frag new file mode 100644 index 000000000..fa240c3a5 --- /dev/null +++ b/fury/shaders/rt_odfs/eval_sh_grad_6.frag @@ -0,0 +1,186 @@ +void eval_sh_grad_6(out float out_shs[28], out vec3 out_grads[28], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + out_grads[2][0] = -c0 * d; + out_grads[4][0] = s0 * d; + out_grads[2][1] = s0 * d; + out_grads[4][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + out_grads[9][0] = -c0 * d; + out_grads[11][0] = s0 * d; + out_grads[9][1] = s0 * d; + out_grads[11][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[20] = -c1 * d; + out_shs[22] = s1 * d; + out_grads[20][0] = -c0 * d; + out_grads[22][0] = s0 * d; + out_grads[20][1] = s0 * d; + out_grads[22][1] = c0 * d; + d = 88.106914343 * b; + out_grads[21][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + d = 1.092548431; + out_grads[1][0] = c1 * d; + out_grads[5][0] = s1 * d; + out_grads[1][1] = -s1 * d; + out_grads[5][1] = c1 * d; + d = -1.092548431; + out_grads[2][2] = -c1 * d; + out_grads[4][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + d = 6.62322287 * a; + out_grads[8][0] = c1 * d; + out_grads[12][0] = s1 * d; + out_grads[8][1] = -s1 * d; + out_grads[12][1] = c1 * d; + d = -14.049977415 * a; + out_grads[9][2] = -c1 * d; + out_grads[11][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[19] = c0 * d; + out_shs[23] = s0 * d; + d = 30.399773564 * a; + out_grads[19][0] = c1 * d; + out_grads[23][0] = s1 * d; + out_grads[19][1] = -s1 * d; + out_grads[23][1] = c1 * d; + d = -96.132524816 * a; + out_grads[20][2] = -c1 * d; + out_grads[22][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + d = -5.310392309 * z; + out_grads[7][0] = -c0 * d; + out_grads[13][0] = s0 * d; + out_grads[7][1] = s0 * d; + out_grads[13][1] = c0 * d; + d = 6.62322287 * z; + out_grads[8][2] = c0 * d; + out_grads[12][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[18] = -c1 * d; + out_shs[24] = s1 * d; + d = -30.399773564 * b; + out_grads[18][0] = -c0 * d; + out_grads[24][0] = s0 * d; + out_grads[18][1] = s0 * d; + out_grads[24][1] = c0 * d; + d = 60.799547128 * b; + out_grads[19][2] = c0 * d; + out_grads[23][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + d = 2.503342942; + out_grads[6][0] = c1 * d; + out_grads[14][0] = s1 * d; + out_grads[6][1] = -s1 * d; + out_grads[14][1] = c1 * d; + d = -1.77013077; + out_grads[7][2] = -c1 * d; + out_grads[13][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[17] = c0 * d; + out_shs[25] = s0 * d; + d = 22.200855632 * a; + out_grads[17][0] = c1 * d; + out_grads[25][0] = s1 * d; + out_grads[17][1] = -s1 * d; + out_grads[25][1] = c1 * d; + d = -30.399773564 * a; + out_grads[18][2] = -c1 * d; + out_grads[24][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[16] = -c1 * d; + out_shs[26] = s1 * d; + d = -11.833095811 * z; + out_grads[16][0] = -c0 * d; + out_grads[26][0] = s0 * d; + out_grads[16][1] = s0 * d; + out_grads[26][1] = c0 * d; + d = 11.100427816 * z; + out_grads[17][2] = c0 * d; + out_grads[25][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[15] = c0 * d; + out_shs[27] = s0 * d; + d = 4.099104631; + out_grads[15][0] = c1 * d; + out_grads[27][0] = s1 * d; + out_grads[15][1] = -s1 * d; + out_grads[27][1] = c1 * d; + d = -2.366619162; + out_grads[16][2] = -c1 * d; + out_grads[26][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; + out_grads[6][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[14][2] = 0.0; + out_grads[15][2] = 0.0; + out_grads[21][0] = 0.0; + out_grads[21][1] = 0.0; + out_grads[27][2] = 0.0; +} diff --git a/fury/shaders/rt_odfs/eval_sh_grad_8.frag b/fury/shaders/rt_odfs/eval_sh_grad_8.frag new file mode 100644 index 000000000..b0a40d0a7 --- /dev/null +++ b/fury/shaders/rt_odfs/eval_sh_grad_8.frag @@ -0,0 +1,295 @@ +void eval_sh_grad_8(out float out_shs[45], out vec3 out_grads[45], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + out_grads[2][0] = -c0 * d; + out_grads[4][0] = s0 * d; + out_grads[2][1] = s0 * d; + out_grads[4][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + out_grads[9][0] = -c0 * d; + out_grads[11][0] = s0 * d; + out_grads[9][1] = s0 * d; + out_grads[11][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[20] = -c1 * d; + out_shs[22] = s1 * d; + out_grads[20][0] = -c0 * d; + out_grads[22][0] = s0 * d; + out_grads[20][1] = s0 * d; + out_grads[22][1] = c0 * d; + d = 88.106914343 * b; + out_grads[21][2] = d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[35] = -c1 * d; + out_shs[37] = s1 * d; + out_grads[35][0] = -c0 * d; + out_grads[37][0] = s0 * d; + out_grads[35][1] = s0 * d; + out_grads[37][1] = c0 * d; + d = 467.786944906 * b; + out_grads[36][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + d = 1.092548431; + out_grads[1][0] = c1 * d; + out_grads[5][0] = s1 * d; + out_grads[1][1] = -s1 * d; + out_grads[5][1] = c1 * d; + d = -1.092548431; + out_grads[2][2] = -c1 * d; + out_grads[4][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + d = 6.62322287 * a; + out_grads[8][0] = c1 * d; + out_grads[12][0] = s1 * d; + out_grads[8][1] = -s1 * d; + out_grads[12][1] = c1 * d; + d = -14.049977415 * a; + out_grads[9][2] = -c1 * d; + out_grads[11][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[19] = c0 * d; + out_shs[23] = s0 * d; + d = 30.399773564 * a; + out_grads[19][0] = c1 * d; + out_grads[23][0] = s1 * d; + out_grads[19][1] = -s1 * d; + out_grads[23][1] = c1 * d; + d = -96.132524816 * a; + out_grads[20][2] = -c1 * d; + out_grads[22][2] = s1 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[34] = c0 * d; + out_shs[38] = s0 * d; + d = 130.459545912 * a; + out_grads[34][0] = c1 * d; + out_grads[38][0] = s1 * d; + out_grads[34][1] = -s1 * d; + out_grads[38][1] = c1 * d; + d = -545.751435723 * a; + out_grads[35][2] = -c1 * d; + out_grads[37][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + d = -5.310392309 * z; + out_grads[7][0] = -c0 * d; + out_grads[13][0] = s0 * d; + out_grads[7][1] = s0 * d; + out_grads[13][1] = c0 * d; + d = 6.62322287 * z; + out_grads[8][2] = c0 * d; + out_grads[12][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[18] = -c1 * d; + out_shs[24] = s1 * d; + d = -30.399773564 * b; + out_grads[18][0] = -c0 * d; + out_grads[24][0] = s0 * d; + out_grads[18][1] = s0 * d; + out_grads[24][1] = c0 * d; + d = 60.799547128 * b; + out_grads[19][2] = c0 * d; + out_grads[23][2] = s0 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[33] = -c1 * d; + out_shs[39] = s1 * d; + d = -144.52614017 * b; + out_grads[33][0] = -c0 * d; + out_grads[39][0] = s0 * d; + out_grads[33][1] = s0 * d; + out_grads[39][1] = c0 * d; + d = 391.378637737 * b; + out_grads[34][2] = c0 * d; + out_grads[38][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + d = 2.503342942; + out_grads[6][0] = c1 * d; + out_grads[14][0] = s1 * d; + out_grads[6][1] = -s1 * d; + out_grads[14][1] = c1 * d; + d = -1.77013077; + out_grads[7][2] = -c1 * d; + out_grads[13][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[17] = c0 * d; + out_shs[25] = s0 * d; + d = 22.200855632 * a; + out_grads[17][0] = c1 * d; + out_grads[25][0] = s1 * d; + out_grads[17][1] = -s1 * d; + out_grads[25][1] = c1 * d; + d = -30.399773564 * a; + out_grads[18][2] = -c1 * d; + out_grads[24][2] = s1 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[32] = c0 * d; + out_shs[40] = s0 * d; + d = 124.388296437 * a; + out_grads[32][0] = c1 * d; + out_grads[40][0] = s1 * d; + out_grads[32][1] = -s1 * d; + out_grads[40][1] = c1 * d; + d = -240.876900283 * a; + out_grads[33][2] = -c1 * d; + out_grads[39][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[16] = -c1 * d; + out_shs[26] = s1 * d; + d = -11.833095811 * z; + out_grads[16][0] = -c0 * d; + out_grads[26][0] = s0 * d; + out_grads[16][1] = s0 * d; + out_grads[26][1] = c0 * d; + d = 11.100427816 * z; + out_grads[17][2] = c0 * d; + out_grads[25][2] = s0 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[31] = -c1 * d; + out_shs[41] = s1 * d; + d = -86.247765552 * b; + out_grads[31][0] = -c0 * d; + out_grads[41][0] = s0 * d; + out_grads[31][1] = s0 * d; + out_grads[41][1] = c0 * d; + d = 124.388296437 * b; + out_grads[32][2] = c0 * d; + out_grads[40][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[15] = c0 * d; + out_shs[27] = s0 * d; + d = 4.099104631; + out_grads[15][0] = c1 * d; + out_grads[27][0] = s1 * d; + out_grads[15][1] = -s1 * d; + out_grads[27][1] = c1 * d; + d = -2.366619162; + out_grads[16][2] = -c1 * d; + out_grads[26][2] = s1 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[30] = c0 * d; + out_shs[42] = s0 * d; + d = 47.909948945 * a; + out_grads[30][0] = c1 * d; + out_grads[42][0] = s1 * d; + out_grads[30][1] = -s1 * d; + out_grads[42][1] = c1 * d; + d = -51.748659331 * a; + out_grads[31][2] = -c1 * d; + out_grads[41][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[29] = -c1 * d; + out_shs[43] = s1 * d; + d = -20.409946485 * z; + out_grads[29][0] = -c0 * d; + out_grads[43][0] = s0 * d; + out_grads[29][1] = s0 * d; + out_grads[43][1] = c0 * d; + d = 15.969982982 * z; + out_grads[30][2] = c0 * d; + out_grads[42][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[28] = c0 * d; + out_shs[44] = s0 * d; + d = 5.831413281; + out_grads[28][0] = c1 * d; + out_grads[44][0] = s1 * d; + out_grads[28][1] = -s1 * d; + out_grads[44][1] = c1 * d; + d = -2.915706641; + out_grads[29][2] = -c1 * d; + out_grads[43][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; + out_grads[6][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[14][2] = 0.0; + out_grads[15][2] = 0.0; + out_grads[21][0] = 0.0; + out_grads[21][1] = 0.0; + out_grads[27][2] = 0.0; + out_grads[28][2] = 0.0; + out_grads[36][0] = 0.0; + out_grads[36][1] = 0.0; + out_grads[44][2] = 0.0; +} diff --git a/fury/shaders/rt_odfs/find_roots.frag b/fury/shaders/rt_odfs/find_roots.frag new file mode 100644 index 000000000..e5b80f7a4 --- /dev/null +++ b/fury/shaders/rt_odfs/find_roots.frag @@ -0,0 +1,82 @@ +void find_roots(out float out_roots[MAX_DEGREE + 1], float poly[MAX_DEGREE + 1], float begin, float end) { + float tolerance = (end - begin) * 1.0e-4; + // Construct the quadratic derivative of the polynomial. We divide each + // derivative by the factorial of its order, such that the constant + // coefficient can be copied directly from poly. That is a safeguard + // against overflow and makes it easier to avoid spilling below. The + // factors happen to be binomial coefficients then. + float derivative[MAX_DEGREE + 1]; + derivative[0] = poly[MAX_DEGREE - 2]; + derivative[1] = float(MAX_DEGREE - 1) * poly[MAX_DEGREE - 1]; + derivative[2] = (0.5 * float((MAX_DEGREE - 1) * MAX_DEGREE)) * poly[MAX_DEGREE - 0]; + _unroll_ + for (int i = 3; i != MAX_DEGREE + 1; ++i) + derivative[i] = 0.0; + // Compute its two roots using the quadratic formula + float discriminant = derivative[1] * derivative[1] - 4.0 * derivative[0] * derivative[2]; + if (discriminant >= 0.0) { + float sqrt_discriminant = sqrt(discriminant); + float scaled_root = derivative[1] + ((derivative[1] > 0.0) ? sqrt_discriminant : (-sqrt_discriminant)); + float root_0 = clamp(-2.0 * derivative[0] / scaled_root, begin, end); + float root_1 = clamp(-0.5 * scaled_root / derivative[2], begin, end); + out_roots[MAX_DEGREE - 2] = min(root_0, root_1); + out_roots[MAX_DEGREE - 1] = max(root_0, root_1); + } + else { + // Indicate that the cubic derivative has a single root + out_roots[MAX_DEGREE - 2] = begin; + out_roots[MAX_DEGREE - 1] = begin; + } + // The last entry in the root array is set to end to make it easier to + // iterate over relevant intervals, all untouched roots are set to begin + out_roots[MAX_DEGREE] = end; + _unroll_ + for (int i = 0; i != MAX_DEGREE - 2; ++i) + out_roots[i] = begin; + // Work your way up to derivatives of higher degree until you reach the + // polynomial itself. This implementation may seem peculiar: It always + // treats the derivative as though it had degree MAX_DEGREE and it + // constructs the derivatives in a contrived way. Changing that would + // reduce the number of arithmetic instructions roughly by a factor of two. + // However, it would also cause register spilling, which has a far more + // negative impact on the overall run time. Profiling indicates that the + // current implementation has no spilling whatsoever. + _loop_ + for (int degree = 3; degree != MAX_DEGREE + 1; ++degree) { + // Take the integral of the previous derivative (scaled such that the + // constant coefficient can still be copied directly from poly) + float prev_derivative_order = float(MAX_DEGREE + 1 - degree); + _unroll_ + for (int i = MAX_DEGREE; i != 0; --i) + derivative[i] = derivative[i - 1] * (prev_derivative_order * (1.0 / float(i))); + // Copy the constant coefficient without causing spilling. This part + // would be harder if the derivative were not scaled the way it is. + _unroll_ + for (int i = 0; i != MAX_DEGREE - 2; ++i) + derivative[0] = (degree == MAX_DEGREE - i) ? poly[i] : derivative[0]; + // Determine the value of this derivative at begin + float begin_value = derivative[MAX_DEGREE]; + _unroll_ + for (int i = MAX_DEGREE - 1; i != -1; --i) + begin_value = begin_value * begin + derivative[i]; + // Iterate over the intervals where roots may be found + _unroll_ + for (int i = 0; i != MAX_DEGREE; ++i) { + if (i < MAX_DEGREE - degree) + continue; + float current_begin = out_roots[i]; + float current_end = out_roots[i + 1]; + // Try to find a root + float root; + if (newton_bisection(root, begin_value, derivative, current_begin, current_end, begin_value, tolerance)) + out_roots[i] = root; + else if (degree < MAX_DEGREE) + // Create an empty interval for the next iteration + out_roots[i] = out_roots[i - 1]; + else + out_roots[i] = NO_INTERSECTION; + } + } + // We no longer need this array entry + out_roots[MAX_DEGREE] = NO_INTERSECTION; +} diff --git a/fury/shaders/rt_odfs/get_inv_vandermonde.frag b/fury/shaders/rt_odfs/get_inv_vandermonde.frag new file mode 100644 index 000000000..4c7f521c0 --- /dev/null +++ b/fury/shaders/rt_odfs/get_inv_vandermonde.frag @@ -0,0 +1,58 @@ +void get_inv_vandermonde(out float v[(SH_DEGREE + 1) * (SH_DEGREE + 1)]) +{ + #if SH_DEGREE == 2 + v[0*3 + 0] = -0.3333333333; v[0*3 + 1] = 0.6666666667; v[0*3 + 2] = 0.6666666667; + v[1*3 + 0] = -0.0; v[1*3 + 1] = 1.1547005384; v[1*3 + 2] = -1.1547005384; + v[2*3 + 0] = 1.0; v[2*3 + 1] = 0.0; v[2*3 + 2] = 0.0; + #elif SH_DEGREE == 4 + v[0*5 + 0] = 0.2; v[0*5 + 1] = -0.2472135955; v[0*5 + 2] = 0.6472135955; v[0*5 + 3] = 0.6472135955; v[0*5 + 4] = -0.2472135955; + v[1*5 + 0] = 0.0; v[1*5 + 1] = -0.1796111906; v[1*5 + 2] = 1.9919186279; v[1*5 + 3] = -1.9919186279; v[1*5 + 4] = 0.1796111906; + v[2*5 + 0] = -2.0; v[2*5 + 1] = 2.3416407865; v[2*5 + 2] = -0.3416407865; v[2*5 + 3] = -0.3416407865; v[2*5 + 4] = 2.3416407865; + v[3*5 + 0] = -0.0; v[3*5 + 1] = 1.7013016167; v[3*5 + 2] = -1.0514622242; v[3*5 + 3] = 1.0514622242; v[3*5 + 4] = -1.7013016167; + v[4*5 + 0] = 1.0; v[4*5 + 1] = 0.0; v[4*5 + 2] = 0.0; v[4*5 + 3] = 0.0; v[4*5 + 4] = 0.0; + #elif SH_DEGREE == 6 + v[0*7 + 0] = -0.1428571429; v[0*7 + 1] = 0.1585594663; v[0*7 + 2] = -0.2291250674; v[0*7 + 3] = 0.6419941725; v[0*7 + 4] = 0.6419941725; v[0*7 + 5] = -0.2291250674; v[0*7 + 6] = 0.1585594663; + v[1*7 + 0] = -0.0; v[1*7 + 1] = 0.0763582145; v[1*7 + 2] = -0.2873137468; v[1*7 + 3] = 2.8127602518; v[1*7 + 4] = -2.8127602518; v[1*7 + 5] = 0.2873137468; v[1*7 + 6] = -0.0763582145; + v[2*7 + 0] = 3.0; v[2*7 + 1] = -3.2929766145; v[2*7 + 2] = 4.4513463718; v[2*7 + 3] = -1.1583697574; v[2*7 + 4] = -1.1583697574; v[2*7 + 5] = 4.4513463718; v[2*7 + 6] = -3.2929766145; + v[3*7 + 0] = 0.0; v[3*7 + 1] = -1.5858139579; v[3*7 + 2] = 5.5818117995; v[3*7 + 3] = -5.0751495106; v[3*7 + 4] = 5.0751495106; v[3*7 + 5] = -5.5818117995; v[3*7 + 6] = 1.5858139579; + v[4*7 + 0] = -5.0; v[4*7 + 1] = 4.7858935686; v[4*7 + 2] = -1.0200067492; v[4*7 + 3] = 0.2341131806; v[4*7 + 4] = 0.2341131806; v[4*7 + 5] = -1.0200067492; v[4*7 + 6] = 4.7858935686; + v[5*7 + 0] = -0.0; v[5*7 + 1] = 2.3047648710; v[5*7 + 2] = -1.2790480077; v[5*7 + 3] = 1.0257168633; v[5*7 + 4] = -1.0257168633; v[5*7 + 5] = 1.2790480077; v[5*7 + 6] = -2.3047648710; + v[6*7 + 0] = 1.0; v[6*7 + 1] = 0.0; v[6*7 + 2] = 0.0; v[6*7 + 3] = 0.0; v[6*7 + 4] = 0.0; v[6*7 + 5] = 0.0; v[6*7 + 6] = 0.0; + #elif SH_DEGREE == 8 + v[0*9 + 0] = 0.1111111111; v[0*9 + 1] = -0.1182419747; v[0*9 + 2] = 0.1450452544; v[0*9 + 3] = -0.2222222222; v[0*9 + 4] = 0.6398633870; v[0*9 + 5] = 0.6398633870; v[0*9 + 6] = -0.2222222222; v[0*9 + 7] = 0.1450452544; v[0*9 + 8] = -0.1182419747; + v[1*9 + 0] = 0.0; v[1*9 + 1] = -0.0430365592; v[1*9 + 2] = 0.1217074194; v[1*9 + 3] = -0.3849001795; v[1*9 + 4] = 3.6288455938; v[1*9 + 5] = -3.6288455938; v[1*9 + 6] = 0.3849001795; v[1*9 + 7] = -0.1217074194; v[1*9 + 8] = 0.0430365592; + v[2*9 + 0] = -4.0; v[2*9 + 1] = 4.2410470634; v[2*9 + 2] = -5.1195045066; v[2*9 + 3] = 7.3333333333; v[2*9 + 4] = -2.4548758901; v[2*9 + 5] = -2.4548758901; v[2*9 + 6] = 7.3333333333; v[2*9 + 7] = -5.1195045066; v[2*9 + 8] = 4.2410470634; + v[3*9 + 0] = -0.0; v[3*9 + 1] = 1.5436148932; v[3*9 + 2] = -4.2957743433; v[3*9 + 3] = 12.7017059222; v[3*9 + 4] = -13.9222930051; v[3*9 + 5] = 13.9222930051; v[3*9 + 6] = -12.7017059222; v[3*9 + 7] = 4.2957743433; v[3*9 + 8] = -1.5436148932; + v[4*9 + 0] = 14.0; v[4*9 + 1] = -14.3366589404; v[4*9 + 2] = 14.6711193836; v[4*9 + 3] = -6.0; v[4*9 + 4] = 1.6655395568; v[4*9 + 5] = 1.6655395568; v[4*9 + 6] = -6.0; v[4*9 + 7] = 14.6711193836; v[4*9 + 8] = -14.3366589404; + v[5*9 + 0] = 0.0; v[5*9 + 1] = -5.2181171131; v[5*9 + 2] = 12.3105308637; v[5*9 + 3] = -10.3923048454; v[5*9 + 4] = 9.4457442082; v[5*9 + 5] = -9.4457442082; v[5*9 + 6] = 10.3923048454; v[5*9 + 7] = -12.3105308637; v[5*9 + 8] = 5.2181171131; + v[6*9 + 0] = -9.3333333333; v[6*9 + 1] = 8.0330865684; v[6*9 + 2] = -1.8540394597; v[6*9 + 3] = 0.6666666667; v[6*9 + 4] = -0.1790471086; v[6*9 + 5] = -0.1790471086; v[6*9 + 6] = 0.6666666667; v[6*9 + 7] = -1.8540394597; v[6*9 + 8] = 8.0330865684; + v[7*9 + 0] = -0.0; v[7*9 + 1] = 2.9238044002; v[7*9 + 2] = -1.5557238269; v[7*9 + 3] = 1.1547005384; v[7*9 + 4] = -1.0154266119; v[7*9 + 5] = 1.0154266119; v[7*9 + 6] = -1.1547005384; v[7*9 + 7] = 1.5557238269; v[7*9 + 8] = -2.9238044002; + v[8*9 + 0] = 1.0; v[8*9 + 1] = 0.0; v[8*9 + 2] = 0.0; v[8*9 + 3] = 0.0; v[8*9 + 4] = 0.0; v[8*9 + 5] = 0.0; v[8*9 + 6] = 0.0; v[8*9 + 7] = 0.0; v[8*9 + 8] = 0.0; + #elif SH_DEGREE == 10 + v[0*11 + 0] = -0.0909090909; v[0*11 + 1] = 0.0947470106; v[0*11 + 2] = -0.1080638444; v[0*11 + 3] = 0.1388220215; v[0*11 + 4] = -0.2188392043; v[0*11 + 5] = 0.6387885621; v[0*11 + 6] = 0.6387885621; v[0*11 + 7] = -0.2188392043; v[0*11 + 8] = 0.1388220215; v[0*11 + 9] = -0.1080638444; v[0*11 + 10] = 0.0947470106; + v[1*11 + 0] = -0.0; v[1*11 + 1] = 0.0278202324; v[1*11 + 2] = -0.0694484159; v[1*11 + 3] = 0.1602091533; v[1*11 + 4] = -0.4791910159; v[1*11 + 5] = 4.4428720384; v[1*11 + 6] = -4.4428720384; v[1*11 + 7] = 0.4791910159; v[1*11 + 8] = -0.1602091533; v[1*11 + 9] = 0.0694484159; v[1*11 + 10] = -0.0278202324; + v[2*11 + 0] = 5.0; v[2*11 + 1] = -5.2029168239; v[2*11 + 2] = 5.8988796576; v[2*11 + 3] = -7.4503199653; v[2*11 + 4] = 10.9868742757; v[2*11 + 5] = -4.2325171441; v[2*11 + 6] = -4.2325171441; v[2*11 + 7] = 10.9868742757; v[2*11 + 8] = -7.4503199653; v[2*11 + 9] = 5.8988796576; v[2*11 + 10] = -5.2029168239; + v[3*11 + 0] = 0.0; v[3*11 + 1] = -1.5277142200; v[3*11 + 2] = 3.7909797649; v[3*11 + 3] = -8.5981275876; v[3*11 + 4] = 24.0578988657; v[3*11 + 5] = -29.4378033460; v[3*11 + 6] = 29.4378033460; v[3*11 + 7] = -24.0578988657; v[3*11 + 8] = 8.5981275876; v[3*11 + 9] = -3.7909797649; v[3*11 + 10] = 1.5277142200; + v[4*11 + 0] = -30.0; v[4*11 + 1] = 30.8179361182; v[4*11 + 2] = -33.2247539061; v[4*11 + 3] = 35.8884989085; v[4*11 + 4] = -19.5374870834; v[4*11 + 5] = 6.0558059629; v[4*11 + 6] = 6.0558059629; v[4*11 + 7] = -19.5374870834; v[4*11 + 8] = 35.8884989085; v[4*11 + 9] = -33.2247539061; v[4*11 + 10] = 30.8179361182; + v[5*11 + 0] = -0.0; v[5*11 + 1] = 9.0489625020; v[5*11 + 2] = -21.3522528115; v[5*11 + 3] = 41.4175356200; v[5*11 + 4] = -42.7811292411; v[5*11 + 5] = 42.1190556280; v[5*11 + 6] = -42.1190556280; v[5*11 + 7] = 42.7811292411; v[5*11 + 8] = -41.4175356200; v[5*11 + 9] = 21.3522528115; v[5*11 + 10] = -9.0489625020; + v[6*11 + 0] = 42.0; v[6*11 + 1] = -41.1161037573; v[6*11 + 2] = 36.2032364762; v[6*11 + 3] = -16.3373898141; v[6*11 + 4] = 7.4261062994; v[6*11 + 5] = -2.1758492042; v[6*11 + 6] = -2.1758492042; v[6*11 + 7] = 7.4261062994; v[6*11 + 8] = -16.3373898141; v[6*11 + 9] = 36.2032364762; v[6*11 + 10] = -41.1161037573; + v[7*11 + 0] = 0.0; v[7*11 + 1] = -12.0727773496; v[7*11 + 2] = 23.2664073304; v[7*11 + 3] = -18.8543529304; v[7*11 + 4] = 16.2609045881; v[7*11 + 5] = -15.1333636234; v[7*11 + 6] = 15.1333636234; v[7*11 + 7] = -16.2609045881; v[7*11 + 8] = 18.8543529304; v[7*11 + 9] = -23.2664073304; v[7*11 + 10] = 12.0727773496; + v[8*11 + 0] = -15.0; v[8*11 + 1] = 12.0883694702; v[8*11 + 2] = -2.8781222629; v[8*11 + 3] = 1.1465503415; v[8*11 + 4] = -0.5020543475; v[8*11 + 5] = 0.1452567988; v[8*11 + 6] = 0.1452567988; v[8*11 + 7] = -0.5020543475; v[8*11 + 8] = 1.1465503415; v[8*11 + 9] = -2.8781222629; v[8*11 + 10] = 12.0883694702; + v[9*11 + 0] = -0.0; v[9*11 + 1] = 3.5494655329; v[9*11 + 2] = -1.8496568659; v[9*11 + 3] = 1.3231896304; v[9*11 + 4] = -1.0993456751; v[9*11 + 5] = 1.0102832265; v[9*11 + 6] = -1.0102832265; v[9*11 + 7] = 1.0993456751; v[9*11 + 8] = -1.3231896304; v[9*11 + 9] = 1.8496568659; v[9*11 + 10] = -3.5494655329; + v[10*11 + 0] = 1.0; v[10*11 + 1] = 0.0; v[10*11 + 2] = 0.0; v[10*11 + 3] = 0.0; v[10*11 + 4] = 0.0; v[10*11 + 5] = 0.0; v[10*11 + 6] = 0.0; v[10*11 + 7] = 0.0; v[10*11 + 8] = 0.0; v[10*11 + 9] = 0.0; v[10*11 + 10] = 0.0; + #elif SH_DEGREE == 12 + v[0*13 + 0] = 0.0769230769; v[0*13 + 1] = -0.0792252178; v[0*13 + 2] = 0.0868739663; v[0*13 + 3] = -0.1027681661; v[0*13 + 4] = 0.1354125166; v[0*13 + 5] = -0.2169261613; v[0*13 + 6] = 0.6381715239; v[0*13 + 7] = 0.6381715239; v[0*13 + 8] = -0.2169261613; v[0*13 + 9] = 0.1354125166; v[0*13 + 10] = -0.1027681661; v[0*13 + 11] = 0.0868739663; v[0*13 + 12] = -0.0792252178; + v[1*13 + 0] = -0.0; v[1*13 + 1] = -0.0195272624; v[1*13 + 2] = 0.0455949748; v[1*13 + 3] = -0.0910446506; v[1*13 + 4] = 0.1961788986; v[1*13 + 5] = -0.5719872785; v[1*13 + 6] = 5.2558153553; v[1*13 + 7] = -5.2558153553; v[1*13 + 8] = 0.5719872785; v[1*13 + 9] = -0.1961788986; v[1*13 + 10] = 0.0910446506; v[1*13 + 11] = -0.0455949748; v[1*13 + 12] = 0.0195272624; + v[2*13 + 0] = -6.0; v[2*13 + 1] = 6.1747539478; v[2*13 + 2] = -6.7522392818; v[2*13 + 3] = 7.9352584366; v[2*13 + 4] = -10.2779620900; v[2*13 + 5] = 15.4120340799; v[2*13 + 6] = -6.4918450925; v[2*13 + 7] = -6.4918450925; v[2*13 + 8] = 15.4120340799; v[2*13 + 9] = -10.2779620900; v[2*13 + 10] = 7.9352584366; v[2*13 + 11] = -6.7522392818; v[2*13 + 12] = 6.1747539478; + v[3*13 + 0] = -0.0; v[3*13 + 1] = 1.5219401578; v[3*13 + 2] = -3.5438485554; v[3*13 + 3] = 7.0300255289; v[3*13 + 4] = -14.8901987371; v[3*13 + 5] = 40.6381940129; v[3*13 + 6] = -53.4651544987; v[3*13 + 7] = 53.4651544987; v[3*13 + 8] = -40.6381940129; v[3*13 + 9] = 14.8901987371; v[3*13 + 10] = -7.0300255289; v[3*13 + 11] = 3.5438485554; v[3*13 + 12] = -1.5219401578; + v[4*13 + 0] = 55.0; v[4*13 + 1] = -56.2709061445; v[4*13 + 2] = 60.2549306937; v[4*13 + 3] = -67.2511796347; v[4*13 + 4] = 75.2477722397; v[4*13 + 5] = -47.9480941911; v[4*13 + 6] = 15.9674770369; v[4*13 + 7] = 15.9674770369; v[4*13 + 8] = -47.9480941911; v[4*13 + 9] = 75.2477722397; v[4*13 + 10] = -67.2511796347; v[4*13 + 11] = 60.2549306937; v[4*13 + 12] = -56.2709061445; + v[5*13 + 0] = 0.0; v[5*13 + 1] = -13.8695326974; v[5*13 + 2] = 31.6242271914; v[5*13 + 3] = -59.5793462127; v[5*13 + 4] = 109.0152185187; v[5*13 + 5] = -126.4287338180; v[5*13 + 6] = 131.5040045727; v[5*13 + 7] = -131.5040045727; v[5*13 + 8] = 126.4287338180; v[5*13 + 9] = -109.0152185187; v[5*13 + 10] = 59.5793462127; v[5*13 + 11] = -31.6242271914; v[5*13 + 12] = 13.8695326974; + v[6*13 + 0] = -132.0; v[6*13 + 1] = 132.5319409049; v[6*13 + 2] = -132.4780513404; v[6*13 + 3] = 123.5674782081; v[6*13 + 4] = -74.4320682907; v[6*13 + 5] = 38.8801193717; v[6*13 + 6] = -12.0694188537; v[6*13 + 7] = -12.0694188537; v[6*13 + 8] = 38.8801193717; v[6*13 + 9] = -74.4320682907; v[6*13 + 10] = 123.5674782081; v[6*13 + 11] = -132.4780513404; v[6*13 + 12] = 132.5319409049; + v[7*13 + 0] = -0.0; v[7*13 + 1] = 32.6661895777; v[7*13 + 2] = -69.5298450306; v[7*13 + 3] = 109.4712331409; v[7*13 + 4] = -107.8334673306; v[7*13 + 5] = 102.5184492897; v[7*13 + 6] = -99.4006071501; v[7*13 + 7] = 99.4006071501; v[7*13 + 8] = -102.5184492897; v[7*13 + 9] = 107.8334673306; v[7*13 + 10] = -109.4712331409; v[7*13 + 11] = 69.5298450306; v[7*13 + 12] = -32.6661895777; + v[8*13 + 0] = 99.0; v[8*13 + 1] = -93.9113626635; v[8*13 + 2] = 75.3147168618; v[8*13 + 3] = -35.2795800772; v[8*13 + 4] = 18.0521608541; v[8*13 + 5] = -8.8650350126; v[8*13 + 6] = 2.6891000373; v[8*13 + 7] = 2.6891000373; v[8*13 + 8] = -8.8650350126; v[8*13 + 9] = 18.0521608541; v[8*13 + 10] = -35.2795800772; v[8*13 + 11] = 75.3147168618; v[8*13 + 12] = -93.9113626635; + v[9*13 + 0] = 0.0; v[9*13 + 1] = -23.1470719837; v[9*13 + 2] = 39.5282127035; v[9*13 + 3] = -31.2549806126; v[9*13 + 4] = 26.1530700733; v[9*13 + 5] = -23.3751762359; v[9*13 + 6] = 22.1467313083; v[9*13 + 7] = -22.1467313083; v[9*13 + 8] = 23.3751762359; v[9*13 + 9] = -26.1530700733; v[9*13 + 10] = 31.2549806126; v[9*13 + 11] = -39.5282127035; v[9*13 + 12] = 23.1470719837; + v[10*13 + 0] = -22.0; v[10*13 + 1] = 16.9531714429; v[10*13 + 2] = -4.0999479387; v[10*13 + 3] = 1.7021989010; v[10*13 + 4] = -0.8387165175; v[10*13 + 5] = 0.4056079008; v[10*13 + 6] = -0.1223137885; v[10*13 + 7] = -0.1223137885; v[10*13 + 8] = 0.4056079008; v[10*13 + 9] = -0.8387165175; v[10*13 + 10] = 1.7021989010; v[10*13 + 11] = -4.0999479387; v[10*13 + 12] = 16.9531714429; + v[11*13 + 0] = -0.0; v[11*13 + 1] = 4.1785814689; v[11*13 + 2] = -2.1518186743; v[11*13 + 3] = 1.5080166355; v[11*13 + 4] = -1.2150906493; v[11*13 + 5] = 1.0695001374; v[11*13 + 6] = -1.0073446769; v[11*13 + 7] = 1.0073446769; v[11*13 + 8] = -1.0695001374; v[11*13 + 9] = 1.2150906493; v[11*13 + 10] = -1.5080166355; v[11*13 + 11] = 2.1518186743; v[11*13 + 12] = -4.1785814689; + v[12*13 + 0] = 1.0; v[12*13 + 1] = 0.0; v[12*13 + 2] = 0.0; v[12*13 + 3] = 0.0; v[12*13 + 4] = 0.0; v[12*13 + 5] = 0.0; v[12*13 + 6] = 0.0; v[12*13 + 7] = 0.0; v[12*13 + 8] = 0.0; v[12*13 + 9] = 0.0; v[12*13 + 10] = 0.0; v[12*13 + 11] = 0.0; v[12*13 + 12] = 0.0; + #endif +} diff --git a/fury/shaders/rt_odfs/get_sh_glyph_normal.frag b/fury/shaders/rt_odfs/get_sh_glyph_normal.frag new file mode 100644 index 000000000..4831fb8b4 --- /dev/null +++ b/fury/shaders/rt_odfs/get_sh_glyph_normal.frag @@ -0,0 +1,16 @@ +vec3 get_sh_glyph_normal(float sh_coeffs[SH_COUNT], vec3 point) +{ + float shs[SH_COUNT]; + vec3 grads[SH_COUNT]; + float length_inv = inversesqrt(dot(point, point)); + vec3 normalized = point * length_inv; + eval_sh_grad(shs, grads, normalized); + float value = 0.0; + vec3 grad = vec3(0.0); + _unroll_ + for (int i = 0; i != SH_COUNT; ++i) { + value += sh_coeffs[i] * shs[i]; + grad += sh_coeffs[i] * grads[i]; + } + return normalize(point - (value * length_inv) * (grad - dot(grad, normalized) * normalized)); +} diff --git a/fury/shaders/rt_odfs/gltf_dielectric_brdf.frag b/fury/shaders/rt_odfs/gltf_dielectric_brdf.frag new file mode 100644 index 000000000..465ab2266 --- /dev/null +++ b/fury/shaders/rt_odfs/gltf_dielectric_brdf.frag @@ -0,0 +1,41 @@ +vec3 gltf_dielectric_brdf(vec3 incoming, vec3 outgoing, vec3 normal, float roughness, vec3 base_color) +{ + float ni = dot(normal, incoming); + float no = dot(normal, outgoing); + // Early out if incoming or outgoing direction are below the horizon + if (ni <= 0.0 || no <= 0.0) + return vec3(0.0); + // Save some work by not actually computing the half-vector. If the half- + // vector were h, ih = dot(incoming, h) and + // sqrt(nh_ih_2 / ih_2) = dot(normal, h). + float ih_2 = dot(incoming, outgoing) * 0.5 + 0.5; + float sum = ni + no; + float nh_ih_2 = 0.25 * sum * sum; + float ih = sqrt(ih_2); + + // Evaluate the GGX normal distribution function + float roughness_2 = roughness * roughness; + float roughness_4 = roughness_2 * roughness_2; + float roughness_flip = 1.0 - roughness_4; + float denominator = ih_2 - nh_ih_2 * roughness_flip; + float ggx = (roughness_4 * M_INV_PI * ih_2) / (denominator * denominator); + // Evaluate the "visibility" (i.e. masking-shadowing times geometry terms) + float vi = ni + sqrt(roughness_4 + roughness_flip * ni * ni); + float vo = no + sqrt(roughness_4 + roughness_flip * no * no); + float v = 1.0 / (vi * vo); + // That completes the specular BRDF + float specular = v * ggx; + + // The diffuse BRDF is Lambertian + vec3 diffuse = M_INV_PI * base_color; + + // Evaluate the Fresnel term using the Fresnel-Schlick approximation + const float ior = 1.5; + const float f0 = ((1.0 - ior) / (1.0 + ior)) * ((1.0 - ior) / (1.0 + ior)); + float ih_flip = 1.0 - ih; + float ih_flip_2 = ih_flip * ih_flip; + float fresnel = f0 + (1.0 - f0) * ih_flip * ih_flip_2 * ih_flip_2; + + // Mix the two components + return mix(diffuse, vec3(specular), fresnel); +} diff --git a/fury/shaders/rt_odfs/linear_rgb_to_srgb.frag b/fury/shaders/rt_odfs/linear_rgb_to_srgb.frag new file mode 100644 index 000000000..d1c72c83b --- /dev/null +++ b/fury/shaders/rt_odfs/linear_rgb_to_srgb.frag @@ -0,0 +1,4 @@ +vec3 linear_rgb_to_srgb(vec3 linear) +{ + return vec3(linear_to_srgb(linear.r), linear_to_srgb(linear.g), linear_to_srgb(linear.b)); +} diff --git a/fury/shaders/rt_odfs/linear_to_srgb.frag b/fury/shaders/rt_odfs/linear_to_srgb.frag new file mode 100644 index 000000000..ac686853c --- /dev/null +++ b/fury/shaders/rt_odfs/linear_to_srgb.frag @@ -0,0 +1,4 @@ +float linear_to_srgb(float linear) +{ + return (linear <= 0.0031308) ? (12.92 * linear) : (1.055 * pow(linear, 1.0 / 2.4) - 0.055); +} diff --git a/fury/shaders/rt_odfs/newton_bisection.frag b/fury/shaders/rt_odfs/newton_bisection.frag new file mode 100644 index 000000000..3f4b7f81f --- /dev/null +++ b/fury/shaders/rt_odfs/newton_bisection.frag @@ -0,0 +1,47 @@ +bool newton_bisection(out float out_root, out float out_end_value, + float poly[MAX_DEGREE + 1], float begin, float end, + float begin_value, float error_tolerance) +{ + if (begin == end) { + out_end_value = begin_value; + return false; + } + // Evaluate the polynomial at the end of the interval + out_end_value = poly[MAX_DEGREE]; + _unroll_ + for (int i = MAX_DEGREE - 1; i != -1; --i) + out_end_value = out_end_value * end + poly[i]; + // If the values at both ends have the same non-zero sign, there is no root + if (begin_value * out_end_value > 0.0) + return false; + // Otherwise, we find the root iteratively using Newton bisection (with + // bounded iteration count) + float current = 0.5 * (begin + end); + _loop_ + for (int i = 0; i != 90; ++i) { + // Evaluate the polynomial and its derivative + float value = poly[MAX_DEGREE] * current + poly[MAX_DEGREE - 1]; + float derivative = poly[MAX_DEGREE]; + _unroll_ + for (int j = MAX_DEGREE - 2; j != -1; --j) { + derivative = derivative * current + value; + value = value * current + poly[j]; + } + // Shorten the interval + bool right = begin_value * value > 0.0; + begin = right ? current : begin; + end = right ? end : current; + // Apply Newton's method + float guess = current - value / derivative; + // Pick a guess + float middle = 0.5 * (begin + end); + float next = (guess >= begin && guess <= end) ? guess : middle; + // Move along or terminate + bool done = abs(next - current) < error_tolerance; + current = next; + if (done) + break; + } + out_root = current; + return true; +} diff --git a/fury/shaders/rt_odfs/ray_sh_glyph_intersections.frag b/fury/shaders/rt_odfs/ray_sh_glyph_intersections.frag new file mode 100644 index 000000000..a47dbbfc4 --- /dev/null +++ b/fury/shaders/rt_odfs/ray_sh_glyph_intersections.frag @@ -0,0 +1,81 @@ +void ray_sh_glyph_intersections(out float out_ray_params[MAX_DEGREE], float sh_coeffs[SH_COUNT], vec3 ray_origin, vec3 ray_dir) +{ + // Determine the direction from the glyph center to the closest point on + // the ray + float dir_dot_origin = dot(ray_dir, ray_origin); + vec3 closest_dir = normalize(ray_origin - dir_dot_origin * ray_dir); + // Evaluate the SH polynomial at SH_DEGREE + 1 points. That is enough to + // know its value everywhere along the ray. + float sh_values[SH_DEGREE + 1]; + _unroll_ + for (int i = 0; i != SH_DEGREE + 1; ++i) { + vec3 point = cos(float(i) * (M_PI / float(SH_DEGREE + 1))) * ray_dir + + sin(float(i) * (M_PI / float(SH_DEGREE + 1))) * closest_dir; + float shs[SH_COUNT]; + eval_sh(shs, point); + sh_values[i] = 0.0; + _unroll_ + for (int j = 0; j != SH_COUNT; ++j) + sh_values[i] += sh_coeffs[j] * shs[j]; + } + // Compute coefficients of the SH polynomial along the ray in the + // coordinate frame given by ray_dir and closest_dir + float radius_poly[SH_DEGREE + 1]; + float inv_vander[(SH_DEGREE + 1) * (SH_DEGREE + 1)]; + get_inv_vandermonde(inv_vander); + _unroll_ + for (int i = 0; i != SH_DEGREE + 1; ++i) { + radius_poly[i] = 0.0; + _unroll_ + for (int j = 0; j != SH_DEGREE + 1; ++j) + radius_poly[i] += inv_vander[i * (SH_DEGREE + 1) + j] * sh_values[j]; + } + // Compute a bounding circle around the glyph in the relevant plane + float radius_max = 0.0; + _unroll_ + for (int i = 0; i != SH_DEGREE + 1; ++i) { + float bound = sqrt(pow(float(i), float(i)) * pow(float(SH_DEGREE - i), float(SH_DEGREE - i)) / pow(float(SH_DEGREE), float(SH_DEGREE))); + // Workaround for buggy compilers where 0^0 is 0 + bound = (i == 0 || i == SH_DEGREE) ? 1.0 : bound; + radius_max += bound * abs(radius_poly[i]); + } + // Figure out the interval, where (if at all) the ray intersects the circle + float closest_dot_origin = dot(closest_dir, ray_origin); + if (radius_max < abs(closest_dot_origin)) { + _unroll_ + for (int i = 0; i != MAX_DEGREE; ++i) + out_ray_params[i] = NO_INTERSECTION; + return; + } + float radius_over_dot = radius_max / closest_dot_origin; + float u_max = sqrt(radius_over_dot * radius_over_dot - 1.0); + // Take the square of radius_poly + float poly[MAX_DEGREE + 1]; + _unroll_ + for (int i = 0; i != MAX_DEGREE + 1; ++i) + poly[i] = 0.0; + _unroll_ + for (int i = 0; i != SH_DEGREE + 1; ++i) + _unroll_ + for (int j = 0; j != SH_DEGREE + 1; ++j) + poly[i + j] += radius_poly[i] * radius_poly[j]; + // Subtract the scaled (2 * SH_DEGREE + 2)-th power of the distance to the + // glyph center + float dot_sq = closest_dot_origin * closest_dot_origin; + float binomial = 1.0; + _unroll_ + for (int i = 0; i != SH_DEGREE + 2; ++i) { + poly[2 * i] -= binomial * dot_sq; + // Update the binomial coefficient using a recurrence relation + binomial *= float(SH_DEGREE + 1 - i) / float(i + 1); + } + // Find roots of the polynomial within the relevant bounds + float roots[MAX_DEGREE + 1]; + find_roots(roots, poly, -u_max, u_max); + // Convert them back to the original coordinate frame (i.e. ray parameters) + _unroll_ + for (int i = 0; i != MAX_DEGREE; ++i) + out_ray_params[i] = (roots[i] != NO_INTERSECTION) + ? (roots[i] * closest_dot_origin - dir_dot_origin) + : NO_INTERSECTION; +} diff --git a/fury/shaders/rt_odfs/srgb_to_linear.frag b/fury/shaders/rt_odfs/srgb_to_linear.frag new file mode 100644 index 000000000..78c765c20 --- /dev/null +++ b/fury/shaders/rt_odfs/srgb_to_linear.frag @@ -0,0 +1,4 @@ +float srgb_to_linear(float non_linear) +{ + return (non_linear <= 0.04045) ? ((1.0 / 12.92) * non_linear) : pow(non_linear * (1.0 / 1.055) + 0.055 / 1.055, 2.4); +} diff --git a/fury/shaders/rt_odfs/srgb_to_linear_rgb.frag b/fury/shaders/rt_odfs/srgb_to_linear_rgb.frag new file mode 100644 index 000000000..e4c2ef22a --- /dev/null +++ b/fury/shaders/rt_odfs/srgb_to_linear_rgb.frag @@ -0,0 +1,4 @@ +vec3 srgb_to_linear_rgb(vec3 srgb) +{ + return vec3(srgb_to_linear(srgb.r), srgb_to_linear(srgb.g), srgb_to_linear(srgb.b)); +} diff --git a/fury/shaders/rt_odfs/tonemap.frag b/fury/shaders/rt_odfs/tonemap.frag new file mode 100644 index 000000000..dd6cdcacb --- /dev/null +++ b/fury/shaders/rt_odfs/tonemap.frag @@ -0,0 +1,5 @@ +vec3 tonemap(vec3 linear) +{ + float max_channel = max(max(1.0, linear.r), max(linear.g, linear.b)); + return linear * ((1.0 - 0.02 * log2(max_channel)) / max_channel); +} diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_10.frag b/fury/shaders/rt_odfs/tournier/eval_sh_10.frag new file mode 100644 index 000000000..bac867d98 --- /dev/null +++ b/fury/shaders/rt_odfs/tournier/eval_sh_10.frag @@ -0,0 +1,175 @@ +void eval_sh_10(out float out_shs[66], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + b = z2 * a - 0.250980392 * b; + a = b - 0.250773994 * a; + d = 233.240148813 * a; + out_shs[55] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[22] = c1 * d; + out_shs[20] = s1 * d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[37] = c1 * d; + out_shs[35] = s1 * d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + out_shs[56] = c1 * d; + out_shs[54] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[23] = c0 * d; + out_shs[19] = s0 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[38] = c0 * d; + out_shs[34] = s0 * d; + b = z2 * a - 0.235294118 * b; + a = b - 0.238390093 * a; + d = 272.365814381 * a; + out_shs[57] = c0 * d; + out_shs[53] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[24] = c1 * d; + out_shs[18] = s1 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[39] = c1 * d; + out_shs[33] = s1 * d; + a = z2 * b - 0.215686275 * a; + b = a - 0.222910217 * b; + d = -213.661323441 * b; + out_shs[58] = c1 * d; + out_shs[52] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[25] = c0 * d; + out_shs[17] = s0 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[40] = c0 * d; + out_shs[32] = s0 * d; + b = z2 * a - 0.188235294 * b; + a = b - 0.20123839 * a; + d = 151.081370682 * a; + out_shs[59] = c0 * d; + out_shs[51] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[26] = c1 * d; + out_shs[16] = s1 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[41] = c1 * d; + out_shs[31] = s1 * d; + a = z2 * b - 0.152941176 * a; + b = a - 0.173374613 * b; + d = -95.552248675 * b; + out_shs[60] = c1 * d; + out_shs[50] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[27] = c0 * d; + out_shs[15] = s0 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[42] = c0 * d; + out_shs[30] = s0 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + out_shs[61] = c0 * d; + out_shs[49] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[43] = c1 * d; + out_shs[29] = s1 * d; + a = (z2 - 5.88235294e-02) * z; + b = a - 9.90712074e-02 * z; + d = -25.910241313 * b; + out_shs[62] = c1 * d; + out_shs[48] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[44] = c0 * d; + out_shs[28] = s0 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + out_shs[63] = c0 * d; + out_shs[47] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + out_shs[64] = c1 * d; + out_shs[46] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + out_shs[65] = c0 * d; + out_shs[45] = s0 * d; +} diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_12.frag b/fury/shaders/rt_odfs/tournier/eval_sh_12.frag new file mode 100644 index 000000000..3bad86fd4 --- /dev/null +++ b/fury/shaders/rt_odfs/tournier/eval_sh_12.frag @@ -0,0 +1,238 @@ +void eval_sh_12(out float out_shs[91], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + b = z2 * a - 0.250980392 * b; + a = b - 0.250773994 * a; + d = 233.240148813 * a; + out_shs[55] = d; + b = z2 * a - 0.250626566 * b; + a = b - 0.250517598 * a; + d = 931.186918633 * a; + out_shs[78] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[22] = c1 * d; + out_shs[20] = s1 * d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[37] = c1 * d; + out_shs[35] = s1 * d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + out_shs[56] = c1 * d; + out_shs[54] = s1 * d; + a = z2 * b - 0.248120301 * a; + b = a - 0.248447205 * b; + d = -1265.233874957 * b; + out_shs[79] = c1 * d; + out_shs[77] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[23] = c0 * d; + out_shs[19] = s0 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[38] = c0 * d; + out_shs[34] = s0 * d; + b = z2 * a - 0.235294118 * b; + a = b - 0.238390093 * a; + d = 272.365814381 * a; + out_shs[57] = c0 * d; + out_shs[53] = s0 * d; + b = z2 * a - 0.240601504 * b; + a = b - 0.242236025 * a; + d = 1121.509962433 * a; + out_shs[80] = c0 * d; + out_shs[76] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[24] = c1 * d; + out_shs[18] = s1 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[39] = c1 * d; + out_shs[33] = s1 * d; + a = z2 * b - 0.215686275 * a; + b = a - 0.222910217 * b; + d = -213.661323441 * b; + out_shs[58] = c1 * d; + out_shs[52] = s1 * d; + a = z2 * b - 0.228070175 * a; + b = a - 0.231884058 * b; + d = -915.709049803 * b; + out_shs[81] = c1 * d; + out_shs[75] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[25] = c0 * d; + out_shs[17] = s0 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[40] = c0 * d; + out_shs[32] = s0 * d; + b = z2 * a - 0.188235294 * b; + a = b - 0.20123839 * a; + d = 151.081370682 * a; + out_shs[59] = c0 * d; + out_shs[51] = s0 * d; + b = z2 * a - 0.210526316 * b; + a = b - 0.217391304 * a; + d = 686.781787352 * a; + out_shs[82] = c0 * d; + out_shs[74] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[26] = c1 * d; + out_shs[16] = s1 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[41] = c1 * d; + out_shs[31] = s1 * d; + a = z2 * b - 0.152941176 * a; + b = a - 0.173374613 * b; + d = -95.552248675 * b; + out_shs[60] = c1 * d; + out_shs[50] = s1 * d; + a = z2 * b - 0.187969925 * a; + b = a - 0.198757764 * b; + d = -471.12841933 * b; + out_shs[83] = c1 * d; + out_shs[73] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[27] = c0 * d; + out_shs[15] = s0 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[42] = c0 * d; + out_shs[30] = s0 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + out_shs[61] = c0 * d; + out_shs[49] = s0 * d; + b = z2 * a - 0.160401003 * b; + a = b - 0.175983437 * a; + d = 293.800188384 * a; + out_shs[84] = c0 * d; + out_shs[72] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[43] = c1 * d; + out_shs[29] = s1 * d; + a = (z2 - 5.88235294e-02) * z; + b = a - 9.90712074e-02 * z; + d = -25.910241313 * b; + out_shs[62] = c1 * d; + out_shs[48] = s1 * d; + a = z2 * b - 0.127819549 * a; + b = a - 0.149068323 * b; + d = -165.101452729 * b; + out_shs[85] = c1 * d; + out_shs[71] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[44] = c0 * d; + out_shs[28] = s0 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + out_shs[63] = c0 * d; + out_shs[47] = s0 * d; + b = z2 * (a - 9.02255639e-02); + a = b - 0.118012422 * a; + d = 82.550726364 * a; + out_shs[86] = c0 * d; + out_shs[70] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + out_shs[64] = c1 * d; + out_shs[46] = s1 * d; + a = (z2 - 4.76190476e-02) * z; + b = a - 8.2815735e-02 * z; + d = -36.028090689 * b; + out_shs[87] = c1 * d; + out_shs[69] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + out_shs[65] = c0 * d; + out_shs[45] = s0 * d; + a = z2 - 4.34782609e-02; + d = 13.3042542 * a; + out_shs[88] = c0 * d; + out_shs[68] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.923210529 * z; + out_shs[89] = c1 * d; + out_shs[67] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.800821996; + out_shs[90] = c0 * d; + out_shs[66] = s0 * d; +} diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_2.frag b/fury/shaders/rt_odfs/tournier/eval_sh_2.frag new file mode 100644 index 000000000..a70493a22 --- /dev/null +++ b/fury/shaders/rt_odfs/tournier/eval_sh_2.frag @@ -0,0 +1,23 @@ +void eval_sh_2(out float out_shs[6], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; +} diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_4.frag b/fury/shaders/rt_odfs/tournier/eval_sh_4.frag new file mode 100644 index 000000000..15335ccad --- /dev/null +++ b/fury/shaders/rt_odfs/tournier/eval_sh_4.frag @@ -0,0 +1,46 @@ +void eval_sh_4(out float out_shs[15], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; +} diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_6.frag b/fury/shaders/rt_odfs/tournier/eval_sh_6.frag new file mode 100644 index 000000000..1051361dd --- /dev/null +++ b/fury/shaders/rt_odfs/tournier/eval_sh_6.frag @@ -0,0 +1,79 @@ +void eval_sh_6(out float out_shs[28], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[22] = c1 * d; + out_shs[20] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[23] = c0 * d; + out_shs[19] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[24] = c1 * d; + out_shs[18] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[25] = c0 * d; + out_shs[17] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[26] = c1 * d; + out_shs[16] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[27] = c0 * d; + out_shs[15] = s0 * d; +} diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_8.frag b/fury/shaders/rt_odfs/tournier/eval_sh_8.frag new file mode 100644 index 000000000..93c32e613 --- /dev/null +++ b/fury/shaders/rt_odfs/tournier/eval_sh_8.frag @@ -0,0 +1,122 @@ +void eval_sh_8(out float out_shs[45], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[22] = c1 * d; + out_shs[20] = s1 * d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[37] = c1 * d; + out_shs[35] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[23] = c0 * d; + out_shs[19] = s0 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[38] = c0 * d; + out_shs[34] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[24] = c1 * d; + out_shs[18] = s1 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[39] = c1 * d; + out_shs[33] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[25] = c0 * d; + out_shs[17] = s0 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[40] = c0 * d; + out_shs[32] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[26] = c1 * d; + out_shs[16] = s1 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[41] = c1 * d; + out_shs[31] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[27] = c0 * d; + out_shs[15] = s0 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[42] = c0 * d; + out_shs[30] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[43] = c1 * d; + out_shs[29] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[44] = c0 * d; + out_shs[28] = s0 * d; +} diff --git a/fury/shaders/utils/minmax_norm.glsl b/fury/shaders/utils/minmax_norm.glsl new file mode 100644 index 000000000..7992b53c7 --- /dev/null +++ b/fury/shaders/utils/minmax_norm.glsl @@ -0,0 +1,4 @@ +float coeffsNorm(float coef, float min, float max, float a, float b) +{ + return (coef - min) * ((b - a) / (max - min)) + a; +} \ No newline at end of file From fbe7ed5542e4e362415777d68e43a3862ed4a379 Mon Sep 17 00:00:00 2001 From: tvcastillod Date: Fri, 23 Feb 2024 11:19:51 -0500 Subject: [PATCH 056/118] adjusted scaling --- docs/experimental/SH-ODF experimental/odf_example.py | 6 +----- fury/actor.py | 3 +++ 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/docs/experimental/SH-ODF experimental/odf_example.py b/docs/experimental/SH-ODF experimental/odf_example.py index 3b6c60469..e16858211 100644 --- a/docs/experimental/SH-ODF experimental/odf_example.py +++ b/docs/experimental/SH-ODF experimental/odf_example.py @@ -22,10 +22,6 @@ coeffs = coeffs[:, :, :].reshape((x * y * z, s)) n_glyphs = coeffs.shape[0] - max_val = coeffs.min(axis=1) - total = np.sum(abs(coeffs), axis=1) - coeffs = np.dot(np.diag(1 / total), coeffs) * 1.7 - - odf_actor = actor.odf(centers=centers, coeffs=coeffs) + odf_actor = actor.odf(centers=centers, coeffs=coeffs, scales=1.0) show_man.scene.add(odf_actor) show_man.start() \ No newline at end of file diff --git a/fury/actor.py b/fury/actor.py index ae71bb95e..cb630a365 100644 --- a/fury/actor.py +++ b/fury/actor.py @@ -3914,5 +3914,8 @@ def odf( elif scales.size != centers.shape[0]: scales = np.concatenate( (scales, np.ones(centers.shape[0] - scales.shape[0])), axis=None) + + total = np.sum(abs(coeffs), axis=1) + coeffs = np.dot(np.diag(1 / total * scales), coeffs) * 1.7 return sh_odf(centers, coeffs, basis_type, scales, opacity) \ No newline at end of file From 8c6b8fd66365ea938596b28c3f4b87b704e0481d Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Mon, 26 Feb 2024 14:10:41 -0500 Subject: [PATCH 057/118] Added ray_traced_7.0.py which includes an argument parser. --- .../SH-ODF experimental/ray_traced_7.0.py | 423 ++++++++++++++++++ 1 file changed, 423 insertions(+) create mode 100644 docs/experimental/SH-ODF experimental/ray_traced_7.0.py diff --git a/docs/experimental/SH-ODF experimental/ray_traced_7.0.py b/docs/experimental/SH-ODF experimental/ray_traced_7.0.py new file mode 100644 index 000000000..de281fd95 --- /dev/null +++ b/docs/experimental/SH-ODF experimental/ray_traced_7.0.py @@ -0,0 +1,423 @@ +""" +This script adds an argument parser to the ray_traced_6.0.py script. +""" + +import argparse +import os + +import numpy as np +from dipy.data.fetcher import dipy_home +from dipy.io.image import load_nifti + +from fury import actor, window +from fury.lib import FloatArray, Texture +from fury.shaders import ( + attribute_to_actor, + compose_shader, + import_fury_shader, + shader_to_actor, +) +from fury.utils import numpy_to_vtk_image_data, set_polydata_tcoords + + +def uv_calculations(n): + uvs = [] + for i in range(0, n): + a = (n - (i + 1)) / n + b = (n - i) / n + # glyph_coord [0, a], [0, b], [1, b], [1, a] + uvs.extend( + [ + [0.001, a + 0.001], + [0.001, b - 0.001], + [0.999, b - 0.001], + [0.999, a + 0.001], + [0.001, a + 0.001], + [0.001, b - 0.001], + [0.999, b - 0.001], + [0.999, a + 0.001], + ] + ) + return uvs + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument( + "file", help="Path to spherical harmonic coefficients file." + ) + args = parser.parse_args() + # print(args.file) + + show_man = window.ShowManager(size=(1280, 720)) + + coeffs, affine = load_nifti(args.file) + + valid_mask = np.abs(coeffs).max(axis=(-1)) > 0 + indices = np.nonzero(valid_mask) + + centers = np.asarray(indices).T + + x, y, z, s = coeffs.shape + coeffs = coeffs[:, :, :].reshape((x * y * z, s)) + n_glyphs = coeffs.shape[0] + + max_val = coeffs.min(axis=1) + total = np.sum(abs(coeffs), axis=1) + coeffs = np.dot(np.diag(1 / total), coeffs) * 1.7 + + odf_actor = actor.box(centers=centers, scales=1) + odf_actor.GetMapper().SetVBOShiftScaleMethod(False) + + big_centers = np.repeat(centers, 8, axis=0) + attribute_to_actor(odf_actor, big_centers, "center") + + minmax = np.array([coeffs.min(axis=1), coeffs.max(axis=1)]).T + big_minmax = np.repeat(minmax, 8, axis=0) + attribute_to_actor(odf_actor, big_minmax, "minmax") + + odf_actor_pd = odf_actor.GetMapper().GetInput() + + uv_vals = np.array(uv_calculations(n_glyphs)) + + num_pnts = uv_vals.shape[0] + + t_coords = FloatArray() + t_coords.SetNumberOfComponents(2) + t_coords.SetNumberOfTuples(num_pnts) + [t_coords.SetTuple(i, uv_vals[i]) for i in range(num_pnts)] + + set_polydata_tcoords(odf_actor_pd, t_coords) + + min = coeffs.min(axis=1) + max = coeffs.max(axis=1) + newmin = 0 + newmax = 1 + arr = np.array( + [ + (coeffs[i] - min[i]) * ((newmax - newmin) / (max[i] - min[i])) + + newmin + for i in range(coeffs.shape[0]) + ] + ) + arr *= 255 + grid = numpy_to_vtk_image_data(arr.astype(np.uint8)) + + texture = Texture() + texture.SetInputDataObject(grid) + texture.Update() + + odf_actor.GetProperty().SetTexture("texture0", texture) + + # TODO: Set int uniform + odf_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniformf( + "numCoeffs", 15 + ) + + vs_dec = """ + in vec3 center; + in vec2 minmax; + + out vec4 vertexMCVSOutput; + out vec3 centerMCVSOutput; + out vec2 minmaxVSOutput; + out vec3 camPosMCVSOutput; + out vec3 camRightMCVSOutput; + out vec3 camUpMCVSOutput; + """ + + vs_impl = """ + vertexMCVSOutput = vertexMC; + centerMCVSOutput = center; + minmaxVSOutput = minmax; + camPosMCVSOutput = -MCVCMatrix[3].xyz * mat3(MCVCMatrix); + camRightMCVSOutput = vec3( + MCVCMatrix[0][0], MCVCMatrix[1][0], MCVCMatrix[2][0]); + camUpMCVSOutput = vec3( + MCVCMatrix[0][1], MCVCMatrix[1][1], MCVCMatrix[2][1]); + """ + + shader_to_actor(odf_actor, "vertex", decl_code=vs_dec, impl_code=vs_impl) + + # The index of the highest used band of the spherical harmonics basis. Must + # be even, at least 2 and at most 12. + def_sh_degree = "#define SH_DEGREE 4" + + # The number of spherical harmonics basis functions + def_sh_count = "#define SH_COUNT (((SH_DEGREE + 1) * (SH_DEGREE + 2)) / 2)" + + # Degree of polynomials for which we have to find roots + def_max_degree = "#define MAX_DEGREE (2 * SH_DEGREE + 2)" + + # If GL_EXT_control_flow_attributes is available, these defines should be + # defined as [[unroll]] and [[loop]] to give reasonable hints to the + # compiler. That avoids register spilling, which makes execution + # considerably faster. + def_gl_ext_control_flow_attributes = """ + #ifndef _unroll_ + #define _unroll_ + #endif + #ifndef _loop_ + #define _loop_ + #endif + """ + + # When there are fewer intersections/roots than theoretically possible, + # some array entries are set to this value + def_no_intersection = "#define NO_INTERSECTION 3.4e38" + + # pi and its reciprocal + def_pis = """ + #define M_PI 3.141592653589793238462643 + #define M_INV_PI 0.318309886183790671537767526745 + """ + + fs_vs_vars = """ + in vec4 vertexMCVSOutput; + in vec3 centerMCVSOutput; + in vec2 minmaxVSOutput; + in vec3 camPosMCVSOutput; + in vec3 camRightMCVSOutput; + in vec3 camUpMCVSOutput; + """ + + coeffs_norm = """ + float coeffsNorm(float coef) + { + float min = 0; + float max = 1; + float newMin = minmaxVSOutput.x; + float newMax = minmaxVSOutput.y; + return (coef - min) * ((newMax - newMin) / (max - min)) + newMin; + } + """ + + eval_sh_2 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_2.frag")) + + eval_sh_4 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_4.frag")) + + eval_sh_6 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_6.frag")) + + eval_sh_8 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_8.frag")) + + eval_sh_10 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_10.frag")) + + eval_sh_12 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_12.frag")) + + eval_sh_grad_2 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_2.frag") + ) + + eval_sh_grad_4 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_4.frag") + ) + + eval_sh_grad_6 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_6.frag") + ) + + eval_sh_grad_8 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_8.frag") + ) + + eval_sh_grad_10 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_10.frag") + ) + + eval_sh_grad_12 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_12.frag") + ) + + # Searches a single root of a polynomial within a given interval. + # param out_root The location of the found root. + # param out_end_value The value of the given polynomial at end. + # param poly Coefficients of the polynomial for which a root should be + # found. + # Coefficient poly[i] is multiplied by x^i. + # param begin The beginning of an interval where the polynomial is + # monotonic. + # param end The end of said interval. + # param begin_value The value of the given polynomial at begin. + # param error_tolerance The error tolerance for the returned root + # location. + # Typically the error will be much lower but in theory it can be + # bigger. + # + # return true if a root was found, false if no root exists. + newton_bisection = import_fury_shader( + os.path.join("rt_odfs", "newton_bisection.frag") + ) + + # Finds all roots of the given polynomial in the interval [begin, end] and + # writes them to out_roots. Some entries will be NO_INTERSECTION but other + # than that the array is sorted. The last entry is always NO_INTERSECTION. + find_roots = import_fury_shader(os.path.join("rt_odfs", "find_roots.frag")) + + # Evaluates the spherical harmonics basis in bands 0, 2, ..., SH_DEGREE. + # Conventions are as in the following paper. + # M. Descoteaux, E. Angelino, S. Fitzgibbons, and R. Deriche. Regularized, + # fast, and robust analytical q-ball imaging. Magnetic Resonance in + # Medicine, 58(3), 2007. https://doi.org/10.1002/mrm.21277 + # param out_shs Values of SH basis functions in bands 0, 2, ..., + # SH_DEGREE in this order. + # param point The point on the unit sphere where the basis should be + # evaluated. + eval_sh = import_fury_shader(os.path.join("rt_odfs", "eval_sh.frag")) + + # Evaluates the gradient of each basis function given by eval_sh() and the + # basis itself + eval_sh_grad = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad.frag") + ) + + # Outputs a matrix that turns equidistant samples on the unit circle of a + # homogeneous polynomial into coefficients of that polynomial. + get_inv_vandermonde = import_fury_shader( + os.path.join("rt_odfs", "get_inv_vandermonde.frag") + ) + + # Determines all intersections between a ray and a spherical harmonics + # glyph. + # param out_ray_params The ray parameters at intersection points. The + # points themselves are at ray_origin + out_ray_params[i] * ray_dir. + # Some entries may be NO_INTERSECTION but other than that the array + # is sorted. + # param sh_coeffs SH_COUNT spherical harmonic coefficients defining the + # glyph. Their exact meaning is defined by eval_sh(). + # param ray_origin The origin of the ray, relative to the glyph center. + # param ray_dir The normalized direction vector of the ray. + ray_sh_glyph_intersections = import_fury_shader( + os.path.join("rt_odfs", "ray_sh_glyph_intersections.frag") + ) + + # Provides a normalized normal vector for a spherical harmonics glyph. + # param sh_coeffs SH_COUNT spherical harmonic coefficients defining the + # glyph. Their exact meaning is defined by eval_sh(). + # param point A point on the surface of the glyph, relative to its + # center. + # + # return A normalized surface normal pointing away from the origin. + get_sh_glyph_normal = import_fury_shader( + os.path.join("rt_odfs", "get_sh_glyph_normal.frag") + ) + + # Applies the non-linearity that maps linear RGB to sRGB + linear_to_srgb = import_fury_shader( + os.path.join("rt_odfs", "linear_to_srgb.frag") + ) + + # Inverse of linear_to_srgb() + srgb_to_linear = import_fury_shader( + os.path.join("rt_odfs", "srgb_to_linear.frag") + ) + + # Turns a linear RGB color (i.e. rec. 709) into sRGB + linear_rgb_to_srgb = import_fury_shader( + os.path.join("rt_odfs", "linear_rgb_to_srgb.frag") + ) + + # Inverse of linear_rgb_to_srgb() + srgb_to_linear_rgb = import_fury_shader( + os.path.join("rt_odfs", "srgb_to_linear_rgb.frag") + ) + + # Logarithmic tonemapping operator. Input and output are linear RGB. + tonemap = import_fury_shader(os.path.join("rt_odfs", "tonemap.frag")) + + # Blinn-Phong illumination model + blinn_phong_model = import_fury_shader( + os.path.join("lighting", "blinn_phong_model.frag") + ) + + # fmt: off + fs_dec = compose_shader([ + def_sh_degree, def_sh_count, def_max_degree, + def_gl_ext_control_flow_attributes, def_no_intersection, def_pis, + fs_vs_vars, coeffs_norm, eval_sh_2, eval_sh_4, eval_sh_6, eval_sh_8, + eval_sh_10, eval_sh_12, eval_sh_grad_2, eval_sh_grad_4, eval_sh_grad_6, + eval_sh_grad_8, eval_sh_grad_10, eval_sh_grad_12, newton_bisection, + find_roots, eval_sh, eval_sh_grad, get_inv_vandermonde, + ray_sh_glyph_intersections, get_sh_glyph_normal, blinn_phong_model, + linear_to_srgb, srgb_to_linear, linear_rgb_to_srgb, srgb_to_linear_rgb, + tonemap + ]) + # fmt: on + + shader_to_actor(odf_actor, "fragment", decl_code=fs_dec) + + point_from_vs = "vec3 pnt = vertexMCVSOutput.xyz;" + + # Ray origin is the camera position in world space + ray_origin = "vec3 ro = camPosMCVSOutput;" + + # TODO: Check aspect for automatic scaling + # Ray direction is the normalized difference between the fragment and the + # camera position/ray origin + ray_direction = "vec3 rd = normalize(pnt - ro);" + + # Light direction in a retroreflective model is the normalized difference + # between the camera position/ray origin and the fragment + light_direction = "vec3 ld = normalize(ro - pnt);" + + # Define SH coefficients (measured up to band 8, noise beyond that) + sh_coeffs = """ + float i = 1 / (numCoeffs * 2); + float sh_coeffs[SH_COUNT]; + for(int j=0; j 0.0) { + first_ray_param = ray_params[i]; + break; + } + } + """ + + # Evaluate shading for a directional light + directional_light = """ + vec3 color = vec3(1.); + if (first_ray_param != NO_INTERSECTION) { + vec3 intersection = ro - centerMCVSOutput + first_ray_param * rd; + vec3 normal = get_sh_glyph_normal(sh_coeffs, intersection); + vec3 colorDir = srgb_to_linear_rgb(abs(normalize(intersection))); + float attenuation = dot(ld, normal); + color = blinnPhongIllumModel( + //attenuation, lightColor0, diffuseColor, specularPower, + attenuation, lightColor0, colorDir, specularPower, + specularColor, ambientColor); + } else { + discard; + } + """ + + frag_output = """ + //vec4 out_color = vec4(linear_rgb_to_srgb(tonemap(color)), 1.0); + vec3 out_color = linear_rgb_to_srgb(tonemap(color)); + fragOutput0 = vec4(out_color, opacity); + //fragOutput0 = vec4(color, opacity); + """ + + # fmt: off + fs_impl = compose_shader([ + point_from_vs, ray_origin, ray_direction, light_direction, sh_coeffs, + intersection_test, first_intersection, directional_light, frag_output + ]) + # fmt: on + + shader_to_actor(odf_actor, "fragment", impl_code=fs_impl, block="picking") + show_man.scene.add(odf_actor) + + show_man.start() From bfd4b01f6708239517b713189a434177ddd39e2d Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Mon, 26 Feb 2024 15:52:07 -0500 Subject: [PATCH 058/118] Added DIPY's ODF slicer python script with argument parser for profiling tool. --- .../SH-ODF experimental/dipy_slicer.py | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 docs/experimental/SH-ODF experimental/dipy_slicer.py diff --git a/docs/experimental/SH-ODF experimental/dipy_slicer.py b/docs/experimental/SH-ODF experimental/dipy_slicer.py new file mode 100644 index 000000000..35c8e12fc --- /dev/null +++ b/docs/experimental/SH-ODF experimental/dipy_slicer.py @@ -0,0 +1,65 @@ +""" +This script adds an argument parser to the ray_traced_6.0.py script. +""" + +import argparse +import os + +import numpy as np +from dipy.data import get_sphere +from dipy.io.image import load_nifti +from dipy.reconst.shm import sh_to_sf + +from fury import actor, window + + +def uv_calculations(n): + uvs = [] + for i in range(0, n): + a = (n - (i + 1)) / n + b = (n - i) / n + # glyph_coord [0, a], [0, b], [1, b], [1, a] + uvs.extend( + [ + [0.001, a + 0.001], + [0.001, b - 0.001], + [0.999, b - 0.001], + [0.999, a + 0.001], + [0.001, a + 0.001], + [0.001, b - 0.001], + [0.999, b - 0.001], + [0.999, a + 0.001], + ] + ) + return uvs + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument( + "file", help="Path to spherical harmonic coefficients file." + ) + args = parser.parse_args() + + show_man = window.ShowManager(size=(1280, 720)) + + coeffs, affine = load_nifti(args.file) + + sphere = get_sphere("repulsion724") + + sh_basis = "tournier07" + sh_order = 8 + + tensor_sf = sh_to_sf( + coeffs, + sh_order=sh_order, + basis_type=sh_basis, + sphere=sphere, + legacy=False, + ) + + odf_slicer_actor = actor.odf_slicer(tensor_sf, sphere=sphere, scale=0.5) + + show_man.scene.add(odf_slicer_actor) + + show_man.start() From 1438b84fa7fa8b2742e1156c7bcc30bebc309943 Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Mon, 26 Feb 2024 16:03:52 -0500 Subject: [PATCH 059/118] Minor changes to ray_traced_7.0.py --- docs/experimental/SH-ODF experimental/ray_traced_7.0.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/experimental/SH-ODF experimental/ray_traced_7.0.py b/docs/experimental/SH-ODF experimental/ray_traced_7.0.py index de281fd95..c4cad1999 100644 --- a/docs/experimental/SH-ODF experimental/ray_traced_7.0.py +++ b/docs/experimental/SH-ODF experimental/ray_traced_7.0.py @@ -6,7 +6,6 @@ import os import numpy as np -from dipy.data.fetcher import dipy_home from dipy.io.image import load_nifti from fury import actor, window @@ -111,7 +110,7 @@ def uv_calculations(n): # TODO: Set int uniform odf_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniformf( - "numCoeffs", 15 + "numCoeffs", coeffs.shape[-1] ) vs_dec = """ @@ -141,7 +140,7 @@ def uv_calculations(n): # The index of the highest used band of the spherical harmonics basis. Must # be even, at least 2 and at most 12. - def_sh_degree = "#define SH_DEGREE 4" + def_sh_degree = "#define SH_DEGREE 8" # The number of spherical harmonics basis functions def_sh_count = "#define SH_COUNT (((SH_DEGREE + 1) * (SH_DEGREE + 2)) / 2)" From 644b4fe9644e227a2a37b57e7b928a4118cab56d Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Mon, 26 Feb 2024 18:27:46 -0500 Subject: [PATCH 060/118] Renamed experimental folder. --- .../{SH-ODF experimental => SH-ODF_experimental}/README.md | 0 .../{SH-ODF experimental => SH-ODF_experimental}/colormapping.py | 0 .../{SH-ODF experimental => SH-ODF_experimental}/dipy_slicer.py | 0 .../direction_scaling.py | 0 .../{SH-ODF experimental => SH-ODF_experimental}/eff_sh.py | 0 .../ray_traced_1.0.py | 0 .../ray_traced_2.0.py | 0 .../ray_traced_3.0.py | 0 .../ray_traced_4.0.py | 0 .../ray_traced_5.0.py | 0 .../ray_traced_5.5.py | 0 .../ray_traced_6.0.py | 0 .../ray_traced_7.0.py | 0 .../texture_coefficients.py | 0 .../texture_data_test.py | 0 15 files changed, 0 insertions(+), 0 deletions(-) rename docs/experimental/{SH-ODF experimental => SH-ODF_experimental}/README.md (100%) rename docs/experimental/{SH-ODF experimental => SH-ODF_experimental}/colormapping.py (100%) rename docs/experimental/{SH-ODF experimental => SH-ODF_experimental}/dipy_slicer.py (100%) rename docs/experimental/{SH-ODF experimental => SH-ODF_experimental}/direction_scaling.py (100%) rename docs/experimental/{SH-ODF experimental => SH-ODF_experimental}/eff_sh.py (100%) rename docs/experimental/{SH-ODF experimental => SH-ODF_experimental}/ray_traced_1.0.py (100%) rename docs/experimental/{SH-ODF experimental => SH-ODF_experimental}/ray_traced_2.0.py (100%) rename docs/experimental/{SH-ODF experimental => SH-ODF_experimental}/ray_traced_3.0.py (100%) rename docs/experimental/{SH-ODF experimental => SH-ODF_experimental}/ray_traced_4.0.py (100%) rename docs/experimental/{SH-ODF experimental => SH-ODF_experimental}/ray_traced_5.0.py (100%) rename docs/experimental/{SH-ODF experimental => SH-ODF_experimental}/ray_traced_5.5.py (100%) rename docs/experimental/{SH-ODF experimental => SH-ODF_experimental}/ray_traced_6.0.py (100%) rename docs/experimental/{SH-ODF experimental => SH-ODF_experimental}/ray_traced_7.0.py (100%) rename docs/experimental/{SH-ODF experimental => SH-ODF_experimental}/texture_coefficients.py (100%) rename docs/experimental/{SH-ODF experimental => SH-ODF_experimental}/texture_data_test.py (100%) diff --git a/docs/experimental/SH-ODF experimental/README.md b/docs/experimental/SH-ODF_experimental/README.md similarity index 100% rename from docs/experimental/SH-ODF experimental/README.md rename to docs/experimental/SH-ODF_experimental/README.md diff --git a/docs/experimental/SH-ODF experimental/colormapping.py b/docs/experimental/SH-ODF_experimental/colormapping.py similarity index 100% rename from docs/experimental/SH-ODF experimental/colormapping.py rename to docs/experimental/SH-ODF_experimental/colormapping.py diff --git a/docs/experimental/SH-ODF experimental/dipy_slicer.py b/docs/experimental/SH-ODF_experimental/dipy_slicer.py similarity index 100% rename from docs/experimental/SH-ODF experimental/dipy_slicer.py rename to docs/experimental/SH-ODF_experimental/dipy_slicer.py diff --git a/docs/experimental/SH-ODF experimental/direction_scaling.py b/docs/experimental/SH-ODF_experimental/direction_scaling.py similarity index 100% rename from docs/experimental/SH-ODF experimental/direction_scaling.py rename to docs/experimental/SH-ODF_experimental/direction_scaling.py diff --git a/docs/experimental/SH-ODF experimental/eff_sh.py b/docs/experimental/SH-ODF_experimental/eff_sh.py similarity index 100% rename from docs/experimental/SH-ODF experimental/eff_sh.py rename to docs/experimental/SH-ODF_experimental/eff_sh.py diff --git a/docs/experimental/SH-ODF experimental/ray_traced_1.0.py b/docs/experimental/SH-ODF_experimental/ray_traced_1.0.py similarity index 100% rename from docs/experimental/SH-ODF experimental/ray_traced_1.0.py rename to docs/experimental/SH-ODF_experimental/ray_traced_1.0.py diff --git a/docs/experimental/SH-ODF experimental/ray_traced_2.0.py b/docs/experimental/SH-ODF_experimental/ray_traced_2.0.py similarity index 100% rename from docs/experimental/SH-ODF experimental/ray_traced_2.0.py rename to docs/experimental/SH-ODF_experimental/ray_traced_2.0.py diff --git a/docs/experimental/SH-ODF experimental/ray_traced_3.0.py b/docs/experimental/SH-ODF_experimental/ray_traced_3.0.py similarity index 100% rename from docs/experimental/SH-ODF experimental/ray_traced_3.0.py rename to docs/experimental/SH-ODF_experimental/ray_traced_3.0.py diff --git a/docs/experimental/SH-ODF experimental/ray_traced_4.0.py b/docs/experimental/SH-ODF_experimental/ray_traced_4.0.py similarity index 100% rename from docs/experimental/SH-ODF experimental/ray_traced_4.0.py rename to docs/experimental/SH-ODF_experimental/ray_traced_4.0.py diff --git a/docs/experimental/SH-ODF experimental/ray_traced_5.0.py b/docs/experimental/SH-ODF_experimental/ray_traced_5.0.py similarity index 100% rename from docs/experimental/SH-ODF experimental/ray_traced_5.0.py rename to docs/experimental/SH-ODF_experimental/ray_traced_5.0.py diff --git a/docs/experimental/SH-ODF experimental/ray_traced_5.5.py b/docs/experimental/SH-ODF_experimental/ray_traced_5.5.py similarity index 100% rename from docs/experimental/SH-ODF experimental/ray_traced_5.5.py rename to docs/experimental/SH-ODF_experimental/ray_traced_5.5.py diff --git a/docs/experimental/SH-ODF experimental/ray_traced_6.0.py b/docs/experimental/SH-ODF_experimental/ray_traced_6.0.py similarity index 100% rename from docs/experimental/SH-ODF experimental/ray_traced_6.0.py rename to docs/experimental/SH-ODF_experimental/ray_traced_6.0.py diff --git a/docs/experimental/SH-ODF experimental/ray_traced_7.0.py b/docs/experimental/SH-ODF_experimental/ray_traced_7.0.py similarity index 100% rename from docs/experimental/SH-ODF experimental/ray_traced_7.0.py rename to docs/experimental/SH-ODF_experimental/ray_traced_7.0.py diff --git a/docs/experimental/SH-ODF experimental/texture_coefficients.py b/docs/experimental/SH-ODF_experimental/texture_coefficients.py similarity index 100% rename from docs/experimental/SH-ODF experimental/texture_coefficients.py rename to docs/experimental/SH-ODF_experimental/texture_coefficients.py diff --git a/docs/experimental/SH-ODF experimental/texture_data_test.py b/docs/experimental/SH-ODF_experimental/texture_data_test.py similarity index 100% rename from docs/experimental/SH-ODF experimental/texture_data_test.py rename to docs/experimental/SH-ODF_experimental/texture_data_test.py From fc85cd64a3d2c749d137d76438670f475130b6c7 Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Tue, 27 Feb 2024 12:16:17 -0500 Subject: [PATCH 061/118] Changed basis to Tournier's. --- .../SH-ODF_experimental/ray_traced_7.0.py | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/docs/experimental/SH-ODF_experimental/ray_traced_7.0.py b/docs/experimental/SH-ODF_experimental/ray_traced_7.0.py index c4cad1999..0302d8834 100644 --- a/docs/experimental/SH-ODF_experimental/ray_traced_7.0.py +++ b/docs/experimental/SH-ODF_experimental/ray_traced_7.0.py @@ -191,17 +191,29 @@ def uv_calculations(n): } """ - eval_sh_2 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_2.frag")) + eval_sh_2 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_2 copy.frag") + ) - eval_sh_4 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_4.frag")) + eval_sh_4 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_4 copy.frag") + ) - eval_sh_6 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_6.frag")) + eval_sh_6 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_6 copy.frag") + ) - eval_sh_8 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_8.frag")) + eval_sh_8 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_8 copy.frag") + ) - eval_sh_10 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_10.frag")) + eval_sh_10 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_10 copy.frag") + ) - eval_sh_12 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_12.frag")) + eval_sh_12 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_12 copy.frag") + ) eval_sh_grad_2 = import_fury_shader( os.path.join("rt_odfs", "eval_sh_grad_2.frag") From 97f1d9300b896fef634d2b86b0ce1ac67cffd6e7 Mon Sep 17 00:00:00 2001 From: tvcastillod Date: Tue, 27 Feb 2024 13:01:14 -0500 Subject: [PATCH 062/118] reorganized files --- fury/actors/odf.py | 24 +- .../linear_rgb_to_srgb.frag | 0 .../{rt_odfs => lighting}/linear_to_srgb.frag | 0 .../{rt_odfs => lighting}/srgb_to_linear.frag | 0 .../srgb_to_linear_rgb.frag | 0 .../{ => descoteaux}/eval_sh_grad_10.frag | 0 .../{ => descoteaux}/eval_sh_grad_12.frag | 0 .../{ => descoteaux}/eval_sh_grad_2.frag | 0 .../{ => descoteaux}/eval_sh_grad_4.frag | 0 .../{ => descoteaux}/eval_sh_grad_6.frag | 0 .../{ => descoteaux}/eval_sh_grad_8.frag | 0 .../tournier/eval_sh_grad_10 copy.frag | 430 +++++++++++++ .../tournier/eval_sh_grad_12 copy.frag | 591 ++++++++++++++++++ .../rt_odfs/tournier/eval_sh_grad_2 copy.frag | 46 ++ .../rt_odfs/tournier/eval_sh_grad_4 copy.frag | 103 +++ .../rt_odfs/tournier/eval_sh_grad_6 copy.frag | 186 ++++++ .../rt_odfs/tournier/eval_sh_grad_8 copy.frag | 295 +++++++++ .../{rt_odfs => utils}/find_roots.frag | 0 .../{rt_odfs => utils}/newton_bisection.frag | 0 19 files changed, 1663 insertions(+), 12 deletions(-) rename fury/shaders/{rt_odfs => lighting}/linear_rgb_to_srgb.frag (100%) rename fury/shaders/{rt_odfs => lighting}/linear_to_srgb.frag (100%) rename fury/shaders/{rt_odfs => lighting}/srgb_to_linear.frag (100%) rename fury/shaders/{rt_odfs => lighting}/srgb_to_linear_rgb.frag (100%) rename fury/shaders/rt_odfs/{ => descoteaux}/eval_sh_grad_10.frag (100%) rename fury/shaders/rt_odfs/{ => descoteaux}/eval_sh_grad_12.frag (100%) rename fury/shaders/rt_odfs/{ => descoteaux}/eval_sh_grad_2.frag (100%) rename fury/shaders/rt_odfs/{ => descoteaux}/eval_sh_grad_4.frag (100%) rename fury/shaders/rt_odfs/{ => descoteaux}/eval_sh_grad_6.frag (100%) rename fury/shaders/rt_odfs/{ => descoteaux}/eval_sh_grad_8.frag (100%) create mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_grad_10 copy.frag create mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_grad_12 copy.frag create mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_grad_2 copy.frag create mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_grad_4 copy.frag create mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_grad_6 copy.frag create mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_grad_8 copy.frag rename fury/shaders/{rt_odfs => utils}/find_roots.frag (100%) rename fury/shaders/{rt_odfs => utils}/newton_bisection.frag (100%) diff --git a/fury/actors/odf.py b/fury/actors/odf.py index a6d991033..e8a762c55 100644 --- a/fury/actors/odf.py +++ b/fury/actors/odf.py @@ -206,27 +206,27 @@ def sh_odf(centers, coeffs, basis_type, scales, opacity): os.path.join("rt_odfs", basis_type, "eval_sh_12.frag")) eval_sh_grad_2 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_2.frag") + os.path.join("rt_odfs/descoteaux", "eval_sh_grad_2.frag") ) eval_sh_grad_4 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_4.frag") + os.path.join("rt_odfs/descoteaux", "eval_sh_grad_4.frag") ) eval_sh_grad_6 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_6.frag") + os.path.join("rt_odfs/descoteaux", "eval_sh_grad_6.frag") ) eval_sh_grad_8 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_8.frag") + os.path.join("rt_odfs/descoteaux", "eval_sh_grad_8.frag") ) eval_sh_grad_10 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_10.frag") + os.path.join("rt_odfs/descoteaux", "eval_sh_grad_10.frag") ) eval_sh_grad_12 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_12.frag") + os.path.join("rt_odfs/descoteaux", "eval_sh_grad_12.frag") ) # Searches a single root of a polynomial within a given interval. @@ -246,13 +246,13 @@ def sh_odf(centers, coeffs, basis_type, scales, opacity): # # return true if a root was found, false if no root exists. newton_bisection = import_fury_shader( - os.path.join("rt_odfs", "newton_bisection.frag") + os.path.join("utils", "newton_bisection.frag") ) # Finds all roots of the given polynomial in the interval [begin, end] and # writes them to out_roots. Some entries will be NO_INTERSECTION but other # than that the array is sorted. The last entry is always NO_INTERSECTION. - find_roots = import_fury_shader(os.path.join("rt_odfs", "find_roots.frag")) + find_roots = import_fury_shader(os.path.join("utils", "find_roots.frag")) # Evaluates the spherical harmonics basis in bands 0, 2, ..., SH_DEGREE. # Conventions are as in the following paper. @@ -304,22 +304,22 @@ def sh_odf(centers, coeffs, basis_type, scales, opacity): # Applies the non-linearity that maps linear RGB to sRGB linear_to_srgb = import_fury_shader( - os.path.join("rt_odfs", "linear_to_srgb.frag") + os.path.join("lighting", "linear_to_srgb.frag") ) # Inverse of linear_to_srgb() srgb_to_linear = import_fury_shader( - os.path.join("rt_odfs", "srgb_to_linear.frag") + os.path.join("lighting", "srgb_to_linear.frag") ) # Turns a linear RGB color (i.e. rec. 709) into sRGB linear_rgb_to_srgb = import_fury_shader( - os.path.join("rt_odfs", "linear_rgb_to_srgb.frag") + os.path.join("lighting", "linear_rgb_to_srgb.frag") ) # Inverse of linear_rgb_to_srgb() srgb_to_linear_rgb = import_fury_shader( - os.path.join("rt_odfs", "srgb_to_linear_rgb.frag") + os.path.join("lighting", "srgb_to_linear_rgb.frag") ) # Logarithmic tonemapping operator. Input and output are linear RGB. diff --git a/fury/shaders/rt_odfs/linear_rgb_to_srgb.frag b/fury/shaders/lighting/linear_rgb_to_srgb.frag similarity index 100% rename from fury/shaders/rt_odfs/linear_rgb_to_srgb.frag rename to fury/shaders/lighting/linear_rgb_to_srgb.frag diff --git a/fury/shaders/rt_odfs/linear_to_srgb.frag b/fury/shaders/lighting/linear_to_srgb.frag similarity index 100% rename from fury/shaders/rt_odfs/linear_to_srgb.frag rename to fury/shaders/lighting/linear_to_srgb.frag diff --git a/fury/shaders/rt_odfs/srgb_to_linear.frag b/fury/shaders/lighting/srgb_to_linear.frag similarity index 100% rename from fury/shaders/rt_odfs/srgb_to_linear.frag rename to fury/shaders/lighting/srgb_to_linear.frag diff --git a/fury/shaders/rt_odfs/srgb_to_linear_rgb.frag b/fury/shaders/lighting/srgb_to_linear_rgb.frag similarity index 100% rename from fury/shaders/rt_odfs/srgb_to_linear_rgb.frag rename to fury/shaders/lighting/srgb_to_linear_rgb.frag diff --git a/fury/shaders/rt_odfs/eval_sh_grad_10.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_10.frag similarity index 100% rename from fury/shaders/rt_odfs/eval_sh_grad_10.frag rename to fury/shaders/rt_odfs/descoteaux/eval_sh_grad_10.frag diff --git a/fury/shaders/rt_odfs/eval_sh_grad_12.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_12.frag similarity index 100% rename from fury/shaders/rt_odfs/eval_sh_grad_12.frag rename to fury/shaders/rt_odfs/descoteaux/eval_sh_grad_12.frag diff --git a/fury/shaders/rt_odfs/eval_sh_grad_2.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_2.frag similarity index 100% rename from fury/shaders/rt_odfs/eval_sh_grad_2.frag rename to fury/shaders/rt_odfs/descoteaux/eval_sh_grad_2.frag diff --git a/fury/shaders/rt_odfs/eval_sh_grad_4.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_4.frag similarity index 100% rename from fury/shaders/rt_odfs/eval_sh_grad_4.frag rename to fury/shaders/rt_odfs/descoteaux/eval_sh_grad_4.frag diff --git a/fury/shaders/rt_odfs/eval_sh_grad_6.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_6.frag similarity index 100% rename from fury/shaders/rt_odfs/eval_sh_grad_6.frag rename to fury/shaders/rt_odfs/descoteaux/eval_sh_grad_6.frag diff --git a/fury/shaders/rt_odfs/eval_sh_grad_8.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_8.frag similarity index 100% rename from fury/shaders/rt_odfs/eval_sh_grad_8.frag rename to fury/shaders/rt_odfs/descoteaux/eval_sh_grad_8.frag diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_10 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_10 copy.frag new file mode 100644 index 000000000..c9e6b0d8d --- /dev/null +++ b/fury/shaders/rt_odfs/tournier/eval_sh_grad_10 copy.frag @@ -0,0 +1,430 @@ +void eval_sh_grad_10(out float out_shs[66], out vec3 out_grads[66], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + b = z2 * a - 0.250980392 * b; + a = b - 0.250773994 * a; + d = 233.240148813 * a; + out_shs[55] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + out_grads[4][0] = c0 * d; + out_grads[2][0] = s0 * d; + out_grads[4][1] = s0 * d; + out_grads[2][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + out_grads[11][0] = c0 * d; + out_grads[9][0] = s0 * d; + out_grads[11][1] = s0 * d; + out_grads[9][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[22] = c1 * d; + out_shs[20] = s1 * d; + out_grads[22][0] = c0 * d; + out_grads[20][0] = s0 * d; + out_grads[22][1] = s0 * d; + out_grads[20][1] = c0 * d; + d = 88.106914343 * b; + out_grads[21][2] = d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[37] = c1 * d; + out_shs[35] = s1 * d; + out_grads[37][0] = c0 * d; + out_grads[35][0] = s0 * d; + out_grads[37][1] = s0 * d; + out_grads[35][1] = c0 * d; + d = 467.786944906 * b; + out_grads[36][2] = d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + out_shs[56] = c1 * d; + out_shs[54] = s1 * d; + out_grads[56][0] = c0 * d; + out_grads[54][0] = s0 * d; + out_grads[56][1] = s0 * d; + out_grads[54][1] = c0 * d; + d = 2332.401488133 * b; + out_grads[55][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + d = 1.092548431; + out_grads[5][0] = c1 * d; + out_grads[1][0] = s1 * d; + out_grads[5][1] = -s1 * d; + out_grads[1][1] = c1 * d; + d = -1.092548431; + out_grads[4][2] = c1 * d; + out_grads[2][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + d = 6.62322287 * a; + out_grads[12][0] = c1 * d; + out_grads[8][0] = s1 * d; + out_grads[12][1] = -s1 * d; + out_grads[8][1] = c1 * d; + d = -14.049977415 * a; + out_grads[11][2] = c1 * d; + out_grads[9][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[23] = c0 * d; + out_shs[19] = s0 * d; + d = 30.399773564 * a; + out_grads[23][0] = c1 * d; + out_grads[19][0] = s1 * d; + out_grads[23][1] = -s1 * d; + out_grads[19][1] = c1 * d; + d = -96.132524816 * a; + out_grads[22][2] = c1 * d; + out_grads[20][2] = s1 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[38] = c0 * d; + out_shs[34] = s0 * d; + d = 130.459545912 * a; + out_grads[38][0] = c1 * d; + out_grads[34][0] = s1 * d; + out_grads[38][1] = -s1 * d; + out_grads[34][1] = c1 * d; + d = -545.751435723 * a; + out_grads[37][2] = c1 * d; + out_grads[35][2] = s1 * d; + b = z2 * a - 0.235294118 * b; + a = b - 0.238390093 * a; + d = 272.365814381 * a; + out_shs[57] = c0 * d; + out_shs[53] = s0 * d; + d = 544.731628762 * a; + out_grads[57][0] = c1 * d; + out_grads[53][0] = s1 * d; + out_grads[57][1] = -s1 * d; + out_grads[53][1] = c1 * d; + d = -2830.508572514 * a; + out_grads[56][2] = c1 * d; + out_grads[54][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; + d = -5.310392309 * z; + out_grads[13][0] = c0 * d; + out_grads[7][0] = s0 * d; + out_grads[13][1] = s0 * d; + out_grads[7][1] = c0 * d; + d = 6.62322287 * z; + out_grads[12][2] = c0 * d; + out_grads[8][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[24] = c1 * d; + out_shs[18] = s1 * d; + d = -30.399773564 * b; + out_grads[24][0] = c0 * d; + out_grads[18][0] = s0 * d; + out_grads[24][1] = s0 * d; + out_grads[18][1] = c0 * d; + d = 60.799547128 * b; + out_grads[23][2] = c0 * d; + out_grads[19][2] = s0 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[39] = c1 * d; + out_shs[33] = s1 * d; + d = -144.52614017 * b; + out_grads[39][0] = c0 * d; + out_grads[33][0] = s0 * d; + out_grads[39][1] = s0 * d; + out_grads[33][1] = c0 * d; + d = 391.378637737 * b; + out_grads[38][2] = c0 * d; + out_grads[34][2] = s0 * d; + a = z2 * b - 0.215686275 * a; + b = a - 0.222910217 * b; + d = -213.661323441 * b; + out_shs[58] = c1 * d; + out_shs[52] = s1 * d; + d = -640.983970322 * b; + out_grads[58][0] = c0 * d; + out_grads[52][0] = s0 * d; + out_grads[58][1] = s0 * d; + out_grads[52][1] = c0 * d; + d = 2178.926515046 * b; + out_grads[57][2] = c0 * d; + out_grads[53][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; + d = 2.503342942; + out_grads[14][0] = c1 * d; + out_grads[6][0] = s1 * d; + out_grads[14][1] = -s1 * d; + out_grads[6][1] = c1 * d; + d = -1.77013077; + out_grads[13][2] = c1 * d; + out_grads[7][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[25] = c0 * d; + out_shs[17] = s0 * d; + d = 22.200855632 * a; + out_grads[25][0] = c1 * d; + out_grads[17][0] = s1 * d; + out_grads[25][1] = -s1 * d; + out_grads[17][1] = c1 * d; + d = -30.399773564 * a; + out_grads[24][2] = c1 * d; + out_grads[18][2] = s1 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[40] = c0 * d; + out_shs[32] = s0 * d; + d = 124.388296437 * a; + out_grads[40][0] = c1 * d; + out_grads[32][0] = s1 * d; + out_grads[40][1] = -s1 * d; + out_grads[32][1] = c1 * d; + d = -240.876900283 * a; + out_grads[39][2] = c1 * d; + out_grads[33][2] = s1 * d; + b = z2 * a - 0.188235294 * b; + a = b - 0.20123839 * a; + d = 151.081370682 * a; + out_shs[59] = c0 * d; + out_shs[51] = s0 * d; + d = 604.325482728 * a; + out_grads[59][0] = c1 * d; + out_grads[51][0] = s1 * d; + out_grads[59][1] = -s1 * d; + out_grads[51][1] = c1 * d; + d = -1495.629264084 * a; + out_grads[58][2] = c1 * d; + out_grads[52][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[26] = c1 * d; + out_shs[16] = s1 * d; + d = -11.833095811 * z; + out_grads[26][0] = c0 * d; + out_grads[16][0] = s0 * d; + out_grads[26][1] = s0 * d; + out_grads[16][1] = c0 * d; + d = 11.100427816 * z; + out_grads[25][2] = c0 * d; + out_grads[17][2] = s0 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[41] = c1 * d; + out_shs[31] = s1 * d; + d = -86.247765552 * b; + out_grads[41][0] = c0 * d; + out_grads[31][0] = s0 * d; + out_grads[41][1] = s0 * d; + out_grads[31][1] = c0 * d; + d = 124.388296437 * b; + out_grads[40][2] = c0 * d; + out_grads[32][2] = s0 * d; + a = z2 * b - 0.152941176 * a; + b = a - 0.173374613 * b; + d = -95.552248675 * b; + out_shs[60] = c1 * d; + out_shs[50] = s1 * d; + d = -477.761243376 * b; + out_grads[60][0] = c0 * d; + out_grads[50][0] = s0 * d; + out_grads[60][1] = s0 * d; + out_grads[50][1] = c0 * d; + d = 906.488224092 * b; + out_grads[59][2] = c0 * d; + out_grads[51][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[27] = c0 * d; + out_shs[15] = s0 * d; + d = 4.099104631; + out_grads[27][0] = c1 * d; + out_grads[15][0] = s1 * d; + out_grads[27][1] = -s1 * d; + out_grads[15][1] = c1 * d; + d = -2.366619162; + out_grads[26][2] = c1 * d; + out_grads[16][2] = s1 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[42] = c0 * d; + out_shs[30] = s0 * d; + d = 47.909948945 * a; + out_grads[42][0] = c1 * d; + out_grads[30][0] = s1 * d; + out_grads[42][1] = -s1 * d; + out_grads[30][1] = c1 * d; + d = -51.748659331 * a; + out_grads[41][2] = c1 * d; + out_grads[31][2] = s1 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + out_shs[61] = c0 * d; + out_shs[49] = s0 * d; + d = 320.491985161 * a; + out_grads[61][0] = c1 * d; + out_grads[49][0] = s1 * d; + out_grads[61][1] = -s1 * d; + out_grads[49][1] = c1 * d; + d = -477.761243376 * a; + out_grads[60][2] = c1 * d; + out_grads[50][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[43] = c1 * d; + out_shs[29] = s1 * d; + d = -20.409946485 * z; + out_grads[43][0] = c0 * d; + out_grads[29][0] = s0 * d; + out_grads[43][1] = s0 * d; + out_grads[29][1] = c0 * d; + d = 15.969982982 * z; + out_grads[42][2] = c0 * d; + out_grads[30][2] = s0 * d; + a = (z2 - 5.88235294e-02) * z; + b = a - 9.90712074e-02 * z; + d = -25.910241313 * b; + out_shs[62] = c1 * d; + out_shs[48] = s1 * d; + d = -181.371689194 * b; + out_grads[62][0] = c0 * d; + out_grads[48][0] = s0 * d; + out_grads[62][1] = s0 * d; + out_grads[48][1] = c0 * d; + d = 213.661323441 * b; + out_grads[61][2] = c0 * d; + out_grads[49][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[44] = c0 * d; + out_shs[28] = s0 * d; + d = 5.831413281; + out_grads[44][0] = c1 * d; + out_grads[28][0] = s1 * d; + out_grads[44][1] = -s1 * d; + out_grads[28][1] = c1 * d; + d = -2.915706641; + out_grads[43][2] = c1 * d; + out_grads[29][2] = s1 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + out_shs[63] = c0 * d; + out_shs[47] = s0 * d; + d = 84.622493774 * a; + out_grads[63][0] = c1 * d; + out_grads[47][0] = s1 * d; + out_grads[63][1] = -s1 * d; + out_grads[47][1] = c1 * d; + d = -77.73072394 * a; + out_grads[62][2] = c1 * d; + out_grads[48][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + out_shs[64] = c1 * d; + out_shs[46] = s1 * d; + d = -30.887057699 * z; + out_grads[64][0] = c0 * d; + out_grads[46][0] = s0 * d; + out_grads[64][1] = s0 * d; + out_grads[46][1] = c0 * d; + d = 21.155623443 * z; + out_grads[63][2] = c0 * d; + out_grads[47][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + out_shs[65] = c0 * d; + out_shs[45] = s0 * d; + d = 7.673951182; + out_grads[65][0] = c1 * d; + out_grads[45][0] = s1 * d; + out_grads[65][1] = -s1 * d; + out_grads[45][1] = c1 * d; + d = -3.4318953; + out_grads[64][2] = c1 * d; + out_grads[46][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; + out_grads[6][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[14][2] = 0.0; + out_grads[15][2] = 0.0; + out_grads[21][0] = 0.0; + out_grads[21][1] = 0.0; + out_grads[27][2] = 0.0; + out_grads[28][2] = 0.0; + out_grads[36][0] = 0.0; + out_grads[36][1] = 0.0; + out_grads[44][2] = 0.0; + out_grads[45][2] = 0.0; + out_grads[55][0] = 0.0; + out_grads[55][1] = 0.0; + out_grads[65][2] = 0.0; +} diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_12 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_12 copy.frag new file mode 100644 index 000000000..35c2a3617 --- /dev/null +++ b/fury/shaders/rt_odfs/tournier/eval_sh_grad_12 copy.frag @@ -0,0 +1,591 @@ +void eval_sh_grad_12(out float out_shs[91], out vec3 out_grads[91], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + b = z2 * a - 0.250980392 * b; + a = b - 0.250773994 * a; + d = 233.240148813 * a; + out_shs[55] = d; + b = z2 * a - 0.250626566 * b; + a = b - 0.250517598 * a; + d = 931.186918633 * a; + out_shs[78] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + out_grads[4][0] = c0 * d; + out_grads[2][0] = s0 * d; + out_grads[4][1] = s0 * d; + out_grads[2][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + out_grads[11][0] = c0 * d; + out_grads[9][0] = s0 * d; + out_grads[11][1] = s0 * d; + out_grads[9][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[22] = c1 * d; + out_shs[20] = s1 * d; + out_grads[22][0] = c0 * d; + out_grads[20][0] = s0 * d; + out_grads[22][1] = s0 * d; + out_grads[20][1] = c0 * d; + d = 88.106914343 * b; + out_grads[21][2] = d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[37] = c1 * d; + out_shs[35] = s1 * d; + out_grads[37][0] = c0 * d; + out_grads[35][0] = s0 * d; + out_grads[37][1] = s0 * d; + out_grads[35][1] = c0 * d; + d = 467.786944906 * b; + out_grads[36][2] = d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + out_shs[56] = c1 * d; + out_shs[54] = s1 * d; + out_grads[56][0] = c0 * d; + out_grads[54][0] = s0 * d; + out_grads[56][1] = s0 * d; + out_grads[54][1] = c0 * d; + d = 2332.401488133 * b; + out_grads[55][2] = d; + a = z2 * b - 0.248120301 * a; + b = a - 0.248447205 * b; + d = -1265.233874957 * b; + out_shs[79] = c1 * d; + out_shs[77] = s1 * d; + out_grads[79][0] = c0 * d; + out_grads[77][0] = s0 * d; + out_grads[79][1] = s0 * d; + out_grads[77][1] = c0 * d; + d = 11174.243023595 * b; + out_grads[78][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + d = 1.092548431; + out_grads[5][0] = c1 * d; + out_grads[1][0] = s1 * d; + out_grads[5][1] = -s1 * d; + out_grads[1][1] = c1 * d; + d = -1.092548431; + out_grads[4][2] = c1 * d; + out_grads[2][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + d = 6.62322287 * a; + out_grads[12][0] = c1 * d; + out_grads[8][0] = s1 * d; + out_grads[12][1] = -s1 * d; + out_grads[8][1] = c1 * d; + d = -14.049977415 * a; + out_grads[11][2] = c1 * d; + out_grads[9][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[23] = c0 * d; + out_shs[19] = s0 * d; + d = 30.399773564 * a; + out_grads[23][0] = c1 * d; + out_grads[19][0] = s1 * d; + out_grads[23][1] = -s1 * d; + out_grads[19][1] = c1 * d; + d = -96.132524816 * a; + out_grads[22][2] = c1 * d; + out_grads[20][2] = s1 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[38] = c0 * d; + out_shs[34] = s0 * d; + d = 130.459545912 * a; + out_grads[38][0] = c1 * d; + out_grads[34][0] = s1 * d; + out_grads[38][1] = -s1 * d; + out_grads[34][1] = c1 * d; + d = -545.751435723 * a; + out_grads[37][2] = c1 * d; + out_grads[35][2] = s1 * d; + b = z2 * a - 0.235294118 * b; + a = b - 0.238390093 * a; + d = 272.365814381 * a; + out_shs[57] = c0 * d; + out_shs[53] = s0 * d; + d = 544.731628762 * a; + out_grads[57][0] = c1 * d; + out_grads[53][0] = s1 * d; + out_grads[57][1] = -s1 * d; + out_grads[53][1] = c1 * d; + d = -2830.508572514 * a; + out_grads[56][2] = c1 * d; + out_grads[54][2] = s1 * d; + b = z2 * a - 0.240601504 * b; + a = b - 0.242236025 * a; + d = 1121.509962433 * a; + out_shs[80] = c0 * d; + out_shs[76] = s0 * d; + d = 2243.019924866 * a; + out_grads[80][0] = c1 * d; + out_grads[76][0] = s1 * d; + out_grads[80][1] = -s1 * d; + out_grads[76][1] = c1 * d; + d = -13917.572624524 * a; + out_grads[79][2] = c1 * d; + out_grads[77][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; + d = -5.310392309 * z; + out_grads[13][0] = c0 * d; + out_grads[7][0] = s0 * d; + out_grads[13][1] = s0 * d; + out_grads[7][1] = c0 * d; + d = 6.62322287 * z; + out_grads[12][2] = c0 * d; + out_grads[8][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[24] = c1 * d; + out_shs[18] = s1 * d; + d = -30.399773564 * b; + out_grads[24][0] = c0 * d; + out_grads[18][0] = s0 * d; + out_grads[24][1] = s0 * d; + out_grads[18][1] = c0 * d; + d = 60.799547128 * b; + out_grads[23][2] = c0 * d; + out_grads[19][2] = s0 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[39] = c1 * d; + out_shs[33] = s1 * d; + d = -144.52614017 * b; + out_grads[39][0] = c0 * d; + out_grads[33][0] = s0 * d; + out_grads[39][1] = s0 * d; + out_grads[33][1] = c0 * d; + d = 391.378637737 * b; + out_grads[38][2] = c0 * d; + out_grads[34][2] = s0 * d; + a = z2 * b - 0.215686275 * a; + b = a - 0.222910217 * b; + d = -213.661323441 * b; + out_shs[58] = c1 * d; + out_shs[52] = s1 * d; + d = -640.983970322 * b; + out_grads[58][0] = c0 * d; + out_grads[52][0] = s0 * d; + out_grads[58][1] = s0 * d; + out_grads[52][1] = c0 * d; + d = 2178.926515046 * b; + out_grads[57][2] = c0 * d; + out_grads[53][2] = s0 * d; + a = z2 * b - 0.228070175 * a; + b = a - 0.231884058 * b; + d = -915.709049803 * b; + out_shs[81] = c1 * d; + out_shs[75] = s1 * d; + d = -2747.127149409 * b; + out_grads[81][0] = c0 * d; + out_grads[75][0] = s0 * d; + out_grads[81][1] = s0 * d; + out_grads[75][1] = c0 * d; + d = 11215.099624332 * b; + out_grads[80][2] = c0 * d; + out_grads[76][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; + d = 2.503342942; + out_grads[14][0] = c1 * d; + out_grads[6][0] = s1 * d; + out_grads[14][1] = -s1 * d; + out_grads[6][1] = c1 * d; + d = -1.77013077; + out_grads[13][2] = c1 * d; + out_grads[7][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[25] = c0 * d; + out_shs[17] = s0 * d; + d = 22.200855632 * a; + out_grads[25][0] = c1 * d; + out_grads[17][0] = s1 * d; + out_grads[25][1] = -s1 * d; + out_grads[17][1] = c1 * d; + d = -30.399773564 * a; + out_grads[24][2] = c1 * d; + out_grads[18][2] = s1 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[40] = c0 * d; + out_shs[32] = s0 * d; + d = 124.388296437 * a; + out_grads[40][0] = c1 * d; + out_grads[32][0] = s1 * d; + out_grads[40][1] = -s1 * d; + out_grads[32][1] = c1 * d; + d = -240.876900283 * a; + out_grads[39][2] = c1 * d; + out_grads[33][2] = s1 * d; + b = z2 * a - 0.188235294 * b; + a = b - 0.20123839 * a; + d = 151.081370682 * a; + out_shs[59] = c0 * d; + out_shs[51] = s0 * d; + d = 604.325482728 * a; + out_grads[59][0] = c1 * d; + out_grads[51][0] = s1 * d; + out_grads[59][1] = -s1 * d; + out_grads[51][1] = c1 * d; + d = -1495.629264084 * a; + out_grads[58][2] = c1 * d; + out_grads[52][2] = s1 * d; + b = z2 * a - 0.210526316 * b; + a = b - 0.217391304 * a; + d = 686.781787352 * a; + out_shs[82] = c0 * d; + out_shs[74] = s0 * d; + d = 2747.127149409 * a; + out_grads[82][0] = c1 * d; + out_grads[74][0] = s1 * d; + out_grads[82][1] = -s1 * d; + out_grads[74][1] = c1 * d; + d = -8241.381448228 * a; + out_grads[81][2] = -c1 * d; + out_grads[75][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[26] = c1 * d; + out_shs[16] = s1 * d; + d = -11.833095811 * z; + out_grads[26][0] = c0 * d; + out_grads[16][0] = s0 * d; + out_grads[26][1] = s0 * d; + out_grads[16][1] = c0 * d; + d = 11.100427816 * z; + out_grads[25][2] = c0 * d; + out_grads[17][2] = s0 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[41] = c1 * d; + out_shs[31] = s1 * d; + d = -86.247765552 * b; + out_grads[41][0] = c0 * d; + out_grads[31][0] = s0 * d; + out_grads[41][1] = s0 * d; + out_grads[31][1] = c0 * d; + d = 124.388296437 * b; + out_grads[40][2] = c0 * d; + out_grads[32][2] = s0 * d; + a = z2 * b - 0.152941176 * a; + b = a - 0.173374613 * b; + d = -95.552248675 * b; + out_shs[60] = c1 * d; + out_shs[50] = s1 * d; + d = -477.761243376 * b; + out_grads[60][0] = c0 * d; + out_grads[50][0] = s0 * d; + out_grads[60][1] = s0 * d; + out_grads[50][1] = c0 * d; + d = 906.488224092 * b; + out_grads[59][2] = c0 * d; + out_grads[51][2] = s0 * d; + a = z2 * b - 0.187969925 * a; + b = a - 0.198757764 * b; + d = -471.12841933 * b; + out_shs[83] = c1 * d; + out_shs[73] = s1 * d; + d = -2355.642096651 * b; + out_grads[83][0] = c0 * d; + out_grads[73][0] = s0 * d; + out_grads[83][1] = s0 * d; + out_grads[73][1] = c0 * d; + d = 5494.254298819 * b; + out_grads[82][2] = c0 * d; + out_grads[74][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[27] = c0 * d; + out_shs[15] = s0 * d; + d = 4.099104631; + out_grads[27][0] = c1 * d; + out_grads[15][0] = s1 * d; + out_grads[27][1] = -s1 * d; + out_grads[15][1] = c1 * d; + d = -2.366619162; + out_grads[26][2] = c1 * d; + out_grads[16][2] = s1 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[42] = c0 * d; + out_shs[30] = s0 * d; + d = 47.909948945 * a; + out_grads[42][0] = c1 * d; + out_grads[30][0] = s1 * d; + out_grads[42][1] = -s1 * d; + out_grads[30][1] = c1 * d; + d = -51.748659331 * a; + out_grads[41][2] = c1 * d; + out_grads[31][2] = s1 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + out_shs[61] = c0 * d; + out_shs[49] = s0 * d; + d = 320.491985161 * a; + out_grads[61][0] = c1 * d; + out_grads[49][0] = s1 * d; + out_grads[61][1] = -s1 * d; + out_grads[49][1] = c1 * d; + d = -477.761243376 * a; + out_grads[60][2] = c1 * d; + out_grads[50][2] = s1 * d; + b = z2 * a - 0.160401003 * b; + a = b - 0.175983437 * a; + d = 293.800188384 * a; + out_shs[84] = c0 * d; + out_shs[72] = s0 * d; + d = 1762.801130306 * a; + out_grads[84][0] = c1 * d; + out_grads[72][0] = s1 * d; + out_grads[84][1] = -s1 * d; + out_grads[72][1] = c1 * d; + d = -3297.898935312 * a; + out_grads[83][2] = c1 * d; + out_grads[73][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[43] = c1 * d; + out_shs[29] = s1 * d; + d = -20.409946485 * z; + out_grads[43][0] = c0 * d; + out_grads[29][0] = s0 * d; + out_grads[43][1] = s0 * d; + out_grads[29][1] = c0 * d; + d = 15.969982982 * z; + out_grads[42][2] = c0 * d; + out_grads[30][2] = s0 * d; + a = (z2 - 5.88235294e-02) * z; + b = a - 9.90712074e-02 * z; + d = -25.910241313 * b; + out_shs[62] = c1 * d; + out_shs[48] = s1 * d; + d = -181.371689194 * b; + out_grads[62][0] = c0 * d; + out_grads[48][0] = s0 * d; + out_grads[62][1] = s0 * d; + out_grads[48][1] = c0 * d; + d = 213.661323441 * b; + out_grads[61][2] = c0 * d; + out_grads[49][2] = s0 * d; + a = z2 * b - 0.127819549 * a; + b = a - 0.149068323 * b; + d = -165.101452729 * b; + out_shs[85] = c1 * d; + out_shs[71] = s1 * d; + d = -1155.7101691 * b; + out_grads[85][0] = c0 * d; + out_grads[71][0] = s0 * d; + out_grads[85][1] = s0 * d; + out_grads[71][1] = c0 * d; + d = 1762.801130306 * b; + out_grads[84][2] = c0 * d; + out_grads[72][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[44] = c0 * d; + out_shs[28] = s0 * d; + d = 5.831413281; + out_grads[44][0] = c1 * d; + out_grads[28][0] = s1 * d; + out_grads[44][1] = -s1 * d; + out_grads[28][1] = c1 * d; + d = -2.915706641; + out_grads[43][2] = c1 * d; + out_grads[29][2] = s1 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + out_shs[63] = c0 * d; + out_shs[47] = s0 * d; + d = 84.622493774 * a; + out_grads[63][0] = c1 * d; + out_grads[47][0] = s1 * d; + out_grads[63][1] = -s1 * d; + out_grads[47][1] = c1 * d; + d = -77.73072394 * a; + out_grads[62][2] = c1 * d; + out_grads[48][2] = s1 * d; + b = z2 * (a - 9.02255639e-02); + a = b - 0.118012422 * a; + d = 82.550726364 * a; + out_shs[86] = c0 * d; + out_shs[70] = s0 * d; + d = 660.405810914 * a; + out_grads[86][0] = c1 * d; + out_grads[70][0] = s1 * d; + out_grads[86][1] = -s1 * d; + out_grads[70][1] = c1 * d; + d = -825.507263643 * a; + out_grads[85][2] = c1 * d; + out_grads[71][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + out_shs[64] = c1 * d; + out_shs[46] = s1 * d; + d = -30.887057699 * z; + out_grads[64][0] = c0 * d; + out_grads[46][0] = s0 * d; + out_grads[64][1] = s0 * d; + out_grads[46][1] = c0 * d; + d = 21.155623443 * z; + out_grads[63][2] = c0 * d; + out_grads[47][2] = s0 * d; + a = (z2 - 4.76190476e-02) * z; + b = a - 8.2815735e-02 * z; + d = -36.028090689 * b; + out_shs[87] = c1 * d; + out_shs[69] = s1 * d; + d = -324.252816204 * b; + out_grads[87][0] = c0 * d; + out_grads[69][0] = s0 * d; + out_grads[87][1] = s0 * d; + out_grads[69][1] = c0 * d; + d = 330.202905457 * b; + out_grads[86][2] = c0 * d; + out_grads[70][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + out_shs[65] = c0 * d; + out_shs[45] = s0 * d; + d = 7.673951182; + out_grads[65][0] = c1 * d; + out_grads[45][0] = s1 * d; + out_grads[65][1] = -s1 * d; + out_grads[45][1] = c1 * d; + d = -3.4318953; + out_grads[64][2] = c1 * d; + out_grads[46][2] = s1 * d; + a = z2 - 4.34782609e-02; + d = 13.3042542 * a; + out_shs[88] = c0 * d; + out_shs[68] = s0 * d; + d = 133.042542003 * a; + out_grads[88][0] = c1 * d; + out_grads[68][0] = s1 * d; + out_grads[88][1] = -s1 * d; + out_grads[68][1] = c1 * d; + d = -108.084272068 * a; + out_grads[87][2] = c1 * d; + out_grads[69][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.923210529 * z; + out_shs[89] = c1 * d; + out_shs[67] = s1 * d; + d = -43.155315818 * z; + out_grads[89][0] = c0 * d; + out_grads[67][0] = s0 * d; + out_grads[89][1] = s0 * d; + out_grads[67][1] = c0 * d; + d = 26.608508401 * z; + out_grads[88][2] = c0 * d; + out_grads[68][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.800821996; + out_shs[90] = c0 * d; + out_shs[66] = s0 * d; + d = 9.609863949; + out_grads[90][0] = c1 * d; + out_grads[66][0] = s1 * d; + out_grads[90][1] = -s1 * d; + out_grads[66][1] = c1 * d; + d = -3.923210529; + out_grads[89][2] = c1 * d; + out_grads[67][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; + out_grads[6][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[14][2] = 0.0; + out_grads[15][2] = 0.0; + out_grads[21][0] = 0.0; + out_grads[21][1] = 0.0; + out_grads[27][2] = 0.0; + out_grads[28][2] = 0.0; + out_grads[36][0] = 0.0; + out_grads[36][1] = 0.0; + out_grads[44][2] = 0.0; + out_grads[45][2] = 0.0; + out_grads[55][0] = 0.0; + out_grads[55][1] = 0.0; + out_grads[65][2] = 0.0; + out_grads[66][2] = 0.0; + out_grads[78][0] = 0.0; + out_grads[78][1] = 0.0; + out_grads[90][2] = 0.0; +} diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_2 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_2 copy.frag new file mode 100644 index 000000000..277a0e07a --- /dev/null +++ b/fury/shaders/rt_odfs/tournier/eval_sh_grad_2 copy.frag @@ -0,0 +1,46 @@ +void eval_sh_grad_2(out float out_shs[6], out vec3 out_grads[6], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + out_grads[4][0] = c0 * d; + out_grads[2][0] = s0 * d; + out_grads[4][1] = s0 * d; + out_grads[2][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + d = 1.092548431; + out_grads[1][0] = c1 * d; + out_grads[5][0] = s1 * d; + out_grads[5][1] = -s1 * d; + out_grads[1][1] = c1 * d; + d = -1.092548431; + out_grads[4][2] = c1 * d; + out_grads[2][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[5][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[1][2] = 0.0; +} diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_4 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_4 copy.frag new file mode 100644 index 000000000..c85847a5b --- /dev/null +++ b/fury/shaders/rt_odfs/tournier/eval_sh_grad_4 copy.frag @@ -0,0 +1,103 @@ +void eval_sh_grad_4(out float out_shs[15], out vec3 out_grads[15], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + out_grads[4][0] = c0 * d; + out_grads[2][0] = s0 * d; + out_grads[4][1] = s0 * d; + out_grads[2][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + out_grads[11][0] = c0 * d; + out_grads[9][0] = s0 * d; + out_grads[11][1] = s0 * d; + out_grads[9][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + d = 1.092548431; + out_grads[5][0] = c1 * d; + out_grads[1][0] = s1 * d; + out_grads[5][1] = -s1 * d; + out_grads[1][1] = c1 * d; + d = -1.092548431; + out_grads[4][2] = c1 * d; + out_grads[2][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + d = 6.62322287 * a; + out_grads[12][0] = c1 * d; + out_grads[8][0] = s1 * d; + out_grads[12][1] = -s1 * d; + out_grads[8][1] = c1 * d; + d = -14.049977415 * a; + out_grads[11][2] = c1 * d; + out_grads[9][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; + d = -5.310392309 * z; + out_grads[13][0] = c0 * d; + out_grads[7][0] = s0 * d; + out_grads[13][1] = s0 * d; + out_grads[7][1] = c0 * d; + d = 6.62322287 * z; + out_grads[12][2] = c0 * d; + out_grads[8][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; + d = 2.503342942; + out_grads[14][0] = c1 * d; + out_grads[6][0] = s1 * d; + out_grads[14][1] = -s1 * d; + out_grads[6][1] = c1 * d; + d = -1.77013077; + out_grads[13][2] = c1 * d; + out_grads[7][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[5][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[1][2] = 0.0; + out_grads[14][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[6][2] = 0.0; +} diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_6 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_6 copy.frag new file mode 100644 index 000000000..617413bc9 --- /dev/null +++ b/fury/shaders/rt_odfs/tournier/eval_sh_grad_6 copy.frag @@ -0,0 +1,186 @@ +void eval_sh_grad_6(out float out_shs[28], out vec3 out_grads[28], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + out_grads[4][0] = c0 * d; + out_grads[2][0] = s0 * d; + out_grads[4][1] = s0 * d; + out_grads[2][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + out_grads[11][0] = c0 * d; + out_grads[9][0] = s0 * d; + out_grads[11][1] = s0 * d; + out_grads[9][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[22] = c1 * d; + out_shs[20] = s1 * d; + out_grads[22][0] = c0 * d; + out_grads[20][0] = s0 * d; + out_grads[22][1] = s0 * d; + out_grads[20][1] = c0 * d; + d = 88.106914343 * b; + out_grads[21][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + d = 1.092548431; + out_grads[5][0] = c1 * d; + out_grads[1][0] = s1 * d; + out_grads[5][1] = -s1 * d; + out_grads[1][1] = c1 * d; + d = -1.092548431; + out_grads[4][2] = c1 * d; + out_grads[2][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + d = 6.62322287 * a; + out_grads[12][0] = c1 * d; + out_grads[8][0] = s1 * d; + out_grads[12][1] = -s1 * d; + out_grads[8][1] = c1 * d; + d = -14.049977415 * a; + out_grads[11][2] = c1 * d; + out_grads[9][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[23] = c0 * d; + out_shs[19] = s0 * d; + d = 30.399773564 * a; + out_grads[23][0] = c1 * d; + out_grads[19][0] = s1 * d; + out_grads[23][1] = -s1 * d; + out_grads[19][1] = c1 * d; + d = -96.132524816 * a; + out_grads[22][2] = c1 * d; + out_grads[20][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; + d = -5.310392309 * z; + out_grads[13][0] = c0 * d; + out_grads[7][0] = s0 * d; + out_grads[13][1] = s0 * d; + out_grads[7][1] = c0 * d; + d = 6.62322287 * z; + out_grads[12][2] = c0 * d; + out_grads[8][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[24] = c1 * d; + out_shs[18] = s1 * d; + d = -30.399773564 * b; + out_grads[24][0] = c0 * d; + out_grads[18][0] = s0 * d; + out_grads[24][1] = s0 * d; + out_grads[18][1] = c0 * d; + d = 60.799547128 * b; + out_grads[23][2] = c0 * d; + out_grads[19][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; + d = 2.503342942; + out_grads[14][0] = c1 * d; + out_grads[6][0] = s1 * d; + out_grads[14][1] = -s1 * d; + out_grads[6][1] = c1 * d; + d = -1.77013077; + out_grads[13][2] = c1 * d; + out_grads[7][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[25] = c0 * d; + out_shs[17] = s0 * d; + d = 22.200855632 * a; + out_grads[25][0] = c1 * d; + out_grads[17][0] = s1 * d; + out_grads[25][1] = -s1 * d; + out_grads[17][1] = c1 * d; + d = -30.399773564 * a; + out_grads[24][2] = c1 * d; + out_grads[18][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[26] = c1 * d; + out_shs[16] = s1 * d; + d = -11.833095811 * z; + out_grads[26][0] = c0 * d; + out_grads[16][0] = s0 * d; + out_grads[26][1] = s0 * d; + out_grads[16][1] = c0 * d; + d = 11.100427816 * z; + out_grads[25][2] = c0 * d; + out_grads[17][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[27] = c0 * d; + out_shs[15] = s0 * d; + d = 4.099104631; + out_grads[27][0] = c1 * d; + out_grads[15][0] = s1 * d; + out_grads[27][1] = -s1 * d; + out_grads[15][1] = c1 * d; + d = -2.366619162; + out_grads[26][2] = c1 * d; + out_grads[16][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[5][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[1][2] = 0.0; + out_grads[14][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[6][2] = 0.0; + out_grads[27][2] = 0.0; + out_grads[21][0] = 0.0; + out_grads[21][1] = 0.0; + out_grads[15][2] = 0.0; +} diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_8 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_8 copy.frag new file mode 100644 index 000000000..712b2dc29 --- /dev/null +++ b/fury/shaders/rt_odfs/tournier/eval_sh_grad_8 copy.frag @@ -0,0 +1,295 @@ +void eval_sh_grad_8(out float out_shs[45], out vec3 out_grads[45], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + out_grads[4][0] = c0 * d; + out_grads[2][0] = s0 * d; + out_grads[4][1] = s0 * d; + out_grads[2][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + out_grads[11][0] = c0 * d; + out_grads[9][0] = s0 * d; + out_grads[11][1] = s0 * d; + out_grads[9][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[22] = c1 * d; + out_shs[20] = s1 * d; + out_grads[22][0] = c0 * d; + out_grads[20][0] = s0 * d; + out_grads[22][1] = s0 * d; + out_grads[20][1] = c0 * d; + d = 88.106914343 * b; + out_grads[21][2] = d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[37] = c1 * d; + out_shs[35] = s1 * d; + out_grads[37][0] = c0 * d; + out_grads[35][0] = s0 * d; + out_grads[37][1] = s0 * d; + out_grads[35][1] = c0 * d; + d = 467.786944906 * b; + out_grads[36][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + d = 1.092548431; + out_grads[5][0] = c1 * d; + out_grads[1][0] = s1 * d; + out_grads[5][1] = -s1 * d; + out_grads[1][1] = c1 * d; + d = -1.092548431; + out_grads[4][2] = c1 * d; + out_grads[2][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + d = 6.62322287 * a; + out_grads[12][0] = c1 * d; + out_grads[8][0] = s1 * d; + out_grads[12][1] = -s1 * d; + out_grads[8][1] = c1 * d; + d = -14.049977415 * a; + out_grads[11][2] = c1 * d; + out_grads[9][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[23] = c0 * d; + out_shs[19] = s0 * d; + d = 30.399773564 * a; + out_grads[23][0] = c1 * d; + out_grads[19][0] = s1 * d; + out_grads[23][1] = -s1 * d; + out_grads[19][1] = c1 * d; + d = -96.132524816 * a; + out_grads[22][2] = c1 * d; + out_grads[20][2] = s1 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[38] = c0 * d; + out_shs[34] = s0 * d; + d = 130.459545912 * a; + out_grads[38][0] = c1 * d; + out_grads[34][0] = s1 * d; + out_grads[38][1] = -s1 * d; + out_grads[34][1] = c1 * d; + d = -545.751435723 * a; + out_grads[37][2] = c1 * d; + out_grads[35][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; + d = -5.310392309 * z; + out_grads[13][0] = c0 * d; + out_grads[7][0] = s0 * d; + out_grads[13][1] = s0 * d; + out_grads[7][1] = c0 * d; + d = 6.62322287 * z; + out_grads[12][2] = c0 * d; + out_grads[8][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[24] = c1 * d; + out_shs[18] = s1 * d; + d = -30.399773564 * b; + out_grads[24][0] = c0 * d; + out_grads[18][0] = s0 * d; + out_grads[24][1] = s0 * d; + out_grads[18][1] = c0 * d; + d = 60.799547128 * b; + out_grads[23][2] = c0 * d; + out_grads[19][2] = s0 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[39] = c1 * d; + out_shs[33] = s1 * d; + d = -144.52614017 * b; + out_grads[39][0] = c0 * d; + out_grads[33][0] = s0 * d; + out_grads[39][1] = s0 * d; + out_grads[33][1] = c0 * d; + d = 391.378637737 * b; + out_grads[38][2] = c0 * d; + out_grads[34][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; + d = 2.503342942; + out_grads[14][0] = c1 * d; + out_grads[6][0] = s1 * d; + out_grads[14][1] = -s1 * d; + out_grads[6][1] = c1 * d; + d = -1.77013077; + out_grads[13][2] = c1 * d; + out_grads[7][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[25] = c0 * d; + out_shs[17] = s0 * d; + d = 22.200855632 * a; + out_grads[25][0] = c1 * d; + out_grads[17][0] = s1 * d; + out_grads[25][1] = -s1 * d; + out_grads[17][1] = c1 * d; + d = -30.399773564 * a; + out_grads[24][2] = c1 * d; + out_grads[18][2] = s1 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[40] = c0 * d; + out_shs[32] = s0 * d; + d = 124.388296437 * a; + out_grads[40][0] = c1 * d; + out_grads[32][0] = s1 * d; + out_grads[40][1] = -s1 * d; + out_grads[32][1] = c1 * d; + d = -240.876900283 * a; + out_grads[39][2] = c1 * d; + out_grads[33][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[26] = c1 * d; + out_shs[16] = s1 * d; + d = -11.833095811 * z; + out_grads[26][0] = c0 * d; + out_grads[16][0] = s0 * d; + out_grads[26][1] = s0 * d; + out_grads[16][1] = c0 * d; + d = 11.100427816 * z; + out_grads[25][2] = c0 * d; + out_grads[17][2] = s0 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[41] = c1 * d; + out_shs[31] = s1 * d; + d = -86.247765552 * b; + out_grads[41][0] = c0 * d; + out_grads[31][0] = s0 * d; + out_grads[41][1] = s0 * d; + out_grads[31][1] = c0 * d; + d = 124.388296437 * b; + out_grads[40][2] = c0 * d; + out_grads[32][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[27] = c0 * d; + out_shs[15] = s0 * d; + d = 4.099104631; + out_grads[27][0] = c1 * d; + out_grads[15][0] = s1 * d; + out_grads[27][1] = -s1 * d; + out_grads[15][1] = c1 * d; + d = -2.366619162; + out_grads[26][2] = c1 * d; + out_grads[16][2] = s1 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[42] = c0 * d; + out_shs[30] = s0 * d; + d = 47.909948945 * a; + out_grads[42][0] = c1 * d; + out_grads[30][0] = s1 * d; + out_grads[42][1] = -s1 * d; + out_grads[30][1] = c1 * d; + d = -51.748659331 * a; + out_grads[41][2] = c1 * d; + out_grads[31][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[43] = c1 * d; + out_shs[29] = s1 * d; + d = -20.409946485 * z; + out_grads[43][0] = c0 * d; + out_grads[29][0] = s0 * d; + out_grads[43][1] = s0 * d; + out_grads[29][1] = c0 * d; + d = 15.969982982 * z; + out_grads[42][2] = c0 * d; + out_grads[30][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[44] = c0 * d; + out_shs[28] = s0 * d; + d = 5.831413281; + out_grads[44][0] = c1 * d; + out_grads[28][0] = s1 * d; + out_grads[44][1] = -s1 * d; + out_grads[28][1] = c1 * d; + d = -2.915706641; + out_grads[43][2] = c1 * d; + out_grads[29][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[5][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[1][2] = 0.0; + out_grads[14][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[6][2] = 0.0; + out_grads[27][2] = 0.0; + out_grads[21][0] = 0.0; + out_grads[21][1] = 0.0; + out_grads[15][2] = 0.0; + out_grads[44][2] = 0.0; + out_grads[36][0] = 0.0; + out_grads[36][1] = 0.0; + out_grads[28][2] = 0.0; +} diff --git a/fury/shaders/rt_odfs/find_roots.frag b/fury/shaders/utils/find_roots.frag similarity index 100% rename from fury/shaders/rt_odfs/find_roots.frag rename to fury/shaders/utils/find_roots.frag diff --git a/fury/shaders/rt_odfs/newton_bisection.frag b/fury/shaders/utils/newton_bisection.frag similarity index 100% rename from fury/shaders/rt_odfs/newton_bisection.frag rename to fury/shaders/utils/newton_bisection.frag From ef09453321f936b19b900766616cfade2d4303a7 Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Tue, 27 Feb 2024 14:34:53 -0500 Subject: [PATCH 063/118] Added folders for Descoteaux and Tournier basis. --- .../rt_odfs/{ => descoteaux}/eval_sh_10.frag | 0 .../rt_odfs/{ => descoteaux}/eval_sh_12.frag | 0 .../rt_odfs/{ => descoteaux}/eval_sh_2.frag | 0 .../rt_odfs/{ => descoteaux}/eval_sh_4.frag | 0 .../rt_odfs/{ => descoteaux}/eval_sh_6.frag | 0 .../rt_odfs/{ => descoteaux}/eval_sh_8.frag | 0 .../{ => descoteaux}/eval_sh_grad_10.frag | 0 .../{ => descoteaux}/eval_sh_grad_12.frag | 0 .../{ => descoteaux}/eval_sh_grad_2.frag | 0 .../{ => descoteaux}/eval_sh_grad_4.frag | 0 .../{ => descoteaux}/eval_sh_grad_6.frag | 0 .../{ => descoteaux}/eval_sh_grad_8.frag | 0 .../eval_sh_10.frag} | 0 .../eval_sh_12.frag} | 0 .../eval_sh_2.frag} | 0 .../eval_sh_4.frag} | 0 .../eval_sh_6.frag} | 0 .../eval_sh_8.frag} | 0 .../rt_odfs/tournier/eval_sh_grad_10.frag | 430 +++++++++++++ .../rt_odfs/tournier/eval_sh_grad_12.frag | 591 ++++++++++++++++++ .../rt_odfs/tournier/eval_sh_grad_2.frag | 46 ++ .../rt_odfs/tournier/eval_sh_grad_4.frag | 103 +++ .../rt_odfs/tournier/eval_sh_grad_6.frag | 186 ++++++ .../rt_odfs/tournier/eval_sh_grad_8.frag | 295 +++++++++ 24 files changed, 1651 insertions(+) rename fury/shaders/rt_odfs/{ => descoteaux}/eval_sh_10.frag (100%) rename fury/shaders/rt_odfs/{ => descoteaux}/eval_sh_12.frag (100%) rename fury/shaders/rt_odfs/{ => descoteaux}/eval_sh_2.frag (100%) rename fury/shaders/rt_odfs/{ => descoteaux}/eval_sh_4.frag (100%) rename fury/shaders/rt_odfs/{ => descoteaux}/eval_sh_6.frag (100%) rename fury/shaders/rt_odfs/{ => descoteaux}/eval_sh_8.frag (100%) rename fury/shaders/rt_odfs/{ => descoteaux}/eval_sh_grad_10.frag (100%) rename fury/shaders/rt_odfs/{ => descoteaux}/eval_sh_grad_12.frag (100%) rename fury/shaders/rt_odfs/{ => descoteaux}/eval_sh_grad_2.frag (100%) rename fury/shaders/rt_odfs/{ => descoteaux}/eval_sh_grad_4.frag (100%) rename fury/shaders/rt_odfs/{ => descoteaux}/eval_sh_grad_6.frag (100%) rename fury/shaders/rt_odfs/{ => descoteaux}/eval_sh_grad_8.frag (100%) rename fury/shaders/rt_odfs/{eval_sh_10 copy.frag => tournier/eval_sh_10.frag} (100%) rename fury/shaders/rt_odfs/{eval_sh_12 copy.frag => tournier/eval_sh_12.frag} (100%) rename fury/shaders/rt_odfs/{eval_sh_2 copy.frag => tournier/eval_sh_2.frag} (100%) rename fury/shaders/rt_odfs/{eval_sh_4 copy.frag => tournier/eval_sh_4.frag} (100%) rename fury/shaders/rt_odfs/{eval_sh_6 copy.frag => tournier/eval_sh_6.frag} (100%) rename fury/shaders/rt_odfs/{eval_sh_8 copy.frag => tournier/eval_sh_8.frag} (100%) create mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_grad_10.frag create mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_grad_12.frag create mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_grad_2.frag create mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_grad_4.frag create mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_grad_6.frag create mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_grad_8.frag diff --git a/fury/shaders/rt_odfs/eval_sh_10.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_10.frag similarity index 100% rename from fury/shaders/rt_odfs/eval_sh_10.frag rename to fury/shaders/rt_odfs/descoteaux/eval_sh_10.frag diff --git a/fury/shaders/rt_odfs/eval_sh_12.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_12.frag similarity index 100% rename from fury/shaders/rt_odfs/eval_sh_12.frag rename to fury/shaders/rt_odfs/descoteaux/eval_sh_12.frag diff --git a/fury/shaders/rt_odfs/eval_sh_2.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_2.frag similarity index 100% rename from fury/shaders/rt_odfs/eval_sh_2.frag rename to fury/shaders/rt_odfs/descoteaux/eval_sh_2.frag diff --git a/fury/shaders/rt_odfs/eval_sh_4.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_4.frag similarity index 100% rename from fury/shaders/rt_odfs/eval_sh_4.frag rename to fury/shaders/rt_odfs/descoteaux/eval_sh_4.frag diff --git a/fury/shaders/rt_odfs/eval_sh_6.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_6.frag similarity index 100% rename from fury/shaders/rt_odfs/eval_sh_6.frag rename to fury/shaders/rt_odfs/descoteaux/eval_sh_6.frag diff --git a/fury/shaders/rt_odfs/eval_sh_8.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_8.frag similarity index 100% rename from fury/shaders/rt_odfs/eval_sh_8.frag rename to fury/shaders/rt_odfs/descoteaux/eval_sh_8.frag diff --git a/fury/shaders/rt_odfs/eval_sh_grad_10.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_10.frag similarity index 100% rename from fury/shaders/rt_odfs/eval_sh_grad_10.frag rename to fury/shaders/rt_odfs/descoteaux/eval_sh_grad_10.frag diff --git a/fury/shaders/rt_odfs/eval_sh_grad_12.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_12.frag similarity index 100% rename from fury/shaders/rt_odfs/eval_sh_grad_12.frag rename to fury/shaders/rt_odfs/descoteaux/eval_sh_grad_12.frag diff --git a/fury/shaders/rt_odfs/eval_sh_grad_2.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_2.frag similarity index 100% rename from fury/shaders/rt_odfs/eval_sh_grad_2.frag rename to fury/shaders/rt_odfs/descoteaux/eval_sh_grad_2.frag diff --git a/fury/shaders/rt_odfs/eval_sh_grad_4.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_4.frag similarity index 100% rename from fury/shaders/rt_odfs/eval_sh_grad_4.frag rename to fury/shaders/rt_odfs/descoteaux/eval_sh_grad_4.frag diff --git a/fury/shaders/rt_odfs/eval_sh_grad_6.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_6.frag similarity index 100% rename from fury/shaders/rt_odfs/eval_sh_grad_6.frag rename to fury/shaders/rt_odfs/descoteaux/eval_sh_grad_6.frag diff --git a/fury/shaders/rt_odfs/eval_sh_grad_8.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_8.frag similarity index 100% rename from fury/shaders/rt_odfs/eval_sh_grad_8.frag rename to fury/shaders/rt_odfs/descoteaux/eval_sh_grad_8.frag diff --git a/fury/shaders/rt_odfs/eval_sh_10 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_10.frag similarity index 100% rename from fury/shaders/rt_odfs/eval_sh_10 copy.frag rename to fury/shaders/rt_odfs/tournier/eval_sh_10.frag diff --git a/fury/shaders/rt_odfs/eval_sh_12 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_12.frag similarity index 100% rename from fury/shaders/rt_odfs/eval_sh_12 copy.frag rename to fury/shaders/rt_odfs/tournier/eval_sh_12.frag diff --git a/fury/shaders/rt_odfs/eval_sh_2 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_2.frag similarity index 100% rename from fury/shaders/rt_odfs/eval_sh_2 copy.frag rename to fury/shaders/rt_odfs/tournier/eval_sh_2.frag diff --git a/fury/shaders/rt_odfs/eval_sh_4 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_4.frag similarity index 100% rename from fury/shaders/rt_odfs/eval_sh_4 copy.frag rename to fury/shaders/rt_odfs/tournier/eval_sh_4.frag diff --git a/fury/shaders/rt_odfs/eval_sh_6 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_6.frag similarity index 100% rename from fury/shaders/rt_odfs/eval_sh_6 copy.frag rename to fury/shaders/rt_odfs/tournier/eval_sh_6.frag diff --git a/fury/shaders/rt_odfs/eval_sh_8 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_8.frag similarity index 100% rename from fury/shaders/rt_odfs/eval_sh_8 copy.frag rename to fury/shaders/rt_odfs/tournier/eval_sh_8.frag diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_10.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_10.frag new file mode 100644 index 000000000..c9e6b0d8d --- /dev/null +++ b/fury/shaders/rt_odfs/tournier/eval_sh_grad_10.frag @@ -0,0 +1,430 @@ +void eval_sh_grad_10(out float out_shs[66], out vec3 out_grads[66], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + b = z2 * a - 0.250980392 * b; + a = b - 0.250773994 * a; + d = 233.240148813 * a; + out_shs[55] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + out_grads[4][0] = c0 * d; + out_grads[2][0] = s0 * d; + out_grads[4][1] = s0 * d; + out_grads[2][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + out_grads[11][0] = c0 * d; + out_grads[9][0] = s0 * d; + out_grads[11][1] = s0 * d; + out_grads[9][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[22] = c1 * d; + out_shs[20] = s1 * d; + out_grads[22][0] = c0 * d; + out_grads[20][0] = s0 * d; + out_grads[22][1] = s0 * d; + out_grads[20][1] = c0 * d; + d = 88.106914343 * b; + out_grads[21][2] = d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[37] = c1 * d; + out_shs[35] = s1 * d; + out_grads[37][0] = c0 * d; + out_grads[35][0] = s0 * d; + out_grads[37][1] = s0 * d; + out_grads[35][1] = c0 * d; + d = 467.786944906 * b; + out_grads[36][2] = d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + out_shs[56] = c1 * d; + out_shs[54] = s1 * d; + out_grads[56][0] = c0 * d; + out_grads[54][0] = s0 * d; + out_grads[56][1] = s0 * d; + out_grads[54][1] = c0 * d; + d = 2332.401488133 * b; + out_grads[55][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + d = 1.092548431; + out_grads[5][0] = c1 * d; + out_grads[1][0] = s1 * d; + out_grads[5][1] = -s1 * d; + out_grads[1][1] = c1 * d; + d = -1.092548431; + out_grads[4][2] = c1 * d; + out_grads[2][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + d = 6.62322287 * a; + out_grads[12][0] = c1 * d; + out_grads[8][0] = s1 * d; + out_grads[12][1] = -s1 * d; + out_grads[8][1] = c1 * d; + d = -14.049977415 * a; + out_grads[11][2] = c1 * d; + out_grads[9][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[23] = c0 * d; + out_shs[19] = s0 * d; + d = 30.399773564 * a; + out_grads[23][0] = c1 * d; + out_grads[19][0] = s1 * d; + out_grads[23][1] = -s1 * d; + out_grads[19][1] = c1 * d; + d = -96.132524816 * a; + out_grads[22][2] = c1 * d; + out_grads[20][2] = s1 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[38] = c0 * d; + out_shs[34] = s0 * d; + d = 130.459545912 * a; + out_grads[38][0] = c1 * d; + out_grads[34][0] = s1 * d; + out_grads[38][1] = -s1 * d; + out_grads[34][1] = c1 * d; + d = -545.751435723 * a; + out_grads[37][2] = c1 * d; + out_grads[35][2] = s1 * d; + b = z2 * a - 0.235294118 * b; + a = b - 0.238390093 * a; + d = 272.365814381 * a; + out_shs[57] = c0 * d; + out_shs[53] = s0 * d; + d = 544.731628762 * a; + out_grads[57][0] = c1 * d; + out_grads[53][0] = s1 * d; + out_grads[57][1] = -s1 * d; + out_grads[53][1] = c1 * d; + d = -2830.508572514 * a; + out_grads[56][2] = c1 * d; + out_grads[54][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; + d = -5.310392309 * z; + out_grads[13][0] = c0 * d; + out_grads[7][0] = s0 * d; + out_grads[13][1] = s0 * d; + out_grads[7][1] = c0 * d; + d = 6.62322287 * z; + out_grads[12][2] = c0 * d; + out_grads[8][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[24] = c1 * d; + out_shs[18] = s1 * d; + d = -30.399773564 * b; + out_grads[24][0] = c0 * d; + out_grads[18][0] = s0 * d; + out_grads[24][1] = s0 * d; + out_grads[18][1] = c0 * d; + d = 60.799547128 * b; + out_grads[23][2] = c0 * d; + out_grads[19][2] = s0 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[39] = c1 * d; + out_shs[33] = s1 * d; + d = -144.52614017 * b; + out_grads[39][0] = c0 * d; + out_grads[33][0] = s0 * d; + out_grads[39][1] = s0 * d; + out_grads[33][1] = c0 * d; + d = 391.378637737 * b; + out_grads[38][2] = c0 * d; + out_grads[34][2] = s0 * d; + a = z2 * b - 0.215686275 * a; + b = a - 0.222910217 * b; + d = -213.661323441 * b; + out_shs[58] = c1 * d; + out_shs[52] = s1 * d; + d = -640.983970322 * b; + out_grads[58][0] = c0 * d; + out_grads[52][0] = s0 * d; + out_grads[58][1] = s0 * d; + out_grads[52][1] = c0 * d; + d = 2178.926515046 * b; + out_grads[57][2] = c0 * d; + out_grads[53][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; + d = 2.503342942; + out_grads[14][0] = c1 * d; + out_grads[6][0] = s1 * d; + out_grads[14][1] = -s1 * d; + out_grads[6][1] = c1 * d; + d = -1.77013077; + out_grads[13][2] = c1 * d; + out_grads[7][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[25] = c0 * d; + out_shs[17] = s0 * d; + d = 22.200855632 * a; + out_grads[25][0] = c1 * d; + out_grads[17][0] = s1 * d; + out_grads[25][1] = -s1 * d; + out_grads[17][1] = c1 * d; + d = -30.399773564 * a; + out_grads[24][2] = c1 * d; + out_grads[18][2] = s1 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[40] = c0 * d; + out_shs[32] = s0 * d; + d = 124.388296437 * a; + out_grads[40][0] = c1 * d; + out_grads[32][0] = s1 * d; + out_grads[40][1] = -s1 * d; + out_grads[32][1] = c1 * d; + d = -240.876900283 * a; + out_grads[39][2] = c1 * d; + out_grads[33][2] = s1 * d; + b = z2 * a - 0.188235294 * b; + a = b - 0.20123839 * a; + d = 151.081370682 * a; + out_shs[59] = c0 * d; + out_shs[51] = s0 * d; + d = 604.325482728 * a; + out_grads[59][0] = c1 * d; + out_grads[51][0] = s1 * d; + out_grads[59][1] = -s1 * d; + out_grads[51][1] = c1 * d; + d = -1495.629264084 * a; + out_grads[58][2] = c1 * d; + out_grads[52][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[26] = c1 * d; + out_shs[16] = s1 * d; + d = -11.833095811 * z; + out_grads[26][0] = c0 * d; + out_grads[16][0] = s0 * d; + out_grads[26][1] = s0 * d; + out_grads[16][1] = c0 * d; + d = 11.100427816 * z; + out_grads[25][2] = c0 * d; + out_grads[17][2] = s0 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[41] = c1 * d; + out_shs[31] = s1 * d; + d = -86.247765552 * b; + out_grads[41][0] = c0 * d; + out_grads[31][0] = s0 * d; + out_grads[41][1] = s0 * d; + out_grads[31][1] = c0 * d; + d = 124.388296437 * b; + out_grads[40][2] = c0 * d; + out_grads[32][2] = s0 * d; + a = z2 * b - 0.152941176 * a; + b = a - 0.173374613 * b; + d = -95.552248675 * b; + out_shs[60] = c1 * d; + out_shs[50] = s1 * d; + d = -477.761243376 * b; + out_grads[60][0] = c0 * d; + out_grads[50][0] = s0 * d; + out_grads[60][1] = s0 * d; + out_grads[50][1] = c0 * d; + d = 906.488224092 * b; + out_grads[59][2] = c0 * d; + out_grads[51][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[27] = c0 * d; + out_shs[15] = s0 * d; + d = 4.099104631; + out_grads[27][0] = c1 * d; + out_grads[15][0] = s1 * d; + out_grads[27][1] = -s1 * d; + out_grads[15][1] = c1 * d; + d = -2.366619162; + out_grads[26][2] = c1 * d; + out_grads[16][2] = s1 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[42] = c0 * d; + out_shs[30] = s0 * d; + d = 47.909948945 * a; + out_grads[42][0] = c1 * d; + out_grads[30][0] = s1 * d; + out_grads[42][1] = -s1 * d; + out_grads[30][1] = c1 * d; + d = -51.748659331 * a; + out_grads[41][2] = c1 * d; + out_grads[31][2] = s1 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + out_shs[61] = c0 * d; + out_shs[49] = s0 * d; + d = 320.491985161 * a; + out_grads[61][0] = c1 * d; + out_grads[49][0] = s1 * d; + out_grads[61][1] = -s1 * d; + out_grads[49][1] = c1 * d; + d = -477.761243376 * a; + out_grads[60][2] = c1 * d; + out_grads[50][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[43] = c1 * d; + out_shs[29] = s1 * d; + d = -20.409946485 * z; + out_grads[43][0] = c0 * d; + out_grads[29][0] = s0 * d; + out_grads[43][1] = s0 * d; + out_grads[29][1] = c0 * d; + d = 15.969982982 * z; + out_grads[42][2] = c0 * d; + out_grads[30][2] = s0 * d; + a = (z2 - 5.88235294e-02) * z; + b = a - 9.90712074e-02 * z; + d = -25.910241313 * b; + out_shs[62] = c1 * d; + out_shs[48] = s1 * d; + d = -181.371689194 * b; + out_grads[62][0] = c0 * d; + out_grads[48][0] = s0 * d; + out_grads[62][1] = s0 * d; + out_grads[48][1] = c0 * d; + d = 213.661323441 * b; + out_grads[61][2] = c0 * d; + out_grads[49][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[44] = c0 * d; + out_shs[28] = s0 * d; + d = 5.831413281; + out_grads[44][0] = c1 * d; + out_grads[28][0] = s1 * d; + out_grads[44][1] = -s1 * d; + out_grads[28][1] = c1 * d; + d = -2.915706641; + out_grads[43][2] = c1 * d; + out_grads[29][2] = s1 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + out_shs[63] = c0 * d; + out_shs[47] = s0 * d; + d = 84.622493774 * a; + out_grads[63][0] = c1 * d; + out_grads[47][0] = s1 * d; + out_grads[63][1] = -s1 * d; + out_grads[47][1] = c1 * d; + d = -77.73072394 * a; + out_grads[62][2] = c1 * d; + out_grads[48][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + out_shs[64] = c1 * d; + out_shs[46] = s1 * d; + d = -30.887057699 * z; + out_grads[64][0] = c0 * d; + out_grads[46][0] = s0 * d; + out_grads[64][1] = s0 * d; + out_grads[46][1] = c0 * d; + d = 21.155623443 * z; + out_grads[63][2] = c0 * d; + out_grads[47][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + out_shs[65] = c0 * d; + out_shs[45] = s0 * d; + d = 7.673951182; + out_grads[65][0] = c1 * d; + out_grads[45][0] = s1 * d; + out_grads[65][1] = -s1 * d; + out_grads[45][1] = c1 * d; + d = -3.4318953; + out_grads[64][2] = c1 * d; + out_grads[46][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; + out_grads[6][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[14][2] = 0.0; + out_grads[15][2] = 0.0; + out_grads[21][0] = 0.0; + out_grads[21][1] = 0.0; + out_grads[27][2] = 0.0; + out_grads[28][2] = 0.0; + out_grads[36][0] = 0.0; + out_grads[36][1] = 0.0; + out_grads[44][2] = 0.0; + out_grads[45][2] = 0.0; + out_grads[55][0] = 0.0; + out_grads[55][1] = 0.0; + out_grads[65][2] = 0.0; +} diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_12.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_12.frag new file mode 100644 index 000000000..35c2a3617 --- /dev/null +++ b/fury/shaders/rt_odfs/tournier/eval_sh_grad_12.frag @@ -0,0 +1,591 @@ +void eval_sh_grad_12(out float out_shs[91], out vec3 out_grads[91], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + b = z2 * a - 0.250980392 * b; + a = b - 0.250773994 * a; + d = 233.240148813 * a; + out_shs[55] = d; + b = z2 * a - 0.250626566 * b; + a = b - 0.250517598 * a; + d = 931.186918633 * a; + out_shs[78] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + out_grads[4][0] = c0 * d; + out_grads[2][0] = s0 * d; + out_grads[4][1] = s0 * d; + out_grads[2][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + out_grads[11][0] = c0 * d; + out_grads[9][0] = s0 * d; + out_grads[11][1] = s0 * d; + out_grads[9][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[22] = c1 * d; + out_shs[20] = s1 * d; + out_grads[22][0] = c0 * d; + out_grads[20][0] = s0 * d; + out_grads[22][1] = s0 * d; + out_grads[20][1] = c0 * d; + d = 88.106914343 * b; + out_grads[21][2] = d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[37] = c1 * d; + out_shs[35] = s1 * d; + out_grads[37][0] = c0 * d; + out_grads[35][0] = s0 * d; + out_grads[37][1] = s0 * d; + out_grads[35][1] = c0 * d; + d = 467.786944906 * b; + out_grads[36][2] = d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + out_shs[56] = c1 * d; + out_shs[54] = s1 * d; + out_grads[56][0] = c0 * d; + out_grads[54][0] = s0 * d; + out_grads[56][1] = s0 * d; + out_grads[54][1] = c0 * d; + d = 2332.401488133 * b; + out_grads[55][2] = d; + a = z2 * b - 0.248120301 * a; + b = a - 0.248447205 * b; + d = -1265.233874957 * b; + out_shs[79] = c1 * d; + out_shs[77] = s1 * d; + out_grads[79][0] = c0 * d; + out_grads[77][0] = s0 * d; + out_grads[79][1] = s0 * d; + out_grads[77][1] = c0 * d; + d = 11174.243023595 * b; + out_grads[78][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + d = 1.092548431; + out_grads[5][0] = c1 * d; + out_grads[1][0] = s1 * d; + out_grads[5][1] = -s1 * d; + out_grads[1][1] = c1 * d; + d = -1.092548431; + out_grads[4][2] = c1 * d; + out_grads[2][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + d = 6.62322287 * a; + out_grads[12][0] = c1 * d; + out_grads[8][0] = s1 * d; + out_grads[12][1] = -s1 * d; + out_grads[8][1] = c1 * d; + d = -14.049977415 * a; + out_grads[11][2] = c1 * d; + out_grads[9][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[23] = c0 * d; + out_shs[19] = s0 * d; + d = 30.399773564 * a; + out_grads[23][0] = c1 * d; + out_grads[19][0] = s1 * d; + out_grads[23][1] = -s1 * d; + out_grads[19][1] = c1 * d; + d = -96.132524816 * a; + out_grads[22][2] = c1 * d; + out_grads[20][2] = s1 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[38] = c0 * d; + out_shs[34] = s0 * d; + d = 130.459545912 * a; + out_grads[38][0] = c1 * d; + out_grads[34][0] = s1 * d; + out_grads[38][1] = -s1 * d; + out_grads[34][1] = c1 * d; + d = -545.751435723 * a; + out_grads[37][2] = c1 * d; + out_grads[35][2] = s1 * d; + b = z2 * a - 0.235294118 * b; + a = b - 0.238390093 * a; + d = 272.365814381 * a; + out_shs[57] = c0 * d; + out_shs[53] = s0 * d; + d = 544.731628762 * a; + out_grads[57][0] = c1 * d; + out_grads[53][0] = s1 * d; + out_grads[57][1] = -s1 * d; + out_grads[53][1] = c1 * d; + d = -2830.508572514 * a; + out_grads[56][2] = c1 * d; + out_grads[54][2] = s1 * d; + b = z2 * a - 0.240601504 * b; + a = b - 0.242236025 * a; + d = 1121.509962433 * a; + out_shs[80] = c0 * d; + out_shs[76] = s0 * d; + d = 2243.019924866 * a; + out_grads[80][0] = c1 * d; + out_grads[76][0] = s1 * d; + out_grads[80][1] = -s1 * d; + out_grads[76][1] = c1 * d; + d = -13917.572624524 * a; + out_grads[79][2] = c1 * d; + out_grads[77][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; + d = -5.310392309 * z; + out_grads[13][0] = c0 * d; + out_grads[7][0] = s0 * d; + out_grads[13][1] = s0 * d; + out_grads[7][1] = c0 * d; + d = 6.62322287 * z; + out_grads[12][2] = c0 * d; + out_grads[8][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[24] = c1 * d; + out_shs[18] = s1 * d; + d = -30.399773564 * b; + out_grads[24][0] = c0 * d; + out_grads[18][0] = s0 * d; + out_grads[24][1] = s0 * d; + out_grads[18][1] = c0 * d; + d = 60.799547128 * b; + out_grads[23][2] = c0 * d; + out_grads[19][2] = s0 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[39] = c1 * d; + out_shs[33] = s1 * d; + d = -144.52614017 * b; + out_grads[39][0] = c0 * d; + out_grads[33][0] = s0 * d; + out_grads[39][1] = s0 * d; + out_grads[33][1] = c0 * d; + d = 391.378637737 * b; + out_grads[38][2] = c0 * d; + out_grads[34][2] = s0 * d; + a = z2 * b - 0.215686275 * a; + b = a - 0.222910217 * b; + d = -213.661323441 * b; + out_shs[58] = c1 * d; + out_shs[52] = s1 * d; + d = -640.983970322 * b; + out_grads[58][0] = c0 * d; + out_grads[52][0] = s0 * d; + out_grads[58][1] = s0 * d; + out_grads[52][1] = c0 * d; + d = 2178.926515046 * b; + out_grads[57][2] = c0 * d; + out_grads[53][2] = s0 * d; + a = z2 * b - 0.228070175 * a; + b = a - 0.231884058 * b; + d = -915.709049803 * b; + out_shs[81] = c1 * d; + out_shs[75] = s1 * d; + d = -2747.127149409 * b; + out_grads[81][0] = c0 * d; + out_grads[75][0] = s0 * d; + out_grads[81][1] = s0 * d; + out_grads[75][1] = c0 * d; + d = 11215.099624332 * b; + out_grads[80][2] = c0 * d; + out_grads[76][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; + d = 2.503342942; + out_grads[14][0] = c1 * d; + out_grads[6][0] = s1 * d; + out_grads[14][1] = -s1 * d; + out_grads[6][1] = c1 * d; + d = -1.77013077; + out_grads[13][2] = c1 * d; + out_grads[7][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[25] = c0 * d; + out_shs[17] = s0 * d; + d = 22.200855632 * a; + out_grads[25][0] = c1 * d; + out_grads[17][0] = s1 * d; + out_grads[25][1] = -s1 * d; + out_grads[17][1] = c1 * d; + d = -30.399773564 * a; + out_grads[24][2] = c1 * d; + out_grads[18][2] = s1 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[40] = c0 * d; + out_shs[32] = s0 * d; + d = 124.388296437 * a; + out_grads[40][0] = c1 * d; + out_grads[32][0] = s1 * d; + out_grads[40][1] = -s1 * d; + out_grads[32][1] = c1 * d; + d = -240.876900283 * a; + out_grads[39][2] = c1 * d; + out_grads[33][2] = s1 * d; + b = z2 * a - 0.188235294 * b; + a = b - 0.20123839 * a; + d = 151.081370682 * a; + out_shs[59] = c0 * d; + out_shs[51] = s0 * d; + d = 604.325482728 * a; + out_grads[59][0] = c1 * d; + out_grads[51][0] = s1 * d; + out_grads[59][1] = -s1 * d; + out_grads[51][1] = c1 * d; + d = -1495.629264084 * a; + out_grads[58][2] = c1 * d; + out_grads[52][2] = s1 * d; + b = z2 * a - 0.210526316 * b; + a = b - 0.217391304 * a; + d = 686.781787352 * a; + out_shs[82] = c0 * d; + out_shs[74] = s0 * d; + d = 2747.127149409 * a; + out_grads[82][0] = c1 * d; + out_grads[74][0] = s1 * d; + out_grads[82][1] = -s1 * d; + out_grads[74][1] = c1 * d; + d = -8241.381448228 * a; + out_grads[81][2] = -c1 * d; + out_grads[75][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[26] = c1 * d; + out_shs[16] = s1 * d; + d = -11.833095811 * z; + out_grads[26][0] = c0 * d; + out_grads[16][0] = s0 * d; + out_grads[26][1] = s0 * d; + out_grads[16][1] = c0 * d; + d = 11.100427816 * z; + out_grads[25][2] = c0 * d; + out_grads[17][2] = s0 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[41] = c1 * d; + out_shs[31] = s1 * d; + d = -86.247765552 * b; + out_grads[41][0] = c0 * d; + out_grads[31][0] = s0 * d; + out_grads[41][1] = s0 * d; + out_grads[31][1] = c0 * d; + d = 124.388296437 * b; + out_grads[40][2] = c0 * d; + out_grads[32][2] = s0 * d; + a = z2 * b - 0.152941176 * a; + b = a - 0.173374613 * b; + d = -95.552248675 * b; + out_shs[60] = c1 * d; + out_shs[50] = s1 * d; + d = -477.761243376 * b; + out_grads[60][0] = c0 * d; + out_grads[50][0] = s0 * d; + out_grads[60][1] = s0 * d; + out_grads[50][1] = c0 * d; + d = 906.488224092 * b; + out_grads[59][2] = c0 * d; + out_grads[51][2] = s0 * d; + a = z2 * b - 0.187969925 * a; + b = a - 0.198757764 * b; + d = -471.12841933 * b; + out_shs[83] = c1 * d; + out_shs[73] = s1 * d; + d = -2355.642096651 * b; + out_grads[83][0] = c0 * d; + out_grads[73][0] = s0 * d; + out_grads[83][1] = s0 * d; + out_grads[73][1] = c0 * d; + d = 5494.254298819 * b; + out_grads[82][2] = c0 * d; + out_grads[74][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[27] = c0 * d; + out_shs[15] = s0 * d; + d = 4.099104631; + out_grads[27][0] = c1 * d; + out_grads[15][0] = s1 * d; + out_grads[27][1] = -s1 * d; + out_grads[15][1] = c1 * d; + d = -2.366619162; + out_grads[26][2] = c1 * d; + out_grads[16][2] = s1 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[42] = c0 * d; + out_shs[30] = s0 * d; + d = 47.909948945 * a; + out_grads[42][0] = c1 * d; + out_grads[30][0] = s1 * d; + out_grads[42][1] = -s1 * d; + out_grads[30][1] = c1 * d; + d = -51.748659331 * a; + out_grads[41][2] = c1 * d; + out_grads[31][2] = s1 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + out_shs[61] = c0 * d; + out_shs[49] = s0 * d; + d = 320.491985161 * a; + out_grads[61][0] = c1 * d; + out_grads[49][0] = s1 * d; + out_grads[61][1] = -s1 * d; + out_grads[49][1] = c1 * d; + d = -477.761243376 * a; + out_grads[60][2] = c1 * d; + out_grads[50][2] = s1 * d; + b = z2 * a - 0.160401003 * b; + a = b - 0.175983437 * a; + d = 293.800188384 * a; + out_shs[84] = c0 * d; + out_shs[72] = s0 * d; + d = 1762.801130306 * a; + out_grads[84][0] = c1 * d; + out_grads[72][0] = s1 * d; + out_grads[84][1] = -s1 * d; + out_grads[72][1] = c1 * d; + d = -3297.898935312 * a; + out_grads[83][2] = c1 * d; + out_grads[73][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[43] = c1 * d; + out_shs[29] = s1 * d; + d = -20.409946485 * z; + out_grads[43][0] = c0 * d; + out_grads[29][0] = s0 * d; + out_grads[43][1] = s0 * d; + out_grads[29][1] = c0 * d; + d = 15.969982982 * z; + out_grads[42][2] = c0 * d; + out_grads[30][2] = s0 * d; + a = (z2 - 5.88235294e-02) * z; + b = a - 9.90712074e-02 * z; + d = -25.910241313 * b; + out_shs[62] = c1 * d; + out_shs[48] = s1 * d; + d = -181.371689194 * b; + out_grads[62][0] = c0 * d; + out_grads[48][0] = s0 * d; + out_grads[62][1] = s0 * d; + out_grads[48][1] = c0 * d; + d = 213.661323441 * b; + out_grads[61][2] = c0 * d; + out_grads[49][2] = s0 * d; + a = z2 * b - 0.127819549 * a; + b = a - 0.149068323 * b; + d = -165.101452729 * b; + out_shs[85] = c1 * d; + out_shs[71] = s1 * d; + d = -1155.7101691 * b; + out_grads[85][0] = c0 * d; + out_grads[71][0] = s0 * d; + out_grads[85][1] = s0 * d; + out_grads[71][1] = c0 * d; + d = 1762.801130306 * b; + out_grads[84][2] = c0 * d; + out_grads[72][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[44] = c0 * d; + out_shs[28] = s0 * d; + d = 5.831413281; + out_grads[44][0] = c1 * d; + out_grads[28][0] = s1 * d; + out_grads[44][1] = -s1 * d; + out_grads[28][1] = c1 * d; + d = -2.915706641; + out_grads[43][2] = c1 * d; + out_grads[29][2] = s1 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + out_shs[63] = c0 * d; + out_shs[47] = s0 * d; + d = 84.622493774 * a; + out_grads[63][0] = c1 * d; + out_grads[47][0] = s1 * d; + out_grads[63][1] = -s1 * d; + out_grads[47][1] = c1 * d; + d = -77.73072394 * a; + out_grads[62][2] = c1 * d; + out_grads[48][2] = s1 * d; + b = z2 * (a - 9.02255639e-02); + a = b - 0.118012422 * a; + d = 82.550726364 * a; + out_shs[86] = c0 * d; + out_shs[70] = s0 * d; + d = 660.405810914 * a; + out_grads[86][0] = c1 * d; + out_grads[70][0] = s1 * d; + out_grads[86][1] = -s1 * d; + out_grads[70][1] = c1 * d; + d = -825.507263643 * a; + out_grads[85][2] = c1 * d; + out_grads[71][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + out_shs[64] = c1 * d; + out_shs[46] = s1 * d; + d = -30.887057699 * z; + out_grads[64][0] = c0 * d; + out_grads[46][0] = s0 * d; + out_grads[64][1] = s0 * d; + out_grads[46][1] = c0 * d; + d = 21.155623443 * z; + out_grads[63][2] = c0 * d; + out_grads[47][2] = s0 * d; + a = (z2 - 4.76190476e-02) * z; + b = a - 8.2815735e-02 * z; + d = -36.028090689 * b; + out_shs[87] = c1 * d; + out_shs[69] = s1 * d; + d = -324.252816204 * b; + out_grads[87][0] = c0 * d; + out_grads[69][0] = s0 * d; + out_grads[87][1] = s0 * d; + out_grads[69][1] = c0 * d; + d = 330.202905457 * b; + out_grads[86][2] = c0 * d; + out_grads[70][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + out_shs[65] = c0 * d; + out_shs[45] = s0 * d; + d = 7.673951182; + out_grads[65][0] = c1 * d; + out_grads[45][0] = s1 * d; + out_grads[65][1] = -s1 * d; + out_grads[45][1] = c1 * d; + d = -3.4318953; + out_grads[64][2] = c1 * d; + out_grads[46][2] = s1 * d; + a = z2 - 4.34782609e-02; + d = 13.3042542 * a; + out_shs[88] = c0 * d; + out_shs[68] = s0 * d; + d = 133.042542003 * a; + out_grads[88][0] = c1 * d; + out_grads[68][0] = s1 * d; + out_grads[88][1] = -s1 * d; + out_grads[68][1] = c1 * d; + d = -108.084272068 * a; + out_grads[87][2] = c1 * d; + out_grads[69][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.923210529 * z; + out_shs[89] = c1 * d; + out_shs[67] = s1 * d; + d = -43.155315818 * z; + out_grads[89][0] = c0 * d; + out_grads[67][0] = s0 * d; + out_grads[89][1] = s0 * d; + out_grads[67][1] = c0 * d; + d = 26.608508401 * z; + out_grads[88][2] = c0 * d; + out_grads[68][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.800821996; + out_shs[90] = c0 * d; + out_shs[66] = s0 * d; + d = 9.609863949; + out_grads[90][0] = c1 * d; + out_grads[66][0] = s1 * d; + out_grads[90][1] = -s1 * d; + out_grads[66][1] = c1 * d; + d = -3.923210529; + out_grads[89][2] = c1 * d; + out_grads[67][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; + out_grads[6][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[14][2] = 0.0; + out_grads[15][2] = 0.0; + out_grads[21][0] = 0.0; + out_grads[21][1] = 0.0; + out_grads[27][2] = 0.0; + out_grads[28][2] = 0.0; + out_grads[36][0] = 0.0; + out_grads[36][1] = 0.0; + out_grads[44][2] = 0.0; + out_grads[45][2] = 0.0; + out_grads[55][0] = 0.0; + out_grads[55][1] = 0.0; + out_grads[65][2] = 0.0; + out_grads[66][2] = 0.0; + out_grads[78][0] = 0.0; + out_grads[78][1] = 0.0; + out_grads[90][2] = 0.0; +} diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_2.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_2.frag new file mode 100644 index 000000000..277a0e07a --- /dev/null +++ b/fury/shaders/rt_odfs/tournier/eval_sh_grad_2.frag @@ -0,0 +1,46 @@ +void eval_sh_grad_2(out float out_shs[6], out vec3 out_grads[6], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + out_grads[4][0] = c0 * d; + out_grads[2][0] = s0 * d; + out_grads[4][1] = s0 * d; + out_grads[2][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + d = 1.092548431; + out_grads[1][0] = c1 * d; + out_grads[5][0] = s1 * d; + out_grads[5][1] = -s1 * d; + out_grads[1][1] = c1 * d; + d = -1.092548431; + out_grads[4][2] = c1 * d; + out_grads[2][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[5][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[1][2] = 0.0; +} diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_4.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_4.frag new file mode 100644 index 000000000..c85847a5b --- /dev/null +++ b/fury/shaders/rt_odfs/tournier/eval_sh_grad_4.frag @@ -0,0 +1,103 @@ +void eval_sh_grad_4(out float out_shs[15], out vec3 out_grads[15], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + out_grads[4][0] = c0 * d; + out_grads[2][0] = s0 * d; + out_grads[4][1] = s0 * d; + out_grads[2][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + out_grads[11][0] = c0 * d; + out_grads[9][0] = s0 * d; + out_grads[11][1] = s0 * d; + out_grads[9][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + d = 1.092548431; + out_grads[5][0] = c1 * d; + out_grads[1][0] = s1 * d; + out_grads[5][1] = -s1 * d; + out_grads[1][1] = c1 * d; + d = -1.092548431; + out_grads[4][2] = c1 * d; + out_grads[2][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + d = 6.62322287 * a; + out_grads[12][0] = c1 * d; + out_grads[8][0] = s1 * d; + out_grads[12][1] = -s1 * d; + out_grads[8][1] = c1 * d; + d = -14.049977415 * a; + out_grads[11][2] = c1 * d; + out_grads[9][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; + d = -5.310392309 * z; + out_grads[13][0] = c0 * d; + out_grads[7][0] = s0 * d; + out_grads[13][1] = s0 * d; + out_grads[7][1] = c0 * d; + d = 6.62322287 * z; + out_grads[12][2] = c0 * d; + out_grads[8][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; + d = 2.503342942; + out_grads[14][0] = c1 * d; + out_grads[6][0] = s1 * d; + out_grads[14][1] = -s1 * d; + out_grads[6][1] = c1 * d; + d = -1.77013077; + out_grads[13][2] = c1 * d; + out_grads[7][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[5][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[1][2] = 0.0; + out_grads[14][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[6][2] = 0.0; +} diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_6.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_6.frag new file mode 100644 index 000000000..617413bc9 --- /dev/null +++ b/fury/shaders/rt_odfs/tournier/eval_sh_grad_6.frag @@ -0,0 +1,186 @@ +void eval_sh_grad_6(out float out_shs[28], out vec3 out_grads[28], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + out_grads[4][0] = c0 * d; + out_grads[2][0] = s0 * d; + out_grads[4][1] = s0 * d; + out_grads[2][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + out_grads[11][0] = c0 * d; + out_grads[9][0] = s0 * d; + out_grads[11][1] = s0 * d; + out_grads[9][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[22] = c1 * d; + out_shs[20] = s1 * d; + out_grads[22][0] = c0 * d; + out_grads[20][0] = s0 * d; + out_grads[22][1] = s0 * d; + out_grads[20][1] = c0 * d; + d = 88.106914343 * b; + out_grads[21][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + d = 1.092548431; + out_grads[5][0] = c1 * d; + out_grads[1][0] = s1 * d; + out_grads[5][1] = -s1 * d; + out_grads[1][1] = c1 * d; + d = -1.092548431; + out_grads[4][2] = c1 * d; + out_grads[2][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + d = 6.62322287 * a; + out_grads[12][0] = c1 * d; + out_grads[8][0] = s1 * d; + out_grads[12][1] = -s1 * d; + out_grads[8][1] = c1 * d; + d = -14.049977415 * a; + out_grads[11][2] = c1 * d; + out_grads[9][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[23] = c0 * d; + out_shs[19] = s0 * d; + d = 30.399773564 * a; + out_grads[23][0] = c1 * d; + out_grads[19][0] = s1 * d; + out_grads[23][1] = -s1 * d; + out_grads[19][1] = c1 * d; + d = -96.132524816 * a; + out_grads[22][2] = c1 * d; + out_grads[20][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; + d = -5.310392309 * z; + out_grads[13][0] = c0 * d; + out_grads[7][0] = s0 * d; + out_grads[13][1] = s0 * d; + out_grads[7][1] = c0 * d; + d = 6.62322287 * z; + out_grads[12][2] = c0 * d; + out_grads[8][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[24] = c1 * d; + out_shs[18] = s1 * d; + d = -30.399773564 * b; + out_grads[24][0] = c0 * d; + out_grads[18][0] = s0 * d; + out_grads[24][1] = s0 * d; + out_grads[18][1] = c0 * d; + d = 60.799547128 * b; + out_grads[23][2] = c0 * d; + out_grads[19][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; + d = 2.503342942; + out_grads[14][0] = c1 * d; + out_grads[6][0] = s1 * d; + out_grads[14][1] = -s1 * d; + out_grads[6][1] = c1 * d; + d = -1.77013077; + out_grads[13][2] = c1 * d; + out_grads[7][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[25] = c0 * d; + out_shs[17] = s0 * d; + d = 22.200855632 * a; + out_grads[25][0] = c1 * d; + out_grads[17][0] = s1 * d; + out_grads[25][1] = -s1 * d; + out_grads[17][1] = c1 * d; + d = -30.399773564 * a; + out_grads[24][2] = c1 * d; + out_grads[18][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[26] = c1 * d; + out_shs[16] = s1 * d; + d = -11.833095811 * z; + out_grads[26][0] = c0 * d; + out_grads[16][0] = s0 * d; + out_grads[26][1] = s0 * d; + out_grads[16][1] = c0 * d; + d = 11.100427816 * z; + out_grads[25][2] = c0 * d; + out_grads[17][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[27] = c0 * d; + out_shs[15] = s0 * d; + d = 4.099104631; + out_grads[27][0] = c1 * d; + out_grads[15][0] = s1 * d; + out_grads[27][1] = -s1 * d; + out_grads[15][1] = c1 * d; + d = -2.366619162; + out_grads[26][2] = c1 * d; + out_grads[16][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[5][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[1][2] = 0.0; + out_grads[14][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[6][2] = 0.0; + out_grads[27][2] = 0.0; + out_grads[21][0] = 0.0; + out_grads[21][1] = 0.0; + out_grads[15][2] = 0.0; +} diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_8.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_8.frag new file mode 100644 index 000000000..712b2dc29 --- /dev/null +++ b/fury/shaders/rt_odfs/tournier/eval_sh_grad_8.frag @@ -0,0 +1,295 @@ +void eval_sh_grad_8(out float out_shs[45], out vec3 out_grads[45], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + out_grads[4][0] = c0 * d; + out_grads[2][0] = s0 * d; + out_grads[4][1] = s0 * d; + out_grads[2][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + out_grads[11][0] = c0 * d; + out_grads[9][0] = s0 * d; + out_grads[11][1] = s0 * d; + out_grads[9][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[22] = c1 * d; + out_shs[20] = s1 * d; + out_grads[22][0] = c0 * d; + out_grads[20][0] = s0 * d; + out_grads[22][1] = s0 * d; + out_grads[20][1] = c0 * d; + d = 88.106914343 * b; + out_grads[21][2] = d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[37] = c1 * d; + out_shs[35] = s1 * d; + out_grads[37][0] = c0 * d; + out_grads[35][0] = s0 * d; + out_grads[37][1] = s0 * d; + out_grads[35][1] = c0 * d; + d = 467.786944906 * b; + out_grads[36][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + d = 1.092548431; + out_grads[5][0] = c1 * d; + out_grads[1][0] = s1 * d; + out_grads[5][1] = -s1 * d; + out_grads[1][1] = c1 * d; + d = -1.092548431; + out_grads[4][2] = c1 * d; + out_grads[2][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + d = 6.62322287 * a; + out_grads[12][0] = c1 * d; + out_grads[8][0] = s1 * d; + out_grads[12][1] = -s1 * d; + out_grads[8][1] = c1 * d; + d = -14.049977415 * a; + out_grads[11][2] = c1 * d; + out_grads[9][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[23] = c0 * d; + out_shs[19] = s0 * d; + d = 30.399773564 * a; + out_grads[23][0] = c1 * d; + out_grads[19][0] = s1 * d; + out_grads[23][1] = -s1 * d; + out_grads[19][1] = c1 * d; + d = -96.132524816 * a; + out_grads[22][2] = c1 * d; + out_grads[20][2] = s1 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[38] = c0 * d; + out_shs[34] = s0 * d; + d = 130.459545912 * a; + out_grads[38][0] = c1 * d; + out_grads[34][0] = s1 * d; + out_grads[38][1] = -s1 * d; + out_grads[34][1] = c1 * d; + d = -545.751435723 * a; + out_grads[37][2] = c1 * d; + out_grads[35][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; + d = -5.310392309 * z; + out_grads[13][0] = c0 * d; + out_grads[7][0] = s0 * d; + out_grads[13][1] = s0 * d; + out_grads[7][1] = c0 * d; + d = 6.62322287 * z; + out_grads[12][2] = c0 * d; + out_grads[8][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[24] = c1 * d; + out_shs[18] = s1 * d; + d = -30.399773564 * b; + out_grads[24][0] = c0 * d; + out_grads[18][0] = s0 * d; + out_grads[24][1] = s0 * d; + out_grads[18][1] = c0 * d; + d = 60.799547128 * b; + out_grads[23][2] = c0 * d; + out_grads[19][2] = s0 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[39] = c1 * d; + out_shs[33] = s1 * d; + d = -144.52614017 * b; + out_grads[39][0] = c0 * d; + out_grads[33][0] = s0 * d; + out_grads[39][1] = s0 * d; + out_grads[33][1] = c0 * d; + d = 391.378637737 * b; + out_grads[38][2] = c0 * d; + out_grads[34][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; + d = 2.503342942; + out_grads[14][0] = c1 * d; + out_grads[6][0] = s1 * d; + out_grads[14][1] = -s1 * d; + out_grads[6][1] = c1 * d; + d = -1.77013077; + out_grads[13][2] = c1 * d; + out_grads[7][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[25] = c0 * d; + out_shs[17] = s0 * d; + d = 22.200855632 * a; + out_grads[25][0] = c1 * d; + out_grads[17][0] = s1 * d; + out_grads[25][1] = -s1 * d; + out_grads[17][1] = c1 * d; + d = -30.399773564 * a; + out_grads[24][2] = c1 * d; + out_grads[18][2] = s1 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[40] = c0 * d; + out_shs[32] = s0 * d; + d = 124.388296437 * a; + out_grads[40][0] = c1 * d; + out_grads[32][0] = s1 * d; + out_grads[40][1] = -s1 * d; + out_grads[32][1] = c1 * d; + d = -240.876900283 * a; + out_grads[39][2] = c1 * d; + out_grads[33][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[26] = c1 * d; + out_shs[16] = s1 * d; + d = -11.833095811 * z; + out_grads[26][0] = c0 * d; + out_grads[16][0] = s0 * d; + out_grads[26][1] = s0 * d; + out_grads[16][1] = c0 * d; + d = 11.100427816 * z; + out_grads[25][2] = c0 * d; + out_grads[17][2] = s0 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[41] = c1 * d; + out_shs[31] = s1 * d; + d = -86.247765552 * b; + out_grads[41][0] = c0 * d; + out_grads[31][0] = s0 * d; + out_grads[41][1] = s0 * d; + out_grads[31][1] = c0 * d; + d = 124.388296437 * b; + out_grads[40][2] = c0 * d; + out_grads[32][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[27] = c0 * d; + out_shs[15] = s0 * d; + d = 4.099104631; + out_grads[27][0] = c1 * d; + out_grads[15][0] = s1 * d; + out_grads[27][1] = -s1 * d; + out_grads[15][1] = c1 * d; + d = -2.366619162; + out_grads[26][2] = c1 * d; + out_grads[16][2] = s1 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[42] = c0 * d; + out_shs[30] = s0 * d; + d = 47.909948945 * a; + out_grads[42][0] = c1 * d; + out_grads[30][0] = s1 * d; + out_grads[42][1] = -s1 * d; + out_grads[30][1] = c1 * d; + d = -51.748659331 * a; + out_grads[41][2] = c1 * d; + out_grads[31][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[43] = c1 * d; + out_shs[29] = s1 * d; + d = -20.409946485 * z; + out_grads[43][0] = c0 * d; + out_grads[29][0] = s0 * d; + out_grads[43][1] = s0 * d; + out_grads[29][1] = c0 * d; + d = 15.969982982 * z; + out_grads[42][2] = c0 * d; + out_grads[30][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[44] = c0 * d; + out_shs[28] = s0 * d; + d = 5.831413281; + out_grads[44][0] = c1 * d; + out_grads[28][0] = s1 * d; + out_grads[44][1] = -s1 * d; + out_grads[28][1] = c1 * d; + d = -2.915706641; + out_grads[43][2] = c1 * d; + out_grads[29][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[5][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[1][2] = 0.0; + out_grads[14][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[6][2] = 0.0; + out_grads[27][2] = 0.0; + out_grads[21][0] = 0.0; + out_grads[21][1] = 0.0; + out_grads[15][2] = 0.0; + out_grads[44][2] = 0.0; + out_grads[36][0] = 0.0; + out_grads[36][1] = 0.0; + out_grads[28][2] = 0.0; +} From 0b5c75f62d19e2fd19eeaddef022a49b427c2003 Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Tue, 27 Feb 2024 17:01:20 -0500 Subject: [PATCH 064/118] Updated ray_traced scripts to use spherical harmonics basis. --- .../SH-ODF_experimental/ray_traced_1.0.py | 36 +++++--- .../SH-ODF_experimental/ray_traced_2.0.py | 36 +++++--- .../SH-ODF_experimental/ray_traced_3.0.py | 36 +++++--- .../SH-ODF_experimental/ray_traced_4.0.py | 36 +++++--- .../SH-ODF_experimental/ray_traced_5.0.py | 34 +++----- .../SH-ODF_experimental/ray_traced_5.5.py | 86 +++++++++++-------- .../SH-ODF_experimental/ray_traced_6.0.py | 36 +++++--- .../SH-ODF_experimental/ray_traced_7.0.py | 27 +++--- 8 files changed, 199 insertions(+), 128 deletions(-) diff --git a/docs/experimental/SH-ODF_experimental/ray_traced_1.0.py b/docs/experimental/SH-ODF_experimental/ray_traced_1.0.py index ce72df391..90715704c 100644 --- a/docs/experimental/SH-ODF_experimental/ray_traced_1.0.py +++ b/docs/experimental/SH-ODF_experimental/ray_traced_1.0.py @@ -97,40 +97,52 @@ in float scaleVSOutput; """ - eval_sh_2 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_2.frag")) + eval_sh_2 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_2.frag") + ) - eval_sh_4 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_4.frag")) + eval_sh_4 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_4.frag") + ) - eval_sh_6 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_6.frag")) + eval_sh_6 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_6.frag") + ) - eval_sh_8 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_8.frag")) + eval_sh_8 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_8.frag") + ) - eval_sh_10 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_10.frag")) + eval_sh_10 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_10.frag") + ) - eval_sh_12 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_12.frag")) + eval_sh_12 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_12.frag") + ) eval_sh_grad_2 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_2.frag") + os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_2.frag") ) eval_sh_grad_4 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_4.frag") + os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_4.frag") ) eval_sh_grad_6 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_6.frag") + os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_6.frag") ) eval_sh_grad_8 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_8.frag") + os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_8.frag") ) eval_sh_grad_10 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_10.frag") + os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_10.frag") ) eval_sh_grad_12 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_12.frag") + os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_12.frag") ) # Searches a single root of a polynomial within a given interval. diff --git a/docs/experimental/SH-ODF_experimental/ray_traced_2.0.py b/docs/experimental/SH-ODF_experimental/ray_traced_2.0.py index ebbdeb1fe..7a6e50f25 100644 --- a/docs/experimental/SH-ODF_experimental/ray_traced_2.0.py +++ b/docs/experimental/SH-ODF_experimental/ray_traced_2.0.py @@ -191,40 +191,52 @@ def uv_calculations(n): } """ - eval_sh_2 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_2.frag")) + eval_sh_2 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_2.frag") + ) - eval_sh_4 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_4.frag")) + eval_sh_4 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_4.frag") + ) - eval_sh_6 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_6.frag")) + eval_sh_6 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_6.frag") + ) - eval_sh_8 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_8.frag")) + eval_sh_8 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_8.frag") + ) - eval_sh_10 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_10.frag")) + eval_sh_10 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_10.frag") + ) - eval_sh_12 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_12.frag")) + eval_sh_12 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_12.frag") + ) eval_sh_grad_2 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_2.frag") + os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_2.frag") ) eval_sh_grad_4 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_4.frag") + os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_4.frag") ) eval_sh_grad_6 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_6.frag") + os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_6.frag") ) eval_sh_grad_8 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_8.frag") + os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_8.frag") ) eval_sh_grad_10 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_10.frag") + os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_10.frag") ) eval_sh_grad_12 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_12.frag") + os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_12.frag") ) # Searches a single root of a polynomial within a given interval. diff --git a/docs/experimental/SH-ODF_experimental/ray_traced_3.0.py b/docs/experimental/SH-ODF_experimental/ray_traced_3.0.py index b12b1e8e8..96eef9606 100644 --- a/docs/experimental/SH-ODF_experimental/ray_traced_3.0.py +++ b/docs/experimental/SH-ODF_experimental/ray_traced_3.0.py @@ -98,40 +98,52 @@ in float scaleVSOutput; """ - eval_sh_2 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_2.frag")) + eval_sh_2 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_2.frag") + ) - eval_sh_4 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_4.frag")) + eval_sh_4 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_4.frag") + ) - eval_sh_6 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_6.frag")) + eval_sh_6 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_6.frag") + ) - eval_sh_8 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_8.frag")) + eval_sh_8 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_8.frag") + ) - eval_sh_10 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_10.frag")) + eval_sh_10 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_10.frag") + ) - eval_sh_12 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_12.frag")) + eval_sh_12 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_12.frag") + ) eval_sh_grad_2 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_2.frag") + os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_2.frag") ) eval_sh_grad_4 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_4.frag") + os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_4.frag") ) eval_sh_grad_6 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_6.frag") + os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_6.frag") ) eval_sh_grad_8 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_8.frag") + os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_8.frag") ) eval_sh_grad_10 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_10.frag") + os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_10.frag") ) eval_sh_grad_12 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_12.frag") + os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_12.frag") ) # Searches a single root of a polynomial within a given interval. diff --git a/docs/experimental/SH-ODF_experimental/ray_traced_4.0.py b/docs/experimental/SH-ODF_experimental/ray_traced_4.0.py index 119c64624..7f7dbe6b6 100644 --- a/docs/experimental/SH-ODF_experimental/ray_traced_4.0.py +++ b/docs/experimental/SH-ODF_experimental/ray_traced_4.0.py @@ -191,40 +191,52 @@ def uv_calculations(n): } """ - eval_sh_2 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_2.frag")) + eval_sh_2 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_2.frag") + ) - eval_sh_4 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_4.frag")) + eval_sh_4 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_4.frag") + ) - eval_sh_6 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_6.frag")) + eval_sh_6 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_6.frag") + ) - eval_sh_8 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_8.frag")) + eval_sh_8 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_8.frag") + ) - eval_sh_10 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_10.frag")) + eval_sh_10 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_10.frag") + ) - eval_sh_12 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_12.frag")) + eval_sh_12 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_12.frag") + ) eval_sh_grad_2 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_2.frag") + os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_2.frag") ) eval_sh_grad_4 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_4.frag") + os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_4.frag") ) eval_sh_grad_6 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_6.frag") + os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_6.frag") ) eval_sh_grad_8 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_8.frag") + os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_8.frag") ) eval_sh_grad_10 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_10.frag") + os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_10.frag") ) eval_sh_grad_12 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_12.frag") + os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_12.frag") ) # Searches a single root of a polynomial within a given interval. diff --git a/docs/experimental/SH-ODF_experimental/ray_traced_5.0.py b/docs/experimental/SH-ODF_experimental/ray_traced_5.0.py index 0cf64c752..497437c94 100644 --- a/docs/experimental/SH-ODF_experimental/ray_traced_5.0.py +++ b/docs/experimental/SH-ODF_experimental/ray_traced_5.0.py @@ -1,12 +1,4 @@ """ -Fury's implementation of "Ray Tracing Spherical Harmonics Glyphs": -https://momentsingraphics.de/VMV2023.html -The fragment shader is based on: https://www.shadertoy.com/view/dlGSDV -(c) 2023, Christoph Peters -This work is licensed under a CC0 1.0 Universal License. To the extent -possible under law, Christoph Peters has waived all copyright and related or -neighboring rights to the following code. This work is published from -Germany. https://creativecommons.org/publicdomain/zero/1.0/ """ import os @@ -48,7 +40,7 @@ def uv_calculations(n): if __name__ == "__main__": - show_man = window.ShowManager(size=(1920, 1080)) + show_man = window.ShowManager(size=(1280, 720)) show_man.scene.background((1, 1, 1)) # fmt: off @@ -199,51 +191,51 @@ def uv_calculations(n): """ eval_sh_2 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_2 copy.frag") + os.path.join("rt_odfs", "tournier", "eval_sh_2.frag") ) eval_sh_4 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_4 copy.frag") + os.path.join("rt_odfs", "tournier", "eval_sh_4.frag") ) eval_sh_6 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_6 copy.frag") + os.path.join("rt_odfs", "tournier", "eval_sh_6.frag") ) eval_sh_8 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_8 copy.frag") + os.path.join("rt_odfs", "tournier", "eval_sh_8.frag") ) eval_sh_10 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_10 copy.frag") + os.path.join("rt_odfs", "tournier", "eval_sh_10.frag") ) eval_sh_12 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_12 copy.frag") + os.path.join("rt_odfs", "tournier", "eval_sh_12.frag") ) eval_sh_grad_2 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_2.frag") + os.path.join("rt_odfs", "tournier", "eval_sh_grad_2.frag") ) eval_sh_grad_4 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_4.frag") + os.path.join("rt_odfs", "tournier", "eval_sh_grad_4.frag") ) eval_sh_grad_6 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_6.frag") + os.path.join("rt_odfs", "tournier", "eval_sh_grad_6.frag") ) eval_sh_grad_8 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_8.frag") + os.path.join("rt_odfs", "tournier", "eval_sh_grad_8.frag") ) eval_sh_grad_10 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_10.frag") + os.path.join("rt_odfs", "tournier", "eval_sh_grad_10.frag") ) eval_sh_grad_12 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_12.frag") + os.path.join("rt_odfs", "tournier", "eval_sh_grad_12.frag") ) # Searches a single root of a polynomial within a given interval. diff --git a/docs/experimental/SH-ODF_experimental/ray_traced_5.5.py b/docs/experimental/SH-ODF_experimental/ray_traced_5.5.py index dd30f9ee1..fad425090 100644 --- a/docs/experimental/SH-ODF_experimental/ray_traced_5.5.py +++ b/docs/experimental/SH-ODF_experimental/ray_traced_5.5.py @@ -1,13 +1,6 @@ """ -Fury's implementation of "Ray Tracing Spherical Harmonics Glyphs": -https://momentsingraphics.de/VMV2023.html -The fragment shader is based on: https://www.shadertoy.com/view/dlGSDV -(c) 2023, Christoph Peters -This work is licensed under a CC0 1.0 Universal License. To the extent -possible under law, Christoph Peters has waived all copyright and related or -neighboring rights to the following code. This work is published from -Germany. https://creativecommons.org/publicdomain/zero/1.0/ """ + import os import numpy as np @@ -27,16 +20,27 @@ def uv_calculations(n): uvs = [] - for i in range (0,n): - a = (n-(i+1))/n - b = (n-i)/n - #glyph_coord [0, a], [0, b], [1, b], [1, a] - uvs.extend([[.01, a+.01], [.01, b-.01], [.99, b-.01], [.99, a+.01], - [.01, a+.01], [.01, b-.01], [.99, b-.01], [.99, a+.01]]) + for i in range(0, n): + a = (n - (i + 1)) / n + b = (n - i) / n + # glyph_coord [0, a], [0, b], [1, b], [1, a] + uvs.extend( + [ + [0.01, a + 0.01], + [0.01, b - 0.01], + [0.99, b - 0.01], + [0.99, a + 0.01], + [0.01, a + 0.01], + [0.01, b - 0.01], + [0.99, b - 0.01], + [0.99, a + 0.01], + ] + ) return uvs + if __name__ == "__main__": - show_man = window.ShowManager(size=(1920, 1080)) + show_man = window.ShowManager(size=(1280, 720)) show_man.scene.background((1, 1, 1)) # fmt: off @@ -44,19 +48,19 @@ def uv_calculations(n): [ -0.2739740312099, 0.2526670396328, 1.8922271728516, 0.2878578901291, -0.5339795947075, -0.2620058953762, 0.1580424904823, 0.0329004973173, -0.1322413831949, -0.1332057565451, - 1.0894461870193, -0.6319401264191, -0.0416776277125, -1.0772529840469, 0.1423762738705, + 1.0894461870193, -0.6319401264191, -0.0416776277125, -1.0772529840469, 0.1423762738705, 0.7941166162491, 0.7490307092667, -0.3428381681442, 0.1024847552180, -0.0219132602215, 0.0499043911695, 0.2162453681231, 0.0921059995890, -0.2611238956451, 0.2549301385880, -0.4534865319729, 0.1922748684883, -0.6200597286224 ] ]) - + """ , -0.0532187558711, -0.3569841980934, - 0.0293972902000, -0.1977960765362, -0.1058669015765, 0.2372217923403, -0.1856198310852, + 0.0293972902000, -0.1977960765362, -0.1058669015765, 0.2372217923403, -0.1856198310852, -0.3373193442822, -0.0750469490886, 0.2146576642990, -0.0490148440003, 0.1288588196039, 0.3173974752426, 0.1990085393190, -0.1736343950033, -0.0482443645597, 0.1749017387629, - -0.0151847425660, 0.0418366046081, 0.0863263587216, -0.0649211244490, 0.0126096132283, + -0.0151847425660, 0.0418366046081, 0.0863263587216, -0.0649211244490, 0.0126096132283, 0.0545089217982, -0.0275142164626, 0.0399986574832, -0.0468244261610, -0.1292105653111, -0.0786858322658, -0.0663828464882, 0.0382439706831, -0.0041550330365, -0.0502800566338, -0.0732471630735, 0.0181751900972, -0.0090119333757, -0.0604443282359, -0.1469985252752, @@ -179,7 +183,7 @@ def uv_calculations(n): in vec3 centerMCVSOutput; in vec2 minmaxVSOutput; """ - + coeffs_norm = """ float coeffsNorm(float coef) { @@ -191,40 +195,52 @@ def uv_calculations(n): } """ - eval_sh_2 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_2.frag")) + eval_sh_2 = import_fury_shader( + os.path.join("rt_odfs", "tournier", "eval_sh_2.frag") + ) - eval_sh_4 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_4.frag")) + eval_sh_4 = import_fury_shader( + os.path.join("rt_odfs", "tournier", "eval_sh_4.frag") + ) - eval_sh_6 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_6.frag")) + eval_sh_6 = import_fury_shader( + os.path.join("rt_odfs", "tournier", "eval_sh_6.frag") + ) - eval_sh_8 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_8.frag")) + eval_sh_8 = import_fury_shader( + os.path.join("rt_odfs", "tournier", "eval_sh_8.frag") + ) - eval_sh_10 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_10.frag")) + eval_sh_10 = import_fury_shader( + os.path.join("rt_odfs", "tournier", "eval_sh_10.frag") + ) - eval_sh_12 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_12.frag")) + eval_sh_12 = import_fury_shader( + os.path.join("rt_odfs", "tournier", "eval_sh_12.frag") + ) eval_sh_grad_2 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_2.frag") + os.path.join("rt_odfs", "tournier", "eval_sh_grad_2.frag") ) eval_sh_grad_4 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_4.frag") + os.path.join("rt_odfs", "tournier", "eval_sh_grad_4.frag") ) eval_sh_grad_6 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_6.frag") + os.path.join("rt_odfs", "tournier", "eval_sh_grad_6.frag") ) eval_sh_grad_8 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_8.frag") + os.path.join("rt_odfs", "tournier", "eval_sh_grad_8.frag") ) eval_sh_grad_10 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_10.frag") + os.path.join("rt_odfs", "tournier", "eval_sh_grad_10.frag") ) eval_sh_grad_12 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_12.frag") + os.path.join("rt_odfs", "tournier", "eval_sh_grad_12.frag") ) # Searches a single root of a polynomial within a given interval. @@ -379,7 +395,7 @@ def uv_calculations(n): sh_coeffs[j] = coeffsNorm(texture(texture0, vec2(i + j / numCoeffs, tcoordVCVSOutput.y)).x); } """ - + # Perform the intersection test intersection_test = """ float ray_params[MAX_DEGREE]; @@ -435,11 +451,11 @@ def uv_calculations(n): sphere = get_sphere("repulsion724") sh_basis = "descoteaux07" - #sh_basis = "tournier07" + # sh_basis = "tournier07" sh_order = 6 n = int((sh_order / 2) + 1) - sz = 2 * n ** 2 - n + sz = 2 * n**2 - n sh = np.zeros((1, 1, 1, sz)) sh[0, 0, 0, :] = coeffs[0, :sz] diff --git a/docs/experimental/SH-ODF_experimental/ray_traced_6.0.py b/docs/experimental/SH-ODF_experimental/ray_traced_6.0.py index 6c2bdc723..c44117830 100644 --- a/docs/experimental/SH-ODF_experimental/ray_traced_6.0.py +++ b/docs/experimental/SH-ODF_experimental/ray_traced_6.0.py @@ -187,40 +187,52 @@ def uv_calculations(n): } """ - eval_sh_2 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_2.frag")) + eval_sh_2 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_2.frag") + ) - eval_sh_4 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_4.frag")) + eval_sh_4 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_4.frag") + ) - eval_sh_6 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_6.frag")) + eval_sh_6 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_6.frag") + ) - eval_sh_8 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_8.frag")) + eval_sh_8 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_8.frag") + ) - eval_sh_10 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_10.frag")) + eval_sh_10 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_10.frag") + ) - eval_sh_12 = import_fury_shader(os.path.join("rt_odfs", "eval_sh_12.frag")) + eval_sh_12 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_12.frag") + ) eval_sh_grad_2 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_2.frag") + os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_2.frag") ) eval_sh_grad_4 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_4.frag") + os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_4.frag") ) eval_sh_grad_6 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_6.frag") + os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_6.frag") ) eval_sh_grad_8 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_8.frag") + os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_8.frag") ) eval_sh_grad_10 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_10.frag") + os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_10.frag") ) eval_sh_grad_12 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_12.frag") + os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_12.frag") ) # Searches a single root of a polynomial within a given interval. diff --git a/docs/experimental/SH-ODF_experimental/ray_traced_7.0.py b/docs/experimental/SH-ODF_experimental/ray_traced_7.0.py index 0302d8834..c455794a1 100644 --- a/docs/experimental/SH-ODF_experimental/ray_traced_7.0.py +++ b/docs/experimental/SH-ODF_experimental/ray_traced_7.0.py @@ -191,52 +191,55 @@ def uv_calculations(n): } """ + # sh_basis = "descoteaux" + sh_basis = "tournier" + eval_sh_2 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_2 copy.frag") + os.path.join("rt_odfs", sh_basis, "eval_sh_2.frag") ) eval_sh_4 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_4 copy.frag") + os.path.join("rt_odfs", sh_basis, "eval_sh_4.frag") ) eval_sh_6 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_6 copy.frag") + os.path.join("rt_odfs", sh_basis, "eval_sh_6.frag") ) eval_sh_8 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_8 copy.frag") + os.path.join("rt_odfs", sh_basis, "eval_sh_8.frag") ) eval_sh_10 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_10 copy.frag") + os.path.join("rt_odfs", sh_basis, "eval_sh_10.frag") ) eval_sh_12 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_12 copy.frag") + os.path.join("rt_odfs", sh_basis, "eval_sh_12.frag") ) eval_sh_grad_2 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_2.frag") + os.path.join("rt_odfs", sh_basis, "eval_sh_grad_2.frag") ) eval_sh_grad_4 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_4.frag") + os.path.join("rt_odfs", sh_basis, "eval_sh_grad_4.frag") ) eval_sh_grad_6 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_6.frag") + os.path.join("rt_odfs", sh_basis, "eval_sh_grad_6.frag") ) eval_sh_grad_8 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_8.frag") + os.path.join("rt_odfs", sh_basis, "eval_sh_grad_8.frag") ) eval_sh_grad_10 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_10.frag") + os.path.join("rt_odfs", sh_basis, "eval_sh_grad_10.frag") ) eval_sh_grad_12 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_12.frag") + os.path.join("rt_odfs", sh_basis, "eval_sh_grad_12.frag") ) # Searches a single root of a polynomial within a given interval. From 8f71a149732d50e858c0360f252b5301b2fc9c5b Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Thu, 29 Feb 2024 19:50:04 -0500 Subject: [PATCH 065/118] Added ray_traced_6.5.py to debug performance issues. --- .../SH-ODF_experimental/ray_traced_6.5.py | 434 ++++++++++++++++++ 1 file changed, 434 insertions(+) create mode 100644 docs/experimental/SH-ODF_experimental/ray_traced_6.5.py diff --git a/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py b/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py new file mode 100644 index 000000000..e92110c99 --- /dev/null +++ b/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py @@ -0,0 +1,434 @@ +""" +""" + +import os + +import numpy as np +from dipy.data.fetcher import dipy_home +from dipy.io.image import load_nifti + +from fury import actor, window +from fury.lib import FloatArray, Texture +from fury.shaders import ( + attribute_to_actor, + compose_shader, + import_fury_shader, + shader_to_actor, +) +from fury.utils import numpy_to_vtk_image_data, set_polydata_tcoords + + +def uv_calculations(n): + uvs = [] + for i in range(0, n): + a = (n - (i + 1)) / n + b = (n - i) / n + # glyph_coord [0, a], [0, b], [1, b], [1, a] + uvs.extend( + [ + [0.001, a + 0.001], + [0.001, b - 0.001], + [0.999, b - 0.001], + [0.999, a + 0.001], + [0.001, a + 0.001], + [0.001, b - 0.001], + [0.999, b - 0.001], + [0.999, a + 0.001], + ] + ) + return uvs + + +if __name__ == "__main__": + show_man = window.ShowManager(size=(1280, 720)) + + dataset_dir = os.path.join(dipy_home, "stanford_hardi") + + coeffs, affine = load_nifti( + os.path.join(dataset_dir, "9x11_debug_sh_coeffs.nii.gz") + ) + + sh_count = coeffs.shape[-1] + + sh_degree = int ((np.sqrt(8 * sh_count + 1) - 3) / 2) + + valid_mask = np.abs(coeffs).max(axis=(-1)) > 0 + indices = np.nonzero(valid_mask) + + centers = np.asarray(indices).T + + x, y, z, s = coeffs.shape + coeffs = coeffs[:, :, :].reshape((x * y * z, s)) + n_glyphs = coeffs.shape[0] + + max_val = coeffs.min(axis=1) + total = np.sum(abs(coeffs), axis=1) + coeffs = np.dot(np.diag(1 / total), coeffs) * 1.7 + + odf_actor = actor.box(centers=centers, scales=1) + odf_actor.GetMapper().SetVBOShiftScaleMethod(False) + + big_centers = np.repeat(centers, 8, axis=0) + attribute_to_actor(odf_actor, big_centers, "center") + + minmax = np.array([coeffs.min(axis=1), coeffs.max(axis=1)]).T + big_minmax = np.repeat(minmax, 8, axis=0) + attribute_to_actor(odf_actor, big_minmax, "minmax") + + odf_actor_pd = odf_actor.GetMapper().GetInput() + + uv_vals = np.array(uv_calculations(n_glyphs)) + + num_pnts = uv_vals.shape[0] + + t_coords = FloatArray() + t_coords.SetNumberOfComponents(2) + t_coords.SetNumberOfTuples(num_pnts) + [t_coords.SetTuple(i, uv_vals[i]) for i in range(num_pnts)] + + set_polydata_tcoords(odf_actor_pd, t_coords) + + min = coeffs.min(axis=1) + max = coeffs.max(axis=1) + newmin = 0 + newmax = 1 + arr = np.array( + [ + (coeffs[i] - min[i]) * ((newmax - newmin) / (max[i] - min[i])) + + newmin + for i in range(coeffs.shape[0]) + ] + ) + arr *= 255 + grid = numpy_to_vtk_image_data(arr.astype(np.uint8)) + + texture = Texture() + texture.SetInputDataObject(grid) + texture.Update() + + odf_actor.GetProperty().SetTexture("texture0", texture) + + # TODO: Set int uniform + odf_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniformf( + "numCoeffs", sh_count + ) + + vs_dec = """ + in vec3 center; + in vec2 minmax; + + out vec4 vertexMCVSOutput; + out vec3 centerMCVSOutput; + out vec2 minmaxVSOutput; + out vec3 camPosMCVSOutput; + out vec3 camRightMCVSOutput; + out vec3 camUpMCVSOutput; + """ + + vs_impl = """ + vertexMCVSOutput = vertexMC; + centerMCVSOutput = center; + minmaxVSOutput = minmax; + camPosMCVSOutput = -MCVCMatrix[3].xyz * mat3(MCVCMatrix); + camRightMCVSOutput = vec3( + MCVCMatrix[0][0], MCVCMatrix[1][0], MCVCMatrix[2][0]); + camUpMCVSOutput = vec3( + MCVCMatrix[0][1], MCVCMatrix[1][1], MCVCMatrix[2][1]); + """ + + shader_to_actor(odf_actor, "vertex", decl_code=vs_dec, impl_code=vs_impl) + + # The index of the highest used band of the spherical harmonics basis. Must + # be even, at least 2 and at most 12. + def_sh_degree = "#define SH_DEGREE 6" + + # The number of spherical harmonics basis functions + def_sh_count = "#define SH_COUNT (((SH_DEGREE + 1) * (SH_DEGREE + 2)) / 2)" + + # Degree of polynomials for which we have to find roots + def_max_degree = "#define MAX_DEGREE (2 * SH_DEGREE + 2)" + + # If GL_EXT_control_flow_attributes is available, these defines should be + # defined as [[unroll]] and [[loop]] to give reasonable hints to the + # compiler. That avoids register spilling, which makes execution + # considerably faster. + def_gl_ext_control_flow_attributes = """ + #ifndef _unroll_ + #define _unroll_ + #endif + #ifndef _loop_ + #define _loop_ + #endif + """ + + # When there are fewer intersections/roots than theoretically possible, + # some array entries are set to this value + def_no_intersection = "#define NO_INTERSECTION 3.4e38" + + # pi and its reciprocal + def_pis = """ + #define M_PI 3.141592653589793238462643 + #define M_INV_PI 0.318309886183790671537767526745 + """ + + fs_vs_vars = """ + in vec4 vertexMCVSOutput; + in vec3 centerMCVSOutput; + in vec2 minmaxVSOutput; + in vec3 camPosMCVSOutput; + in vec3 camRightMCVSOutput; + in vec3 camUpMCVSOutput; + """ + + coeffs_norm = """ + float coeffsNorm(float coef) + { + float min = 0; + float max = 1; + float newMin = minmaxVSOutput.x; + float newMax = minmaxVSOutput.y; + return (coef - min) * ((newMax - newMin) / (max - min)) + newMin; + } + """ + + eval_sh_2 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_2.frag") + ) + + eval_sh_4 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_4.frag") + ) + + eval_sh_6 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_6.frag") + ) + + eval_sh_8 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_8.frag") + ) + + eval_sh_10 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_10.frag") + ) + + eval_sh_12 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_12.frag") + ) + + eval_sh_grad_2 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_2.frag") + ) + + eval_sh_grad_4 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_4.frag") + ) + + eval_sh_grad_6 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_6.frag") + ) + + eval_sh_grad_8 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_8.frag") + ) + + eval_sh_grad_10 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_10.frag") + ) + + eval_sh_grad_12 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_12.frag") + ) + + # Searches a single root of a polynomial within a given interval. + # param out_root The location of the found root. + # param out_end_value The value of the given polynomial at end. + # param poly Coefficients of the polynomial for which a root should be + # found. + # Coefficient poly[i] is multiplied by x^i. + # param begin The beginning of an interval where the polynomial is + # monotonic. + # param end The end of said interval. + # param begin_value The value of the given polynomial at begin. + # param error_tolerance The error tolerance for the returned root + # location. + # Typically the error will be much lower but in theory it can be + # bigger. + # + # return true if a root was found, false if no root exists. + newton_bisection = import_fury_shader( + os.path.join("rt_odfs", "newton_bisection.frag") + ) + + # Finds all roots of the given polynomial in the interval [begin, end] and + # writes them to out_roots. Some entries will be NO_INTERSECTION but other + # than that the array is sorted. The last entry is always NO_INTERSECTION. + find_roots = import_fury_shader(os.path.join("rt_odfs", "find_roots.frag")) + + # Evaluates the spherical harmonics basis in bands 0, 2, ..., SH_DEGREE. + # Conventions are as in the following paper. + # M. Descoteaux, E. Angelino, S. Fitzgibbons, and R. Deriche. Regularized, + # fast, and robust analytical q-ball imaging. Magnetic Resonance in + # Medicine, 58(3), 2007. https://doi.org/10.1002/mrm.21277 + # param out_shs Values of SH basis functions in bands 0, 2, ..., + # SH_DEGREE in this order. + # param point The point on the unit sphere where the basis should be + # evaluated. + eval_sh = import_fury_shader(os.path.join("rt_odfs", "eval_sh.frag")) + + # Evaluates the gradient of each basis function given by eval_sh() and the + # basis itself + eval_sh_grad = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad.frag") + ) + + # Outputs a matrix that turns equidistant samples on the unit circle of a + # homogeneous polynomial into coefficients of that polynomial. + get_inv_vandermonde = import_fury_shader( + os.path.join("rt_odfs", "get_inv_vandermonde.frag") + ) + + # Determines all intersections between a ray and a spherical harmonics + # glyph. + # param out_ray_params The ray parameters at intersection points. The + # points themselves are at ray_origin + out_ray_params[i] * ray_dir. + # Some entries may be NO_INTERSECTION but other than that the array + # is sorted. + # param sh_coeffs SH_COUNT spherical harmonic coefficients defining the + # glyph. Their exact meaning is defined by eval_sh(). + # param ray_origin The origin of the ray, relative to the glyph center. + # param ray_dir The normalized direction vector of the ray. + ray_sh_glyph_intersections = import_fury_shader( + os.path.join("rt_odfs", "ray_sh_glyph_intersections.frag") + ) + + # Provides a normalized normal vector for a spherical harmonics glyph. + # param sh_coeffs SH_COUNT spherical harmonic coefficients defining the + # glyph. Their exact meaning is defined by eval_sh(). + # param point A point on the surface of the glyph, relative to its + # center. + # + # return A normalized surface normal pointing away from the origin. + get_sh_glyph_normal = import_fury_shader( + os.path.join("rt_odfs", "get_sh_glyph_normal.frag") + ) + + # Applies the non-linearity that maps linear RGB to sRGB + linear_to_srgb = import_fury_shader( + os.path.join("rt_odfs", "linear_to_srgb.frag") + ) + + # Inverse of linear_to_srgb() + srgb_to_linear = import_fury_shader( + os.path.join("rt_odfs", "srgb_to_linear.frag") + ) + + # Turns a linear RGB color (i.e. rec. 709) into sRGB + linear_rgb_to_srgb = import_fury_shader( + os.path.join("rt_odfs", "linear_rgb_to_srgb.frag") + ) + + # Inverse of linear_rgb_to_srgb() + srgb_to_linear_rgb = import_fury_shader( + os.path.join("rt_odfs", "srgb_to_linear_rgb.frag") + ) + + # Logarithmic tonemapping operator. Input and output are linear RGB. + tonemap = import_fury_shader(os.path.join("rt_odfs", "tonemap.frag")) + + # Blinn-Phong illumination model + blinn_phong_model = import_fury_shader( + os.path.join("lighting", "blinn_phong_model.frag") + ) + + # fmt: off + fs_dec = compose_shader([ + def_sh_degree, def_sh_count, def_max_degree, + def_gl_ext_control_flow_attributes, def_no_intersection, def_pis, + fs_vs_vars, coeffs_norm, eval_sh_2, eval_sh_4, eval_sh_6, eval_sh_8, + eval_sh_10, eval_sh_12, eval_sh_grad_2, eval_sh_grad_4, eval_sh_grad_6, + eval_sh_grad_8, eval_sh_grad_10, eval_sh_grad_12, newton_bisection, + find_roots, eval_sh, eval_sh_grad, get_inv_vandermonde, + ray_sh_glyph_intersections, get_sh_glyph_normal, blinn_phong_model, + linear_to_srgb, srgb_to_linear, linear_rgb_to_srgb, srgb_to_linear_rgb, + tonemap + ]) + # fmt: on + + shader_to_actor(odf_actor, "fragment", decl_code=fs_dec) + + point_from_vs = "vec3 pnt = vertexMCVSOutput.xyz;" + + # Ray origin is the camera position in world space + ray_origin = "vec3 ro = camPosMCVSOutput;" + + # TODO: Check aspect for automatic scaling + # Ray direction is the normalized difference between the fragment and the + # camera position/ray origin + ray_direction = "vec3 rd = normalize(pnt - ro);" + + # Light direction in a retroreflective model is the normalized difference + # between the camera position/ray origin and the fragment + light_direction = "vec3 ld = normalize(ro - pnt);" + + # Define SH coefficients (measured up to band 8, noise beyond that) + sh_coeffs = """ + float i = 1 / (numCoeffs * 2); + float sh_coeffs[SH_COUNT]; + for(int j=0; j 0.0) { + first_ray_param = ray_params[i]; + break; + } + } + """ + + # Evaluate shading for a directional light + directional_light = """ + vec3 color = vec3(1.); + if (first_ray_param != NO_INTERSECTION) { + vec3 intersection = ro - centerMCVSOutput + first_ray_param * rd; + vec3 normal = get_sh_glyph_normal(sh_coeffs, intersection); + vec3 colorDir = srgb_to_linear_rgb(abs(normalize(intersection))); + float attenuation = dot(ld, normal); + color = blinnPhongIllumModel( + //attenuation, lightColor0, diffuseColor, specularPower, + attenuation, lightColor0, colorDir, specularPower, + specularColor, ambientColor); + } else { + discard; + } + """ + + frag_output = """ + //vec4 out_color = vec4(linear_rgb_to_srgb(tonemap(color)), 1.0); + vec3 out_color = linear_rgb_to_srgb(tonemap(color)); + fragOutput0 = vec4(out_color, opacity); + //fragOutput0 = vec4(color, opacity); + """ + + # fmt: off + fs_impl = compose_shader([ + point_from_vs, ray_origin, ray_direction, light_direction, sh_coeffs, + intersection_test, first_intersection, directional_light, frag_output + ]) + # fmt: on + + shader_to_actor(odf_actor, "fragment", impl_code=fs_impl, block="picking") + show_man.scene.add(odf_actor) + + show_man.start() From 66dda5d94d1f1e904d0bc74303c8d37026b2ec0f Mon Sep 17 00:00:00 2001 From: tvcastillod Date: Fri, 1 Mar 2024 11:39:22 -0500 Subject: [PATCH 066/118] added degree param --- .../SH-ODF experimental/odf_example.py | 37 +++++++++- fury/actor.py | 20 ++++- fury/actors/odf.py | 74 +++++-------------- ...grad_10 copy.frag => eval_sh_grad_10.frag} | 0 ...grad_12 copy.frag => eval_sh_grad_12.frag} | 0 ...h_grad_2 copy.frag => eval_sh_grad_2.frag} | 0 ...h_grad_4 copy.frag => eval_sh_grad_4.frag} | 0 ...h_grad_6 copy.frag => eval_sh_grad_6.frag} | 0 ...h_grad_8 copy.frag => eval_sh_grad_8.frag} | 0 9 files changed, 72 insertions(+), 59 deletions(-) rename fury/shaders/rt_odfs/tournier/{eval_sh_grad_10 copy.frag => eval_sh_grad_10.frag} (100%) rename fury/shaders/rt_odfs/tournier/{eval_sh_grad_12 copy.frag => eval_sh_grad_12.frag} (100%) rename fury/shaders/rt_odfs/tournier/{eval_sh_grad_2 copy.frag => eval_sh_grad_2.frag} (100%) rename fury/shaders/rt_odfs/tournier/{eval_sh_grad_4 copy.frag => eval_sh_grad_4.frag} (100%) rename fury/shaders/rt_odfs/tournier/{eval_sh_grad_6 copy.frag => eval_sh_grad_6.frag} (100%) rename fury/shaders/rt_odfs/tournier/{eval_sh_grad_8 copy.frag => eval_sh_grad_8.frag} (100%) diff --git a/docs/experimental/SH-ODF experimental/odf_example.py b/docs/experimental/SH-ODF experimental/odf_example.py index e16858211..50978942d 100644 --- a/docs/experimental/SH-ODF experimental/odf_example.py +++ b/docs/experimental/SH-ODF experimental/odf_example.py @@ -20,8 +20,39 @@ x, y, z, s = coeffs.shape coeffs = coeffs[:, :, :].reshape((x * y * z, s)) - n_glyphs = coeffs.shape[0] - - odf_actor = actor.odf(centers=centers, coeffs=coeffs, scales=1.0) + + #''' + coeffs = np.array([ + [ + -0.2739740312099, 0.2526670396328, 1.8922271728516, 0.2878578901291, + -0.5339795947075, -0.2620058953762, 0.1580424904823, 0.0329004973173, + -0.1322413831949, -0.1332057565451, 1.0894461870193, -0.6319401264191, + -0.0416776277125, -1.0772529840469, 0.1423762738705, 0.7941166162491, + 0.7490307092667, -0.3428381681442, 0.1024847552180, -0.0219132602215, + 0.0499043911695, 0.2162453681231, 0.0921059995890, -0.2611238956451, + 0.2549301385880, -0.4534865319729, 0.1922748684883, -0.6200597286224, + -0.0532187558711, -0.3569841980934, 0.0293972902000, -0.1977960765362, + -0.1058669015765, 0.2372217923403, -0.1856198310852, -0.3373193442822, + -0.0750469490886, 0.2146576642990, -0.0490148440003, 0.1288588196039, + 0.3173974752426, 0.1990085393190, -0.1736343950033, -0.0482443645597, + 0.1749017387629, -0.0151847425660, 0.0418366046081, 0.0863263587216, + -0.0649211244490, 0.0126096132283, 0.0545089217982, -0.0275142164626, + 0.0399986574832, -0.0468244261610, -0.1292105653111, -0.0786858322658, + -0.0663828464882, 0.0382439706831, -0.0041550330365, -0.0502800566338, + -0.0732471630735, 0.0181751900972, -0.0090119333757, -0.0604443282359, + -0.1469985252752, -0.0534046899715, -0.0896672753415, -0.0130841364808, + -0.0112942893801, 0.0272257498541, 0.0626717616331, -0.0222197983050, + -0.0018541504308, -0.1653251944056, 0.0409697402846, 0.0749921454327, + -0.0282830872616, 0.0006909458525, 0.0625599842287, 0.0812529816082, + 0.0914693020772, -0.1197222726745, 0.0376277453183, -0.0832617004142, + -0.0482175038043, -0.0839003635737, -0.0349423908400, 0.1204519568256, + 0.0783745984003, 0.0297401205976, -0.0505947662525 + ] + ]) + centers= np.array([0, 0, 0]) + #''' + + odf_actor = actor.odf(centers=centers, coeffs=coeffs, scales=1.0, + basis_type='descoteaux', degree=6) show_man.scene.add(odf_actor) show_man.start() \ No newline at end of file diff --git a/fury/actor.py b/fury/actor.py index cb630a365..085c9aa79 100644 --- a/fury/actor.py +++ b/fury/actor.py @@ -3873,6 +3873,7 @@ def ellipsoid( def odf( centers, coeffs, + degree=4, basis_type='descoteaux', scales=1.0, opacity=1.0 @@ -3887,6 +3888,9 @@ def odf( ODFs positions. coeffs : ndarray 2D ODFs array in SH coefficients. + degree: int, optional + Index of the highest used band of the spherical harmonics basis. Must + be even, at least 2 and at most 12. basis_type: str, optional Type of basis (descoteaux, tournier) 'descoteaux' for the default ``descoteaux07`` DYPY basis. @@ -3906,6 +3910,20 @@ def odf( centers = np.array(centers) if centers.ndim == 1: centers = np.array([centers]) + + if not isinstance(coeffs, np.ndarray): + coeffs = np.array(coeffs) + + coeffs_given = coeffs.shape[1] + coeffs_needed = int(((degree + 1) * (degree + 2)) / 2) + if degree % 2 != 0: + raise ValueError('degree must be even') + if coeffs_given < coeffs_needed: + raise ValueError( + 'Not enough number of coefficient for SH of degree {0}. ' + 'Expected at least {1}'.format(degree, coeffs_needed)) + else: + coeffs = coeffs[:, :coeffs_needed] if not isinstance(scales, np.ndarray): scales = np.array(scales) @@ -3918,4 +3936,4 @@ def odf( total = np.sum(abs(coeffs), axis=1) coeffs = np.dot(np.diag(1 / total * scales), coeffs) * 1.7 - return sh_odf(centers, coeffs, basis_type, scales, opacity) \ No newline at end of file + return sh_odf(centers, coeffs, degree, basis_type, scales, opacity) \ No newline at end of file diff --git a/fury/actors/odf.py b/fury/actors/odf.py index e8a762c55..139567a56 100644 --- a/fury/actors/odf.py +++ b/fury/actors/odf.py @@ -32,14 +32,13 @@ def uv_calculations(n): return uvs def minmax_norm(data): - min = data.min(axis=1) max = data.max(axis=1) return np.array([(data[i] - min[i]) / (max[i] - min[i]) for i in range(data.shape[0])]) -def sh_odf(centers, coeffs, basis_type, scales, opacity): +def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): """ Visualize one or many ODFs with different features. @@ -53,6 +52,9 @@ def sh_odf(centers, coeffs, basis_type, scales, opacity): Type of basis (descoteaux, tournier) 'descoteaux' for the default ``descoteaux07`` DYPY basis. 'tournier' for the default ``tournier07` DYPY basis. + degree: int, optional + Index of the highest used band of the spherical harmonics basis. Must + be even, at least 2 and at most 12. scales : float or ndarray (N, ) ODFs size. opacity : float @@ -108,7 +110,7 @@ def sh_odf(centers, coeffs, basis_type, scales, opacity): # The number of coefficients is associated to the order of the SH odf_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniformf( - "numCoeffs", 15 + "numCoeffs", ((degree + 1) * (degree + 2)) / 2 ) # Start of shader implementation @@ -142,7 +144,7 @@ def sh_odf(centers, coeffs, basis_type, scales, opacity): # The index of the highest used band of the spherical harmonics basis. Must # be even, at least 2 and at most 12. - def_sh_degree = "#define SH_DEGREE 4" + def_sh_degree = "#define SH_DEGREE " + str(degree) # The number of spherical harmonics basis functions def_sh_count = "#define SH_COUNT (((SH_DEGREE + 1) * (SH_DEGREE + 2)) / 2)" @@ -187,47 +189,14 @@ def sh_odf(centers, coeffs, basis_type, scales, opacity): coeffs_norm = import_fury_shader(os.path.join("utils", "minmax_norm.glsl")) - eval_sh_2 = import_fury_shader( - os.path.join("rt_odfs", basis_type, "eval_sh_2.frag")) - - eval_sh_4 = import_fury_shader( - os.path.join("rt_odfs", basis_type, "eval_sh_4.frag")) - - eval_sh_6 = import_fury_shader( - os.path.join("rt_odfs", basis_type, "eval_sh_6.frag")) - - eval_sh_8 = import_fury_shader( - os.path.join("rt_odfs", basis_type, "eval_sh_8.frag")) - - eval_sh_10 = import_fury_shader( - os.path.join("rt_odfs", basis_type, "eval_sh_10.frag")) - - eval_sh_12 = import_fury_shader( - os.path.join("rt_odfs", basis_type, "eval_sh_12.frag")) - - eval_sh_grad_2 = import_fury_shader( - os.path.join("rt_odfs/descoteaux", "eval_sh_grad_2.frag") - ) - - eval_sh_grad_4 = import_fury_shader( - os.path.join("rt_odfs/descoteaux", "eval_sh_grad_4.frag") - ) - - eval_sh_grad_6 = import_fury_shader( - os.path.join("rt_odfs/descoteaux", "eval_sh_grad_6.frag") - ) - - eval_sh_grad_8 = import_fury_shader( - os.path.join("rt_odfs/descoteaux", "eval_sh_grad_8.frag") - ) - - eval_sh_grad_10 = import_fury_shader( - os.path.join("rt_odfs/descoteaux", "eval_sh_grad_10.frag") - ) - - eval_sh_grad_12 = import_fury_shader( - os.path.join("rt_odfs/descoteaux", "eval_sh_grad_12.frag") - ) + eval_sh_list = '' + for i in range (2, degree+1, 2): + eval_sh = import_fury_shader( + os.path.join("rt_odfs", basis_type, 'eval_sh_' + str(i) + '.frag')) + eval_sh_grad = import_fury_shader( + os.path.join("rt_odfs", basis_type, + 'eval_sh_grad_' + str(i) + '.frag')) + eval_sh_list = eval_sh_list + '\n\n' + eval_sh + '\n\n' + eval_sh_grad # Searches a single root of a polynomial within a given interval. # param out_root The location of the found root. @@ -334,13 +303,10 @@ def sh_odf(centers, coeffs, basis_type, scales, opacity): fs_dec = compose_shader([ def_sh_degree, def_sh_count, def_max_degree, def_gl_ext_control_flow_attributes, def_no_intersection, def_pis, - fs_vs_vars, coeffs_norm, eval_sh_2, eval_sh_4, eval_sh_6, eval_sh_8, - eval_sh_10, eval_sh_12, eval_sh_grad_2, eval_sh_grad_4, eval_sh_grad_6, - eval_sh_grad_8, eval_sh_grad_10, eval_sh_grad_12, newton_bisection, - find_roots, eval_sh, eval_sh_grad, get_inv_vandermonde, - ray_sh_glyph_intersections, get_sh_glyph_normal, blinn_phong_model, - linear_to_srgb, srgb_to_linear, linear_rgb_to_srgb, srgb_to_linear_rgb, - tonemap + fs_vs_vars, coeffs_norm, eval_sh_list, newton_bisection, find_roots, + eval_sh, eval_sh_grad, get_inv_vandermonde, ray_sh_glyph_intersections, + get_sh_glyph_normal, blinn_phong_model, linear_to_srgb, srgb_to_linear, + linear_rgb_to_srgb, srgb_to_linear_rgb, tonemap ]) # fmt: on @@ -351,7 +317,6 @@ def sh_odf(centers, coeffs, basis_type, scales, opacity): # Ray origin is the camera position in world space ray_origin = "vec3 ro = camPosMCVSOutput;" - # TODO: Check aspect for automatic scaling # Ray direction is the normalized difference between the fragment and the # camera position/ray origin ray_direction = "vec3 rd = normalize(pnt - ro);" @@ -392,7 +357,7 @@ def sh_odf(centers, coeffs, basis_type, scales, opacity): break; } } - """ + """ # Evaluate shading for a directional light directional_light = \ @@ -404,7 +369,6 @@ def sh_odf(centers, coeffs, basis_type, scales, opacity): vec3 colorDir = srgb_to_linear_rgb(abs(normalize(intersection))); float attenuation = dot(ld, normal); color = blinnPhongIllumModel( - //attenuation, lightColor0, diffuseColor, specularPower, attenuation, lightColor0, colorDir, specularPower, specularColor, ambientColor); } else { diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_10 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_10.frag similarity index 100% rename from fury/shaders/rt_odfs/tournier/eval_sh_grad_10 copy.frag rename to fury/shaders/rt_odfs/tournier/eval_sh_grad_10.frag diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_12 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_12.frag similarity index 100% rename from fury/shaders/rt_odfs/tournier/eval_sh_grad_12 copy.frag rename to fury/shaders/rt_odfs/tournier/eval_sh_grad_12.frag diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_2 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_2.frag similarity index 100% rename from fury/shaders/rt_odfs/tournier/eval_sh_grad_2 copy.frag rename to fury/shaders/rt_odfs/tournier/eval_sh_grad_2.frag diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_4 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_4.frag similarity index 100% rename from fury/shaders/rt_odfs/tournier/eval_sh_grad_4 copy.frag rename to fury/shaders/rt_odfs/tournier/eval_sh_grad_4.frag diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_6 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_6.frag similarity index 100% rename from fury/shaders/rt_odfs/tournier/eval_sh_grad_6 copy.frag rename to fury/shaders/rt_odfs/tournier/eval_sh_grad_6.frag diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_8 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_8.frag similarity index 100% rename from fury/shaders/rt_odfs/tournier/eval_sh_grad_8 copy.frag rename to fury/shaders/rt_odfs/tournier/eval_sh_grad_8.frag From badb5a9782a1e587ba3ed65fd2f77394ec952c3d Mon Sep 17 00:00:00 2001 From: tvcastillod Date: Wed, 6 Mar 2024 18:05:58 -0500 Subject: [PATCH 067/118] adjusted the degree setting --- .../SH-ODF experimental/odf_example.py | 13 +------- fury/actor.py | 31 ++++++++++++------- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/docs/experimental/SH-ODF experimental/odf_example.py b/docs/experimental/SH-ODF experimental/odf_example.py index 50978942d..c31dac722 100644 --- a/docs/experimental/SH-ODF experimental/odf_example.py +++ b/docs/experimental/SH-ODF experimental/odf_example.py @@ -35,18 +35,7 @@ -0.1058669015765, 0.2372217923403, -0.1856198310852, -0.3373193442822, -0.0750469490886, 0.2146576642990, -0.0490148440003, 0.1288588196039, 0.3173974752426, 0.1990085393190, -0.1736343950033, -0.0482443645597, - 0.1749017387629, -0.0151847425660, 0.0418366046081, 0.0863263587216, - -0.0649211244490, 0.0126096132283, 0.0545089217982, -0.0275142164626, - 0.0399986574832, -0.0468244261610, -0.1292105653111, -0.0786858322658, - -0.0663828464882, 0.0382439706831, -0.0041550330365, -0.0502800566338, - -0.0732471630735, 0.0181751900972, -0.0090119333757, -0.0604443282359, - -0.1469985252752, -0.0534046899715, -0.0896672753415, -0.0130841364808, - -0.0112942893801, 0.0272257498541, 0.0626717616331, -0.0222197983050, - -0.0018541504308, -0.1653251944056, 0.0409697402846, 0.0749921454327, - -0.0282830872616, 0.0006909458525, 0.0625599842287, 0.0812529816082, - 0.0914693020772, -0.1197222726745, 0.0376277453183, -0.0832617004142, - -0.0482175038043, -0.0839003635737, -0.0349423908400, 0.1204519568256, - 0.0783745984003, 0.0297401205976, -0.0505947662525 + 0.1749017387629 ] ]) centers= np.array([0, 0, 0]) diff --git a/fury/actor.py b/fury/actor.py index 085c9aa79..6d150ceb1 100644 --- a/fury/actor.py +++ b/fury/actor.py @@ -3873,7 +3873,7 @@ def ellipsoid( def odf( centers, coeffs, - degree=4, + degree=None, basis_type='descoteaux', scales=1.0, opacity=1.0 @@ -3890,7 +3890,8 @@ def odf( 2D ODFs array in SH coefficients. degree: int, optional Index of the highest used band of the spherical harmonics basis. Must - be even, at least 2 and at most 12. + be even, at least 2 and at most 12. If None the degree is set based on + the number of SH coefficients given. basis_type: str, optional Type of basis (descoteaux, tournier) 'descoteaux' for the default ``descoteaux07`` DYPY basis. @@ -3913,17 +3914,25 @@ def odf( if not isinstance(coeffs, np.ndarray): coeffs = np.array(coeffs) - - coeffs_given = coeffs.shape[1] - coeffs_needed = int(((degree + 1) * (degree + 2)) / 2) - if degree % 2 != 0: + if coeffs.ndim == 1: + coeffs = np.array([coeffs]) + if coeffs.shape[0] != centers.shape[0]: + raise ValueError('number of odf glyphs defined does not match with ' + 'number of centers') + + coeffs_given = coeffs.shape[-1] + if degree == None: + degree = int((np.sqrt(8 * coeffs_given + 1) - 3)/2) + elif degree % 2 != 0: raise ValueError('degree must be even') + coeffs_needed = int(((degree + 1) * (degree + 2)) / 2) if coeffs_given < coeffs_needed: - raise ValueError( - 'Not enough number of coefficient for SH of degree {0}. ' - 'Expected at least {1}'.format(degree, coeffs_needed)) - else: - coeffs = coeffs[:, :coeffs_needed] + print('Not enough number of coefficient for SH of degree {0}. ' + 'Expected at least {1}'.format(degree, coeffs_needed)) + degree = int((np.sqrt(8 * coeffs_given + 1) - 3)/2) + if (degree % 2 != 0): degree -= 1 + coeffs_needed = int(((degree + 1) * (degree + 2)) / 2) + coeffs = coeffs[:, :coeffs_needed] if not isinstance(scales, np.ndarray): scales = np.array(scales) From 290b330f7761ef64dc56f12c85ce512eabc51d25 Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Mon, 11 Mar 2024 21:41:30 -0400 Subject: [PATCH 068/118] Changed first uniform. --- .../SH-ODF_experimental/ray_traced_6.5.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py b/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py index e92110c99..112ba8c80 100644 --- a/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py +++ b/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py @@ -50,7 +50,7 @@ def uv_calculations(n): sh_count = coeffs.shape[-1] - sh_degree = int ((np.sqrt(8 * sh_count + 1) - 3) / 2) + sh_degree = int((np.sqrt(8 * sh_count + 1) - 3) / 2) valid_mask = np.abs(coeffs).max(axis=(-1)) > 0 indices = np.nonzero(valid_mask) @@ -108,8 +108,11 @@ def uv_calculations(n): odf_actor.GetProperty().SetTexture("texture0", texture) - # TODO: Set int uniform - odf_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniformf( + odf_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniformi( + "shDegree", sh_degree + ) + + odf_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniformi( "numCoeffs", sh_count ) @@ -140,13 +143,15 @@ def uv_calculations(n): # The index of the highest used band of the spherical harmonics basis. Must # be even, at least 2 and at most 12. - def_sh_degree = "#define SH_DEGREE 6" + def_sh_degree = "//#define SH_DEGREE 8" # The number of spherical harmonics basis functions - def_sh_count = "#define SH_COUNT (((SH_DEGREE + 1) * (SH_DEGREE + 2)) / 2)" + # def_sh_count = "#define SH_COUNT (((SH_DEGREE + 1) * (SH_DEGREE + 2)) / 2)" + def_sh_count = "#define SH_COUNT (((shDegree + 1) * (shDegree + 2)) / 2)" # Degree of polynomials for which we have to find roots - def_max_degree = "#define MAX_DEGREE (2 * SH_DEGREE + 2)" + # def_max_degree = "#define MAX_DEGREE (2 * SH_DEGREE + 2)" + def_max_degree = "#define MAX_DEGREE (2 * shDegree + 2)" # If GL_EXT_control_flow_attributes is available, these defines should be # defined as [[unroll]] and [[loop]] to give reasonable hints to the From ecef0ffa7ba60bde8d43c7b52f034bd8735b79f6 Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Tue, 12 Mar 2024 02:46:53 -0400 Subject: [PATCH 069/118] Added ray_traced_3.5.py to take single ODF screenshot. --- .../SH-ODF_experimental/ray_traced_3.5.py | 420 ++++++++++++++++++ 1 file changed, 420 insertions(+) create mode 100644 docs/experimental/SH-ODF_experimental/ray_traced_3.5.py diff --git a/docs/experimental/SH-ODF_experimental/ray_traced_3.5.py b/docs/experimental/SH-ODF_experimental/ray_traced_3.5.py new file mode 100644 index 000000000..42a855a5a --- /dev/null +++ b/docs/experimental/SH-ODF_experimental/ray_traced_3.5.py @@ -0,0 +1,420 @@ +""" +Fury's simplified version of the script ray_traced_1.0.py. + - Simplified color calculation. + - Simplified lighting. +""" + +import os + +import numpy as np + +from fury import actor, window +from fury.shaders import ( + attribute_to_actor, + compose_shader, + import_fury_shader, + shader_to_actor, +) + + +def key_pressed(obj, event): + global show_man + key = obj.GetKeySym() + if key == "s" or key == "S": + print("Saving image...") + show_man.save_screenshot("screenshot.png", magnification=4) + print("Image saved.") + + +if __name__ == "__main__": + global show_man + + show_man = window.ShowManager(size=(1280, 720)) + show_man.scene.background((1, 1, 1)) + + centers = np.array([[0, 0, 0]]) + scales = np.array([4]) + + odf_actor = actor.box(centers=centers, scales=scales) + + big_centers = np.repeat(centers, 8, axis=0) + attribute_to_actor(odf_actor, big_centers, "center") + + big_scales = np.repeat(scales, 8, axis=0) + attribute_to_actor(odf_actor, big_scales, "scale") + + vs_dec = """ + in vec3 center; + in float scale; + + out vec4 vertexMCVSOutput; + out vec3 centerMCVSOutput; + out vec3 camPosMCVSOutput; + out vec3 camRightMCVSOutput; + out vec3 camUpMCVSOutput; + out float scaleVSOutput; + """ + + vs_impl = """ + vertexMCVSOutput = vertexMC; + centerMCVSOutput = center; + scaleVSOutput = scale; + camPosMCVSOutput = -MCVCMatrix[3].xyz * mat3(MCVCMatrix); + camRightMCVSOutput = vec3( + MCVCMatrix[0][0], MCVCMatrix[1][0], MCVCMatrix[2][0]); + camUpMCVSOutput = vec3( + MCVCMatrix[0][1], MCVCMatrix[1][1], MCVCMatrix[2][1]); + """ + + shader_to_actor(odf_actor, "vertex", decl_code=vs_dec, impl_code=vs_impl) + + # The index of the highest used band of the spherical harmonics basis. Must + # be even, at least 2 and at most 12. + def_sh_degree = "#define SH_DEGREE 4" + + # The number of spherical harmonics basis functions + def_sh_count = "#define SH_COUNT (((SH_DEGREE + 1) * (SH_DEGREE + 2)) / 2)" + + # Degree of polynomials for which we have to find roots + def_max_degree = "#define MAX_DEGREE (2 * SH_DEGREE + 2)" + + # If GL_EXT_control_flow_attributes is available, these defines should be + # defined as [[unroll]] and [[loop]] to give reasonable hints to the + # compiler. That avoids register spilling, which makes execution + # considerably faster. + def_gl_ext_control_flow_attributes = """ + #ifndef _unroll_ + #define _unroll_ + #endif + #ifndef _loop_ + #define _loop_ + #endif + """ + + # When there are fewer intersections/roots than theoretically possible, + # some array entries are set to this value + def_no_intersection = "#define NO_INTERSECTION 3.4e38" + + # pi and its reciprocal + def_pis = """ + #define M_PI 3.141592653589793238462643 + #define M_INV_PI 0.318309886183790671537767526745 + """ + + fs_vs_vars = """ + in vec4 vertexMCVSOutput; + in vec3 centerMCVSOutput; + in vec3 camPosMCVSOutput; + in vec3 camRightMCVSOutput; + in vec3 camUpMCVSOutput; + in float scaleVSOutput; + """ + + eval_sh_2 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_2.frag") + ) + + eval_sh_4 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_4.frag") + ) + + eval_sh_6 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_6.frag") + ) + + eval_sh_8 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_8.frag") + ) + + eval_sh_10 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_10.frag") + ) + + eval_sh_12 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_12.frag") + ) + + eval_sh_grad_2 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_2.frag") + ) + + eval_sh_grad_4 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_4.frag") + ) + + eval_sh_grad_6 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_6.frag") + ) + + eval_sh_grad_8 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_8.frag") + ) + + eval_sh_grad_10 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_10.frag") + ) + + eval_sh_grad_12 = import_fury_shader( + os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_12.frag") + ) + + # Searches a single root of a polynomial within a given interval. + # param out_root The location of the found root. + # param out_end_value The value of the given polynomial at end. + # param poly Coefficients of the polynomial for which a root should be + # found. + # Coefficient poly[i] is multiplied by x^i. + # param begin The beginning of an interval where the polynomial is + # monotonic. + # param end The end of said interval. + # param begin_value The value of the given polynomial at begin. + # param error_tolerance The error tolerance for the returned root + # location. + # Typically the error will be much lower but in theory it can be + # bigger. + # + # return true if a root was found, false if no root exists. + newton_bisection = import_fury_shader( + os.path.join("rt_odfs", "newton_bisection.frag") + ) + + # Finds all roots of the given polynomial in the interval [begin, end] and + # writes them to out_roots. Some entries will be NO_INTERSECTION but other + # than that the array is sorted. The last entry is always NO_INTERSECTION. + find_roots = import_fury_shader(os.path.join("rt_odfs", "find_roots.frag")) + + # Evaluates the spherical harmonics basis in bands 0, 2, ..., SH_DEGREE. + # Conventions are as in the following paper. + # M. Descoteaux, E. Angelino, S. Fitzgibbons, and R. Deriche. Regularized, + # fast, and robust analytical q-ball imaging. Magnetic Resonance in + # Medicine, 58(3), 2007. https://doi.org/10.1002/mrm.21277 + # param out_shs Values of SH basis functions in bands 0, 2, ..., + # SH_DEGREE in this order. + # param point The point on the unit sphere where the basis should be + # evaluated. + eval_sh = import_fury_shader(os.path.join("rt_odfs", "eval_sh.frag")) + + # Evaluates the gradient of each basis function given by eval_sh() and the + # basis itself + eval_sh_grad = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad.frag") + ) + + # Outputs a matrix that turns equidistant samples on the unit circle of a + # homogeneous polynomial into coefficients of that polynomial. + get_inv_vandermonde = import_fury_shader( + os.path.join("rt_odfs", "get_inv_vandermonde.frag") + ) + + # Determines all intersections between a ray and a spherical harmonics + # glyph. + # param out_ray_params The ray parameters at intersection points. The + # points themselves are at ray_origin + out_ray_params[i] * ray_dir. + # Some entries may be NO_INTERSECTION but other than that the array + # is sorted. + # param sh_coeffs SH_COUNT spherical harmonic coefficients defining the + # glyph. Their exact meaning is defined by eval_sh(). + # param ray_origin The origin of the ray, relative to the glyph center. + # param ray_dir The normalized direction vector of the ray. + ray_sh_glyph_intersections = import_fury_shader( + os.path.join("rt_odfs", "ray_sh_glyph_intersections.frag") + ) + + # Provides a normalized normal vector for a spherical harmonics glyph. + # param sh_coeffs SH_COUNT spherical harmonic coefficients defining the + # glyph. Their exact meaning is defined by eval_sh(). + # param point A point on the surface of the glyph, relative to its + # center. + # + # return A normalized surface normal pointing away from the origin. + get_sh_glyph_normal = import_fury_shader( + os.path.join("rt_odfs", "get_sh_glyph_normal.frag") + ) + + # Applies the non-linearity that maps linear RGB to sRGB + linear_to_srgb = import_fury_shader( + os.path.join("rt_odfs", "linear_to_srgb.frag") + ) + + # Inverse of linear_to_srgb() + srgb_to_linear = import_fury_shader( + os.path.join("rt_odfs", "srgb_to_linear.frag") + ) + + # Turns a linear RGB color (i.e. rec. 709) into sRGB + linear_rgb_to_srgb = import_fury_shader( + os.path.join("rt_odfs", "linear_rgb_to_srgb.frag") + ) + + # Inverse of linear_rgb_to_srgb() + srgb_to_linear_rgb = import_fury_shader( + os.path.join("rt_odfs", "srgb_to_linear_rgb.frag") + ) + + # Logarithmic tonemapping operator. Input and output are linear RGB. + tonemap = import_fury_shader(os.path.join("rt_odfs", "tonemap.frag")) + + # Blinn-Phong illumination model + blinn_phong_model = import_fury_shader( + os.path.join("lighting", "blinn_phong_model.frag") + ) + + # fmt: off + fs_dec = compose_shader([ + def_sh_degree, def_sh_count, def_max_degree, + def_gl_ext_control_flow_attributes, def_no_intersection, def_pis, + fs_vs_vars, eval_sh_2, eval_sh_4, eval_sh_6, eval_sh_8, eval_sh_10, + eval_sh_12, eval_sh_grad_2, eval_sh_grad_4, eval_sh_grad_6, + eval_sh_grad_8, eval_sh_grad_10, eval_sh_grad_12, newton_bisection, + find_roots, eval_sh, eval_sh_grad, get_inv_vandermonde, + ray_sh_glyph_intersections, get_sh_glyph_normal, blinn_phong_model, + linear_to_srgb, srgb_to_linear, linear_rgb_to_srgb, srgb_to_linear_rgb, + tonemap + ]) + # fmt: on + + shader_to_actor(odf_actor, "fragment", decl_code=fs_dec) + + point_from_vs = "vec3 pnt = vertexMCVSOutput.xyz;" + + # Ray origin is the camera position in world space + ray_origin = "vec3 ro = camPosMCVSOutput;" + + # TODO: Check aspect for automatic scaling + # Ray direction is the normalized difference between the fragment and the + # camera position/ray origin + ray_direction = """ + vec3 rd = normalize(pnt - ro); + //float aspect = float(iResolution.x) / float(iResolution.y); + //float aspect = 1; + //float zoom = .8; + //vec3 right = (aspect / zoom) * vec3(3.0, 0.0, 0.0); + //vec3 up = (1.0 / zoom) * vec3(0.0, 0.0, 3.0); + //vec3 bottom_left = -0.5 * (right + up); + //vec2 frag_coord = gl_FragCoord.xy; + //vec2 uv = frag_coord / vec2(iResolution.xy); + //vec3 ray_dir = normalize(bottom_left + uv.x * right + uv.y * up - camera_pos); + //vec3 ray_dir = rd; + """ + + # Light direction in a retroreflective model is the normalized difference + # between the camera position/ray origin and the fragment + light_direction = "vec3 ld = normalize(ro - pnt);" + + # Define SH coefficients (measured up to band 8, noise beyond that) + sh_coeffs = """ + float sh_coeffs[SH_COUNT]; + sh_coeffs[0] = -0.2739740312099; sh_coeffs[1] = 0.2526670396328; + sh_coeffs[2] = 1.8922271728516; sh_coeffs[3] = 0.2878578901291; + sh_coeffs[4] = -0.5339795947075; sh_coeffs[5] = -0.2620058953762; + #if SH_DEGREE >= 4 + sh_coeffs[6] = 0.1580424904823; sh_coeffs[7] = 0.0329004973173; + sh_coeffs[8] = -0.1322413831949; sh_coeffs[9] = -0.1332057565451; + sh_coeffs[10] = 1.0894461870193; sh_coeffs[11] = -0.6319401264191; + sh_coeffs[12] = -0.0416776277125; sh_coeffs[13] = -1.0772529840469; + sh_coeffs[14] = 0.1423762738705; + #endif + #if SH_DEGREE >= 6 + sh_coeffs[15] = 0.7941166162491; sh_coeffs[16] = 0.7490307092667; + sh_coeffs[17] = -0.3428381681442; sh_coeffs[18] = 0.1024847552180; + sh_coeffs[19] = -0.0219132602215; sh_coeffs[20] = 0.0499043911695; + sh_coeffs[21] = 0.2162453681231; sh_coeffs[22] = 0.0921059995890; + sh_coeffs[23] = -0.2611238956451; sh_coeffs[24] = 0.2549301385880; + sh_coeffs[25] = -0.4534865319729; sh_coeffs[26] = 0.1922748684883; + sh_coeffs[27] = -0.6200597286224; + #endif + #if SH_DEGREE >= 8 + sh_coeffs[28] = -0.0532187558711; sh_coeffs[29] = -0.3569841980934; + sh_coeffs[30] = 0.0293972902000; sh_coeffs[31] = -0.1977960765362; + sh_coeffs[32] = -0.1058669015765; sh_coeffs[33] = 0.2372217923403; + sh_coeffs[34] = -0.1856198310852; sh_coeffs[35] = -0.3373193442822; + sh_coeffs[36] = -0.0750469490886; sh_coeffs[37] = 0.2146576642990; + sh_coeffs[38] = -0.0490148440003; sh_coeffs[39] = 0.1288588196039; + sh_coeffs[40] = 0.3173974752426; sh_coeffs[41] = 0.1990085393190; + sh_coeffs[42] = -0.1736343950033; sh_coeffs[43] = -0.0482443645597; + sh_coeffs[44] = 0.1749017387629; + #endif + #if SH_DEGREE >= 10 + sh_coeffs[45] = -0.0151847425660; sh_coeffs[46] = 0.0418366046081; + sh_coeffs[47] = 0.0863263587216; sh_coeffs[48] = -0.0649211244490; + sh_coeffs[49] = 0.0126096132283; sh_coeffs[50] = 0.0545089217982; + sh_coeffs[51] = -0.0275142164626; sh_coeffs[52] = 0.0399986574832; + sh_coeffs[53] = -0.0468244261610; sh_coeffs[54] = -0.1292105653111; + sh_coeffs[55] = -0.0786858322658; sh_coeffs[56] = -0.0663828464882; + sh_coeffs[57] = 0.0382439706831; sh_coeffs[58] = -0.0041550330365; + sh_coeffs[59] = -0.0502800566338; sh_coeffs[60] = -0.0732471630735; + sh_coeffs[61] = 0.0181751900972; sh_coeffs[62] = -0.0090119333757; + sh_coeffs[63] = -0.0604443282359; sh_coeffs[64] = -0.1469985252752; + sh_coeffs[65] = -0.0534046899715; + #endif + #if SH_DEGREE >= 12 + sh_coeffs[66] = -0.0896672753415; sh_coeffs[67] = -0.0130841364808; + sh_coeffs[68] = -0.0112942893801; sh_coeffs[69] = 0.0272257498541; + sh_coeffs[70] = 0.0626717616331; sh_coeffs[71] = -0.0222197983050; + sh_coeffs[72] = -0.0018541504308; sh_coeffs[73] = -0.1653251944056; + sh_coeffs[74] = 0.0409697402846; sh_coeffs[75] = 0.0749921454327; + sh_coeffs[76] = -0.0282830872616; sh_coeffs[77] = 0.0006909458525; + sh_coeffs[78] = 0.0625599842287; sh_coeffs[79] = 0.0812529816082; + sh_coeffs[80] = 0.0914693020772; sh_coeffs[81] = -0.1197222726745; + sh_coeffs[82] = 0.0376277453183; sh_coeffs[83] = -0.0832617004142; + sh_coeffs[84] = -0.0482175038043; sh_coeffs[85] = -0.0839003635737; + sh_coeffs[86] = -0.0349423908400; sh_coeffs[87] = 0.1204519568256; + sh_coeffs[88] = 0.0783745984003; sh_coeffs[89] = 0.0297401205976; + sh_coeffs[90] = -0.0505947662525; + #endif + """ + + # Perform the intersection test + intersection_test = """ + float ray_params[MAX_DEGREE]; + ray_sh_glyph_intersections(ray_params, sh_coeffs, ro, rd); + """ + + # Identify the first intersection + first_intersection = """ + float first_ray_param = NO_INTERSECTION; + _unroll_ + for (int i = 0; i != MAX_DEGREE; ++i) { + if (ray_params[i] != NO_INTERSECTION && ray_params[i] > 0.0) { + first_ray_param = ray_params[i]; + break; + } + } + """ + + # Evaluate shading for a directional light + directional_light = """ + vec3 color = vec3(1.); + if (first_ray_param != NO_INTERSECTION) { + vec3 intersection = ro + first_ray_param * rd; + vec3 normal = get_sh_glyph_normal(sh_coeffs, intersection); + vec3 colorDir = srgb_to_linear_rgb(abs(normalize(intersection))); + float attenuation = dot(ld, normal); + color = blinnPhongIllumModel( + //attenuation, lightColor0, diffuseColor, specularPower, + attenuation, lightColor0, colorDir, specularPower, + specularColor, ambientColor); + } + """ + + frag_output = """ + //vec4 out_color = vec4(linear_rgb_to_srgb(tonemap(color)), 1.0); + vec3 out_color = linear_rgb_to_srgb(tonemap(color)); + fragOutput0 = vec4(out_color, opacity); + //fragOutput0 = vec4(color, opacity); + """ + + # fmt: off + fs_impl = compose_shader([ + point_from_vs, ray_origin, ray_direction, light_direction, sh_coeffs, + intersection_test, first_intersection, directional_light, frag_output + ]) + # fmt: on + + shader_to_actor(odf_actor, "fragment", impl_code=fs_impl, block="light") + + show_man.scene.add(odf_actor) + + show_man.iren.AddObserver("KeyPressEvent", key_pressed) + + show_man.start() From dc4168497eb74f33a4e8b466fc1c631990f6ea50 Mon Sep 17 00:00:00 2001 From: tvcastillod Date: Mon, 18 Mar 2024 13:07:16 -0500 Subject: [PATCH 070/118] added tests --- .../SH-ODF experimental/odf_example.py | 47 ------------ fury/actor.py | 11 +-- fury/actors/odf.py | 54 +++++--------- fury/tests/test_actors.py | 73 +++++++++++++++++++ fury/tests/test_utils.py | 21 ++++++ fury/texture/utils.py | 18 +++++ fury/utils.py | 33 +++++++++ 7 files changed, 168 insertions(+), 89 deletions(-) delete mode 100644 docs/experimental/SH-ODF experimental/odf_example.py create mode 100644 fury/texture/utils.py diff --git a/docs/experimental/SH-ODF experimental/odf_example.py b/docs/experimental/SH-ODF experimental/odf_example.py deleted file mode 100644 index c31dac722..000000000 --- a/docs/experimental/SH-ODF experimental/odf_example.py +++ /dev/null @@ -1,47 +0,0 @@ -import os - -import numpy as np -from dipy.data.fetcher import dipy_home -from dipy.io.image import load_nifti - -from fury import actor, window - -if __name__ == "__main__": - show_man = window.ShowManager(size=(1280, 720)) - - dataset_dir = os.path.join(dipy_home, "stanford_hardi") - - coeffs, affine = load_nifti("docs\experimental\SH-ODF experimental\coefs_odf.nii") - - valid_mask = np.abs(coeffs).max(axis=(-1)) > 0 - indices = np.nonzero(valid_mask) - - centers = np.asarray(indices).T - - x, y, z, s = coeffs.shape - coeffs = coeffs[:, :, :].reshape((x * y * z, s)) - - #''' - coeffs = np.array([ - [ - -0.2739740312099, 0.2526670396328, 1.8922271728516, 0.2878578901291, - -0.5339795947075, -0.2620058953762, 0.1580424904823, 0.0329004973173, - -0.1322413831949, -0.1332057565451, 1.0894461870193, -0.6319401264191, - -0.0416776277125, -1.0772529840469, 0.1423762738705, 0.7941166162491, - 0.7490307092667, -0.3428381681442, 0.1024847552180, -0.0219132602215, - 0.0499043911695, 0.2162453681231, 0.0921059995890, -0.2611238956451, - 0.2549301385880, -0.4534865319729, 0.1922748684883, -0.6200597286224, - -0.0532187558711, -0.3569841980934, 0.0293972902000, -0.1977960765362, - -0.1058669015765, 0.2372217923403, -0.1856198310852, -0.3373193442822, - -0.0750469490886, 0.2146576642990, -0.0490148440003, 0.1288588196039, - 0.3173974752426, 0.1990085393190, -0.1736343950033, -0.0482443645597, - 0.1749017387629 - ] - ]) - centers= np.array([0, 0, 0]) - #''' - - odf_actor = actor.odf(centers=centers, coeffs=coeffs, scales=1.0, - basis_type='descoteaux', degree=6) - show_man.scene.add(odf_actor) - show_man.start() \ No newline at end of file diff --git a/fury/actor.py b/fury/actor.py index e2811ba82..b1bad30f3 100644 --- a/fury/actor.py +++ b/fury/actor.py @@ -3987,7 +3987,7 @@ def odf( ODFs size. opacity : float Takes values from 0 (fully transparent) to 1 (opaque). - + Returns ------- odf: Actor @@ -3998,7 +3998,7 @@ def odf( centers = np.array(centers) if centers.ndim == 1: centers = np.array([centers]) - + if not isinstance(coeffs, np.ndarray): coeffs = np.array(coeffs) if coeffs.ndim == 1: @@ -4008,7 +4008,7 @@ def odf( 'number of centers') coeffs_given = coeffs.shape[-1] - if degree == None: + if degree is None: degree = int((np.sqrt(8 * coeffs_given + 1) - 3)/2) elif degree % 2 != 0: raise ValueError('degree must be even') @@ -4017,7 +4017,8 @@ def odf( print('Not enough number of coefficient for SH of degree {0}. ' 'Expected at least {1}'.format(degree, coeffs_needed)) degree = int((np.sqrt(8 * coeffs_given + 1) - 3)/2) - if (degree % 2 != 0): degree -= 1 + if (degree % 2 != 0): + degree -= 1 coeffs_needed = int(((degree + 1) * (degree + 2)) / 2) coeffs = coeffs[:, :coeffs_needed] @@ -4028,7 +4029,7 @@ def odf( elif scales.size != centers.shape[0]: scales = np.concatenate( (scales, np.ones(centers.shape[0] - scales.shape[0])), axis=None) - + total = np.sum(abs(coeffs), axis=1) coeffs = np.dot(np.diag(1 / total * scales), coeffs) * 1.7 diff --git a/fury/actors/odf.py b/fury/actors/odf.py index 139567a56..938cae791 100644 --- a/fury/actors/odf.py +++ b/fury/actors/odf.py @@ -10,33 +10,13 @@ import_fury_shader, shader_to_actor, ) -from fury.utils import numpy_to_vtk_image_data, set_polydata_tcoords - -def uv_calculations(n): - uvs = [] - for i in range(0, n): - a = (n - (i + 1)) / n - b = (n - i) / n - uvs.extend( - [ - [0.001, a + 0.001], - [0.001, b - 0.001], - [0.999, b - 0.001], - [0.999, a + 0.001], - [0.001, a + 0.001], - [0.001, b - 0.001], - [0.999, b - 0.001], - [0.999, a + 0.001], - ] - ) - return uvs - -def minmax_norm(data): - min = data.min(axis=1) - max = data.max(axis=1) - return np.array([(data[i] - min[i]) / (max[i] - min[i]) - for i in range(data.shape[0])]) - +from fury.utils import ( + numpy_to_vtk_image_data, + set_polydata_tcoords, + minmax_norm +) +from fury.texture.utils import uv_calculations + def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): """ @@ -75,9 +55,9 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): minmax = np.array([coeffs.min(axis=1), coeffs.max(axis=1)]).T big_minmax = np.repeat(minmax, 8, axis=0) attribute_to_actor(odf_actor, big_minmax, "minmax") - + # The coefficient data is stored in a texture to be passed to the shaders. - + # Data is normalized to a range of 0 to 1. arr = minmax_norm(coeffs) # Data is turned into values within the RGB color range, and then coverted @@ -92,8 +72,7 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): # Texture is associated with the actor odf_actor.GetProperty().SetTexture("texture0", texture) - - + odf_actor_pd = odf_actor.GetMapper().GetInput() n_glyphs = coeffs.shape[0] @@ -101,6 +80,7 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): uv_vals = np.array(uv_calculations(n_glyphs)) num_pnts = uv_vals.shape[0] + # Definition of texture coordinates to be associated with the actor. t_coords = FloatArray() t_coords.SetNumberOfComponents(2) t_coords.SetNumberOfTuples(num_pnts) @@ -112,9 +92,9 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): odf_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniformf( "numCoeffs", ((degree + 1) * (degree + 2)) / 2 ) - + # Start of shader implementation - + vs_dec = \ """ in vec3 center; @@ -188,13 +168,13 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): """ coeffs_norm = import_fury_shader(os.path.join("utils", "minmax_norm.glsl")) - + eval_sh_list = '' - for i in range (2, degree+1, 2): + for i in range(2, degree+1, 2): eval_sh = import_fury_shader( os.path.join("rt_odfs", basis_type, 'eval_sh_' + str(i) + '.frag')) eval_sh_grad = import_fury_shader( - os.path.join("rt_odfs", basis_type, + os.path.join("rt_odfs", basis_type, 'eval_sh_grad_' + str(i) + '.frag')) eval_sh_list = eval_sh_list + '\n\n' + eval_sh + '\n\n' + eval_sh_grad @@ -388,5 +368,5 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): ]) shader_to_actor(odf_actor, "fragment", impl_code=fs_impl, block="picking") - + return odf_actor \ No newline at end of file diff --git a/fury/tests/test_actors.py b/fury/tests/test_actors.py index c09862b98..49ad49970 100644 --- a/fury/tests/test_actors.py +++ b/fury/tests/test_actors.py @@ -1881,3 +1881,76 @@ def test_actors_primitives_count(): primitives_count = test_case[2] act = act_func(**args) npt.assert_equal(primitives_count_from_actor(act), primitives_count) + + +def test_odf_actor(interactive=False): + # number of odf glyphs does not match with number of centers + centers = np.array([[0, -1, 0]]) + coeffs = np.array([[0.282, 0.152, -0.040, -0.112, -0.045, 0.149], + [0.285, 0.097, -0.115, 0.125, -0.001, 0.003]]) + npt.assert_raises(ValueError, actor.odf, centers, coeffs) + + scene = window.Scene() + centers = np.array([[0, -1, 0], [1, -1, 0], [2, -1, 0]]) + coeffs = np.array([ + [0.2820735, 0.15236554, -0.04038717, -0.11270988, -0.04532376, + 0.14921817, 0.00257928, 0.0040734, -0.05313807, 0.03486542, + 0.04083064, 0.02105767, -0.04389586, -0.04302812, 0.1048641], + [0.28549338, 0.0978267, -0.11544838, 0.12525354, -0.00126003, + 0.00320594, 0.04744155, -0.07141446, 0.03211689, 0.04711322, + 0.08064896, 0.00154299, 0.00086506, 0.00162543, -0.00444893], + [0.28208936, -0.13133252, -0.04701012, -0.06303016, -0.0468775, + 0.02348355, 0.03991898, 0.02587433, 0.02645416, 0.00668765, + 0.00890633, 0.02189304, 0.00387415, 0.01665629, -0.01427194] + ]) + odf_actor = actor.odf(centers=centers, coeffs=coeffs) + scene.add(odf_actor) + + if interactive: + window.show(scene) + + report = window.analyze_scene(scene) + npt.assert_equal(report.actors, 1) + scene.clear() + + # given degree is not even + npt.assert_raises(ValueError, actor.odf, centers, coeffs, degree=3) + + centers= np.array([0, 0, 0]) + coeffs = np.array([ + [-0.2739740312099, 0.2526670396328, 1.8922271728516, 0.2878578901291, + -0.5339795947075, -0.2620058953762, 0.1580424904823, 0.0329004973173, + -0.1322413831949, -0.1332057565451, 1.0894461870193, -0.6319401264191, + -0.0416776277125, -1.0772529840469, 0.1423762738705, 0.7941166162491, + 0.7490307092667, -0.3428381681442, 0.1024847552180, -0.0219132602215, + 0.0499043911695, 0.2162453681231, 0.0921059995890, -0.2611238956451, + 0.2549301385880,-0.4534865319729, 0.1922748684883, -0.6200597286224] + ]) + odf_actor = actor.odf(centers=centers, coeffs=coeffs, degree=6) + scene.add(odf_actor) + + if interactive: + window.show(scene) + + report = window.analyze_scene(scene) + npt.assert_equal(report.actors, 1) + scene.clear() + + odf_actor = actor.odf(centers=centers, coeffs=coeffs, degree=4) + scene.add(odf_actor) + + if interactive: + window.show(scene) + + report = window.analyze_scene(scene) + npt.assert_equal(report.actors, 1) + scene.clear() + + odf_actor = actor.odf(centers=centers, coeffs=coeffs, degree=8) + scene.add(odf_actor) + + if interactive: + window.show(scene) + + npt.assert_equal(report.actors, 1) + scene.clear() diff --git a/fury/tests/test_utils.py b/fury/tests/test_utils.py index 821fa386c..6e95a8c19 100644 --- a/fury/tests/test_utils.py +++ b/fury/tests/test_utils.py @@ -53,6 +53,7 @@ update_surface_actor_colors, vertices_from_actor, vtk_matrix_to_numpy, + minmax_norm, ) dipy, have_dipy, _ = optional_package('dipy') @@ -959,3 +960,23 @@ def test_set_actor_origin(): utils.set_actor_origin(cube) centered_cube_vertices = np.copy(vertices_from_actor(cube)) npt.assert_array_equal(orig_vert, centered_cube_vertices) + + +def test_minmax_normalization(): + data = np.array([[1, 2, -1, 3], [4, -1, 3, 5], [-1, 9, 8, 0]]) + + actual = minmax_norm(data, axis=0) + expected = np.array([[0.4, 0.3, 0, 0.6], [1, 0, 0.444, 1], [0, 1, 1, 0]]) + npt.assert_array_almost_equal(actual, expected, decimal=3) + actual = minmax_norm(data, axis=1) + expected = np.array([[0.5, 0.75, 0, 1], [0.833, 0, 0.666, 1], + [0, 1, 0.9, 0.1]]) + npt.assert_array_almost_equal(actual, expected, decimal=3) + + data2 = np.array([1, 3, 9, 6]) + actual2 = minmax_norm(data2, axis=0) + expected2 = np.array([[1, 3, 9, 6]]) + npt.assert_array_equal(actual2, expected2) + actual2 = minmax_norm(data2, axis=1) + expected2 = np.array([[0, 0.25 , 1, 0.625]]) + npt.assert_array_almost_equal(actual2, expected2, decimal=3) diff --git a/fury/texture/utils.py b/fury/texture/utils.py new file mode 100644 index 000000000..b75bebde5 --- /dev/null +++ b/fury/texture/utils.py @@ -0,0 +1,18 @@ +def uv_calculations(n): + uvs = [] + for i in range(0, n): + a = (n - (i + 1)) / n + b = (n - i) / n + uvs.extend( + [ + [0.001, a + 0.001], + [0.001, b - 0.001], + [0.999, b - 0.001], + [0.999, a + 0.001], + [0.001, a + 0.001], + [0.001, b - 0.001], + [0.999, b - 0.001], + [0.999, a + 0.001], + ] + ) + return uvs \ No newline at end of file diff --git a/fury/utils.py b/fury/utils.py index 92abd4e4a..47c9f5c0e 100644 --- a/fury/utils.py +++ b/fury/utils.py @@ -1596,3 +1596,36 @@ def set_actor_origin(actor, center=None): center = np.mean(vertices) vertices[:] -= center update_actor(actor) + + +def minmax_norm(data, axis=1): + """Returns the min-max normalization of data + + Parameters + ---------- + data: ndarray + 2D array + axis: int + axis for the function to be applied on + + Returns + ------- + output : ndarray + + """ + + if not isinstance(data, np.ndarray): + data = np.array(data) + if data.ndim == 1: + data = np.array([data]) + elif data.ndim > 2: + raise ValueError('the dimension of the array must be 2.') + + min = data.min(axis=axis) + max = data.max(axis=axis) + if np.array_equal(min, max): + return data + if (axis == 0): + return (data - min)/(max - min) + if (axis == 1): + return (data - min[:, None])/(max - min)[:, None] From f4824f60a4e9bd6a8a819c4400e8e1fabca4550d Mon Sep 17 00:00:00 2001 From: tvcastillod Date: Fri, 29 Mar 2024 10:15:18 -0500 Subject: [PATCH 071/118] adjustments on tests and parameter validation --- fury/actor.py | 49 +++++++++++++++++++------------- fury/actors/odf.py | 2 +- fury/tests/test_actors.py | 22 +++++++------- fury/tests/test_utils.py | 14 +++++++-- fury/texture/tests/__init__.py | 0 fury/texture/tests/test_utils.py | 41 ++++++++++++++++++++++++++ fury/texture/utils.py | 15 +++++++++- fury/utils.py | 12 ++++---- 8 files changed, 115 insertions(+), 40 deletions(-) create mode 100644 fury/texture/tests/__init__.py create mode 100644 fury/texture/tests/test_utils.py diff --git a/fury/actor.py b/fury/actor.py index b1bad30f3..ae3d7423f 100644 --- a/fury/actor.py +++ b/fury/actor.py @@ -3966,15 +3966,16 @@ def odf( opacity=1.0 ): """ - VTK actor for visualizing ODFs given an array of spherical harmonics (SH) - coefficients. + FURY actor for visualizing Orientation Distribution Functions (ODFs) given + an array of Spherical Harmonics (SH) coefficients. Parameters ---------- centers : ndarray(N, 3) ODFs positions. - coeffs : ndarray - 2D ODFs array in SH coefficients. + coeffs : (N, M) or (N, 6) or (N, 15) or (N, 28) or (N, 45) or (N, 66) or + (N, 91) ndarray. + Corresponding SH coefficients for the ODFs. degree: int, optional Index of the highest used band of the spherical harmonics basis. Must be even, at least 2 and at most 12. If None the degree is set based on @@ -3998,29 +3999,39 @@ def odf( centers = np.array(centers) if centers.ndim == 1: centers = np.array([centers]) - + if not isinstance(coeffs, np.ndarray): coeffs = np.array(coeffs) - if coeffs.ndim == 1: - coeffs = np.array([coeffs]) + if coeffs.ndim != 2: + if coeffs.ndim == 1: + coeffs = np.array([coeffs]) + else: + raise ValueError('coeffs should be a 2D array.') if coeffs.shape[0] != centers.shape[0]: raise ValueError('number of odf glyphs defined does not match with ' 'number of centers') coeffs_given = coeffs.shape[-1] + max_degree = int((np.sqrt(8 * coeffs_given + 1) - 3) / 2) if degree is None: - degree = int((np.sqrt(8 * coeffs_given + 1) - 3)/2) - elif degree % 2 != 0: - raise ValueError('degree must be even') - coeffs_needed = int(((degree + 1) * (degree + 2)) / 2) - if coeffs_given < coeffs_needed: - print('Not enough number of coefficient for SH of degree {0}. ' - 'Expected at least {1}'.format(degree, coeffs_needed)) - degree = int((np.sqrt(8 * coeffs_given + 1) - 3)/2) - if (degree % 2 != 0): - degree -= 1 - coeffs_needed = int(((degree + 1) * (degree + 2)) / 2) - coeffs = coeffs[:, :coeffs_needed] + degree = max_degree + else: + if degree % 2 != 0: + warnings.warn('Invalid degree value. Degree must be a positive ' + 'even number lower or equal to 12. Ignoring passed ' + 'value and using maximum degree supported by the ' + 'number of SH coefficients.') + degree = max_degree + else: + coeffs_needed = int(((degree + 1) * (degree + 2)) / 2) + if coeffs_given < coeffs_needed: + warnings.warn('Not enough number of coefficient for SH of ' + 'degree {0}, expected at least {1}. Ignoring ' + 'passed value and using maximum degree supported ' + 'by the number of SH coefficients.' + .format(degree, coeffs_needed)) + degree = max_degree + coeffs = coeffs[:, :int(((degree + 1) * (degree + 2)) / 2)] if not isinstance(scales, np.ndarray): scales = np.array(scales) diff --git a/fury/actors/odf.py b/fury/actors/odf.py index 938cae791..5e8fbe4d4 100644 --- a/fury/actors/odf.py +++ b/fury/actors/odf.py @@ -369,4 +369,4 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): shader_to_actor(odf_actor, "fragment", impl_code=fs_impl, block="picking") - return odf_actor \ No newline at end of file + return odf_actor diff --git a/fury/tests/test_actors.py b/fury/tests/test_actors.py index 49ad49970..8e69c5afa 100644 --- a/fury/tests/test_actors.py +++ b/fury/tests/test_actors.py @@ -1889,7 +1889,7 @@ def test_odf_actor(interactive=False): coeffs = np.array([[0.282, 0.152, -0.040, -0.112, -0.045, 0.149], [0.285, 0.097, -0.115, 0.125, -0.001, 0.003]]) npt.assert_raises(ValueError, actor.odf, centers, coeffs) - + scene = window.Scene() centers = np.array([[0, -1, 0], [1, -1, 0], [2, -1, 0]]) coeffs = np.array([ @@ -1912,11 +1912,11 @@ def test_odf_actor(interactive=False): report = window.analyze_scene(scene) npt.assert_equal(report.actors, 1) scene.clear() - + # given degree is not even - npt.assert_raises(ValueError, actor.odf, centers, coeffs, degree=3) + npt.assert_warns(UserWarning, actor.odf, centers, coeffs, 3) - centers= np.array([0, 0, 0]) + centers = np.array([0, 0, 0]) coeffs = np.array([ [-0.2739740312099, 0.2526670396328, 1.8922271728516, 0.2878578901291, -0.5339795947075, -0.2620058953762, 0.1580424904823, 0.0329004973173, @@ -1924,7 +1924,7 @@ def test_odf_actor(interactive=False): -0.0416776277125, -1.0772529840469, 0.1423762738705, 0.7941166162491, 0.7490307092667, -0.3428381681442, 0.1024847552180, -0.0219132602215, 0.0499043911695, 0.2162453681231, 0.0921059995890, -0.2611238956451, - 0.2549301385880,-0.4534865319729, 0.1922748684883, -0.6200597286224] + 0.2549301385880, -0.4534865319729, 0.1922748684883, -0.6200597286224] ]) odf_actor = actor.odf(centers=centers, coeffs=coeffs, degree=6) scene.add(odf_actor) @@ -1938,19 +1938,21 @@ def test_odf_actor(interactive=False): odf_actor = actor.odf(centers=centers, coeffs=coeffs, degree=4) scene.add(odf_actor) - + if interactive: window.show(scene) - + report = window.analyze_scene(scene) npt.assert_equal(report.actors, 1) scene.clear() - + odf_actor = actor.odf(centers=centers, coeffs=coeffs, degree=8) + # not enough coefficients for given degree + npt.assert_warns(UserWarning, actor.odf, centers, coeffs, 8) scene.add(odf_actor) - + if interactive: window.show(scene) - + npt.assert_equal(report.actors, 1) scene.clear() diff --git a/fury/tests/test_utils.py b/fury/tests/test_utils.py index 6e95a8c19..6a99179c8 100644 --- a/fury/tests/test_utils.py +++ b/fury/tests/test_utils.py @@ -963,13 +963,21 @@ def test_set_actor_origin(): def test_minmax_normalization(): - data = np.array([[1, 2, -1, 3], [4, -1, 3, 5], [-1, 9, 8, 0]]) + data1d = np.array([2, -2, 5, -1, 8]) + actual_data1d = minmax_norm(data1d) + expected_data1d = np.array([[0.4, 0. , 0.7, 0.1, 1. ]]) + npt.assert_array_almost_equal(actual_data1d, expected_data1d, decimal=1) + + data3d = np.array([[[2, 7, 7, 9], [2, -1, -3, 5]], + [[-4, 5, 6, 0], [1, 1, -9, 3]]]) + npt.assert_raises(ValueError, utils.minmax_norm, data3d) + data = np.array([[1, 2, -1, 3], [4, -1, 3, 5], [-1, 9, 8, 0]]) actual = minmax_norm(data, axis=0) expected = np.array([[0.4, 0.3, 0, 0.6], [1, 0, 0.444, 1], [0, 1, 1, 0]]) npt.assert_array_almost_equal(actual, expected, decimal=3) actual = minmax_norm(data, axis=1) - expected = np.array([[0.5, 0.75, 0, 1], [0.833, 0, 0.666, 1], + expected = np.array([[0.5, 0.75, 0, 1], [0.833, 0, 0.666, 1], [0, 1, 0.9, 0.1]]) npt.assert_array_almost_equal(actual, expected, decimal=3) @@ -978,5 +986,5 @@ def test_minmax_normalization(): expected2 = np.array([[1, 3, 9, 6]]) npt.assert_array_equal(actual2, expected2) actual2 = minmax_norm(data2, axis=1) - expected2 = np.array([[0, 0.25 , 1, 0.625]]) + expected2 = np.array([[0, 0.25, 1, 0.625]]) npt.assert_array_almost_equal(actual2, expected2, decimal=3) diff --git a/fury/texture/tests/__init__.py b/fury/texture/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/fury/texture/tests/test_utils.py b/fury/texture/tests/test_utils.py new file mode 100644 index 000000000..71f108596 --- /dev/null +++ b/fury/texture/tests/test_utils.py @@ -0,0 +1,41 @@ +import numpy as np +import numpy.testing as npt +from fury.texture.utils import uv_calculations + +def test_uv_calculations(): + uv_coords = uv_calculations(1) + expected_uv1 = np.array([ + [0.001, 0.001], [0.001, 0.999], [0.999, 0.999], [0.999, 0.001], + [0.001, 0.001], [0.001, 0.999], [0.999, 0.999], [0.999, 0.001] + ]) + npt.assert_array_almost_equal(uv_coords, expected_uv1, decimal=3) + + uv_coords = uv_calculations(3) + expected_uv3 = np.array([ + [0.001, 0.667], [0.001, 0.999], [0.999, 0.999], [0.999, 0.667], + [0.001, 0.667], [0.001, 0.999], [0.999, 0.999], [0.999, 0.667], + [0.001, 0.334], [0.001, 0.665], [0.999, 0.665], [0.999, 0.334], + [0.001, 0.334], [0.001, 0.665], [0.999, 0.665], [0.999, 0.334], + [0.001, 0.001], [0.001, 0.332], [0.999, 0.332], [0.999, 0.001], + [0.001, 0.001], [0.001, 0.332], [0.999, 0.332], [0.999, 0.001] + ]) + npt.assert_array_almost_equal(uv_coords, expected_uv3, decimal=3) + + uv_coords = uv_calculations(7) + expected_uv7 = np.array([ + [0.001, 0.858], [0.001, 0.999], [0.999, 0.999], [0.999, 0.858], + [0.001, 0.858], [0.001, 0.999], [0.999, 0.999], [0.999, 0.858], + [0.001, 0.715], [0.001, 0.856], [0.999, 0.856], [0.999, 0.715], + [0.001, 0.715], [0.001, 0.856], [0.999, 0.856], [0.999, 0.715], + [0.001, 0.572], [0.001, 0.713], [0.999, 0.713], [0.999, 0.572], + [0.001, 0.572], [0.001, 0.713], [0.999, 0.713], [0.999, 0.572], + [0.001, 0.429], [0.001, 0.570], [0.999, 0.570], [0.999, 0.429], + [0.001, 0.429], [0.001, 0.570], [0.999, 0.570], [0.999, 0.429], + [0.001, 0.286], [0.001, 0.427], [0.999, 0.427], [0.999, 0.286], + [0.001, 0.286], [0.001, 0.427], [0.999, 0.427], [0.999, 0.286], + [0.001, 0.143], [0.001, 0.284], [0.999, 0.284], [0.999, 0.143], + [0.001, 0.143], [0.001, 0.284], [0.999, 0.284], [0.999, 0.143], + [0.001, 0.001], [0.001, 0.141], [0.999, 0.141], [0.999, 0.001], + [0.001, 0.001], [0.001, 0.141], [0.999, 0.141], [0.999, 0.001] + ]) + npt.assert_array_almost_equal(uv_coords, expected_uv7, decimal=3) diff --git a/fury/texture/utils.py b/fury/texture/utils.py index b75bebde5..25da3a714 100644 --- a/fury/texture/utils.py +++ b/fury/texture/utils.py @@ -1,4 +1,17 @@ def uv_calculations(n): + """Return UV coordinates based on the number of elements. + + Parameters + ---------- + n : int + number of elements. + + Returns + ------- + uvs : ndrray + UV coordinates for each element. + + """ uvs = [] for i in range(0, n): a = (n - (i + 1)) / n @@ -15,4 +28,4 @@ def uv_calculations(n): [0.999, a + 0.001], ] ) - return uvs \ No newline at end of file + return uvs diff --git a/fury/utils.py b/fury/utils.py index 47c9f5c0e..b806b2d99 100644 --- a/fury/utils.py +++ b/fury/utils.py @@ -1599,7 +1599,7 @@ def set_actor_origin(actor, center=None): def minmax_norm(data, axis=1): - """Returns the min-max normalization of data + """Returns the min-max normalization of data along an axis. Parameters ---------- @@ -1621,11 +1621,11 @@ def minmax_norm(data, axis=1): elif data.ndim > 2: raise ValueError('the dimension of the array must be 2.') - min = data.min(axis=axis) - max = data.max(axis=axis) - if np.array_equal(min, max): + minimum = data.min(axis=axis) + maximum = data.max(axis=axis) + if np.array_equal(minimum, maximum): return data if (axis == 0): - return (data - min)/(max - min) + return (data - minimum)/(maximum - minimum) if (axis == 1): - return (data - min[:, None])/(max - min)[:, None] + return (data - minimum[:, None])/(maximum - minimum)[:, None] From a17222e1658bfd0a9649cd8ff9f8c75798137f28 Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Fri, 29 Mar 2024 14:02:04 -0400 Subject: [PATCH 072/118] Added Min-Max Normalization function. --- .../SH-ODF_experimental/ray_traced_6.5.py | 27 +++++++------------ fury/shaders/utils/minmax_norm.glsl | 4 +++ 2 files changed, 14 insertions(+), 17 deletions(-) create mode 100644 fury/shaders/utils/minmax_norm.glsl diff --git a/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py b/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py index 112ba8c80..2849982f4 100644 --- a/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py +++ b/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py @@ -108,7 +108,7 @@ def uv_calculations(n): odf_actor.GetProperty().SetTexture("texture0", texture) - odf_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniformi( + odf_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniformf( "shDegree", sh_degree ) @@ -143,15 +143,15 @@ def uv_calculations(n): # The index of the highest used band of the spherical harmonics basis. Must # be even, at least 2 and at most 12. - def_sh_degree = "//#define SH_DEGREE 8" + def_sh_degree = "#define SH_DEGREE 4" # The number of spherical harmonics basis functions - # def_sh_count = "#define SH_COUNT (((SH_DEGREE + 1) * (SH_DEGREE + 2)) / 2)" - def_sh_count = "#define SH_COUNT (((shDegree + 1) * (shDegree + 2)) / 2)" + def_sh_count = "#define SH_COUNT (((SH_DEGREE + 1) * (SH_DEGREE + 2)) / 2)" + # def_sh_count = "#define SH_COUNT (((shDegree + 1) * (shDegree + 2)) / 2)" # Degree of polynomials for which we have to find roots - # def_max_degree = "#define MAX_DEGREE (2 * SH_DEGREE + 2)" - def_max_degree = "#define MAX_DEGREE (2 * shDegree + 2)" + def_max_degree = "#define MAX_DEGREE (2 * SH_DEGREE + 2)" + # def_max_degree = "#define MAX_DEGREE (2 * shDegree + 2)" # If GL_EXT_control_flow_attributes is available, these defines should be # defined as [[unroll]] and [[loop]] to give reasonable hints to the @@ -185,16 +185,7 @@ def uv_calculations(n): in vec3 camUpMCVSOutput; """ - coeffs_norm = """ - float coeffsNorm(float coef) - { - float min = 0; - float max = 1; - float newMin = minmaxVSOutput.x; - float newMax = minmaxVSOutput.y; - return (coef - min) * ((newMax - newMin) / (max - min)) + newMin; - } - """ + coeffs_norm = import_fury_shader(os.path.join("utils", "minmax_norm.glsl")) eval_sh_2 = import_fury_shader( os.path.join("rt_odfs", "descoteaux", "eval_sh_2.frag") @@ -380,7 +371,9 @@ def uv_calculations(n): float i = 1 / (numCoeffs * 2); float sh_coeffs[SH_COUNT]; for(int j=0; j Date: Fri, 29 Mar 2024 14:22:15 -0400 Subject: [PATCH 073/118] Added composed eval sh. --- .../SH-ODF_experimental/ray_traced_6.5.py | 67 +++++-------------- 1 file changed, 17 insertions(+), 50 deletions(-) diff --git a/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py b/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py index 2849982f4..7d3c203ef 100644 --- a/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py +++ b/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py @@ -185,55 +185,24 @@ def uv_calculations(n): in vec3 camUpMCVSOutput; """ - coeffs_norm = import_fury_shader(os.path.join("utils", "minmax_norm.glsl")) + minmax_norm = import_fury_shader(os.path.join("utils", "minmax_norm.glsl")) - eval_sh_2 = import_fury_shader( - os.path.join("rt_odfs", "descoteaux", "eval_sh_2.frag") - ) - - eval_sh_4 = import_fury_shader( - os.path.join("rt_odfs", "descoteaux", "eval_sh_4.frag") - ) - - eval_sh_6 = import_fury_shader( - os.path.join("rt_odfs", "descoteaux", "eval_sh_6.frag") - ) - - eval_sh_8 = import_fury_shader( - os.path.join("rt_odfs", "descoteaux", "eval_sh_8.frag") - ) - - eval_sh_10 = import_fury_shader( - os.path.join("rt_odfs", "descoteaux", "eval_sh_10.frag") - ) - - eval_sh_12 = import_fury_shader( - os.path.join("rt_odfs", "descoteaux", "eval_sh_12.frag") - ) - - eval_sh_grad_2 = import_fury_shader( - os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_2.frag") - ) + sh_basis = "descoteaux" + # sh_basis = "tournier" - eval_sh_grad_4 = import_fury_shader( - os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_4.frag") - ) - - eval_sh_grad_6 = import_fury_shader( - os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_6.frag") - ) - - eval_sh_grad_8 = import_fury_shader( - os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_8.frag") - ) - - eval_sh_grad_10 = import_fury_shader( - os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_10.frag") - ) - - eval_sh_grad_12 = import_fury_shader( - os.path.join("rt_odfs", "descoteaux", "eval_sh_grad_12.frag") - ) + eval_sh_composed = "" + for i in range(2, sh_degree + 1, 2): + eval_sh = import_fury_shader( + os.path.join("rt_odfs", sh_basis, "eval_sh_" + str(i) + ".frag") + ) + eval_sh_grad = import_fury_shader( + os.path.join( + "rt_odfs", sh_basis, "eval_sh_grad_" + str(i) + ".frag" + ) + ) + eval_sh_composed = compose_shader( + [eval_sh_composed, eval_sh, eval_sh_grad] + ) # Searches a single root of a polynomial within a given interval. # param out_root The location of the found root. @@ -340,9 +309,7 @@ def uv_calculations(n): fs_dec = compose_shader([ def_sh_degree, def_sh_count, def_max_degree, def_gl_ext_control_flow_attributes, def_no_intersection, def_pis, - fs_vs_vars, coeffs_norm, eval_sh_2, eval_sh_4, eval_sh_6, eval_sh_8, - eval_sh_10, eval_sh_12, eval_sh_grad_2, eval_sh_grad_4, eval_sh_grad_6, - eval_sh_grad_8, eval_sh_grad_10, eval_sh_grad_12, newton_bisection, + fs_vs_vars, minmax_norm, eval_sh_composed, newton_bisection, find_roots, eval_sh, eval_sh_grad, get_inv_vandermonde, ray_sh_glyph_intersections, get_sh_glyph_normal, blinn_phong_model, linear_to_srgb, srgb_to_linear, linear_rgb_to_srgb, srgb_to_linear_rgb, From 9f4a515b944bfd5ccc1507741e2db5b37a01fc78 Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Tue, 9 Apr 2024 12:35:44 -0400 Subject: [PATCH 074/118] Moved newton_bisection.frag to root_finding folder. --- docs/experimental/SH-ODF_experimental/ray_traced_1.0.py | 2 +- docs/experimental/SH-ODF_experimental/ray_traced_2.0.py | 2 +- docs/experimental/SH-ODF_experimental/ray_traced_3.0.py | 2 +- docs/experimental/SH-ODF_experimental/ray_traced_3.5.py | 2 +- docs/experimental/SH-ODF_experimental/ray_traced_4.0.py | 2 +- docs/experimental/SH-ODF_experimental/ray_traced_5.0.py | 2 +- docs/experimental/SH-ODF_experimental/ray_traced_5.5.py | 2 +- docs/experimental/SH-ODF_experimental/ray_traced_6.0.py | 2 +- docs/experimental/SH-ODF_experimental/ray_traced_6.5.py | 2 +- docs/experimental/SH-ODF_experimental/ray_traced_7.0.py | 2 +- fury/shaders/{rt_odfs => root_finding}/newton_bisection.frag | 0 11 files changed, 10 insertions(+), 10 deletions(-) rename fury/shaders/{rt_odfs => root_finding}/newton_bisection.frag (100%) diff --git a/docs/experimental/SH-ODF_experimental/ray_traced_1.0.py b/docs/experimental/SH-ODF_experimental/ray_traced_1.0.py index 90715704c..52002b9a5 100644 --- a/docs/experimental/SH-ODF_experimental/ray_traced_1.0.py +++ b/docs/experimental/SH-ODF_experimental/ray_traced_1.0.py @@ -162,7 +162,7 @@ # # return true if a root was found, false if no root exists. newton_bisection = import_fury_shader( - os.path.join("rt_odfs", "newton_bisection.frag") + os.path.join("root_finding", "newton_bisection.frag") ) # Finds all roots of the given polynomial in the interval [begin, end] and diff --git a/docs/experimental/SH-ODF_experimental/ray_traced_2.0.py b/docs/experimental/SH-ODF_experimental/ray_traced_2.0.py index 7a6e50f25..279812986 100644 --- a/docs/experimental/SH-ODF_experimental/ray_traced_2.0.py +++ b/docs/experimental/SH-ODF_experimental/ray_traced_2.0.py @@ -256,7 +256,7 @@ def uv_calculations(n): # # return true if a root was found, false if no root exists. newton_bisection = import_fury_shader( - os.path.join("rt_odfs", "newton_bisection.frag") + os.path.join("root_finding", "newton_bisection.frag") ) # Finds all roots of the given polynomial in the interval [begin, end] and diff --git a/docs/experimental/SH-ODF_experimental/ray_traced_3.0.py b/docs/experimental/SH-ODF_experimental/ray_traced_3.0.py index 96eef9606..f08b46a3f 100644 --- a/docs/experimental/SH-ODF_experimental/ray_traced_3.0.py +++ b/docs/experimental/SH-ODF_experimental/ray_traced_3.0.py @@ -163,7 +163,7 @@ # # return true if a root was found, false if no root exists. newton_bisection = import_fury_shader( - os.path.join("rt_odfs", "newton_bisection.frag") + os.path.join("root_finding", "newton_bisection.frag") ) # Finds all roots of the given polynomial in the interval [begin, end] and diff --git a/docs/experimental/SH-ODF_experimental/ray_traced_3.5.py b/docs/experimental/SH-ODF_experimental/ray_traced_3.5.py index 42a855a5a..e4cb2c6cc 100644 --- a/docs/experimental/SH-ODF_experimental/ray_traced_3.5.py +++ b/docs/experimental/SH-ODF_experimental/ray_traced_3.5.py @@ -175,7 +175,7 @@ def key_pressed(obj, event): # # return true if a root was found, false if no root exists. newton_bisection = import_fury_shader( - os.path.join("rt_odfs", "newton_bisection.frag") + os.path.join("root_finding", "newton_bisection.frag") ) # Finds all roots of the given polynomial in the interval [begin, end] and diff --git a/docs/experimental/SH-ODF_experimental/ray_traced_4.0.py b/docs/experimental/SH-ODF_experimental/ray_traced_4.0.py index 7f7dbe6b6..907980ab7 100644 --- a/docs/experimental/SH-ODF_experimental/ray_traced_4.0.py +++ b/docs/experimental/SH-ODF_experimental/ray_traced_4.0.py @@ -256,7 +256,7 @@ def uv_calculations(n): # # return true if a root was found, false if no root exists. newton_bisection = import_fury_shader( - os.path.join("rt_odfs", "newton_bisection.frag") + os.path.join("root_finding", "newton_bisection.frag") ) # Finds all roots of the given polynomial in the interval [begin, end] and diff --git a/docs/experimental/SH-ODF_experimental/ray_traced_5.0.py b/docs/experimental/SH-ODF_experimental/ray_traced_5.0.py index 497437c94..e4f4a5afb 100644 --- a/docs/experimental/SH-ODF_experimental/ray_traced_5.0.py +++ b/docs/experimental/SH-ODF_experimental/ray_traced_5.0.py @@ -255,7 +255,7 @@ def uv_calculations(n): # # return true if a root was found, false if no root exists. newton_bisection = import_fury_shader( - os.path.join("rt_odfs", "newton_bisection.frag") + os.path.join("root_finding", "newton_bisection.frag") ) # Finds all roots of the given polynomial in the interval [begin, end] and diff --git a/docs/experimental/SH-ODF_experimental/ray_traced_5.5.py b/docs/experimental/SH-ODF_experimental/ray_traced_5.5.py index fad425090..f345f62ea 100644 --- a/docs/experimental/SH-ODF_experimental/ray_traced_5.5.py +++ b/docs/experimental/SH-ODF_experimental/ray_traced_5.5.py @@ -260,7 +260,7 @@ def uv_calculations(n): # # return true if a root was found, false if no root exists. newton_bisection = import_fury_shader( - os.path.join("rt_odfs", "newton_bisection.frag") + os.path.join("root_finding", "newton_bisection.frag") ) # Finds all roots of the given polynomial in the interval [begin, end] and diff --git a/docs/experimental/SH-ODF_experimental/ray_traced_6.0.py b/docs/experimental/SH-ODF_experimental/ray_traced_6.0.py index c44117830..3b11c4092 100644 --- a/docs/experimental/SH-ODF_experimental/ray_traced_6.0.py +++ b/docs/experimental/SH-ODF_experimental/ray_traced_6.0.py @@ -252,7 +252,7 @@ def uv_calculations(n): # # return true if a root was found, false if no root exists. newton_bisection = import_fury_shader( - os.path.join("rt_odfs", "newton_bisection.frag") + os.path.join("root_finding", "newton_bisection.frag") ) # Finds all roots of the given polynomial in the interval [begin, end] and diff --git a/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py b/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py index 7d3c203ef..128f12db2 100644 --- a/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py +++ b/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py @@ -221,7 +221,7 @@ def uv_calculations(n): # # return true if a root was found, false if no root exists. newton_bisection = import_fury_shader( - os.path.join("rt_odfs", "newton_bisection.frag") + os.path.join("root_finding", "newton_bisection.frag") ) # Finds all roots of the given polynomial in the interval [begin, end] and diff --git a/docs/experimental/SH-ODF_experimental/ray_traced_7.0.py b/docs/experimental/SH-ODF_experimental/ray_traced_7.0.py index c455794a1..67a0abf30 100644 --- a/docs/experimental/SH-ODF_experimental/ray_traced_7.0.py +++ b/docs/experimental/SH-ODF_experimental/ray_traced_7.0.py @@ -259,7 +259,7 @@ def uv_calculations(n): # # return true if a root was found, false if no root exists. newton_bisection = import_fury_shader( - os.path.join("rt_odfs", "newton_bisection.frag") + os.path.join("root_finding", "newton_bisection.frag") ) # Finds all roots of the given polynomial in the interval [begin, end] and diff --git a/fury/shaders/rt_odfs/newton_bisection.frag b/fury/shaders/root_finding/newton_bisection.frag similarity index 100% rename from fury/shaders/rt_odfs/newton_bisection.frag rename to fury/shaders/root_finding/newton_bisection.frag From a5803559e7f7c293df5068890ba93ef877498c5c Mon Sep 17 00:00:00 2001 From: tvcastillod Date: Tue, 16 Apr 2024 09:49:44 -0500 Subject: [PATCH 075/118] reorganized and refactored odf actor --- fury/actor.py | 6 +-- fury/actors/odf.py | 62 +++++++++++++++-------------- fury/shaders/utils/minmax_norm.glsl | 6 +-- 3 files changed, 39 insertions(+), 35 deletions(-) diff --git a/fury/actor.py b/fury/actor.py index ae3d7423f..91a0e244a 100644 --- a/fury/actor.py +++ b/fury/actor.py @@ -3961,7 +3961,7 @@ def odf( centers, coeffs, degree=None, - basis_type='descoteaux', + sh_basis='descoteaux', scales=1.0, opacity=1.0 ): @@ -3980,7 +3980,7 @@ def odf( Index of the highest used band of the spherical harmonics basis. Must be even, at least 2 and at most 12. If None the degree is set based on the number of SH coefficients given. - basis_type: str, optional + sh_basis: str, optional Type of basis (descoteaux, tournier) 'descoteaux' for the default ``descoteaux07`` DYPY basis. 'tournier' for the default ``tournier07` DYPY basis. @@ -4044,4 +4044,4 @@ def odf( total = np.sum(abs(coeffs), axis=1) coeffs = np.dot(np.diag(1 / total * scales), coeffs) * 1.7 - return sh_odf(centers, coeffs, degree, basis_type, scales, opacity) + return sh_odf(centers, coeffs, degree, sh_basis, scales, opacity) diff --git a/fury/actors/odf.py b/fury/actors/odf.py index 5e8fbe4d4..2f2b07f39 100644 --- a/fury/actors/odf.py +++ b/fury/actors/odf.py @@ -18,7 +18,7 @@ from fury.texture.utils import uv_calculations -def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): +def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): """ Visualize one or many ODFs with different features. @@ -28,7 +28,7 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): ODFs positions. coeffs : ndarray 2D ODFs array in SH coefficients. - basis_type: str, optional + sh_basis: str, optional Type of basis (descoteaux, tournier) 'descoteaux' for the default ``descoteaux07`` DYPY basis. 'tournier' for the default ``tournier07` DYPY basis. @@ -56,11 +56,26 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): big_minmax = np.repeat(minmax, 8, axis=0) attribute_to_actor(odf_actor, big_minmax, "minmax") + odf_actor_pd = odf_actor.GetMapper().GetInput() + + n_glyphs = coeffs.shape[0] + # Coordinates to locate the data of each glyph in the texture. + uv_vals = np.array(uv_calculations(n_glyphs)) + num_pnts = uv_vals.shape[0] + + # Definition of texture coordinates to be associated with the actor. + t_coords = FloatArray() + t_coords.SetNumberOfComponents(2) + t_coords.SetNumberOfTuples(num_pnts) + [t_coords.SetTuple(i, uv_vals[i]) for i in range(num_pnts)] + + set_polydata_tcoords(odf_actor_pd, t_coords) + # The coefficient data is stored in a texture to be passed to the shaders. # Data is normalized to a range of 0 to 1. arr = minmax_norm(coeffs) - # Data is turned into values within the RGB color range, and then coverted + # Data is turned into values within the RGB color range, and then converted # into a vtk image data. arr *= 255 grid = numpy_to_vtk_image_data(arr.astype(np.uint8)) @@ -73,21 +88,6 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): # Texture is associated with the actor odf_actor.GetProperty().SetTexture("texture0", texture) - odf_actor_pd = odf_actor.GetMapper().GetInput() - - n_glyphs = coeffs.shape[0] - # Coordinates to locate the data of each glyph in the texture. - uv_vals = np.array(uv_calculations(n_glyphs)) - num_pnts = uv_vals.shape[0] - - # Definition of texture coordinates to be associated with the actor. - t_coords = FloatArray() - t_coords.SetNumberOfComponents(2) - t_coords.SetNumberOfTuples(num_pnts) - [t_coords.SetTuple(i, uv_vals[i]) for i in range(num_pnts)] - - set_polydata_tcoords(odf_actor_pd, t_coords) - # The number of coefficients is associated to the order of the SH odf_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniformf( "numCoeffs", ((degree + 1) * (degree + 2)) / 2 @@ -169,14 +169,19 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): coeffs_norm = import_fury_shader(os.path.join("utils", "minmax_norm.glsl")) - eval_sh_list = '' - for i in range(2, degree+1, 2): + eval_sh_composed = "" + for i in range(2, degree + 1, 2): #PUT sh_degree eval_sh = import_fury_shader( - os.path.join("rt_odfs", basis_type, 'eval_sh_' + str(i) + '.frag')) + os.path.join("rt_odfs", sh_basis, "eval_sh_" + str(i) + ".frag") + ) eval_sh_grad = import_fury_shader( - os.path.join("rt_odfs", basis_type, - 'eval_sh_grad_' + str(i) + '.frag')) - eval_sh_list = eval_sh_list + '\n\n' + eval_sh + '\n\n' + eval_sh_grad + os.path.join( + "rt_odfs", sh_basis, "eval_sh_grad_" + str(i) + ".frag" + ) + ) + eval_sh_composed = compose_shader( + [eval_sh_composed, eval_sh, eval_sh_grad] + ) # Searches a single root of a polynomial within a given interval. # param out_root The location of the found root. @@ -283,7 +288,7 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): fs_dec = compose_shader([ def_sh_degree, def_sh_count, def_max_degree, def_gl_ext_control_flow_attributes, def_no_intersection, def_pis, - fs_vs_vars, coeffs_norm, eval_sh_list, newton_bisection, find_roots, + fs_vs_vars, coeffs_norm, eval_sh_composed, newton_bisection, find_roots, eval_sh, eval_sh_grad, get_inv_vandermonde, ray_sh_glyph_intersections, get_sh_glyph_normal, blinn_phong_model, linear_to_srgb, srgb_to_linear, linear_rgb_to_srgb, srgb_to_linear_rgb, tonemap @@ -311,10 +316,9 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): float i = 1 / (numCoeffs * 2); float sh_coeffs[SH_COUNT]; for(int j=0; j Date: Tue, 23 Apr 2024 15:37:55 -0400 Subject: [PATCH 076/118] Re-added newton_bisection.frag to rt_odfs. --- .../SH-ODF_experimental/ray_traced_1.0.py | 2 +- .../SH-ODF_experimental/ray_traced_2.0.py | 2 +- .../SH-ODF_experimental/ray_traced_3.0.py | 2 +- .../SH-ODF_experimental/ray_traced_3.5.py | 2 +- .../SH-ODF_experimental/ray_traced_4.0.py | 2 +- .../SH-ODF_experimental/ray_traced_5.0.py | 2 +- .../SH-ODF_experimental/ray_traced_5.5.py | 2 +- .../SH-ODF_experimental/ray_traced_6.0.py | 2 +- .../SH-ODF_experimental/ray_traced_6.5.py | 52 ++++++++++++------- fury/shaders/rt_odfs/newton_bisection.frag | 47 +++++++++++++++++ 10 files changed, 88 insertions(+), 27 deletions(-) create mode 100644 fury/shaders/rt_odfs/newton_bisection.frag diff --git a/docs/experimental/SH-ODF_experimental/ray_traced_1.0.py b/docs/experimental/SH-ODF_experimental/ray_traced_1.0.py index 52002b9a5..90715704c 100644 --- a/docs/experimental/SH-ODF_experimental/ray_traced_1.0.py +++ b/docs/experimental/SH-ODF_experimental/ray_traced_1.0.py @@ -162,7 +162,7 @@ # # return true if a root was found, false if no root exists. newton_bisection = import_fury_shader( - os.path.join("root_finding", "newton_bisection.frag") + os.path.join("rt_odfs", "newton_bisection.frag") ) # Finds all roots of the given polynomial in the interval [begin, end] and diff --git a/docs/experimental/SH-ODF_experimental/ray_traced_2.0.py b/docs/experimental/SH-ODF_experimental/ray_traced_2.0.py index 279812986..7a6e50f25 100644 --- a/docs/experimental/SH-ODF_experimental/ray_traced_2.0.py +++ b/docs/experimental/SH-ODF_experimental/ray_traced_2.0.py @@ -256,7 +256,7 @@ def uv_calculations(n): # # return true if a root was found, false if no root exists. newton_bisection = import_fury_shader( - os.path.join("root_finding", "newton_bisection.frag") + os.path.join("rt_odfs", "newton_bisection.frag") ) # Finds all roots of the given polynomial in the interval [begin, end] and diff --git a/docs/experimental/SH-ODF_experimental/ray_traced_3.0.py b/docs/experimental/SH-ODF_experimental/ray_traced_3.0.py index f08b46a3f..96eef9606 100644 --- a/docs/experimental/SH-ODF_experimental/ray_traced_3.0.py +++ b/docs/experimental/SH-ODF_experimental/ray_traced_3.0.py @@ -163,7 +163,7 @@ # # return true if a root was found, false if no root exists. newton_bisection = import_fury_shader( - os.path.join("root_finding", "newton_bisection.frag") + os.path.join("rt_odfs", "newton_bisection.frag") ) # Finds all roots of the given polynomial in the interval [begin, end] and diff --git a/docs/experimental/SH-ODF_experimental/ray_traced_3.5.py b/docs/experimental/SH-ODF_experimental/ray_traced_3.5.py index e4cb2c6cc..42a855a5a 100644 --- a/docs/experimental/SH-ODF_experimental/ray_traced_3.5.py +++ b/docs/experimental/SH-ODF_experimental/ray_traced_3.5.py @@ -175,7 +175,7 @@ def key_pressed(obj, event): # # return true if a root was found, false if no root exists. newton_bisection = import_fury_shader( - os.path.join("root_finding", "newton_bisection.frag") + os.path.join("rt_odfs", "newton_bisection.frag") ) # Finds all roots of the given polynomial in the interval [begin, end] and diff --git a/docs/experimental/SH-ODF_experimental/ray_traced_4.0.py b/docs/experimental/SH-ODF_experimental/ray_traced_4.0.py index 907980ab7..7f7dbe6b6 100644 --- a/docs/experimental/SH-ODF_experimental/ray_traced_4.0.py +++ b/docs/experimental/SH-ODF_experimental/ray_traced_4.0.py @@ -256,7 +256,7 @@ def uv_calculations(n): # # return true if a root was found, false if no root exists. newton_bisection = import_fury_shader( - os.path.join("root_finding", "newton_bisection.frag") + os.path.join("rt_odfs", "newton_bisection.frag") ) # Finds all roots of the given polynomial in the interval [begin, end] and diff --git a/docs/experimental/SH-ODF_experimental/ray_traced_5.0.py b/docs/experimental/SH-ODF_experimental/ray_traced_5.0.py index e4f4a5afb..497437c94 100644 --- a/docs/experimental/SH-ODF_experimental/ray_traced_5.0.py +++ b/docs/experimental/SH-ODF_experimental/ray_traced_5.0.py @@ -255,7 +255,7 @@ def uv_calculations(n): # # return true if a root was found, false if no root exists. newton_bisection = import_fury_shader( - os.path.join("root_finding", "newton_bisection.frag") + os.path.join("rt_odfs", "newton_bisection.frag") ) # Finds all roots of the given polynomial in the interval [begin, end] and diff --git a/docs/experimental/SH-ODF_experimental/ray_traced_5.5.py b/docs/experimental/SH-ODF_experimental/ray_traced_5.5.py index f345f62ea..fad425090 100644 --- a/docs/experimental/SH-ODF_experimental/ray_traced_5.5.py +++ b/docs/experimental/SH-ODF_experimental/ray_traced_5.5.py @@ -260,7 +260,7 @@ def uv_calculations(n): # # return true if a root was found, false if no root exists. newton_bisection = import_fury_shader( - os.path.join("root_finding", "newton_bisection.frag") + os.path.join("rt_odfs", "newton_bisection.frag") ) # Finds all roots of the given polynomial in the interval [begin, end] and diff --git a/docs/experimental/SH-ODF_experimental/ray_traced_6.0.py b/docs/experimental/SH-ODF_experimental/ray_traced_6.0.py index 3b11c4092..c44117830 100644 --- a/docs/experimental/SH-ODF_experimental/ray_traced_6.0.py +++ b/docs/experimental/SH-ODF_experimental/ray_traced_6.0.py @@ -252,7 +252,7 @@ def uv_calculations(n): # # return true if a root was found, false if no root exists. newton_bisection = import_fury_shader( - os.path.join("root_finding", "newton_bisection.frag") + os.path.join("rt_odfs", "newton_bisection.frag") ) # Finds all roots of the given polynomial in the interval [begin, end] and diff --git a/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py b/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py index 128f12db2..083cc56e8 100644 --- a/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py +++ b/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py @@ -45,12 +45,16 @@ def uv_calculations(n): dataset_dir = os.path.join(dipy_home, "stanford_hardi") coeffs, affine = load_nifti( - os.path.join(dataset_dir, "9x11_debug_sh_coeffs.nii.gz") + os.path.join(dataset_dir, "odf_debug_sh_coeffs_9x11x28(6).nii.gz") ) - sh_count = coeffs.shape[-1] + max_num_coeffs = coeffs.shape[-1] - sh_degree = int((np.sqrt(8 * sh_count + 1) - 3) / 2) + max_sh_degree = int((np.sqrt(8 * max_num_coeffs + 1) - 3) / 2) + + max_poly_degree = 2 * max_sh_degree + 2 + + viz_sh_degree = 6 valid_mask = np.abs(coeffs).max(axis=(-1)) > 0 indices = np.nonzero(valid_mask) @@ -108,18 +112,18 @@ def uv_calculations(n): odf_actor.GetProperty().SetTexture("texture0", texture) - odf_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniformf( - "shDegree", sh_degree - ) - odf_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniformi( - "numCoeffs", sh_count + "shDegree", viz_sh_degree ) vs_dec = """ + uniform int shDegree; + in vec3 center; in vec2 minmax; + flat out int numCoeffsVSOutput; + flat out int maxPolyDegreeVSOutput; out vec4 vertexMCVSOutput; out vec3 centerMCVSOutput; out vec2 minmaxVSOutput; @@ -129,6 +133,8 @@ def uv_calculations(n): """ vs_impl = """ + numCoeffsVSOutput = (shDegree + 1) * (shDegree + 2) / 2; + maxPolyDegreeVSOutput = 2 * shDegree + 2; vertexMCVSOutput = vertexMC; centerMCVSOutput = center; minmaxVSOutput = minmax; @@ -143,15 +149,16 @@ def uv_calculations(n): # The index of the highest used band of the spherical harmonics basis. Must # be even, at least 2 and at most 12. - def_sh_degree = "#define SH_DEGREE 4" + # def_sh_degree = "#define SH_DEGREE 4" + def_sh_degree = f"#define SH_DEGREE {max_sh_degree}" # The number of spherical harmonics basis functions - def_sh_count = "#define SH_COUNT (((SH_DEGREE + 1) * (SH_DEGREE + 2)) / 2)" - # def_sh_count = "#define SH_COUNT (((shDegree + 1) * (shDegree + 2)) / 2)" + # def_sh_count = "#define SH_COUNT (((SH_DEGREE + 1) * (SH_DEGREE + 2)) / 2)" + def_sh_count = f"#define SH_COUNT {max_num_coeffs}" # Degree of polynomials for which we have to find roots - def_max_degree = "#define MAX_DEGREE (2 * SH_DEGREE + 2)" - # def_max_degree = "#define MAX_DEGREE (2 * shDegree + 2)" + # def_max_degree = "#define MAX_DEGREE (2 * SH_DEGREE + 2)" + def_max_degree = f"#define MAX_DEGREE {max_poly_degree}" # If GL_EXT_control_flow_attributes is available, these defines should be # defined as [[unroll]] and [[loop]] to give reasonable hints to the @@ -177,6 +184,8 @@ def uv_calculations(n): """ fs_vs_vars = """ + flat in int numCoeffsVSOutput; + flat in int maxPolyDegreeVSOutput; in vec4 vertexMCVSOutput; in vec3 centerMCVSOutput; in vec2 minmaxVSOutput; @@ -191,7 +200,7 @@ def uv_calculations(n): # sh_basis = "tournier" eval_sh_composed = "" - for i in range(2, sh_degree + 1, 2): + for i in range(2, max_sh_degree + 1, 2): eval_sh = import_fury_shader( os.path.join("rt_odfs", sh_basis, "eval_sh_" + str(i) + ".frag") ) @@ -262,6 +271,7 @@ def uv_calculations(n): # glyph. Their exact meaning is defined by eval_sh(). # param ray_origin The origin of the ray, relative to the glyph center. # param ray_dir The normalized direction vector of the ray. + # TODO: Pass numCoeffs ray_sh_glyph_intersections = import_fury_shader( os.path.join("rt_odfs", "ray_sh_glyph_intersections.frag") ) @@ -335,12 +345,15 @@ def uv_calculations(n): # Define SH coefficients (measured up to band 8, noise beyond that) sh_coeffs = """ - float i = 1 / (numCoeffs * 2); + float i = 1 / (numCoeffsVSOutput * 2); float sh_coeffs[SH_COUNT]; - for(int j=0; j 0.0) { first_ray_param = ray_params[i]; break; diff --git a/fury/shaders/rt_odfs/newton_bisection.frag b/fury/shaders/rt_odfs/newton_bisection.frag new file mode 100644 index 000000000..3f4b7f81f --- /dev/null +++ b/fury/shaders/rt_odfs/newton_bisection.frag @@ -0,0 +1,47 @@ +bool newton_bisection(out float out_root, out float out_end_value, + float poly[MAX_DEGREE + 1], float begin, float end, + float begin_value, float error_tolerance) +{ + if (begin == end) { + out_end_value = begin_value; + return false; + } + // Evaluate the polynomial at the end of the interval + out_end_value = poly[MAX_DEGREE]; + _unroll_ + for (int i = MAX_DEGREE - 1; i != -1; --i) + out_end_value = out_end_value * end + poly[i]; + // If the values at both ends have the same non-zero sign, there is no root + if (begin_value * out_end_value > 0.0) + return false; + // Otherwise, we find the root iteratively using Newton bisection (with + // bounded iteration count) + float current = 0.5 * (begin + end); + _loop_ + for (int i = 0; i != 90; ++i) { + // Evaluate the polynomial and its derivative + float value = poly[MAX_DEGREE] * current + poly[MAX_DEGREE - 1]; + float derivative = poly[MAX_DEGREE]; + _unroll_ + for (int j = MAX_DEGREE - 2; j != -1; --j) { + derivative = derivative * current + value; + value = value * current + poly[j]; + } + // Shorten the interval + bool right = begin_value * value > 0.0; + begin = right ? current : begin; + end = right ? end : current; + // Apply Newton's method + float guess = current - value / derivative; + // Pick a guess + float middle = 0.5 * (begin + end); + float next = (guess >= begin && guess <= end) ? guess : middle; + // Move along or terminate + bool done = abs(next - current) < error_tolerance; + current = next; + if (done) + break; + } + out_root = current; + return true; +} From 4c66c8197af3b8bc3a6f66805646c9d5b820e2ca Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Tue, 23 Apr 2024 17:12:41 -0400 Subject: [PATCH 077/118] Fixed uniform and flats data type. Added numCoeffs param to rayGlyphInteresctions function. --- .../SH-ODF_experimental/ray_traced_6.5.py | 27 +++--- .../odf/ray_glyph_intersections.frag | 85 +++++++++++++++++++ 2 files changed, 100 insertions(+), 12 deletions(-) create mode 100644 fury/shaders/ray_traced/odf/ray_glyph_intersections.frag diff --git a/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py b/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py index 083cc56e8..247cadd30 100644 --- a/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py +++ b/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py @@ -45,7 +45,8 @@ def uv_calculations(n): dataset_dir = os.path.join(dipy_home, "stanford_hardi") coeffs, affine = load_nifti( - os.path.join(dataset_dir, "odf_debug_sh_coeffs_9x11x28(6).nii.gz") + # os.path.join(dataset_dir, "odf_debug_sh_coeffs_9x11x28(6).nii.gz") + os.path.join(dataset_dir, "odf_slice_2.nii.gz") ) max_num_coeffs = coeffs.shape[-1] @@ -54,7 +55,7 @@ def uv_calculations(n): max_poly_degree = 2 * max_sh_degree + 2 - viz_sh_degree = 6 + viz_sh_degree = max_sh_degree valid_mask = np.abs(coeffs).max(axis=(-1)) > 0 indices = np.nonzero(valid_mask) @@ -112,18 +113,18 @@ def uv_calculations(n): odf_actor.GetProperty().SetTexture("texture0", texture) - odf_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniformi( + odf_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniformf( "shDegree", viz_sh_degree ) vs_dec = """ - uniform int shDegree; + uniform float shDegree; in vec3 center; in vec2 minmax; - flat out int numCoeffsVSOutput; - flat out int maxPolyDegreeVSOutput; + flat out float numCoeffsVSOutput; + flat out float maxPolyDegreeVSOutput; out vec4 vertexMCVSOutput; out vec3 centerMCVSOutput; out vec2 minmaxVSOutput; @@ -184,8 +185,8 @@ def uv_calculations(n): """ fs_vs_vars = """ - flat in int numCoeffsVSOutput; - flat in int maxPolyDegreeVSOutput; + flat in float numCoeffsVSOutput; + flat in float maxPolyDegreeVSOutput; in vec4 vertexMCVSOutput; in vec3 centerMCVSOutput; in vec2 minmaxVSOutput; @@ -273,7 +274,7 @@ def uv_calculations(n): # param ray_dir The normalized direction vector of the ray. # TODO: Pass numCoeffs ray_sh_glyph_intersections = import_fury_shader( - os.path.join("rt_odfs", "ray_sh_glyph_intersections.frag") + os.path.join("ray_traced", "odf", "ray_glyph_intersections.frag") ) # Provides a normalized normal vector for a spherical harmonics glyph. @@ -360,15 +361,17 @@ def uv_calculations(n): # Perform the intersection test intersection_test = """ float ray_params[MAX_DEGREE]; - ray_sh_glyph_intersections(ray_params, sh_coeffs, ro - centerMCVSOutput, rd); + rayGlyphIntersections( + ray_params, sh_coeffs, numCoeffsVSOutput, ro - centerMCVSOutput, rd + ); """ # Identify the first intersection first_intersection = """ float first_ray_param = NO_INTERSECTION; _unroll_ - //for (int i = 0; i != MAX_DEGREE; ++i) { - for (int i = 0; i != maxPolyDegreeVSOutput; ++i) { + for (int i = 0; i != MAX_DEGREE; ++i) { + //for (int i = 0; i != maxPolyDegreeVSOutput; ++i) { if (ray_params[i] != NO_INTERSECTION && ray_params[i] > 0.0) { first_ray_param = ray_params[i]; break; diff --git a/fury/shaders/ray_traced/odf/ray_glyph_intersections.frag b/fury/shaders/ray_traced/odf/ray_glyph_intersections.frag new file mode 100644 index 000000000..058c6516b --- /dev/null +++ b/fury/shaders/ray_traced/odf/ray_glyph_intersections.frag @@ -0,0 +1,85 @@ +void rayGlyphIntersections(out float outRayParams[MAX_DEGREE], float shCoeffs[SH_COUNT], + float numCoeffs, vec3 rayOrigin, vec3 rayDir) +{ + // Determine the direction from the glyph center to the closest point on + // the ray + float dir_dot_origin = dot(rayDir, rayOrigin); + vec3 closest_dir = normalize(rayOrigin - dir_dot_origin * rayDir); + // Evaluate the SH polynomial at SH_DEGREE + 1 points. That is enough to + // know its value everywhere along the ray. + float sh_values[SH_DEGREE + 1]; + _unroll_ + for (int i = 0; i != SH_DEGREE + 1; ++i) { + vec3 point = cos(float(i) * (M_PI / float(SH_DEGREE + 1))) * rayDir + + sin(float(i) * (M_PI / float(SH_DEGREE + 1))) * closest_dir; + float shs[SH_COUNT]; + eval_sh(shs, point); + sh_values[i] = 0.0; + _unroll_ + for (int j = 0; j != SH_COUNT; ++j) + sh_values[i] += shCoeffs[j] * shs[j]; + } + // Compute coefficients of the SH polynomial along the ray in the + // coordinate frame given by rayDir and closest_dir + float radius_poly[SH_DEGREE + 1]; + float inv_vander[(SH_DEGREE + 1) * (SH_DEGREE + 1)]; + get_inv_vandermonde(inv_vander); + _unroll_ + for (int i = 0; i != SH_DEGREE + 1; ++i) { + radius_poly[i] = 0.0; + _unroll_ + for (int j = 0; j != SH_DEGREE + 1; ++j) + radius_poly[i] += inv_vander[i * (SH_DEGREE + 1) + j] * sh_values[j]; + } + // Compute a bounding circle around the glyph in the relevant plane + float radius_max = 0.0; + _unroll_ + for (int i = 0; i != SH_DEGREE + 1; ++i) { + float bound = sqrt( + pow(float(i), float(i)) * pow(float(SH_DEGREE - i), float(SH_DEGREE - i)) / + pow(float(SH_DEGREE), float(SH_DEGREE)) + ); + // Workaround for buggy compilers where 0^0 is 0 + bound = (i == 0 || i == SH_DEGREE) ? 1.0 : bound; + radius_max += bound * abs(radius_poly[i]); + } + // Figure out the interval, where (if at all) the ray intersects the circle + float closest_dot_origin = dot(closest_dir, rayOrigin); + if (radius_max < abs(closest_dot_origin)) { + _unroll_ + for (int i = 0; i != MAX_DEGREE; ++i) + outRayParams[i] = NO_INTERSECTION; + return; + } + float radius_over_dot = radius_max / closest_dot_origin; + float u_max = sqrt(radius_over_dot * radius_over_dot - 1.0); + // Take the square of radius_poly + float poly[MAX_DEGREE + 1]; + _unroll_ + for (int i = 0; i != MAX_DEGREE + 1; ++i) + poly[i] = 0.0; + _unroll_ + for (int i = 0; i != SH_DEGREE + 1; ++i) + _unroll_ + for (int j = 0; j != SH_DEGREE + 1; ++j) + poly[i + j] += radius_poly[i] * radius_poly[j]; + // Subtract the scaled (2 * SH_DEGREE + 2)-th power of the distance to the + // glyph center + float dot_sq = closest_dot_origin * closest_dot_origin; + float binomial = 1.0; + _unroll_ + for (int i = 0; i != SH_DEGREE + 2; ++i) { + poly[2 * i] -= binomial * dot_sq; + // Update the binomial coefficient using a recurrence relation + binomial *= float(SH_DEGREE + 1 - i) / float(i + 1); + } + // Find roots of the polynomial within the relevant bounds + float roots[MAX_DEGREE + 1]; + find_roots(roots, poly, -u_max, u_max); + // Convert them back to the original coordinate frame (i.e. ray parameters) + _unroll_ + for (int i = 0; i != MAX_DEGREE; ++i) + outRayParams[i] = (roots[i] != NO_INTERSECTION) + ? (roots[i] * closest_dot_origin - dir_dot_origin) + : NO_INTERSECTION; +} From 00c069aca2e1b4c6c06806fa8a70940fa8d612d7 Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Wed, 24 Apr 2024 15:35:21 -0400 Subject: [PATCH 078/118] Moved dipy_slicer.py script to personal repo. Renamed as odf_slicer_cli.py --- .../SH-ODF_experimental/dipy_slicer.py | 65 ------------------- 1 file changed, 65 deletions(-) delete mode 100644 docs/experimental/SH-ODF_experimental/dipy_slicer.py diff --git a/docs/experimental/SH-ODF_experimental/dipy_slicer.py b/docs/experimental/SH-ODF_experimental/dipy_slicer.py deleted file mode 100644 index 35c8e12fc..000000000 --- a/docs/experimental/SH-ODF_experimental/dipy_slicer.py +++ /dev/null @@ -1,65 +0,0 @@ -""" -This script adds an argument parser to the ray_traced_6.0.py script. -""" - -import argparse -import os - -import numpy as np -from dipy.data import get_sphere -from dipy.io.image import load_nifti -from dipy.reconst.shm import sh_to_sf - -from fury import actor, window - - -def uv_calculations(n): - uvs = [] - for i in range(0, n): - a = (n - (i + 1)) / n - b = (n - i) / n - # glyph_coord [0, a], [0, b], [1, b], [1, a] - uvs.extend( - [ - [0.001, a + 0.001], - [0.001, b - 0.001], - [0.999, b - 0.001], - [0.999, a + 0.001], - [0.001, a + 0.001], - [0.001, b - 0.001], - [0.999, b - 0.001], - [0.999, a + 0.001], - ] - ) - return uvs - - -if __name__ == "__main__": - parser = argparse.ArgumentParser() - parser.add_argument( - "file", help="Path to spherical harmonic coefficients file." - ) - args = parser.parse_args() - - show_man = window.ShowManager(size=(1280, 720)) - - coeffs, affine = load_nifti(args.file) - - sphere = get_sphere("repulsion724") - - sh_basis = "tournier07" - sh_order = 8 - - tensor_sf = sh_to_sf( - coeffs, - sh_order=sh_order, - basis_type=sh_basis, - sphere=sphere, - legacy=False, - ) - - odf_slicer_actor = actor.odf_slicer(tensor_sf, sphere=sphere, scale=0.5) - - show_man.scene.add(odf_slicer_actor) - - show_man.start() From c33c4d697907d970a0cc8003d9f0ba4a3baffdf9 Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Fri, 26 Apr 2024 11:43:27 -0400 Subject: [PATCH 079/118] Minor fix on uncertainty cone actor. --- fury/actors/tensor.py | 208 ++++++++++++++++++++++++------------------ 1 file changed, 117 insertions(+), 91 deletions(-) diff --git a/fury/actors/tensor.py b/fury/actors/tensor.py index c4478554b..864849100 100644 --- a/fury/actors/tensor.py +++ b/fury/actors/tensor.py @@ -42,29 +42,28 @@ def tensor_ellipsoid(centers, axes, lengths, colors, scales, opacity): n_verts = 8 big_centers = np.repeat(centers, n_verts, axis=0) - attribute_to_actor(box_actor, big_centers, 'center') + attribute_to_actor(box_actor, big_centers, "center") big_scales = np.repeat(scales, n_verts, axis=0) - attribute_to_actor(box_actor, big_scales, 'scale') + attribute_to_actor(box_actor, big_scales, "scale") big_values = np.repeat(np.array(lengths, dtype=float), n_verts, axis=0) - attribute_to_actor(box_actor, big_values, 'evals') + attribute_to_actor(box_actor, big_values, "evals") evec1 = np.array([item[0] for item in axes]) evec2 = np.array([item[1] for item in axes]) evec3 = np.array([item[2] for item in axes]) big_vectors_1 = np.repeat(evec1, n_verts, axis=0) - attribute_to_actor(box_actor, big_vectors_1, 'evec1') + attribute_to_actor(box_actor, big_vectors_1, "evec1") big_vectors_2 = np.repeat(evec2, n_verts, axis=0) - attribute_to_actor(box_actor, big_vectors_2, 'evec2') + attribute_to_actor(box_actor, big_vectors_2, "evec2") big_vectors_3 = np.repeat(evec3, n_verts, axis=0) - attribute_to_actor(box_actor, big_vectors_3, 'evec3') + attribute_to_actor(box_actor, big_vectors_3, "evec3") # Start of shader implementation - vs_dec = \ - """ + vs_dec = """ in vec3 center; in float scale; in vec3 evals; @@ -80,8 +79,7 @@ def tensor_ellipsoid(centers, axes, lengths, colors, scales, opacity): """ # Variables assignment - v_assign = \ - """ + v_assign = """ vertexMCVSOutput = vertexMC; centerMCVSOutput = center; scaleVSOutput = scale; @@ -94,8 +92,7 @@ def tensor_ellipsoid(centers, axes, lengths, colors, scales, opacity): evals = "evalsVSOutput = clamp(evalsVSOutput,0.05,1);" # Scaling matrix - sc_matrix = \ - """ + sc_matrix = """ mat3 S = mat3(1/evalsVSOutput.x, 0.0, 0.0, 0.0, 1/evalsVSOutput.y, 0.0, 0.0, 0.0, 1/evalsVSOutput.z); @@ -107,14 +104,14 @@ def tensor_ellipsoid(centers, axes, lengths, colors, scales, opacity): # Tensor matrix t_matrix = "tensorMatrix = inverse(R) * S * R;" - vs_impl = compose_shader([v_assign, n_evals, evals, sc_matrix, rot_matrix, - t_matrix]) + vs_impl = compose_shader( + [v_assign, n_evals, evals, sc_matrix, rot_matrix, t_matrix] + ) # Adding shader implementation to actor - shader_to_actor(box_actor, 'vertex', decl_code=vs_dec, impl_code=vs_impl) + shader_to_actor(box_actor, "vertex", decl_code=vs_dec, impl_code=vs_impl) - fs_vars_dec = \ - """ + fs_vars_dec = """ in vec4 vertexMCVSOutput; in vec3 centerMCVSOutput; in float scaleVSOutput; @@ -125,11 +122,10 @@ def tensor_ellipsoid(centers, axes, lengths, colors, scales, opacity): """ # Importing the sphere SDF - sd_sphere = import_fury_shader(os.path.join('sdf', 'sd_sphere.frag')) + sd_sphere = import_fury_shader(os.path.join("sdf", "sd_sphere.frag")) # SDF definition - sdf_map = \ - """ + sdf_map = """ float map(in vec3 position) { /* @@ -152,38 +148,48 @@ def tensor_ellipsoid(centers, axes, lengths, colors, scales, opacity): """ # Importing central differences function for computing surface normals - central_diffs_normal = import_fury_shader(os.path.join( - 'sdf', 'central_diffs.frag')) + central_diffs_normal = import_fury_shader( + os.path.join("sdf", "central_diffs.frag") + ) # Importing raymarching function - cast_ray = import_fury_shader(os.path.join( - 'ray_marching', 'cast_ray.frag')) + cast_ray = import_fury_shader( + os.path.join("ray_marching", "cast_ray.frag") + ) # Importing the function that generates the ray components - ray_generation = import_fury_shader(os.path.join( - 'ray_marching', 'gen_ray.frag')) + ray_generation = import_fury_shader( + os.path.join("ray_marching", "gen_ray.frag") + ) # Importing Blinn-Phong model for lighting - blinn_phong_model = import_fury_shader(os.path.join( - 'lighting', 'blinn_phong_model.frag')) + blinn_phong_model = import_fury_shader( + os.path.join("lighting", "blinn_phong_model.frag") + ) # Full fragment shader declaration - fs_dec = compose_shader([fs_vars_dec, sd_sphere, sdf_map, - central_diffs_normal, cast_ray, ray_generation, - blinn_phong_model]) - - shader_to_actor(box_actor, 'fragment', decl_code=fs_dec) - - ray_components = \ - """ + fs_dec = compose_shader( + [ + fs_vars_dec, + sd_sphere, + sdf_map, + central_diffs_normal, + cast_ray, + ray_generation, + blinn_phong_model, + ] + ) + + shader_to_actor(box_actor, "fragment", decl_code=fs_dec) + + ray_components = """ vec3 ro; vec3 rd; float t; gen_ray(ro, rd, t); """ # Fragment shader output definition # If surface is detected, color is assigned, otherwise, nothing is painted - frag_output_def = \ - """ + frag_output_def = """ if(t < 20) { vec3 pos = ro + t * rd; @@ -205,8 +211,9 @@ def tensor_ellipsoid(centers, axes, lengths, colors, scales, opacity): # Full fragment shader implementation sdf_frag_impl = compose_shader([ray_components, frag_output_def]) - shader_to_actor(box_actor, 'fragment', impl_code=sdf_frag_impl, - block='light') + shader_to_actor( + box_actor, "fragment", impl_code=sdf_frag_impl, block="light" + ) return box_actor @@ -242,29 +249,28 @@ def double_cone(centers, axes, angles, colors, scales, opacity): n_verts = 8 big_centers = np.repeat(centers, n_verts, axis=0) - attribute_to_actor(box_actor, big_centers, 'center') + attribute_to_actor(box_actor, big_centers, "center") big_scales = np.repeat(scales, n_verts, axis=0) - attribute_to_actor(box_actor, big_scales, 'scale') + attribute_to_actor(box_actor, big_scales, "scale") evec1 = np.array([item[0] for item in axes]) evec2 = np.array([item[1] for item in axes]) evec3 = np.array([item[2] for item in axes]) big_vectors_1 = np.repeat(evec1, n_verts, axis=0) - attribute_to_actor(box_actor, big_vectors_1, 'evec1') + attribute_to_actor(box_actor, big_vectors_1, "evec1") big_vectors_2 = np.repeat(evec2, n_verts, axis=0) - attribute_to_actor(box_actor, big_vectors_2, 'evec2') + attribute_to_actor(box_actor, big_vectors_2, "evec2") big_vectors_3 = np.repeat(evec3, n_verts, axis=0) - attribute_to_actor(box_actor, big_vectors_3, 'evec3') + attribute_to_actor(box_actor, big_vectors_3, "evec3") big_angles = np.repeat(np.array(angles, dtype=float), n_verts, axis=0) - attribute_to_actor(box_actor, big_angles, 'angle') + attribute_to_actor(box_actor, big_angles, "angle") # Start of shader implementation - vs_dec = \ - """ + vs_dec = """ in vec3 center; in float scale; in vec3 evec1; @@ -280,8 +286,7 @@ def double_cone(centers, axes, angles, colors, scales, opacity): """ # Variables assignment - v_assign = \ - """ + v_assign = """ vertexMCVSOutput = vertexMC; centerMCVSOutput = center; scaleVSOutput = scale; @@ -289,10 +294,9 @@ def double_cone(centers, axes, angles, colors, scales, opacity): """ # Rotation matrix - rot_matrix = \ - """ + rot_matrix = """ mat3 R = mat3(normalize(evec1), normalize(evec2), normalize(evec3)); - float a = radians(90); + float a = radians(90.0); mat3 rot = mat3(cos(a),-sin(a), 0, sin(a), cos(a), 0, 0 , 0, 1); @@ -301,11 +305,9 @@ def double_cone(centers, axes, angles, colors, scales, opacity): vs_impl = compose_shader([v_assign, rot_matrix]) - shader_to_actor(box_actor, 'vertex', decl_code=vs_dec, - impl_code=vs_impl) + shader_to_actor(box_actor, "vertex", decl_code=vs_dec, impl_code=vs_impl) - fs_vars_dec = \ - """ + fs_vars_dec = """ in vec4 vertexMCVSOutput; in vec3 centerMCVSOutput; in float scaleVSOutput; @@ -316,14 +318,13 @@ def double_cone(centers, axes, angles, colors, scales, opacity): """ # Importing the cone SDF - sd_cone = import_fury_shader(os.path.join('sdf', 'sd_cone.frag')) + sd_cone = import_fury_shader(os.path.join("sdf", "sd_cone.frag")) # Importing the union operation SDF - sd_union = import_fury_shader(os.path.join('sdf', 'sd_union.frag')) + sd_union = import_fury_shader(os.path.join("sdf", "sd_union.frag")) # SDF definition - sdf_map = \ - """ + sdf_map = """ float map(in vec3 position) { vec3 p = (position - centerMCVSOutput)/scaleVSOutput @@ -336,38 +337,49 @@ def double_cone(centers, axes, angles, colors, scales, opacity): """ # Importing central differences function for computing surface normals - central_diffs_normal = import_fury_shader(os.path.join( - 'sdf', 'central_diffs.frag')) + central_diffs_normal = import_fury_shader( + os.path.join("sdf", "central_diffs.frag") + ) # Importing raymarching function - cast_ray = import_fury_shader(os.path.join( - 'ray_marching', 'cast_ray.frag')) + cast_ray = import_fury_shader( + os.path.join("ray_marching", "cast_ray.frag") + ) # Importing the function that generates the ray components - ray_generation = import_fury_shader(os.path.join( - 'ray_marching', 'gen_ray.frag')) + ray_generation = import_fury_shader( + os.path.join("ray_marching", "gen_ray.frag") + ) # Importing Blinn-Phong model for lighting - blinn_phong_model = import_fury_shader(os.path.join( - 'lighting', 'blinn_phong_model.frag')) + blinn_phong_model = import_fury_shader( + os.path.join("lighting", "blinn_phong_model.frag") + ) # Full fragment shader declaration - fs_dec = compose_shader([fs_vars_dec, sd_cone, sd_union, sdf_map, - central_diffs_normal, cast_ray, ray_generation, - blinn_phong_model]) - - shader_to_actor(box_actor, 'fragment', decl_code=fs_dec) - - ray_components = \ - """ + fs_dec = compose_shader( + [ + fs_vars_dec, + sd_cone, + sd_union, + sdf_map, + central_diffs_normal, + cast_ray, + ray_generation, + blinn_phong_model, + ] + ) + + shader_to_actor(box_actor, "fragment", decl_code=fs_dec) + + ray_components = """ vec3 ro; vec3 rd; float t; gen_ray(ro, rd, t); """ # Fragment shader output definition # If surface is detected, color is assigned, otherwise, nothing is painted - frag_output_def = \ - """ + frag_output_def = """ if(t < 20) { vec3 pos = ro + t * rd; @@ -389,8 +401,9 @@ def double_cone(centers, axes, angles, colors, scales, opacity): # Full fragment shader implementation sdf_frag_impl = compose_shader([ray_components, frag_output_def]) - shader_to_actor(box_actor, 'fragment', impl_code=sdf_frag_impl, - block='light') + shader_to_actor( + box_actor, "fragment", impl_code=sdf_frag_impl, block="light" + ) return box_actor @@ -449,14 +462,18 @@ def main_dir_uncertainty(evals, evecs, signal, sigma, b_matrix): """ angles = np.ones(evecs.shape[0]) for i in range(evecs.shape[0]): - sigma_e = np.diag(signal[i] / sigma ** 2) + sigma_e = np.diag(signal[i] / sigma**2) k = np.dot(np.transpose(b_matrix), sigma_e) sigma_ = np.dot(k, b_matrix) dd = np.diag(sigma_) - delta_DD = np.array([[dd[0], dd[3], dd[4]], - [dd[3], dd[1], dd[5]], - [dd[4], dd[5], dd[2]]]) + delta_DD = np.array( + [ + [dd[0], dd[3], dd[4]], + [dd[3], dd[1], dd[5]], + [dd[4], dd[5], dd[2]], + ] + ) # perturbation matrix of tensor D try: @@ -467,17 +484,26 @@ def main_dir_uncertainty(evals, evecs, signal, sigma, b_matrix): D_ = evecs eigen_vals = evals[i] - e1, e2, e3 = np.array(D_[i, :, 0]), np.array(D_[i, :, 1]), \ - np.array(D_[i, :, 2]) + e1, e2, e3 = ( + np.array(D_[i, :, 0]), + np.array(D_[i, :, 1]), + np.array(D_[i, :, 2]), + ) lambda1, lambda2, lambda3 = eigen_vals[0], eigen_vals[1], eigen_vals[2] if lambda1 > lambda2 and lambda1 > lambda3: # The perturbation of the eigenvector associated with the largest # eigenvalue is given by - a = np.dot(np.outer(np.dot(e1, delta_D), np.transpose(e2)) / - (lambda1 - lambda2), e2) - b = np.dot(np.outer(np.dot(e1, delta_D), np.transpose(e3)) / - (lambda1 - lambda3), e3) + a = np.dot( + np.outer(np.dot(e1, delta_D), np.transpose(e2)) + / (lambda1 - lambda2), + e2, + ) + b = np.dot( + np.outer(np.dot(e1, delta_D), np.transpose(e3)) + / (lambda1 - lambda3), + e3, + ) delta_e1 = a + b # The angle \theta between the perturbed principal eigenvector of D From de817abbe685f586cdc24e2a0a6dfbea976df5ca Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Thu, 30 May 2024 07:51:20 -0400 Subject: [PATCH 080/118] Replaced SH_DEGREE with shDegree in rayGlyphIntersections function. --- .../SH-ODF_experimental/ray_traced_6.5.py | 6 +-- .../odf/ray_glyph_intersections.frag | 48 +++++++++---------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py b/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py index 247cadd30..fe7434158 100644 --- a/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py +++ b/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py @@ -45,8 +45,8 @@ def uv_calculations(n): dataset_dir = os.path.join(dipy_home, "stanford_hardi") coeffs, affine = load_nifti( - # os.path.join(dataset_dir, "odf_debug_sh_coeffs_9x11x28(6).nii.gz") - os.path.join(dataset_dir, "odf_slice_2.nii.gz") + os.path.join(dataset_dir, "odf_debug_sh_coeffs_9x11x28(6).nii.gz") + # os.path.join(dataset_dir, "odf_slice_2.nii.gz") ) max_num_coeffs = coeffs.shape[-1] @@ -362,7 +362,7 @@ def uv_calculations(n): intersection_test = """ float ray_params[MAX_DEGREE]; rayGlyphIntersections( - ray_params, sh_coeffs, numCoeffsVSOutput, ro - centerMCVSOutput, rd + ray_params, sh_coeffs, ro - centerMCVSOutput, rd, int(shDegree), int(numCoeffsVSOutput) ); """ diff --git a/fury/shaders/ray_traced/odf/ray_glyph_intersections.frag b/fury/shaders/ray_traced/odf/ray_glyph_intersections.frag index 058c6516b..5ab1cc892 100644 --- a/fury/shaders/ray_traced/odf/ray_glyph_intersections.frag +++ b/fury/shaders/ray_traced/odf/ray_glyph_intersections.frag @@ -1,50 +1,50 @@ void rayGlyphIntersections(out float outRayParams[MAX_DEGREE], float shCoeffs[SH_COUNT], - float numCoeffs, vec3 rayOrigin, vec3 rayDir) + vec3 rayOri, vec3 rayDir, int shDegree, int numCoeffs) { // Determine the direction from the glyph center to the closest point on // the ray - float dir_dot_origin = dot(rayDir, rayOrigin); - vec3 closest_dir = normalize(rayOrigin - dir_dot_origin * rayDir); + float dotDirOri = dot(rayDir, rayOri); + vec3 closestDir = normalize(rayOri - dotDirOri * rayDir); // Evaluate the SH polynomial at SH_DEGREE + 1 points. That is enough to // know its value everywhere along the ray. - float sh_values[SH_DEGREE + 1]; + float shValues[SH_DEGREE + 1]; _unroll_ - for (int i = 0; i != SH_DEGREE + 1; ++i) { - vec3 point = cos(float(i) * (M_PI / float(SH_DEGREE + 1))) * rayDir - + sin(float(i) * (M_PI / float(SH_DEGREE + 1))) * closest_dir; + for (int i = 0; i != shDegree + 1; ++i) { + vec3 point = cos(float(i) * (M_PI / float(shDegree + 1))) * rayDir + + sin(float(i) * (M_PI / float(shDegree + 1))) * closestDir; float shs[SH_COUNT]; eval_sh(shs, point); - sh_values[i] = 0.0; + shValues[i] = 0.0; _unroll_ - for (int j = 0; j != SH_COUNT; ++j) - sh_values[i] += shCoeffs[j] * shs[j]; + for (int j = 0; j != numCoeffs; ++j) + shValues[i] += shCoeffs[j] * shs[j]; } // Compute coefficients of the SH polynomial along the ray in the - // coordinate frame given by rayDir and closest_dir + // coordinate frame given by rayDir and closestDir float radius_poly[SH_DEGREE + 1]; float inv_vander[(SH_DEGREE + 1) * (SH_DEGREE + 1)]; get_inv_vandermonde(inv_vander); _unroll_ - for (int i = 0; i != SH_DEGREE + 1; ++i) { + for (int i = 0; i != shDegree + 1; ++i) { radius_poly[i] = 0.0; _unroll_ - for (int j = 0; j != SH_DEGREE + 1; ++j) - radius_poly[i] += inv_vander[i * (SH_DEGREE + 1) + j] * sh_values[j]; + for (int j = 0; j != shDegree + 1; ++j) + radius_poly[i] += inv_vander[i * (shDegree + 1) + j] * shValues[j]; } // Compute a bounding circle around the glyph in the relevant plane float radius_max = 0.0; _unroll_ - for (int i = 0; i != SH_DEGREE + 1; ++i) { + for (int i = 0; i != shDegree + 1; ++i) { float bound = sqrt( - pow(float(i), float(i)) * pow(float(SH_DEGREE - i), float(SH_DEGREE - i)) / - pow(float(SH_DEGREE), float(SH_DEGREE)) + pow(float(i), float(i)) * pow(float(shDegree - i), float(shDegree - i)) / + pow(float(shDegree), float(shDegree)) ); // Workaround for buggy compilers where 0^0 is 0 - bound = (i == 0 || i == SH_DEGREE) ? 1.0 : bound; + bound = (i == 0 || i == shDegree) ? 1.0 : bound; radius_max += bound * abs(radius_poly[i]); } // Figure out the interval, where (if at all) the ray intersects the circle - float closest_dot_origin = dot(closest_dir, rayOrigin); + float closest_dot_origin = dot(closestDir, rayOri); if (radius_max < abs(closest_dot_origin)) { _unroll_ for (int i = 0; i != MAX_DEGREE; ++i) @@ -59,19 +59,19 @@ void rayGlyphIntersections(out float outRayParams[MAX_DEGREE], float shCoeffs[SH for (int i = 0; i != MAX_DEGREE + 1; ++i) poly[i] = 0.0; _unroll_ - for (int i = 0; i != SH_DEGREE + 1; ++i) + for (int i = 0; i != shDegree + 1; ++i) _unroll_ - for (int j = 0; j != SH_DEGREE + 1; ++j) + for (int j = 0; j != shDegree + 1; ++j) poly[i + j] += radius_poly[i] * radius_poly[j]; // Subtract the scaled (2 * SH_DEGREE + 2)-th power of the distance to the // glyph center float dot_sq = closest_dot_origin * closest_dot_origin; float binomial = 1.0; _unroll_ - for (int i = 0; i != SH_DEGREE + 2; ++i) { + for (int i = 0; i != shDegree + 2; ++i) { poly[2 * i] -= binomial * dot_sq; // Update the binomial coefficient using a recurrence relation - binomial *= float(SH_DEGREE + 1 - i) / float(i + 1); + binomial *= float(shDegree + 1 - i) / float(i + 1); } // Find roots of the polynomial within the relevant bounds float roots[MAX_DEGREE + 1]; @@ -80,6 +80,6 @@ void rayGlyphIntersections(out float outRayParams[MAX_DEGREE], float shCoeffs[SH _unroll_ for (int i = 0; i != MAX_DEGREE; ++i) outRayParams[i] = (roots[i] != NO_INTERSECTION) - ? (roots[i] * closest_dot_origin - dir_dot_origin) + ? (roots[i] * closest_dot_origin - dotDirOri) : NO_INTERSECTION; } From 64a078992569043ad36828e94af7fba2a9b5c160 Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Thu, 30 May 2024 12:04:53 -0400 Subject: [PATCH 081/118] Added extra arguments to rayGlyphIntersections function. --- .../SH-ODF_experimental/ray_traced_6.5.py | 4 +++- .../odf/ray_glyph_intersections.frag | 19 ++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py b/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py index fe7434158..7b15a9983 100644 --- a/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py +++ b/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py @@ -362,7 +362,9 @@ def uv_calculations(n): intersection_test = """ float ray_params[MAX_DEGREE]; rayGlyphIntersections( - ray_params, sh_coeffs, ro - centerMCVSOutput, rd, int(shDegree), int(numCoeffsVSOutput) + ray_params, sh_coeffs, ro - centerMCVSOutput, rd, int(shDegree), + int(numCoeffsVSOutput), int(maxPolyDegreeVSOutput), M_PI, + NO_INTERSECTION ); """ diff --git a/fury/shaders/ray_traced/odf/ray_glyph_intersections.frag b/fury/shaders/ray_traced/odf/ray_glyph_intersections.frag index 5ab1cc892..88967e8f1 100644 --- a/fury/shaders/ray_traced/odf/ray_glyph_intersections.frag +++ b/fury/shaders/ray_traced/odf/ray_glyph_intersections.frag @@ -1,5 +1,6 @@ void rayGlyphIntersections(out float outRayParams[MAX_DEGREE], float shCoeffs[SH_COUNT], - vec3 rayOri, vec3 rayDir, int shDegree, int numCoeffs) + vec3 rayOri, vec3 rayDir, int shDegree, int numCoeffs, int maxPolyDegree, float pi, + float noIntersection) { // Determine the direction from the glyph center to the closest point on // the ray @@ -10,8 +11,8 @@ void rayGlyphIntersections(out float outRayParams[MAX_DEGREE], float shCoeffs[SH float shValues[SH_DEGREE + 1]; _unroll_ for (int i = 0; i != shDegree + 1; ++i) { - vec3 point = cos(float(i) * (M_PI / float(shDegree + 1))) * rayDir - + sin(float(i) * (M_PI / float(shDegree + 1))) * closestDir; + vec3 point = cos(float(i) * (pi / float(shDegree + 1))) * rayDir + + sin(float(i) * (pi / float(shDegree + 1))) * closestDir; float shs[SH_COUNT]; eval_sh(shs, point); shValues[i] = 0.0; @@ -47,8 +48,8 @@ void rayGlyphIntersections(out float outRayParams[MAX_DEGREE], float shCoeffs[SH float closest_dot_origin = dot(closestDir, rayOri); if (radius_max < abs(closest_dot_origin)) { _unroll_ - for (int i = 0; i != MAX_DEGREE; ++i) - outRayParams[i] = NO_INTERSECTION; + for (int i = 0; i != maxPolyDegree; ++i) + outRayParams[i] = noIntersection; return; } float radius_over_dot = radius_max / closest_dot_origin; @@ -56,7 +57,7 @@ void rayGlyphIntersections(out float outRayParams[MAX_DEGREE], float shCoeffs[SH // Take the square of radius_poly float poly[MAX_DEGREE + 1]; _unroll_ - for (int i = 0; i != MAX_DEGREE + 1; ++i) + for (int i = 0; i != maxPolyDegree + 1; ++i) poly[i] = 0.0; _unroll_ for (int i = 0; i != shDegree + 1; ++i) @@ -78,8 +79,8 @@ void rayGlyphIntersections(out float outRayParams[MAX_DEGREE], float shCoeffs[SH find_roots(roots, poly, -u_max, u_max); // Convert them back to the original coordinate frame (i.e. ray parameters) _unroll_ - for (int i = 0; i != MAX_DEGREE; ++i) - outRayParams[i] = (roots[i] != NO_INTERSECTION) + for (int i = 0; i != maxPolyDegree; ++i) + outRayParams[i] = (roots[i] != noIntersection) ? (roots[i] * closest_dot_origin - dotDirOri) - : NO_INTERSECTION; + : noIntersection; } From 326c77f7de09194148175bc900a4f0ce7066c1fa Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Fri, 31 May 2024 12:30:01 -0400 Subject: [PATCH 082/118] Renamed variables in rayGlyphIntersections finction. --- .../odf/ray_glyph_intersections.frag | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/fury/shaders/ray_traced/odf/ray_glyph_intersections.frag b/fury/shaders/ray_traced/odf/ray_glyph_intersections.frag index 88967e8f1..857ee3799 100644 --- a/fury/shaders/ray_traced/odf/ray_glyph_intersections.frag +++ b/fury/shaders/ray_traced/odf/ray_glyph_intersections.frag @@ -22,18 +22,18 @@ void rayGlyphIntersections(out float outRayParams[MAX_DEGREE], float shCoeffs[SH } // Compute coefficients of the SH polynomial along the ray in the // coordinate frame given by rayDir and closestDir - float radius_poly[SH_DEGREE + 1]; - float inv_vander[(SH_DEGREE + 1) * (SH_DEGREE + 1)]; - get_inv_vandermonde(inv_vander); + float radiusPoly[SH_DEGREE + 1]; + float invVander[(SH_DEGREE + 1) * (SH_DEGREE + 1)]; + get_inv_vandermonde(invVander); _unroll_ for (int i = 0; i != shDegree + 1; ++i) { - radius_poly[i] = 0.0; + radiusPoly[i] = 0.0; _unroll_ for (int j = 0; j != shDegree + 1; ++j) - radius_poly[i] += inv_vander[i * (shDegree + 1) + j] * shValues[j]; + radiusPoly[i] += invVander[i * (shDegree + 1) + j] * shValues[j]; } // Compute a bounding circle around the glyph in the relevant plane - float radius_max = 0.0; + float radiusMax = 0.0; _unroll_ for (int i = 0; i != shDegree + 1; ++i) { float bound = sqrt( @@ -42,19 +42,19 @@ void rayGlyphIntersections(out float outRayParams[MAX_DEGREE], float shCoeffs[SH ); // Workaround for buggy compilers where 0^0 is 0 bound = (i == 0 || i == shDegree) ? 1.0 : bound; - radius_max += bound * abs(radius_poly[i]); + radiusMax += bound * abs(radiusPoly[i]); } // Figure out the interval, where (if at all) the ray intersects the circle - float closest_dot_origin = dot(closestDir, rayOri); - if (radius_max < abs(closest_dot_origin)) { + float dotCloOri = dot(closestDir, rayOri); + if (radiusMax < abs(dotCloOri)) { _unroll_ for (int i = 0; i != maxPolyDegree; ++i) outRayParams[i] = noIntersection; return; } - float radius_over_dot = radius_max / closest_dot_origin; - float u_max = sqrt(radius_over_dot * radius_over_dot - 1.0); - // Take the square of radius_poly + float radOverDot = radiusMax / dotCloOri; + float uMax = sqrt(radOverDot * radOverDot - 1.0); + // Take the square of radiusPoly float poly[MAX_DEGREE + 1]; _unroll_ for (int i = 0; i != maxPolyDegree + 1; ++i) @@ -63,24 +63,24 @@ void rayGlyphIntersections(out float outRayParams[MAX_DEGREE], float shCoeffs[SH for (int i = 0; i != shDegree + 1; ++i) _unroll_ for (int j = 0; j != shDegree + 1; ++j) - poly[i + j] += radius_poly[i] * radius_poly[j]; + poly[i + j] += radiusPoly[i] * radiusPoly[j]; // Subtract the scaled (2 * SH_DEGREE + 2)-th power of the distance to the // glyph center - float dot_sq = closest_dot_origin * closest_dot_origin; + float dotSq = dotCloOri * dotCloOri; float binomial = 1.0; _unroll_ for (int i = 0; i != shDegree + 2; ++i) { - poly[2 * i] -= binomial * dot_sq; + poly[2 * i] -= binomial * dotSq; // Update the binomial coefficient using a recurrence relation binomial *= float(shDegree + 1 - i) / float(i + 1); } // Find roots of the polynomial within the relevant bounds float roots[MAX_DEGREE + 1]; - find_roots(roots, poly, -u_max, u_max); + find_roots(roots, poly, -uMax, uMax); // Convert them back to the original coordinate frame (i.e. ray parameters) _unroll_ for (int i = 0; i != maxPolyDegree; ++i) outRayParams[i] = (roots[i] != noIntersection) - ? (roots[i] * closest_dot_origin - dotDirOri) + ? (roots[i] * dotCloOri - dotDirOri) : noIntersection; } From 283446da45aa698bf718586bdf43868169408a44 Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Thu, 6 Jun 2024 09:43:41 -0400 Subject: [PATCH 083/118] Added new eval_sh.frag. --- .../SH-ODF_experimental/ray_traced_6.5.py | 5 +++-- fury/shaders/ray_traced/odf/eval_sh.frag | 16 ++++++++++++++++ .../ray_traced/odf/ray_glyph_intersections.frag | 2 +- 3 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 fury/shaders/ray_traced/odf/eval_sh.frag diff --git a/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py b/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py index 7b15a9983..401d7d898 100644 --- a/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py +++ b/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py @@ -248,7 +248,9 @@ def uv_calculations(n): # SH_DEGREE in this order. # param point The point on the unit sphere where the basis should be # evaluated. - eval_sh = import_fury_shader(os.path.join("rt_odfs", "eval_sh.frag")) + eval_sh = import_fury_shader( + os.path.join("ray_traced", "odf", "eval_sh.frag") + ) # Evaluates the gradient of each basis function given by eval_sh() and the # basis itself @@ -272,7 +274,6 @@ def uv_calculations(n): # glyph. Their exact meaning is defined by eval_sh(). # param ray_origin The origin of the ray, relative to the glyph center. # param ray_dir The normalized direction vector of the ray. - # TODO: Pass numCoeffs ray_sh_glyph_intersections = import_fury_shader( os.path.join("ray_traced", "odf", "ray_glyph_intersections.frag") ) diff --git a/fury/shaders/ray_traced/odf/eval_sh.frag b/fury/shaders/ray_traced/odf/eval_sh.frag new file mode 100644 index 000000000..4373dc5cd --- /dev/null +++ b/fury/shaders/ray_traced/odf/eval_sh.frag @@ -0,0 +1,16 @@ +void evalSH(out float outSHs[SH_COUNT], vec3 point, int shDegree) +{ + #if SH_DEGREE == 2 + eval_sh_2(outSHs, point); + #elif SH_DEGREE == 4 + eval_sh_4(outSHs, point); + #elif SH_DEGREE == 6 + eval_sh_6(outSHs, point); + #elif SH_DEGREE == 8 + eval_sh_8(outSHs, point); + #elif SH_DEGREE == 10 + eval_sh_10(outSHs, point); + #elif SH_DEGREE == 12 + eval_sh_12(outSHs, point); + #endif +} diff --git a/fury/shaders/ray_traced/odf/ray_glyph_intersections.frag b/fury/shaders/ray_traced/odf/ray_glyph_intersections.frag index 857ee3799..3005c0803 100644 --- a/fury/shaders/ray_traced/odf/ray_glyph_intersections.frag +++ b/fury/shaders/ray_traced/odf/ray_glyph_intersections.frag @@ -14,7 +14,7 @@ void rayGlyphIntersections(out float outRayParams[MAX_DEGREE], float shCoeffs[SH vec3 point = cos(float(i) * (pi / float(shDegree + 1))) * rayDir + sin(float(i) * (pi / float(shDegree + 1))) * closestDir; float shs[SH_COUNT]; - eval_sh(shs, point); + evalSH(shs, point, shDegree); shValues[i] = 0.0; _unroll_ for (int j = 0; j != numCoeffs; ++j) From 9321cf78785fc87752592bc2cafd873abf14ecea Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Fri, 7 Jun 2024 08:47:45 -0400 Subject: [PATCH 084/118] Added dynamic evalSH function. --- .../SH-ODF_experimental/ray_traced_6.5.py | 63 +++++++++++++++++++ fury/shaders/ray_traced/odf/eval_sh.frag | 51 +++++++++++---- .../odf/ray_glyph_intersections.frag | 2 +- 3 files changed, 104 insertions(+), 12 deletions(-) diff --git a/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py b/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py index 401d7d898..763b6fa55 100644 --- a/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py +++ b/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py @@ -248,9 +248,72 @@ def uv_calculations(n): # SH_DEGREE in this order. # param point The point on the unit sphere where the basis should be # evaluated. + """ eval_sh = import_fury_shader( os.path.join("ray_traced", "odf", "eval_sh.frag") ) + """ + + eval_sh = """ + void evalSH(out float outSHs[SH_COUNT], vec3 point, int shDegree, + int numCoeffs) + { + if (shDegree == 2) + { + float tmpOutSHs[6]; + #if SH_DEGREE == 2 + eval_sh_2(tmpOutSHs, point); + #endif + for (int i = 0; i != numCoeffs; ++i) + outSHs[i] = tmpOutSHs[i]; + } + else if (shDegree == 4) + { + float tmpOutSHs[15]; + #if SH_DEGREE == 4 + eval_sh_4(tmpOutSHs, point); + #endif + for (int i = 0; i != numCoeffs; ++i) + outSHs[i] = tmpOutSHs[i]; + } + else if (shDegree == 6) + { + float tmpOutSHs[28]; + #if SH_DEGREE == 6 + eval_sh_6(tmpOutSHs, point); + #endif + for (int i = 0; i != numCoeffs; ++i) + outSHs[i] = tmpOutSHs[i]; + } + else if (shDegree == 8) + { + float tmpOutSHs[45]; + #if SH_DEGREE == 8 + eval_sh_8(tmpOutSHs, point); + #endif + for (int i = 0; i != numCoeffs; ++i) + outSHs[i] = tmpOutSHs[i]; + } + else if (shDegree == 10) + { + float tmpOutSHs[66]; + #if SH_DEGREE == 10 + eval_sh_10(tmpOutSHs, point); + #endif + for (int i = 0; i != numCoeffs; ++i) + outSHs[i] = tmpOutSHs[i]; + } + else if (shDegree == 12) + { + float tmpOutSHs[91]; + #if SH_DEGREE == 12 + eval_sh_12(tmpOutSHs, point); + #endif + for (int i = 0; i != numCoeffs; ++i) + outSHs[i] = tmpOutSHs[i]; + } + } + """ # Evaluates the gradient of each basis function given by eval_sh() and the # basis itself diff --git a/fury/shaders/ray_traced/odf/eval_sh.frag b/fury/shaders/ray_traced/odf/eval_sh.frag index 4373dc5cd..f6e4dc8af 100644 --- a/fury/shaders/ray_traced/odf/eval_sh.frag +++ b/fury/shaders/ray_traced/odf/eval_sh.frag @@ -1,16 +1,45 @@ -void evalSH(out float outSHs[SH_COUNT], vec3 point, int shDegree) +void evalSH(out float outSHs[SH_COUNT], vec3 point, int shDegree, int numCoeffs) { - #if SH_DEGREE == 2 - eval_sh_2(outSHs, point); - #elif SH_DEGREE == 4 - eval_sh_4(outSHs, point); - #elif SH_DEGREE == 6 - eval_sh_6(outSHs, point); - #elif SH_DEGREE == 8 + if (shDegree == 2) + { + float tmpOutSHs[6]; + eval_sh_2(tmpOutSHs, point); + for (int i = 0; i != numCoeffs; ++i) + outSHs[i] = tmpOutSHs[i]; + } + else if (shDegree == 4) + { + float tmpOutSHs[15]; + eval_sh_4(tmpOutSHs, point); + for (int i = 0; i != numCoeffs; ++i) + outSHs[i] = tmpOutSHs[i]; + } + else if (shDegree == 6) + { + float tmpOutSHs[28]; + eval_sh_6(tmpOutSHs, point); + for (int i = 0; i != numCoeffs; ++i) + outSHs[i] = tmpOutSHs[i]; + } + else if (shDegree == 8) + { + float outSHs[45]; eval_sh_8(outSHs, point); - #elif SH_DEGREE == 10 + for (int i = 0; i != numCoeffs; ++i) + outSHs[i] = tmpOutSHs[i]; + } + else if (shDegree == 10) + { + float outSHs[66]; eval_sh_10(outSHs, point); - #elif SH_DEGREE == 12 + for (int i = 0; i != numCoeffs; ++i) + outSHs[i] = tmpOutSHs[i]; + } + else if (shDegree == 12) + { + float outSHs[91]; eval_sh_12(outSHs, point); - #endif + for (int i = 0; i != numCoeffs; ++i) + outSHs[i] = tmpOutSHs[i]; + } } diff --git a/fury/shaders/ray_traced/odf/ray_glyph_intersections.frag b/fury/shaders/ray_traced/odf/ray_glyph_intersections.frag index 3005c0803..3c01f166a 100644 --- a/fury/shaders/ray_traced/odf/ray_glyph_intersections.frag +++ b/fury/shaders/ray_traced/odf/ray_glyph_intersections.frag @@ -14,7 +14,7 @@ void rayGlyphIntersections(out float outRayParams[MAX_DEGREE], float shCoeffs[SH vec3 point = cos(float(i) * (pi / float(shDegree + 1))) * rayDir + sin(float(i) * (pi / float(shDegree + 1))) * closestDir; float shs[SH_COUNT]; - evalSH(shs, point, shDegree); + evalSH(shs, point, shDegree, numCoeffs); shValues[i] = 0.0; _unroll_ for (int j = 0; j != numCoeffs; ++j) From a5d1ff1992871dc9eec1a9de2bed239c47967324 Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Fri, 7 Jun 2024 09:32:21 -0400 Subject: [PATCH 085/118] Refactored eval_sh_x functions. --- .../SH-ODF_experimental/ray_traced_6.5.py | 47 +- .../ray_traced/odf/descoteaux/eval_sh_10.frag | 175 ++++++ .../ray_traced/odf/descoteaux/eval_sh_12.frag | 238 +++++++ .../ray_traced/odf/descoteaux/eval_sh_2.frag | 23 + .../ray_traced/odf/descoteaux/eval_sh_4.frag | 46 ++ .../ray_traced/odf/descoteaux/eval_sh_6.frag | 79 +++ .../ray_traced/odf/descoteaux/eval_sh_8.frag | 122 ++++ .../odf/descoteaux/eval_sh_grad_10.frag | 430 +++++++++++++ .../odf/descoteaux/eval_sh_grad_12.frag | 591 ++++++++++++++++++ .../odf/descoteaux/eval_sh_grad_2.frag | 46 ++ .../odf/descoteaux/eval_sh_grad_4.frag | 103 +++ .../odf/descoteaux/eval_sh_grad_6.frag | 186 ++++++ .../odf/descoteaux/eval_sh_grad_8.frag | 295 +++++++++ fury/shaders/ray_traced/odf/eval_sh.frag | 38 +- .../ray_traced/odf/tournier/eval_sh_10.frag | 175 ++++++ .../ray_traced/odf/tournier/eval_sh_12.frag | 238 +++++++ .../ray_traced/odf/tournier/eval_sh_2.frag | 21 + .../ray_traced/odf/tournier/eval_sh_4.frag | 46 ++ .../ray_traced/odf/tournier/eval_sh_6.frag | 79 +++ .../ray_traced/odf/tournier/eval_sh_8.frag | 122 ++++ .../odf/tournier/eval_sh_grad_10.frag | 430 +++++++++++++ .../odf/tournier/eval_sh_grad_12.frag | 591 ++++++++++++++++++ .../odf/tournier/eval_sh_grad_2.frag | 46 ++ .../odf/tournier/eval_sh_grad_4.frag | 103 +++ .../odf/tournier/eval_sh_grad_6.frag | 186 ++++++ .../odf/tournier/eval_sh_grad_8.frag | 295 +++++++++ 26 files changed, 4711 insertions(+), 40 deletions(-) create mode 100644 fury/shaders/ray_traced/odf/descoteaux/eval_sh_10.frag create mode 100644 fury/shaders/ray_traced/odf/descoteaux/eval_sh_12.frag create mode 100644 fury/shaders/ray_traced/odf/descoteaux/eval_sh_2.frag create mode 100644 fury/shaders/ray_traced/odf/descoteaux/eval_sh_4.frag create mode 100644 fury/shaders/ray_traced/odf/descoteaux/eval_sh_6.frag create mode 100644 fury/shaders/ray_traced/odf/descoteaux/eval_sh_8.frag create mode 100644 fury/shaders/ray_traced/odf/descoteaux/eval_sh_grad_10.frag create mode 100644 fury/shaders/ray_traced/odf/descoteaux/eval_sh_grad_12.frag create mode 100644 fury/shaders/ray_traced/odf/descoteaux/eval_sh_grad_2.frag create mode 100644 fury/shaders/ray_traced/odf/descoteaux/eval_sh_grad_4.frag create mode 100644 fury/shaders/ray_traced/odf/descoteaux/eval_sh_grad_6.frag create mode 100644 fury/shaders/ray_traced/odf/descoteaux/eval_sh_grad_8.frag create mode 100644 fury/shaders/ray_traced/odf/tournier/eval_sh_10.frag create mode 100644 fury/shaders/ray_traced/odf/tournier/eval_sh_12.frag create mode 100644 fury/shaders/ray_traced/odf/tournier/eval_sh_2.frag create mode 100644 fury/shaders/ray_traced/odf/tournier/eval_sh_4.frag create mode 100644 fury/shaders/ray_traced/odf/tournier/eval_sh_6.frag create mode 100644 fury/shaders/ray_traced/odf/tournier/eval_sh_8.frag create mode 100644 fury/shaders/ray_traced/odf/tournier/eval_sh_grad_10.frag create mode 100644 fury/shaders/ray_traced/odf/tournier/eval_sh_grad_12.frag create mode 100644 fury/shaders/ray_traced/odf/tournier/eval_sh_grad_2.frag create mode 100644 fury/shaders/ray_traced/odf/tournier/eval_sh_grad_4.frag create mode 100644 fury/shaders/ray_traced/odf/tournier/eval_sh_grad_6.frag create mode 100644 fury/shaders/ray_traced/odf/tournier/eval_sh_grad_8.frag diff --git a/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py b/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py index 763b6fa55..83d6f23e0 100644 --- a/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py +++ b/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py @@ -203,11 +203,16 @@ def uv_calculations(n): eval_sh_composed = "" for i in range(2, max_sh_degree + 1, 2): eval_sh = import_fury_shader( - os.path.join("rt_odfs", sh_basis, "eval_sh_" + str(i) + ".frag") + os.path.join( + "ray_traced", "odf", sh_basis, "eval_sh_" + str(i) + ".frag" + ) ) eval_sh_grad = import_fury_shader( os.path.join( - "rt_odfs", sh_basis, "eval_sh_grad_" + str(i) + ".frag" + "ray_traced", + "odf", + sh_basis, + "eval_sh_grad_" + str(i) + ".frag", ) ) eval_sh_composed = compose_shader( @@ -255,62 +260,62 @@ def uv_calculations(n): """ eval_sh = """ - void evalSH(out float outSHs[SH_COUNT], vec3 point, int shDegree, + void evalSH(out float outSH[SH_COUNT], vec3 point, int shDegree, int numCoeffs) { if (shDegree == 2) { - float tmpOutSHs[6]; + float tmpOutSH[6]; #if SH_DEGREE == 2 - eval_sh_2(tmpOutSHs, point); + evalSH2(tmpOutSH, point); #endif for (int i = 0; i != numCoeffs; ++i) - outSHs[i] = tmpOutSHs[i]; + outSH[i] = tmpOutSH[i]; } else if (shDegree == 4) { - float tmpOutSHs[15]; + float tmpOutSH[15]; #if SH_DEGREE == 4 - eval_sh_4(tmpOutSHs, point); + evalSH4(tmpOutSH, point); #endif for (int i = 0; i != numCoeffs; ++i) - outSHs[i] = tmpOutSHs[i]; + outSH[i] = tmpOutSH[i]; } else if (shDegree == 6) { - float tmpOutSHs[28]; + float tmpOutSH[28]; #if SH_DEGREE == 6 - eval_sh_6(tmpOutSHs, point); + evalSH6(tmpOutSH, point); #endif for (int i = 0; i != numCoeffs; ++i) - outSHs[i] = tmpOutSHs[i]; + outSH[i] = tmpOutSH[i]; } else if (shDegree == 8) { - float tmpOutSHs[45]; + float tmpOutSH[45]; #if SH_DEGREE == 8 - eval_sh_8(tmpOutSHs, point); + evalSH8(tmpOutSH, point); #endif for (int i = 0; i != numCoeffs; ++i) - outSHs[i] = tmpOutSHs[i]; + outSH[i] = tmpOutSH[i]; } else if (shDegree == 10) { - float tmpOutSHs[66]; + float tmpOutSH[66]; #if SH_DEGREE == 10 - eval_sh_10(tmpOutSHs, point); + evalSH10(tmpOutSH, point); #endif for (int i = 0; i != numCoeffs; ++i) - outSHs[i] = tmpOutSHs[i]; + outSH[i] = tmpOutSH[i]; } else if (shDegree == 12) { - float tmpOutSHs[91]; + float tmpOutSH[91]; #if SH_DEGREE == 12 - eval_sh_12(tmpOutSHs, point); + evalSH12(tmpOutSH, point); #endif for (int i = 0; i != numCoeffs; ++i) - outSHs[i] = tmpOutSHs[i]; + outSH[i] = tmpOutSH[i]; } } """ diff --git a/fury/shaders/ray_traced/odf/descoteaux/eval_sh_10.frag b/fury/shaders/ray_traced/odf/descoteaux/eval_sh_10.frag new file mode 100644 index 000000000..f12ad5881 --- /dev/null +++ b/fury/shaders/ray_traced/odf/descoteaux/eval_sh_10.frag @@ -0,0 +1,175 @@ +void evalSH10(out float outSH[66], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + outSH[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + outSH[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + outSH[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + outSH[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + outSH[36] = d; + b = z2 * a - 0.250980392 * b; + a = b - 0.250773994 * a; + d = 233.240148813 * a; + outSH[55] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + outSH[2] = -c1 * d; + outSH[4] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + outSH[9] = -c1 * d; + outSH[11] = s1 * d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + outSH[20] = -c1 * d; + outSH[22] = s1 * d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + outSH[35] = -c1 * d; + outSH[37] = s1 * d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + outSH[54] = -c1 * d; + outSH[56] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + outSH[1] = c0 * d; + outSH[5] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + outSH[8] = c0 * d; + outSH[12] = s0 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + outSH[19] = c0 * d; + outSH[23] = s0 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + outSH[34] = c0 * d; + outSH[38] = s0 * d; + b = z2 * a - 0.235294118 * b; + a = b - 0.238390093 * a; + d = 272.365814381 * a; + outSH[53] = c0 * d; + outSH[57] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + outSH[7] = -c1 * d; + outSH[13] = s1 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + outSH[18] = -c1 * d; + outSH[24] = s1 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + outSH[33] = -c1 * d; + outSH[39] = s1 * d; + a = z2 * b - 0.215686275 * a; + b = a - 0.222910217 * b; + d = -213.661323441 * b; + outSH[52] = -c1 * d; + outSH[58] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + outSH[6] = c0 * d; + outSH[14] = s0 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + outSH[17] = c0 * d; + outSH[25] = s0 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + outSH[32] = c0 * d; + outSH[40] = s0 * d; + b = z2 * a - 0.188235294 * b; + a = b - 0.20123839 * a; + d = 151.081370682 * a; + outSH[51] = c0 * d; + outSH[59] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + outSH[16] = -c1 * d; + outSH[26] = s1 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + outSH[31] = -c1 * d; + outSH[41] = s1 * d; + a = z2 * b - 0.152941176 * a; + b = a - 0.173374613 * b; + d = -95.552248675 * b; + outSH[50] = -c1 * d; + outSH[60] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + outSH[15] = c0 * d; + outSH[27] = s0 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + outSH[30] = c0 * d; + outSH[42] = s0 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + outSH[49] = c0 * d; + outSH[61] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + outSH[29] = -c1 * d; + outSH[43] = s1 * d; + a = (z2 - 5.88235294e-02) * z; + b = a - 9.90712074e-02 * z; + d = -25.910241313 * b; + outSH[48] = -c1 * d; + outSH[62] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + outSH[28] = c0 * d; + outSH[44] = s0 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + outSH[47] = c0 * d; + outSH[63] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + outSH[46] = -c1 * d; + outSH[64] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + outSH[45] = c0 * d; + outSH[65] = s0 * d; +} diff --git a/fury/shaders/ray_traced/odf/descoteaux/eval_sh_12.frag b/fury/shaders/ray_traced/odf/descoteaux/eval_sh_12.frag new file mode 100644 index 000000000..93a0da982 --- /dev/null +++ b/fury/shaders/ray_traced/odf/descoteaux/eval_sh_12.frag @@ -0,0 +1,238 @@ +void evalSH12(out float outSH[91], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + outSH[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + outSH[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + outSH[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + outSH[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + outSH[36] = d; + b = z2 * a - 0.250980392 * b; + a = b - 0.250773994 * a; + d = 233.240148813 * a; + outSH[55] = d; + b = z2 * a - 0.250626566 * b; + a = b - 0.250517598 * a; + d = 931.186918633 * a; + outSH[78] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + outSH[2] = -c1 * d; + outSH[4] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + outSH[9] = -c1 * d; + outSH[11] = s1 * d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + outSH[20] = -c1 * d; + outSH[22] = s1 * d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + outSH[35] = -c1 * d; + outSH[37] = s1 * d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + outSH[54] = -c1 * d; + outSH[56] = s1 * d; + a = z2 * b - 0.248120301 * a; + b = a - 0.248447205 * b; + d = -1265.233874957 * b; + outSH[77] = -c1 * d; + outSH[79] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + outSH[1] = c0 * d; + outSH[5] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + outSH[8] = c0 * d; + outSH[12] = s0 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + outSH[19] = c0 * d; + outSH[23] = s0 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + outSH[34] = c0 * d; + outSH[38] = s0 * d; + b = z2 * a - 0.235294118 * b; + a = b - 0.238390093 * a; + d = 272.365814381 * a; + outSH[53] = c0 * d; + outSH[57] = s0 * d; + b = z2 * a - 0.240601504 * b; + a = b - 0.242236025 * a; + d = 1121.509962433 * a; + outSH[76] = c0 * d; + outSH[80] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + outSH[7] = -c1 * d; + outSH[13] = s1 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + outSH[18] = -c1 * d; + outSH[24] = s1 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + outSH[33] = -c1 * d; + outSH[39] = s1 * d; + a = z2 * b - 0.215686275 * a; + b = a - 0.222910217 * b; + d = -213.661323441 * b; + outSH[52] = -c1 * d; + outSH[58] = s1 * d; + a = z2 * b - 0.228070175 * a; + b = a - 0.231884058 * b; + d = -915.709049803 * b; + outSH[75] = -c1 * d; + outSH[81] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + outSH[6] = c0 * d; + outSH[14] = s0 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + outSH[17] = c0 * d; + outSH[25] = s0 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + outSH[32] = c0 * d; + outSH[40] = s0 * d; + b = z2 * a - 0.188235294 * b; + a = b - 0.20123839 * a; + d = 151.081370682 * a; + outSH[51] = c0 * d; + outSH[59] = s0 * d; + b = z2 * a - 0.210526316 * b; + a = b - 0.217391304 * a; + d = 686.781787352 * a; + outSH[74] = c0 * d; + outSH[82] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + outSH[16] = -c1 * d; + outSH[26] = s1 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + outSH[31] = -c1 * d; + outSH[41] = s1 * d; + a = z2 * b - 0.152941176 * a; + b = a - 0.173374613 * b; + d = -95.552248675 * b; + outSH[50] = -c1 * d; + outSH[60] = s1 * d; + a = z2 * b - 0.187969925 * a; + b = a - 0.198757764 * b; + d = -471.12841933 * b; + outSH[73] = -c1 * d; + outSH[83] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + outSH[15] = c0 * d; + outSH[27] = s0 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + outSH[30] = c0 * d; + outSH[42] = s0 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + outSH[49] = c0 * d; + outSH[61] = s0 * d; + b = z2 * a - 0.160401003 * b; + a = b - 0.175983437 * a; + d = 293.800188384 * a; + outSH[72] = c0 * d; + outSH[84] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + outSH[29] = -c1 * d; + outSH[43] = s1 * d; + a = (z2 - 5.88235294e-02) * z; + b = a - 9.90712074e-02 * z; + d = -25.910241313 * b; + outSH[48] = -c1 * d; + outSH[62] = s1 * d; + a = z2 * b - 0.127819549 * a; + b = a - 0.149068323 * b; + d = -165.101452729 * b; + outSH[71] = -c1 * d; + outSH[85] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + outSH[28] = c0 * d; + outSH[44] = s0 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + outSH[47] = c0 * d; + outSH[63] = s0 * d; + b = z2 * (a - 9.02255639e-02); + a = b - 0.118012422 * a; + d = 82.550726364 * a; + outSH[70] = c0 * d; + outSH[86] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + outSH[46] = -c1 * d; + outSH[64] = s1 * d; + a = (z2 - 4.76190476e-02) * z; + b = a - 8.2815735e-02 * z; + d = -36.028090689 * b; + outSH[69] = -c1 * d; + outSH[87] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + outSH[45] = c0 * d; + outSH[65] = s0 * d; + a = z2 - 4.34782609e-02; + d = 13.3042542 * a; + outSH[68] = c0 * d; + outSH[88] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.923210529 * z; + outSH[67] = -c1 * d; + outSH[89] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.800821996; + outSH[66] = c0 * d; + outSH[90] = s0 * d; +} diff --git a/fury/shaders/ray_traced/odf/descoteaux/eval_sh_2.frag b/fury/shaders/ray_traced/odf/descoteaux/eval_sh_2.frag new file mode 100644 index 000000000..77c9b62bb --- /dev/null +++ b/fury/shaders/ray_traced/odf/descoteaux/eval_sh_2.frag @@ -0,0 +1,23 @@ +void evalSH2(out float outSH[6], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + outSH[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + outSH[3] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + outSH[2] = -c1 * d; + outSH[4] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + outSH[1] = c0 * d; + outSH[5] = s0 * d; +} diff --git a/fury/shaders/ray_traced/odf/descoteaux/eval_sh_4.frag b/fury/shaders/ray_traced/odf/descoteaux/eval_sh_4.frag new file mode 100644 index 000000000..2c1b927c3 --- /dev/null +++ b/fury/shaders/ray_traced/odf/descoteaux/eval_sh_4.frag @@ -0,0 +1,46 @@ +void evalSH4(out float outSH[15], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + outSH[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + outSH[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + outSH[10] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + outSH[2] = -c1 * d; + outSH[4] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + outSH[9] = -c1 * d; + outSH[11] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + outSH[1] = c0 * d; + outSH[5] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + outSH[8] = c0 * d; + outSH[12] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + outSH[7] = -c1 * d; + outSH[13] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + outSH[6] = c0 * d; + outSH[14] = s0 * d; +} diff --git a/fury/shaders/ray_traced/odf/descoteaux/eval_sh_6.frag b/fury/shaders/ray_traced/odf/descoteaux/eval_sh_6.frag new file mode 100644 index 000000000..e080626a2 --- /dev/null +++ b/fury/shaders/ray_traced/odf/descoteaux/eval_sh_6.frag @@ -0,0 +1,79 @@ +void evalSH6(out float outSH[28], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + outSH[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + outSH[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + outSH[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + outSH[21] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + outSH[2] = -c1 * d; + outSH[4] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + outSH[9] = -c1 * d; + outSH[11] = s1 * d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + outSH[20] = -c1 * d; + outSH[22] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + outSH[1] = c0 * d; + outSH[5] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + outSH[8] = c0 * d; + outSH[12] = s0 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + outSH[19] = c0 * d; + outSH[23] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + outSH[7] = -c1 * d; + outSH[13] = s1 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + outSH[18] = -c1 * d; + outSH[24] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + outSH[6] = c0 * d; + outSH[14] = s0 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + outSH[17] = c0 * d; + outSH[25] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + outSH[16] = -c1 * d; + outSH[26] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + outSH[15] = c0 * d; + outSH[27] = s0 * d; +} diff --git a/fury/shaders/ray_traced/odf/descoteaux/eval_sh_8.frag b/fury/shaders/ray_traced/odf/descoteaux/eval_sh_8.frag new file mode 100644 index 000000000..a88190d35 --- /dev/null +++ b/fury/shaders/ray_traced/odf/descoteaux/eval_sh_8.frag @@ -0,0 +1,122 @@ +void evalSH8(out float outSH[45], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + outSH[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + outSH[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + outSH[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + outSH[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + outSH[36] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + outSH[2] = -c1 * d; + outSH[4] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + outSH[9] = -c1 * d; + outSH[11] = s1 * d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + outSH[20] = -c1 * d; + outSH[22] = s1 * d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + outSH[35] = -c1 * d; + outSH[37] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + outSH[1] = c0 * d; + outSH[5] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + outSH[8] = c0 * d; + outSH[12] = s0 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + outSH[19] = c0 * d; + outSH[23] = s0 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + outSH[34] = c0 * d; + outSH[38] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + outSH[7] = -c1 * d; + outSH[13] = s1 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + outSH[18] = -c1 * d; + outSH[24] = s1 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + outSH[33] = -c1 * d; + outSH[39] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + outSH[6] = c0 * d; + outSH[14] = s0 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + outSH[17] = c0 * d; + outSH[25] = s0 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + outSH[32] = c0 * d; + outSH[40] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + outSH[16] = -c1 * d; + outSH[26] = s1 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + outSH[31] = -c1 * d; + outSH[41] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + outSH[15] = c0 * d; + outSH[27] = s0 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + outSH[30] = c0 * d; + outSH[42] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + outSH[29] = -c1 * d; + outSH[43] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + outSH[28] = c0 * d; + outSH[44] = s0 * d; +} diff --git a/fury/shaders/ray_traced/odf/descoteaux/eval_sh_grad_10.frag b/fury/shaders/ray_traced/odf/descoteaux/eval_sh_grad_10.frag new file mode 100644 index 000000000..9d5feea39 --- /dev/null +++ b/fury/shaders/ray_traced/odf/descoteaux/eval_sh_grad_10.frag @@ -0,0 +1,430 @@ +void eval_sh_grad_10(out float out_shs[66], out vec3 out_grads[66], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + b = z2 * a - 0.250980392 * b; + a = b - 0.250773994 * a; + d = 233.240148813 * a; + out_shs[55] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + out_grads[2][0] = -c0 * d; + out_grads[4][0] = s0 * d; + out_grads[2][1] = s0 * d; + out_grads[4][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + out_grads[9][0] = -c0 * d; + out_grads[11][0] = s0 * d; + out_grads[9][1] = s0 * d; + out_grads[11][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[20] = -c1 * d; + out_shs[22] = s1 * d; + out_grads[20][0] = -c0 * d; + out_grads[22][0] = s0 * d; + out_grads[20][1] = s0 * d; + out_grads[22][1] = c0 * d; + d = 88.106914343 * b; + out_grads[21][2] = d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[35] = -c1 * d; + out_shs[37] = s1 * d; + out_grads[35][0] = -c0 * d; + out_grads[37][0] = s0 * d; + out_grads[35][1] = s0 * d; + out_grads[37][1] = c0 * d; + d = 467.786944906 * b; + out_grads[36][2] = d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + out_shs[54] = -c1 * d; + out_shs[56] = s1 * d; + out_grads[54][0] = -c0 * d; + out_grads[56][0] = s0 * d; + out_grads[54][1] = s0 * d; + out_grads[56][1] = c0 * d; + d = 2332.401488133 * b; + out_grads[55][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + d = 1.092548431; + out_grads[1][0] = c1 * d; + out_grads[5][0] = s1 * d; + out_grads[1][1] = -s1 * d; + out_grads[5][1] = c1 * d; + d = -1.092548431; + out_grads[2][2] = -c1 * d; + out_grads[4][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + d = 6.62322287 * a; + out_grads[8][0] = c1 * d; + out_grads[12][0] = s1 * d; + out_grads[8][1] = -s1 * d; + out_grads[12][1] = c1 * d; + d = -14.049977415 * a; + out_grads[9][2] = -c1 * d; + out_grads[11][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[19] = c0 * d; + out_shs[23] = s0 * d; + d = 30.399773564 * a; + out_grads[19][0] = c1 * d; + out_grads[23][0] = s1 * d; + out_grads[19][1] = -s1 * d; + out_grads[23][1] = c1 * d; + d = -96.132524816 * a; + out_grads[20][2] = -c1 * d; + out_grads[22][2] = s1 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[34] = c0 * d; + out_shs[38] = s0 * d; + d = 130.459545912 * a; + out_grads[34][0] = c1 * d; + out_grads[38][0] = s1 * d; + out_grads[34][1] = -s1 * d; + out_grads[38][1] = c1 * d; + d = -545.751435723 * a; + out_grads[35][2] = -c1 * d; + out_grads[37][2] = s1 * d; + b = z2 * a - 0.235294118 * b; + a = b - 0.238390093 * a; + d = 272.365814381 * a; + out_shs[53] = c0 * d; + out_shs[57] = s0 * d; + d = 544.731628762 * a; + out_grads[53][0] = c1 * d; + out_grads[57][0] = s1 * d; + out_grads[53][1] = -s1 * d; + out_grads[57][1] = c1 * d; + d = -2830.508572514 * a; + out_grads[54][2] = -c1 * d; + out_grads[56][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + d = -5.310392309 * z; + out_grads[7][0] = -c0 * d; + out_grads[13][0] = s0 * d; + out_grads[7][1] = s0 * d; + out_grads[13][1] = c0 * d; + d = 6.62322287 * z; + out_grads[8][2] = c0 * d; + out_grads[12][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[18] = -c1 * d; + out_shs[24] = s1 * d; + d = -30.399773564 * b; + out_grads[18][0] = -c0 * d; + out_grads[24][0] = s0 * d; + out_grads[18][1] = s0 * d; + out_grads[24][1] = c0 * d; + d = 60.799547128 * b; + out_grads[19][2] = c0 * d; + out_grads[23][2] = s0 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[33] = -c1 * d; + out_shs[39] = s1 * d; + d = -144.52614017 * b; + out_grads[33][0] = -c0 * d; + out_grads[39][0] = s0 * d; + out_grads[33][1] = s0 * d; + out_grads[39][1] = c0 * d; + d = 391.378637737 * b; + out_grads[34][2] = c0 * d; + out_grads[38][2] = s0 * d; + a = z2 * b - 0.215686275 * a; + b = a - 0.222910217 * b; + d = -213.661323441 * b; + out_shs[52] = -c1 * d; + out_shs[58] = s1 * d; + d = -640.983970322 * b; + out_grads[52][0] = -c0 * d; + out_grads[58][0] = s0 * d; + out_grads[52][1] = s0 * d; + out_grads[58][1] = c0 * d; + d = 2178.926515046 * b; + out_grads[53][2] = c0 * d; + out_grads[57][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + d = 2.503342942; + out_grads[6][0] = c1 * d; + out_grads[14][0] = s1 * d; + out_grads[6][1] = -s1 * d; + out_grads[14][1] = c1 * d; + d = -1.77013077; + out_grads[7][2] = -c1 * d; + out_grads[13][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[17] = c0 * d; + out_shs[25] = s0 * d; + d = 22.200855632 * a; + out_grads[17][0] = c1 * d; + out_grads[25][0] = s1 * d; + out_grads[17][1] = -s1 * d; + out_grads[25][1] = c1 * d; + d = -30.399773564 * a; + out_grads[18][2] = -c1 * d; + out_grads[24][2] = s1 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[32] = c0 * d; + out_shs[40] = s0 * d; + d = 124.388296437 * a; + out_grads[32][0] = c1 * d; + out_grads[40][0] = s1 * d; + out_grads[32][1] = -s1 * d; + out_grads[40][1] = c1 * d; + d = -240.876900283 * a; + out_grads[33][2] = -c1 * d; + out_grads[39][2] = s1 * d; + b = z2 * a - 0.188235294 * b; + a = b - 0.20123839 * a; + d = 151.081370682 * a; + out_shs[51] = c0 * d; + out_shs[59] = s0 * d; + d = 604.325482728 * a; + out_grads[51][0] = c1 * d; + out_grads[59][0] = s1 * d; + out_grads[51][1] = -s1 * d; + out_grads[59][1] = c1 * d; + d = -1495.629264084 * a; + out_grads[52][2] = -c1 * d; + out_grads[58][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[16] = -c1 * d; + out_shs[26] = s1 * d; + d = -11.833095811 * z; + out_grads[16][0] = -c0 * d; + out_grads[26][0] = s0 * d; + out_grads[16][1] = s0 * d; + out_grads[26][1] = c0 * d; + d = 11.100427816 * z; + out_grads[17][2] = c0 * d; + out_grads[25][2] = s0 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[31] = -c1 * d; + out_shs[41] = s1 * d; + d = -86.247765552 * b; + out_grads[31][0] = -c0 * d; + out_grads[41][0] = s0 * d; + out_grads[31][1] = s0 * d; + out_grads[41][1] = c0 * d; + d = 124.388296437 * b; + out_grads[32][2] = c0 * d; + out_grads[40][2] = s0 * d; + a = z2 * b - 0.152941176 * a; + b = a - 0.173374613 * b; + d = -95.552248675 * b; + out_shs[50] = -c1 * d; + out_shs[60] = s1 * d; + d = -477.761243376 * b; + out_grads[50][0] = -c0 * d; + out_grads[60][0] = s0 * d; + out_grads[50][1] = s0 * d; + out_grads[60][1] = c0 * d; + d = 906.488224092 * b; + out_grads[51][2] = c0 * d; + out_grads[59][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[15] = c0 * d; + out_shs[27] = s0 * d; + d = 4.099104631; + out_grads[15][0] = c1 * d; + out_grads[27][0] = s1 * d; + out_grads[15][1] = -s1 * d; + out_grads[27][1] = c1 * d; + d = -2.366619162; + out_grads[16][2] = -c1 * d; + out_grads[26][2] = s1 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[30] = c0 * d; + out_shs[42] = s0 * d; + d = 47.909948945 * a; + out_grads[30][0] = c1 * d; + out_grads[42][0] = s1 * d; + out_grads[30][1] = -s1 * d; + out_grads[42][1] = c1 * d; + d = -51.748659331 * a; + out_grads[31][2] = -c1 * d; + out_grads[41][2] = s1 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + out_shs[49] = c0 * d; + out_shs[61] = s0 * d; + d = 320.491985161 * a; + out_grads[49][0] = c1 * d; + out_grads[61][0] = s1 * d; + out_grads[49][1] = -s1 * d; + out_grads[61][1] = c1 * d; + d = -477.761243376 * a; + out_grads[50][2] = -c1 * d; + out_grads[60][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[29] = -c1 * d; + out_shs[43] = s1 * d; + d = -20.409946485 * z; + out_grads[29][0] = -c0 * d; + out_grads[43][0] = s0 * d; + out_grads[29][1] = s0 * d; + out_grads[43][1] = c0 * d; + d = 15.969982982 * z; + out_grads[30][2] = c0 * d; + out_grads[42][2] = s0 * d; + a = (z2 - 5.88235294e-02) * z; + b = a - 9.90712074e-02 * z; + d = -25.910241313 * b; + out_shs[48] = -c1 * d; + out_shs[62] = s1 * d; + d = -181.371689194 * b; + out_grads[48][0] = -c0 * d; + out_grads[62][0] = s0 * d; + out_grads[48][1] = s0 * d; + out_grads[62][1] = c0 * d; + d = 213.661323441 * b; + out_grads[49][2] = c0 * d; + out_grads[61][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[28] = c0 * d; + out_shs[44] = s0 * d; + d = 5.831413281; + out_grads[28][0] = c1 * d; + out_grads[44][0] = s1 * d; + out_grads[28][1] = -s1 * d; + out_grads[44][1] = c1 * d; + d = -2.915706641; + out_grads[29][2] = -c1 * d; + out_grads[43][2] = s1 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + out_shs[47] = c0 * d; + out_shs[63] = s0 * d; + d = 84.622493774 * a; + out_grads[47][0] = c1 * d; + out_grads[63][0] = s1 * d; + out_grads[47][1] = -s1 * d; + out_grads[63][1] = c1 * d; + d = -77.73072394 * a; + out_grads[48][2] = -c1 * d; + out_grads[62][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + out_shs[46] = -c1 * d; + out_shs[64] = s1 * d; + d = -30.887057699 * z; + out_grads[46][0] = -c0 * d; + out_grads[64][0] = s0 * d; + out_grads[46][1] = s0 * d; + out_grads[64][1] = c0 * d; + d = 21.155623443 * z; + out_grads[47][2] = c0 * d; + out_grads[63][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + out_shs[45] = c0 * d; + out_shs[65] = s0 * d; + d = 7.673951182; + out_grads[45][0] = c1 * d; + out_grads[65][0] = s1 * d; + out_grads[45][1] = -s1 * d; + out_grads[65][1] = c1 * d; + d = -3.4318953; + out_grads[46][2] = -c1 * d; + out_grads[64][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; + out_grads[6][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[14][2] = 0.0; + out_grads[15][2] = 0.0; + out_grads[21][0] = 0.0; + out_grads[21][1] = 0.0; + out_grads[27][2] = 0.0; + out_grads[28][2] = 0.0; + out_grads[36][0] = 0.0; + out_grads[36][1] = 0.0; + out_grads[44][2] = 0.0; + out_grads[45][2] = 0.0; + out_grads[55][0] = 0.0; + out_grads[55][1] = 0.0; + out_grads[65][2] = 0.0; +} diff --git a/fury/shaders/ray_traced/odf/descoteaux/eval_sh_grad_12.frag b/fury/shaders/ray_traced/odf/descoteaux/eval_sh_grad_12.frag new file mode 100644 index 000000000..f7ff069bc --- /dev/null +++ b/fury/shaders/ray_traced/odf/descoteaux/eval_sh_grad_12.frag @@ -0,0 +1,591 @@ +void eval_sh_grad_12(out float out_shs[91], out vec3 out_grads[91], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + b = z2 * a - 0.250980392 * b; + a = b - 0.250773994 * a; + d = 233.240148813 * a; + out_shs[55] = d; + b = z2 * a - 0.250626566 * b; + a = b - 0.250517598 * a; + d = 931.186918633 * a; + out_shs[78] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + out_grads[2][0] = -c0 * d; + out_grads[4][0] = s0 * d; + out_grads[2][1] = s0 * d; + out_grads[4][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + out_grads[9][0] = -c0 * d; + out_grads[11][0] = s0 * d; + out_grads[9][1] = s0 * d; + out_grads[11][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[20] = -c1 * d; + out_shs[22] = s1 * d; + out_grads[20][0] = -c0 * d; + out_grads[22][0] = s0 * d; + out_grads[20][1] = s0 * d; + out_grads[22][1] = c0 * d; + d = 88.106914343 * b; + out_grads[21][2] = d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[35] = -c1 * d; + out_shs[37] = s1 * d; + out_grads[35][0] = -c0 * d; + out_grads[37][0] = s0 * d; + out_grads[35][1] = s0 * d; + out_grads[37][1] = c0 * d; + d = 467.786944906 * b; + out_grads[36][2] = d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + out_shs[54] = -c1 * d; + out_shs[56] = s1 * d; + out_grads[54][0] = -c0 * d; + out_grads[56][0] = s0 * d; + out_grads[54][1] = s0 * d; + out_grads[56][1] = c0 * d; + d = 2332.401488133 * b; + out_grads[55][2] = d; + a = z2 * b - 0.248120301 * a; + b = a - 0.248447205 * b; + d = -1265.233874957 * b; + out_shs[77] = -c1 * d; + out_shs[79] = s1 * d; + out_grads[77][0] = -c0 * d; + out_grads[79][0] = s0 * d; + out_grads[77][1] = s0 * d; + out_grads[79][1] = c0 * d; + d = 11174.243023595 * b; + out_grads[78][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + d = 1.092548431; + out_grads[1][0] = c1 * d; + out_grads[5][0] = s1 * d; + out_grads[1][1] = -s1 * d; + out_grads[5][1] = c1 * d; + d = -1.092548431; + out_grads[2][2] = -c1 * d; + out_grads[4][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + d = 6.62322287 * a; + out_grads[8][0] = c1 * d; + out_grads[12][0] = s1 * d; + out_grads[8][1] = -s1 * d; + out_grads[12][1] = c1 * d; + d = -14.049977415 * a; + out_grads[9][2] = -c1 * d; + out_grads[11][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[19] = c0 * d; + out_shs[23] = s0 * d; + d = 30.399773564 * a; + out_grads[19][0] = c1 * d; + out_grads[23][0] = s1 * d; + out_grads[19][1] = -s1 * d; + out_grads[23][1] = c1 * d; + d = -96.132524816 * a; + out_grads[20][2] = -c1 * d; + out_grads[22][2] = s1 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[34] = c0 * d; + out_shs[38] = s0 * d; + d = 130.459545912 * a; + out_grads[34][0] = c1 * d; + out_grads[38][0] = s1 * d; + out_grads[34][1] = -s1 * d; + out_grads[38][1] = c1 * d; + d = -545.751435723 * a; + out_grads[35][2] = -c1 * d; + out_grads[37][2] = s1 * d; + b = z2 * a - 0.235294118 * b; + a = b - 0.238390093 * a; + d = 272.365814381 * a; + out_shs[53] = c0 * d; + out_shs[57] = s0 * d; + d = 544.731628762 * a; + out_grads[53][0] = c1 * d; + out_grads[57][0] = s1 * d; + out_grads[53][1] = -s1 * d; + out_grads[57][1] = c1 * d; + d = -2830.508572514 * a; + out_grads[54][2] = -c1 * d; + out_grads[56][2] = s1 * d; + b = z2 * a - 0.240601504 * b; + a = b - 0.242236025 * a; + d = 1121.509962433 * a; + out_shs[76] = c0 * d; + out_shs[80] = s0 * d; + d = 2243.019924866 * a; + out_grads[76][0] = c1 * d; + out_grads[80][0] = s1 * d; + out_grads[76][1] = -s1 * d; + out_grads[80][1] = c1 * d; + d = -13917.572624524 * a; + out_grads[77][2] = -c1 * d; + out_grads[79][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + d = -5.310392309 * z; + out_grads[7][0] = -c0 * d; + out_grads[13][0] = s0 * d; + out_grads[7][1] = s0 * d; + out_grads[13][1] = c0 * d; + d = 6.62322287 * z; + out_grads[8][2] = c0 * d; + out_grads[12][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[18] = -c1 * d; + out_shs[24] = s1 * d; + d = -30.399773564 * b; + out_grads[18][0] = -c0 * d; + out_grads[24][0] = s0 * d; + out_grads[18][1] = s0 * d; + out_grads[24][1] = c0 * d; + d = 60.799547128 * b; + out_grads[19][2] = c0 * d; + out_grads[23][2] = s0 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[33] = -c1 * d; + out_shs[39] = s1 * d; + d = -144.52614017 * b; + out_grads[33][0] = -c0 * d; + out_grads[39][0] = s0 * d; + out_grads[33][1] = s0 * d; + out_grads[39][1] = c0 * d; + d = 391.378637737 * b; + out_grads[34][2] = c0 * d; + out_grads[38][2] = s0 * d; + a = z2 * b - 0.215686275 * a; + b = a - 0.222910217 * b; + d = -213.661323441 * b; + out_shs[52] = -c1 * d; + out_shs[58] = s1 * d; + d = -640.983970322 * b; + out_grads[52][0] = -c0 * d; + out_grads[58][0] = s0 * d; + out_grads[52][1] = s0 * d; + out_grads[58][1] = c0 * d; + d = 2178.926515046 * b; + out_grads[53][2] = c0 * d; + out_grads[57][2] = s0 * d; + a = z2 * b - 0.228070175 * a; + b = a - 0.231884058 * b; + d = -915.709049803 * b; + out_shs[75] = -c1 * d; + out_shs[81] = s1 * d; + d = -2747.127149409 * b; + out_grads[75][0] = -c0 * d; + out_grads[81][0] = s0 * d; + out_grads[75][1] = s0 * d; + out_grads[81][1] = c0 * d; + d = 11215.099624332 * b; + out_grads[76][2] = c0 * d; + out_grads[80][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + d = 2.503342942; + out_grads[6][0] = c1 * d; + out_grads[14][0] = s1 * d; + out_grads[6][1] = -s1 * d; + out_grads[14][1] = c1 * d; + d = -1.77013077; + out_grads[7][2] = -c1 * d; + out_grads[13][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[17] = c0 * d; + out_shs[25] = s0 * d; + d = 22.200855632 * a; + out_grads[17][0] = c1 * d; + out_grads[25][0] = s1 * d; + out_grads[17][1] = -s1 * d; + out_grads[25][1] = c1 * d; + d = -30.399773564 * a; + out_grads[18][2] = -c1 * d; + out_grads[24][2] = s1 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[32] = c0 * d; + out_shs[40] = s0 * d; + d = 124.388296437 * a; + out_grads[32][0] = c1 * d; + out_grads[40][0] = s1 * d; + out_grads[32][1] = -s1 * d; + out_grads[40][1] = c1 * d; + d = -240.876900283 * a; + out_grads[33][2] = -c1 * d; + out_grads[39][2] = s1 * d; + b = z2 * a - 0.188235294 * b; + a = b - 0.20123839 * a; + d = 151.081370682 * a; + out_shs[51] = c0 * d; + out_shs[59] = s0 * d; + d = 604.325482728 * a; + out_grads[51][0] = c1 * d; + out_grads[59][0] = s1 * d; + out_grads[51][1] = -s1 * d; + out_grads[59][1] = c1 * d; + d = -1495.629264084 * a; + out_grads[52][2] = -c1 * d; + out_grads[58][2] = s1 * d; + b = z2 * a - 0.210526316 * b; + a = b - 0.217391304 * a; + d = 686.781787352 * a; + out_shs[74] = c0 * d; + out_shs[82] = s0 * d; + d = 2747.127149409 * a; + out_grads[74][0] = c1 * d; + out_grads[82][0] = s1 * d; + out_grads[74][1] = -s1 * d; + out_grads[82][1] = c1 * d; + d = -8241.381448228 * a; + out_grads[75][2] = -c1 * d; + out_grads[81][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[16] = -c1 * d; + out_shs[26] = s1 * d; + d = -11.833095811 * z; + out_grads[16][0] = -c0 * d; + out_grads[26][0] = s0 * d; + out_grads[16][1] = s0 * d; + out_grads[26][1] = c0 * d; + d = 11.100427816 * z; + out_grads[17][2] = c0 * d; + out_grads[25][2] = s0 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[31] = -c1 * d; + out_shs[41] = s1 * d; + d = -86.247765552 * b; + out_grads[31][0] = -c0 * d; + out_grads[41][0] = s0 * d; + out_grads[31][1] = s0 * d; + out_grads[41][1] = c0 * d; + d = 124.388296437 * b; + out_grads[32][2] = c0 * d; + out_grads[40][2] = s0 * d; + a = z2 * b - 0.152941176 * a; + b = a - 0.173374613 * b; + d = -95.552248675 * b; + out_shs[50] = -c1 * d; + out_shs[60] = s1 * d; + d = -477.761243376 * b; + out_grads[50][0] = -c0 * d; + out_grads[60][0] = s0 * d; + out_grads[50][1] = s0 * d; + out_grads[60][1] = c0 * d; + d = 906.488224092 * b; + out_grads[51][2] = c0 * d; + out_grads[59][2] = s0 * d; + a = z2 * b - 0.187969925 * a; + b = a - 0.198757764 * b; + d = -471.12841933 * b; + out_shs[73] = -c1 * d; + out_shs[83] = s1 * d; + d = -2355.642096651 * b; + out_grads[73][0] = -c0 * d; + out_grads[83][0] = s0 * d; + out_grads[73][1] = s0 * d; + out_grads[83][1] = c0 * d; + d = 5494.254298819 * b; + out_grads[74][2] = c0 * d; + out_grads[82][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[15] = c0 * d; + out_shs[27] = s0 * d; + d = 4.099104631; + out_grads[15][0] = c1 * d; + out_grads[27][0] = s1 * d; + out_grads[15][1] = -s1 * d; + out_grads[27][1] = c1 * d; + d = -2.366619162; + out_grads[16][2] = -c1 * d; + out_grads[26][2] = s1 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[30] = c0 * d; + out_shs[42] = s0 * d; + d = 47.909948945 * a; + out_grads[30][0] = c1 * d; + out_grads[42][0] = s1 * d; + out_grads[30][1] = -s1 * d; + out_grads[42][1] = c1 * d; + d = -51.748659331 * a; + out_grads[31][2] = -c1 * d; + out_grads[41][2] = s1 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + out_shs[49] = c0 * d; + out_shs[61] = s0 * d; + d = 320.491985161 * a; + out_grads[49][0] = c1 * d; + out_grads[61][0] = s1 * d; + out_grads[49][1] = -s1 * d; + out_grads[61][1] = c1 * d; + d = -477.761243376 * a; + out_grads[50][2] = -c1 * d; + out_grads[60][2] = s1 * d; + b = z2 * a - 0.160401003 * b; + a = b - 0.175983437 * a; + d = 293.800188384 * a; + out_shs[72] = c0 * d; + out_shs[84] = s0 * d; + d = 1762.801130306 * a; + out_grads[72][0] = c1 * d; + out_grads[84][0] = s1 * d; + out_grads[72][1] = -s1 * d; + out_grads[84][1] = c1 * d; + d = -3297.898935312 * a; + out_grads[73][2] = -c1 * d; + out_grads[83][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[29] = -c1 * d; + out_shs[43] = s1 * d; + d = -20.409946485 * z; + out_grads[29][0] = -c0 * d; + out_grads[43][0] = s0 * d; + out_grads[29][1] = s0 * d; + out_grads[43][1] = c0 * d; + d = 15.969982982 * z; + out_grads[30][2] = c0 * d; + out_grads[42][2] = s0 * d; + a = (z2 - 5.88235294e-02) * z; + b = a - 9.90712074e-02 * z; + d = -25.910241313 * b; + out_shs[48] = -c1 * d; + out_shs[62] = s1 * d; + d = -181.371689194 * b; + out_grads[48][0] = -c0 * d; + out_grads[62][0] = s0 * d; + out_grads[48][1] = s0 * d; + out_grads[62][1] = c0 * d; + d = 213.661323441 * b; + out_grads[49][2] = c0 * d; + out_grads[61][2] = s0 * d; + a = z2 * b - 0.127819549 * a; + b = a - 0.149068323 * b; + d = -165.101452729 * b; + out_shs[71] = -c1 * d; + out_shs[85] = s1 * d; + d = -1155.7101691 * b; + out_grads[71][0] = -c0 * d; + out_grads[85][0] = s0 * d; + out_grads[71][1] = s0 * d; + out_grads[85][1] = c0 * d; + d = 1762.801130306 * b; + out_grads[72][2] = c0 * d; + out_grads[84][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[28] = c0 * d; + out_shs[44] = s0 * d; + d = 5.831413281; + out_grads[28][0] = c1 * d; + out_grads[44][0] = s1 * d; + out_grads[28][1] = -s1 * d; + out_grads[44][1] = c1 * d; + d = -2.915706641; + out_grads[29][2] = -c1 * d; + out_grads[43][2] = s1 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + out_shs[47] = c0 * d; + out_shs[63] = s0 * d; + d = 84.622493774 * a; + out_grads[47][0] = c1 * d; + out_grads[63][0] = s1 * d; + out_grads[47][1] = -s1 * d; + out_grads[63][1] = c1 * d; + d = -77.73072394 * a; + out_grads[48][2] = -c1 * d; + out_grads[62][2] = s1 * d; + b = z2 * (a - 9.02255639e-02); + a = b - 0.118012422 * a; + d = 82.550726364 * a; + out_shs[70] = c0 * d; + out_shs[86] = s0 * d; + d = 660.405810914 * a; + out_grads[70][0] = c1 * d; + out_grads[86][0] = s1 * d; + out_grads[70][1] = -s1 * d; + out_grads[86][1] = c1 * d; + d = -825.507263643 * a; + out_grads[71][2] = -c1 * d; + out_grads[85][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + out_shs[46] = -c1 * d; + out_shs[64] = s1 * d; + d = -30.887057699 * z; + out_grads[46][0] = -c0 * d; + out_grads[64][0] = s0 * d; + out_grads[46][1] = s0 * d; + out_grads[64][1] = c0 * d; + d = 21.155623443 * z; + out_grads[47][2] = c0 * d; + out_grads[63][2] = s0 * d; + a = (z2 - 4.76190476e-02) * z; + b = a - 8.2815735e-02 * z; + d = -36.028090689 * b; + out_shs[69] = -c1 * d; + out_shs[87] = s1 * d; + d = -324.252816204 * b; + out_grads[69][0] = -c0 * d; + out_grads[87][0] = s0 * d; + out_grads[69][1] = s0 * d; + out_grads[87][1] = c0 * d; + d = 330.202905457 * b; + out_grads[70][2] = c0 * d; + out_grads[86][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + out_shs[45] = c0 * d; + out_shs[65] = s0 * d; + d = 7.673951182; + out_grads[45][0] = c1 * d; + out_grads[65][0] = s1 * d; + out_grads[45][1] = -s1 * d; + out_grads[65][1] = c1 * d; + d = -3.4318953; + out_grads[46][2] = -c1 * d; + out_grads[64][2] = s1 * d; + a = z2 - 4.34782609e-02; + d = 13.3042542 * a; + out_shs[68] = c0 * d; + out_shs[88] = s0 * d; + d = 133.042542003 * a; + out_grads[68][0] = c1 * d; + out_grads[88][0] = s1 * d; + out_grads[68][1] = -s1 * d; + out_grads[88][1] = c1 * d; + d = -108.084272068 * a; + out_grads[69][2] = -c1 * d; + out_grads[87][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.923210529 * z; + out_shs[67] = -c1 * d; + out_shs[89] = s1 * d; + d = -43.155315818 * z; + out_grads[67][0] = -c0 * d; + out_grads[89][0] = s0 * d; + out_grads[67][1] = s0 * d; + out_grads[89][1] = c0 * d; + d = 26.608508401 * z; + out_grads[68][2] = c0 * d; + out_grads[88][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.800821996; + out_shs[66] = c0 * d; + out_shs[90] = s0 * d; + d = 9.609863949; + out_grads[66][0] = c1 * d; + out_grads[90][0] = s1 * d; + out_grads[66][1] = -s1 * d; + out_grads[90][1] = c1 * d; + d = -3.923210529; + out_grads[67][2] = -c1 * d; + out_grads[89][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; + out_grads[6][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[14][2] = 0.0; + out_grads[15][2] = 0.0; + out_grads[21][0] = 0.0; + out_grads[21][1] = 0.0; + out_grads[27][2] = 0.0; + out_grads[28][2] = 0.0; + out_grads[36][0] = 0.0; + out_grads[36][1] = 0.0; + out_grads[44][2] = 0.0; + out_grads[45][2] = 0.0; + out_grads[55][0] = 0.0; + out_grads[55][1] = 0.0; + out_grads[65][2] = 0.0; + out_grads[66][2] = 0.0; + out_grads[78][0] = 0.0; + out_grads[78][1] = 0.0; + out_grads[90][2] = 0.0; +} diff --git a/fury/shaders/ray_traced/odf/descoteaux/eval_sh_grad_2.frag b/fury/shaders/ray_traced/odf/descoteaux/eval_sh_grad_2.frag new file mode 100644 index 000000000..7004bd528 --- /dev/null +++ b/fury/shaders/ray_traced/odf/descoteaux/eval_sh_grad_2.frag @@ -0,0 +1,46 @@ +void eval_sh_grad_2(out float out_shs[6], out vec3 out_grads[6], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + out_grads[2][0] = -c0 * d; + out_grads[4][0] = s0 * d; + out_grads[2][1] = s0 * d; + out_grads[4][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + d = 1.092548431; + out_grads[1][0] = c1 * d; + out_grads[5][0] = s1 * d; + out_grads[1][1] = -s1 * d; + out_grads[5][1] = c1 * d; + d = -1.092548431; + out_grads[2][2] = -c1 * d; + out_grads[4][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; +} diff --git a/fury/shaders/ray_traced/odf/descoteaux/eval_sh_grad_4.frag b/fury/shaders/ray_traced/odf/descoteaux/eval_sh_grad_4.frag new file mode 100644 index 000000000..715302f39 --- /dev/null +++ b/fury/shaders/ray_traced/odf/descoteaux/eval_sh_grad_4.frag @@ -0,0 +1,103 @@ +void eval_sh_grad_4(out float out_shs[15], out vec3 out_grads[15], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + out_grads[2][0] = -c0 * d; + out_grads[4][0] = s0 * d; + out_grads[2][1] = s0 * d; + out_grads[4][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + out_grads[9][0] = -c0 * d; + out_grads[11][0] = s0 * d; + out_grads[9][1] = s0 * d; + out_grads[11][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + d = 1.092548431; + out_grads[1][0] = c1 * d; + out_grads[5][0] = s1 * d; + out_grads[1][1] = -s1 * d; + out_grads[5][1] = c1 * d; + d = -1.092548431; + out_grads[2][2] = -c1 * d; + out_grads[4][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + d = 6.62322287 * a; + out_grads[8][0] = c1 * d; + out_grads[12][0] = s1 * d; + out_grads[8][1] = -s1 * d; + out_grads[12][1] = c1 * d; + d = -14.049977415 * a; + out_grads[9][2] = -c1 * d; + out_grads[11][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + d = -5.310392309 * z; + out_grads[7][0] = -c0 * d; + out_grads[13][0] = s0 * d; + out_grads[7][1] = s0 * d; + out_grads[13][1] = c0 * d; + d = 6.62322287 * z; + out_grads[8][2] = c0 * d; + out_grads[12][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + d = 2.503342942; + out_grads[6][0] = c1 * d; + out_grads[14][0] = s1 * d; + out_grads[6][1] = -s1 * d; + out_grads[14][1] = c1 * d; + d = -1.77013077; + out_grads[7][2] = -c1 * d; + out_grads[13][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; + out_grads[6][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[14][2] = 0.0; +} diff --git a/fury/shaders/ray_traced/odf/descoteaux/eval_sh_grad_6.frag b/fury/shaders/ray_traced/odf/descoteaux/eval_sh_grad_6.frag new file mode 100644 index 000000000..fa240c3a5 --- /dev/null +++ b/fury/shaders/ray_traced/odf/descoteaux/eval_sh_grad_6.frag @@ -0,0 +1,186 @@ +void eval_sh_grad_6(out float out_shs[28], out vec3 out_grads[28], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + out_grads[2][0] = -c0 * d; + out_grads[4][0] = s0 * d; + out_grads[2][1] = s0 * d; + out_grads[4][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + out_grads[9][0] = -c0 * d; + out_grads[11][0] = s0 * d; + out_grads[9][1] = s0 * d; + out_grads[11][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[20] = -c1 * d; + out_shs[22] = s1 * d; + out_grads[20][0] = -c0 * d; + out_grads[22][0] = s0 * d; + out_grads[20][1] = s0 * d; + out_grads[22][1] = c0 * d; + d = 88.106914343 * b; + out_grads[21][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + d = 1.092548431; + out_grads[1][0] = c1 * d; + out_grads[5][0] = s1 * d; + out_grads[1][1] = -s1 * d; + out_grads[5][1] = c1 * d; + d = -1.092548431; + out_grads[2][2] = -c1 * d; + out_grads[4][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + d = 6.62322287 * a; + out_grads[8][0] = c1 * d; + out_grads[12][0] = s1 * d; + out_grads[8][1] = -s1 * d; + out_grads[12][1] = c1 * d; + d = -14.049977415 * a; + out_grads[9][2] = -c1 * d; + out_grads[11][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[19] = c0 * d; + out_shs[23] = s0 * d; + d = 30.399773564 * a; + out_grads[19][0] = c1 * d; + out_grads[23][0] = s1 * d; + out_grads[19][1] = -s1 * d; + out_grads[23][1] = c1 * d; + d = -96.132524816 * a; + out_grads[20][2] = -c1 * d; + out_grads[22][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + d = -5.310392309 * z; + out_grads[7][0] = -c0 * d; + out_grads[13][0] = s0 * d; + out_grads[7][1] = s0 * d; + out_grads[13][1] = c0 * d; + d = 6.62322287 * z; + out_grads[8][2] = c0 * d; + out_grads[12][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[18] = -c1 * d; + out_shs[24] = s1 * d; + d = -30.399773564 * b; + out_grads[18][0] = -c0 * d; + out_grads[24][0] = s0 * d; + out_grads[18][1] = s0 * d; + out_grads[24][1] = c0 * d; + d = 60.799547128 * b; + out_grads[19][2] = c0 * d; + out_grads[23][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + d = 2.503342942; + out_grads[6][0] = c1 * d; + out_grads[14][0] = s1 * d; + out_grads[6][1] = -s1 * d; + out_grads[14][1] = c1 * d; + d = -1.77013077; + out_grads[7][2] = -c1 * d; + out_grads[13][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[17] = c0 * d; + out_shs[25] = s0 * d; + d = 22.200855632 * a; + out_grads[17][0] = c1 * d; + out_grads[25][0] = s1 * d; + out_grads[17][1] = -s1 * d; + out_grads[25][1] = c1 * d; + d = -30.399773564 * a; + out_grads[18][2] = -c1 * d; + out_grads[24][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[16] = -c1 * d; + out_shs[26] = s1 * d; + d = -11.833095811 * z; + out_grads[16][0] = -c0 * d; + out_grads[26][0] = s0 * d; + out_grads[16][1] = s0 * d; + out_grads[26][1] = c0 * d; + d = 11.100427816 * z; + out_grads[17][2] = c0 * d; + out_grads[25][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[15] = c0 * d; + out_shs[27] = s0 * d; + d = 4.099104631; + out_grads[15][0] = c1 * d; + out_grads[27][0] = s1 * d; + out_grads[15][1] = -s1 * d; + out_grads[27][1] = c1 * d; + d = -2.366619162; + out_grads[16][2] = -c1 * d; + out_grads[26][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; + out_grads[6][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[14][2] = 0.0; + out_grads[15][2] = 0.0; + out_grads[21][0] = 0.0; + out_grads[21][1] = 0.0; + out_grads[27][2] = 0.0; +} diff --git a/fury/shaders/ray_traced/odf/descoteaux/eval_sh_grad_8.frag b/fury/shaders/ray_traced/odf/descoteaux/eval_sh_grad_8.frag new file mode 100644 index 000000000..b0a40d0a7 --- /dev/null +++ b/fury/shaders/ray_traced/odf/descoteaux/eval_sh_grad_8.frag @@ -0,0 +1,295 @@ +void eval_sh_grad_8(out float out_shs[45], out vec3 out_grads[45], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + out_grads[2][0] = -c0 * d; + out_grads[4][0] = s0 * d; + out_grads[2][1] = s0 * d; + out_grads[4][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + out_grads[9][0] = -c0 * d; + out_grads[11][0] = s0 * d; + out_grads[9][1] = s0 * d; + out_grads[11][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[20] = -c1 * d; + out_shs[22] = s1 * d; + out_grads[20][0] = -c0 * d; + out_grads[22][0] = s0 * d; + out_grads[20][1] = s0 * d; + out_grads[22][1] = c0 * d; + d = 88.106914343 * b; + out_grads[21][2] = d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[35] = -c1 * d; + out_shs[37] = s1 * d; + out_grads[35][0] = -c0 * d; + out_grads[37][0] = s0 * d; + out_grads[35][1] = s0 * d; + out_grads[37][1] = c0 * d; + d = 467.786944906 * b; + out_grads[36][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + d = 1.092548431; + out_grads[1][0] = c1 * d; + out_grads[5][0] = s1 * d; + out_grads[1][1] = -s1 * d; + out_grads[5][1] = c1 * d; + d = -1.092548431; + out_grads[2][2] = -c1 * d; + out_grads[4][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + d = 6.62322287 * a; + out_grads[8][0] = c1 * d; + out_grads[12][0] = s1 * d; + out_grads[8][1] = -s1 * d; + out_grads[12][1] = c1 * d; + d = -14.049977415 * a; + out_grads[9][2] = -c1 * d; + out_grads[11][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[19] = c0 * d; + out_shs[23] = s0 * d; + d = 30.399773564 * a; + out_grads[19][0] = c1 * d; + out_grads[23][0] = s1 * d; + out_grads[19][1] = -s1 * d; + out_grads[23][1] = c1 * d; + d = -96.132524816 * a; + out_grads[20][2] = -c1 * d; + out_grads[22][2] = s1 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[34] = c0 * d; + out_shs[38] = s0 * d; + d = 130.459545912 * a; + out_grads[34][0] = c1 * d; + out_grads[38][0] = s1 * d; + out_grads[34][1] = -s1 * d; + out_grads[38][1] = c1 * d; + d = -545.751435723 * a; + out_grads[35][2] = -c1 * d; + out_grads[37][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + d = -5.310392309 * z; + out_grads[7][0] = -c0 * d; + out_grads[13][0] = s0 * d; + out_grads[7][1] = s0 * d; + out_grads[13][1] = c0 * d; + d = 6.62322287 * z; + out_grads[8][2] = c0 * d; + out_grads[12][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[18] = -c1 * d; + out_shs[24] = s1 * d; + d = -30.399773564 * b; + out_grads[18][0] = -c0 * d; + out_grads[24][0] = s0 * d; + out_grads[18][1] = s0 * d; + out_grads[24][1] = c0 * d; + d = 60.799547128 * b; + out_grads[19][2] = c0 * d; + out_grads[23][2] = s0 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[33] = -c1 * d; + out_shs[39] = s1 * d; + d = -144.52614017 * b; + out_grads[33][0] = -c0 * d; + out_grads[39][0] = s0 * d; + out_grads[33][1] = s0 * d; + out_grads[39][1] = c0 * d; + d = 391.378637737 * b; + out_grads[34][2] = c0 * d; + out_grads[38][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + d = 2.503342942; + out_grads[6][0] = c1 * d; + out_grads[14][0] = s1 * d; + out_grads[6][1] = -s1 * d; + out_grads[14][1] = c1 * d; + d = -1.77013077; + out_grads[7][2] = -c1 * d; + out_grads[13][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[17] = c0 * d; + out_shs[25] = s0 * d; + d = 22.200855632 * a; + out_grads[17][0] = c1 * d; + out_grads[25][0] = s1 * d; + out_grads[17][1] = -s1 * d; + out_grads[25][1] = c1 * d; + d = -30.399773564 * a; + out_grads[18][2] = -c1 * d; + out_grads[24][2] = s1 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[32] = c0 * d; + out_shs[40] = s0 * d; + d = 124.388296437 * a; + out_grads[32][0] = c1 * d; + out_grads[40][0] = s1 * d; + out_grads[32][1] = -s1 * d; + out_grads[40][1] = c1 * d; + d = -240.876900283 * a; + out_grads[33][2] = -c1 * d; + out_grads[39][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[16] = -c1 * d; + out_shs[26] = s1 * d; + d = -11.833095811 * z; + out_grads[16][0] = -c0 * d; + out_grads[26][0] = s0 * d; + out_grads[16][1] = s0 * d; + out_grads[26][1] = c0 * d; + d = 11.100427816 * z; + out_grads[17][2] = c0 * d; + out_grads[25][2] = s0 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[31] = -c1 * d; + out_shs[41] = s1 * d; + d = -86.247765552 * b; + out_grads[31][0] = -c0 * d; + out_grads[41][0] = s0 * d; + out_grads[31][1] = s0 * d; + out_grads[41][1] = c0 * d; + d = 124.388296437 * b; + out_grads[32][2] = c0 * d; + out_grads[40][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[15] = c0 * d; + out_shs[27] = s0 * d; + d = 4.099104631; + out_grads[15][0] = c1 * d; + out_grads[27][0] = s1 * d; + out_grads[15][1] = -s1 * d; + out_grads[27][1] = c1 * d; + d = -2.366619162; + out_grads[16][2] = -c1 * d; + out_grads[26][2] = s1 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[30] = c0 * d; + out_shs[42] = s0 * d; + d = 47.909948945 * a; + out_grads[30][0] = c1 * d; + out_grads[42][0] = s1 * d; + out_grads[30][1] = -s1 * d; + out_grads[42][1] = c1 * d; + d = -51.748659331 * a; + out_grads[31][2] = -c1 * d; + out_grads[41][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[29] = -c1 * d; + out_shs[43] = s1 * d; + d = -20.409946485 * z; + out_grads[29][0] = -c0 * d; + out_grads[43][0] = s0 * d; + out_grads[29][1] = s0 * d; + out_grads[43][1] = c0 * d; + d = 15.969982982 * z; + out_grads[30][2] = c0 * d; + out_grads[42][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[28] = c0 * d; + out_shs[44] = s0 * d; + d = 5.831413281; + out_grads[28][0] = c1 * d; + out_grads[44][0] = s1 * d; + out_grads[28][1] = -s1 * d; + out_grads[44][1] = c1 * d; + d = -2.915706641; + out_grads[29][2] = -c1 * d; + out_grads[43][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; + out_grads[6][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[14][2] = 0.0; + out_grads[15][2] = 0.0; + out_grads[21][0] = 0.0; + out_grads[21][1] = 0.0; + out_grads[27][2] = 0.0; + out_grads[28][2] = 0.0; + out_grads[36][0] = 0.0; + out_grads[36][1] = 0.0; + out_grads[44][2] = 0.0; +} diff --git a/fury/shaders/ray_traced/odf/eval_sh.frag b/fury/shaders/ray_traced/odf/eval_sh.frag index f6e4dc8af..18625f297 100644 --- a/fury/shaders/ray_traced/odf/eval_sh.frag +++ b/fury/shaders/ray_traced/odf/eval_sh.frag @@ -1,45 +1,45 @@ -void evalSH(out float outSHs[SH_COUNT], vec3 point, int shDegree, int numCoeffs) +void evalSH(out float outSH[SH_COUNT], vec3 point, int shDegree, int numCoeffs) { if (shDegree == 2) { - float tmpOutSHs[6]; - eval_sh_2(tmpOutSHs, point); + float tmpOutSH[6]; + evalSH2(tmpOutSH, point); for (int i = 0; i != numCoeffs; ++i) - outSHs[i] = tmpOutSHs[i]; + outSH[i] = tmpOutSH[i]; } else if (shDegree == 4) { - float tmpOutSHs[15]; - eval_sh_4(tmpOutSHs, point); + float tmpOutSH[15]; + evalSH4(tmpOutSH, point); for (int i = 0; i != numCoeffs; ++i) - outSHs[i] = tmpOutSHs[i]; + outSH[i] = tmpOutSH[i]; } else if (shDegree == 6) { - float tmpOutSHs[28]; - eval_sh_6(tmpOutSHs, point); + float tmpOutSH[28]; + evalSH6(tmpOutSH, point); for (int i = 0; i != numCoeffs; ++i) - outSHs[i] = tmpOutSHs[i]; + outSH[i] = tmpOutSH[i]; } else if (shDegree == 8) { - float outSHs[45]; - eval_sh_8(outSHs, point); + float tmpOutSH[45]; + evalSH8(outSH, point); for (int i = 0; i != numCoeffs; ++i) - outSHs[i] = tmpOutSHs[i]; + outSH[i] = tmpOutSH[i]; } else if (shDegree == 10) { - float outSHs[66]; - eval_sh_10(outSHs, point); + float tmpOutSH[66]; + evalSH10(outSH, point); for (int i = 0; i != numCoeffs; ++i) - outSHs[i] = tmpOutSHs[i]; + outSH[i] = tmpOutSH[i]; } else if (shDegree == 12) { - float outSHs[91]; - eval_sh_12(outSHs, point); + float tmpOutSH[91]; + evalSH12(outSH, point); for (int i = 0; i != numCoeffs; ++i) - outSHs[i] = tmpOutSHs[i]; + outSH[i] = tmpOutSH[i]; } } diff --git a/fury/shaders/ray_traced/odf/tournier/eval_sh_10.frag b/fury/shaders/ray_traced/odf/tournier/eval_sh_10.frag new file mode 100644 index 000000000..d5b33c189 --- /dev/null +++ b/fury/shaders/ray_traced/odf/tournier/eval_sh_10.frag @@ -0,0 +1,175 @@ +void evalSH10(out float outSH[66], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + outSH[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + outSH[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + outSH[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + outSH[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + outSH[36] = d; + b = z2 * a - 0.250980392 * b; + a = b - 0.250773994 * a; + d = 233.240148813 * a; + outSH[55] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + outSH[4] = c1 * d; + outSH[2] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + outSH[11] = c1 * d; + outSH[9] = s1 * d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + outSH[22] = c1 * d; + outSH[20] = s1 * d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + outSH[37] = c1 * d; + outSH[35] = s1 * d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + outSH[56] = c1 * d; + outSH[54] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + outSH[5] = c0 * d; + outSH[1] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + outSH[12] = c0 * d; + outSH[8] = s0 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + outSH[23] = c0 * d; + outSH[19] = s0 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + outSH[38] = c0 * d; + outSH[34] = s0 * d; + b = z2 * a - 0.235294118 * b; + a = b - 0.238390093 * a; + d = 272.365814381 * a; + outSH[57] = c0 * d; + outSH[53] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + outSH[13] = c1 * d; + outSH[7] = s1 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + outSH[24] = c1 * d; + outSH[18] = s1 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + outSH[39] = c1 * d; + outSH[33] = s1 * d; + a = z2 * b - 0.215686275 * a; + b = a - 0.222910217 * b; + d = -213.661323441 * b; + outSH[58] = c1 * d; + outSH[52] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + outSH[14] = c0 * d; + outSH[6] = s0 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + outSH[25] = c0 * d; + outSH[17] = s0 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + outSH[40] = c0 * d; + outSH[32] = s0 * d; + b = z2 * a - 0.188235294 * b; + a = b - 0.20123839 * a; + d = 151.081370682 * a; + outSH[59] = c0 * d; + outSH[51] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + outSH[26] = c1 * d; + outSH[16] = s1 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + outSH[41] = c1 * d; + outSH[31] = s1 * d; + a = z2 * b - 0.152941176 * a; + b = a - 0.173374613 * b; + d = -95.552248675 * b; + outSH[60] = c1 * d; + outSH[50] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + outSH[27] = c0 * d; + outSH[15] = s0 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + outSH[42] = c0 * d; + outSH[30] = s0 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + outSH[61] = c0 * d; + outSH[49] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + outSH[43] = c1 * d; + outSH[29] = s1 * d; + a = (z2 - 5.88235294e-02) * z; + b = a - 9.90712074e-02 * z; + d = -25.910241313 * b; + outSH[62] = c1 * d; + outSH[48] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + outSH[44] = c0 * d; + outSH[28] = s0 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + outSH[63] = c0 * d; + outSH[47] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + outSH[64] = c1 * d; + outSH[46] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + outSH[65] = c0 * d; + outSH[45] = s0 * d; +} diff --git a/fury/shaders/ray_traced/odf/tournier/eval_sh_12.frag b/fury/shaders/ray_traced/odf/tournier/eval_sh_12.frag new file mode 100644 index 000000000..3994374e9 --- /dev/null +++ b/fury/shaders/ray_traced/odf/tournier/eval_sh_12.frag @@ -0,0 +1,238 @@ +void evalSH12(out float outSH[91], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + outSH[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + outSH[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + outSH[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + outSH[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + outSH[36] = d; + b = z2 * a - 0.250980392 * b; + a = b - 0.250773994 * a; + d = 233.240148813 * a; + outSH[55] = d; + b = z2 * a - 0.250626566 * b; + a = b - 0.250517598 * a; + d = 931.186918633 * a; + outSH[78] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + outSH[4] = c1 * d; + outSH[2] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + outSH[11] = c1 * d; + outSH[9] = s1 * d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + outSH[22] = c1 * d; + outSH[20] = s1 * d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + outSH[37] = c1 * d; + outSH[35] = s1 * d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + outSH[56] = c1 * d; + outSH[54] = s1 * d; + a = z2 * b - 0.248120301 * a; + b = a - 0.248447205 * b; + d = -1265.233874957 * b; + outSH[79] = c1 * d; + outSH[77] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + outSH[5] = c0 * d; + outSH[1] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + outSH[12] = c0 * d; + outSH[8] = s0 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + outSH[23] = c0 * d; + outSH[19] = s0 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + outSH[38] = c0 * d; + outSH[34] = s0 * d; + b = z2 * a - 0.235294118 * b; + a = b - 0.238390093 * a; + d = 272.365814381 * a; + outSH[57] = c0 * d; + outSH[53] = s0 * d; + b = z2 * a - 0.240601504 * b; + a = b - 0.242236025 * a; + d = 1121.509962433 * a; + outSH[80] = c0 * d; + outSH[76] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + outSH[13] = c1 * d; + outSH[7] = s1 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + outSH[24] = c1 * d; + outSH[18] = s1 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + outSH[39] = c1 * d; + outSH[33] = s1 * d; + a = z2 * b - 0.215686275 * a; + b = a - 0.222910217 * b; + d = -213.661323441 * b; + outSH[58] = c1 * d; + outSH[52] = s1 * d; + a = z2 * b - 0.228070175 * a; + b = a - 0.231884058 * b; + d = -915.709049803 * b; + outSH[81] = c1 * d; + outSH[75] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + outSH[14] = c0 * d; + outSH[6] = s0 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + outSH[25] = c0 * d; + outSH[17] = s0 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + outSH[40] = c0 * d; + outSH[32] = s0 * d; + b = z2 * a - 0.188235294 * b; + a = b - 0.20123839 * a; + d = 151.081370682 * a; + outSH[59] = c0 * d; + outSH[51] = s0 * d; + b = z2 * a - 0.210526316 * b; + a = b - 0.217391304 * a; + d = 686.781787352 * a; + outSH[82] = c0 * d; + outSH[74] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + outSH[26] = c1 * d; + outSH[16] = s1 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + outSH[41] = c1 * d; + outSH[31] = s1 * d; + a = z2 * b - 0.152941176 * a; + b = a - 0.173374613 * b; + d = -95.552248675 * b; + outSH[60] = c1 * d; + outSH[50] = s1 * d; + a = z2 * b - 0.187969925 * a; + b = a - 0.198757764 * b; + d = -471.12841933 * b; + outSH[83] = c1 * d; + outSH[73] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + outSH[27] = c0 * d; + outSH[15] = s0 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + outSH[42] = c0 * d; + outSH[30] = s0 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + outSH[61] = c0 * d; + outSH[49] = s0 * d; + b = z2 * a - 0.160401003 * b; + a = b - 0.175983437 * a; + d = 293.800188384 * a; + outSH[84] = c0 * d; + outSH[72] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + outSH[43] = c1 * d; + outSH[29] = s1 * d; + a = (z2 - 5.88235294e-02) * z; + b = a - 9.90712074e-02 * z; + d = -25.910241313 * b; + outSH[62] = c1 * d; + outSH[48] = s1 * d; + a = z2 * b - 0.127819549 * a; + b = a - 0.149068323 * b; + d = -165.101452729 * b; + outSH[85] = c1 * d; + outSH[71] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + outSH[44] = c0 * d; + outSH[28] = s0 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + outSH[63] = c0 * d; + outSH[47] = s0 * d; + b = z2 * (a - 9.02255639e-02); + a = b - 0.118012422 * a; + d = 82.550726364 * a; + outSH[86] = c0 * d; + outSH[70] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + outSH[64] = c1 * d; + outSH[46] = s1 * d; + a = (z2 - 4.76190476e-02) * z; + b = a - 8.2815735e-02 * z; + d = -36.028090689 * b; + outSH[87] = c1 * d; + outSH[69] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + outSH[65] = c0 * d; + outSH[45] = s0 * d; + a = z2 - 4.34782609e-02; + d = 13.3042542 * a; + outSH[88] = c0 * d; + outSH[68] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.923210529 * z; + outSH[89] = c1 * d; + outSH[67] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.800821996; + outSH[90] = c0 * d; + outSH[66] = s0 * d; +} diff --git a/fury/shaders/ray_traced/odf/tournier/eval_sh_2.frag b/fury/shaders/ray_traced/odf/tournier/eval_sh_2.frag new file mode 100644 index 000000000..6e0907c91 --- /dev/null +++ b/fury/shaders/ray_traced/odf/tournier/eval_sh_2.frag @@ -0,0 +1,21 @@ +void evalSH2(out float outSH[6], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + outSH[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + outSH[3] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + outSH[4] = c1 * d; + outSH x * s1; + d = 0.546274215; + outSH[5] = c0 * d; + outSH* d; +} diff --git a/fury/shaders/ray_traced/odf/tournier/eval_sh_4.frag b/fury/shaders/ray_traced/odf/tournier/eval_sh_4.frag new file mode 100644 index 000000000..77152bb6a --- /dev/null +++ b/fury/shaders/ray_traced/odf/tournier/eval_sh_4.frag @@ -0,0 +1,46 @@ +void evalSH4(out float outSH[15], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + outSH[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + outSH[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + outSH[10] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + outSH[4] = c1 * d; + outSH[2] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + outSH[11] = c1 * d; + outSH[9] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + outSH[5] = c0 * d; + outSH[1] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + outSH[12] = c0 * d; + outSH[8] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + outSH[13] = c1 * d; + outSH[7] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + outSH[14] = c0 * d; + outSH[6] = s0 * d; +} diff --git a/fury/shaders/ray_traced/odf/tournier/eval_sh_6.frag b/fury/shaders/ray_traced/odf/tournier/eval_sh_6.frag new file mode 100644 index 000000000..6e3d53307 --- /dev/null +++ b/fury/shaders/ray_traced/odf/tournier/eval_sh_6.frag @@ -0,0 +1,79 @@ +void evalSH6(out float outSH[28], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + outSH[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + outSH[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + outSH[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + outSH[21] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + outSH[4] = c1 * d; + outSH[2] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + outSH[11] = c1 * d; + outSH[9] = s1 * d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + outSH[22] = c1 * d; + outSH[20] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + outSH[5] = c0 * d; + outSH[1] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + outSH[12] = c0 * d; + outSH[8] = s0 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + outSH[23] = c0 * d; + outSH[19] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + outSH[13] = c1 * d; + outSH[7] = s1 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + outSH[24] = c1 * d; + outSH[18] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + outSH[14] = c0 * d; + outSH[6] = s0 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + outSH[25] = c0 * d; + outSH[17] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + outSH[26] = c1 * d; + outSH[16] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + outSH[27] = c0 * d; + outSH[15] = s0 * d; +} diff --git a/fury/shaders/ray_traced/odf/tournier/eval_sh_8.frag b/fury/shaders/ray_traced/odf/tournier/eval_sh_8.frag new file mode 100644 index 000000000..e68a3efba --- /dev/null +++ b/fury/shaders/ray_traced/odf/tournier/eval_sh_8.frag @@ -0,0 +1,122 @@ +void evalSH8(out float outSH[45], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + outSH[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + outSH[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + outSH[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + outSH[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + outSH[36] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + outSH[4] = c1 * d; + outSH[2] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + outSH[11] = c1 * d; + outSH[9] = s1 * d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + outSH[22] = c1 * d; + outSH[20] = s1 * d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + outSH[37] = c1 * d; + outSH[35] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + outSH[5] = c0 * d; + outSH[1] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + outSH[12] = c0 * d; + outSH[8] = s0 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + outSH[23] = c0 * d; + outSH[19] = s0 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + outSH[38] = c0 * d; + outSH[34] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + outSH[13] = c1 * d; + outSH[7] = s1 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + outSH[24] = c1 * d; + outSH[18] = s1 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + outSH[39] = c1 * d; + outSH[33] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + outSH[14] = c0 * d; + outSH[6] = s0 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + outSH[25] = c0 * d; + outSH[17] = s0 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + outSH[40] = c0 * d; + outSH[32] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + outSH[26] = c1 * d; + outSH[16] = s1 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + outSH[41] = c1 * d; + outSH[31] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + outSH[27] = c0 * d; + outSH[15] = s0 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + outSH[42] = c0 * d; + outSH[30] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + outSH[43] = c1 * d; + outSH[29] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + outSH[44] = c0 * d; + outSH[28] = s0 * d; +} diff --git a/fury/shaders/ray_traced/odf/tournier/eval_sh_grad_10.frag b/fury/shaders/ray_traced/odf/tournier/eval_sh_grad_10.frag new file mode 100644 index 000000000..c9e6b0d8d --- /dev/null +++ b/fury/shaders/ray_traced/odf/tournier/eval_sh_grad_10.frag @@ -0,0 +1,430 @@ +void eval_sh_grad_10(out float out_shs[66], out vec3 out_grads[66], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + b = z2 * a - 0.250980392 * b; + a = b - 0.250773994 * a; + d = 233.240148813 * a; + out_shs[55] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + out_grads[4][0] = c0 * d; + out_grads[2][0] = s0 * d; + out_grads[4][1] = s0 * d; + out_grads[2][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + out_grads[11][0] = c0 * d; + out_grads[9][0] = s0 * d; + out_grads[11][1] = s0 * d; + out_grads[9][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[22] = c1 * d; + out_shs[20] = s1 * d; + out_grads[22][0] = c0 * d; + out_grads[20][0] = s0 * d; + out_grads[22][1] = s0 * d; + out_grads[20][1] = c0 * d; + d = 88.106914343 * b; + out_grads[21][2] = d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[37] = c1 * d; + out_shs[35] = s1 * d; + out_grads[37][0] = c0 * d; + out_grads[35][0] = s0 * d; + out_grads[37][1] = s0 * d; + out_grads[35][1] = c0 * d; + d = 467.786944906 * b; + out_grads[36][2] = d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + out_shs[56] = c1 * d; + out_shs[54] = s1 * d; + out_grads[56][0] = c0 * d; + out_grads[54][0] = s0 * d; + out_grads[56][1] = s0 * d; + out_grads[54][1] = c0 * d; + d = 2332.401488133 * b; + out_grads[55][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + d = 1.092548431; + out_grads[5][0] = c1 * d; + out_grads[1][0] = s1 * d; + out_grads[5][1] = -s1 * d; + out_grads[1][1] = c1 * d; + d = -1.092548431; + out_grads[4][2] = c1 * d; + out_grads[2][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + d = 6.62322287 * a; + out_grads[12][0] = c1 * d; + out_grads[8][0] = s1 * d; + out_grads[12][1] = -s1 * d; + out_grads[8][1] = c1 * d; + d = -14.049977415 * a; + out_grads[11][2] = c1 * d; + out_grads[9][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[23] = c0 * d; + out_shs[19] = s0 * d; + d = 30.399773564 * a; + out_grads[23][0] = c1 * d; + out_grads[19][0] = s1 * d; + out_grads[23][1] = -s1 * d; + out_grads[19][1] = c1 * d; + d = -96.132524816 * a; + out_grads[22][2] = c1 * d; + out_grads[20][2] = s1 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[38] = c0 * d; + out_shs[34] = s0 * d; + d = 130.459545912 * a; + out_grads[38][0] = c1 * d; + out_grads[34][0] = s1 * d; + out_grads[38][1] = -s1 * d; + out_grads[34][1] = c1 * d; + d = -545.751435723 * a; + out_grads[37][2] = c1 * d; + out_grads[35][2] = s1 * d; + b = z2 * a - 0.235294118 * b; + a = b - 0.238390093 * a; + d = 272.365814381 * a; + out_shs[57] = c0 * d; + out_shs[53] = s0 * d; + d = 544.731628762 * a; + out_grads[57][0] = c1 * d; + out_grads[53][0] = s1 * d; + out_grads[57][1] = -s1 * d; + out_grads[53][1] = c1 * d; + d = -2830.508572514 * a; + out_grads[56][2] = c1 * d; + out_grads[54][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; + d = -5.310392309 * z; + out_grads[13][0] = c0 * d; + out_grads[7][0] = s0 * d; + out_grads[13][1] = s0 * d; + out_grads[7][1] = c0 * d; + d = 6.62322287 * z; + out_grads[12][2] = c0 * d; + out_grads[8][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[24] = c1 * d; + out_shs[18] = s1 * d; + d = -30.399773564 * b; + out_grads[24][0] = c0 * d; + out_grads[18][0] = s0 * d; + out_grads[24][1] = s0 * d; + out_grads[18][1] = c0 * d; + d = 60.799547128 * b; + out_grads[23][2] = c0 * d; + out_grads[19][2] = s0 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[39] = c1 * d; + out_shs[33] = s1 * d; + d = -144.52614017 * b; + out_grads[39][0] = c0 * d; + out_grads[33][0] = s0 * d; + out_grads[39][1] = s0 * d; + out_grads[33][1] = c0 * d; + d = 391.378637737 * b; + out_grads[38][2] = c0 * d; + out_grads[34][2] = s0 * d; + a = z2 * b - 0.215686275 * a; + b = a - 0.222910217 * b; + d = -213.661323441 * b; + out_shs[58] = c1 * d; + out_shs[52] = s1 * d; + d = -640.983970322 * b; + out_grads[58][0] = c0 * d; + out_grads[52][0] = s0 * d; + out_grads[58][1] = s0 * d; + out_grads[52][1] = c0 * d; + d = 2178.926515046 * b; + out_grads[57][2] = c0 * d; + out_grads[53][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; + d = 2.503342942; + out_grads[14][0] = c1 * d; + out_grads[6][0] = s1 * d; + out_grads[14][1] = -s1 * d; + out_grads[6][1] = c1 * d; + d = -1.77013077; + out_grads[13][2] = c1 * d; + out_grads[7][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[25] = c0 * d; + out_shs[17] = s0 * d; + d = 22.200855632 * a; + out_grads[25][0] = c1 * d; + out_grads[17][0] = s1 * d; + out_grads[25][1] = -s1 * d; + out_grads[17][1] = c1 * d; + d = -30.399773564 * a; + out_grads[24][2] = c1 * d; + out_grads[18][2] = s1 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[40] = c0 * d; + out_shs[32] = s0 * d; + d = 124.388296437 * a; + out_grads[40][0] = c1 * d; + out_grads[32][0] = s1 * d; + out_grads[40][1] = -s1 * d; + out_grads[32][1] = c1 * d; + d = -240.876900283 * a; + out_grads[39][2] = c1 * d; + out_grads[33][2] = s1 * d; + b = z2 * a - 0.188235294 * b; + a = b - 0.20123839 * a; + d = 151.081370682 * a; + out_shs[59] = c0 * d; + out_shs[51] = s0 * d; + d = 604.325482728 * a; + out_grads[59][0] = c1 * d; + out_grads[51][0] = s1 * d; + out_grads[59][1] = -s1 * d; + out_grads[51][1] = c1 * d; + d = -1495.629264084 * a; + out_grads[58][2] = c1 * d; + out_grads[52][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[26] = c1 * d; + out_shs[16] = s1 * d; + d = -11.833095811 * z; + out_grads[26][0] = c0 * d; + out_grads[16][0] = s0 * d; + out_grads[26][1] = s0 * d; + out_grads[16][1] = c0 * d; + d = 11.100427816 * z; + out_grads[25][2] = c0 * d; + out_grads[17][2] = s0 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[41] = c1 * d; + out_shs[31] = s1 * d; + d = -86.247765552 * b; + out_grads[41][0] = c0 * d; + out_grads[31][0] = s0 * d; + out_grads[41][1] = s0 * d; + out_grads[31][1] = c0 * d; + d = 124.388296437 * b; + out_grads[40][2] = c0 * d; + out_grads[32][2] = s0 * d; + a = z2 * b - 0.152941176 * a; + b = a - 0.173374613 * b; + d = -95.552248675 * b; + out_shs[60] = c1 * d; + out_shs[50] = s1 * d; + d = -477.761243376 * b; + out_grads[60][0] = c0 * d; + out_grads[50][0] = s0 * d; + out_grads[60][1] = s0 * d; + out_grads[50][1] = c0 * d; + d = 906.488224092 * b; + out_grads[59][2] = c0 * d; + out_grads[51][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[27] = c0 * d; + out_shs[15] = s0 * d; + d = 4.099104631; + out_grads[27][0] = c1 * d; + out_grads[15][0] = s1 * d; + out_grads[27][1] = -s1 * d; + out_grads[15][1] = c1 * d; + d = -2.366619162; + out_grads[26][2] = c1 * d; + out_grads[16][2] = s1 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[42] = c0 * d; + out_shs[30] = s0 * d; + d = 47.909948945 * a; + out_grads[42][0] = c1 * d; + out_grads[30][0] = s1 * d; + out_grads[42][1] = -s1 * d; + out_grads[30][1] = c1 * d; + d = -51.748659331 * a; + out_grads[41][2] = c1 * d; + out_grads[31][2] = s1 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + out_shs[61] = c0 * d; + out_shs[49] = s0 * d; + d = 320.491985161 * a; + out_grads[61][0] = c1 * d; + out_grads[49][0] = s1 * d; + out_grads[61][1] = -s1 * d; + out_grads[49][1] = c1 * d; + d = -477.761243376 * a; + out_grads[60][2] = c1 * d; + out_grads[50][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[43] = c1 * d; + out_shs[29] = s1 * d; + d = -20.409946485 * z; + out_grads[43][0] = c0 * d; + out_grads[29][0] = s0 * d; + out_grads[43][1] = s0 * d; + out_grads[29][1] = c0 * d; + d = 15.969982982 * z; + out_grads[42][2] = c0 * d; + out_grads[30][2] = s0 * d; + a = (z2 - 5.88235294e-02) * z; + b = a - 9.90712074e-02 * z; + d = -25.910241313 * b; + out_shs[62] = c1 * d; + out_shs[48] = s1 * d; + d = -181.371689194 * b; + out_grads[62][0] = c0 * d; + out_grads[48][0] = s0 * d; + out_grads[62][1] = s0 * d; + out_grads[48][1] = c0 * d; + d = 213.661323441 * b; + out_grads[61][2] = c0 * d; + out_grads[49][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[44] = c0 * d; + out_shs[28] = s0 * d; + d = 5.831413281; + out_grads[44][0] = c1 * d; + out_grads[28][0] = s1 * d; + out_grads[44][1] = -s1 * d; + out_grads[28][1] = c1 * d; + d = -2.915706641; + out_grads[43][2] = c1 * d; + out_grads[29][2] = s1 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + out_shs[63] = c0 * d; + out_shs[47] = s0 * d; + d = 84.622493774 * a; + out_grads[63][0] = c1 * d; + out_grads[47][0] = s1 * d; + out_grads[63][1] = -s1 * d; + out_grads[47][1] = c1 * d; + d = -77.73072394 * a; + out_grads[62][2] = c1 * d; + out_grads[48][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + out_shs[64] = c1 * d; + out_shs[46] = s1 * d; + d = -30.887057699 * z; + out_grads[64][0] = c0 * d; + out_grads[46][0] = s0 * d; + out_grads[64][1] = s0 * d; + out_grads[46][1] = c0 * d; + d = 21.155623443 * z; + out_grads[63][2] = c0 * d; + out_grads[47][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + out_shs[65] = c0 * d; + out_shs[45] = s0 * d; + d = 7.673951182; + out_grads[65][0] = c1 * d; + out_grads[45][0] = s1 * d; + out_grads[65][1] = -s1 * d; + out_grads[45][1] = c1 * d; + d = -3.4318953; + out_grads[64][2] = c1 * d; + out_grads[46][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; + out_grads[6][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[14][2] = 0.0; + out_grads[15][2] = 0.0; + out_grads[21][0] = 0.0; + out_grads[21][1] = 0.0; + out_grads[27][2] = 0.0; + out_grads[28][2] = 0.0; + out_grads[36][0] = 0.0; + out_grads[36][1] = 0.0; + out_grads[44][2] = 0.0; + out_grads[45][2] = 0.0; + out_grads[55][0] = 0.0; + out_grads[55][1] = 0.0; + out_grads[65][2] = 0.0; +} diff --git a/fury/shaders/ray_traced/odf/tournier/eval_sh_grad_12.frag b/fury/shaders/ray_traced/odf/tournier/eval_sh_grad_12.frag new file mode 100644 index 000000000..35c2a3617 --- /dev/null +++ b/fury/shaders/ray_traced/odf/tournier/eval_sh_grad_12.frag @@ -0,0 +1,591 @@ +void eval_sh_grad_12(out float out_shs[91], out vec3 out_grads[91], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + b = z2 * a - 0.250980392 * b; + a = b - 0.250773994 * a; + d = 233.240148813 * a; + out_shs[55] = d; + b = z2 * a - 0.250626566 * b; + a = b - 0.250517598 * a; + d = 931.186918633 * a; + out_shs[78] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + out_grads[4][0] = c0 * d; + out_grads[2][0] = s0 * d; + out_grads[4][1] = s0 * d; + out_grads[2][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + out_grads[11][0] = c0 * d; + out_grads[9][0] = s0 * d; + out_grads[11][1] = s0 * d; + out_grads[9][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[22] = c1 * d; + out_shs[20] = s1 * d; + out_grads[22][0] = c0 * d; + out_grads[20][0] = s0 * d; + out_grads[22][1] = s0 * d; + out_grads[20][1] = c0 * d; + d = 88.106914343 * b; + out_grads[21][2] = d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[37] = c1 * d; + out_shs[35] = s1 * d; + out_grads[37][0] = c0 * d; + out_grads[35][0] = s0 * d; + out_grads[37][1] = s0 * d; + out_grads[35][1] = c0 * d; + d = 467.786944906 * b; + out_grads[36][2] = d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + out_shs[56] = c1 * d; + out_shs[54] = s1 * d; + out_grads[56][0] = c0 * d; + out_grads[54][0] = s0 * d; + out_grads[56][1] = s0 * d; + out_grads[54][1] = c0 * d; + d = 2332.401488133 * b; + out_grads[55][2] = d; + a = z2 * b - 0.248120301 * a; + b = a - 0.248447205 * b; + d = -1265.233874957 * b; + out_shs[79] = c1 * d; + out_shs[77] = s1 * d; + out_grads[79][0] = c0 * d; + out_grads[77][0] = s0 * d; + out_grads[79][1] = s0 * d; + out_grads[77][1] = c0 * d; + d = 11174.243023595 * b; + out_grads[78][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + d = 1.092548431; + out_grads[5][0] = c1 * d; + out_grads[1][0] = s1 * d; + out_grads[5][1] = -s1 * d; + out_grads[1][1] = c1 * d; + d = -1.092548431; + out_grads[4][2] = c1 * d; + out_grads[2][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + d = 6.62322287 * a; + out_grads[12][0] = c1 * d; + out_grads[8][0] = s1 * d; + out_grads[12][1] = -s1 * d; + out_grads[8][1] = c1 * d; + d = -14.049977415 * a; + out_grads[11][2] = c1 * d; + out_grads[9][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[23] = c0 * d; + out_shs[19] = s0 * d; + d = 30.399773564 * a; + out_grads[23][0] = c1 * d; + out_grads[19][0] = s1 * d; + out_grads[23][1] = -s1 * d; + out_grads[19][1] = c1 * d; + d = -96.132524816 * a; + out_grads[22][2] = c1 * d; + out_grads[20][2] = s1 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[38] = c0 * d; + out_shs[34] = s0 * d; + d = 130.459545912 * a; + out_grads[38][0] = c1 * d; + out_grads[34][0] = s1 * d; + out_grads[38][1] = -s1 * d; + out_grads[34][1] = c1 * d; + d = -545.751435723 * a; + out_grads[37][2] = c1 * d; + out_grads[35][2] = s1 * d; + b = z2 * a - 0.235294118 * b; + a = b - 0.238390093 * a; + d = 272.365814381 * a; + out_shs[57] = c0 * d; + out_shs[53] = s0 * d; + d = 544.731628762 * a; + out_grads[57][0] = c1 * d; + out_grads[53][0] = s1 * d; + out_grads[57][1] = -s1 * d; + out_grads[53][1] = c1 * d; + d = -2830.508572514 * a; + out_grads[56][2] = c1 * d; + out_grads[54][2] = s1 * d; + b = z2 * a - 0.240601504 * b; + a = b - 0.242236025 * a; + d = 1121.509962433 * a; + out_shs[80] = c0 * d; + out_shs[76] = s0 * d; + d = 2243.019924866 * a; + out_grads[80][0] = c1 * d; + out_grads[76][0] = s1 * d; + out_grads[80][1] = -s1 * d; + out_grads[76][1] = c1 * d; + d = -13917.572624524 * a; + out_grads[79][2] = c1 * d; + out_grads[77][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; + d = -5.310392309 * z; + out_grads[13][0] = c0 * d; + out_grads[7][0] = s0 * d; + out_grads[13][1] = s0 * d; + out_grads[7][1] = c0 * d; + d = 6.62322287 * z; + out_grads[12][2] = c0 * d; + out_grads[8][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[24] = c1 * d; + out_shs[18] = s1 * d; + d = -30.399773564 * b; + out_grads[24][0] = c0 * d; + out_grads[18][0] = s0 * d; + out_grads[24][1] = s0 * d; + out_grads[18][1] = c0 * d; + d = 60.799547128 * b; + out_grads[23][2] = c0 * d; + out_grads[19][2] = s0 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[39] = c1 * d; + out_shs[33] = s1 * d; + d = -144.52614017 * b; + out_grads[39][0] = c0 * d; + out_grads[33][0] = s0 * d; + out_grads[39][1] = s0 * d; + out_grads[33][1] = c0 * d; + d = 391.378637737 * b; + out_grads[38][2] = c0 * d; + out_grads[34][2] = s0 * d; + a = z2 * b - 0.215686275 * a; + b = a - 0.222910217 * b; + d = -213.661323441 * b; + out_shs[58] = c1 * d; + out_shs[52] = s1 * d; + d = -640.983970322 * b; + out_grads[58][0] = c0 * d; + out_grads[52][0] = s0 * d; + out_grads[58][1] = s0 * d; + out_grads[52][1] = c0 * d; + d = 2178.926515046 * b; + out_grads[57][2] = c0 * d; + out_grads[53][2] = s0 * d; + a = z2 * b - 0.228070175 * a; + b = a - 0.231884058 * b; + d = -915.709049803 * b; + out_shs[81] = c1 * d; + out_shs[75] = s1 * d; + d = -2747.127149409 * b; + out_grads[81][0] = c0 * d; + out_grads[75][0] = s0 * d; + out_grads[81][1] = s0 * d; + out_grads[75][1] = c0 * d; + d = 11215.099624332 * b; + out_grads[80][2] = c0 * d; + out_grads[76][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; + d = 2.503342942; + out_grads[14][0] = c1 * d; + out_grads[6][0] = s1 * d; + out_grads[14][1] = -s1 * d; + out_grads[6][1] = c1 * d; + d = -1.77013077; + out_grads[13][2] = c1 * d; + out_grads[7][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[25] = c0 * d; + out_shs[17] = s0 * d; + d = 22.200855632 * a; + out_grads[25][0] = c1 * d; + out_grads[17][0] = s1 * d; + out_grads[25][1] = -s1 * d; + out_grads[17][1] = c1 * d; + d = -30.399773564 * a; + out_grads[24][2] = c1 * d; + out_grads[18][2] = s1 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[40] = c0 * d; + out_shs[32] = s0 * d; + d = 124.388296437 * a; + out_grads[40][0] = c1 * d; + out_grads[32][0] = s1 * d; + out_grads[40][1] = -s1 * d; + out_grads[32][1] = c1 * d; + d = -240.876900283 * a; + out_grads[39][2] = c1 * d; + out_grads[33][2] = s1 * d; + b = z2 * a - 0.188235294 * b; + a = b - 0.20123839 * a; + d = 151.081370682 * a; + out_shs[59] = c0 * d; + out_shs[51] = s0 * d; + d = 604.325482728 * a; + out_grads[59][0] = c1 * d; + out_grads[51][0] = s1 * d; + out_grads[59][1] = -s1 * d; + out_grads[51][1] = c1 * d; + d = -1495.629264084 * a; + out_grads[58][2] = c1 * d; + out_grads[52][2] = s1 * d; + b = z2 * a - 0.210526316 * b; + a = b - 0.217391304 * a; + d = 686.781787352 * a; + out_shs[82] = c0 * d; + out_shs[74] = s0 * d; + d = 2747.127149409 * a; + out_grads[82][0] = c1 * d; + out_grads[74][0] = s1 * d; + out_grads[82][1] = -s1 * d; + out_grads[74][1] = c1 * d; + d = -8241.381448228 * a; + out_grads[81][2] = -c1 * d; + out_grads[75][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[26] = c1 * d; + out_shs[16] = s1 * d; + d = -11.833095811 * z; + out_grads[26][0] = c0 * d; + out_grads[16][0] = s0 * d; + out_grads[26][1] = s0 * d; + out_grads[16][1] = c0 * d; + d = 11.100427816 * z; + out_grads[25][2] = c0 * d; + out_grads[17][2] = s0 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[41] = c1 * d; + out_shs[31] = s1 * d; + d = -86.247765552 * b; + out_grads[41][0] = c0 * d; + out_grads[31][0] = s0 * d; + out_grads[41][1] = s0 * d; + out_grads[31][1] = c0 * d; + d = 124.388296437 * b; + out_grads[40][2] = c0 * d; + out_grads[32][2] = s0 * d; + a = z2 * b - 0.152941176 * a; + b = a - 0.173374613 * b; + d = -95.552248675 * b; + out_shs[60] = c1 * d; + out_shs[50] = s1 * d; + d = -477.761243376 * b; + out_grads[60][0] = c0 * d; + out_grads[50][0] = s0 * d; + out_grads[60][1] = s0 * d; + out_grads[50][1] = c0 * d; + d = 906.488224092 * b; + out_grads[59][2] = c0 * d; + out_grads[51][2] = s0 * d; + a = z2 * b - 0.187969925 * a; + b = a - 0.198757764 * b; + d = -471.12841933 * b; + out_shs[83] = c1 * d; + out_shs[73] = s1 * d; + d = -2355.642096651 * b; + out_grads[83][0] = c0 * d; + out_grads[73][0] = s0 * d; + out_grads[83][1] = s0 * d; + out_grads[73][1] = c0 * d; + d = 5494.254298819 * b; + out_grads[82][2] = c0 * d; + out_grads[74][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[27] = c0 * d; + out_shs[15] = s0 * d; + d = 4.099104631; + out_grads[27][0] = c1 * d; + out_grads[15][0] = s1 * d; + out_grads[27][1] = -s1 * d; + out_grads[15][1] = c1 * d; + d = -2.366619162; + out_grads[26][2] = c1 * d; + out_grads[16][2] = s1 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[42] = c0 * d; + out_shs[30] = s0 * d; + d = 47.909948945 * a; + out_grads[42][0] = c1 * d; + out_grads[30][0] = s1 * d; + out_grads[42][1] = -s1 * d; + out_grads[30][1] = c1 * d; + d = -51.748659331 * a; + out_grads[41][2] = c1 * d; + out_grads[31][2] = s1 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + out_shs[61] = c0 * d; + out_shs[49] = s0 * d; + d = 320.491985161 * a; + out_grads[61][0] = c1 * d; + out_grads[49][0] = s1 * d; + out_grads[61][1] = -s1 * d; + out_grads[49][1] = c1 * d; + d = -477.761243376 * a; + out_grads[60][2] = c1 * d; + out_grads[50][2] = s1 * d; + b = z2 * a - 0.160401003 * b; + a = b - 0.175983437 * a; + d = 293.800188384 * a; + out_shs[84] = c0 * d; + out_shs[72] = s0 * d; + d = 1762.801130306 * a; + out_grads[84][0] = c1 * d; + out_grads[72][0] = s1 * d; + out_grads[84][1] = -s1 * d; + out_grads[72][1] = c1 * d; + d = -3297.898935312 * a; + out_grads[83][2] = c1 * d; + out_grads[73][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[43] = c1 * d; + out_shs[29] = s1 * d; + d = -20.409946485 * z; + out_grads[43][0] = c0 * d; + out_grads[29][0] = s0 * d; + out_grads[43][1] = s0 * d; + out_grads[29][1] = c0 * d; + d = 15.969982982 * z; + out_grads[42][2] = c0 * d; + out_grads[30][2] = s0 * d; + a = (z2 - 5.88235294e-02) * z; + b = a - 9.90712074e-02 * z; + d = -25.910241313 * b; + out_shs[62] = c1 * d; + out_shs[48] = s1 * d; + d = -181.371689194 * b; + out_grads[62][0] = c0 * d; + out_grads[48][0] = s0 * d; + out_grads[62][1] = s0 * d; + out_grads[48][1] = c0 * d; + d = 213.661323441 * b; + out_grads[61][2] = c0 * d; + out_grads[49][2] = s0 * d; + a = z2 * b - 0.127819549 * a; + b = a - 0.149068323 * b; + d = -165.101452729 * b; + out_shs[85] = c1 * d; + out_shs[71] = s1 * d; + d = -1155.7101691 * b; + out_grads[85][0] = c0 * d; + out_grads[71][0] = s0 * d; + out_grads[85][1] = s0 * d; + out_grads[71][1] = c0 * d; + d = 1762.801130306 * b; + out_grads[84][2] = c0 * d; + out_grads[72][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[44] = c0 * d; + out_shs[28] = s0 * d; + d = 5.831413281; + out_grads[44][0] = c1 * d; + out_grads[28][0] = s1 * d; + out_grads[44][1] = -s1 * d; + out_grads[28][1] = c1 * d; + d = -2.915706641; + out_grads[43][2] = c1 * d; + out_grads[29][2] = s1 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + out_shs[63] = c0 * d; + out_shs[47] = s0 * d; + d = 84.622493774 * a; + out_grads[63][0] = c1 * d; + out_grads[47][0] = s1 * d; + out_grads[63][1] = -s1 * d; + out_grads[47][1] = c1 * d; + d = -77.73072394 * a; + out_grads[62][2] = c1 * d; + out_grads[48][2] = s1 * d; + b = z2 * (a - 9.02255639e-02); + a = b - 0.118012422 * a; + d = 82.550726364 * a; + out_shs[86] = c0 * d; + out_shs[70] = s0 * d; + d = 660.405810914 * a; + out_grads[86][0] = c1 * d; + out_grads[70][0] = s1 * d; + out_grads[86][1] = -s1 * d; + out_grads[70][1] = c1 * d; + d = -825.507263643 * a; + out_grads[85][2] = c1 * d; + out_grads[71][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + out_shs[64] = c1 * d; + out_shs[46] = s1 * d; + d = -30.887057699 * z; + out_grads[64][0] = c0 * d; + out_grads[46][0] = s0 * d; + out_grads[64][1] = s0 * d; + out_grads[46][1] = c0 * d; + d = 21.155623443 * z; + out_grads[63][2] = c0 * d; + out_grads[47][2] = s0 * d; + a = (z2 - 4.76190476e-02) * z; + b = a - 8.2815735e-02 * z; + d = -36.028090689 * b; + out_shs[87] = c1 * d; + out_shs[69] = s1 * d; + d = -324.252816204 * b; + out_grads[87][0] = c0 * d; + out_grads[69][0] = s0 * d; + out_grads[87][1] = s0 * d; + out_grads[69][1] = c0 * d; + d = 330.202905457 * b; + out_grads[86][2] = c0 * d; + out_grads[70][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + out_shs[65] = c0 * d; + out_shs[45] = s0 * d; + d = 7.673951182; + out_grads[65][0] = c1 * d; + out_grads[45][0] = s1 * d; + out_grads[65][1] = -s1 * d; + out_grads[45][1] = c1 * d; + d = -3.4318953; + out_grads[64][2] = c1 * d; + out_grads[46][2] = s1 * d; + a = z2 - 4.34782609e-02; + d = 13.3042542 * a; + out_shs[88] = c0 * d; + out_shs[68] = s0 * d; + d = 133.042542003 * a; + out_grads[88][0] = c1 * d; + out_grads[68][0] = s1 * d; + out_grads[88][1] = -s1 * d; + out_grads[68][1] = c1 * d; + d = -108.084272068 * a; + out_grads[87][2] = c1 * d; + out_grads[69][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.923210529 * z; + out_shs[89] = c1 * d; + out_shs[67] = s1 * d; + d = -43.155315818 * z; + out_grads[89][0] = c0 * d; + out_grads[67][0] = s0 * d; + out_grads[89][1] = s0 * d; + out_grads[67][1] = c0 * d; + d = 26.608508401 * z; + out_grads[88][2] = c0 * d; + out_grads[68][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.800821996; + out_shs[90] = c0 * d; + out_shs[66] = s0 * d; + d = 9.609863949; + out_grads[90][0] = c1 * d; + out_grads[66][0] = s1 * d; + out_grads[90][1] = -s1 * d; + out_grads[66][1] = c1 * d; + d = -3.923210529; + out_grads[89][2] = c1 * d; + out_grads[67][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; + out_grads[6][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[14][2] = 0.0; + out_grads[15][2] = 0.0; + out_grads[21][0] = 0.0; + out_grads[21][1] = 0.0; + out_grads[27][2] = 0.0; + out_grads[28][2] = 0.0; + out_grads[36][0] = 0.0; + out_grads[36][1] = 0.0; + out_grads[44][2] = 0.0; + out_grads[45][2] = 0.0; + out_grads[55][0] = 0.0; + out_grads[55][1] = 0.0; + out_grads[65][2] = 0.0; + out_grads[66][2] = 0.0; + out_grads[78][0] = 0.0; + out_grads[78][1] = 0.0; + out_grads[90][2] = 0.0; +} diff --git a/fury/shaders/ray_traced/odf/tournier/eval_sh_grad_2.frag b/fury/shaders/ray_traced/odf/tournier/eval_sh_grad_2.frag new file mode 100644 index 000000000..277a0e07a --- /dev/null +++ b/fury/shaders/ray_traced/odf/tournier/eval_sh_grad_2.frag @@ -0,0 +1,46 @@ +void eval_sh_grad_2(out float out_shs[6], out vec3 out_grads[6], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + out_grads[4][0] = c0 * d; + out_grads[2][0] = s0 * d; + out_grads[4][1] = s0 * d; + out_grads[2][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + d = 1.092548431; + out_grads[1][0] = c1 * d; + out_grads[5][0] = s1 * d; + out_grads[5][1] = -s1 * d; + out_grads[1][1] = c1 * d; + d = -1.092548431; + out_grads[4][2] = c1 * d; + out_grads[2][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[5][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[1][2] = 0.0; +} diff --git a/fury/shaders/ray_traced/odf/tournier/eval_sh_grad_4.frag b/fury/shaders/ray_traced/odf/tournier/eval_sh_grad_4.frag new file mode 100644 index 000000000..c85847a5b --- /dev/null +++ b/fury/shaders/ray_traced/odf/tournier/eval_sh_grad_4.frag @@ -0,0 +1,103 @@ +void eval_sh_grad_4(out float out_shs[15], out vec3 out_grads[15], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + out_grads[4][0] = c0 * d; + out_grads[2][0] = s0 * d; + out_grads[4][1] = s0 * d; + out_grads[2][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + out_grads[11][0] = c0 * d; + out_grads[9][0] = s0 * d; + out_grads[11][1] = s0 * d; + out_grads[9][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + d = 1.092548431; + out_grads[5][0] = c1 * d; + out_grads[1][0] = s1 * d; + out_grads[5][1] = -s1 * d; + out_grads[1][1] = c1 * d; + d = -1.092548431; + out_grads[4][2] = c1 * d; + out_grads[2][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + d = 6.62322287 * a; + out_grads[12][0] = c1 * d; + out_grads[8][0] = s1 * d; + out_grads[12][1] = -s1 * d; + out_grads[8][1] = c1 * d; + d = -14.049977415 * a; + out_grads[11][2] = c1 * d; + out_grads[9][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; + d = -5.310392309 * z; + out_grads[13][0] = c0 * d; + out_grads[7][0] = s0 * d; + out_grads[13][1] = s0 * d; + out_grads[7][1] = c0 * d; + d = 6.62322287 * z; + out_grads[12][2] = c0 * d; + out_grads[8][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; + d = 2.503342942; + out_grads[14][0] = c1 * d; + out_grads[6][0] = s1 * d; + out_grads[14][1] = -s1 * d; + out_grads[6][1] = c1 * d; + d = -1.77013077; + out_grads[13][2] = c1 * d; + out_grads[7][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[5][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[1][2] = 0.0; + out_grads[14][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[6][2] = 0.0; +} diff --git a/fury/shaders/ray_traced/odf/tournier/eval_sh_grad_6.frag b/fury/shaders/ray_traced/odf/tournier/eval_sh_grad_6.frag new file mode 100644 index 000000000..617413bc9 --- /dev/null +++ b/fury/shaders/ray_traced/odf/tournier/eval_sh_grad_6.frag @@ -0,0 +1,186 @@ +void eval_sh_grad_6(out float out_shs[28], out vec3 out_grads[28], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + out_grads[4][0] = c0 * d; + out_grads[2][0] = s0 * d; + out_grads[4][1] = s0 * d; + out_grads[2][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + out_grads[11][0] = c0 * d; + out_grads[9][0] = s0 * d; + out_grads[11][1] = s0 * d; + out_grads[9][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[22] = c1 * d; + out_shs[20] = s1 * d; + out_grads[22][0] = c0 * d; + out_grads[20][0] = s0 * d; + out_grads[22][1] = s0 * d; + out_grads[20][1] = c0 * d; + d = 88.106914343 * b; + out_grads[21][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + d = 1.092548431; + out_grads[5][0] = c1 * d; + out_grads[1][0] = s1 * d; + out_grads[5][1] = -s1 * d; + out_grads[1][1] = c1 * d; + d = -1.092548431; + out_grads[4][2] = c1 * d; + out_grads[2][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + d = 6.62322287 * a; + out_grads[12][0] = c1 * d; + out_grads[8][0] = s1 * d; + out_grads[12][1] = -s1 * d; + out_grads[8][1] = c1 * d; + d = -14.049977415 * a; + out_grads[11][2] = c1 * d; + out_grads[9][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[23] = c0 * d; + out_shs[19] = s0 * d; + d = 30.399773564 * a; + out_grads[23][0] = c1 * d; + out_grads[19][0] = s1 * d; + out_grads[23][1] = -s1 * d; + out_grads[19][1] = c1 * d; + d = -96.132524816 * a; + out_grads[22][2] = c1 * d; + out_grads[20][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; + d = -5.310392309 * z; + out_grads[13][0] = c0 * d; + out_grads[7][0] = s0 * d; + out_grads[13][1] = s0 * d; + out_grads[7][1] = c0 * d; + d = 6.62322287 * z; + out_grads[12][2] = c0 * d; + out_grads[8][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[24] = c1 * d; + out_shs[18] = s1 * d; + d = -30.399773564 * b; + out_grads[24][0] = c0 * d; + out_grads[18][0] = s0 * d; + out_grads[24][1] = s0 * d; + out_grads[18][1] = c0 * d; + d = 60.799547128 * b; + out_grads[23][2] = c0 * d; + out_grads[19][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; + d = 2.503342942; + out_grads[14][0] = c1 * d; + out_grads[6][0] = s1 * d; + out_grads[14][1] = -s1 * d; + out_grads[6][1] = c1 * d; + d = -1.77013077; + out_grads[13][2] = c1 * d; + out_grads[7][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[25] = c0 * d; + out_shs[17] = s0 * d; + d = 22.200855632 * a; + out_grads[25][0] = c1 * d; + out_grads[17][0] = s1 * d; + out_grads[25][1] = -s1 * d; + out_grads[17][1] = c1 * d; + d = -30.399773564 * a; + out_grads[24][2] = c1 * d; + out_grads[18][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[26] = c1 * d; + out_shs[16] = s1 * d; + d = -11.833095811 * z; + out_grads[26][0] = c0 * d; + out_grads[16][0] = s0 * d; + out_grads[26][1] = s0 * d; + out_grads[16][1] = c0 * d; + d = 11.100427816 * z; + out_grads[25][2] = c0 * d; + out_grads[17][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[27] = c0 * d; + out_shs[15] = s0 * d; + d = 4.099104631; + out_grads[27][0] = c1 * d; + out_grads[15][0] = s1 * d; + out_grads[27][1] = -s1 * d; + out_grads[15][1] = c1 * d; + d = -2.366619162; + out_grads[26][2] = c1 * d; + out_grads[16][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[5][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[1][2] = 0.0; + out_grads[14][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[6][2] = 0.0; + out_grads[27][2] = 0.0; + out_grads[21][0] = 0.0; + out_grads[21][1] = 0.0; + out_grads[15][2] = 0.0; +} diff --git a/fury/shaders/ray_traced/odf/tournier/eval_sh_grad_8.frag b/fury/shaders/ray_traced/odf/tournier/eval_sh_grad_8.frag new file mode 100644 index 000000000..712b2dc29 --- /dev/null +++ b/fury/shaders/ray_traced/odf/tournier/eval_sh_grad_8.frag @@ -0,0 +1,295 @@ +void eval_sh_grad_8(out float out_shs[45], out vec3 out_grads[45], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + out_grads[4][0] = c0 * d; + out_grads[2][0] = s0 * d; + out_grads[4][1] = s0 * d; + out_grads[2][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + out_grads[11][0] = c0 * d; + out_grads[9][0] = s0 * d; + out_grads[11][1] = s0 * d; + out_grads[9][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[22] = c1 * d; + out_shs[20] = s1 * d; + out_grads[22][0] = c0 * d; + out_grads[20][0] = s0 * d; + out_grads[22][1] = s0 * d; + out_grads[20][1] = c0 * d; + d = 88.106914343 * b; + out_grads[21][2] = d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[37] = c1 * d; + out_shs[35] = s1 * d; + out_grads[37][0] = c0 * d; + out_grads[35][0] = s0 * d; + out_grads[37][1] = s0 * d; + out_grads[35][1] = c0 * d; + d = 467.786944906 * b; + out_grads[36][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + d = 1.092548431; + out_grads[5][0] = c1 * d; + out_grads[1][0] = s1 * d; + out_grads[5][1] = -s1 * d; + out_grads[1][1] = c1 * d; + d = -1.092548431; + out_grads[4][2] = c1 * d; + out_grads[2][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + d = 6.62322287 * a; + out_grads[12][0] = c1 * d; + out_grads[8][0] = s1 * d; + out_grads[12][1] = -s1 * d; + out_grads[8][1] = c1 * d; + d = -14.049977415 * a; + out_grads[11][2] = c1 * d; + out_grads[9][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[23] = c0 * d; + out_shs[19] = s0 * d; + d = 30.399773564 * a; + out_grads[23][0] = c1 * d; + out_grads[19][0] = s1 * d; + out_grads[23][1] = -s1 * d; + out_grads[19][1] = c1 * d; + d = -96.132524816 * a; + out_grads[22][2] = c1 * d; + out_grads[20][2] = s1 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[38] = c0 * d; + out_shs[34] = s0 * d; + d = 130.459545912 * a; + out_grads[38][0] = c1 * d; + out_grads[34][0] = s1 * d; + out_grads[38][1] = -s1 * d; + out_grads[34][1] = c1 * d; + d = -545.751435723 * a; + out_grads[37][2] = c1 * d; + out_grads[35][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; + d = -5.310392309 * z; + out_grads[13][0] = c0 * d; + out_grads[7][0] = s0 * d; + out_grads[13][1] = s0 * d; + out_grads[7][1] = c0 * d; + d = 6.62322287 * z; + out_grads[12][2] = c0 * d; + out_grads[8][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[24] = c1 * d; + out_shs[18] = s1 * d; + d = -30.399773564 * b; + out_grads[24][0] = c0 * d; + out_grads[18][0] = s0 * d; + out_grads[24][1] = s0 * d; + out_grads[18][1] = c0 * d; + d = 60.799547128 * b; + out_grads[23][2] = c0 * d; + out_grads[19][2] = s0 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[39] = c1 * d; + out_shs[33] = s1 * d; + d = -144.52614017 * b; + out_grads[39][0] = c0 * d; + out_grads[33][0] = s0 * d; + out_grads[39][1] = s0 * d; + out_grads[33][1] = c0 * d; + d = 391.378637737 * b; + out_grads[38][2] = c0 * d; + out_grads[34][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; + d = 2.503342942; + out_grads[14][0] = c1 * d; + out_grads[6][0] = s1 * d; + out_grads[14][1] = -s1 * d; + out_grads[6][1] = c1 * d; + d = -1.77013077; + out_grads[13][2] = c1 * d; + out_grads[7][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[25] = c0 * d; + out_shs[17] = s0 * d; + d = 22.200855632 * a; + out_grads[25][0] = c1 * d; + out_grads[17][0] = s1 * d; + out_grads[25][1] = -s1 * d; + out_grads[17][1] = c1 * d; + d = -30.399773564 * a; + out_grads[24][2] = c1 * d; + out_grads[18][2] = s1 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[40] = c0 * d; + out_shs[32] = s0 * d; + d = 124.388296437 * a; + out_grads[40][0] = c1 * d; + out_grads[32][0] = s1 * d; + out_grads[40][1] = -s1 * d; + out_grads[32][1] = c1 * d; + d = -240.876900283 * a; + out_grads[39][2] = c1 * d; + out_grads[33][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[26] = c1 * d; + out_shs[16] = s1 * d; + d = -11.833095811 * z; + out_grads[26][0] = c0 * d; + out_grads[16][0] = s0 * d; + out_grads[26][1] = s0 * d; + out_grads[16][1] = c0 * d; + d = 11.100427816 * z; + out_grads[25][2] = c0 * d; + out_grads[17][2] = s0 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[41] = c1 * d; + out_shs[31] = s1 * d; + d = -86.247765552 * b; + out_grads[41][0] = c0 * d; + out_grads[31][0] = s0 * d; + out_grads[41][1] = s0 * d; + out_grads[31][1] = c0 * d; + d = 124.388296437 * b; + out_grads[40][2] = c0 * d; + out_grads[32][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[27] = c0 * d; + out_shs[15] = s0 * d; + d = 4.099104631; + out_grads[27][0] = c1 * d; + out_grads[15][0] = s1 * d; + out_grads[27][1] = -s1 * d; + out_grads[15][1] = c1 * d; + d = -2.366619162; + out_grads[26][2] = c1 * d; + out_grads[16][2] = s1 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[42] = c0 * d; + out_shs[30] = s0 * d; + d = 47.909948945 * a; + out_grads[42][0] = c1 * d; + out_grads[30][0] = s1 * d; + out_grads[42][1] = -s1 * d; + out_grads[30][1] = c1 * d; + d = -51.748659331 * a; + out_grads[41][2] = c1 * d; + out_grads[31][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[43] = c1 * d; + out_shs[29] = s1 * d; + d = -20.409946485 * z; + out_grads[43][0] = c0 * d; + out_grads[29][0] = s0 * d; + out_grads[43][1] = s0 * d; + out_grads[29][1] = c0 * d; + d = 15.969982982 * z; + out_grads[42][2] = c0 * d; + out_grads[30][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[44] = c0 * d; + out_shs[28] = s0 * d; + d = 5.831413281; + out_grads[44][0] = c1 * d; + out_grads[28][0] = s1 * d; + out_grads[44][1] = -s1 * d; + out_grads[28][1] = c1 * d; + d = -2.915706641; + out_grads[43][2] = c1 * d; + out_grads[29][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[5][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[1][2] = 0.0; + out_grads[14][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[6][2] = 0.0; + out_grads[27][2] = 0.0; + out_grads[21][0] = 0.0; + out_grads[21][1] = 0.0; + out_grads[15][2] = 0.0; + out_grads[44][2] = 0.0; + out_grads[36][0] = 0.0; + out_grads[36][1] = 0.0; + out_grads[28][2] = 0.0; +} From 86c761359aa0d70b8a693fcd9d8be8ddd98a2924 Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Fri, 7 Jun 2024 11:03:25 -0400 Subject: [PATCH 086/118] Refactored getInvVandermonde function. --- .../SH-ODF_experimental/ray_traced_6.5.py | 2 +- .../ray_traced/odf/get_inv_vandermonde.frag | 93 +++++++++++++++++++ .../odf/ray_glyph_intersections.frag | 2 +- 3 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 fury/shaders/ray_traced/odf/get_inv_vandermonde.frag diff --git a/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py b/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py index 83d6f23e0..92f33b7f6 100644 --- a/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py +++ b/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py @@ -329,7 +329,7 @@ def uv_calculations(n): # Outputs a matrix that turns equidistant samples on the unit circle of a # homogeneous polynomial into coefficients of that polynomial. get_inv_vandermonde = import_fury_shader( - os.path.join("rt_odfs", "get_inv_vandermonde.frag") + os.path.join("ray_traced", "odf", "get_inv_vandermonde.frag") ) # Determines all intersections between a ray and a spherical harmonics diff --git a/fury/shaders/ray_traced/odf/get_inv_vandermonde.frag b/fury/shaders/ray_traced/odf/get_inv_vandermonde.frag new file mode 100644 index 000000000..988cd5783 --- /dev/null +++ b/fury/shaders/ray_traced/odf/get_inv_vandermonde.frag @@ -0,0 +1,93 @@ +void getInvVandermonde(out float v[(SH_DEGREE + 1) * (SH_DEGREE + 1)], int shDegree) +{ + if (shDegree == 2) + { + float tmpV[9]; + tmpV[0*3 + 0] = -0.3333333333; tmpV[0*3 + 1] = 0.6666666667; tmpV[0*3 + 2] = 0.6666666667; + tmpV[1*3 + 0] = -0.0; tmpV[1*3 + 1] = 1.1547005384; tmpV[1*3 + 2] = -1.1547005384; + tmpV[2*3 + 0] = 1.0; tmpV[2*3 + 1] = 0.0; tmpV[2*3 + 2] = 0.0; + int tmpVLength = (shDegree + 1) * (shDegree + 1); + for (int i = 0; i != tmpVLength; ++i) + v[i] = tmpV[i]; + } + else if (shDegree == 4) + { + float tmpV[25]; + tmpV[0*5 + 0] = 0.2; tmpV[0*5 + 1] = -0.2472135955; tmpV[0*5 + 2] = 0.6472135955; tmpV[0*5 + 3] = 0.6472135955; tmpV[0*5 + 4] = -0.2472135955; + tmpV[1*5 + 0] = 0.0; tmpV[1*5 + 1] = -0.1796111906; tmpV[1*5 + 2] = 1.9919186279; tmpV[1*5 + 3] = -1.9919186279; tmpV[1*5 + 4] = 0.1796111906; + tmpV[2*5 + 0] = -2.0; tmpV[2*5 + 1] = 2.3416407865; tmpV[2*5 + 2] = -0.3416407865; tmpV[2*5 + 3] = -0.3416407865; tmpV[2*5 + 4] = 2.3416407865; + tmpV[3*5 + 0] = -0.0; tmpV[3*5 + 1] = 1.7013016167; tmpV[3*5 + 2] = -1.0514622242; tmpV[3*5 + 3] = 1.0514622242; tmpV[3*5 + 4] = -1.7013016167; + tmpV[4*5 + 0] = 1.0; tmpV[4*5 + 1] = 0.0; tmpV[4*5 + 2] = 0.0; tmpV[4*5 + 3] = 0.0; tmpV[4*5 + 4] = 0.0; + int tmpVLength = (shDegree + 1) * (shDegree + 1); + for (int i = 0; i != tmpVLength; ++i) + v[i] = tmpV[i]; + } + else if (shDegree == 6) + { + float tmpV[49]; + tmpV[0*7 + 0] = -0.1428571429; tmpV[0*7 + 1] = 0.1585594663; tmpV[0*7 + 2] = -0.2291250674; tmpV[0*7 + 3] = 0.6419941725; tmpV[0*7 + 4] = 0.6419941725; tmpV[0*7 + 5] = -0.2291250674; tmpV[0*7 + 6] = 0.1585594663; + tmpV[1*7 + 0] = -0.0; tmpV[1*7 + 1] = 0.0763582145; tmpV[1*7 + 2] = -0.2873137468; tmpV[1*7 + 3] = 2.8127602518; tmpV[1*7 + 4] = -2.8127602518; tmpV[1*7 + 5] = 0.2873137468; tmpV[1*7 + 6] = -0.0763582145; + tmpV[2*7 + 0] = 3.0; tmpV[2*7 + 1] = -3.2929766145; tmpV[2*7 + 2] = 4.4513463718; tmpV[2*7 + 3] = -1.1583697574; tmpV[2*7 + 4] = -1.1583697574; tmpV[2*7 + 5] = 4.4513463718; tmpV[2*7 + 6] = -3.2929766145; + tmpV[3*7 + 0] = 0.0; tmpV[3*7 + 1] = -1.5858139579; tmpV[3*7 + 2] = 5.5818117995; tmpV[3*7 + 3] = -5.0751495106; tmpV[3*7 + 4] = 5.0751495106; tmpV[3*7 + 5] = -5.5818117995; tmpV[3*7 + 6] = 1.5858139579; + tmpV[4*7 + 0] = -5.0; tmpV[4*7 + 1] = 4.7858935686; tmpV[4*7 + 2] = -1.0200067492; tmpV[4*7 + 3] = 0.2341131806; tmpV[4*7 + 4] = 0.2341131806; tmpV[4*7 + 5] = -1.0200067492; tmpV[4*7 + 6] = 4.7858935686; + tmpV[5*7 + 0] = -0.0; tmpV[5*7 + 1] = 2.3047648710; tmpV[5*7 + 2] = -1.2790480077; tmpV[5*7 + 3] = 1.0257168633; tmpV[5*7 + 4] = -1.0257168633; tmpV[5*7 + 5] = 1.2790480077; tmpV[5*7 + 6] = -2.3047648710; + tmpV[6*7 + 0] = 1.0; tmpV[6*7 + 1] = 0.0; tmpV[6*7 + 2] = 0.0; tmpV[6*7 + 3] = 0.0; tmpV[6*7 + 4] = 0.0; tmpV[6*7 + 5] = 0.0; tmpV[6*7 + 6] = 0.0; + int tmpVLength = (shDegree + 1) * (shDegree + 1); + for (int i = 0; i != tmpVLength; ++i) + v[i] = tmpV[i]; + } + else if (shDegree == 8) + { + float tmpV[81]; + tmpV[0*9 + 0] = 0.1111111111; tmpV[0*9 + 1] = -0.1182419747; tmpV[0*9 + 2] = 0.1450452544; tmpV[0*9 + 3] = -0.2222222222; tmpV[0*9 + 4] = 0.6398633870; tmpV[0*9 + 5] = 0.6398633870; tmpV[0*9 + 6] = -0.2222222222; tmpV[0*9 + 7] = 0.1450452544; tmpV[0*9 + 8] = -0.1182419747; + tmpV[1*9 + 0] = 0.0; tmpV[1*9 + 1] = -0.0430365592; tmpV[1*9 + 2] = 0.1217074194; tmpV[1*9 + 3] = -0.3849001795; tmpV[1*9 + 4] = 3.6288455938; tmpV[1*9 + 5] = -3.6288455938; tmpV[1*9 + 6] = 0.3849001795; tmpV[1*9 + 7] = -0.1217074194; tmpV[1*9 + 8] = 0.0430365592; + tmpV[2*9 + 0] = -4.0; tmpV[2*9 + 1] = 4.2410470634; tmpV[2*9 + 2] = -5.1195045066; tmpV[2*9 + 3] = 7.3333333333; tmpV[2*9 + 4] = -2.4548758901; tmpV[2*9 + 5] = -2.4548758901; tmpV[2*9 + 6] = 7.3333333333; tmpV[2*9 + 7] = -5.1195045066; tmpV[2*9 + 8] = 4.2410470634; + tmpV[3*9 + 0] = -0.0; tmpV[3*9 + 1] = 1.5436148932; tmpV[3*9 + 2] = -4.2957743433; tmpV[3*9 + 3] = 12.7017059222; tmpV[3*9 + 4] = -13.9222930051; tmpV[3*9 + 5] = 13.9222930051; tmpV[3*9 + 6] = -12.7017059222; tmpV[3*9 + 7] = 4.2957743433; tmpV[3*9 + 8] = -1.5436148932; + tmpV[4*9 + 0] = 14.0; tmpV[4*9 + 1] = -14.3366589404; tmpV[4*9 + 2] = 14.6711193836; tmpV[4*9 + 3] = -6.0; tmpV[4*9 + 4] = 1.6655395568; tmpV[4*9 + 5] = 1.6655395568; tmpV[4*9 + 6] = -6.0; tmpV[4*9 + 7] = 14.6711193836; tmpV[4*9 + 8] = -14.3366589404; + tmpV[5*9 + 0] = 0.0; tmpV[5*9 + 1] = -5.2181171131; tmpV[5*9 + 2] = 12.3105308637; tmpV[5*9 + 3] = -10.3923048454; tmpV[5*9 + 4] = 9.4457442082; tmpV[5*9 + 5] = -9.4457442082; tmpV[5*9 + 6] = 10.3923048454; tmpV[5*9 + 7] = -12.3105308637; tmpV[5*9 + 8] = 5.2181171131; + tmpV[6*9 + 0] = -9.3333333333; tmpV[6*9 + 1] = 8.0330865684; tmpV[6*9 + 2] = -1.8540394597; tmpV[6*9 + 3] = 0.6666666667; tmpV[6*9 + 4] = -0.1790471086; tmpV[6*9 + 5] = -0.1790471086; tmpV[6*9 + 6] = 0.6666666667; tmpV[6*9 + 7] = -1.8540394597; tmpV[6*9 + 8] = 8.0330865684; + tmpV[7*9 + 0] = -0.0; tmpV[7*9 + 1] = 2.9238044002; tmpV[7*9 + 2] = -1.5557238269; tmpV[7*9 + 3] = 1.1547005384; tmpV[7*9 + 4] = -1.0154266119; tmpV[7*9 + 5] = 1.0154266119; tmpV[7*9 + 6] = -1.1547005384; tmpV[7*9 + 7] = 1.5557238269; tmpV[7*9 + 8] = -2.9238044002; + tmpV[8*9 + 0] = 1.0; tmpV[8*9 + 1] = 0.0; tmpV[8*9 + 2] = 0.0; tmpV[8*9 + 3] = 0.0; tmpV[8*9 + 4] = 0.0; tmpV[8*9 + 5] = 0.0; tmpV[8*9 + 6] = 0.0; tmpV[8*9 + 7] = 0.0; tmpV[8*9 + 8] = 0.0; + int tmpVLength = (shDegree + 1) * (shDegree + 1); + for (int i = 0; i != tmpVLength; ++i) + v[i] = tmpV[i]; + } + else if (shDegree == 10) + { + float tmpV[121]; + tmpV[0*11 + 0] = -0.0909090909; tmpV[0*11 + 1] = 0.0947470106; tmpV[0*11 + 2] = -0.1080638444; tmpV[0*11 + 3] = 0.1388220215; tmpV[0*11 + 4] = -0.2188392043; tmpV[0*11 + 5] = 0.6387885621; tmpV[0*11 + 6] = 0.6387885621; tmpV[0*11 + 7] = -0.2188392043; tmpV[0*11 + 8] = 0.1388220215; tmpV[0*11 + 9] = -0.1080638444; tmpV[0*11 + 10] = 0.0947470106; + tmpV[1*11 + 0] = -0.0; tmpV[1*11 + 1] = 0.0278202324; tmpV[1*11 + 2] = -0.0694484159; tmpV[1*11 + 3] = 0.1602091533; tmpV[1*11 + 4] = -0.4791910159; tmpV[1*11 + 5] = 4.4428720384; tmpV[1*11 + 6] = -4.4428720384; tmpV[1*11 + 7] = 0.4791910159; tmpV[1*11 + 8] = -0.1602091533; tmpV[1*11 + 9] = 0.0694484159; tmpV[1*11 + 10] = -0.0278202324; + tmpV[2*11 + 0] = 5.0; tmpV[2*11 + 1] = -5.2029168239; tmpV[2*11 + 2] = 5.8988796576; tmpV[2*11 + 3] = -7.4503199653; tmpV[2*11 + 4] = 10.9868742757; tmpV[2*11 + 5] = -4.2325171441; tmpV[2*11 + 6] = -4.2325171441; tmpV[2*11 + 7] = 10.9868742757; tmpV[2*11 + 8] = -7.4503199653; tmpV[2*11 + 9] = 5.8988796576; tmpV[2*11 + 10] = -5.2029168239; + tmpV[3*11 + 0] = 0.0; tmpV[3*11 + 1] = -1.5277142200; tmpV[3*11 + 2] = 3.7909797649; tmpV[3*11 + 3] = -8.5981275876; tmpV[3*11 + 4] = 24.0578988657; tmpV[3*11 + 5] = -29.4378033460; tmpV[3*11 + 6] = 29.4378033460; tmpV[3*11 + 7] = -24.0578988657; tmpV[3*11 + 8] = 8.5981275876; tmpV[3*11 + 9] = -3.7909797649; tmpV[3*11 + 10] = 1.5277142200; + tmpV[4*11 + 0] = -30.0; tmpV[4*11 + 1] = 30.8179361182; tmpV[4*11 + 2] = -33.2247539061; tmpV[4*11 + 3] = 35.8884989085; tmpV[4*11 + 4] = -19.5374870834; tmpV[4*11 + 5] = 6.0558059629; tmpV[4*11 + 6] = 6.0558059629; tmpV[4*11 + 7] = -19.5374870834; tmpV[4*11 + 8] = 35.8884989085; tmpV[4*11 + 9] = -33.2247539061; tmpV[4*11 + 10] = 30.8179361182; + tmpV[5*11 + 0] = -0.0; tmpV[5*11 + 1] = 9.0489625020; tmpV[5*11 + 2] = -21.3522528115; tmpV[5*11 + 3] = 41.4175356200; tmpV[5*11 + 4] = -42.7811292411; tmpV[5*11 + 5] = 42.1190556280; tmpV[5*11 + 6] = -42.1190556280; tmpV[5*11 + 7] = 42.7811292411; tmpV[5*11 + 8] = -41.4175356200; tmpV[5*11 + 9] = 21.3522528115; tmpV[5*11 + 10] = -9.0489625020; + tmpV[6*11 + 0] = 42.0; tmpV[6*11 + 1] = -41.1161037573; tmpV[6*11 + 2] = 36.2032364762; tmpV[6*11 + 3] = -16.3373898141; tmpV[6*11 + 4] = 7.4261062994; tmpV[6*11 + 5] = -2.1758492042; tmpV[6*11 + 6] = -2.1758492042; tmpV[6*11 + 7] = 7.4261062994; tmpV[6*11 + 8] = -16.3373898141; tmpV[6*11 + 9] = 36.2032364762; tmpV[6*11 + 10] = -41.1161037573; + tmpV[7*11 + 0] = 0.0; tmpV[7*11 + 1] = -12.0727773496; tmpV[7*11 + 2] = 23.2664073304; tmpV[7*11 + 3] = -18.8543529304; tmpV[7*11 + 4] = 16.2609045881; tmpV[7*11 + 5] = -15.1333636234; tmpV[7*11 + 6] = 15.1333636234; tmpV[7*11 + 7] = -16.2609045881; tmpV[7*11 + 8] = 18.8543529304; tmpV[7*11 + 9] = -23.2664073304; tmpV[7*11 + 10] = 12.0727773496; + tmpV[8*11 + 0] = -15.0; tmpV[8*11 + 1] = 12.0883694702; tmpV[8*11 + 2] = -2.8781222629; tmpV[8*11 + 3] = 1.1465503415; tmpV[8*11 + 4] = -0.5020543475; tmpV[8*11 + 5] = 0.1452567988; tmpV[8*11 + 6] = 0.1452567988; tmpV[8*11 + 7] = -0.5020543475; tmpV[8*11 + 8] = 1.1465503415; tmpV[8*11 + 9] = -2.8781222629; tmpV[8*11 + 10] = 12.0883694702; + tmpV[9*11 + 0] = -0.0; tmpV[9*11 + 1] = 3.5494655329; tmpV[9*11 + 2] = -1.8496568659; tmpV[9*11 + 3] = 1.3231896304; tmpV[9*11 + 4] = -1.0993456751; tmpV[9*11 + 5] = 1.0102832265; tmpV[9*11 + 6] = -1.0102832265; tmpV[9*11 + 7] = 1.0993456751; tmpV[9*11 + 8] = -1.3231896304; tmpV[9*11 + 9] = 1.8496568659; tmpV[9*11 + 10] = -3.5494655329; + tmpV[10*11 + 0] = 1.0; tmpV[10*11 + 1] = 0.0; tmpV[10*11 + 2] = 0.0; tmpV[10*11 + 3] = 0.0; tmpV[10*11 + 4] = 0.0; tmpV[10*11 + 5] = 0.0; tmpV[10*11 + 6] = 0.0; tmpV[10*11 + 7] = 0.0; tmpV[10*11 + 8] = 0.0; tmpV[10*11 + 9] = 0.0; tmpV[10*11 + 10] = 0.0; + int tmpVLength = (shDegree + 1) * (shDegree + 1); + for (int i = 0; i != tmpVLength; ++i) + v[i] = tmpV[i]; + } + else if (shDegree == 12) + { + float tmpV[169]; + tmpV[0*13 + 0] = 0.0769230769; tmpV[0*13 + 1] = -0.0792252178; tmpV[0*13 + 2] = 0.0868739663; tmpV[0*13 + 3] = -0.1027681661; tmpV[0*13 + 4] = 0.1354125166; tmpV[0*13 + 5] = -0.2169261613; tmpV[0*13 + 6] = 0.6381715239; tmpV[0*13 + 7] = 0.6381715239; tmpV[0*13 + 8] = -0.2169261613; tmpV[0*13 + 9] = 0.1354125166; tmpV[0*13 + 10] = -0.1027681661; tmpV[0*13 + 11] = 0.0868739663; tmpV[0*13 + 12] = -0.0792252178; + tmpV[1*13 + 0] = -0.0; tmpV[1*13 + 1] = -0.0195272624; tmpV[1*13 + 2] = 0.0455949748; tmpV[1*13 + 3] = -0.0910446506; tmpV[1*13 + 4] = 0.1961788986; tmpV[1*13 + 5] = -0.5719872785; tmpV[1*13 + 6] = 5.2558153553; tmpV[1*13 + 7] = -5.2558153553; tmpV[1*13 + 8] = 0.5719872785; tmpV[1*13 + 9] = -0.1961788986; tmpV[1*13 + 10] = 0.0910446506; tmpV[1*13 + 11] = -0.0455949748; tmpV[1*13 + 12] = 0.0195272624; + tmpV[2*13 + 0] = -6.0; tmpV[2*13 + 1] = 6.1747539478; tmpV[2*13 + 2] = -6.7522392818; tmpV[2*13 + 3] = 7.9352584366; tmpV[2*13 + 4] = -10.2779620900; tmpV[2*13 + 5] = 15.4120340799; tmpV[2*13 + 6] = -6.4918450925; tmpV[2*13 + 7] = -6.4918450925; tmpV[2*13 + 8] = 15.4120340799; tmpV[2*13 + 9] = -10.2779620900; tmpV[2*13 + 10] = 7.9352584366; tmpV[2*13 + 11] = -6.7522392818; tmpV[2*13 + 12] = 6.1747539478; + tmpV[3*13 + 0] = -0.0; tmpV[3*13 + 1] = 1.5219401578; tmpV[3*13 + 2] = -3.5438485554; tmpV[3*13 + 3] = 7.0300255289; tmpV[3*13 + 4] = -14.8901987371; tmpV[3*13 + 5] = 40.6381940129; tmpV[3*13 + 6] = -53.4651544987; tmpV[3*13 + 7] = 53.4651544987; tmpV[3*13 + 8] = -40.6381940129; tmpV[3*13 + 9] = 14.8901987371; tmpV[3*13 + 10] = -7.0300255289; tmpV[3*13 + 11] = 3.5438485554; tmpV[3*13 + 12] = -1.5219401578; + tmpV[4*13 + 0] = 55.0; tmpV[4*13 + 1] = -56.2709061445; tmpV[4*13 + 2] = 60.2549306937; tmpV[4*13 + 3] = -67.2511796347; tmpV[4*13 + 4] = 75.2477722397; tmpV[4*13 + 5] = -47.9480941911; tmpV[4*13 + 6] = 15.9674770369; tmpV[4*13 + 7] = 15.9674770369; tmpV[4*13 + 8] = -47.9480941911; tmpV[4*13 + 9] = 75.2477722397; tmpV[4*13 + 10] = -67.2511796347; tmpV[4*13 + 11] = 60.2549306937; tmpV[4*13 + 12] = -56.2709061445; + tmpV[5*13 + 0] = 0.0; tmpV[5*13 + 1] = -13.8695326974; tmpV[5*13 + 2] = 31.6242271914; tmpV[5*13 + 3] = -59.5793462127; tmpV[5*13 + 4] = 109.0152185187; tmpV[5*13 + 5] = -126.4287338180; tmpV[5*13 + 6] = 131.5040045727; tmpV[5*13 + 7] = -131.5040045727; tmpV[5*13 + 8] = 126.4287338180; tmpV[5*13 + 9] = -109.0152185187; tmpV[5*13 + 10] = 59.5793462127; tmpV[5*13 + 11] = -31.6242271914; tmpV[5*13 + 12] = 13.8695326974; + tmpV[6*13 + 0] = -132.0; tmpV[6*13 + 1] = 132.5319409049; tmpV[6*13 + 2] = -132.4780513404; tmpV[6*13 + 3] = 123.5674782081; tmpV[6*13 + 4] = -74.4320682907; tmpV[6*13 + 5] = 38.8801193717; tmpV[6*13 + 6] = -12.0694188537; tmpV[6*13 + 7] = -12.0694188537; tmpV[6*13 + 8] = 38.8801193717; tmpV[6*13 + 9] = -74.4320682907; tmpV[6*13 + 10] = 123.5674782081; tmpV[6*13 + 11] = -132.4780513404; tmpV[6*13 + 12] = 132.5319409049; + tmpV[7*13 + 0] = -0.0; tmpV[7*13 + 1] = 32.6661895777; tmpV[7*13 + 2] = -69.5298450306; tmpV[7*13 + 3] = 109.4712331409; tmpV[7*13 + 4] = -107.8334673306; tmpV[7*13 + 5] = 102.5184492897; tmpV[7*13 + 6] = -99.4006071501; tmpV[7*13 + 7] = 99.4006071501; tmpV[7*13 + 8] = -102.5184492897; tmpV[7*13 + 9] = 107.8334673306; tmpV[7*13 + 10] = -109.4712331409; tmpV[7*13 + 11] = 69.5298450306; tmpV[7*13 + 12] = -32.6661895777; + tmpV[8*13 + 0] = 99.0; tmpV[8*13 + 1] = -93.9113626635; tmpV[8*13 + 2] = 75.3147168618; tmpV[8*13 + 3] = -35.2795800772; tmpV[8*13 + 4] = 18.0521608541; tmpV[8*13 + 5] = -8.8650350126; tmpV[8*13 + 6] = 2.6891000373; tmpV[8*13 + 7] = 2.6891000373; tmpV[8*13 + 8] = -8.8650350126; tmpV[8*13 + 9] = 18.0521608541; tmpV[8*13 + 10] = -35.2795800772; tmpV[8*13 + 11] = 75.3147168618; tmpV[8*13 + 12] = -93.9113626635; + tmpV[9*13 + 0] = 0.0; tmpV[9*13 + 1] = -23.1470719837; tmpV[9*13 + 2] = 39.5282127035; tmpV[9*13 + 3] = -31.2549806126; tmpV[9*13 + 4] = 26.1530700733; tmpV[9*13 + 5] = -23.3751762359; tmpV[9*13 + 6] = 22.1467313083; tmpV[9*13 + 7] = -22.1467313083; tmpV[9*13 + 8] = 23.3751762359; tmpV[9*13 + 9] = -26.1530700733; tmpV[9*13 + 10] = 31.2549806126; tmpV[9*13 + 11] = -39.5282127035; tmpV[9*13 + 12] = 23.1470719837; + tmpV[10*13 + 0] = -22.0; tmpV[10*13 + 1] = 16.9531714429; tmpV[10*13 + 2] = -4.0999479387; tmpV[10*13 + 3] = 1.7021989010; tmpV[10*13 + 4] = -0.8387165175; tmpV[10*13 + 5] = 0.4056079008; tmpV[10*13 + 6] = -0.1223137885; tmpV[10*13 + 7] = -0.1223137885; tmpV[10*13 + 8] = 0.4056079008; tmpV[10*13 + 9] = -0.8387165175; tmpV[10*13 + 10] = 1.7021989010; tmpV[10*13 + 11] = -4.0999479387; tmpV[10*13 + 12] = 16.9531714429; + tmpV[11*13 + 0] = -0.0; tmpV[11*13 + 1] = 4.1785814689; tmpV[11*13 + 2] = -2.1518186743; tmpV[11*13 + 3] = 1.5080166355; tmpV[11*13 + 4] = -1.2150906493; tmpV[11*13 + 5] = 1.0695001374; tmpV[11*13 + 6] = -1.0073446769; tmpV[11*13 + 7] = 1.0073446769; tmpV[11*13 + 8] = -1.0695001374; tmpV[11*13 + 9] = 1.2150906493; tmpV[11*13 + 10] = -1.5080166355; tmpV[11*13 + 11] = 2.1518186743; tmpV[11*13 + 12] = -4.1785814689; + tmpV[12*13 + 0] = 1.0; tmpV[12*13 + 1] = 0.0; tmpV[12*13 + 2] = 0.0; tmpV[12*13 + 3] = 0.0; tmpV[12*13 + 4] = 0.0; tmpV[12*13 + 5] = 0.0; tmpV[12*13 + 6] = 0.0; tmpV[12*13 + 7] = 0.0; tmpV[12*13 + 8] = 0.0; tmpV[12*13 + 9] = 0.0; tmpV[12*13 + 10] = 0.0; tmpV[12*13 + 11] = 0.0; tmpV[12*13 + 12] = 0.0; + int tmpVLength = (shDegree + 1) * (shDegree + 1); + for (int i = 0; i != tmpVLength; ++i) + v[i] = tmpV[i]; + } +} diff --git a/fury/shaders/ray_traced/odf/ray_glyph_intersections.frag b/fury/shaders/ray_traced/odf/ray_glyph_intersections.frag index 3c01f166a..87fdc4127 100644 --- a/fury/shaders/ray_traced/odf/ray_glyph_intersections.frag +++ b/fury/shaders/ray_traced/odf/ray_glyph_intersections.frag @@ -24,7 +24,7 @@ void rayGlyphIntersections(out float outRayParams[MAX_DEGREE], float shCoeffs[SH // coordinate frame given by rayDir and closestDir float radiusPoly[SH_DEGREE + 1]; float invVander[(SH_DEGREE + 1) * (SH_DEGREE + 1)]; - get_inv_vandermonde(invVander); + getInvVandermonde(invVander, shDegree); _unroll_ for (int i = 0; i != shDegree + 1; ++i) { radiusPoly[i] = 0.0; From e150d065216b7a4c2cc6320ea3c5d2d051ab72c2 Mon Sep 17 00:00:00 2001 From: Javier Guaje Date: Thu, 13 Jun 2024 02:04:21 -0400 Subject: [PATCH 087/118] Removed unnecessary eval_sh.frag file. --- .../SH-ODF_experimental/ray_traced_6.5.py | 6 --- fury/shaders/ray_traced/odf/eval_sh.frag | 45 ------------------- 2 files changed, 51 deletions(-) delete mode 100644 fury/shaders/ray_traced/odf/eval_sh.frag diff --git a/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py b/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py index 92f33b7f6..20efeabfc 100644 --- a/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py +++ b/docs/experimental/SH-ODF_experimental/ray_traced_6.5.py @@ -253,12 +253,6 @@ def uv_calculations(n): # SH_DEGREE in this order. # param point The point on the unit sphere where the basis should be # evaluated. - """ - eval_sh = import_fury_shader( - os.path.join("ray_traced", "odf", "eval_sh.frag") - ) - """ - eval_sh = """ void evalSH(out float outSH[SH_COUNT], vec3 point, int shDegree, int numCoeffs) diff --git a/fury/shaders/ray_traced/odf/eval_sh.frag b/fury/shaders/ray_traced/odf/eval_sh.frag deleted file mode 100644 index 18625f297..000000000 --- a/fury/shaders/ray_traced/odf/eval_sh.frag +++ /dev/null @@ -1,45 +0,0 @@ -void evalSH(out float outSH[SH_COUNT], vec3 point, int shDegree, int numCoeffs) -{ - if (shDegree == 2) - { - float tmpOutSH[6]; - evalSH2(tmpOutSH, point); - for (int i = 0; i != numCoeffs; ++i) - outSH[i] = tmpOutSH[i]; - } - else if (shDegree == 4) - { - float tmpOutSH[15]; - evalSH4(tmpOutSH, point); - for (int i = 0; i != numCoeffs; ++i) - outSH[i] = tmpOutSH[i]; - } - else if (shDegree == 6) - { - float tmpOutSH[28]; - evalSH6(tmpOutSH, point); - for (int i = 0; i != numCoeffs; ++i) - outSH[i] = tmpOutSH[i]; - } - else if (shDegree == 8) - { - float tmpOutSH[45]; - evalSH8(outSH, point); - for (int i = 0; i != numCoeffs; ++i) - outSH[i] = tmpOutSH[i]; - } - else if (shDegree == 10) - { - float tmpOutSH[66]; - evalSH10(outSH, point); - for (int i = 0; i != numCoeffs; ++i) - outSH[i] = tmpOutSH[i]; - } - else if (shDegree == 12) - { - float tmpOutSH[91]; - evalSH12(outSH, point); - for (int i = 0; i != numCoeffs; ++i) - outSH[i] = tmpOutSH[i]; - } -} From f68991b5c10566b012911d1b8d5f55e0e4ea2294 Mon Sep 17 00:00:00 2001 From: tvcastillod Date: Fri, 23 Feb 2024 09:29:11 -0500 Subject: [PATCH 088/118] added odf actor implementation --- .../SH-ODF experimental/odf_example.py | 31 + fury/actors/odf.py | 428 +++++++++++++ .../rt_odfs/descoteaux/eval_sh_10.frag | 175 ++++++ .../rt_odfs/descoteaux/eval_sh_12.frag | 238 +++++++ .../shaders/rt_odfs/descoteaux/eval_sh_2.frag | 23 + .../shaders/rt_odfs/descoteaux/eval_sh_4.frag | 46 ++ .../shaders/rt_odfs/descoteaux/eval_sh_6.frag | 79 +++ .../shaders/rt_odfs/descoteaux/eval_sh_8.frag | 122 ++++ fury/shaders/rt_odfs/eval_sh.frag | 16 + fury/shaders/rt_odfs/eval_sh_grad.frag | 16 + fury/shaders/rt_odfs/eval_sh_grad_10.frag | 430 +++++++++++++ fury/shaders/rt_odfs/eval_sh_grad_12.frag | 591 ++++++++++++++++++ fury/shaders/rt_odfs/eval_sh_grad_2.frag | 46 ++ fury/shaders/rt_odfs/eval_sh_grad_4.frag | 103 +++ fury/shaders/rt_odfs/eval_sh_grad_6.frag | 186 ++++++ fury/shaders/rt_odfs/eval_sh_grad_8.frag | 295 +++++++++ fury/shaders/rt_odfs/find_roots.frag | 82 +++ fury/shaders/rt_odfs/get_inv_vandermonde.frag | 58 ++ fury/shaders/rt_odfs/get_sh_glyph_normal.frag | 16 + .../shaders/rt_odfs/gltf_dielectric_brdf.frag | 41 ++ fury/shaders/rt_odfs/linear_rgb_to_srgb.frag | 4 + fury/shaders/rt_odfs/linear_to_srgb.frag | 4 + fury/shaders/rt_odfs/newton_bisection.frag | 47 ++ .../rt_odfs/ray_sh_glyph_intersections.frag | 81 +++ fury/shaders/rt_odfs/srgb_to_linear.frag | 4 + fury/shaders/rt_odfs/srgb_to_linear_rgb.frag | 4 + fury/shaders/rt_odfs/tonemap.frag | 5 + fury/shaders/rt_odfs/tournier/eval_sh_10.frag | 175 ++++++ fury/shaders/rt_odfs/tournier/eval_sh_12.frag | 238 +++++++ fury/shaders/rt_odfs/tournier/eval_sh_2.frag | 23 + fury/shaders/rt_odfs/tournier/eval_sh_4.frag | 46 ++ fury/shaders/rt_odfs/tournier/eval_sh_6.frag | 79 +++ fury/shaders/rt_odfs/tournier/eval_sh_8.frag | 122 ++++ fury/shaders/utils/minmax_norm.glsl | 4 + 34 files changed, 3858 insertions(+) create mode 100644 docs/experimental/SH-ODF experimental/odf_example.py create mode 100644 fury/actors/odf.py create mode 100644 fury/shaders/rt_odfs/descoteaux/eval_sh_10.frag create mode 100644 fury/shaders/rt_odfs/descoteaux/eval_sh_12.frag create mode 100644 fury/shaders/rt_odfs/descoteaux/eval_sh_2.frag create mode 100644 fury/shaders/rt_odfs/descoteaux/eval_sh_4.frag create mode 100644 fury/shaders/rt_odfs/descoteaux/eval_sh_6.frag create mode 100644 fury/shaders/rt_odfs/descoteaux/eval_sh_8.frag create mode 100644 fury/shaders/rt_odfs/eval_sh.frag create mode 100644 fury/shaders/rt_odfs/eval_sh_grad.frag create mode 100644 fury/shaders/rt_odfs/eval_sh_grad_10.frag create mode 100644 fury/shaders/rt_odfs/eval_sh_grad_12.frag create mode 100644 fury/shaders/rt_odfs/eval_sh_grad_2.frag create mode 100644 fury/shaders/rt_odfs/eval_sh_grad_4.frag create mode 100644 fury/shaders/rt_odfs/eval_sh_grad_6.frag create mode 100644 fury/shaders/rt_odfs/eval_sh_grad_8.frag create mode 100644 fury/shaders/rt_odfs/find_roots.frag create mode 100644 fury/shaders/rt_odfs/get_inv_vandermonde.frag create mode 100644 fury/shaders/rt_odfs/get_sh_glyph_normal.frag create mode 100644 fury/shaders/rt_odfs/gltf_dielectric_brdf.frag create mode 100644 fury/shaders/rt_odfs/linear_rgb_to_srgb.frag create mode 100644 fury/shaders/rt_odfs/linear_to_srgb.frag create mode 100644 fury/shaders/rt_odfs/newton_bisection.frag create mode 100644 fury/shaders/rt_odfs/ray_sh_glyph_intersections.frag create mode 100644 fury/shaders/rt_odfs/srgb_to_linear.frag create mode 100644 fury/shaders/rt_odfs/srgb_to_linear_rgb.frag create mode 100644 fury/shaders/rt_odfs/tonemap.frag create mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_10.frag create mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_12.frag create mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_2.frag create mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_4.frag create mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_6.frag create mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_8.frag create mode 100644 fury/shaders/utils/minmax_norm.glsl diff --git a/docs/experimental/SH-ODF experimental/odf_example.py b/docs/experimental/SH-ODF experimental/odf_example.py new file mode 100644 index 000000000..3b6c60469 --- /dev/null +++ b/docs/experimental/SH-ODF experimental/odf_example.py @@ -0,0 +1,31 @@ +import os + +import numpy as np +from dipy.data.fetcher import dipy_home +from dipy.io.image import load_nifti + +from fury import actor, window + +if __name__ == "__main__": + show_man = window.ShowManager(size=(1280, 720)) + + dataset_dir = os.path.join(dipy_home, "stanford_hardi") + + coeffs, affine = load_nifti("docs\experimental\SH-ODF experimental\coefs_odf.nii") + + valid_mask = np.abs(coeffs).max(axis=(-1)) > 0 + indices = np.nonzero(valid_mask) + + centers = np.asarray(indices).T + + x, y, z, s = coeffs.shape + coeffs = coeffs[:, :, :].reshape((x * y * z, s)) + n_glyphs = coeffs.shape[0] + + max_val = coeffs.min(axis=1) + total = np.sum(abs(coeffs), axis=1) + coeffs = np.dot(np.diag(1 / total), coeffs) * 1.7 + + odf_actor = actor.odf(centers=centers, coeffs=coeffs) + show_man.scene.add(odf_actor) + show_man.start() \ No newline at end of file diff --git a/fury/actors/odf.py b/fury/actors/odf.py new file mode 100644 index 000000000..a6d991033 --- /dev/null +++ b/fury/actors/odf.py @@ -0,0 +1,428 @@ +import os + +import numpy as np + +from fury import actor +from fury.lib import FloatArray, Texture +from fury.shaders import ( + attribute_to_actor, + compose_shader, + import_fury_shader, + shader_to_actor, +) +from fury.utils import numpy_to_vtk_image_data, set_polydata_tcoords + +def uv_calculations(n): + uvs = [] + for i in range(0, n): + a = (n - (i + 1)) / n + b = (n - i) / n + uvs.extend( + [ + [0.001, a + 0.001], + [0.001, b - 0.001], + [0.999, b - 0.001], + [0.999, a + 0.001], + [0.001, a + 0.001], + [0.001, b - 0.001], + [0.999, b - 0.001], + [0.999, a + 0.001], + ] + ) + return uvs + +def minmax_norm(data): + + min = data.min(axis=1) + max = data.max(axis=1) + return np.array([(data[i] - min[i]) / (max[i] - min[i]) + for i in range(data.shape[0])]) + + +def sh_odf(centers, coeffs, basis_type, scales, opacity): + """ + Visualize one or many ODFs with different features. + + Parameters + ---------- + centers : ndarray(N, 3) + ODFs positions. + coeffs : ndarray + 2D ODFs array in SH coefficients. + basis_type: str, optional + Type of basis (descoteaux, tournier) + 'descoteaux' for the default ``descoteaux07`` DYPY basis. + 'tournier' for the default ``tournier07` DYPY basis. + scales : float or ndarray (N, ) + ODFs size. + opacity : float + Takes values from 0 (fully transparent) to 1 (opaque). + + Returns + ------- + box_actor: Actor + + """ + odf_actor = actor.box(centers=centers, scales=scales) + odf_actor.GetMapper().SetVBOShiftScaleMethod(False) + odf_actor.GetProperty().SetOpacity(opacity) + + big_centers = np.repeat(centers, 8, axis=0) + attribute_to_actor(odf_actor, big_centers, "center") + + minmax = np.array([coeffs.min(axis=1), coeffs.max(axis=1)]).T + big_minmax = np.repeat(minmax, 8, axis=0) + attribute_to_actor(odf_actor, big_minmax, "minmax") + + # The coefficient data is stored in a texture to be passed to the shaders. + + # Data is normalized to a range of 0 to 1. + arr = minmax_norm(coeffs) + # Data is turned into values within the RGB color range, and then coverted + # into a vtk image data. + arr *= 255 + grid = numpy_to_vtk_image_data(arr.astype(np.uint8)) + + # Vtk image data is associated to a texture. + texture = Texture() + texture.SetInputDataObject(grid) + texture.Update() + + # Texture is associated with the actor + odf_actor.GetProperty().SetTexture("texture0", texture) + + + odf_actor_pd = odf_actor.GetMapper().GetInput() + + n_glyphs = coeffs.shape[0] + # Coordinates to locate the data of each glyph in the texture. + uv_vals = np.array(uv_calculations(n_glyphs)) + num_pnts = uv_vals.shape[0] + + t_coords = FloatArray() + t_coords.SetNumberOfComponents(2) + t_coords.SetNumberOfTuples(num_pnts) + [t_coords.SetTuple(i, uv_vals[i]) for i in range(num_pnts)] + + set_polydata_tcoords(odf_actor_pd, t_coords) + + # The number of coefficients is associated to the order of the SH + odf_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniformf( + "numCoeffs", 15 + ) + + # Start of shader implementation + + vs_dec = \ + """ + in vec3 center; + in vec2 minmax; + + out vec4 vertexMCVSOutput; + out vec3 centerMCVSOutput; + out vec2 minmaxVSOutput; + out vec3 camPosMCVSOutput; + out vec3 camRightMCVSOutput; + out vec3 camUpMCVSOutput; + """ + + vs_impl = \ + """ + vertexMCVSOutput = vertexMC; + centerMCVSOutput = center; + minmaxVSOutput = minmax; + camPosMCVSOutput = -MCVCMatrix[3].xyz * mat3(MCVCMatrix); + camRightMCVSOutput = vec3( + MCVCMatrix[0][0], MCVCMatrix[1][0], MCVCMatrix[2][0]); + camUpMCVSOutput = vec3( + MCVCMatrix[0][1], MCVCMatrix[1][1], MCVCMatrix[2][1]); + """ + + shader_to_actor(odf_actor, "vertex", decl_code=vs_dec, impl_code=vs_impl) + + # The index of the highest used band of the spherical harmonics basis. Must + # be even, at least 2 and at most 12. + def_sh_degree = "#define SH_DEGREE 4" + + # The number of spherical harmonics basis functions + def_sh_count = "#define SH_COUNT (((SH_DEGREE + 1) * (SH_DEGREE + 2)) / 2)" + + # Degree of polynomials for which we have to find roots + def_max_degree = "#define MAX_DEGREE (2 * SH_DEGREE + 2)" + + # If GL_EXT_control_flow_attributes is available, these defines should be + # defined as [[unroll]] and [[loop]] to give reasonable hints to the + # compiler. That avoids register spilling, which makes execution + # considerably faster. + def_gl_ext_control_flow_attributes = \ + """ + #ifndef _unroll_ + #define _unroll_ + #endif + #ifndef _loop_ + #define _loop_ + #endif + """ + + # When there are fewer intersections/roots than theoretically possible, + # some array entries are set to this value + def_no_intersection = "#define NO_INTERSECTION 3.4e38" + + # pi and its reciprocal + def_pis = \ + """ + #define M_PI 3.141592653589793238462643 + #define M_INV_PI 0.318309886183790671537767526745 + """ + + fs_vs_vars = \ + """ + in vec4 vertexMCVSOutput; + in vec3 centerMCVSOutput; + in vec2 minmaxVSOutput; + in vec3 camPosMCVSOutput; + in vec3 camRightMCVSOutput; + in vec3 camUpMCVSOutput; + """ + + coeffs_norm = import_fury_shader(os.path.join("utils", "minmax_norm.glsl")) + + eval_sh_2 = import_fury_shader( + os.path.join("rt_odfs", basis_type, "eval_sh_2.frag")) + + eval_sh_4 = import_fury_shader( + os.path.join("rt_odfs", basis_type, "eval_sh_4.frag")) + + eval_sh_6 = import_fury_shader( + os.path.join("rt_odfs", basis_type, "eval_sh_6.frag")) + + eval_sh_8 = import_fury_shader( + os.path.join("rt_odfs", basis_type, "eval_sh_8.frag")) + + eval_sh_10 = import_fury_shader( + os.path.join("rt_odfs", basis_type, "eval_sh_10.frag")) + + eval_sh_12 = import_fury_shader( + os.path.join("rt_odfs", basis_type, "eval_sh_12.frag")) + + eval_sh_grad_2 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_2.frag") + ) + + eval_sh_grad_4 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_4.frag") + ) + + eval_sh_grad_6 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_6.frag") + ) + + eval_sh_grad_8 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_8.frag") + ) + + eval_sh_grad_10 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_10.frag") + ) + + eval_sh_grad_12 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_12.frag") + ) + + # Searches a single root of a polynomial within a given interval. + # param out_root The location of the found root. + # param out_end_value The value of the given polynomial at end. + # param poly Coefficients of the polynomial for which a root should be + # found. + # Coefficient poly[i] is multiplied by x^i. + # param begin The beginning of an interval where the polynomial is + # monotonic. + # param end The end of said interval. + # param begin_value The value of the given polynomial at begin. + # param error_tolerance The error tolerance for the returned root + # location. + # Typically the error will be much lower but in theory it can be + # bigger. + # + # return true if a root was found, false if no root exists. + newton_bisection = import_fury_shader( + os.path.join("rt_odfs", "newton_bisection.frag") + ) + + # Finds all roots of the given polynomial in the interval [begin, end] and + # writes them to out_roots. Some entries will be NO_INTERSECTION but other + # than that the array is sorted. The last entry is always NO_INTERSECTION. + find_roots = import_fury_shader(os.path.join("rt_odfs", "find_roots.frag")) + + # Evaluates the spherical harmonics basis in bands 0, 2, ..., SH_DEGREE. + # Conventions are as in the following paper. + # M. Descoteaux, E. Angelino, S. Fitzgibbons, and R. Deriche. Regularized, + # fast, and robust analytical q-ball imaging. Magnetic Resonance in + # Medicine, 58(3), 2007. https://doi.org/10.1002/mrm.21277 + # param out_shs Values of SH basis functions in bands 0, 2, ..., + # SH_DEGREE in this order. + # param point The point on the unit sphere where the basis should be + # evaluated. + eval_sh = import_fury_shader(os.path.join("rt_odfs", "eval_sh.frag")) + + # Evaluates the gradient of each basis function given by eval_sh() and the + # basis itself + eval_sh_grad = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad.frag") + ) + + # Outputs a matrix that turns equidistant samples on the unit circle of a + # homogeneous polynomial into coefficients of that polynomial. + get_inv_vandermonde = import_fury_shader( + os.path.join("rt_odfs", "get_inv_vandermonde.frag") + ) + + # Determines all intersections between a ray and a spherical harmonics + # glyph. + # param out_ray_params The ray parameters at intersection points. The + # points themselves are at ray_origin + out_ray_params[i] * ray_dir. + # Some entries may be NO_INTERSECTION but other than that the array + # is sorted. + # param sh_coeffs SH_COUNT spherical harmonic coefficients defining the + # glyph. Their exact meaning is defined by eval_sh(). + # param ray_origin The origin of the ray, relative to the glyph center. + # param ray_dir The normalized direction vector of the ray. + ray_sh_glyph_intersections = import_fury_shader( + os.path.join("rt_odfs", "ray_sh_glyph_intersections.frag") + ) + + # Provides a normalized normal vector for a spherical harmonics glyph. + # param sh_coeffs SH_COUNT spherical harmonic coefficients defining the + # glyph. Their exact meaning is defined by eval_sh(). + # param point A point on the surface of the glyph, relative to its + # center. + # + # return A normalized surface normal pointing away from the origin. + get_sh_glyph_normal = import_fury_shader( + os.path.join("rt_odfs", "get_sh_glyph_normal.frag") + ) + + # Applies the non-linearity that maps linear RGB to sRGB + linear_to_srgb = import_fury_shader( + os.path.join("rt_odfs", "linear_to_srgb.frag") + ) + + # Inverse of linear_to_srgb() + srgb_to_linear = import_fury_shader( + os.path.join("rt_odfs", "srgb_to_linear.frag") + ) + + # Turns a linear RGB color (i.e. rec. 709) into sRGB + linear_rgb_to_srgb = import_fury_shader( + os.path.join("rt_odfs", "linear_rgb_to_srgb.frag") + ) + + # Inverse of linear_rgb_to_srgb() + srgb_to_linear_rgb = import_fury_shader( + os.path.join("rt_odfs", "srgb_to_linear_rgb.frag") + ) + + # Logarithmic tonemapping operator. Input and output are linear RGB. + tonemap = import_fury_shader(os.path.join("rt_odfs", "tonemap.frag")) + + # Blinn-Phong illumination model + blinn_phong_model = import_fury_shader( + os.path.join("lighting", "blinn_phong_model.frag") + ) + + # fmt: off + fs_dec = compose_shader([ + def_sh_degree, def_sh_count, def_max_degree, + def_gl_ext_control_flow_attributes, def_no_intersection, def_pis, + fs_vs_vars, coeffs_norm, eval_sh_2, eval_sh_4, eval_sh_6, eval_sh_8, + eval_sh_10, eval_sh_12, eval_sh_grad_2, eval_sh_grad_4, eval_sh_grad_6, + eval_sh_grad_8, eval_sh_grad_10, eval_sh_grad_12, newton_bisection, + find_roots, eval_sh, eval_sh_grad, get_inv_vandermonde, + ray_sh_glyph_intersections, get_sh_glyph_normal, blinn_phong_model, + linear_to_srgb, srgb_to_linear, linear_rgb_to_srgb, srgb_to_linear_rgb, + tonemap + ]) + # fmt: on + + shader_to_actor(odf_actor, "fragment", decl_code=fs_dec) + + point_from_vs = "vec3 pnt = vertexMCVSOutput.xyz;" + + # Ray origin is the camera position in world space + ray_origin = "vec3 ro = camPosMCVSOutput;" + + # TODO: Check aspect for automatic scaling + # Ray direction is the normalized difference between the fragment and the + # camera position/ray origin + ray_direction = "vec3 rd = normalize(pnt - ro);" + + # Light direction in a retroreflective model is the normalized difference + # between the camera position/ray origin and the fragment + light_direction = "vec3 ld = normalize(ro - pnt);" + + # Define SH coefficients (measured up to band 8, noise beyond that) + sh_coeffs = \ + """ + float i = 1 / (numCoeffs * 2); + float sh_coeffs[SH_COUNT]; + for(int j=0; j 0.0) { + first_ray_param = ray_params[i]; + break; + } + } + """ + + # Evaluate shading for a directional light + directional_light = \ + """ + vec3 color = vec3(1.); + if (first_ray_param != NO_INTERSECTION) { + vec3 intersection = ro - centerMCVSOutput + first_ray_param * rd; + vec3 normal = get_sh_glyph_normal(sh_coeffs, intersection); + vec3 colorDir = srgb_to_linear_rgb(abs(normalize(intersection))); + float attenuation = dot(ld, normal); + color = blinnPhongIllumModel( + //attenuation, lightColor0, diffuseColor, specularPower, + attenuation, lightColor0, colorDir, specularPower, + specularColor, ambientColor); + } else { + discard; + } + """ + + frag_output = \ + """ + vec3 out_color = linear_rgb_to_srgb(tonemap(color)); + fragOutput0 = vec4(out_color, opacity); + """ + + fs_impl = compose_shader([ + point_from_vs, ray_origin, ray_direction, light_direction, sh_coeffs, + intersection_test, first_intersection, directional_light, frag_output + ]) + + shader_to_actor(odf_actor, "fragment", impl_code=fs_impl, block="picking") + + return odf_actor \ No newline at end of file diff --git a/fury/shaders/rt_odfs/descoteaux/eval_sh_10.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_10.frag new file mode 100644 index 000000000..178033cae --- /dev/null +++ b/fury/shaders/rt_odfs/descoteaux/eval_sh_10.frag @@ -0,0 +1,175 @@ +void eval_sh_10(out float out_shs[66], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + b = z2 * a - 0.250980392 * b; + a = b - 0.250773994 * a; + d = 233.240148813 * a; + out_shs[55] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[20] = -c1 * d; + out_shs[22] = s1 * d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[35] = -c1 * d; + out_shs[37] = s1 * d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + out_shs[54] = -c1 * d; + out_shs[56] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[19] = c0 * d; + out_shs[23] = s0 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[34] = c0 * d; + out_shs[38] = s0 * d; + b = z2 * a - 0.235294118 * b; + a = b - 0.238390093 * a; + d = 272.365814381 * a; + out_shs[53] = c0 * d; + out_shs[57] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[18] = -c1 * d; + out_shs[24] = s1 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[33] = -c1 * d; + out_shs[39] = s1 * d; + a = z2 * b - 0.215686275 * a; + b = a - 0.222910217 * b; + d = -213.661323441 * b; + out_shs[52] = -c1 * d; + out_shs[58] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[17] = c0 * d; + out_shs[25] = s0 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[32] = c0 * d; + out_shs[40] = s0 * d; + b = z2 * a - 0.188235294 * b; + a = b - 0.20123839 * a; + d = 151.081370682 * a; + out_shs[51] = c0 * d; + out_shs[59] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[16] = -c1 * d; + out_shs[26] = s1 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[31] = -c1 * d; + out_shs[41] = s1 * d; + a = z2 * b - 0.152941176 * a; + b = a - 0.173374613 * b; + d = -95.552248675 * b; + out_shs[50] = -c1 * d; + out_shs[60] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[15] = c0 * d; + out_shs[27] = s0 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[30] = c0 * d; + out_shs[42] = s0 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + out_shs[49] = c0 * d; + out_shs[61] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[29] = -c1 * d; + out_shs[43] = s1 * d; + a = (z2 - 5.88235294e-02) * z; + b = a - 9.90712074e-02 * z; + d = -25.910241313 * b; + out_shs[48] = -c1 * d; + out_shs[62] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[28] = c0 * d; + out_shs[44] = s0 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + out_shs[47] = c0 * d; + out_shs[63] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + out_shs[46] = -c1 * d; + out_shs[64] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + out_shs[45] = c0 * d; + out_shs[65] = s0 * d; +} diff --git a/fury/shaders/rt_odfs/descoteaux/eval_sh_12.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_12.frag new file mode 100644 index 000000000..f1a6d85e9 --- /dev/null +++ b/fury/shaders/rt_odfs/descoteaux/eval_sh_12.frag @@ -0,0 +1,238 @@ +void eval_sh_12(out float out_shs[91], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + b = z2 * a - 0.250980392 * b; + a = b - 0.250773994 * a; + d = 233.240148813 * a; + out_shs[55] = d; + b = z2 * a - 0.250626566 * b; + a = b - 0.250517598 * a; + d = 931.186918633 * a; + out_shs[78] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[20] = -c1 * d; + out_shs[22] = s1 * d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[35] = -c1 * d; + out_shs[37] = s1 * d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + out_shs[54] = -c1 * d; + out_shs[56] = s1 * d; + a = z2 * b - 0.248120301 * a; + b = a - 0.248447205 * b; + d = -1265.233874957 * b; + out_shs[77] = -c1 * d; + out_shs[79] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[19] = c0 * d; + out_shs[23] = s0 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[34] = c0 * d; + out_shs[38] = s0 * d; + b = z2 * a - 0.235294118 * b; + a = b - 0.238390093 * a; + d = 272.365814381 * a; + out_shs[53] = c0 * d; + out_shs[57] = s0 * d; + b = z2 * a - 0.240601504 * b; + a = b - 0.242236025 * a; + d = 1121.509962433 * a; + out_shs[76] = c0 * d; + out_shs[80] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[18] = -c1 * d; + out_shs[24] = s1 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[33] = -c1 * d; + out_shs[39] = s1 * d; + a = z2 * b - 0.215686275 * a; + b = a - 0.222910217 * b; + d = -213.661323441 * b; + out_shs[52] = -c1 * d; + out_shs[58] = s1 * d; + a = z2 * b - 0.228070175 * a; + b = a - 0.231884058 * b; + d = -915.709049803 * b; + out_shs[75] = -c1 * d; + out_shs[81] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[17] = c0 * d; + out_shs[25] = s0 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[32] = c0 * d; + out_shs[40] = s0 * d; + b = z2 * a - 0.188235294 * b; + a = b - 0.20123839 * a; + d = 151.081370682 * a; + out_shs[51] = c0 * d; + out_shs[59] = s0 * d; + b = z2 * a - 0.210526316 * b; + a = b - 0.217391304 * a; + d = 686.781787352 * a; + out_shs[74] = c0 * d; + out_shs[82] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[16] = -c1 * d; + out_shs[26] = s1 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[31] = -c1 * d; + out_shs[41] = s1 * d; + a = z2 * b - 0.152941176 * a; + b = a - 0.173374613 * b; + d = -95.552248675 * b; + out_shs[50] = -c1 * d; + out_shs[60] = s1 * d; + a = z2 * b - 0.187969925 * a; + b = a - 0.198757764 * b; + d = -471.12841933 * b; + out_shs[73] = -c1 * d; + out_shs[83] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[15] = c0 * d; + out_shs[27] = s0 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[30] = c0 * d; + out_shs[42] = s0 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + out_shs[49] = c0 * d; + out_shs[61] = s0 * d; + b = z2 * a - 0.160401003 * b; + a = b - 0.175983437 * a; + d = 293.800188384 * a; + out_shs[72] = c0 * d; + out_shs[84] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[29] = -c1 * d; + out_shs[43] = s1 * d; + a = (z2 - 5.88235294e-02) * z; + b = a - 9.90712074e-02 * z; + d = -25.910241313 * b; + out_shs[48] = -c1 * d; + out_shs[62] = s1 * d; + a = z2 * b - 0.127819549 * a; + b = a - 0.149068323 * b; + d = -165.101452729 * b; + out_shs[71] = -c1 * d; + out_shs[85] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[28] = c0 * d; + out_shs[44] = s0 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + out_shs[47] = c0 * d; + out_shs[63] = s0 * d; + b = z2 * (a - 9.02255639e-02); + a = b - 0.118012422 * a; + d = 82.550726364 * a; + out_shs[70] = c0 * d; + out_shs[86] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + out_shs[46] = -c1 * d; + out_shs[64] = s1 * d; + a = (z2 - 4.76190476e-02) * z; + b = a - 8.2815735e-02 * z; + d = -36.028090689 * b; + out_shs[69] = -c1 * d; + out_shs[87] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + out_shs[45] = c0 * d; + out_shs[65] = s0 * d; + a = z2 - 4.34782609e-02; + d = 13.3042542 * a; + out_shs[68] = c0 * d; + out_shs[88] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.923210529 * z; + out_shs[67] = -c1 * d; + out_shs[89] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.800821996; + out_shs[66] = c0 * d; + out_shs[90] = s0 * d; +} diff --git a/fury/shaders/rt_odfs/descoteaux/eval_sh_2.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_2.frag new file mode 100644 index 000000000..c15510b74 --- /dev/null +++ b/fury/shaders/rt_odfs/descoteaux/eval_sh_2.frag @@ -0,0 +1,23 @@ +void eval_sh_2(out float out_shs[6], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; +} diff --git a/fury/shaders/rt_odfs/descoteaux/eval_sh_4.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_4.frag new file mode 100644 index 000000000..975fac054 --- /dev/null +++ b/fury/shaders/rt_odfs/descoteaux/eval_sh_4.frag @@ -0,0 +1,46 @@ +void eval_sh_4(out float out_shs[15], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; +} diff --git a/fury/shaders/rt_odfs/descoteaux/eval_sh_6.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_6.frag new file mode 100644 index 000000000..6cbd1bcf1 --- /dev/null +++ b/fury/shaders/rt_odfs/descoteaux/eval_sh_6.frag @@ -0,0 +1,79 @@ +void eval_sh_6(out float out_shs[28], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[20] = -c1 * d; + out_shs[22] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[19] = c0 * d; + out_shs[23] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[18] = -c1 * d; + out_shs[24] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[17] = c0 * d; + out_shs[25] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[16] = -c1 * d; + out_shs[26] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[15] = c0 * d; + out_shs[27] = s0 * d; +} diff --git a/fury/shaders/rt_odfs/descoteaux/eval_sh_8.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_8.frag new file mode 100644 index 000000000..6e79b2b16 --- /dev/null +++ b/fury/shaders/rt_odfs/descoteaux/eval_sh_8.frag @@ -0,0 +1,122 @@ +void eval_sh_8(out float out_shs[45], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[20] = -c1 * d; + out_shs[22] = s1 * d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[35] = -c1 * d; + out_shs[37] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[19] = c0 * d; + out_shs[23] = s0 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[34] = c0 * d; + out_shs[38] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[18] = -c1 * d; + out_shs[24] = s1 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[33] = -c1 * d; + out_shs[39] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[17] = c0 * d; + out_shs[25] = s0 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[32] = c0 * d; + out_shs[40] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[16] = -c1 * d; + out_shs[26] = s1 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[31] = -c1 * d; + out_shs[41] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[15] = c0 * d; + out_shs[27] = s0 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[30] = c0 * d; + out_shs[42] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[29] = -c1 * d; + out_shs[43] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[28] = c0 * d; + out_shs[44] = s0 * d; +} diff --git a/fury/shaders/rt_odfs/eval_sh.frag b/fury/shaders/rt_odfs/eval_sh.frag new file mode 100644 index 000000000..e3810af25 --- /dev/null +++ b/fury/shaders/rt_odfs/eval_sh.frag @@ -0,0 +1,16 @@ +void eval_sh(out float out_shs[SH_COUNT], vec3 point) +{ + #if SH_DEGREE == 2 + eval_sh_2(out_shs, point); + #elif SH_DEGREE == 4 + eval_sh_4(out_shs, point); + #elif SH_DEGREE == 6 + eval_sh_6(out_shs, point); + #elif SH_DEGREE == 8 + eval_sh_8(out_shs, point); + #elif SH_DEGREE == 10 + eval_sh_10(out_shs, point); + #elif SH_DEGREE == 12 + eval_sh_12(out_shs, point); + #endif +} diff --git a/fury/shaders/rt_odfs/eval_sh_grad.frag b/fury/shaders/rt_odfs/eval_sh_grad.frag new file mode 100644 index 000000000..c318dbd6c --- /dev/null +++ b/fury/shaders/rt_odfs/eval_sh_grad.frag @@ -0,0 +1,16 @@ +void eval_sh_grad(out float out_shs[SH_COUNT], out vec3 out_grads[SH_COUNT], vec3 point) +{ + #if SH_DEGREE == 2 + eval_sh_grad_2(out_shs, out_grads, point); + #elif SH_DEGREE == 4 + eval_sh_grad_4(out_shs, out_grads, point); + #elif SH_DEGREE == 6 + eval_sh_grad_6(out_shs, out_grads, point); + #elif SH_DEGREE == 8 + eval_sh_grad_8(out_shs, out_grads, point); + #elif SH_DEGREE == 10 + eval_sh_grad_10(out_shs, out_grads, point); + #elif SH_DEGREE == 12 + eval_sh_grad_12(out_shs, out_grads, point); + #endif +} diff --git a/fury/shaders/rt_odfs/eval_sh_grad_10.frag b/fury/shaders/rt_odfs/eval_sh_grad_10.frag new file mode 100644 index 000000000..9d5feea39 --- /dev/null +++ b/fury/shaders/rt_odfs/eval_sh_grad_10.frag @@ -0,0 +1,430 @@ +void eval_sh_grad_10(out float out_shs[66], out vec3 out_grads[66], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + b = z2 * a - 0.250980392 * b; + a = b - 0.250773994 * a; + d = 233.240148813 * a; + out_shs[55] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + out_grads[2][0] = -c0 * d; + out_grads[4][0] = s0 * d; + out_grads[2][1] = s0 * d; + out_grads[4][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + out_grads[9][0] = -c0 * d; + out_grads[11][0] = s0 * d; + out_grads[9][1] = s0 * d; + out_grads[11][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[20] = -c1 * d; + out_shs[22] = s1 * d; + out_grads[20][0] = -c0 * d; + out_grads[22][0] = s0 * d; + out_grads[20][1] = s0 * d; + out_grads[22][1] = c0 * d; + d = 88.106914343 * b; + out_grads[21][2] = d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[35] = -c1 * d; + out_shs[37] = s1 * d; + out_grads[35][0] = -c0 * d; + out_grads[37][0] = s0 * d; + out_grads[35][1] = s0 * d; + out_grads[37][1] = c0 * d; + d = 467.786944906 * b; + out_grads[36][2] = d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + out_shs[54] = -c1 * d; + out_shs[56] = s1 * d; + out_grads[54][0] = -c0 * d; + out_grads[56][0] = s0 * d; + out_grads[54][1] = s0 * d; + out_grads[56][1] = c0 * d; + d = 2332.401488133 * b; + out_grads[55][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + d = 1.092548431; + out_grads[1][0] = c1 * d; + out_grads[5][0] = s1 * d; + out_grads[1][1] = -s1 * d; + out_grads[5][1] = c1 * d; + d = -1.092548431; + out_grads[2][2] = -c1 * d; + out_grads[4][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + d = 6.62322287 * a; + out_grads[8][0] = c1 * d; + out_grads[12][0] = s1 * d; + out_grads[8][1] = -s1 * d; + out_grads[12][1] = c1 * d; + d = -14.049977415 * a; + out_grads[9][2] = -c1 * d; + out_grads[11][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[19] = c0 * d; + out_shs[23] = s0 * d; + d = 30.399773564 * a; + out_grads[19][0] = c1 * d; + out_grads[23][0] = s1 * d; + out_grads[19][1] = -s1 * d; + out_grads[23][1] = c1 * d; + d = -96.132524816 * a; + out_grads[20][2] = -c1 * d; + out_grads[22][2] = s1 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[34] = c0 * d; + out_shs[38] = s0 * d; + d = 130.459545912 * a; + out_grads[34][0] = c1 * d; + out_grads[38][0] = s1 * d; + out_grads[34][1] = -s1 * d; + out_grads[38][1] = c1 * d; + d = -545.751435723 * a; + out_grads[35][2] = -c1 * d; + out_grads[37][2] = s1 * d; + b = z2 * a - 0.235294118 * b; + a = b - 0.238390093 * a; + d = 272.365814381 * a; + out_shs[53] = c0 * d; + out_shs[57] = s0 * d; + d = 544.731628762 * a; + out_grads[53][0] = c1 * d; + out_grads[57][0] = s1 * d; + out_grads[53][1] = -s1 * d; + out_grads[57][1] = c1 * d; + d = -2830.508572514 * a; + out_grads[54][2] = -c1 * d; + out_grads[56][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + d = -5.310392309 * z; + out_grads[7][0] = -c0 * d; + out_grads[13][0] = s0 * d; + out_grads[7][1] = s0 * d; + out_grads[13][1] = c0 * d; + d = 6.62322287 * z; + out_grads[8][2] = c0 * d; + out_grads[12][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[18] = -c1 * d; + out_shs[24] = s1 * d; + d = -30.399773564 * b; + out_grads[18][0] = -c0 * d; + out_grads[24][0] = s0 * d; + out_grads[18][1] = s0 * d; + out_grads[24][1] = c0 * d; + d = 60.799547128 * b; + out_grads[19][2] = c0 * d; + out_grads[23][2] = s0 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[33] = -c1 * d; + out_shs[39] = s1 * d; + d = -144.52614017 * b; + out_grads[33][0] = -c0 * d; + out_grads[39][0] = s0 * d; + out_grads[33][1] = s0 * d; + out_grads[39][1] = c0 * d; + d = 391.378637737 * b; + out_grads[34][2] = c0 * d; + out_grads[38][2] = s0 * d; + a = z2 * b - 0.215686275 * a; + b = a - 0.222910217 * b; + d = -213.661323441 * b; + out_shs[52] = -c1 * d; + out_shs[58] = s1 * d; + d = -640.983970322 * b; + out_grads[52][0] = -c0 * d; + out_grads[58][0] = s0 * d; + out_grads[52][1] = s0 * d; + out_grads[58][1] = c0 * d; + d = 2178.926515046 * b; + out_grads[53][2] = c0 * d; + out_grads[57][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + d = 2.503342942; + out_grads[6][0] = c1 * d; + out_grads[14][0] = s1 * d; + out_grads[6][1] = -s1 * d; + out_grads[14][1] = c1 * d; + d = -1.77013077; + out_grads[7][2] = -c1 * d; + out_grads[13][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[17] = c0 * d; + out_shs[25] = s0 * d; + d = 22.200855632 * a; + out_grads[17][0] = c1 * d; + out_grads[25][0] = s1 * d; + out_grads[17][1] = -s1 * d; + out_grads[25][1] = c1 * d; + d = -30.399773564 * a; + out_grads[18][2] = -c1 * d; + out_grads[24][2] = s1 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[32] = c0 * d; + out_shs[40] = s0 * d; + d = 124.388296437 * a; + out_grads[32][0] = c1 * d; + out_grads[40][0] = s1 * d; + out_grads[32][1] = -s1 * d; + out_grads[40][1] = c1 * d; + d = -240.876900283 * a; + out_grads[33][2] = -c1 * d; + out_grads[39][2] = s1 * d; + b = z2 * a - 0.188235294 * b; + a = b - 0.20123839 * a; + d = 151.081370682 * a; + out_shs[51] = c0 * d; + out_shs[59] = s0 * d; + d = 604.325482728 * a; + out_grads[51][0] = c1 * d; + out_grads[59][0] = s1 * d; + out_grads[51][1] = -s1 * d; + out_grads[59][1] = c1 * d; + d = -1495.629264084 * a; + out_grads[52][2] = -c1 * d; + out_grads[58][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[16] = -c1 * d; + out_shs[26] = s1 * d; + d = -11.833095811 * z; + out_grads[16][0] = -c0 * d; + out_grads[26][0] = s0 * d; + out_grads[16][1] = s0 * d; + out_grads[26][1] = c0 * d; + d = 11.100427816 * z; + out_grads[17][2] = c0 * d; + out_grads[25][2] = s0 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[31] = -c1 * d; + out_shs[41] = s1 * d; + d = -86.247765552 * b; + out_grads[31][0] = -c0 * d; + out_grads[41][0] = s0 * d; + out_grads[31][1] = s0 * d; + out_grads[41][1] = c0 * d; + d = 124.388296437 * b; + out_grads[32][2] = c0 * d; + out_grads[40][2] = s0 * d; + a = z2 * b - 0.152941176 * a; + b = a - 0.173374613 * b; + d = -95.552248675 * b; + out_shs[50] = -c1 * d; + out_shs[60] = s1 * d; + d = -477.761243376 * b; + out_grads[50][0] = -c0 * d; + out_grads[60][0] = s0 * d; + out_grads[50][1] = s0 * d; + out_grads[60][1] = c0 * d; + d = 906.488224092 * b; + out_grads[51][2] = c0 * d; + out_grads[59][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[15] = c0 * d; + out_shs[27] = s0 * d; + d = 4.099104631; + out_grads[15][0] = c1 * d; + out_grads[27][0] = s1 * d; + out_grads[15][1] = -s1 * d; + out_grads[27][1] = c1 * d; + d = -2.366619162; + out_grads[16][2] = -c1 * d; + out_grads[26][2] = s1 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[30] = c0 * d; + out_shs[42] = s0 * d; + d = 47.909948945 * a; + out_grads[30][0] = c1 * d; + out_grads[42][0] = s1 * d; + out_grads[30][1] = -s1 * d; + out_grads[42][1] = c1 * d; + d = -51.748659331 * a; + out_grads[31][2] = -c1 * d; + out_grads[41][2] = s1 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + out_shs[49] = c0 * d; + out_shs[61] = s0 * d; + d = 320.491985161 * a; + out_grads[49][0] = c1 * d; + out_grads[61][0] = s1 * d; + out_grads[49][1] = -s1 * d; + out_grads[61][1] = c1 * d; + d = -477.761243376 * a; + out_grads[50][2] = -c1 * d; + out_grads[60][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[29] = -c1 * d; + out_shs[43] = s1 * d; + d = -20.409946485 * z; + out_grads[29][0] = -c0 * d; + out_grads[43][0] = s0 * d; + out_grads[29][1] = s0 * d; + out_grads[43][1] = c0 * d; + d = 15.969982982 * z; + out_grads[30][2] = c0 * d; + out_grads[42][2] = s0 * d; + a = (z2 - 5.88235294e-02) * z; + b = a - 9.90712074e-02 * z; + d = -25.910241313 * b; + out_shs[48] = -c1 * d; + out_shs[62] = s1 * d; + d = -181.371689194 * b; + out_grads[48][0] = -c0 * d; + out_grads[62][0] = s0 * d; + out_grads[48][1] = s0 * d; + out_grads[62][1] = c0 * d; + d = 213.661323441 * b; + out_grads[49][2] = c0 * d; + out_grads[61][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[28] = c0 * d; + out_shs[44] = s0 * d; + d = 5.831413281; + out_grads[28][0] = c1 * d; + out_grads[44][0] = s1 * d; + out_grads[28][1] = -s1 * d; + out_grads[44][1] = c1 * d; + d = -2.915706641; + out_grads[29][2] = -c1 * d; + out_grads[43][2] = s1 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + out_shs[47] = c0 * d; + out_shs[63] = s0 * d; + d = 84.622493774 * a; + out_grads[47][0] = c1 * d; + out_grads[63][0] = s1 * d; + out_grads[47][1] = -s1 * d; + out_grads[63][1] = c1 * d; + d = -77.73072394 * a; + out_grads[48][2] = -c1 * d; + out_grads[62][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + out_shs[46] = -c1 * d; + out_shs[64] = s1 * d; + d = -30.887057699 * z; + out_grads[46][0] = -c0 * d; + out_grads[64][0] = s0 * d; + out_grads[46][1] = s0 * d; + out_grads[64][1] = c0 * d; + d = 21.155623443 * z; + out_grads[47][2] = c0 * d; + out_grads[63][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + out_shs[45] = c0 * d; + out_shs[65] = s0 * d; + d = 7.673951182; + out_grads[45][0] = c1 * d; + out_grads[65][0] = s1 * d; + out_grads[45][1] = -s1 * d; + out_grads[65][1] = c1 * d; + d = -3.4318953; + out_grads[46][2] = -c1 * d; + out_grads[64][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; + out_grads[6][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[14][2] = 0.0; + out_grads[15][2] = 0.0; + out_grads[21][0] = 0.0; + out_grads[21][1] = 0.0; + out_grads[27][2] = 0.0; + out_grads[28][2] = 0.0; + out_grads[36][0] = 0.0; + out_grads[36][1] = 0.0; + out_grads[44][2] = 0.0; + out_grads[45][2] = 0.0; + out_grads[55][0] = 0.0; + out_grads[55][1] = 0.0; + out_grads[65][2] = 0.0; +} diff --git a/fury/shaders/rt_odfs/eval_sh_grad_12.frag b/fury/shaders/rt_odfs/eval_sh_grad_12.frag new file mode 100644 index 000000000..f7ff069bc --- /dev/null +++ b/fury/shaders/rt_odfs/eval_sh_grad_12.frag @@ -0,0 +1,591 @@ +void eval_sh_grad_12(out float out_shs[91], out vec3 out_grads[91], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + b = z2 * a - 0.250980392 * b; + a = b - 0.250773994 * a; + d = 233.240148813 * a; + out_shs[55] = d; + b = z2 * a - 0.250626566 * b; + a = b - 0.250517598 * a; + d = 931.186918633 * a; + out_shs[78] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + out_grads[2][0] = -c0 * d; + out_grads[4][0] = s0 * d; + out_grads[2][1] = s0 * d; + out_grads[4][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + out_grads[9][0] = -c0 * d; + out_grads[11][0] = s0 * d; + out_grads[9][1] = s0 * d; + out_grads[11][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[20] = -c1 * d; + out_shs[22] = s1 * d; + out_grads[20][0] = -c0 * d; + out_grads[22][0] = s0 * d; + out_grads[20][1] = s0 * d; + out_grads[22][1] = c0 * d; + d = 88.106914343 * b; + out_grads[21][2] = d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[35] = -c1 * d; + out_shs[37] = s1 * d; + out_grads[35][0] = -c0 * d; + out_grads[37][0] = s0 * d; + out_grads[35][1] = s0 * d; + out_grads[37][1] = c0 * d; + d = 467.786944906 * b; + out_grads[36][2] = d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + out_shs[54] = -c1 * d; + out_shs[56] = s1 * d; + out_grads[54][0] = -c0 * d; + out_grads[56][0] = s0 * d; + out_grads[54][1] = s0 * d; + out_grads[56][1] = c0 * d; + d = 2332.401488133 * b; + out_grads[55][2] = d; + a = z2 * b - 0.248120301 * a; + b = a - 0.248447205 * b; + d = -1265.233874957 * b; + out_shs[77] = -c1 * d; + out_shs[79] = s1 * d; + out_grads[77][0] = -c0 * d; + out_grads[79][0] = s0 * d; + out_grads[77][1] = s0 * d; + out_grads[79][1] = c0 * d; + d = 11174.243023595 * b; + out_grads[78][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + d = 1.092548431; + out_grads[1][0] = c1 * d; + out_grads[5][0] = s1 * d; + out_grads[1][1] = -s1 * d; + out_grads[5][1] = c1 * d; + d = -1.092548431; + out_grads[2][2] = -c1 * d; + out_grads[4][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + d = 6.62322287 * a; + out_grads[8][0] = c1 * d; + out_grads[12][0] = s1 * d; + out_grads[8][1] = -s1 * d; + out_grads[12][1] = c1 * d; + d = -14.049977415 * a; + out_grads[9][2] = -c1 * d; + out_grads[11][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[19] = c0 * d; + out_shs[23] = s0 * d; + d = 30.399773564 * a; + out_grads[19][0] = c1 * d; + out_grads[23][0] = s1 * d; + out_grads[19][1] = -s1 * d; + out_grads[23][1] = c1 * d; + d = -96.132524816 * a; + out_grads[20][2] = -c1 * d; + out_grads[22][2] = s1 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[34] = c0 * d; + out_shs[38] = s0 * d; + d = 130.459545912 * a; + out_grads[34][0] = c1 * d; + out_grads[38][0] = s1 * d; + out_grads[34][1] = -s1 * d; + out_grads[38][1] = c1 * d; + d = -545.751435723 * a; + out_grads[35][2] = -c1 * d; + out_grads[37][2] = s1 * d; + b = z2 * a - 0.235294118 * b; + a = b - 0.238390093 * a; + d = 272.365814381 * a; + out_shs[53] = c0 * d; + out_shs[57] = s0 * d; + d = 544.731628762 * a; + out_grads[53][0] = c1 * d; + out_grads[57][0] = s1 * d; + out_grads[53][1] = -s1 * d; + out_grads[57][1] = c1 * d; + d = -2830.508572514 * a; + out_grads[54][2] = -c1 * d; + out_grads[56][2] = s1 * d; + b = z2 * a - 0.240601504 * b; + a = b - 0.242236025 * a; + d = 1121.509962433 * a; + out_shs[76] = c0 * d; + out_shs[80] = s0 * d; + d = 2243.019924866 * a; + out_grads[76][0] = c1 * d; + out_grads[80][0] = s1 * d; + out_grads[76][1] = -s1 * d; + out_grads[80][1] = c1 * d; + d = -13917.572624524 * a; + out_grads[77][2] = -c1 * d; + out_grads[79][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + d = -5.310392309 * z; + out_grads[7][0] = -c0 * d; + out_grads[13][0] = s0 * d; + out_grads[7][1] = s0 * d; + out_grads[13][1] = c0 * d; + d = 6.62322287 * z; + out_grads[8][2] = c0 * d; + out_grads[12][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[18] = -c1 * d; + out_shs[24] = s1 * d; + d = -30.399773564 * b; + out_grads[18][0] = -c0 * d; + out_grads[24][0] = s0 * d; + out_grads[18][1] = s0 * d; + out_grads[24][1] = c0 * d; + d = 60.799547128 * b; + out_grads[19][2] = c0 * d; + out_grads[23][2] = s0 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[33] = -c1 * d; + out_shs[39] = s1 * d; + d = -144.52614017 * b; + out_grads[33][0] = -c0 * d; + out_grads[39][0] = s0 * d; + out_grads[33][1] = s0 * d; + out_grads[39][1] = c0 * d; + d = 391.378637737 * b; + out_grads[34][2] = c0 * d; + out_grads[38][2] = s0 * d; + a = z2 * b - 0.215686275 * a; + b = a - 0.222910217 * b; + d = -213.661323441 * b; + out_shs[52] = -c1 * d; + out_shs[58] = s1 * d; + d = -640.983970322 * b; + out_grads[52][0] = -c0 * d; + out_grads[58][0] = s0 * d; + out_grads[52][1] = s0 * d; + out_grads[58][1] = c0 * d; + d = 2178.926515046 * b; + out_grads[53][2] = c0 * d; + out_grads[57][2] = s0 * d; + a = z2 * b - 0.228070175 * a; + b = a - 0.231884058 * b; + d = -915.709049803 * b; + out_shs[75] = -c1 * d; + out_shs[81] = s1 * d; + d = -2747.127149409 * b; + out_grads[75][0] = -c0 * d; + out_grads[81][0] = s0 * d; + out_grads[75][1] = s0 * d; + out_grads[81][1] = c0 * d; + d = 11215.099624332 * b; + out_grads[76][2] = c0 * d; + out_grads[80][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + d = 2.503342942; + out_grads[6][0] = c1 * d; + out_grads[14][0] = s1 * d; + out_grads[6][1] = -s1 * d; + out_grads[14][1] = c1 * d; + d = -1.77013077; + out_grads[7][2] = -c1 * d; + out_grads[13][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[17] = c0 * d; + out_shs[25] = s0 * d; + d = 22.200855632 * a; + out_grads[17][0] = c1 * d; + out_grads[25][0] = s1 * d; + out_grads[17][1] = -s1 * d; + out_grads[25][1] = c1 * d; + d = -30.399773564 * a; + out_grads[18][2] = -c1 * d; + out_grads[24][2] = s1 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[32] = c0 * d; + out_shs[40] = s0 * d; + d = 124.388296437 * a; + out_grads[32][0] = c1 * d; + out_grads[40][0] = s1 * d; + out_grads[32][1] = -s1 * d; + out_grads[40][1] = c1 * d; + d = -240.876900283 * a; + out_grads[33][2] = -c1 * d; + out_grads[39][2] = s1 * d; + b = z2 * a - 0.188235294 * b; + a = b - 0.20123839 * a; + d = 151.081370682 * a; + out_shs[51] = c0 * d; + out_shs[59] = s0 * d; + d = 604.325482728 * a; + out_grads[51][0] = c1 * d; + out_grads[59][0] = s1 * d; + out_grads[51][1] = -s1 * d; + out_grads[59][1] = c1 * d; + d = -1495.629264084 * a; + out_grads[52][2] = -c1 * d; + out_grads[58][2] = s1 * d; + b = z2 * a - 0.210526316 * b; + a = b - 0.217391304 * a; + d = 686.781787352 * a; + out_shs[74] = c0 * d; + out_shs[82] = s0 * d; + d = 2747.127149409 * a; + out_grads[74][0] = c1 * d; + out_grads[82][0] = s1 * d; + out_grads[74][1] = -s1 * d; + out_grads[82][1] = c1 * d; + d = -8241.381448228 * a; + out_grads[75][2] = -c1 * d; + out_grads[81][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[16] = -c1 * d; + out_shs[26] = s1 * d; + d = -11.833095811 * z; + out_grads[16][0] = -c0 * d; + out_grads[26][0] = s0 * d; + out_grads[16][1] = s0 * d; + out_grads[26][1] = c0 * d; + d = 11.100427816 * z; + out_grads[17][2] = c0 * d; + out_grads[25][2] = s0 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[31] = -c1 * d; + out_shs[41] = s1 * d; + d = -86.247765552 * b; + out_grads[31][0] = -c0 * d; + out_grads[41][0] = s0 * d; + out_grads[31][1] = s0 * d; + out_grads[41][1] = c0 * d; + d = 124.388296437 * b; + out_grads[32][2] = c0 * d; + out_grads[40][2] = s0 * d; + a = z2 * b - 0.152941176 * a; + b = a - 0.173374613 * b; + d = -95.552248675 * b; + out_shs[50] = -c1 * d; + out_shs[60] = s1 * d; + d = -477.761243376 * b; + out_grads[50][0] = -c0 * d; + out_grads[60][0] = s0 * d; + out_grads[50][1] = s0 * d; + out_grads[60][1] = c0 * d; + d = 906.488224092 * b; + out_grads[51][2] = c0 * d; + out_grads[59][2] = s0 * d; + a = z2 * b - 0.187969925 * a; + b = a - 0.198757764 * b; + d = -471.12841933 * b; + out_shs[73] = -c1 * d; + out_shs[83] = s1 * d; + d = -2355.642096651 * b; + out_grads[73][0] = -c0 * d; + out_grads[83][0] = s0 * d; + out_grads[73][1] = s0 * d; + out_grads[83][1] = c0 * d; + d = 5494.254298819 * b; + out_grads[74][2] = c0 * d; + out_grads[82][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[15] = c0 * d; + out_shs[27] = s0 * d; + d = 4.099104631; + out_grads[15][0] = c1 * d; + out_grads[27][0] = s1 * d; + out_grads[15][1] = -s1 * d; + out_grads[27][1] = c1 * d; + d = -2.366619162; + out_grads[16][2] = -c1 * d; + out_grads[26][2] = s1 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[30] = c0 * d; + out_shs[42] = s0 * d; + d = 47.909948945 * a; + out_grads[30][0] = c1 * d; + out_grads[42][0] = s1 * d; + out_grads[30][1] = -s1 * d; + out_grads[42][1] = c1 * d; + d = -51.748659331 * a; + out_grads[31][2] = -c1 * d; + out_grads[41][2] = s1 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + out_shs[49] = c0 * d; + out_shs[61] = s0 * d; + d = 320.491985161 * a; + out_grads[49][0] = c1 * d; + out_grads[61][0] = s1 * d; + out_grads[49][1] = -s1 * d; + out_grads[61][1] = c1 * d; + d = -477.761243376 * a; + out_grads[50][2] = -c1 * d; + out_grads[60][2] = s1 * d; + b = z2 * a - 0.160401003 * b; + a = b - 0.175983437 * a; + d = 293.800188384 * a; + out_shs[72] = c0 * d; + out_shs[84] = s0 * d; + d = 1762.801130306 * a; + out_grads[72][0] = c1 * d; + out_grads[84][0] = s1 * d; + out_grads[72][1] = -s1 * d; + out_grads[84][1] = c1 * d; + d = -3297.898935312 * a; + out_grads[73][2] = -c1 * d; + out_grads[83][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[29] = -c1 * d; + out_shs[43] = s1 * d; + d = -20.409946485 * z; + out_grads[29][0] = -c0 * d; + out_grads[43][0] = s0 * d; + out_grads[29][1] = s0 * d; + out_grads[43][1] = c0 * d; + d = 15.969982982 * z; + out_grads[30][2] = c0 * d; + out_grads[42][2] = s0 * d; + a = (z2 - 5.88235294e-02) * z; + b = a - 9.90712074e-02 * z; + d = -25.910241313 * b; + out_shs[48] = -c1 * d; + out_shs[62] = s1 * d; + d = -181.371689194 * b; + out_grads[48][0] = -c0 * d; + out_grads[62][0] = s0 * d; + out_grads[48][1] = s0 * d; + out_grads[62][1] = c0 * d; + d = 213.661323441 * b; + out_grads[49][2] = c0 * d; + out_grads[61][2] = s0 * d; + a = z2 * b - 0.127819549 * a; + b = a - 0.149068323 * b; + d = -165.101452729 * b; + out_shs[71] = -c1 * d; + out_shs[85] = s1 * d; + d = -1155.7101691 * b; + out_grads[71][0] = -c0 * d; + out_grads[85][0] = s0 * d; + out_grads[71][1] = s0 * d; + out_grads[85][1] = c0 * d; + d = 1762.801130306 * b; + out_grads[72][2] = c0 * d; + out_grads[84][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[28] = c0 * d; + out_shs[44] = s0 * d; + d = 5.831413281; + out_grads[28][0] = c1 * d; + out_grads[44][0] = s1 * d; + out_grads[28][1] = -s1 * d; + out_grads[44][1] = c1 * d; + d = -2.915706641; + out_grads[29][2] = -c1 * d; + out_grads[43][2] = s1 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + out_shs[47] = c0 * d; + out_shs[63] = s0 * d; + d = 84.622493774 * a; + out_grads[47][0] = c1 * d; + out_grads[63][0] = s1 * d; + out_grads[47][1] = -s1 * d; + out_grads[63][1] = c1 * d; + d = -77.73072394 * a; + out_grads[48][2] = -c1 * d; + out_grads[62][2] = s1 * d; + b = z2 * (a - 9.02255639e-02); + a = b - 0.118012422 * a; + d = 82.550726364 * a; + out_shs[70] = c0 * d; + out_shs[86] = s0 * d; + d = 660.405810914 * a; + out_grads[70][0] = c1 * d; + out_grads[86][0] = s1 * d; + out_grads[70][1] = -s1 * d; + out_grads[86][1] = c1 * d; + d = -825.507263643 * a; + out_grads[71][2] = -c1 * d; + out_grads[85][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + out_shs[46] = -c1 * d; + out_shs[64] = s1 * d; + d = -30.887057699 * z; + out_grads[46][0] = -c0 * d; + out_grads[64][0] = s0 * d; + out_grads[46][1] = s0 * d; + out_grads[64][1] = c0 * d; + d = 21.155623443 * z; + out_grads[47][2] = c0 * d; + out_grads[63][2] = s0 * d; + a = (z2 - 4.76190476e-02) * z; + b = a - 8.2815735e-02 * z; + d = -36.028090689 * b; + out_shs[69] = -c1 * d; + out_shs[87] = s1 * d; + d = -324.252816204 * b; + out_grads[69][0] = -c0 * d; + out_grads[87][0] = s0 * d; + out_grads[69][1] = s0 * d; + out_grads[87][1] = c0 * d; + d = 330.202905457 * b; + out_grads[70][2] = c0 * d; + out_grads[86][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + out_shs[45] = c0 * d; + out_shs[65] = s0 * d; + d = 7.673951182; + out_grads[45][0] = c1 * d; + out_grads[65][0] = s1 * d; + out_grads[45][1] = -s1 * d; + out_grads[65][1] = c1 * d; + d = -3.4318953; + out_grads[46][2] = -c1 * d; + out_grads[64][2] = s1 * d; + a = z2 - 4.34782609e-02; + d = 13.3042542 * a; + out_shs[68] = c0 * d; + out_shs[88] = s0 * d; + d = 133.042542003 * a; + out_grads[68][0] = c1 * d; + out_grads[88][0] = s1 * d; + out_grads[68][1] = -s1 * d; + out_grads[88][1] = c1 * d; + d = -108.084272068 * a; + out_grads[69][2] = -c1 * d; + out_grads[87][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.923210529 * z; + out_shs[67] = -c1 * d; + out_shs[89] = s1 * d; + d = -43.155315818 * z; + out_grads[67][0] = -c0 * d; + out_grads[89][0] = s0 * d; + out_grads[67][1] = s0 * d; + out_grads[89][1] = c0 * d; + d = 26.608508401 * z; + out_grads[68][2] = c0 * d; + out_grads[88][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.800821996; + out_shs[66] = c0 * d; + out_shs[90] = s0 * d; + d = 9.609863949; + out_grads[66][0] = c1 * d; + out_grads[90][0] = s1 * d; + out_grads[66][1] = -s1 * d; + out_grads[90][1] = c1 * d; + d = -3.923210529; + out_grads[67][2] = -c1 * d; + out_grads[89][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; + out_grads[6][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[14][2] = 0.0; + out_grads[15][2] = 0.0; + out_grads[21][0] = 0.0; + out_grads[21][1] = 0.0; + out_grads[27][2] = 0.0; + out_grads[28][2] = 0.0; + out_grads[36][0] = 0.0; + out_grads[36][1] = 0.0; + out_grads[44][2] = 0.0; + out_grads[45][2] = 0.0; + out_grads[55][0] = 0.0; + out_grads[55][1] = 0.0; + out_grads[65][2] = 0.0; + out_grads[66][2] = 0.0; + out_grads[78][0] = 0.0; + out_grads[78][1] = 0.0; + out_grads[90][2] = 0.0; +} diff --git a/fury/shaders/rt_odfs/eval_sh_grad_2.frag b/fury/shaders/rt_odfs/eval_sh_grad_2.frag new file mode 100644 index 000000000..7004bd528 --- /dev/null +++ b/fury/shaders/rt_odfs/eval_sh_grad_2.frag @@ -0,0 +1,46 @@ +void eval_sh_grad_2(out float out_shs[6], out vec3 out_grads[6], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + out_grads[2][0] = -c0 * d; + out_grads[4][0] = s0 * d; + out_grads[2][1] = s0 * d; + out_grads[4][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + d = 1.092548431; + out_grads[1][0] = c1 * d; + out_grads[5][0] = s1 * d; + out_grads[1][1] = -s1 * d; + out_grads[5][1] = c1 * d; + d = -1.092548431; + out_grads[2][2] = -c1 * d; + out_grads[4][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; +} diff --git a/fury/shaders/rt_odfs/eval_sh_grad_4.frag b/fury/shaders/rt_odfs/eval_sh_grad_4.frag new file mode 100644 index 000000000..715302f39 --- /dev/null +++ b/fury/shaders/rt_odfs/eval_sh_grad_4.frag @@ -0,0 +1,103 @@ +void eval_sh_grad_4(out float out_shs[15], out vec3 out_grads[15], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + out_grads[2][0] = -c0 * d; + out_grads[4][0] = s0 * d; + out_grads[2][1] = s0 * d; + out_grads[4][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + out_grads[9][0] = -c0 * d; + out_grads[11][0] = s0 * d; + out_grads[9][1] = s0 * d; + out_grads[11][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + d = 1.092548431; + out_grads[1][0] = c1 * d; + out_grads[5][0] = s1 * d; + out_grads[1][1] = -s1 * d; + out_grads[5][1] = c1 * d; + d = -1.092548431; + out_grads[2][2] = -c1 * d; + out_grads[4][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + d = 6.62322287 * a; + out_grads[8][0] = c1 * d; + out_grads[12][0] = s1 * d; + out_grads[8][1] = -s1 * d; + out_grads[12][1] = c1 * d; + d = -14.049977415 * a; + out_grads[9][2] = -c1 * d; + out_grads[11][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + d = -5.310392309 * z; + out_grads[7][0] = -c0 * d; + out_grads[13][0] = s0 * d; + out_grads[7][1] = s0 * d; + out_grads[13][1] = c0 * d; + d = 6.62322287 * z; + out_grads[8][2] = c0 * d; + out_grads[12][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + d = 2.503342942; + out_grads[6][0] = c1 * d; + out_grads[14][0] = s1 * d; + out_grads[6][1] = -s1 * d; + out_grads[14][1] = c1 * d; + d = -1.77013077; + out_grads[7][2] = -c1 * d; + out_grads[13][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; + out_grads[6][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[14][2] = 0.0; +} diff --git a/fury/shaders/rt_odfs/eval_sh_grad_6.frag b/fury/shaders/rt_odfs/eval_sh_grad_6.frag new file mode 100644 index 000000000..fa240c3a5 --- /dev/null +++ b/fury/shaders/rt_odfs/eval_sh_grad_6.frag @@ -0,0 +1,186 @@ +void eval_sh_grad_6(out float out_shs[28], out vec3 out_grads[28], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + out_grads[2][0] = -c0 * d; + out_grads[4][0] = s0 * d; + out_grads[2][1] = s0 * d; + out_grads[4][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + out_grads[9][0] = -c0 * d; + out_grads[11][0] = s0 * d; + out_grads[9][1] = s0 * d; + out_grads[11][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[20] = -c1 * d; + out_shs[22] = s1 * d; + out_grads[20][0] = -c0 * d; + out_grads[22][0] = s0 * d; + out_grads[20][1] = s0 * d; + out_grads[22][1] = c0 * d; + d = 88.106914343 * b; + out_grads[21][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + d = 1.092548431; + out_grads[1][0] = c1 * d; + out_grads[5][0] = s1 * d; + out_grads[1][1] = -s1 * d; + out_grads[5][1] = c1 * d; + d = -1.092548431; + out_grads[2][2] = -c1 * d; + out_grads[4][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + d = 6.62322287 * a; + out_grads[8][0] = c1 * d; + out_grads[12][0] = s1 * d; + out_grads[8][1] = -s1 * d; + out_grads[12][1] = c1 * d; + d = -14.049977415 * a; + out_grads[9][2] = -c1 * d; + out_grads[11][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[19] = c0 * d; + out_shs[23] = s0 * d; + d = 30.399773564 * a; + out_grads[19][0] = c1 * d; + out_grads[23][0] = s1 * d; + out_grads[19][1] = -s1 * d; + out_grads[23][1] = c1 * d; + d = -96.132524816 * a; + out_grads[20][2] = -c1 * d; + out_grads[22][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + d = -5.310392309 * z; + out_grads[7][0] = -c0 * d; + out_grads[13][0] = s0 * d; + out_grads[7][1] = s0 * d; + out_grads[13][1] = c0 * d; + d = 6.62322287 * z; + out_grads[8][2] = c0 * d; + out_grads[12][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[18] = -c1 * d; + out_shs[24] = s1 * d; + d = -30.399773564 * b; + out_grads[18][0] = -c0 * d; + out_grads[24][0] = s0 * d; + out_grads[18][1] = s0 * d; + out_grads[24][1] = c0 * d; + d = 60.799547128 * b; + out_grads[19][2] = c0 * d; + out_grads[23][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + d = 2.503342942; + out_grads[6][0] = c1 * d; + out_grads[14][0] = s1 * d; + out_grads[6][1] = -s1 * d; + out_grads[14][1] = c1 * d; + d = -1.77013077; + out_grads[7][2] = -c1 * d; + out_grads[13][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[17] = c0 * d; + out_shs[25] = s0 * d; + d = 22.200855632 * a; + out_grads[17][0] = c1 * d; + out_grads[25][0] = s1 * d; + out_grads[17][1] = -s1 * d; + out_grads[25][1] = c1 * d; + d = -30.399773564 * a; + out_grads[18][2] = -c1 * d; + out_grads[24][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[16] = -c1 * d; + out_shs[26] = s1 * d; + d = -11.833095811 * z; + out_grads[16][0] = -c0 * d; + out_grads[26][0] = s0 * d; + out_grads[16][1] = s0 * d; + out_grads[26][1] = c0 * d; + d = 11.100427816 * z; + out_grads[17][2] = c0 * d; + out_grads[25][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[15] = c0 * d; + out_shs[27] = s0 * d; + d = 4.099104631; + out_grads[15][0] = c1 * d; + out_grads[27][0] = s1 * d; + out_grads[15][1] = -s1 * d; + out_grads[27][1] = c1 * d; + d = -2.366619162; + out_grads[16][2] = -c1 * d; + out_grads[26][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; + out_grads[6][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[14][2] = 0.0; + out_grads[15][2] = 0.0; + out_grads[21][0] = 0.0; + out_grads[21][1] = 0.0; + out_grads[27][2] = 0.0; +} diff --git a/fury/shaders/rt_odfs/eval_sh_grad_8.frag b/fury/shaders/rt_odfs/eval_sh_grad_8.frag new file mode 100644 index 000000000..b0a40d0a7 --- /dev/null +++ b/fury/shaders/rt_odfs/eval_sh_grad_8.frag @@ -0,0 +1,295 @@ +void eval_sh_grad_8(out float out_shs[45], out vec3 out_grads[45], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + out_grads[2][0] = -c0 * d; + out_grads[4][0] = s0 * d; + out_grads[2][1] = s0 * d; + out_grads[4][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + out_grads[9][0] = -c0 * d; + out_grads[11][0] = s0 * d; + out_grads[9][1] = s0 * d; + out_grads[11][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[20] = -c1 * d; + out_shs[22] = s1 * d; + out_grads[20][0] = -c0 * d; + out_grads[22][0] = s0 * d; + out_grads[20][1] = s0 * d; + out_grads[22][1] = c0 * d; + d = 88.106914343 * b; + out_grads[21][2] = d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[35] = -c1 * d; + out_shs[37] = s1 * d; + out_grads[35][0] = -c0 * d; + out_grads[37][0] = s0 * d; + out_grads[35][1] = s0 * d; + out_grads[37][1] = c0 * d; + d = 467.786944906 * b; + out_grads[36][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + d = 1.092548431; + out_grads[1][0] = c1 * d; + out_grads[5][0] = s1 * d; + out_grads[1][1] = -s1 * d; + out_grads[5][1] = c1 * d; + d = -1.092548431; + out_grads[2][2] = -c1 * d; + out_grads[4][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + d = 6.62322287 * a; + out_grads[8][0] = c1 * d; + out_grads[12][0] = s1 * d; + out_grads[8][1] = -s1 * d; + out_grads[12][1] = c1 * d; + d = -14.049977415 * a; + out_grads[9][2] = -c1 * d; + out_grads[11][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[19] = c0 * d; + out_shs[23] = s0 * d; + d = 30.399773564 * a; + out_grads[19][0] = c1 * d; + out_grads[23][0] = s1 * d; + out_grads[19][1] = -s1 * d; + out_grads[23][1] = c1 * d; + d = -96.132524816 * a; + out_grads[20][2] = -c1 * d; + out_grads[22][2] = s1 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[34] = c0 * d; + out_shs[38] = s0 * d; + d = 130.459545912 * a; + out_grads[34][0] = c1 * d; + out_grads[38][0] = s1 * d; + out_grads[34][1] = -s1 * d; + out_grads[38][1] = c1 * d; + d = -545.751435723 * a; + out_grads[35][2] = -c1 * d; + out_grads[37][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + d = -5.310392309 * z; + out_grads[7][0] = -c0 * d; + out_grads[13][0] = s0 * d; + out_grads[7][1] = s0 * d; + out_grads[13][1] = c0 * d; + d = 6.62322287 * z; + out_grads[8][2] = c0 * d; + out_grads[12][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[18] = -c1 * d; + out_shs[24] = s1 * d; + d = -30.399773564 * b; + out_grads[18][0] = -c0 * d; + out_grads[24][0] = s0 * d; + out_grads[18][1] = s0 * d; + out_grads[24][1] = c0 * d; + d = 60.799547128 * b; + out_grads[19][2] = c0 * d; + out_grads[23][2] = s0 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[33] = -c1 * d; + out_shs[39] = s1 * d; + d = -144.52614017 * b; + out_grads[33][0] = -c0 * d; + out_grads[39][0] = s0 * d; + out_grads[33][1] = s0 * d; + out_grads[39][1] = c0 * d; + d = 391.378637737 * b; + out_grads[34][2] = c0 * d; + out_grads[38][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + d = 2.503342942; + out_grads[6][0] = c1 * d; + out_grads[14][0] = s1 * d; + out_grads[6][1] = -s1 * d; + out_grads[14][1] = c1 * d; + d = -1.77013077; + out_grads[7][2] = -c1 * d; + out_grads[13][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[17] = c0 * d; + out_shs[25] = s0 * d; + d = 22.200855632 * a; + out_grads[17][0] = c1 * d; + out_grads[25][0] = s1 * d; + out_grads[17][1] = -s1 * d; + out_grads[25][1] = c1 * d; + d = -30.399773564 * a; + out_grads[18][2] = -c1 * d; + out_grads[24][2] = s1 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[32] = c0 * d; + out_shs[40] = s0 * d; + d = 124.388296437 * a; + out_grads[32][0] = c1 * d; + out_grads[40][0] = s1 * d; + out_grads[32][1] = -s1 * d; + out_grads[40][1] = c1 * d; + d = -240.876900283 * a; + out_grads[33][2] = -c1 * d; + out_grads[39][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[16] = -c1 * d; + out_shs[26] = s1 * d; + d = -11.833095811 * z; + out_grads[16][0] = -c0 * d; + out_grads[26][0] = s0 * d; + out_grads[16][1] = s0 * d; + out_grads[26][1] = c0 * d; + d = 11.100427816 * z; + out_grads[17][2] = c0 * d; + out_grads[25][2] = s0 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[31] = -c1 * d; + out_shs[41] = s1 * d; + d = -86.247765552 * b; + out_grads[31][0] = -c0 * d; + out_grads[41][0] = s0 * d; + out_grads[31][1] = s0 * d; + out_grads[41][1] = c0 * d; + d = 124.388296437 * b; + out_grads[32][2] = c0 * d; + out_grads[40][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[15] = c0 * d; + out_shs[27] = s0 * d; + d = 4.099104631; + out_grads[15][0] = c1 * d; + out_grads[27][0] = s1 * d; + out_grads[15][1] = -s1 * d; + out_grads[27][1] = c1 * d; + d = -2.366619162; + out_grads[16][2] = -c1 * d; + out_grads[26][2] = s1 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[30] = c0 * d; + out_shs[42] = s0 * d; + d = 47.909948945 * a; + out_grads[30][0] = c1 * d; + out_grads[42][0] = s1 * d; + out_grads[30][1] = -s1 * d; + out_grads[42][1] = c1 * d; + d = -51.748659331 * a; + out_grads[31][2] = -c1 * d; + out_grads[41][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[29] = -c1 * d; + out_shs[43] = s1 * d; + d = -20.409946485 * z; + out_grads[29][0] = -c0 * d; + out_grads[43][0] = s0 * d; + out_grads[29][1] = s0 * d; + out_grads[43][1] = c0 * d; + d = 15.969982982 * z; + out_grads[30][2] = c0 * d; + out_grads[42][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[28] = c0 * d; + out_shs[44] = s0 * d; + d = 5.831413281; + out_grads[28][0] = c1 * d; + out_grads[44][0] = s1 * d; + out_grads[28][1] = -s1 * d; + out_grads[44][1] = c1 * d; + d = -2.915706641; + out_grads[29][2] = -c1 * d; + out_grads[43][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; + out_grads[6][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[14][2] = 0.0; + out_grads[15][2] = 0.0; + out_grads[21][0] = 0.0; + out_grads[21][1] = 0.0; + out_grads[27][2] = 0.0; + out_grads[28][2] = 0.0; + out_grads[36][0] = 0.0; + out_grads[36][1] = 0.0; + out_grads[44][2] = 0.0; +} diff --git a/fury/shaders/rt_odfs/find_roots.frag b/fury/shaders/rt_odfs/find_roots.frag new file mode 100644 index 000000000..e5b80f7a4 --- /dev/null +++ b/fury/shaders/rt_odfs/find_roots.frag @@ -0,0 +1,82 @@ +void find_roots(out float out_roots[MAX_DEGREE + 1], float poly[MAX_DEGREE + 1], float begin, float end) { + float tolerance = (end - begin) * 1.0e-4; + // Construct the quadratic derivative of the polynomial. We divide each + // derivative by the factorial of its order, such that the constant + // coefficient can be copied directly from poly. That is a safeguard + // against overflow and makes it easier to avoid spilling below. The + // factors happen to be binomial coefficients then. + float derivative[MAX_DEGREE + 1]; + derivative[0] = poly[MAX_DEGREE - 2]; + derivative[1] = float(MAX_DEGREE - 1) * poly[MAX_DEGREE - 1]; + derivative[2] = (0.5 * float((MAX_DEGREE - 1) * MAX_DEGREE)) * poly[MAX_DEGREE - 0]; + _unroll_ + for (int i = 3; i != MAX_DEGREE + 1; ++i) + derivative[i] = 0.0; + // Compute its two roots using the quadratic formula + float discriminant = derivative[1] * derivative[1] - 4.0 * derivative[0] * derivative[2]; + if (discriminant >= 0.0) { + float sqrt_discriminant = sqrt(discriminant); + float scaled_root = derivative[1] + ((derivative[1] > 0.0) ? sqrt_discriminant : (-sqrt_discriminant)); + float root_0 = clamp(-2.0 * derivative[0] / scaled_root, begin, end); + float root_1 = clamp(-0.5 * scaled_root / derivative[2], begin, end); + out_roots[MAX_DEGREE - 2] = min(root_0, root_1); + out_roots[MAX_DEGREE - 1] = max(root_0, root_1); + } + else { + // Indicate that the cubic derivative has a single root + out_roots[MAX_DEGREE - 2] = begin; + out_roots[MAX_DEGREE - 1] = begin; + } + // The last entry in the root array is set to end to make it easier to + // iterate over relevant intervals, all untouched roots are set to begin + out_roots[MAX_DEGREE] = end; + _unroll_ + for (int i = 0; i != MAX_DEGREE - 2; ++i) + out_roots[i] = begin; + // Work your way up to derivatives of higher degree until you reach the + // polynomial itself. This implementation may seem peculiar: It always + // treats the derivative as though it had degree MAX_DEGREE and it + // constructs the derivatives in a contrived way. Changing that would + // reduce the number of arithmetic instructions roughly by a factor of two. + // However, it would also cause register spilling, which has a far more + // negative impact on the overall run time. Profiling indicates that the + // current implementation has no spilling whatsoever. + _loop_ + for (int degree = 3; degree != MAX_DEGREE + 1; ++degree) { + // Take the integral of the previous derivative (scaled such that the + // constant coefficient can still be copied directly from poly) + float prev_derivative_order = float(MAX_DEGREE + 1 - degree); + _unroll_ + for (int i = MAX_DEGREE; i != 0; --i) + derivative[i] = derivative[i - 1] * (prev_derivative_order * (1.0 / float(i))); + // Copy the constant coefficient without causing spilling. This part + // would be harder if the derivative were not scaled the way it is. + _unroll_ + for (int i = 0; i != MAX_DEGREE - 2; ++i) + derivative[0] = (degree == MAX_DEGREE - i) ? poly[i] : derivative[0]; + // Determine the value of this derivative at begin + float begin_value = derivative[MAX_DEGREE]; + _unroll_ + for (int i = MAX_DEGREE - 1; i != -1; --i) + begin_value = begin_value * begin + derivative[i]; + // Iterate over the intervals where roots may be found + _unroll_ + for (int i = 0; i != MAX_DEGREE; ++i) { + if (i < MAX_DEGREE - degree) + continue; + float current_begin = out_roots[i]; + float current_end = out_roots[i + 1]; + // Try to find a root + float root; + if (newton_bisection(root, begin_value, derivative, current_begin, current_end, begin_value, tolerance)) + out_roots[i] = root; + else if (degree < MAX_DEGREE) + // Create an empty interval for the next iteration + out_roots[i] = out_roots[i - 1]; + else + out_roots[i] = NO_INTERSECTION; + } + } + // We no longer need this array entry + out_roots[MAX_DEGREE] = NO_INTERSECTION; +} diff --git a/fury/shaders/rt_odfs/get_inv_vandermonde.frag b/fury/shaders/rt_odfs/get_inv_vandermonde.frag new file mode 100644 index 000000000..4c7f521c0 --- /dev/null +++ b/fury/shaders/rt_odfs/get_inv_vandermonde.frag @@ -0,0 +1,58 @@ +void get_inv_vandermonde(out float v[(SH_DEGREE + 1) * (SH_DEGREE + 1)]) +{ + #if SH_DEGREE == 2 + v[0*3 + 0] = -0.3333333333; v[0*3 + 1] = 0.6666666667; v[0*3 + 2] = 0.6666666667; + v[1*3 + 0] = -0.0; v[1*3 + 1] = 1.1547005384; v[1*3 + 2] = -1.1547005384; + v[2*3 + 0] = 1.0; v[2*3 + 1] = 0.0; v[2*3 + 2] = 0.0; + #elif SH_DEGREE == 4 + v[0*5 + 0] = 0.2; v[0*5 + 1] = -0.2472135955; v[0*5 + 2] = 0.6472135955; v[0*5 + 3] = 0.6472135955; v[0*5 + 4] = -0.2472135955; + v[1*5 + 0] = 0.0; v[1*5 + 1] = -0.1796111906; v[1*5 + 2] = 1.9919186279; v[1*5 + 3] = -1.9919186279; v[1*5 + 4] = 0.1796111906; + v[2*5 + 0] = -2.0; v[2*5 + 1] = 2.3416407865; v[2*5 + 2] = -0.3416407865; v[2*5 + 3] = -0.3416407865; v[2*5 + 4] = 2.3416407865; + v[3*5 + 0] = -0.0; v[3*5 + 1] = 1.7013016167; v[3*5 + 2] = -1.0514622242; v[3*5 + 3] = 1.0514622242; v[3*5 + 4] = -1.7013016167; + v[4*5 + 0] = 1.0; v[4*5 + 1] = 0.0; v[4*5 + 2] = 0.0; v[4*5 + 3] = 0.0; v[4*5 + 4] = 0.0; + #elif SH_DEGREE == 6 + v[0*7 + 0] = -0.1428571429; v[0*7 + 1] = 0.1585594663; v[0*7 + 2] = -0.2291250674; v[0*7 + 3] = 0.6419941725; v[0*7 + 4] = 0.6419941725; v[0*7 + 5] = -0.2291250674; v[0*7 + 6] = 0.1585594663; + v[1*7 + 0] = -0.0; v[1*7 + 1] = 0.0763582145; v[1*7 + 2] = -0.2873137468; v[1*7 + 3] = 2.8127602518; v[1*7 + 4] = -2.8127602518; v[1*7 + 5] = 0.2873137468; v[1*7 + 6] = -0.0763582145; + v[2*7 + 0] = 3.0; v[2*7 + 1] = -3.2929766145; v[2*7 + 2] = 4.4513463718; v[2*7 + 3] = -1.1583697574; v[2*7 + 4] = -1.1583697574; v[2*7 + 5] = 4.4513463718; v[2*7 + 6] = -3.2929766145; + v[3*7 + 0] = 0.0; v[3*7 + 1] = -1.5858139579; v[3*7 + 2] = 5.5818117995; v[3*7 + 3] = -5.0751495106; v[3*7 + 4] = 5.0751495106; v[3*7 + 5] = -5.5818117995; v[3*7 + 6] = 1.5858139579; + v[4*7 + 0] = -5.0; v[4*7 + 1] = 4.7858935686; v[4*7 + 2] = -1.0200067492; v[4*7 + 3] = 0.2341131806; v[4*7 + 4] = 0.2341131806; v[4*7 + 5] = -1.0200067492; v[4*7 + 6] = 4.7858935686; + v[5*7 + 0] = -0.0; v[5*7 + 1] = 2.3047648710; v[5*7 + 2] = -1.2790480077; v[5*7 + 3] = 1.0257168633; v[5*7 + 4] = -1.0257168633; v[5*7 + 5] = 1.2790480077; v[5*7 + 6] = -2.3047648710; + v[6*7 + 0] = 1.0; v[6*7 + 1] = 0.0; v[6*7 + 2] = 0.0; v[6*7 + 3] = 0.0; v[6*7 + 4] = 0.0; v[6*7 + 5] = 0.0; v[6*7 + 6] = 0.0; + #elif SH_DEGREE == 8 + v[0*9 + 0] = 0.1111111111; v[0*9 + 1] = -0.1182419747; v[0*9 + 2] = 0.1450452544; v[0*9 + 3] = -0.2222222222; v[0*9 + 4] = 0.6398633870; v[0*9 + 5] = 0.6398633870; v[0*9 + 6] = -0.2222222222; v[0*9 + 7] = 0.1450452544; v[0*9 + 8] = -0.1182419747; + v[1*9 + 0] = 0.0; v[1*9 + 1] = -0.0430365592; v[1*9 + 2] = 0.1217074194; v[1*9 + 3] = -0.3849001795; v[1*9 + 4] = 3.6288455938; v[1*9 + 5] = -3.6288455938; v[1*9 + 6] = 0.3849001795; v[1*9 + 7] = -0.1217074194; v[1*9 + 8] = 0.0430365592; + v[2*9 + 0] = -4.0; v[2*9 + 1] = 4.2410470634; v[2*9 + 2] = -5.1195045066; v[2*9 + 3] = 7.3333333333; v[2*9 + 4] = -2.4548758901; v[2*9 + 5] = -2.4548758901; v[2*9 + 6] = 7.3333333333; v[2*9 + 7] = -5.1195045066; v[2*9 + 8] = 4.2410470634; + v[3*9 + 0] = -0.0; v[3*9 + 1] = 1.5436148932; v[3*9 + 2] = -4.2957743433; v[3*9 + 3] = 12.7017059222; v[3*9 + 4] = -13.9222930051; v[3*9 + 5] = 13.9222930051; v[3*9 + 6] = -12.7017059222; v[3*9 + 7] = 4.2957743433; v[3*9 + 8] = -1.5436148932; + v[4*9 + 0] = 14.0; v[4*9 + 1] = -14.3366589404; v[4*9 + 2] = 14.6711193836; v[4*9 + 3] = -6.0; v[4*9 + 4] = 1.6655395568; v[4*9 + 5] = 1.6655395568; v[4*9 + 6] = -6.0; v[4*9 + 7] = 14.6711193836; v[4*9 + 8] = -14.3366589404; + v[5*9 + 0] = 0.0; v[5*9 + 1] = -5.2181171131; v[5*9 + 2] = 12.3105308637; v[5*9 + 3] = -10.3923048454; v[5*9 + 4] = 9.4457442082; v[5*9 + 5] = -9.4457442082; v[5*9 + 6] = 10.3923048454; v[5*9 + 7] = -12.3105308637; v[5*9 + 8] = 5.2181171131; + v[6*9 + 0] = -9.3333333333; v[6*9 + 1] = 8.0330865684; v[6*9 + 2] = -1.8540394597; v[6*9 + 3] = 0.6666666667; v[6*9 + 4] = -0.1790471086; v[6*9 + 5] = -0.1790471086; v[6*9 + 6] = 0.6666666667; v[6*9 + 7] = -1.8540394597; v[6*9 + 8] = 8.0330865684; + v[7*9 + 0] = -0.0; v[7*9 + 1] = 2.9238044002; v[7*9 + 2] = -1.5557238269; v[7*9 + 3] = 1.1547005384; v[7*9 + 4] = -1.0154266119; v[7*9 + 5] = 1.0154266119; v[7*9 + 6] = -1.1547005384; v[7*9 + 7] = 1.5557238269; v[7*9 + 8] = -2.9238044002; + v[8*9 + 0] = 1.0; v[8*9 + 1] = 0.0; v[8*9 + 2] = 0.0; v[8*9 + 3] = 0.0; v[8*9 + 4] = 0.0; v[8*9 + 5] = 0.0; v[8*9 + 6] = 0.0; v[8*9 + 7] = 0.0; v[8*9 + 8] = 0.0; + #elif SH_DEGREE == 10 + v[0*11 + 0] = -0.0909090909; v[0*11 + 1] = 0.0947470106; v[0*11 + 2] = -0.1080638444; v[0*11 + 3] = 0.1388220215; v[0*11 + 4] = -0.2188392043; v[0*11 + 5] = 0.6387885621; v[0*11 + 6] = 0.6387885621; v[0*11 + 7] = -0.2188392043; v[0*11 + 8] = 0.1388220215; v[0*11 + 9] = -0.1080638444; v[0*11 + 10] = 0.0947470106; + v[1*11 + 0] = -0.0; v[1*11 + 1] = 0.0278202324; v[1*11 + 2] = -0.0694484159; v[1*11 + 3] = 0.1602091533; v[1*11 + 4] = -0.4791910159; v[1*11 + 5] = 4.4428720384; v[1*11 + 6] = -4.4428720384; v[1*11 + 7] = 0.4791910159; v[1*11 + 8] = -0.1602091533; v[1*11 + 9] = 0.0694484159; v[1*11 + 10] = -0.0278202324; + v[2*11 + 0] = 5.0; v[2*11 + 1] = -5.2029168239; v[2*11 + 2] = 5.8988796576; v[2*11 + 3] = -7.4503199653; v[2*11 + 4] = 10.9868742757; v[2*11 + 5] = -4.2325171441; v[2*11 + 6] = -4.2325171441; v[2*11 + 7] = 10.9868742757; v[2*11 + 8] = -7.4503199653; v[2*11 + 9] = 5.8988796576; v[2*11 + 10] = -5.2029168239; + v[3*11 + 0] = 0.0; v[3*11 + 1] = -1.5277142200; v[3*11 + 2] = 3.7909797649; v[3*11 + 3] = -8.5981275876; v[3*11 + 4] = 24.0578988657; v[3*11 + 5] = -29.4378033460; v[3*11 + 6] = 29.4378033460; v[3*11 + 7] = -24.0578988657; v[3*11 + 8] = 8.5981275876; v[3*11 + 9] = -3.7909797649; v[3*11 + 10] = 1.5277142200; + v[4*11 + 0] = -30.0; v[4*11 + 1] = 30.8179361182; v[4*11 + 2] = -33.2247539061; v[4*11 + 3] = 35.8884989085; v[4*11 + 4] = -19.5374870834; v[4*11 + 5] = 6.0558059629; v[4*11 + 6] = 6.0558059629; v[4*11 + 7] = -19.5374870834; v[4*11 + 8] = 35.8884989085; v[4*11 + 9] = -33.2247539061; v[4*11 + 10] = 30.8179361182; + v[5*11 + 0] = -0.0; v[5*11 + 1] = 9.0489625020; v[5*11 + 2] = -21.3522528115; v[5*11 + 3] = 41.4175356200; v[5*11 + 4] = -42.7811292411; v[5*11 + 5] = 42.1190556280; v[5*11 + 6] = -42.1190556280; v[5*11 + 7] = 42.7811292411; v[5*11 + 8] = -41.4175356200; v[5*11 + 9] = 21.3522528115; v[5*11 + 10] = -9.0489625020; + v[6*11 + 0] = 42.0; v[6*11 + 1] = -41.1161037573; v[6*11 + 2] = 36.2032364762; v[6*11 + 3] = -16.3373898141; v[6*11 + 4] = 7.4261062994; v[6*11 + 5] = -2.1758492042; v[6*11 + 6] = -2.1758492042; v[6*11 + 7] = 7.4261062994; v[6*11 + 8] = -16.3373898141; v[6*11 + 9] = 36.2032364762; v[6*11 + 10] = -41.1161037573; + v[7*11 + 0] = 0.0; v[7*11 + 1] = -12.0727773496; v[7*11 + 2] = 23.2664073304; v[7*11 + 3] = -18.8543529304; v[7*11 + 4] = 16.2609045881; v[7*11 + 5] = -15.1333636234; v[7*11 + 6] = 15.1333636234; v[7*11 + 7] = -16.2609045881; v[7*11 + 8] = 18.8543529304; v[7*11 + 9] = -23.2664073304; v[7*11 + 10] = 12.0727773496; + v[8*11 + 0] = -15.0; v[8*11 + 1] = 12.0883694702; v[8*11 + 2] = -2.8781222629; v[8*11 + 3] = 1.1465503415; v[8*11 + 4] = -0.5020543475; v[8*11 + 5] = 0.1452567988; v[8*11 + 6] = 0.1452567988; v[8*11 + 7] = -0.5020543475; v[8*11 + 8] = 1.1465503415; v[8*11 + 9] = -2.8781222629; v[8*11 + 10] = 12.0883694702; + v[9*11 + 0] = -0.0; v[9*11 + 1] = 3.5494655329; v[9*11 + 2] = -1.8496568659; v[9*11 + 3] = 1.3231896304; v[9*11 + 4] = -1.0993456751; v[9*11 + 5] = 1.0102832265; v[9*11 + 6] = -1.0102832265; v[9*11 + 7] = 1.0993456751; v[9*11 + 8] = -1.3231896304; v[9*11 + 9] = 1.8496568659; v[9*11 + 10] = -3.5494655329; + v[10*11 + 0] = 1.0; v[10*11 + 1] = 0.0; v[10*11 + 2] = 0.0; v[10*11 + 3] = 0.0; v[10*11 + 4] = 0.0; v[10*11 + 5] = 0.0; v[10*11 + 6] = 0.0; v[10*11 + 7] = 0.0; v[10*11 + 8] = 0.0; v[10*11 + 9] = 0.0; v[10*11 + 10] = 0.0; + #elif SH_DEGREE == 12 + v[0*13 + 0] = 0.0769230769; v[0*13 + 1] = -0.0792252178; v[0*13 + 2] = 0.0868739663; v[0*13 + 3] = -0.1027681661; v[0*13 + 4] = 0.1354125166; v[0*13 + 5] = -0.2169261613; v[0*13 + 6] = 0.6381715239; v[0*13 + 7] = 0.6381715239; v[0*13 + 8] = -0.2169261613; v[0*13 + 9] = 0.1354125166; v[0*13 + 10] = -0.1027681661; v[0*13 + 11] = 0.0868739663; v[0*13 + 12] = -0.0792252178; + v[1*13 + 0] = -0.0; v[1*13 + 1] = -0.0195272624; v[1*13 + 2] = 0.0455949748; v[1*13 + 3] = -0.0910446506; v[1*13 + 4] = 0.1961788986; v[1*13 + 5] = -0.5719872785; v[1*13 + 6] = 5.2558153553; v[1*13 + 7] = -5.2558153553; v[1*13 + 8] = 0.5719872785; v[1*13 + 9] = -0.1961788986; v[1*13 + 10] = 0.0910446506; v[1*13 + 11] = -0.0455949748; v[1*13 + 12] = 0.0195272624; + v[2*13 + 0] = -6.0; v[2*13 + 1] = 6.1747539478; v[2*13 + 2] = -6.7522392818; v[2*13 + 3] = 7.9352584366; v[2*13 + 4] = -10.2779620900; v[2*13 + 5] = 15.4120340799; v[2*13 + 6] = -6.4918450925; v[2*13 + 7] = -6.4918450925; v[2*13 + 8] = 15.4120340799; v[2*13 + 9] = -10.2779620900; v[2*13 + 10] = 7.9352584366; v[2*13 + 11] = -6.7522392818; v[2*13 + 12] = 6.1747539478; + v[3*13 + 0] = -0.0; v[3*13 + 1] = 1.5219401578; v[3*13 + 2] = -3.5438485554; v[3*13 + 3] = 7.0300255289; v[3*13 + 4] = -14.8901987371; v[3*13 + 5] = 40.6381940129; v[3*13 + 6] = -53.4651544987; v[3*13 + 7] = 53.4651544987; v[3*13 + 8] = -40.6381940129; v[3*13 + 9] = 14.8901987371; v[3*13 + 10] = -7.0300255289; v[3*13 + 11] = 3.5438485554; v[3*13 + 12] = -1.5219401578; + v[4*13 + 0] = 55.0; v[4*13 + 1] = -56.2709061445; v[4*13 + 2] = 60.2549306937; v[4*13 + 3] = -67.2511796347; v[4*13 + 4] = 75.2477722397; v[4*13 + 5] = -47.9480941911; v[4*13 + 6] = 15.9674770369; v[4*13 + 7] = 15.9674770369; v[4*13 + 8] = -47.9480941911; v[4*13 + 9] = 75.2477722397; v[4*13 + 10] = -67.2511796347; v[4*13 + 11] = 60.2549306937; v[4*13 + 12] = -56.2709061445; + v[5*13 + 0] = 0.0; v[5*13 + 1] = -13.8695326974; v[5*13 + 2] = 31.6242271914; v[5*13 + 3] = -59.5793462127; v[5*13 + 4] = 109.0152185187; v[5*13 + 5] = -126.4287338180; v[5*13 + 6] = 131.5040045727; v[5*13 + 7] = -131.5040045727; v[5*13 + 8] = 126.4287338180; v[5*13 + 9] = -109.0152185187; v[5*13 + 10] = 59.5793462127; v[5*13 + 11] = -31.6242271914; v[5*13 + 12] = 13.8695326974; + v[6*13 + 0] = -132.0; v[6*13 + 1] = 132.5319409049; v[6*13 + 2] = -132.4780513404; v[6*13 + 3] = 123.5674782081; v[6*13 + 4] = -74.4320682907; v[6*13 + 5] = 38.8801193717; v[6*13 + 6] = -12.0694188537; v[6*13 + 7] = -12.0694188537; v[6*13 + 8] = 38.8801193717; v[6*13 + 9] = -74.4320682907; v[6*13 + 10] = 123.5674782081; v[6*13 + 11] = -132.4780513404; v[6*13 + 12] = 132.5319409049; + v[7*13 + 0] = -0.0; v[7*13 + 1] = 32.6661895777; v[7*13 + 2] = -69.5298450306; v[7*13 + 3] = 109.4712331409; v[7*13 + 4] = -107.8334673306; v[7*13 + 5] = 102.5184492897; v[7*13 + 6] = -99.4006071501; v[7*13 + 7] = 99.4006071501; v[7*13 + 8] = -102.5184492897; v[7*13 + 9] = 107.8334673306; v[7*13 + 10] = -109.4712331409; v[7*13 + 11] = 69.5298450306; v[7*13 + 12] = -32.6661895777; + v[8*13 + 0] = 99.0; v[8*13 + 1] = -93.9113626635; v[8*13 + 2] = 75.3147168618; v[8*13 + 3] = -35.2795800772; v[8*13 + 4] = 18.0521608541; v[8*13 + 5] = -8.8650350126; v[8*13 + 6] = 2.6891000373; v[8*13 + 7] = 2.6891000373; v[8*13 + 8] = -8.8650350126; v[8*13 + 9] = 18.0521608541; v[8*13 + 10] = -35.2795800772; v[8*13 + 11] = 75.3147168618; v[8*13 + 12] = -93.9113626635; + v[9*13 + 0] = 0.0; v[9*13 + 1] = -23.1470719837; v[9*13 + 2] = 39.5282127035; v[9*13 + 3] = -31.2549806126; v[9*13 + 4] = 26.1530700733; v[9*13 + 5] = -23.3751762359; v[9*13 + 6] = 22.1467313083; v[9*13 + 7] = -22.1467313083; v[9*13 + 8] = 23.3751762359; v[9*13 + 9] = -26.1530700733; v[9*13 + 10] = 31.2549806126; v[9*13 + 11] = -39.5282127035; v[9*13 + 12] = 23.1470719837; + v[10*13 + 0] = -22.0; v[10*13 + 1] = 16.9531714429; v[10*13 + 2] = -4.0999479387; v[10*13 + 3] = 1.7021989010; v[10*13 + 4] = -0.8387165175; v[10*13 + 5] = 0.4056079008; v[10*13 + 6] = -0.1223137885; v[10*13 + 7] = -0.1223137885; v[10*13 + 8] = 0.4056079008; v[10*13 + 9] = -0.8387165175; v[10*13 + 10] = 1.7021989010; v[10*13 + 11] = -4.0999479387; v[10*13 + 12] = 16.9531714429; + v[11*13 + 0] = -0.0; v[11*13 + 1] = 4.1785814689; v[11*13 + 2] = -2.1518186743; v[11*13 + 3] = 1.5080166355; v[11*13 + 4] = -1.2150906493; v[11*13 + 5] = 1.0695001374; v[11*13 + 6] = -1.0073446769; v[11*13 + 7] = 1.0073446769; v[11*13 + 8] = -1.0695001374; v[11*13 + 9] = 1.2150906493; v[11*13 + 10] = -1.5080166355; v[11*13 + 11] = 2.1518186743; v[11*13 + 12] = -4.1785814689; + v[12*13 + 0] = 1.0; v[12*13 + 1] = 0.0; v[12*13 + 2] = 0.0; v[12*13 + 3] = 0.0; v[12*13 + 4] = 0.0; v[12*13 + 5] = 0.0; v[12*13 + 6] = 0.0; v[12*13 + 7] = 0.0; v[12*13 + 8] = 0.0; v[12*13 + 9] = 0.0; v[12*13 + 10] = 0.0; v[12*13 + 11] = 0.0; v[12*13 + 12] = 0.0; + #endif +} diff --git a/fury/shaders/rt_odfs/get_sh_glyph_normal.frag b/fury/shaders/rt_odfs/get_sh_glyph_normal.frag new file mode 100644 index 000000000..4831fb8b4 --- /dev/null +++ b/fury/shaders/rt_odfs/get_sh_glyph_normal.frag @@ -0,0 +1,16 @@ +vec3 get_sh_glyph_normal(float sh_coeffs[SH_COUNT], vec3 point) +{ + float shs[SH_COUNT]; + vec3 grads[SH_COUNT]; + float length_inv = inversesqrt(dot(point, point)); + vec3 normalized = point * length_inv; + eval_sh_grad(shs, grads, normalized); + float value = 0.0; + vec3 grad = vec3(0.0); + _unroll_ + for (int i = 0; i != SH_COUNT; ++i) { + value += sh_coeffs[i] * shs[i]; + grad += sh_coeffs[i] * grads[i]; + } + return normalize(point - (value * length_inv) * (grad - dot(grad, normalized) * normalized)); +} diff --git a/fury/shaders/rt_odfs/gltf_dielectric_brdf.frag b/fury/shaders/rt_odfs/gltf_dielectric_brdf.frag new file mode 100644 index 000000000..465ab2266 --- /dev/null +++ b/fury/shaders/rt_odfs/gltf_dielectric_brdf.frag @@ -0,0 +1,41 @@ +vec3 gltf_dielectric_brdf(vec3 incoming, vec3 outgoing, vec3 normal, float roughness, vec3 base_color) +{ + float ni = dot(normal, incoming); + float no = dot(normal, outgoing); + // Early out if incoming or outgoing direction are below the horizon + if (ni <= 0.0 || no <= 0.0) + return vec3(0.0); + // Save some work by not actually computing the half-vector. If the half- + // vector were h, ih = dot(incoming, h) and + // sqrt(nh_ih_2 / ih_2) = dot(normal, h). + float ih_2 = dot(incoming, outgoing) * 0.5 + 0.5; + float sum = ni + no; + float nh_ih_2 = 0.25 * sum * sum; + float ih = sqrt(ih_2); + + // Evaluate the GGX normal distribution function + float roughness_2 = roughness * roughness; + float roughness_4 = roughness_2 * roughness_2; + float roughness_flip = 1.0 - roughness_4; + float denominator = ih_2 - nh_ih_2 * roughness_flip; + float ggx = (roughness_4 * M_INV_PI * ih_2) / (denominator * denominator); + // Evaluate the "visibility" (i.e. masking-shadowing times geometry terms) + float vi = ni + sqrt(roughness_4 + roughness_flip * ni * ni); + float vo = no + sqrt(roughness_4 + roughness_flip * no * no); + float v = 1.0 / (vi * vo); + // That completes the specular BRDF + float specular = v * ggx; + + // The diffuse BRDF is Lambertian + vec3 diffuse = M_INV_PI * base_color; + + // Evaluate the Fresnel term using the Fresnel-Schlick approximation + const float ior = 1.5; + const float f0 = ((1.0 - ior) / (1.0 + ior)) * ((1.0 - ior) / (1.0 + ior)); + float ih_flip = 1.0 - ih; + float ih_flip_2 = ih_flip * ih_flip; + float fresnel = f0 + (1.0 - f0) * ih_flip * ih_flip_2 * ih_flip_2; + + // Mix the two components + return mix(diffuse, vec3(specular), fresnel); +} diff --git a/fury/shaders/rt_odfs/linear_rgb_to_srgb.frag b/fury/shaders/rt_odfs/linear_rgb_to_srgb.frag new file mode 100644 index 000000000..d1c72c83b --- /dev/null +++ b/fury/shaders/rt_odfs/linear_rgb_to_srgb.frag @@ -0,0 +1,4 @@ +vec3 linear_rgb_to_srgb(vec3 linear) +{ + return vec3(linear_to_srgb(linear.r), linear_to_srgb(linear.g), linear_to_srgb(linear.b)); +} diff --git a/fury/shaders/rt_odfs/linear_to_srgb.frag b/fury/shaders/rt_odfs/linear_to_srgb.frag new file mode 100644 index 000000000..ac686853c --- /dev/null +++ b/fury/shaders/rt_odfs/linear_to_srgb.frag @@ -0,0 +1,4 @@ +float linear_to_srgb(float linear) +{ + return (linear <= 0.0031308) ? (12.92 * linear) : (1.055 * pow(linear, 1.0 / 2.4) - 0.055); +} diff --git a/fury/shaders/rt_odfs/newton_bisection.frag b/fury/shaders/rt_odfs/newton_bisection.frag new file mode 100644 index 000000000..3f4b7f81f --- /dev/null +++ b/fury/shaders/rt_odfs/newton_bisection.frag @@ -0,0 +1,47 @@ +bool newton_bisection(out float out_root, out float out_end_value, + float poly[MAX_DEGREE + 1], float begin, float end, + float begin_value, float error_tolerance) +{ + if (begin == end) { + out_end_value = begin_value; + return false; + } + // Evaluate the polynomial at the end of the interval + out_end_value = poly[MAX_DEGREE]; + _unroll_ + for (int i = MAX_DEGREE - 1; i != -1; --i) + out_end_value = out_end_value * end + poly[i]; + // If the values at both ends have the same non-zero sign, there is no root + if (begin_value * out_end_value > 0.0) + return false; + // Otherwise, we find the root iteratively using Newton bisection (with + // bounded iteration count) + float current = 0.5 * (begin + end); + _loop_ + for (int i = 0; i != 90; ++i) { + // Evaluate the polynomial and its derivative + float value = poly[MAX_DEGREE] * current + poly[MAX_DEGREE - 1]; + float derivative = poly[MAX_DEGREE]; + _unroll_ + for (int j = MAX_DEGREE - 2; j != -1; --j) { + derivative = derivative * current + value; + value = value * current + poly[j]; + } + // Shorten the interval + bool right = begin_value * value > 0.0; + begin = right ? current : begin; + end = right ? end : current; + // Apply Newton's method + float guess = current - value / derivative; + // Pick a guess + float middle = 0.5 * (begin + end); + float next = (guess >= begin && guess <= end) ? guess : middle; + // Move along or terminate + bool done = abs(next - current) < error_tolerance; + current = next; + if (done) + break; + } + out_root = current; + return true; +} diff --git a/fury/shaders/rt_odfs/ray_sh_glyph_intersections.frag b/fury/shaders/rt_odfs/ray_sh_glyph_intersections.frag new file mode 100644 index 000000000..a47dbbfc4 --- /dev/null +++ b/fury/shaders/rt_odfs/ray_sh_glyph_intersections.frag @@ -0,0 +1,81 @@ +void ray_sh_glyph_intersections(out float out_ray_params[MAX_DEGREE], float sh_coeffs[SH_COUNT], vec3 ray_origin, vec3 ray_dir) +{ + // Determine the direction from the glyph center to the closest point on + // the ray + float dir_dot_origin = dot(ray_dir, ray_origin); + vec3 closest_dir = normalize(ray_origin - dir_dot_origin * ray_dir); + // Evaluate the SH polynomial at SH_DEGREE + 1 points. That is enough to + // know its value everywhere along the ray. + float sh_values[SH_DEGREE + 1]; + _unroll_ + for (int i = 0; i != SH_DEGREE + 1; ++i) { + vec3 point = cos(float(i) * (M_PI / float(SH_DEGREE + 1))) * ray_dir + + sin(float(i) * (M_PI / float(SH_DEGREE + 1))) * closest_dir; + float shs[SH_COUNT]; + eval_sh(shs, point); + sh_values[i] = 0.0; + _unroll_ + for (int j = 0; j != SH_COUNT; ++j) + sh_values[i] += sh_coeffs[j] * shs[j]; + } + // Compute coefficients of the SH polynomial along the ray in the + // coordinate frame given by ray_dir and closest_dir + float radius_poly[SH_DEGREE + 1]; + float inv_vander[(SH_DEGREE + 1) * (SH_DEGREE + 1)]; + get_inv_vandermonde(inv_vander); + _unroll_ + for (int i = 0; i != SH_DEGREE + 1; ++i) { + radius_poly[i] = 0.0; + _unroll_ + for (int j = 0; j != SH_DEGREE + 1; ++j) + radius_poly[i] += inv_vander[i * (SH_DEGREE + 1) + j] * sh_values[j]; + } + // Compute a bounding circle around the glyph in the relevant plane + float radius_max = 0.0; + _unroll_ + for (int i = 0; i != SH_DEGREE + 1; ++i) { + float bound = sqrt(pow(float(i), float(i)) * pow(float(SH_DEGREE - i), float(SH_DEGREE - i)) / pow(float(SH_DEGREE), float(SH_DEGREE))); + // Workaround for buggy compilers where 0^0 is 0 + bound = (i == 0 || i == SH_DEGREE) ? 1.0 : bound; + radius_max += bound * abs(radius_poly[i]); + } + // Figure out the interval, where (if at all) the ray intersects the circle + float closest_dot_origin = dot(closest_dir, ray_origin); + if (radius_max < abs(closest_dot_origin)) { + _unroll_ + for (int i = 0; i != MAX_DEGREE; ++i) + out_ray_params[i] = NO_INTERSECTION; + return; + } + float radius_over_dot = radius_max / closest_dot_origin; + float u_max = sqrt(radius_over_dot * radius_over_dot - 1.0); + // Take the square of radius_poly + float poly[MAX_DEGREE + 1]; + _unroll_ + for (int i = 0; i != MAX_DEGREE + 1; ++i) + poly[i] = 0.0; + _unroll_ + for (int i = 0; i != SH_DEGREE + 1; ++i) + _unroll_ + for (int j = 0; j != SH_DEGREE + 1; ++j) + poly[i + j] += radius_poly[i] * radius_poly[j]; + // Subtract the scaled (2 * SH_DEGREE + 2)-th power of the distance to the + // glyph center + float dot_sq = closest_dot_origin * closest_dot_origin; + float binomial = 1.0; + _unroll_ + for (int i = 0; i != SH_DEGREE + 2; ++i) { + poly[2 * i] -= binomial * dot_sq; + // Update the binomial coefficient using a recurrence relation + binomial *= float(SH_DEGREE + 1 - i) / float(i + 1); + } + // Find roots of the polynomial within the relevant bounds + float roots[MAX_DEGREE + 1]; + find_roots(roots, poly, -u_max, u_max); + // Convert them back to the original coordinate frame (i.e. ray parameters) + _unroll_ + for (int i = 0; i != MAX_DEGREE; ++i) + out_ray_params[i] = (roots[i] != NO_INTERSECTION) + ? (roots[i] * closest_dot_origin - dir_dot_origin) + : NO_INTERSECTION; +} diff --git a/fury/shaders/rt_odfs/srgb_to_linear.frag b/fury/shaders/rt_odfs/srgb_to_linear.frag new file mode 100644 index 000000000..78c765c20 --- /dev/null +++ b/fury/shaders/rt_odfs/srgb_to_linear.frag @@ -0,0 +1,4 @@ +float srgb_to_linear(float non_linear) +{ + return (non_linear <= 0.04045) ? ((1.0 / 12.92) * non_linear) : pow(non_linear * (1.0 / 1.055) + 0.055 / 1.055, 2.4); +} diff --git a/fury/shaders/rt_odfs/srgb_to_linear_rgb.frag b/fury/shaders/rt_odfs/srgb_to_linear_rgb.frag new file mode 100644 index 000000000..e4c2ef22a --- /dev/null +++ b/fury/shaders/rt_odfs/srgb_to_linear_rgb.frag @@ -0,0 +1,4 @@ +vec3 srgb_to_linear_rgb(vec3 srgb) +{ + return vec3(srgb_to_linear(srgb.r), srgb_to_linear(srgb.g), srgb_to_linear(srgb.b)); +} diff --git a/fury/shaders/rt_odfs/tonemap.frag b/fury/shaders/rt_odfs/tonemap.frag new file mode 100644 index 000000000..dd6cdcacb --- /dev/null +++ b/fury/shaders/rt_odfs/tonemap.frag @@ -0,0 +1,5 @@ +vec3 tonemap(vec3 linear) +{ + float max_channel = max(max(1.0, linear.r), max(linear.g, linear.b)); + return linear * ((1.0 - 0.02 * log2(max_channel)) / max_channel); +} diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_10.frag b/fury/shaders/rt_odfs/tournier/eval_sh_10.frag new file mode 100644 index 000000000..bac867d98 --- /dev/null +++ b/fury/shaders/rt_odfs/tournier/eval_sh_10.frag @@ -0,0 +1,175 @@ +void eval_sh_10(out float out_shs[66], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + b = z2 * a - 0.250980392 * b; + a = b - 0.250773994 * a; + d = 233.240148813 * a; + out_shs[55] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[22] = c1 * d; + out_shs[20] = s1 * d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[37] = c1 * d; + out_shs[35] = s1 * d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + out_shs[56] = c1 * d; + out_shs[54] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[23] = c0 * d; + out_shs[19] = s0 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[38] = c0 * d; + out_shs[34] = s0 * d; + b = z2 * a - 0.235294118 * b; + a = b - 0.238390093 * a; + d = 272.365814381 * a; + out_shs[57] = c0 * d; + out_shs[53] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[24] = c1 * d; + out_shs[18] = s1 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[39] = c1 * d; + out_shs[33] = s1 * d; + a = z2 * b - 0.215686275 * a; + b = a - 0.222910217 * b; + d = -213.661323441 * b; + out_shs[58] = c1 * d; + out_shs[52] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[25] = c0 * d; + out_shs[17] = s0 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[40] = c0 * d; + out_shs[32] = s0 * d; + b = z2 * a - 0.188235294 * b; + a = b - 0.20123839 * a; + d = 151.081370682 * a; + out_shs[59] = c0 * d; + out_shs[51] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[26] = c1 * d; + out_shs[16] = s1 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[41] = c1 * d; + out_shs[31] = s1 * d; + a = z2 * b - 0.152941176 * a; + b = a - 0.173374613 * b; + d = -95.552248675 * b; + out_shs[60] = c1 * d; + out_shs[50] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[27] = c0 * d; + out_shs[15] = s0 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[42] = c0 * d; + out_shs[30] = s0 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + out_shs[61] = c0 * d; + out_shs[49] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[43] = c1 * d; + out_shs[29] = s1 * d; + a = (z2 - 5.88235294e-02) * z; + b = a - 9.90712074e-02 * z; + d = -25.910241313 * b; + out_shs[62] = c1 * d; + out_shs[48] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[44] = c0 * d; + out_shs[28] = s0 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + out_shs[63] = c0 * d; + out_shs[47] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + out_shs[64] = c1 * d; + out_shs[46] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + out_shs[65] = c0 * d; + out_shs[45] = s0 * d; +} diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_12.frag b/fury/shaders/rt_odfs/tournier/eval_sh_12.frag new file mode 100644 index 000000000..3bad86fd4 --- /dev/null +++ b/fury/shaders/rt_odfs/tournier/eval_sh_12.frag @@ -0,0 +1,238 @@ +void eval_sh_12(out float out_shs[91], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + b = z2 * a - 0.250980392 * b; + a = b - 0.250773994 * a; + d = 233.240148813 * a; + out_shs[55] = d; + b = z2 * a - 0.250626566 * b; + a = b - 0.250517598 * a; + d = 931.186918633 * a; + out_shs[78] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[22] = c1 * d; + out_shs[20] = s1 * d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[37] = c1 * d; + out_shs[35] = s1 * d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + out_shs[56] = c1 * d; + out_shs[54] = s1 * d; + a = z2 * b - 0.248120301 * a; + b = a - 0.248447205 * b; + d = -1265.233874957 * b; + out_shs[79] = c1 * d; + out_shs[77] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[23] = c0 * d; + out_shs[19] = s0 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[38] = c0 * d; + out_shs[34] = s0 * d; + b = z2 * a - 0.235294118 * b; + a = b - 0.238390093 * a; + d = 272.365814381 * a; + out_shs[57] = c0 * d; + out_shs[53] = s0 * d; + b = z2 * a - 0.240601504 * b; + a = b - 0.242236025 * a; + d = 1121.509962433 * a; + out_shs[80] = c0 * d; + out_shs[76] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[24] = c1 * d; + out_shs[18] = s1 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[39] = c1 * d; + out_shs[33] = s1 * d; + a = z2 * b - 0.215686275 * a; + b = a - 0.222910217 * b; + d = -213.661323441 * b; + out_shs[58] = c1 * d; + out_shs[52] = s1 * d; + a = z2 * b - 0.228070175 * a; + b = a - 0.231884058 * b; + d = -915.709049803 * b; + out_shs[81] = c1 * d; + out_shs[75] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[25] = c0 * d; + out_shs[17] = s0 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[40] = c0 * d; + out_shs[32] = s0 * d; + b = z2 * a - 0.188235294 * b; + a = b - 0.20123839 * a; + d = 151.081370682 * a; + out_shs[59] = c0 * d; + out_shs[51] = s0 * d; + b = z2 * a - 0.210526316 * b; + a = b - 0.217391304 * a; + d = 686.781787352 * a; + out_shs[82] = c0 * d; + out_shs[74] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[26] = c1 * d; + out_shs[16] = s1 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[41] = c1 * d; + out_shs[31] = s1 * d; + a = z2 * b - 0.152941176 * a; + b = a - 0.173374613 * b; + d = -95.552248675 * b; + out_shs[60] = c1 * d; + out_shs[50] = s1 * d; + a = z2 * b - 0.187969925 * a; + b = a - 0.198757764 * b; + d = -471.12841933 * b; + out_shs[83] = c1 * d; + out_shs[73] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[27] = c0 * d; + out_shs[15] = s0 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[42] = c0 * d; + out_shs[30] = s0 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + out_shs[61] = c0 * d; + out_shs[49] = s0 * d; + b = z2 * a - 0.160401003 * b; + a = b - 0.175983437 * a; + d = 293.800188384 * a; + out_shs[84] = c0 * d; + out_shs[72] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[43] = c1 * d; + out_shs[29] = s1 * d; + a = (z2 - 5.88235294e-02) * z; + b = a - 9.90712074e-02 * z; + d = -25.910241313 * b; + out_shs[62] = c1 * d; + out_shs[48] = s1 * d; + a = z2 * b - 0.127819549 * a; + b = a - 0.149068323 * b; + d = -165.101452729 * b; + out_shs[85] = c1 * d; + out_shs[71] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[44] = c0 * d; + out_shs[28] = s0 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + out_shs[63] = c0 * d; + out_shs[47] = s0 * d; + b = z2 * (a - 9.02255639e-02); + a = b - 0.118012422 * a; + d = 82.550726364 * a; + out_shs[86] = c0 * d; + out_shs[70] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + out_shs[64] = c1 * d; + out_shs[46] = s1 * d; + a = (z2 - 4.76190476e-02) * z; + b = a - 8.2815735e-02 * z; + d = -36.028090689 * b; + out_shs[87] = c1 * d; + out_shs[69] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + out_shs[65] = c0 * d; + out_shs[45] = s0 * d; + a = z2 - 4.34782609e-02; + d = 13.3042542 * a; + out_shs[88] = c0 * d; + out_shs[68] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.923210529 * z; + out_shs[89] = c1 * d; + out_shs[67] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.800821996; + out_shs[90] = c0 * d; + out_shs[66] = s0 * d; +} diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_2.frag b/fury/shaders/rt_odfs/tournier/eval_sh_2.frag new file mode 100644 index 000000000..a70493a22 --- /dev/null +++ b/fury/shaders/rt_odfs/tournier/eval_sh_2.frag @@ -0,0 +1,23 @@ +void eval_sh_2(out float out_shs[6], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; +} diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_4.frag b/fury/shaders/rt_odfs/tournier/eval_sh_4.frag new file mode 100644 index 000000000..15335ccad --- /dev/null +++ b/fury/shaders/rt_odfs/tournier/eval_sh_4.frag @@ -0,0 +1,46 @@ +void eval_sh_4(out float out_shs[15], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; +} diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_6.frag b/fury/shaders/rt_odfs/tournier/eval_sh_6.frag new file mode 100644 index 000000000..1051361dd --- /dev/null +++ b/fury/shaders/rt_odfs/tournier/eval_sh_6.frag @@ -0,0 +1,79 @@ +void eval_sh_6(out float out_shs[28], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[22] = c1 * d; + out_shs[20] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[23] = c0 * d; + out_shs[19] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[24] = c1 * d; + out_shs[18] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[25] = c0 * d; + out_shs[17] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[26] = c1 * d; + out_shs[16] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[27] = c0 * d; + out_shs[15] = s0 * d; +} diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_8.frag b/fury/shaders/rt_odfs/tournier/eval_sh_8.frag new file mode 100644 index 000000000..93c32e613 --- /dev/null +++ b/fury/shaders/rt_odfs/tournier/eval_sh_8.frag @@ -0,0 +1,122 @@ +void eval_sh_8(out float out_shs[45], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[22] = c1 * d; + out_shs[20] = s1 * d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[37] = c1 * d; + out_shs[35] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[23] = c0 * d; + out_shs[19] = s0 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[38] = c0 * d; + out_shs[34] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[24] = c1 * d; + out_shs[18] = s1 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[39] = c1 * d; + out_shs[33] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[25] = c0 * d; + out_shs[17] = s0 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[40] = c0 * d; + out_shs[32] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[26] = c1 * d; + out_shs[16] = s1 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[41] = c1 * d; + out_shs[31] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[27] = c0 * d; + out_shs[15] = s0 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[42] = c0 * d; + out_shs[30] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[43] = c1 * d; + out_shs[29] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[44] = c0 * d; + out_shs[28] = s0 * d; +} diff --git a/fury/shaders/utils/minmax_norm.glsl b/fury/shaders/utils/minmax_norm.glsl new file mode 100644 index 000000000..7992b53c7 --- /dev/null +++ b/fury/shaders/utils/minmax_norm.glsl @@ -0,0 +1,4 @@ +float coeffsNorm(float coef, float min, float max, float a, float b) +{ + return (coef - min) * ((b - a) / (max - min)) + a; +} \ No newline at end of file From 0e6dc18f7490be72451d3026adab419f304d59a6 Mon Sep 17 00:00:00 2001 From: tvcastillod Date: Fri, 23 Feb 2024 11:19:51 -0500 Subject: [PATCH 089/118] adjusted scaling --- docs/experimental/SH-ODF experimental/odf_example.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/docs/experimental/SH-ODF experimental/odf_example.py b/docs/experimental/SH-ODF experimental/odf_example.py index 3b6c60469..e16858211 100644 --- a/docs/experimental/SH-ODF experimental/odf_example.py +++ b/docs/experimental/SH-ODF experimental/odf_example.py @@ -22,10 +22,6 @@ coeffs = coeffs[:, :, :].reshape((x * y * z, s)) n_glyphs = coeffs.shape[0] - max_val = coeffs.min(axis=1) - total = np.sum(abs(coeffs), axis=1) - coeffs = np.dot(np.diag(1 / total), coeffs) * 1.7 - - odf_actor = actor.odf(centers=centers, coeffs=coeffs) + odf_actor = actor.odf(centers=centers, coeffs=coeffs, scales=1.0) show_man.scene.add(odf_actor) show_man.start() \ No newline at end of file From 54fbd0db21fe9a2060bd7c94b469dc22ad5f050d Mon Sep 17 00:00:00 2001 From: tvcastillod Date: Tue, 27 Feb 2024 13:01:14 -0500 Subject: [PATCH 090/118] reorganized files --- fury/actors/odf.py | 24 +- .../linear_rgb_to_srgb.frag | 0 .../{rt_odfs => lighting}/linear_to_srgb.frag | 0 .../{rt_odfs => lighting}/srgb_to_linear.frag | 0 .../srgb_to_linear_rgb.frag | 0 .../{ => descoteaux}/eval_sh_grad_10.frag | 0 .../{ => descoteaux}/eval_sh_grad_12.frag | 0 .../{ => descoteaux}/eval_sh_grad_2.frag | 0 .../{ => descoteaux}/eval_sh_grad_4.frag | 0 .../{ => descoteaux}/eval_sh_grad_6.frag | 0 .../{ => descoteaux}/eval_sh_grad_8.frag | 0 .../tournier/eval_sh_grad_10 copy.frag | 430 +++++++++++++ .../tournier/eval_sh_grad_12 copy.frag | 591 ++++++++++++++++++ .../rt_odfs/tournier/eval_sh_grad_2 copy.frag | 46 ++ .../rt_odfs/tournier/eval_sh_grad_4 copy.frag | 103 +++ .../rt_odfs/tournier/eval_sh_grad_6 copy.frag | 186 ++++++ .../rt_odfs/tournier/eval_sh_grad_8 copy.frag | 295 +++++++++ .../{rt_odfs => utils}/find_roots.frag | 0 .../{rt_odfs => utils}/newton_bisection.frag | 0 19 files changed, 1663 insertions(+), 12 deletions(-) rename fury/shaders/{rt_odfs => lighting}/linear_rgb_to_srgb.frag (100%) rename fury/shaders/{rt_odfs => lighting}/linear_to_srgb.frag (100%) rename fury/shaders/{rt_odfs => lighting}/srgb_to_linear.frag (100%) rename fury/shaders/{rt_odfs => lighting}/srgb_to_linear_rgb.frag (100%) rename fury/shaders/rt_odfs/{ => descoteaux}/eval_sh_grad_10.frag (100%) rename fury/shaders/rt_odfs/{ => descoteaux}/eval_sh_grad_12.frag (100%) rename fury/shaders/rt_odfs/{ => descoteaux}/eval_sh_grad_2.frag (100%) rename fury/shaders/rt_odfs/{ => descoteaux}/eval_sh_grad_4.frag (100%) rename fury/shaders/rt_odfs/{ => descoteaux}/eval_sh_grad_6.frag (100%) rename fury/shaders/rt_odfs/{ => descoteaux}/eval_sh_grad_8.frag (100%) create mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_grad_10 copy.frag create mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_grad_12 copy.frag create mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_grad_2 copy.frag create mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_grad_4 copy.frag create mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_grad_6 copy.frag create mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_grad_8 copy.frag rename fury/shaders/{rt_odfs => utils}/find_roots.frag (100%) rename fury/shaders/{rt_odfs => utils}/newton_bisection.frag (100%) diff --git a/fury/actors/odf.py b/fury/actors/odf.py index a6d991033..e8a762c55 100644 --- a/fury/actors/odf.py +++ b/fury/actors/odf.py @@ -206,27 +206,27 @@ def sh_odf(centers, coeffs, basis_type, scales, opacity): os.path.join("rt_odfs", basis_type, "eval_sh_12.frag")) eval_sh_grad_2 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_2.frag") + os.path.join("rt_odfs/descoteaux", "eval_sh_grad_2.frag") ) eval_sh_grad_4 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_4.frag") + os.path.join("rt_odfs/descoteaux", "eval_sh_grad_4.frag") ) eval_sh_grad_6 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_6.frag") + os.path.join("rt_odfs/descoteaux", "eval_sh_grad_6.frag") ) eval_sh_grad_8 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_8.frag") + os.path.join("rt_odfs/descoteaux", "eval_sh_grad_8.frag") ) eval_sh_grad_10 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_10.frag") + os.path.join("rt_odfs/descoteaux", "eval_sh_grad_10.frag") ) eval_sh_grad_12 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_12.frag") + os.path.join("rt_odfs/descoteaux", "eval_sh_grad_12.frag") ) # Searches a single root of a polynomial within a given interval. @@ -246,13 +246,13 @@ def sh_odf(centers, coeffs, basis_type, scales, opacity): # # return true if a root was found, false if no root exists. newton_bisection = import_fury_shader( - os.path.join("rt_odfs", "newton_bisection.frag") + os.path.join("utils", "newton_bisection.frag") ) # Finds all roots of the given polynomial in the interval [begin, end] and # writes them to out_roots. Some entries will be NO_INTERSECTION but other # than that the array is sorted. The last entry is always NO_INTERSECTION. - find_roots = import_fury_shader(os.path.join("rt_odfs", "find_roots.frag")) + find_roots = import_fury_shader(os.path.join("utils", "find_roots.frag")) # Evaluates the spherical harmonics basis in bands 0, 2, ..., SH_DEGREE. # Conventions are as in the following paper. @@ -304,22 +304,22 @@ def sh_odf(centers, coeffs, basis_type, scales, opacity): # Applies the non-linearity that maps linear RGB to sRGB linear_to_srgb = import_fury_shader( - os.path.join("rt_odfs", "linear_to_srgb.frag") + os.path.join("lighting", "linear_to_srgb.frag") ) # Inverse of linear_to_srgb() srgb_to_linear = import_fury_shader( - os.path.join("rt_odfs", "srgb_to_linear.frag") + os.path.join("lighting", "srgb_to_linear.frag") ) # Turns a linear RGB color (i.e. rec. 709) into sRGB linear_rgb_to_srgb = import_fury_shader( - os.path.join("rt_odfs", "linear_rgb_to_srgb.frag") + os.path.join("lighting", "linear_rgb_to_srgb.frag") ) # Inverse of linear_rgb_to_srgb() srgb_to_linear_rgb = import_fury_shader( - os.path.join("rt_odfs", "srgb_to_linear_rgb.frag") + os.path.join("lighting", "srgb_to_linear_rgb.frag") ) # Logarithmic tonemapping operator. Input and output are linear RGB. diff --git a/fury/shaders/rt_odfs/linear_rgb_to_srgb.frag b/fury/shaders/lighting/linear_rgb_to_srgb.frag similarity index 100% rename from fury/shaders/rt_odfs/linear_rgb_to_srgb.frag rename to fury/shaders/lighting/linear_rgb_to_srgb.frag diff --git a/fury/shaders/rt_odfs/linear_to_srgb.frag b/fury/shaders/lighting/linear_to_srgb.frag similarity index 100% rename from fury/shaders/rt_odfs/linear_to_srgb.frag rename to fury/shaders/lighting/linear_to_srgb.frag diff --git a/fury/shaders/rt_odfs/srgb_to_linear.frag b/fury/shaders/lighting/srgb_to_linear.frag similarity index 100% rename from fury/shaders/rt_odfs/srgb_to_linear.frag rename to fury/shaders/lighting/srgb_to_linear.frag diff --git a/fury/shaders/rt_odfs/srgb_to_linear_rgb.frag b/fury/shaders/lighting/srgb_to_linear_rgb.frag similarity index 100% rename from fury/shaders/rt_odfs/srgb_to_linear_rgb.frag rename to fury/shaders/lighting/srgb_to_linear_rgb.frag diff --git a/fury/shaders/rt_odfs/eval_sh_grad_10.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_10.frag similarity index 100% rename from fury/shaders/rt_odfs/eval_sh_grad_10.frag rename to fury/shaders/rt_odfs/descoteaux/eval_sh_grad_10.frag diff --git a/fury/shaders/rt_odfs/eval_sh_grad_12.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_12.frag similarity index 100% rename from fury/shaders/rt_odfs/eval_sh_grad_12.frag rename to fury/shaders/rt_odfs/descoteaux/eval_sh_grad_12.frag diff --git a/fury/shaders/rt_odfs/eval_sh_grad_2.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_2.frag similarity index 100% rename from fury/shaders/rt_odfs/eval_sh_grad_2.frag rename to fury/shaders/rt_odfs/descoteaux/eval_sh_grad_2.frag diff --git a/fury/shaders/rt_odfs/eval_sh_grad_4.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_4.frag similarity index 100% rename from fury/shaders/rt_odfs/eval_sh_grad_4.frag rename to fury/shaders/rt_odfs/descoteaux/eval_sh_grad_4.frag diff --git a/fury/shaders/rt_odfs/eval_sh_grad_6.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_6.frag similarity index 100% rename from fury/shaders/rt_odfs/eval_sh_grad_6.frag rename to fury/shaders/rt_odfs/descoteaux/eval_sh_grad_6.frag diff --git a/fury/shaders/rt_odfs/eval_sh_grad_8.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_8.frag similarity index 100% rename from fury/shaders/rt_odfs/eval_sh_grad_8.frag rename to fury/shaders/rt_odfs/descoteaux/eval_sh_grad_8.frag diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_10 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_10 copy.frag new file mode 100644 index 000000000..c9e6b0d8d --- /dev/null +++ b/fury/shaders/rt_odfs/tournier/eval_sh_grad_10 copy.frag @@ -0,0 +1,430 @@ +void eval_sh_grad_10(out float out_shs[66], out vec3 out_grads[66], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + b = z2 * a - 0.250980392 * b; + a = b - 0.250773994 * a; + d = 233.240148813 * a; + out_shs[55] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + out_grads[4][0] = c0 * d; + out_grads[2][0] = s0 * d; + out_grads[4][1] = s0 * d; + out_grads[2][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + out_grads[11][0] = c0 * d; + out_grads[9][0] = s0 * d; + out_grads[11][1] = s0 * d; + out_grads[9][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[22] = c1 * d; + out_shs[20] = s1 * d; + out_grads[22][0] = c0 * d; + out_grads[20][0] = s0 * d; + out_grads[22][1] = s0 * d; + out_grads[20][1] = c0 * d; + d = 88.106914343 * b; + out_grads[21][2] = d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[37] = c1 * d; + out_shs[35] = s1 * d; + out_grads[37][0] = c0 * d; + out_grads[35][0] = s0 * d; + out_grads[37][1] = s0 * d; + out_grads[35][1] = c0 * d; + d = 467.786944906 * b; + out_grads[36][2] = d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + out_shs[56] = c1 * d; + out_shs[54] = s1 * d; + out_grads[56][0] = c0 * d; + out_grads[54][0] = s0 * d; + out_grads[56][1] = s0 * d; + out_grads[54][1] = c0 * d; + d = 2332.401488133 * b; + out_grads[55][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + d = 1.092548431; + out_grads[5][0] = c1 * d; + out_grads[1][0] = s1 * d; + out_grads[5][1] = -s1 * d; + out_grads[1][1] = c1 * d; + d = -1.092548431; + out_grads[4][2] = c1 * d; + out_grads[2][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + d = 6.62322287 * a; + out_grads[12][0] = c1 * d; + out_grads[8][0] = s1 * d; + out_grads[12][1] = -s1 * d; + out_grads[8][1] = c1 * d; + d = -14.049977415 * a; + out_grads[11][2] = c1 * d; + out_grads[9][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[23] = c0 * d; + out_shs[19] = s0 * d; + d = 30.399773564 * a; + out_grads[23][0] = c1 * d; + out_grads[19][0] = s1 * d; + out_grads[23][1] = -s1 * d; + out_grads[19][1] = c1 * d; + d = -96.132524816 * a; + out_grads[22][2] = c1 * d; + out_grads[20][2] = s1 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[38] = c0 * d; + out_shs[34] = s0 * d; + d = 130.459545912 * a; + out_grads[38][0] = c1 * d; + out_grads[34][0] = s1 * d; + out_grads[38][1] = -s1 * d; + out_grads[34][1] = c1 * d; + d = -545.751435723 * a; + out_grads[37][2] = c1 * d; + out_grads[35][2] = s1 * d; + b = z2 * a - 0.235294118 * b; + a = b - 0.238390093 * a; + d = 272.365814381 * a; + out_shs[57] = c0 * d; + out_shs[53] = s0 * d; + d = 544.731628762 * a; + out_grads[57][0] = c1 * d; + out_grads[53][0] = s1 * d; + out_grads[57][1] = -s1 * d; + out_grads[53][1] = c1 * d; + d = -2830.508572514 * a; + out_grads[56][2] = c1 * d; + out_grads[54][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; + d = -5.310392309 * z; + out_grads[13][0] = c0 * d; + out_grads[7][0] = s0 * d; + out_grads[13][1] = s0 * d; + out_grads[7][1] = c0 * d; + d = 6.62322287 * z; + out_grads[12][2] = c0 * d; + out_grads[8][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[24] = c1 * d; + out_shs[18] = s1 * d; + d = -30.399773564 * b; + out_grads[24][0] = c0 * d; + out_grads[18][0] = s0 * d; + out_grads[24][1] = s0 * d; + out_grads[18][1] = c0 * d; + d = 60.799547128 * b; + out_grads[23][2] = c0 * d; + out_grads[19][2] = s0 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[39] = c1 * d; + out_shs[33] = s1 * d; + d = -144.52614017 * b; + out_grads[39][0] = c0 * d; + out_grads[33][0] = s0 * d; + out_grads[39][1] = s0 * d; + out_grads[33][1] = c0 * d; + d = 391.378637737 * b; + out_grads[38][2] = c0 * d; + out_grads[34][2] = s0 * d; + a = z2 * b - 0.215686275 * a; + b = a - 0.222910217 * b; + d = -213.661323441 * b; + out_shs[58] = c1 * d; + out_shs[52] = s1 * d; + d = -640.983970322 * b; + out_grads[58][0] = c0 * d; + out_grads[52][0] = s0 * d; + out_grads[58][1] = s0 * d; + out_grads[52][1] = c0 * d; + d = 2178.926515046 * b; + out_grads[57][2] = c0 * d; + out_grads[53][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; + d = 2.503342942; + out_grads[14][0] = c1 * d; + out_grads[6][0] = s1 * d; + out_grads[14][1] = -s1 * d; + out_grads[6][1] = c1 * d; + d = -1.77013077; + out_grads[13][2] = c1 * d; + out_grads[7][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[25] = c0 * d; + out_shs[17] = s0 * d; + d = 22.200855632 * a; + out_grads[25][0] = c1 * d; + out_grads[17][0] = s1 * d; + out_grads[25][1] = -s1 * d; + out_grads[17][1] = c1 * d; + d = -30.399773564 * a; + out_grads[24][2] = c1 * d; + out_grads[18][2] = s1 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[40] = c0 * d; + out_shs[32] = s0 * d; + d = 124.388296437 * a; + out_grads[40][0] = c1 * d; + out_grads[32][0] = s1 * d; + out_grads[40][1] = -s1 * d; + out_grads[32][1] = c1 * d; + d = -240.876900283 * a; + out_grads[39][2] = c1 * d; + out_grads[33][2] = s1 * d; + b = z2 * a - 0.188235294 * b; + a = b - 0.20123839 * a; + d = 151.081370682 * a; + out_shs[59] = c0 * d; + out_shs[51] = s0 * d; + d = 604.325482728 * a; + out_grads[59][0] = c1 * d; + out_grads[51][0] = s1 * d; + out_grads[59][1] = -s1 * d; + out_grads[51][1] = c1 * d; + d = -1495.629264084 * a; + out_grads[58][2] = c1 * d; + out_grads[52][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[26] = c1 * d; + out_shs[16] = s1 * d; + d = -11.833095811 * z; + out_grads[26][0] = c0 * d; + out_grads[16][0] = s0 * d; + out_grads[26][1] = s0 * d; + out_grads[16][1] = c0 * d; + d = 11.100427816 * z; + out_grads[25][2] = c0 * d; + out_grads[17][2] = s0 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[41] = c1 * d; + out_shs[31] = s1 * d; + d = -86.247765552 * b; + out_grads[41][0] = c0 * d; + out_grads[31][0] = s0 * d; + out_grads[41][1] = s0 * d; + out_grads[31][1] = c0 * d; + d = 124.388296437 * b; + out_grads[40][2] = c0 * d; + out_grads[32][2] = s0 * d; + a = z2 * b - 0.152941176 * a; + b = a - 0.173374613 * b; + d = -95.552248675 * b; + out_shs[60] = c1 * d; + out_shs[50] = s1 * d; + d = -477.761243376 * b; + out_grads[60][0] = c0 * d; + out_grads[50][0] = s0 * d; + out_grads[60][1] = s0 * d; + out_grads[50][1] = c0 * d; + d = 906.488224092 * b; + out_grads[59][2] = c0 * d; + out_grads[51][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[27] = c0 * d; + out_shs[15] = s0 * d; + d = 4.099104631; + out_grads[27][0] = c1 * d; + out_grads[15][0] = s1 * d; + out_grads[27][1] = -s1 * d; + out_grads[15][1] = c1 * d; + d = -2.366619162; + out_grads[26][2] = c1 * d; + out_grads[16][2] = s1 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[42] = c0 * d; + out_shs[30] = s0 * d; + d = 47.909948945 * a; + out_grads[42][0] = c1 * d; + out_grads[30][0] = s1 * d; + out_grads[42][1] = -s1 * d; + out_grads[30][1] = c1 * d; + d = -51.748659331 * a; + out_grads[41][2] = c1 * d; + out_grads[31][2] = s1 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + out_shs[61] = c0 * d; + out_shs[49] = s0 * d; + d = 320.491985161 * a; + out_grads[61][0] = c1 * d; + out_grads[49][0] = s1 * d; + out_grads[61][1] = -s1 * d; + out_grads[49][1] = c1 * d; + d = -477.761243376 * a; + out_grads[60][2] = c1 * d; + out_grads[50][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[43] = c1 * d; + out_shs[29] = s1 * d; + d = -20.409946485 * z; + out_grads[43][0] = c0 * d; + out_grads[29][0] = s0 * d; + out_grads[43][1] = s0 * d; + out_grads[29][1] = c0 * d; + d = 15.969982982 * z; + out_grads[42][2] = c0 * d; + out_grads[30][2] = s0 * d; + a = (z2 - 5.88235294e-02) * z; + b = a - 9.90712074e-02 * z; + d = -25.910241313 * b; + out_shs[62] = c1 * d; + out_shs[48] = s1 * d; + d = -181.371689194 * b; + out_grads[62][0] = c0 * d; + out_grads[48][0] = s0 * d; + out_grads[62][1] = s0 * d; + out_grads[48][1] = c0 * d; + d = 213.661323441 * b; + out_grads[61][2] = c0 * d; + out_grads[49][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[44] = c0 * d; + out_shs[28] = s0 * d; + d = 5.831413281; + out_grads[44][0] = c1 * d; + out_grads[28][0] = s1 * d; + out_grads[44][1] = -s1 * d; + out_grads[28][1] = c1 * d; + d = -2.915706641; + out_grads[43][2] = c1 * d; + out_grads[29][2] = s1 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + out_shs[63] = c0 * d; + out_shs[47] = s0 * d; + d = 84.622493774 * a; + out_grads[63][0] = c1 * d; + out_grads[47][0] = s1 * d; + out_grads[63][1] = -s1 * d; + out_grads[47][1] = c1 * d; + d = -77.73072394 * a; + out_grads[62][2] = c1 * d; + out_grads[48][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + out_shs[64] = c1 * d; + out_shs[46] = s1 * d; + d = -30.887057699 * z; + out_grads[64][0] = c0 * d; + out_grads[46][0] = s0 * d; + out_grads[64][1] = s0 * d; + out_grads[46][1] = c0 * d; + d = 21.155623443 * z; + out_grads[63][2] = c0 * d; + out_grads[47][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + out_shs[65] = c0 * d; + out_shs[45] = s0 * d; + d = 7.673951182; + out_grads[65][0] = c1 * d; + out_grads[45][0] = s1 * d; + out_grads[65][1] = -s1 * d; + out_grads[45][1] = c1 * d; + d = -3.4318953; + out_grads[64][2] = c1 * d; + out_grads[46][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; + out_grads[6][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[14][2] = 0.0; + out_grads[15][2] = 0.0; + out_grads[21][0] = 0.0; + out_grads[21][1] = 0.0; + out_grads[27][2] = 0.0; + out_grads[28][2] = 0.0; + out_grads[36][0] = 0.0; + out_grads[36][1] = 0.0; + out_grads[44][2] = 0.0; + out_grads[45][2] = 0.0; + out_grads[55][0] = 0.0; + out_grads[55][1] = 0.0; + out_grads[65][2] = 0.0; +} diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_12 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_12 copy.frag new file mode 100644 index 000000000..35c2a3617 --- /dev/null +++ b/fury/shaders/rt_odfs/tournier/eval_sh_grad_12 copy.frag @@ -0,0 +1,591 @@ +void eval_sh_grad_12(out float out_shs[91], out vec3 out_grads[91], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + b = z2 * a - 0.250980392 * b; + a = b - 0.250773994 * a; + d = 233.240148813 * a; + out_shs[55] = d; + b = z2 * a - 0.250626566 * b; + a = b - 0.250517598 * a; + d = 931.186918633 * a; + out_shs[78] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + out_grads[4][0] = c0 * d; + out_grads[2][0] = s0 * d; + out_grads[4][1] = s0 * d; + out_grads[2][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + out_grads[11][0] = c0 * d; + out_grads[9][0] = s0 * d; + out_grads[11][1] = s0 * d; + out_grads[9][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[22] = c1 * d; + out_shs[20] = s1 * d; + out_grads[22][0] = c0 * d; + out_grads[20][0] = s0 * d; + out_grads[22][1] = s0 * d; + out_grads[20][1] = c0 * d; + d = 88.106914343 * b; + out_grads[21][2] = d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[37] = c1 * d; + out_shs[35] = s1 * d; + out_grads[37][0] = c0 * d; + out_grads[35][0] = s0 * d; + out_grads[37][1] = s0 * d; + out_grads[35][1] = c0 * d; + d = 467.786944906 * b; + out_grads[36][2] = d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + out_shs[56] = c1 * d; + out_shs[54] = s1 * d; + out_grads[56][0] = c0 * d; + out_grads[54][0] = s0 * d; + out_grads[56][1] = s0 * d; + out_grads[54][1] = c0 * d; + d = 2332.401488133 * b; + out_grads[55][2] = d; + a = z2 * b - 0.248120301 * a; + b = a - 0.248447205 * b; + d = -1265.233874957 * b; + out_shs[79] = c1 * d; + out_shs[77] = s1 * d; + out_grads[79][0] = c0 * d; + out_grads[77][0] = s0 * d; + out_grads[79][1] = s0 * d; + out_grads[77][1] = c0 * d; + d = 11174.243023595 * b; + out_grads[78][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + d = 1.092548431; + out_grads[5][0] = c1 * d; + out_grads[1][0] = s1 * d; + out_grads[5][1] = -s1 * d; + out_grads[1][1] = c1 * d; + d = -1.092548431; + out_grads[4][2] = c1 * d; + out_grads[2][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + d = 6.62322287 * a; + out_grads[12][0] = c1 * d; + out_grads[8][0] = s1 * d; + out_grads[12][1] = -s1 * d; + out_grads[8][1] = c1 * d; + d = -14.049977415 * a; + out_grads[11][2] = c1 * d; + out_grads[9][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[23] = c0 * d; + out_shs[19] = s0 * d; + d = 30.399773564 * a; + out_grads[23][0] = c1 * d; + out_grads[19][0] = s1 * d; + out_grads[23][1] = -s1 * d; + out_grads[19][1] = c1 * d; + d = -96.132524816 * a; + out_grads[22][2] = c1 * d; + out_grads[20][2] = s1 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[38] = c0 * d; + out_shs[34] = s0 * d; + d = 130.459545912 * a; + out_grads[38][0] = c1 * d; + out_grads[34][0] = s1 * d; + out_grads[38][1] = -s1 * d; + out_grads[34][1] = c1 * d; + d = -545.751435723 * a; + out_grads[37][2] = c1 * d; + out_grads[35][2] = s1 * d; + b = z2 * a - 0.235294118 * b; + a = b - 0.238390093 * a; + d = 272.365814381 * a; + out_shs[57] = c0 * d; + out_shs[53] = s0 * d; + d = 544.731628762 * a; + out_grads[57][0] = c1 * d; + out_grads[53][0] = s1 * d; + out_grads[57][1] = -s1 * d; + out_grads[53][1] = c1 * d; + d = -2830.508572514 * a; + out_grads[56][2] = c1 * d; + out_grads[54][2] = s1 * d; + b = z2 * a - 0.240601504 * b; + a = b - 0.242236025 * a; + d = 1121.509962433 * a; + out_shs[80] = c0 * d; + out_shs[76] = s0 * d; + d = 2243.019924866 * a; + out_grads[80][0] = c1 * d; + out_grads[76][0] = s1 * d; + out_grads[80][1] = -s1 * d; + out_grads[76][1] = c1 * d; + d = -13917.572624524 * a; + out_grads[79][2] = c1 * d; + out_grads[77][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; + d = -5.310392309 * z; + out_grads[13][0] = c0 * d; + out_grads[7][0] = s0 * d; + out_grads[13][1] = s0 * d; + out_grads[7][1] = c0 * d; + d = 6.62322287 * z; + out_grads[12][2] = c0 * d; + out_grads[8][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[24] = c1 * d; + out_shs[18] = s1 * d; + d = -30.399773564 * b; + out_grads[24][0] = c0 * d; + out_grads[18][0] = s0 * d; + out_grads[24][1] = s0 * d; + out_grads[18][1] = c0 * d; + d = 60.799547128 * b; + out_grads[23][2] = c0 * d; + out_grads[19][2] = s0 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[39] = c1 * d; + out_shs[33] = s1 * d; + d = -144.52614017 * b; + out_grads[39][0] = c0 * d; + out_grads[33][0] = s0 * d; + out_grads[39][1] = s0 * d; + out_grads[33][1] = c0 * d; + d = 391.378637737 * b; + out_grads[38][2] = c0 * d; + out_grads[34][2] = s0 * d; + a = z2 * b - 0.215686275 * a; + b = a - 0.222910217 * b; + d = -213.661323441 * b; + out_shs[58] = c1 * d; + out_shs[52] = s1 * d; + d = -640.983970322 * b; + out_grads[58][0] = c0 * d; + out_grads[52][0] = s0 * d; + out_grads[58][1] = s0 * d; + out_grads[52][1] = c0 * d; + d = 2178.926515046 * b; + out_grads[57][2] = c0 * d; + out_grads[53][2] = s0 * d; + a = z2 * b - 0.228070175 * a; + b = a - 0.231884058 * b; + d = -915.709049803 * b; + out_shs[81] = c1 * d; + out_shs[75] = s1 * d; + d = -2747.127149409 * b; + out_grads[81][0] = c0 * d; + out_grads[75][0] = s0 * d; + out_grads[81][1] = s0 * d; + out_grads[75][1] = c0 * d; + d = 11215.099624332 * b; + out_grads[80][2] = c0 * d; + out_grads[76][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; + d = 2.503342942; + out_grads[14][0] = c1 * d; + out_grads[6][0] = s1 * d; + out_grads[14][1] = -s1 * d; + out_grads[6][1] = c1 * d; + d = -1.77013077; + out_grads[13][2] = c1 * d; + out_grads[7][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[25] = c0 * d; + out_shs[17] = s0 * d; + d = 22.200855632 * a; + out_grads[25][0] = c1 * d; + out_grads[17][0] = s1 * d; + out_grads[25][1] = -s1 * d; + out_grads[17][1] = c1 * d; + d = -30.399773564 * a; + out_grads[24][2] = c1 * d; + out_grads[18][2] = s1 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[40] = c0 * d; + out_shs[32] = s0 * d; + d = 124.388296437 * a; + out_grads[40][0] = c1 * d; + out_grads[32][0] = s1 * d; + out_grads[40][1] = -s1 * d; + out_grads[32][1] = c1 * d; + d = -240.876900283 * a; + out_grads[39][2] = c1 * d; + out_grads[33][2] = s1 * d; + b = z2 * a - 0.188235294 * b; + a = b - 0.20123839 * a; + d = 151.081370682 * a; + out_shs[59] = c0 * d; + out_shs[51] = s0 * d; + d = 604.325482728 * a; + out_grads[59][0] = c1 * d; + out_grads[51][0] = s1 * d; + out_grads[59][1] = -s1 * d; + out_grads[51][1] = c1 * d; + d = -1495.629264084 * a; + out_grads[58][2] = c1 * d; + out_grads[52][2] = s1 * d; + b = z2 * a - 0.210526316 * b; + a = b - 0.217391304 * a; + d = 686.781787352 * a; + out_shs[82] = c0 * d; + out_shs[74] = s0 * d; + d = 2747.127149409 * a; + out_grads[82][0] = c1 * d; + out_grads[74][0] = s1 * d; + out_grads[82][1] = -s1 * d; + out_grads[74][1] = c1 * d; + d = -8241.381448228 * a; + out_grads[81][2] = -c1 * d; + out_grads[75][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[26] = c1 * d; + out_shs[16] = s1 * d; + d = -11.833095811 * z; + out_grads[26][0] = c0 * d; + out_grads[16][0] = s0 * d; + out_grads[26][1] = s0 * d; + out_grads[16][1] = c0 * d; + d = 11.100427816 * z; + out_grads[25][2] = c0 * d; + out_grads[17][2] = s0 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[41] = c1 * d; + out_shs[31] = s1 * d; + d = -86.247765552 * b; + out_grads[41][0] = c0 * d; + out_grads[31][0] = s0 * d; + out_grads[41][1] = s0 * d; + out_grads[31][1] = c0 * d; + d = 124.388296437 * b; + out_grads[40][2] = c0 * d; + out_grads[32][2] = s0 * d; + a = z2 * b - 0.152941176 * a; + b = a - 0.173374613 * b; + d = -95.552248675 * b; + out_shs[60] = c1 * d; + out_shs[50] = s1 * d; + d = -477.761243376 * b; + out_grads[60][0] = c0 * d; + out_grads[50][0] = s0 * d; + out_grads[60][1] = s0 * d; + out_grads[50][1] = c0 * d; + d = 906.488224092 * b; + out_grads[59][2] = c0 * d; + out_grads[51][2] = s0 * d; + a = z2 * b - 0.187969925 * a; + b = a - 0.198757764 * b; + d = -471.12841933 * b; + out_shs[83] = c1 * d; + out_shs[73] = s1 * d; + d = -2355.642096651 * b; + out_grads[83][0] = c0 * d; + out_grads[73][0] = s0 * d; + out_grads[83][1] = s0 * d; + out_grads[73][1] = c0 * d; + d = 5494.254298819 * b; + out_grads[82][2] = c0 * d; + out_grads[74][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[27] = c0 * d; + out_shs[15] = s0 * d; + d = 4.099104631; + out_grads[27][0] = c1 * d; + out_grads[15][0] = s1 * d; + out_grads[27][1] = -s1 * d; + out_grads[15][1] = c1 * d; + d = -2.366619162; + out_grads[26][2] = c1 * d; + out_grads[16][2] = s1 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[42] = c0 * d; + out_shs[30] = s0 * d; + d = 47.909948945 * a; + out_grads[42][0] = c1 * d; + out_grads[30][0] = s1 * d; + out_grads[42][1] = -s1 * d; + out_grads[30][1] = c1 * d; + d = -51.748659331 * a; + out_grads[41][2] = c1 * d; + out_grads[31][2] = s1 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + out_shs[61] = c0 * d; + out_shs[49] = s0 * d; + d = 320.491985161 * a; + out_grads[61][0] = c1 * d; + out_grads[49][0] = s1 * d; + out_grads[61][1] = -s1 * d; + out_grads[49][1] = c1 * d; + d = -477.761243376 * a; + out_grads[60][2] = c1 * d; + out_grads[50][2] = s1 * d; + b = z2 * a - 0.160401003 * b; + a = b - 0.175983437 * a; + d = 293.800188384 * a; + out_shs[84] = c0 * d; + out_shs[72] = s0 * d; + d = 1762.801130306 * a; + out_grads[84][0] = c1 * d; + out_grads[72][0] = s1 * d; + out_grads[84][1] = -s1 * d; + out_grads[72][1] = c1 * d; + d = -3297.898935312 * a; + out_grads[83][2] = c1 * d; + out_grads[73][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[43] = c1 * d; + out_shs[29] = s1 * d; + d = -20.409946485 * z; + out_grads[43][0] = c0 * d; + out_grads[29][0] = s0 * d; + out_grads[43][1] = s0 * d; + out_grads[29][1] = c0 * d; + d = 15.969982982 * z; + out_grads[42][2] = c0 * d; + out_grads[30][2] = s0 * d; + a = (z2 - 5.88235294e-02) * z; + b = a - 9.90712074e-02 * z; + d = -25.910241313 * b; + out_shs[62] = c1 * d; + out_shs[48] = s1 * d; + d = -181.371689194 * b; + out_grads[62][0] = c0 * d; + out_grads[48][0] = s0 * d; + out_grads[62][1] = s0 * d; + out_grads[48][1] = c0 * d; + d = 213.661323441 * b; + out_grads[61][2] = c0 * d; + out_grads[49][2] = s0 * d; + a = z2 * b - 0.127819549 * a; + b = a - 0.149068323 * b; + d = -165.101452729 * b; + out_shs[85] = c1 * d; + out_shs[71] = s1 * d; + d = -1155.7101691 * b; + out_grads[85][0] = c0 * d; + out_grads[71][0] = s0 * d; + out_grads[85][1] = s0 * d; + out_grads[71][1] = c0 * d; + d = 1762.801130306 * b; + out_grads[84][2] = c0 * d; + out_grads[72][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[44] = c0 * d; + out_shs[28] = s0 * d; + d = 5.831413281; + out_grads[44][0] = c1 * d; + out_grads[28][0] = s1 * d; + out_grads[44][1] = -s1 * d; + out_grads[28][1] = c1 * d; + d = -2.915706641; + out_grads[43][2] = c1 * d; + out_grads[29][2] = s1 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + out_shs[63] = c0 * d; + out_shs[47] = s0 * d; + d = 84.622493774 * a; + out_grads[63][0] = c1 * d; + out_grads[47][0] = s1 * d; + out_grads[63][1] = -s1 * d; + out_grads[47][1] = c1 * d; + d = -77.73072394 * a; + out_grads[62][2] = c1 * d; + out_grads[48][2] = s1 * d; + b = z2 * (a - 9.02255639e-02); + a = b - 0.118012422 * a; + d = 82.550726364 * a; + out_shs[86] = c0 * d; + out_shs[70] = s0 * d; + d = 660.405810914 * a; + out_grads[86][0] = c1 * d; + out_grads[70][0] = s1 * d; + out_grads[86][1] = -s1 * d; + out_grads[70][1] = c1 * d; + d = -825.507263643 * a; + out_grads[85][2] = c1 * d; + out_grads[71][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + out_shs[64] = c1 * d; + out_shs[46] = s1 * d; + d = -30.887057699 * z; + out_grads[64][0] = c0 * d; + out_grads[46][0] = s0 * d; + out_grads[64][1] = s0 * d; + out_grads[46][1] = c0 * d; + d = 21.155623443 * z; + out_grads[63][2] = c0 * d; + out_grads[47][2] = s0 * d; + a = (z2 - 4.76190476e-02) * z; + b = a - 8.2815735e-02 * z; + d = -36.028090689 * b; + out_shs[87] = c1 * d; + out_shs[69] = s1 * d; + d = -324.252816204 * b; + out_grads[87][0] = c0 * d; + out_grads[69][0] = s0 * d; + out_grads[87][1] = s0 * d; + out_grads[69][1] = c0 * d; + d = 330.202905457 * b; + out_grads[86][2] = c0 * d; + out_grads[70][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + out_shs[65] = c0 * d; + out_shs[45] = s0 * d; + d = 7.673951182; + out_grads[65][0] = c1 * d; + out_grads[45][0] = s1 * d; + out_grads[65][1] = -s1 * d; + out_grads[45][1] = c1 * d; + d = -3.4318953; + out_grads[64][2] = c1 * d; + out_grads[46][2] = s1 * d; + a = z2 - 4.34782609e-02; + d = 13.3042542 * a; + out_shs[88] = c0 * d; + out_shs[68] = s0 * d; + d = 133.042542003 * a; + out_grads[88][0] = c1 * d; + out_grads[68][0] = s1 * d; + out_grads[88][1] = -s1 * d; + out_grads[68][1] = c1 * d; + d = -108.084272068 * a; + out_grads[87][2] = c1 * d; + out_grads[69][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.923210529 * z; + out_shs[89] = c1 * d; + out_shs[67] = s1 * d; + d = -43.155315818 * z; + out_grads[89][0] = c0 * d; + out_grads[67][0] = s0 * d; + out_grads[89][1] = s0 * d; + out_grads[67][1] = c0 * d; + d = 26.608508401 * z; + out_grads[88][2] = c0 * d; + out_grads[68][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.800821996; + out_shs[90] = c0 * d; + out_shs[66] = s0 * d; + d = 9.609863949; + out_grads[90][0] = c1 * d; + out_grads[66][0] = s1 * d; + out_grads[90][1] = -s1 * d; + out_grads[66][1] = c1 * d; + d = -3.923210529; + out_grads[89][2] = c1 * d; + out_grads[67][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; + out_grads[6][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[14][2] = 0.0; + out_grads[15][2] = 0.0; + out_grads[21][0] = 0.0; + out_grads[21][1] = 0.0; + out_grads[27][2] = 0.0; + out_grads[28][2] = 0.0; + out_grads[36][0] = 0.0; + out_grads[36][1] = 0.0; + out_grads[44][2] = 0.0; + out_grads[45][2] = 0.0; + out_grads[55][0] = 0.0; + out_grads[55][1] = 0.0; + out_grads[65][2] = 0.0; + out_grads[66][2] = 0.0; + out_grads[78][0] = 0.0; + out_grads[78][1] = 0.0; + out_grads[90][2] = 0.0; +} diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_2 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_2 copy.frag new file mode 100644 index 000000000..277a0e07a --- /dev/null +++ b/fury/shaders/rt_odfs/tournier/eval_sh_grad_2 copy.frag @@ -0,0 +1,46 @@ +void eval_sh_grad_2(out float out_shs[6], out vec3 out_grads[6], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + out_grads[4][0] = c0 * d; + out_grads[2][0] = s0 * d; + out_grads[4][1] = s0 * d; + out_grads[2][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + d = 1.092548431; + out_grads[1][0] = c1 * d; + out_grads[5][0] = s1 * d; + out_grads[5][1] = -s1 * d; + out_grads[1][1] = c1 * d; + d = -1.092548431; + out_grads[4][2] = c1 * d; + out_grads[2][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[5][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[1][2] = 0.0; +} diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_4 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_4 copy.frag new file mode 100644 index 000000000..c85847a5b --- /dev/null +++ b/fury/shaders/rt_odfs/tournier/eval_sh_grad_4 copy.frag @@ -0,0 +1,103 @@ +void eval_sh_grad_4(out float out_shs[15], out vec3 out_grads[15], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + out_grads[4][0] = c0 * d; + out_grads[2][0] = s0 * d; + out_grads[4][1] = s0 * d; + out_grads[2][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + out_grads[11][0] = c0 * d; + out_grads[9][0] = s0 * d; + out_grads[11][1] = s0 * d; + out_grads[9][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + d = 1.092548431; + out_grads[5][0] = c1 * d; + out_grads[1][0] = s1 * d; + out_grads[5][1] = -s1 * d; + out_grads[1][1] = c1 * d; + d = -1.092548431; + out_grads[4][2] = c1 * d; + out_grads[2][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + d = 6.62322287 * a; + out_grads[12][0] = c1 * d; + out_grads[8][0] = s1 * d; + out_grads[12][1] = -s1 * d; + out_grads[8][1] = c1 * d; + d = -14.049977415 * a; + out_grads[11][2] = c1 * d; + out_grads[9][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; + d = -5.310392309 * z; + out_grads[13][0] = c0 * d; + out_grads[7][0] = s0 * d; + out_grads[13][1] = s0 * d; + out_grads[7][1] = c0 * d; + d = 6.62322287 * z; + out_grads[12][2] = c0 * d; + out_grads[8][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; + d = 2.503342942; + out_grads[14][0] = c1 * d; + out_grads[6][0] = s1 * d; + out_grads[14][1] = -s1 * d; + out_grads[6][1] = c1 * d; + d = -1.77013077; + out_grads[13][2] = c1 * d; + out_grads[7][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[5][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[1][2] = 0.0; + out_grads[14][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[6][2] = 0.0; +} diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_6 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_6 copy.frag new file mode 100644 index 000000000..617413bc9 --- /dev/null +++ b/fury/shaders/rt_odfs/tournier/eval_sh_grad_6 copy.frag @@ -0,0 +1,186 @@ +void eval_sh_grad_6(out float out_shs[28], out vec3 out_grads[28], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + out_grads[4][0] = c0 * d; + out_grads[2][0] = s0 * d; + out_grads[4][1] = s0 * d; + out_grads[2][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + out_grads[11][0] = c0 * d; + out_grads[9][0] = s0 * d; + out_grads[11][1] = s0 * d; + out_grads[9][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[22] = c1 * d; + out_shs[20] = s1 * d; + out_grads[22][0] = c0 * d; + out_grads[20][0] = s0 * d; + out_grads[22][1] = s0 * d; + out_grads[20][1] = c0 * d; + d = 88.106914343 * b; + out_grads[21][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + d = 1.092548431; + out_grads[5][0] = c1 * d; + out_grads[1][0] = s1 * d; + out_grads[5][1] = -s1 * d; + out_grads[1][1] = c1 * d; + d = -1.092548431; + out_grads[4][2] = c1 * d; + out_grads[2][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + d = 6.62322287 * a; + out_grads[12][0] = c1 * d; + out_grads[8][0] = s1 * d; + out_grads[12][1] = -s1 * d; + out_grads[8][1] = c1 * d; + d = -14.049977415 * a; + out_grads[11][2] = c1 * d; + out_grads[9][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[23] = c0 * d; + out_shs[19] = s0 * d; + d = 30.399773564 * a; + out_grads[23][0] = c1 * d; + out_grads[19][0] = s1 * d; + out_grads[23][1] = -s1 * d; + out_grads[19][1] = c1 * d; + d = -96.132524816 * a; + out_grads[22][2] = c1 * d; + out_grads[20][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; + d = -5.310392309 * z; + out_grads[13][0] = c0 * d; + out_grads[7][0] = s0 * d; + out_grads[13][1] = s0 * d; + out_grads[7][1] = c0 * d; + d = 6.62322287 * z; + out_grads[12][2] = c0 * d; + out_grads[8][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[24] = c1 * d; + out_shs[18] = s1 * d; + d = -30.399773564 * b; + out_grads[24][0] = c0 * d; + out_grads[18][0] = s0 * d; + out_grads[24][1] = s0 * d; + out_grads[18][1] = c0 * d; + d = 60.799547128 * b; + out_grads[23][2] = c0 * d; + out_grads[19][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; + d = 2.503342942; + out_grads[14][0] = c1 * d; + out_grads[6][0] = s1 * d; + out_grads[14][1] = -s1 * d; + out_grads[6][1] = c1 * d; + d = -1.77013077; + out_grads[13][2] = c1 * d; + out_grads[7][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[25] = c0 * d; + out_shs[17] = s0 * d; + d = 22.200855632 * a; + out_grads[25][0] = c1 * d; + out_grads[17][0] = s1 * d; + out_grads[25][1] = -s1 * d; + out_grads[17][1] = c1 * d; + d = -30.399773564 * a; + out_grads[24][2] = c1 * d; + out_grads[18][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[26] = c1 * d; + out_shs[16] = s1 * d; + d = -11.833095811 * z; + out_grads[26][0] = c0 * d; + out_grads[16][0] = s0 * d; + out_grads[26][1] = s0 * d; + out_grads[16][1] = c0 * d; + d = 11.100427816 * z; + out_grads[25][2] = c0 * d; + out_grads[17][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[27] = c0 * d; + out_shs[15] = s0 * d; + d = 4.099104631; + out_grads[27][0] = c1 * d; + out_grads[15][0] = s1 * d; + out_grads[27][1] = -s1 * d; + out_grads[15][1] = c1 * d; + d = -2.366619162; + out_grads[26][2] = c1 * d; + out_grads[16][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[5][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[1][2] = 0.0; + out_grads[14][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[6][2] = 0.0; + out_grads[27][2] = 0.0; + out_grads[21][0] = 0.0; + out_grads[21][1] = 0.0; + out_grads[15][2] = 0.0; +} diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_8 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_8 copy.frag new file mode 100644 index 000000000..712b2dc29 --- /dev/null +++ b/fury/shaders/rt_odfs/tournier/eval_sh_grad_8 copy.frag @@ -0,0 +1,295 @@ +void eval_sh_grad_8(out float out_shs[45], out vec3 out_grads[45], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + out_grads[4][0] = c0 * d; + out_grads[2][0] = s0 * d; + out_grads[4][1] = s0 * d; + out_grads[2][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + out_grads[11][0] = c0 * d; + out_grads[9][0] = s0 * d; + out_grads[11][1] = s0 * d; + out_grads[9][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[22] = c1 * d; + out_shs[20] = s1 * d; + out_grads[22][0] = c0 * d; + out_grads[20][0] = s0 * d; + out_grads[22][1] = s0 * d; + out_grads[20][1] = c0 * d; + d = 88.106914343 * b; + out_grads[21][2] = d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[37] = c1 * d; + out_shs[35] = s1 * d; + out_grads[37][0] = c0 * d; + out_grads[35][0] = s0 * d; + out_grads[37][1] = s0 * d; + out_grads[35][1] = c0 * d; + d = 467.786944906 * b; + out_grads[36][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + d = 1.092548431; + out_grads[5][0] = c1 * d; + out_grads[1][0] = s1 * d; + out_grads[5][1] = -s1 * d; + out_grads[1][1] = c1 * d; + d = -1.092548431; + out_grads[4][2] = c1 * d; + out_grads[2][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + d = 6.62322287 * a; + out_grads[12][0] = c1 * d; + out_grads[8][0] = s1 * d; + out_grads[12][1] = -s1 * d; + out_grads[8][1] = c1 * d; + d = -14.049977415 * a; + out_grads[11][2] = c1 * d; + out_grads[9][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[23] = c0 * d; + out_shs[19] = s0 * d; + d = 30.399773564 * a; + out_grads[23][0] = c1 * d; + out_grads[19][0] = s1 * d; + out_grads[23][1] = -s1 * d; + out_grads[19][1] = c1 * d; + d = -96.132524816 * a; + out_grads[22][2] = c1 * d; + out_grads[20][2] = s1 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[38] = c0 * d; + out_shs[34] = s0 * d; + d = 130.459545912 * a; + out_grads[38][0] = c1 * d; + out_grads[34][0] = s1 * d; + out_grads[38][1] = -s1 * d; + out_grads[34][1] = c1 * d; + d = -545.751435723 * a; + out_grads[37][2] = c1 * d; + out_grads[35][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; + d = -5.310392309 * z; + out_grads[13][0] = c0 * d; + out_grads[7][0] = s0 * d; + out_grads[13][1] = s0 * d; + out_grads[7][1] = c0 * d; + d = 6.62322287 * z; + out_grads[12][2] = c0 * d; + out_grads[8][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[24] = c1 * d; + out_shs[18] = s1 * d; + d = -30.399773564 * b; + out_grads[24][0] = c0 * d; + out_grads[18][0] = s0 * d; + out_grads[24][1] = s0 * d; + out_grads[18][1] = c0 * d; + d = 60.799547128 * b; + out_grads[23][2] = c0 * d; + out_grads[19][2] = s0 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[39] = c1 * d; + out_shs[33] = s1 * d; + d = -144.52614017 * b; + out_grads[39][0] = c0 * d; + out_grads[33][0] = s0 * d; + out_grads[39][1] = s0 * d; + out_grads[33][1] = c0 * d; + d = 391.378637737 * b; + out_grads[38][2] = c0 * d; + out_grads[34][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; + d = 2.503342942; + out_grads[14][0] = c1 * d; + out_grads[6][0] = s1 * d; + out_grads[14][1] = -s1 * d; + out_grads[6][1] = c1 * d; + d = -1.77013077; + out_grads[13][2] = c1 * d; + out_grads[7][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[25] = c0 * d; + out_shs[17] = s0 * d; + d = 22.200855632 * a; + out_grads[25][0] = c1 * d; + out_grads[17][0] = s1 * d; + out_grads[25][1] = -s1 * d; + out_grads[17][1] = c1 * d; + d = -30.399773564 * a; + out_grads[24][2] = c1 * d; + out_grads[18][2] = s1 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[40] = c0 * d; + out_shs[32] = s0 * d; + d = 124.388296437 * a; + out_grads[40][0] = c1 * d; + out_grads[32][0] = s1 * d; + out_grads[40][1] = -s1 * d; + out_grads[32][1] = c1 * d; + d = -240.876900283 * a; + out_grads[39][2] = c1 * d; + out_grads[33][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[26] = c1 * d; + out_shs[16] = s1 * d; + d = -11.833095811 * z; + out_grads[26][0] = c0 * d; + out_grads[16][0] = s0 * d; + out_grads[26][1] = s0 * d; + out_grads[16][1] = c0 * d; + d = 11.100427816 * z; + out_grads[25][2] = c0 * d; + out_grads[17][2] = s0 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[41] = c1 * d; + out_shs[31] = s1 * d; + d = -86.247765552 * b; + out_grads[41][0] = c0 * d; + out_grads[31][0] = s0 * d; + out_grads[41][1] = s0 * d; + out_grads[31][1] = c0 * d; + d = 124.388296437 * b; + out_grads[40][2] = c0 * d; + out_grads[32][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[27] = c0 * d; + out_shs[15] = s0 * d; + d = 4.099104631; + out_grads[27][0] = c1 * d; + out_grads[15][0] = s1 * d; + out_grads[27][1] = -s1 * d; + out_grads[15][1] = c1 * d; + d = -2.366619162; + out_grads[26][2] = c1 * d; + out_grads[16][2] = s1 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[42] = c0 * d; + out_shs[30] = s0 * d; + d = 47.909948945 * a; + out_grads[42][0] = c1 * d; + out_grads[30][0] = s1 * d; + out_grads[42][1] = -s1 * d; + out_grads[30][1] = c1 * d; + d = -51.748659331 * a; + out_grads[41][2] = c1 * d; + out_grads[31][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[43] = c1 * d; + out_shs[29] = s1 * d; + d = -20.409946485 * z; + out_grads[43][0] = c0 * d; + out_grads[29][0] = s0 * d; + out_grads[43][1] = s0 * d; + out_grads[29][1] = c0 * d; + d = 15.969982982 * z; + out_grads[42][2] = c0 * d; + out_grads[30][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[44] = c0 * d; + out_shs[28] = s0 * d; + d = 5.831413281; + out_grads[44][0] = c1 * d; + out_grads[28][0] = s1 * d; + out_grads[44][1] = -s1 * d; + out_grads[28][1] = c1 * d; + d = -2.915706641; + out_grads[43][2] = c1 * d; + out_grads[29][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[5][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[1][2] = 0.0; + out_grads[14][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[6][2] = 0.0; + out_grads[27][2] = 0.0; + out_grads[21][0] = 0.0; + out_grads[21][1] = 0.0; + out_grads[15][2] = 0.0; + out_grads[44][2] = 0.0; + out_grads[36][0] = 0.0; + out_grads[36][1] = 0.0; + out_grads[28][2] = 0.0; +} diff --git a/fury/shaders/rt_odfs/find_roots.frag b/fury/shaders/utils/find_roots.frag similarity index 100% rename from fury/shaders/rt_odfs/find_roots.frag rename to fury/shaders/utils/find_roots.frag diff --git a/fury/shaders/rt_odfs/newton_bisection.frag b/fury/shaders/utils/newton_bisection.frag similarity index 100% rename from fury/shaders/rt_odfs/newton_bisection.frag rename to fury/shaders/utils/newton_bisection.frag From 23c53df97e91aabbd28082c3752c129229f4021a Mon Sep 17 00:00:00 2001 From: tvcastillod Date: Fri, 1 Mar 2024 11:39:22 -0500 Subject: [PATCH 091/118] added degree param --- .../SH-ODF experimental/odf_example.py | 37 +++++++++- fury/actors/odf.py | 74 +++++-------------- ...grad_10 copy.frag => eval_sh_grad_10.frag} | 0 ...grad_12 copy.frag => eval_sh_grad_12.frag} | 0 ...h_grad_2 copy.frag => eval_sh_grad_2.frag} | 0 ...h_grad_4 copy.frag => eval_sh_grad_4.frag} | 0 ...h_grad_6 copy.frag => eval_sh_grad_6.frag} | 0 ...h_grad_8 copy.frag => eval_sh_grad_8.frag} | 0 8 files changed, 53 insertions(+), 58 deletions(-) rename fury/shaders/rt_odfs/tournier/{eval_sh_grad_10 copy.frag => eval_sh_grad_10.frag} (100%) rename fury/shaders/rt_odfs/tournier/{eval_sh_grad_12 copy.frag => eval_sh_grad_12.frag} (100%) rename fury/shaders/rt_odfs/tournier/{eval_sh_grad_2 copy.frag => eval_sh_grad_2.frag} (100%) rename fury/shaders/rt_odfs/tournier/{eval_sh_grad_4 copy.frag => eval_sh_grad_4.frag} (100%) rename fury/shaders/rt_odfs/tournier/{eval_sh_grad_6 copy.frag => eval_sh_grad_6.frag} (100%) rename fury/shaders/rt_odfs/tournier/{eval_sh_grad_8 copy.frag => eval_sh_grad_8.frag} (100%) diff --git a/docs/experimental/SH-ODF experimental/odf_example.py b/docs/experimental/SH-ODF experimental/odf_example.py index e16858211..50978942d 100644 --- a/docs/experimental/SH-ODF experimental/odf_example.py +++ b/docs/experimental/SH-ODF experimental/odf_example.py @@ -20,8 +20,39 @@ x, y, z, s = coeffs.shape coeffs = coeffs[:, :, :].reshape((x * y * z, s)) - n_glyphs = coeffs.shape[0] - - odf_actor = actor.odf(centers=centers, coeffs=coeffs, scales=1.0) + + #''' + coeffs = np.array([ + [ + -0.2739740312099, 0.2526670396328, 1.8922271728516, 0.2878578901291, + -0.5339795947075, -0.2620058953762, 0.1580424904823, 0.0329004973173, + -0.1322413831949, -0.1332057565451, 1.0894461870193, -0.6319401264191, + -0.0416776277125, -1.0772529840469, 0.1423762738705, 0.7941166162491, + 0.7490307092667, -0.3428381681442, 0.1024847552180, -0.0219132602215, + 0.0499043911695, 0.2162453681231, 0.0921059995890, -0.2611238956451, + 0.2549301385880, -0.4534865319729, 0.1922748684883, -0.6200597286224, + -0.0532187558711, -0.3569841980934, 0.0293972902000, -0.1977960765362, + -0.1058669015765, 0.2372217923403, -0.1856198310852, -0.3373193442822, + -0.0750469490886, 0.2146576642990, -0.0490148440003, 0.1288588196039, + 0.3173974752426, 0.1990085393190, -0.1736343950033, -0.0482443645597, + 0.1749017387629, -0.0151847425660, 0.0418366046081, 0.0863263587216, + -0.0649211244490, 0.0126096132283, 0.0545089217982, -0.0275142164626, + 0.0399986574832, -0.0468244261610, -0.1292105653111, -0.0786858322658, + -0.0663828464882, 0.0382439706831, -0.0041550330365, -0.0502800566338, + -0.0732471630735, 0.0181751900972, -0.0090119333757, -0.0604443282359, + -0.1469985252752, -0.0534046899715, -0.0896672753415, -0.0130841364808, + -0.0112942893801, 0.0272257498541, 0.0626717616331, -0.0222197983050, + -0.0018541504308, -0.1653251944056, 0.0409697402846, 0.0749921454327, + -0.0282830872616, 0.0006909458525, 0.0625599842287, 0.0812529816082, + 0.0914693020772, -0.1197222726745, 0.0376277453183, -0.0832617004142, + -0.0482175038043, -0.0839003635737, -0.0349423908400, 0.1204519568256, + 0.0783745984003, 0.0297401205976, -0.0505947662525 + ] + ]) + centers= np.array([0, 0, 0]) + #''' + + odf_actor = actor.odf(centers=centers, coeffs=coeffs, scales=1.0, + basis_type='descoteaux', degree=6) show_man.scene.add(odf_actor) show_man.start() \ No newline at end of file diff --git a/fury/actors/odf.py b/fury/actors/odf.py index e8a762c55..139567a56 100644 --- a/fury/actors/odf.py +++ b/fury/actors/odf.py @@ -32,14 +32,13 @@ def uv_calculations(n): return uvs def minmax_norm(data): - min = data.min(axis=1) max = data.max(axis=1) return np.array([(data[i] - min[i]) / (max[i] - min[i]) for i in range(data.shape[0])]) -def sh_odf(centers, coeffs, basis_type, scales, opacity): +def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): """ Visualize one or many ODFs with different features. @@ -53,6 +52,9 @@ def sh_odf(centers, coeffs, basis_type, scales, opacity): Type of basis (descoteaux, tournier) 'descoteaux' for the default ``descoteaux07`` DYPY basis. 'tournier' for the default ``tournier07` DYPY basis. + degree: int, optional + Index of the highest used band of the spherical harmonics basis. Must + be even, at least 2 and at most 12. scales : float or ndarray (N, ) ODFs size. opacity : float @@ -108,7 +110,7 @@ def sh_odf(centers, coeffs, basis_type, scales, opacity): # The number of coefficients is associated to the order of the SH odf_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniformf( - "numCoeffs", 15 + "numCoeffs", ((degree + 1) * (degree + 2)) / 2 ) # Start of shader implementation @@ -142,7 +144,7 @@ def sh_odf(centers, coeffs, basis_type, scales, opacity): # The index of the highest used band of the spherical harmonics basis. Must # be even, at least 2 and at most 12. - def_sh_degree = "#define SH_DEGREE 4" + def_sh_degree = "#define SH_DEGREE " + str(degree) # The number of spherical harmonics basis functions def_sh_count = "#define SH_COUNT (((SH_DEGREE + 1) * (SH_DEGREE + 2)) / 2)" @@ -187,47 +189,14 @@ def sh_odf(centers, coeffs, basis_type, scales, opacity): coeffs_norm = import_fury_shader(os.path.join("utils", "minmax_norm.glsl")) - eval_sh_2 = import_fury_shader( - os.path.join("rt_odfs", basis_type, "eval_sh_2.frag")) - - eval_sh_4 = import_fury_shader( - os.path.join("rt_odfs", basis_type, "eval_sh_4.frag")) - - eval_sh_6 = import_fury_shader( - os.path.join("rt_odfs", basis_type, "eval_sh_6.frag")) - - eval_sh_8 = import_fury_shader( - os.path.join("rt_odfs", basis_type, "eval_sh_8.frag")) - - eval_sh_10 = import_fury_shader( - os.path.join("rt_odfs", basis_type, "eval_sh_10.frag")) - - eval_sh_12 = import_fury_shader( - os.path.join("rt_odfs", basis_type, "eval_sh_12.frag")) - - eval_sh_grad_2 = import_fury_shader( - os.path.join("rt_odfs/descoteaux", "eval_sh_grad_2.frag") - ) - - eval_sh_grad_4 = import_fury_shader( - os.path.join("rt_odfs/descoteaux", "eval_sh_grad_4.frag") - ) - - eval_sh_grad_6 = import_fury_shader( - os.path.join("rt_odfs/descoteaux", "eval_sh_grad_6.frag") - ) - - eval_sh_grad_8 = import_fury_shader( - os.path.join("rt_odfs/descoteaux", "eval_sh_grad_8.frag") - ) - - eval_sh_grad_10 = import_fury_shader( - os.path.join("rt_odfs/descoteaux", "eval_sh_grad_10.frag") - ) - - eval_sh_grad_12 = import_fury_shader( - os.path.join("rt_odfs/descoteaux", "eval_sh_grad_12.frag") - ) + eval_sh_list = '' + for i in range (2, degree+1, 2): + eval_sh = import_fury_shader( + os.path.join("rt_odfs", basis_type, 'eval_sh_' + str(i) + '.frag')) + eval_sh_grad = import_fury_shader( + os.path.join("rt_odfs", basis_type, + 'eval_sh_grad_' + str(i) + '.frag')) + eval_sh_list = eval_sh_list + '\n\n' + eval_sh + '\n\n' + eval_sh_grad # Searches a single root of a polynomial within a given interval. # param out_root The location of the found root. @@ -334,13 +303,10 @@ def sh_odf(centers, coeffs, basis_type, scales, opacity): fs_dec = compose_shader([ def_sh_degree, def_sh_count, def_max_degree, def_gl_ext_control_flow_attributes, def_no_intersection, def_pis, - fs_vs_vars, coeffs_norm, eval_sh_2, eval_sh_4, eval_sh_6, eval_sh_8, - eval_sh_10, eval_sh_12, eval_sh_grad_2, eval_sh_grad_4, eval_sh_grad_6, - eval_sh_grad_8, eval_sh_grad_10, eval_sh_grad_12, newton_bisection, - find_roots, eval_sh, eval_sh_grad, get_inv_vandermonde, - ray_sh_glyph_intersections, get_sh_glyph_normal, blinn_phong_model, - linear_to_srgb, srgb_to_linear, linear_rgb_to_srgb, srgb_to_linear_rgb, - tonemap + fs_vs_vars, coeffs_norm, eval_sh_list, newton_bisection, find_roots, + eval_sh, eval_sh_grad, get_inv_vandermonde, ray_sh_glyph_intersections, + get_sh_glyph_normal, blinn_phong_model, linear_to_srgb, srgb_to_linear, + linear_rgb_to_srgb, srgb_to_linear_rgb, tonemap ]) # fmt: on @@ -351,7 +317,6 @@ def sh_odf(centers, coeffs, basis_type, scales, opacity): # Ray origin is the camera position in world space ray_origin = "vec3 ro = camPosMCVSOutput;" - # TODO: Check aspect for automatic scaling # Ray direction is the normalized difference between the fragment and the # camera position/ray origin ray_direction = "vec3 rd = normalize(pnt - ro);" @@ -392,7 +357,7 @@ def sh_odf(centers, coeffs, basis_type, scales, opacity): break; } } - """ + """ # Evaluate shading for a directional light directional_light = \ @@ -404,7 +369,6 @@ def sh_odf(centers, coeffs, basis_type, scales, opacity): vec3 colorDir = srgb_to_linear_rgb(abs(normalize(intersection))); float attenuation = dot(ld, normal); color = blinnPhongIllumModel( - //attenuation, lightColor0, diffuseColor, specularPower, attenuation, lightColor0, colorDir, specularPower, specularColor, ambientColor); } else { diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_10 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_10.frag similarity index 100% rename from fury/shaders/rt_odfs/tournier/eval_sh_grad_10 copy.frag rename to fury/shaders/rt_odfs/tournier/eval_sh_grad_10.frag diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_12 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_12.frag similarity index 100% rename from fury/shaders/rt_odfs/tournier/eval_sh_grad_12 copy.frag rename to fury/shaders/rt_odfs/tournier/eval_sh_grad_12.frag diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_2 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_2.frag similarity index 100% rename from fury/shaders/rt_odfs/tournier/eval_sh_grad_2 copy.frag rename to fury/shaders/rt_odfs/tournier/eval_sh_grad_2.frag diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_4 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_4.frag similarity index 100% rename from fury/shaders/rt_odfs/tournier/eval_sh_grad_4 copy.frag rename to fury/shaders/rt_odfs/tournier/eval_sh_grad_4.frag diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_6 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_6.frag similarity index 100% rename from fury/shaders/rt_odfs/tournier/eval_sh_grad_6 copy.frag rename to fury/shaders/rt_odfs/tournier/eval_sh_grad_6.frag diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_8 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_8.frag similarity index 100% rename from fury/shaders/rt_odfs/tournier/eval_sh_grad_8 copy.frag rename to fury/shaders/rt_odfs/tournier/eval_sh_grad_8.frag From 236d809e1b21ccedf2f96b117d87a87a3e7f348f Mon Sep 17 00:00:00 2001 From: tvcastillod Date: Wed, 6 Mar 2024 18:05:58 -0500 Subject: [PATCH 092/118] adjusted the degree setting --- .../experimental/SH-ODF experimental/odf_example.py | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/docs/experimental/SH-ODF experimental/odf_example.py b/docs/experimental/SH-ODF experimental/odf_example.py index 50978942d..c31dac722 100644 --- a/docs/experimental/SH-ODF experimental/odf_example.py +++ b/docs/experimental/SH-ODF experimental/odf_example.py @@ -35,18 +35,7 @@ -0.1058669015765, 0.2372217923403, -0.1856198310852, -0.3373193442822, -0.0750469490886, 0.2146576642990, -0.0490148440003, 0.1288588196039, 0.3173974752426, 0.1990085393190, -0.1736343950033, -0.0482443645597, - 0.1749017387629, -0.0151847425660, 0.0418366046081, 0.0863263587216, - -0.0649211244490, 0.0126096132283, 0.0545089217982, -0.0275142164626, - 0.0399986574832, -0.0468244261610, -0.1292105653111, -0.0786858322658, - -0.0663828464882, 0.0382439706831, -0.0041550330365, -0.0502800566338, - -0.0732471630735, 0.0181751900972, -0.0090119333757, -0.0604443282359, - -0.1469985252752, -0.0534046899715, -0.0896672753415, -0.0130841364808, - -0.0112942893801, 0.0272257498541, 0.0626717616331, -0.0222197983050, - -0.0018541504308, -0.1653251944056, 0.0409697402846, 0.0749921454327, - -0.0282830872616, 0.0006909458525, 0.0625599842287, 0.0812529816082, - 0.0914693020772, -0.1197222726745, 0.0376277453183, -0.0832617004142, - -0.0482175038043, -0.0839003635737, -0.0349423908400, 0.1204519568256, - 0.0783745984003, 0.0297401205976, -0.0505947662525 + 0.1749017387629 ] ]) centers= np.array([0, 0, 0]) From ecd1d75e33509df3c69f7915b561c456f4f7767e Mon Sep 17 00:00:00 2001 From: tvcastillod Date: Mon, 18 Mar 2024 13:07:16 -0500 Subject: [PATCH 093/118] added tests --- .../SH-ODF experimental/odf_example.py | 47 ----------- fury/actor.py | 79 +++++++++++++++++++ fury/actors/odf.py | 54 ++++--------- fury/tests/test_actors.py | 73 +++++++++++++++++ fury/tests/test_utils.py | 21 +++++ fury/texture/utils.py | 18 +++++ fury/utils.py | 33 ++++++++ 7 files changed, 241 insertions(+), 84 deletions(-) delete mode 100644 docs/experimental/SH-ODF experimental/odf_example.py create mode 100644 fury/texture/utils.py diff --git a/docs/experimental/SH-ODF experimental/odf_example.py b/docs/experimental/SH-ODF experimental/odf_example.py deleted file mode 100644 index c31dac722..000000000 --- a/docs/experimental/SH-ODF experimental/odf_example.py +++ /dev/null @@ -1,47 +0,0 @@ -import os - -import numpy as np -from dipy.data.fetcher import dipy_home -from dipy.io.image import load_nifti - -from fury import actor, window - -if __name__ == "__main__": - show_man = window.ShowManager(size=(1280, 720)) - - dataset_dir = os.path.join(dipy_home, "stanford_hardi") - - coeffs, affine = load_nifti("docs\experimental\SH-ODF experimental\coefs_odf.nii") - - valid_mask = np.abs(coeffs).max(axis=(-1)) > 0 - indices = np.nonzero(valid_mask) - - centers = np.asarray(indices).T - - x, y, z, s = coeffs.shape - coeffs = coeffs[:, :, :].reshape((x * y * z, s)) - - #''' - coeffs = np.array([ - [ - -0.2739740312099, 0.2526670396328, 1.8922271728516, 0.2878578901291, - -0.5339795947075, -0.2620058953762, 0.1580424904823, 0.0329004973173, - -0.1322413831949, -0.1332057565451, 1.0894461870193, -0.6319401264191, - -0.0416776277125, -1.0772529840469, 0.1423762738705, 0.7941166162491, - 0.7490307092667, -0.3428381681442, 0.1024847552180, -0.0219132602215, - 0.0499043911695, 0.2162453681231, 0.0921059995890, -0.2611238956451, - 0.2549301385880, -0.4534865319729, 0.1922748684883, -0.6200597286224, - -0.0532187558711, -0.3569841980934, 0.0293972902000, -0.1977960765362, - -0.1058669015765, 0.2372217923403, -0.1856198310852, -0.3373193442822, - -0.0750469490886, 0.2146576642990, -0.0490148440003, 0.1288588196039, - 0.3173974752426, 0.1990085393190, -0.1736343950033, -0.0482443645597, - 0.1749017387629 - ] - ]) - centers= np.array([0, 0, 0]) - #''' - - odf_actor = actor.odf(centers=centers, coeffs=coeffs, scales=1.0, - basis_type='descoteaux', degree=6) - show_man.scene.add(odf_actor) - show_man.start() \ No newline at end of file diff --git a/fury/actor.py b/fury/actor.py index 3d552ae3a..488d72fb3 100644 --- a/fury/actor.py +++ b/fury/actor.py @@ -4019,3 +4019,82 @@ def uncertainty_cone( angles = main_dir_uncertainty(evals, evecs, signal, sigma, b_matrix) return double_cone(centers, evecs, angles, colors, scales, opacity) + + +def odf( + centers, + coeffs, + degree=None, + basis_type='descoteaux', + scales=1.0, + opacity=1.0 +): + """ + VTK actor for visualizing ODFs given an array of spherical harmonics (SH) + coefficients. + + Parameters + ---------- + centers : ndarray(N, 3) + ODFs positions. + coeffs : ndarray + 2D ODFs array in SH coefficients. + degree: int, optional + Index of the highest used band of the spherical harmonics basis. Must + be even, at least 2 and at most 12. If None the degree is set based on + the number of SH coefficients given. + basis_type: str, optional + Type of basis (descoteaux, tournier) + 'descoteaux' for the default ``descoteaux07`` DYPY basis. + 'tournier' for the default ``tournier07` DYPY basis. + scales : float or ndarray (N, ) + ODFs size. + opacity : float + Takes values from 0 (fully transparent) to 1 (opaque). + + Returns + ------- + odf: Actor + + """ + + if not isinstance(centers, np.ndarray): + centers = np.array(centers) + if centers.ndim == 1: + centers = np.array([centers]) + + if not isinstance(coeffs, np.ndarray): + coeffs = np.array(coeffs) + if coeffs.ndim == 1: + coeffs = np.array([coeffs]) + if coeffs.shape[0] != centers.shape[0]: + raise ValueError('number of odf glyphs defined does not match with ' + 'number of centers') + + coeffs_given = coeffs.shape[-1] + if degree is None: + degree = int((np.sqrt(8 * coeffs_given + 1) - 3)/2) + elif degree % 2 != 0: + raise ValueError('degree must be even') + coeffs_needed = int(((degree + 1) * (degree + 2)) / 2) + if coeffs_given < coeffs_needed: + print('Not enough number of coefficient for SH of degree {0}. ' + 'Expected at least {1}'.format(degree, coeffs_needed)) + degree = int((np.sqrt(8 * coeffs_given + 1) - 3)/2) + if (degree % 2 != 0): + degree -= 1 + coeffs_needed = int(((degree + 1) * (degree + 2)) / 2) + coeffs = coeffs[:, :coeffs_needed] + + if not isinstance(scales, np.ndarray): + scales = np.array(scales) + if scales.size == 1: + scales = np.repeat(scales, centers.shape[0]) + elif scales.size != centers.shape[0]: + scales = np.concatenate( + (scales, np.ones(centers.shape[0] - scales.shape[0])), axis=None) + + total = np.sum(abs(coeffs), axis=1) + coeffs = np.dot(np.diag(1 / total * scales), coeffs) * 1.7 + + return sh_odf(centers, coeffs, degree, basis_type, scales, opacity) diff --git a/fury/actors/odf.py b/fury/actors/odf.py index 139567a56..938cae791 100644 --- a/fury/actors/odf.py +++ b/fury/actors/odf.py @@ -10,33 +10,13 @@ import_fury_shader, shader_to_actor, ) -from fury.utils import numpy_to_vtk_image_data, set_polydata_tcoords - -def uv_calculations(n): - uvs = [] - for i in range(0, n): - a = (n - (i + 1)) / n - b = (n - i) / n - uvs.extend( - [ - [0.001, a + 0.001], - [0.001, b - 0.001], - [0.999, b - 0.001], - [0.999, a + 0.001], - [0.001, a + 0.001], - [0.001, b - 0.001], - [0.999, b - 0.001], - [0.999, a + 0.001], - ] - ) - return uvs - -def minmax_norm(data): - min = data.min(axis=1) - max = data.max(axis=1) - return np.array([(data[i] - min[i]) / (max[i] - min[i]) - for i in range(data.shape[0])]) - +from fury.utils import ( + numpy_to_vtk_image_data, + set_polydata_tcoords, + minmax_norm +) +from fury.texture.utils import uv_calculations + def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): """ @@ -75,9 +55,9 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): minmax = np.array([coeffs.min(axis=1), coeffs.max(axis=1)]).T big_minmax = np.repeat(minmax, 8, axis=0) attribute_to_actor(odf_actor, big_minmax, "minmax") - + # The coefficient data is stored in a texture to be passed to the shaders. - + # Data is normalized to a range of 0 to 1. arr = minmax_norm(coeffs) # Data is turned into values within the RGB color range, and then coverted @@ -92,8 +72,7 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): # Texture is associated with the actor odf_actor.GetProperty().SetTexture("texture0", texture) - - + odf_actor_pd = odf_actor.GetMapper().GetInput() n_glyphs = coeffs.shape[0] @@ -101,6 +80,7 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): uv_vals = np.array(uv_calculations(n_glyphs)) num_pnts = uv_vals.shape[0] + # Definition of texture coordinates to be associated with the actor. t_coords = FloatArray() t_coords.SetNumberOfComponents(2) t_coords.SetNumberOfTuples(num_pnts) @@ -112,9 +92,9 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): odf_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniformf( "numCoeffs", ((degree + 1) * (degree + 2)) / 2 ) - + # Start of shader implementation - + vs_dec = \ """ in vec3 center; @@ -188,13 +168,13 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): """ coeffs_norm = import_fury_shader(os.path.join("utils", "minmax_norm.glsl")) - + eval_sh_list = '' - for i in range (2, degree+1, 2): + for i in range(2, degree+1, 2): eval_sh = import_fury_shader( os.path.join("rt_odfs", basis_type, 'eval_sh_' + str(i) + '.frag')) eval_sh_grad = import_fury_shader( - os.path.join("rt_odfs", basis_type, + os.path.join("rt_odfs", basis_type, 'eval_sh_grad_' + str(i) + '.frag')) eval_sh_list = eval_sh_list + '\n\n' + eval_sh + '\n\n' + eval_sh_grad @@ -388,5 +368,5 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): ]) shader_to_actor(odf_actor, "fragment", impl_code=fs_impl, block="picking") - + return odf_actor \ No newline at end of file diff --git a/fury/tests/test_actors.py b/fury/tests/test_actors.py index 4f6b2b5df..1ddde3b68 100644 --- a/fury/tests/test_actors.py +++ b/fury/tests/test_actors.py @@ -1950,3 +1950,76 @@ def test_actors_primitives_count(): primitives_count = test_case[2] act = act_func(**args) npt.assert_equal(primitives_count_from_actor(act), primitives_count) + + +def test_odf_actor(interactive=False): + # number of odf glyphs does not match with number of centers + centers = np.array([[0, -1, 0]]) + coeffs = np.array([[0.282, 0.152, -0.040, -0.112, -0.045, 0.149], + [0.285, 0.097, -0.115, 0.125, -0.001, 0.003]]) + npt.assert_raises(ValueError, actor.odf, centers, coeffs) + + scene = window.Scene() + centers = np.array([[0, -1, 0], [1, -1, 0], [2, -1, 0]]) + coeffs = np.array([ + [0.2820735, 0.15236554, -0.04038717, -0.11270988, -0.04532376, + 0.14921817, 0.00257928, 0.0040734, -0.05313807, 0.03486542, + 0.04083064, 0.02105767, -0.04389586, -0.04302812, 0.1048641], + [0.28549338, 0.0978267, -0.11544838, 0.12525354, -0.00126003, + 0.00320594, 0.04744155, -0.07141446, 0.03211689, 0.04711322, + 0.08064896, 0.00154299, 0.00086506, 0.00162543, -0.00444893], + [0.28208936, -0.13133252, -0.04701012, -0.06303016, -0.0468775, + 0.02348355, 0.03991898, 0.02587433, 0.02645416, 0.00668765, + 0.00890633, 0.02189304, 0.00387415, 0.01665629, -0.01427194] + ]) + odf_actor = actor.odf(centers=centers, coeffs=coeffs) + scene.add(odf_actor) + + if interactive: + window.show(scene) + + report = window.analyze_scene(scene) + npt.assert_equal(report.actors, 1) + scene.clear() + + # given degree is not even + npt.assert_raises(ValueError, actor.odf, centers, coeffs, degree=3) + + centers= np.array([0, 0, 0]) + coeffs = np.array([ + [-0.2739740312099, 0.2526670396328, 1.8922271728516, 0.2878578901291, + -0.5339795947075, -0.2620058953762, 0.1580424904823, 0.0329004973173, + -0.1322413831949, -0.1332057565451, 1.0894461870193, -0.6319401264191, + -0.0416776277125, -1.0772529840469, 0.1423762738705, 0.7941166162491, + 0.7490307092667, -0.3428381681442, 0.1024847552180, -0.0219132602215, + 0.0499043911695, 0.2162453681231, 0.0921059995890, -0.2611238956451, + 0.2549301385880,-0.4534865319729, 0.1922748684883, -0.6200597286224] + ]) + odf_actor = actor.odf(centers=centers, coeffs=coeffs, degree=6) + scene.add(odf_actor) + + if interactive: + window.show(scene) + + report = window.analyze_scene(scene) + npt.assert_equal(report.actors, 1) + scene.clear() + + odf_actor = actor.odf(centers=centers, coeffs=coeffs, degree=4) + scene.add(odf_actor) + + if interactive: + window.show(scene) + + report = window.analyze_scene(scene) + npt.assert_equal(report.actors, 1) + scene.clear() + + odf_actor = actor.odf(centers=centers, coeffs=coeffs, degree=8) + scene.add(odf_actor) + + if interactive: + window.show(scene) + + npt.assert_equal(report.actors, 1) + scene.clear() diff --git a/fury/tests/test_utils.py b/fury/tests/test_utils.py index e7c347438..6f3b793ab 100644 --- a/fury/tests/test_utils.py +++ b/fury/tests/test_utils.py @@ -54,6 +54,7 @@ update_surface_actor_colors, vertices_from_actor, vtk_matrix_to_numpy, + minmax_norm, ) dipy, have_dipy, _ = optional_package("dipy") @@ -970,3 +971,23 @@ def test_set_actor_origin(): utils.set_actor_origin(cube) centered_cube_vertices = np.copy(vertices_from_actor(cube)) npt.assert_array_equal(orig_vert, centered_cube_vertices) + + +def test_minmax_normalization(): + data = np.array([[1, 2, -1, 3], [4, -1, 3, 5], [-1, 9, 8, 0]]) + + actual = minmax_norm(data, axis=0) + expected = np.array([[0.4, 0.3, 0, 0.6], [1, 0, 0.444, 1], [0, 1, 1, 0]]) + npt.assert_array_almost_equal(actual, expected, decimal=3) + actual = minmax_norm(data, axis=1) + expected = np.array([[0.5, 0.75, 0, 1], [0.833, 0, 0.666, 1], + [0, 1, 0.9, 0.1]]) + npt.assert_array_almost_equal(actual, expected, decimal=3) + + data2 = np.array([1, 3, 9, 6]) + actual2 = minmax_norm(data2, axis=0) + expected2 = np.array([[1, 3, 9, 6]]) + npt.assert_array_equal(actual2, expected2) + actual2 = minmax_norm(data2, axis=1) + expected2 = np.array([[0, 0.25 , 1, 0.625]]) + npt.assert_array_almost_equal(actual2, expected2, decimal=3) diff --git a/fury/texture/utils.py b/fury/texture/utils.py new file mode 100644 index 000000000..b75bebde5 --- /dev/null +++ b/fury/texture/utils.py @@ -0,0 +1,18 @@ +def uv_calculations(n): + uvs = [] + for i in range(0, n): + a = (n - (i + 1)) / n + b = (n - i) / n + uvs.extend( + [ + [0.001, a + 0.001], + [0.001, b - 0.001], + [0.999, b - 0.001], + [0.999, a + 0.001], + [0.001, a + 0.001], + [0.001, b - 0.001], + [0.999, b - 0.001], + [0.999, a + 0.001], + ] + ) + return uvs \ No newline at end of file diff --git a/fury/utils.py b/fury/utils.py index cb5d0671f..089108826 100644 --- a/fury/utils.py +++ b/fury/utils.py @@ -1622,3 +1622,36 @@ def set_actor_origin(actor, *, center=None): center = np.mean(vertices) vertices[:] -= center update_actor(actor) + + +def minmax_norm(data, axis=1): + """Returns the min-max normalization of data + + Parameters + ---------- + data: ndarray + 2D array + axis: int + axis for the function to be applied on + + Returns + ------- + output : ndarray + + """ + + if not isinstance(data, np.ndarray): + data = np.array(data) + if data.ndim == 1: + data = np.array([data]) + elif data.ndim > 2: + raise ValueError('the dimension of the array must be 2.') + + min = data.min(axis=axis) + max = data.max(axis=axis) + if np.array_equal(min, max): + return data + if (axis == 0): + return (data - min)/(max - min) + if (axis == 1): + return (data - min[:, None])/(max - min)[:, None] From 3a375d9e444fb0340efd3eeea89f16566c26f15c Mon Sep 17 00:00:00 2001 From: tvcastillod Date: Fri, 29 Mar 2024 10:15:18 -0500 Subject: [PATCH 094/118] adjustments on tests and parameter validation --- fury/actor.py | 49 +++++++++++++++++++------------- fury/actors/odf.py | 2 +- fury/tests/test_actors.py | 22 +++++++------- fury/tests/test_utils.py | 14 +++++++-- fury/texture/tests/__init__.py | 0 fury/texture/tests/test_utils.py | 41 ++++++++++++++++++++++++++ fury/texture/utils.py | 15 +++++++++- fury/utils.py | 12 ++++---- 8 files changed, 115 insertions(+), 40 deletions(-) create mode 100644 fury/texture/tests/__init__.py create mode 100644 fury/texture/tests/test_utils.py diff --git a/fury/actor.py b/fury/actor.py index 488d72fb3..075050f68 100644 --- a/fury/actor.py +++ b/fury/actor.py @@ -4030,15 +4030,16 @@ def odf( opacity=1.0 ): """ - VTK actor for visualizing ODFs given an array of spherical harmonics (SH) - coefficients. + FURY actor for visualizing Orientation Distribution Functions (ODFs) given + an array of Spherical Harmonics (SH) coefficients. Parameters ---------- centers : ndarray(N, 3) ODFs positions. - coeffs : ndarray - 2D ODFs array in SH coefficients. + coeffs : (N, M) or (N, 6) or (N, 15) or (N, 28) or (N, 45) or (N, 66) or + (N, 91) ndarray. + Corresponding SH coefficients for the ODFs. degree: int, optional Index of the highest used band of the spherical harmonics basis. Must be even, at least 2 and at most 12. If None the degree is set based on @@ -4062,29 +4063,39 @@ def odf( centers = np.array(centers) if centers.ndim == 1: centers = np.array([centers]) - + if not isinstance(coeffs, np.ndarray): coeffs = np.array(coeffs) - if coeffs.ndim == 1: - coeffs = np.array([coeffs]) + if coeffs.ndim != 2: + if coeffs.ndim == 1: + coeffs = np.array([coeffs]) + else: + raise ValueError('coeffs should be a 2D array.') if coeffs.shape[0] != centers.shape[0]: raise ValueError('number of odf glyphs defined does not match with ' 'number of centers') coeffs_given = coeffs.shape[-1] + max_degree = int((np.sqrt(8 * coeffs_given + 1) - 3) / 2) if degree is None: - degree = int((np.sqrt(8 * coeffs_given + 1) - 3)/2) - elif degree % 2 != 0: - raise ValueError('degree must be even') - coeffs_needed = int(((degree + 1) * (degree + 2)) / 2) - if coeffs_given < coeffs_needed: - print('Not enough number of coefficient for SH of degree {0}. ' - 'Expected at least {1}'.format(degree, coeffs_needed)) - degree = int((np.sqrt(8 * coeffs_given + 1) - 3)/2) - if (degree % 2 != 0): - degree -= 1 - coeffs_needed = int(((degree + 1) * (degree + 2)) / 2) - coeffs = coeffs[:, :coeffs_needed] + degree = max_degree + else: + if degree % 2 != 0: + warnings.warn('Invalid degree value. Degree must be a positive ' + 'even number lower or equal to 12. Ignoring passed ' + 'value and using maximum degree supported by the ' + 'number of SH coefficients.') + degree = max_degree + else: + coeffs_needed = int(((degree + 1) * (degree + 2)) / 2) + if coeffs_given < coeffs_needed: + warnings.warn('Not enough number of coefficient for SH of ' + 'degree {0}, expected at least {1}. Ignoring ' + 'passed value and using maximum degree supported ' + 'by the number of SH coefficients.' + .format(degree, coeffs_needed)) + degree = max_degree + coeffs = coeffs[:, :int(((degree + 1) * (degree + 2)) / 2)] if not isinstance(scales, np.ndarray): scales = np.array(scales) diff --git a/fury/actors/odf.py b/fury/actors/odf.py index 938cae791..5e8fbe4d4 100644 --- a/fury/actors/odf.py +++ b/fury/actors/odf.py @@ -369,4 +369,4 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): shader_to_actor(odf_actor, "fragment", impl_code=fs_impl, block="picking") - return odf_actor \ No newline at end of file + return odf_actor diff --git a/fury/tests/test_actors.py b/fury/tests/test_actors.py index 1ddde3b68..043cc0992 100644 --- a/fury/tests/test_actors.py +++ b/fury/tests/test_actors.py @@ -1958,7 +1958,7 @@ def test_odf_actor(interactive=False): coeffs = np.array([[0.282, 0.152, -0.040, -0.112, -0.045, 0.149], [0.285, 0.097, -0.115, 0.125, -0.001, 0.003]]) npt.assert_raises(ValueError, actor.odf, centers, coeffs) - + scene = window.Scene() centers = np.array([[0, -1, 0], [1, -1, 0], [2, -1, 0]]) coeffs = np.array([ @@ -1981,11 +1981,11 @@ def test_odf_actor(interactive=False): report = window.analyze_scene(scene) npt.assert_equal(report.actors, 1) scene.clear() - + # given degree is not even - npt.assert_raises(ValueError, actor.odf, centers, coeffs, degree=3) + npt.assert_warns(UserWarning, actor.odf, centers, coeffs, 3) - centers= np.array([0, 0, 0]) + centers = np.array([0, 0, 0]) coeffs = np.array([ [-0.2739740312099, 0.2526670396328, 1.8922271728516, 0.2878578901291, -0.5339795947075, -0.2620058953762, 0.1580424904823, 0.0329004973173, @@ -1993,7 +1993,7 @@ def test_odf_actor(interactive=False): -0.0416776277125, -1.0772529840469, 0.1423762738705, 0.7941166162491, 0.7490307092667, -0.3428381681442, 0.1024847552180, -0.0219132602215, 0.0499043911695, 0.2162453681231, 0.0921059995890, -0.2611238956451, - 0.2549301385880,-0.4534865319729, 0.1922748684883, -0.6200597286224] + 0.2549301385880, -0.4534865319729, 0.1922748684883, -0.6200597286224] ]) odf_actor = actor.odf(centers=centers, coeffs=coeffs, degree=6) scene.add(odf_actor) @@ -2007,19 +2007,21 @@ def test_odf_actor(interactive=False): odf_actor = actor.odf(centers=centers, coeffs=coeffs, degree=4) scene.add(odf_actor) - + if interactive: window.show(scene) - + report = window.analyze_scene(scene) npt.assert_equal(report.actors, 1) scene.clear() - + odf_actor = actor.odf(centers=centers, coeffs=coeffs, degree=8) + # not enough coefficients for given degree + npt.assert_warns(UserWarning, actor.odf, centers, coeffs, 8) scene.add(odf_actor) - + if interactive: window.show(scene) - + npt.assert_equal(report.actors, 1) scene.clear() diff --git a/fury/tests/test_utils.py b/fury/tests/test_utils.py index 6f3b793ab..f1758fa95 100644 --- a/fury/tests/test_utils.py +++ b/fury/tests/test_utils.py @@ -974,13 +974,21 @@ def test_set_actor_origin(): def test_minmax_normalization(): - data = np.array([[1, 2, -1, 3], [4, -1, 3, 5], [-1, 9, 8, 0]]) + data1d = np.array([2, -2, 5, -1, 8]) + actual_data1d = minmax_norm(data1d) + expected_data1d = np.array([[0.4, 0. , 0.7, 0.1, 1. ]]) + npt.assert_array_almost_equal(actual_data1d, expected_data1d, decimal=1) + + data3d = np.array([[[2, 7, 7, 9], [2, -1, -3, 5]], + [[-4, 5, 6, 0], [1, 1, -9, 3]]]) + npt.assert_raises(ValueError, utils.minmax_norm, data3d) + data = np.array([[1, 2, -1, 3], [4, -1, 3, 5], [-1, 9, 8, 0]]) actual = minmax_norm(data, axis=0) expected = np.array([[0.4, 0.3, 0, 0.6], [1, 0, 0.444, 1], [0, 1, 1, 0]]) npt.assert_array_almost_equal(actual, expected, decimal=3) actual = minmax_norm(data, axis=1) - expected = np.array([[0.5, 0.75, 0, 1], [0.833, 0, 0.666, 1], + expected = np.array([[0.5, 0.75, 0, 1], [0.833, 0, 0.666, 1], [0, 1, 0.9, 0.1]]) npt.assert_array_almost_equal(actual, expected, decimal=3) @@ -989,5 +997,5 @@ def test_minmax_normalization(): expected2 = np.array([[1, 3, 9, 6]]) npt.assert_array_equal(actual2, expected2) actual2 = minmax_norm(data2, axis=1) - expected2 = np.array([[0, 0.25 , 1, 0.625]]) + expected2 = np.array([[0, 0.25, 1, 0.625]]) npt.assert_array_almost_equal(actual2, expected2, decimal=3) diff --git a/fury/texture/tests/__init__.py b/fury/texture/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/fury/texture/tests/test_utils.py b/fury/texture/tests/test_utils.py new file mode 100644 index 000000000..71f108596 --- /dev/null +++ b/fury/texture/tests/test_utils.py @@ -0,0 +1,41 @@ +import numpy as np +import numpy.testing as npt +from fury.texture.utils import uv_calculations + +def test_uv_calculations(): + uv_coords = uv_calculations(1) + expected_uv1 = np.array([ + [0.001, 0.001], [0.001, 0.999], [0.999, 0.999], [0.999, 0.001], + [0.001, 0.001], [0.001, 0.999], [0.999, 0.999], [0.999, 0.001] + ]) + npt.assert_array_almost_equal(uv_coords, expected_uv1, decimal=3) + + uv_coords = uv_calculations(3) + expected_uv3 = np.array([ + [0.001, 0.667], [0.001, 0.999], [0.999, 0.999], [0.999, 0.667], + [0.001, 0.667], [0.001, 0.999], [0.999, 0.999], [0.999, 0.667], + [0.001, 0.334], [0.001, 0.665], [0.999, 0.665], [0.999, 0.334], + [0.001, 0.334], [0.001, 0.665], [0.999, 0.665], [0.999, 0.334], + [0.001, 0.001], [0.001, 0.332], [0.999, 0.332], [0.999, 0.001], + [0.001, 0.001], [0.001, 0.332], [0.999, 0.332], [0.999, 0.001] + ]) + npt.assert_array_almost_equal(uv_coords, expected_uv3, decimal=3) + + uv_coords = uv_calculations(7) + expected_uv7 = np.array([ + [0.001, 0.858], [0.001, 0.999], [0.999, 0.999], [0.999, 0.858], + [0.001, 0.858], [0.001, 0.999], [0.999, 0.999], [0.999, 0.858], + [0.001, 0.715], [0.001, 0.856], [0.999, 0.856], [0.999, 0.715], + [0.001, 0.715], [0.001, 0.856], [0.999, 0.856], [0.999, 0.715], + [0.001, 0.572], [0.001, 0.713], [0.999, 0.713], [0.999, 0.572], + [0.001, 0.572], [0.001, 0.713], [0.999, 0.713], [0.999, 0.572], + [0.001, 0.429], [0.001, 0.570], [0.999, 0.570], [0.999, 0.429], + [0.001, 0.429], [0.001, 0.570], [0.999, 0.570], [0.999, 0.429], + [0.001, 0.286], [0.001, 0.427], [0.999, 0.427], [0.999, 0.286], + [0.001, 0.286], [0.001, 0.427], [0.999, 0.427], [0.999, 0.286], + [0.001, 0.143], [0.001, 0.284], [0.999, 0.284], [0.999, 0.143], + [0.001, 0.143], [0.001, 0.284], [0.999, 0.284], [0.999, 0.143], + [0.001, 0.001], [0.001, 0.141], [0.999, 0.141], [0.999, 0.001], + [0.001, 0.001], [0.001, 0.141], [0.999, 0.141], [0.999, 0.001] + ]) + npt.assert_array_almost_equal(uv_coords, expected_uv7, decimal=3) diff --git a/fury/texture/utils.py b/fury/texture/utils.py index b75bebde5..25da3a714 100644 --- a/fury/texture/utils.py +++ b/fury/texture/utils.py @@ -1,4 +1,17 @@ def uv_calculations(n): + """Return UV coordinates based on the number of elements. + + Parameters + ---------- + n : int + number of elements. + + Returns + ------- + uvs : ndrray + UV coordinates for each element. + + """ uvs = [] for i in range(0, n): a = (n - (i + 1)) / n @@ -15,4 +28,4 @@ def uv_calculations(n): [0.999, a + 0.001], ] ) - return uvs \ No newline at end of file + return uvs diff --git a/fury/utils.py b/fury/utils.py index 089108826..2b170a2a2 100644 --- a/fury/utils.py +++ b/fury/utils.py @@ -1625,7 +1625,7 @@ def set_actor_origin(actor, *, center=None): def minmax_norm(data, axis=1): - """Returns the min-max normalization of data + """Returns the min-max normalization of data along an axis. Parameters ---------- @@ -1647,11 +1647,11 @@ def minmax_norm(data, axis=1): elif data.ndim > 2: raise ValueError('the dimension of the array must be 2.') - min = data.min(axis=axis) - max = data.max(axis=axis) - if np.array_equal(min, max): + minimum = data.min(axis=axis) + maximum = data.max(axis=axis) + if np.array_equal(minimum, maximum): return data if (axis == 0): - return (data - min)/(max - min) + return (data - minimum)/(maximum - minimum) if (axis == 1): - return (data - min[:, None])/(max - min)[:, None] + return (data - minimum[:, None])/(maximum - minimum)[:, None] From c56920b23af83908f1fc8f68c54482f1b6d2eb72 Mon Sep 17 00:00:00 2001 From: tvcastillod Date: Tue, 16 Apr 2024 09:49:44 -0500 Subject: [PATCH 095/118] reorganized and refactored odf actor --- fury/actor.py | 6 +-- fury/actors/odf.py | 62 +++++++++++++++-------------- fury/shaders/utils/minmax_norm.glsl | 6 +-- 3 files changed, 39 insertions(+), 35 deletions(-) diff --git a/fury/actor.py b/fury/actor.py index 075050f68..681b4e018 100644 --- a/fury/actor.py +++ b/fury/actor.py @@ -4025,7 +4025,7 @@ def odf( centers, coeffs, degree=None, - basis_type='descoteaux', + sh_basis='descoteaux', scales=1.0, opacity=1.0 ): @@ -4044,7 +4044,7 @@ def odf( Index of the highest used band of the spherical harmonics basis. Must be even, at least 2 and at most 12. If None the degree is set based on the number of SH coefficients given. - basis_type: str, optional + sh_basis: str, optional Type of basis (descoteaux, tournier) 'descoteaux' for the default ``descoteaux07`` DYPY basis. 'tournier' for the default ``tournier07` DYPY basis. @@ -4108,4 +4108,4 @@ def odf( total = np.sum(abs(coeffs), axis=1) coeffs = np.dot(np.diag(1 / total * scales), coeffs) * 1.7 - return sh_odf(centers, coeffs, degree, basis_type, scales, opacity) + return sh_odf(centers, coeffs, degree, sh_basis, scales, opacity) diff --git a/fury/actors/odf.py b/fury/actors/odf.py index 5e8fbe4d4..2f2b07f39 100644 --- a/fury/actors/odf.py +++ b/fury/actors/odf.py @@ -18,7 +18,7 @@ from fury.texture.utils import uv_calculations -def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): +def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): """ Visualize one or many ODFs with different features. @@ -28,7 +28,7 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): ODFs positions. coeffs : ndarray 2D ODFs array in SH coefficients. - basis_type: str, optional + sh_basis: str, optional Type of basis (descoteaux, tournier) 'descoteaux' for the default ``descoteaux07`` DYPY basis. 'tournier' for the default ``tournier07` DYPY basis. @@ -56,11 +56,26 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): big_minmax = np.repeat(minmax, 8, axis=0) attribute_to_actor(odf_actor, big_minmax, "minmax") + odf_actor_pd = odf_actor.GetMapper().GetInput() + + n_glyphs = coeffs.shape[0] + # Coordinates to locate the data of each glyph in the texture. + uv_vals = np.array(uv_calculations(n_glyphs)) + num_pnts = uv_vals.shape[0] + + # Definition of texture coordinates to be associated with the actor. + t_coords = FloatArray() + t_coords.SetNumberOfComponents(2) + t_coords.SetNumberOfTuples(num_pnts) + [t_coords.SetTuple(i, uv_vals[i]) for i in range(num_pnts)] + + set_polydata_tcoords(odf_actor_pd, t_coords) + # The coefficient data is stored in a texture to be passed to the shaders. # Data is normalized to a range of 0 to 1. arr = minmax_norm(coeffs) - # Data is turned into values within the RGB color range, and then coverted + # Data is turned into values within the RGB color range, and then converted # into a vtk image data. arr *= 255 grid = numpy_to_vtk_image_data(arr.astype(np.uint8)) @@ -73,21 +88,6 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): # Texture is associated with the actor odf_actor.GetProperty().SetTexture("texture0", texture) - odf_actor_pd = odf_actor.GetMapper().GetInput() - - n_glyphs = coeffs.shape[0] - # Coordinates to locate the data of each glyph in the texture. - uv_vals = np.array(uv_calculations(n_glyphs)) - num_pnts = uv_vals.shape[0] - - # Definition of texture coordinates to be associated with the actor. - t_coords = FloatArray() - t_coords.SetNumberOfComponents(2) - t_coords.SetNumberOfTuples(num_pnts) - [t_coords.SetTuple(i, uv_vals[i]) for i in range(num_pnts)] - - set_polydata_tcoords(odf_actor_pd, t_coords) - # The number of coefficients is associated to the order of the SH odf_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniformf( "numCoeffs", ((degree + 1) * (degree + 2)) / 2 @@ -169,14 +169,19 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): coeffs_norm = import_fury_shader(os.path.join("utils", "minmax_norm.glsl")) - eval_sh_list = '' - for i in range(2, degree+1, 2): + eval_sh_composed = "" + for i in range(2, degree + 1, 2): #PUT sh_degree eval_sh = import_fury_shader( - os.path.join("rt_odfs", basis_type, 'eval_sh_' + str(i) + '.frag')) + os.path.join("rt_odfs", sh_basis, "eval_sh_" + str(i) + ".frag") + ) eval_sh_grad = import_fury_shader( - os.path.join("rt_odfs", basis_type, - 'eval_sh_grad_' + str(i) + '.frag')) - eval_sh_list = eval_sh_list + '\n\n' + eval_sh + '\n\n' + eval_sh_grad + os.path.join( + "rt_odfs", sh_basis, "eval_sh_grad_" + str(i) + ".frag" + ) + ) + eval_sh_composed = compose_shader( + [eval_sh_composed, eval_sh, eval_sh_grad] + ) # Searches a single root of a polynomial within a given interval. # param out_root The location of the found root. @@ -283,7 +288,7 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): fs_dec = compose_shader([ def_sh_degree, def_sh_count, def_max_degree, def_gl_ext_control_flow_attributes, def_no_intersection, def_pis, - fs_vs_vars, coeffs_norm, eval_sh_list, newton_bisection, find_roots, + fs_vs_vars, coeffs_norm, eval_sh_composed, newton_bisection, find_roots, eval_sh, eval_sh_grad, get_inv_vandermonde, ray_sh_glyph_intersections, get_sh_glyph_normal, blinn_phong_model, linear_to_srgb, srgb_to_linear, linear_rgb_to_srgb, srgb_to_linear_rgb, tonemap @@ -311,10 +316,9 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): float i = 1 / (numCoeffs * 2); float sh_coeffs[SH_COUNT]; for(int j=0; j Date: Fri, 23 Feb 2024 09:29:11 -0500 Subject: [PATCH 096/118] added odf actor implementation --- .../SH-ODF experimental/odf_example.py | 31 + fury/actors/odf.py | 174 ++++-- fury/shaders/rt_odfs/eval_sh_grad_10.frag | 430 +++++++++++++ fury/shaders/rt_odfs/eval_sh_grad_12.frag | 591 ++++++++++++++++++ fury/shaders/rt_odfs/eval_sh_grad_2.frag | 46 ++ fury/shaders/rt_odfs/eval_sh_grad_4.frag | 103 +++ fury/shaders/rt_odfs/eval_sh_grad_6.frag | 186 ++++++ fury/shaders/rt_odfs/eval_sh_grad_8.frag | 295 +++++++++ fury/shaders/rt_odfs/find_roots.frag | 82 +++ fury/shaders/rt_odfs/linear_rgb_to_srgb.frag | 4 + fury/shaders/rt_odfs/linear_to_srgb.frag | 4 + fury/shaders/rt_odfs/newton_bisection.frag | 47 ++ fury/shaders/rt_odfs/srgb_to_linear.frag | 4 + fury/shaders/rt_odfs/srgb_to_linear_rgb.frag | 4 + fury/shaders/utils/minmax_norm.glsl | 6 +- 15 files changed, 1943 insertions(+), 64 deletions(-) create mode 100644 docs/experimental/SH-ODF experimental/odf_example.py create mode 100644 fury/shaders/rt_odfs/eval_sh_grad_10.frag create mode 100644 fury/shaders/rt_odfs/eval_sh_grad_12.frag create mode 100644 fury/shaders/rt_odfs/eval_sh_grad_2.frag create mode 100644 fury/shaders/rt_odfs/eval_sh_grad_4.frag create mode 100644 fury/shaders/rt_odfs/eval_sh_grad_6.frag create mode 100644 fury/shaders/rt_odfs/eval_sh_grad_8.frag create mode 100644 fury/shaders/rt_odfs/find_roots.frag create mode 100644 fury/shaders/rt_odfs/linear_rgb_to_srgb.frag create mode 100644 fury/shaders/rt_odfs/linear_to_srgb.frag create mode 100644 fury/shaders/rt_odfs/newton_bisection.frag create mode 100644 fury/shaders/rt_odfs/srgb_to_linear.frag create mode 100644 fury/shaders/rt_odfs/srgb_to_linear_rgb.frag diff --git a/docs/experimental/SH-ODF experimental/odf_example.py b/docs/experimental/SH-ODF experimental/odf_example.py new file mode 100644 index 000000000..3b6c60469 --- /dev/null +++ b/docs/experimental/SH-ODF experimental/odf_example.py @@ -0,0 +1,31 @@ +import os + +import numpy as np +from dipy.data.fetcher import dipy_home +from dipy.io.image import load_nifti + +from fury import actor, window + +if __name__ == "__main__": + show_man = window.ShowManager(size=(1280, 720)) + + dataset_dir = os.path.join(dipy_home, "stanford_hardi") + + coeffs, affine = load_nifti("docs\experimental\SH-ODF experimental\coefs_odf.nii") + + valid_mask = np.abs(coeffs).max(axis=(-1)) > 0 + indices = np.nonzero(valid_mask) + + centers = np.asarray(indices).T + + x, y, z, s = coeffs.shape + coeffs = coeffs[:, :, :].reshape((x * y * z, s)) + n_glyphs = coeffs.shape[0] + + max_val = coeffs.min(axis=1) + total = np.sum(abs(coeffs), axis=1) + coeffs = np.dot(np.diag(1 / total), coeffs) * 1.7 + + odf_actor = actor.odf(centers=centers, coeffs=coeffs) + show_man.scene.add(odf_actor) + show_man.start() \ No newline at end of file diff --git a/fury/actors/odf.py b/fury/actors/odf.py index 2f2b07f39..a6d991033 100644 --- a/fury/actors/odf.py +++ b/fury/actors/odf.py @@ -10,15 +10,36 @@ import_fury_shader, shader_to_actor, ) -from fury.utils import ( - numpy_to_vtk_image_data, - set_polydata_tcoords, - minmax_norm -) -from fury.texture.utils import uv_calculations +from fury.utils import numpy_to_vtk_image_data, set_polydata_tcoords + +def uv_calculations(n): + uvs = [] + for i in range(0, n): + a = (n - (i + 1)) / n + b = (n - i) / n + uvs.extend( + [ + [0.001, a + 0.001], + [0.001, b - 0.001], + [0.999, b - 0.001], + [0.999, a + 0.001], + [0.001, a + 0.001], + [0.001, b - 0.001], + [0.999, b - 0.001], + [0.999, a + 0.001], + ] + ) + return uvs +def minmax_norm(data): + + min = data.min(axis=1) + max = data.max(axis=1) + return np.array([(data[i] - min[i]) / (max[i] - min[i]) + for i in range(data.shape[0])]) + -def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): +def sh_odf(centers, coeffs, basis_type, scales, opacity): """ Visualize one or many ODFs with different features. @@ -28,13 +49,10 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): ODFs positions. coeffs : ndarray 2D ODFs array in SH coefficients. - sh_basis: str, optional + basis_type: str, optional Type of basis (descoteaux, tournier) 'descoteaux' for the default ``descoteaux07`` DYPY basis. 'tournier' for the default ``tournier07` DYPY basis. - degree: int, optional - Index of the highest used band of the spherical harmonics basis. Must - be even, at least 2 and at most 12. scales : float or ndarray (N, ) ODFs size. opacity : float @@ -55,27 +73,12 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): minmax = np.array([coeffs.min(axis=1), coeffs.max(axis=1)]).T big_minmax = np.repeat(minmax, 8, axis=0) attribute_to_actor(odf_actor, big_minmax, "minmax") - - odf_actor_pd = odf_actor.GetMapper().GetInput() - - n_glyphs = coeffs.shape[0] - # Coordinates to locate the data of each glyph in the texture. - uv_vals = np.array(uv_calculations(n_glyphs)) - num_pnts = uv_vals.shape[0] - - # Definition of texture coordinates to be associated with the actor. - t_coords = FloatArray() - t_coords.SetNumberOfComponents(2) - t_coords.SetNumberOfTuples(num_pnts) - [t_coords.SetTuple(i, uv_vals[i]) for i in range(num_pnts)] - - set_polydata_tcoords(odf_actor_pd, t_coords) # The coefficient data is stored in a texture to be passed to the shaders. - + # Data is normalized to a range of 0 to 1. arr = minmax_norm(coeffs) - # Data is turned into values within the RGB color range, and then converted + # Data is turned into values within the RGB color range, and then coverted # into a vtk image data. arr *= 255 grid = numpy_to_vtk_image_data(arr.astype(np.uint8)) @@ -87,14 +90,29 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): # Texture is associated with the actor odf_actor.GetProperty().SetTexture("texture0", texture) + + + odf_actor_pd = odf_actor.GetMapper().GetInput() + + n_glyphs = coeffs.shape[0] + # Coordinates to locate the data of each glyph in the texture. + uv_vals = np.array(uv_calculations(n_glyphs)) + num_pnts = uv_vals.shape[0] + + t_coords = FloatArray() + t_coords.SetNumberOfComponents(2) + t_coords.SetNumberOfTuples(num_pnts) + [t_coords.SetTuple(i, uv_vals[i]) for i in range(num_pnts)] + + set_polydata_tcoords(odf_actor_pd, t_coords) # The number of coefficients is associated to the order of the SH odf_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniformf( - "numCoeffs", ((degree + 1) * (degree + 2)) / 2 + "numCoeffs", 15 ) - + # Start of shader implementation - + vs_dec = \ """ in vec3 center; @@ -124,7 +142,7 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): # The index of the highest used band of the spherical harmonics basis. Must # be even, at least 2 and at most 12. - def_sh_degree = "#define SH_DEGREE " + str(degree) + def_sh_degree = "#define SH_DEGREE 4" # The number of spherical harmonics basis functions def_sh_count = "#define SH_COUNT (((SH_DEGREE + 1) * (SH_DEGREE + 2)) / 2)" @@ -168,20 +186,48 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): """ coeffs_norm = import_fury_shader(os.path.join("utils", "minmax_norm.glsl")) + + eval_sh_2 = import_fury_shader( + os.path.join("rt_odfs", basis_type, "eval_sh_2.frag")) - eval_sh_composed = "" - for i in range(2, degree + 1, 2): #PUT sh_degree - eval_sh = import_fury_shader( - os.path.join("rt_odfs", sh_basis, "eval_sh_" + str(i) + ".frag") - ) - eval_sh_grad = import_fury_shader( - os.path.join( - "rt_odfs", sh_basis, "eval_sh_grad_" + str(i) + ".frag" - ) - ) - eval_sh_composed = compose_shader( - [eval_sh_composed, eval_sh, eval_sh_grad] - ) + eval_sh_4 = import_fury_shader( + os.path.join("rt_odfs", basis_type, "eval_sh_4.frag")) + + eval_sh_6 = import_fury_shader( + os.path.join("rt_odfs", basis_type, "eval_sh_6.frag")) + + eval_sh_8 = import_fury_shader( + os.path.join("rt_odfs", basis_type, "eval_sh_8.frag")) + + eval_sh_10 = import_fury_shader( + os.path.join("rt_odfs", basis_type, "eval_sh_10.frag")) + + eval_sh_12 = import_fury_shader( + os.path.join("rt_odfs", basis_type, "eval_sh_12.frag")) + + eval_sh_grad_2 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_2.frag") + ) + + eval_sh_grad_4 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_4.frag") + ) + + eval_sh_grad_6 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_6.frag") + ) + + eval_sh_grad_8 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_8.frag") + ) + + eval_sh_grad_10 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_10.frag") + ) + + eval_sh_grad_12 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_12.frag") + ) # Searches a single root of a polynomial within a given interval. # param out_root The location of the found root. @@ -200,13 +246,13 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): # # return true if a root was found, false if no root exists. newton_bisection = import_fury_shader( - os.path.join("utils", "newton_bisection.frag") + os.path.join("rt_odfs", "newton_bisection.frag") ) # Finds all roots of the given polynomial in the interval [begin, end] and # writes them to out_roots. Some entries will be NO_INTERSECTION but other # than that the array is sorted. The last entry is always NO_INTERSECTION. - find_roots = import_fury_shader(os.path.join("utils", "find_roots.frag")) + find_roots = import_fury_shader(os.path.join("rt_odfs", "find_roots.frag")) # Evaluates the spherical harmonics basis in bands 0, 2, ..., SH_DEGREE. # Conventions are as in the following paper. @@ -258,22 +304,22 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): # Applies the non-linearity that maps linear RGB to sRGB linear_to_srgb = import_fury_shader( - os.path.join("lighting", "linear_to_srgb.frag") + os.path.join("rt_odfs", "linear_to_srgb.frag") ) # Inverse of linear_to_srgb() srgb_to_linear = import_fury_shader( - os.path.join("lighting", "srgb_to_linear.frag") + os.path.join("rt_odfs", "srgb_to_linear.frag") ) # Turns a linear RGB color (i.e. rec. 709) into sRGB linear_rgb_to_srgb = import_fury_shader( - os.path.join("lighting", "linear_rgb_to_srgb.frag") + os.path.join("rt_odfs", "linear_rgb_to_srgb.frag") ) # Inverse of linear_rgb_to_srgb() srgb_to_linear_rgb = import_fury_shader( - os.path.join("lighting", "srgb_to_linear_rgb.frag") + os.path.join("rt_odfs", "srgb_to_linear_rgb.frag") ) # Logarithmic tonemapping operator. Input and output are linear RGB. @@ -288,10 +334,13 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): fs_dec = compose_shader([ def_sh_degree, def_sh_count, def_max_degree, def_gl_ext_control_flow_attributes, def_no_intersection, def_pis, - fs_vs_vars, coeffs_norm, eval_sh_composed, newton_bisection, find_roots, - eval_sh, eval_sh_grad, get_inv_vandermonde, ray_sh_glyph_intersections, - get_sh_glyph_normal, blinn_phong_model, linear_to_srgb, srgb_to_linear, - linear_rgb_to_srgb, srgb_to_linear_rgb, tonemap + fs_vs_vars, coeffs_norm, eval_sh_2, eval_sh_4, eval_sh_6, eval_sh_8, + eval_sh_10, eval_sh_12, eval_sh_grad_2, eval_sh_grad_4, eval_sh_grad_6, + eval_sh_grad_8, eval_sh_grad_10, eval_sh_grad_12, newton_bisection, + find_roots, eval_sh, eval_sh_grad, get_inv_vandermonde, + ray_sh_glyph_intersections, get_sh_glyph_normal, blinn_phong_model, + linear_to_srgb, srgb_to_linear, linear_rgb_to_srgb, srgb_to_linear_rgb, + tonemap ]) # fmt: on @@ -302,6 +351,7 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): # Ray origin is the camera position in world space ray_origin = "vec3 ro = camPosMCVSOutput;" + # TODO: Check aspect for automatic scaling # Ray direction is the normalized difference between the fragment and the # camera position/ray origin ray_direction = "vec3 rd = normalize(pnt - ro);" @@ -316,9 +366,10 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): float i = 1 / (numCoeffs * 2); float sh_coeffs[SH_COUNT]; for(int j=0; j= 0.0) { + float sqrt_discriminant = sqrt(discriminant); + float scaled_root = derivative[1] + ((derivative[1] > 0.0) ? sqrt_discriminant : (-sqrt_discriminant)); + float root_0 = clamp(-2.0 * derivative[0] / scaled_root, begin, end); + float root_1 = clamp(-0.5 * scaled_root / derivative[2], begin, end); + out_roots[MAX_DEGREE - 2] = min(root_0, root_1); + out_roots[MAX_DEGREE - 1] = max(root_0, root_1); + } + else { + // Indicate that the cubic derivative has a single root + out_roots[MAX_DEGREE - 2] = begin; + out_roots[MAX_DEGREE - 1] = begin; + } + // The last entry in the root array is set to end to make it easier to + // iterate over relevant intervals, all untouched roots are set to begin + out_roots[MAX_DEGREE] = end; + _unroll_ + for (int i = 0; i != MAX_DEGREE - 2; ++i) + out_roots[i] = begin; + // Work your way up to derivatives of higher degree until you reach the + // polynomial itself. This implementation may seem peculiar: It always + // treats the derivative as though it had degree MAX_DEGREE and it + // constructs the derivatives in a contrived way. Changing that would + // reduce the number of arithmetic instructions roughly by a factor of two. + // However, it would also cause register spilling, which has a far more + // negative impact on the overall run time. Profiling indicates that the + // current implementation has no spilling whatsoever. + _loop_ + for (int degree = 3; degree != MAX_DEGREE + 1; ++degree) { + // Take the integral of the previous derivative (scaled such that the + // constant coefficient can still be copied directly from poly) + float prev_derivative_order = float(MAX_DEGREE + 1 - degree); + _unroll_ + for (int i = MAX_DEGREE; i != 0; --i) + derivative[i] = derivative[i - 1] * (prev_derivative_order * (1.0 / float(i))); + // Copy the constant coefficient without causing spilling. This part + // would be harder if the derivative were not scaled the way it is. + _unroll_ + for (int i = 0; i != MAX_DEGREE - 2; ++i) + derivative[0] = (degree == MAX_DEGREE - i) ? poly[i] : derivative[0]; + // Determine the value of this derivative at begin + float begin_value = derivative[MAX_DEGREE]; + _unroll_ + for (int i = MAX_DEGREE - 1; i != -1; --i) + begin_value = begin_value * begin + derivative[i]; + // Iterate over the intervals where roots may be found + _unroll_ + for (int i = 0; i != MAX_DEGREE; ++i) { + if (i < MAX_DEGREE - degree) + continue; + float current_begin = out_roots[i]; + float current_end = out_roots[i + 1]; + // Try to find a root + float root; + if (newton_bisection(root, begin_value, derivative, current_begin, current_end, begin_value, tolerance)) + out_roots[i] = root; + else if (degree < MAX_DEGREE) + // Create an empty interval for the next iteration + out_roots[i] = out_roots[i - 1]; + else + out_roots[i] = NO_INTERSECTION; + } + } + // We no longer need this array entry + out_roots[MAX_DEGREE] = NO_INTERSECTION; +} diff --git a/fury/shaders/rt_odfs/linear_rgb_to_srgb.frag b/fury/shaders/rt_odfs/linear_rgb_to_srgb.frag new file mode 100644 index 000000000..d1c72c83b --- /dev/null +++ b/fury/shaders/rt_odfs/linear_rgb_to_srgb.frag @@ -0,0 +1,4 @@ +vec3 linear_rgb_to_srgb(vec3 linear) +{ + return vec3(linear_to_srgb(linear.r), linear_to_srgb(linear.g), linear_to_srgb(linear.b)); +} diff --git a/fury/shaders/rt_odfs/linear_to_srgb.frag b/fury/shaders/rt_odfs/linear_to_srgb.frag new file mode 100644 index 000000000..ac686853c --- /dev/null +++ b/fury/shaders/rt_odfs/linear_to_srgb.frag @@ -0,0 +1,4 @@ +float linear_to_srgb(float linear) +{ + return (linear <= 0.0031308) ? (12.92 * linear) : (1.055 * pow(linear, 1.0 / 2.4) - 0.055); +} diff --git a/fury/shaders/rt_odfs/newton_bisection.frag b/fury/shaders/rt_odfs/newton_bisection.frag new file mode 100644 index 000000000..3f4b7f81f --- /dev/null +++ b/fury/shaders/rt_odfs/newton_bisection.frag @@ -0,0 +1,47 @@ +bool newton_bisection(out float out_root, out float out_end_value, + float poly[MAX_DEGREE + 1], float begin, float end, + float begin_value, float error_tolerance) +{ + if (begin == end) { + out_end_value = begin_value; + return false; + } + // Evaluate the polynomial at the end of the interval + out_end_value = poly[MAX_DEGREE]; + _unroll_ + for (int i = MAX_DEGREE - 1; i != -1; --i) + out_end_value = out_end_value * end + poly[i]; + // If the values at both ends have the same non-zero sign, there is no root + if (begin_value * out_end_value > 0.0) + return false; + // Otherwise, we find the root iteratively using Newton bisection (with + // bounded iteration count) + float current = 0.5 * (begin + end); + _loop_ + for (int i = 0; i != 90; ++i) { + // Evaluate the polynomial and its derivative + float value = poly[MAX_DEGREE] * current + poly[MAX_DEGREE - 1]; + float derivative = poly[MAX_DEGREE]; + _unroll_ + for (int j = MAX_DEGREE - 2; j != -1; --j) { + derivative = derivative * current + value; + value = value * current + poly[j]; + } + // Shorten the interval + bool right = begin_value * value > 0.0; + begin = right ? current : begin; + end = right ? end : current; + // Apply Newton's method + float guess = current - value / derivative; + // Pick a guess + float middle = 0.5 * (begin + end); + float next = (guess >= begin && guess <= end) ? guess : middle; + // Move along or terminate + bool done = abs(next - current) < error_tolerance; + current = next; + if (done) + break; + } + out_root = current; + return true; +} diff --git a/fury/shaders/rt_odfs/srgb_to_linear.frag b/fury/shaders/rt_odfs/srgb_to_linear.frag new file mode 100644 index 000000000..78c765c20 --- /dev/null +++ b/fury/shaders/rt_odfs/srgb_to_linear.frag @@ -0,0 +1,4 @@ +float srgb_to_linear(float non_linear) +{ + return (non_linear <= 0.04045) ? ((1.0 / 12.92) * non_linear) : pow(non_linear * (1.0 / 1.055) + 0.055 / 1.055, 2.4); +} diff --git a/fury/shaders/rt_odfs/srgb_to_linear_rgb.frag b/fury/shaders/rt_odfs/srgb_to_linear_rgb.frag new file mode 100644 index 000000000..e4c2ef22a --- /dev/null +++ b/fury/shaders/rt_odfs/srgb_to_linear_rgb.frag @@ -0,0 +1,4 @@ +vec3 srgb_to_linear_rgb(vec3 srgb) +{ + return vec3(srgb_to_linear(srgb.r), srgb_to_linear(srgb.g), srgb_to_linear(srgb.b)); +} diff --git a/fury/shaders/utils/minmax_norm.glsl b/fury/shaders/utils/minmax_norm.glsl index fea8817ae..7992b53c7 100644 --- a/fury/shaders/utils/minmax_norm.glsl +++ b/fury/shaders/utils/minmax_norm.glsl @@ -1,4 +1,4 @@ -float rescale(float x, float oldMin, float oldMax, float newMin, float newMax) +float coeffsNorm(float coef, float min, float max, float a, float b) { - return (x - oldMin) * (newMax - newMin) / (oldMax - oldMin) + newMin; -} + return (coef - min) * ((b - a) / (max - min)) + a; +} \ No newline at end of file From 18dc83a5727ff880657b9bfc98224ee1f3a531fd Mon Sep 17 00:00:00 2001 From: tvcastillod Date: Fri, 23 Feb 2024 11:19:51 -0500 Subject: [PATCH 097/118] adjusted scaling --- docs/experimental/SH-ODF experimental/odf_example.py | 6 +----- fury/actor.py | 3 +++ 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/docs/experimental/SH-ODF experimental/odf_example.py b/docs/experimental/SH-ODF experimental/odf_example.py index 3b6c60469..e16858211 100644 --- a/docs/experimental/SH-ODF experimental/odf_example.py +++ b/docs/experimental/SH-ODF experimental/odf_example.py @@ -22,10 +22,6 @@ coeffs = coeffs[:, :, :].reshape((x * y * z, s)) n_glyphs = coeffs.shape[0] - max_val = coeffs.min(axis=1) - total = np.sum(abs(coeffs), axis=1) - coeffs = np.dot(np.diag(1 / total), coeffs) * 1.7 - - odf_actor = actor.odf(centers=centers, coeffs=coeffs) + odf_actor = actor.odf(centers=centers, coeffs=coeffs, scales=1.0) show_man.scene.add(odf_actor) show_man.start() \ No newline at end of file diff --git a/fury/actor.py b/fury/actor.py index 681b4e018..90438a7ce 100644 --- a/fury/actor.py +++ b/fury/actor.py @@ -4104,6 +4104,9 @@ def odf( elif scales.size != centers.shape[0]: scales = np.concatenate( (scales, np.ones(centers.shape[0] - scales.shape[0])), axis=None) + + total = np.sum(abs(coeffs), axis=1) + coeffs = np.dot(np.diag(1 / total * scales), coeffs) * 1.7 total = np.sum(abs(coeffs), axis=1) coeffs = np.dot(np.diag(1 / total * scales), coeffs) * 1.7 From e25971321de1f8b8ef0ebf958cdb989a0e9ddc15 Mon Sep 17 00:00:00 2001 From: tvcastillod Date: Tue, 27 Feb 2024 13:01:14 -0500 Subject: [PATCH 098/118] reorganized files --- fury/actors/odf.py | 24 +- fury/shaders/rt_odfs/eval_sh_grad_10.frag | 430 ------------- fury/shaders/rt_odfs/eval_sh_grad_12.frag | 591 ------------------ fury/shaders/rt_odfs/eval_sh_grad_8.frag | 295 --------- fury/shaders/rt_odfs/find_roots.frag | 82 --- fury/shaders/rt_odfs/linear_rgb_to_srgb.frag | 4 - fury/shaders/rt_odfs/linear_to_srgb.frag | 4 - fury/shaders/rt_odfs/newton_bisection.frag | 47 -- fury/shaders/rt_odfs/srgb_to_linear.frag | 4 - fury/shaders/rt_odfs/srgb_to_linear_rgb.frag | 4 - .../tournier/eval_sh_grad_10 copy.frag | 430 +++++++++++++ .../tournier/eval_sh_grad_12 copy.frag | 591 ++++++++++++++++++ .../eval_sh_grad_2 copy.frag} | 28 +- .../eval_sh_grad_4 copy.frag} | 96 +-- .../eval_sh_grad_6 copy.frag} | 192 +++--- .../rt_odfs/tournier/eval_sh_grad_8 copy.frag | 295 +++++++++ 16 files changed, 1486 insertions(+), 1631 deletions(-) delete mode 100644 fury/shaders/rt_odfs/eval_sh_grad_10.frag delete mode 100644 fury/shaders/rt_odfs/eval_sh_grad_12.frag delete mode 100644 fury/shaders/rt_odfs/eval_sh_grad_8.frag delete mode 100644 fury/shaders/rt_odfs/find_roots.frag delete mode 100644 fury/shaders/rt_odfs/linear_rgb_to_srgb.frag delete mode 100644 fury/shaders/rt_odfs/linear_to_srgb.frag delete mode 100644 fury/shaders/rt_odfs/newton_bisection.frag delete mode 100644 fury/shaders/rt_odfs/srgb_to_linear.frag delete mode 100644 fury/shaders/rt_odfs/srgb_to_linear_rgb.frag create mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_grad_10 copy.frag create mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_grad_12 copy.frag rename fury/shaders/rt_odfs/{eval_sh_grad_2.frag => tournier/eval_sh_grad_2 copy.frag} (69%) rename fury/shaders/rt_odfs/{eval_sh_grad_4.frag => tournier/eval_sh_grad_4 copy.frag} (54%) rename fury/shaders/rt_odfs/{eval_sh_grad_6.frag => tournier/eval_sh_grad_6 copy.frag} (50%) create mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_grad_8 copy.frag diff --git a/fury/actors/odf.py b/fury/actors/odf.py index a6d991033..e8a762c55 100644 --- a/fury/actors/odf.py +++ b/fury/actors/odf.py @@ -206,27 +206,27 @@ def sh_odf(centers, coeffs, basis_type, scales, opacity): os.path.join("rt_odfs", basis_type, "eval_sh_12.frag")) eval_sh_grad_2 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_2.frag") + os.path.join("rt_odfs/descoteaux", "eval_sh_grad_2.frag") ) eval_sh_grad_4 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_4.frag") + os.path.join("rt_odfs/descoteaux", "eval_sh_grad_4.frag") ) eval_sh_grad_6 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_6.frag") + os.path.join("rt_odfs/descoteaux", "eval_sh_grad_6.frag") ) eval_sh_grad_8 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_8.frag") + os.path.join("rt_odfs/descoteaux", "eval_sh_grad_8.frag") ) eval_sh_grad_10 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_10.frag") + os.path.join("rt_odfs/descoteaux", "eval_sh_grad_10.frag") ) eval_sh_grad_12 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_12.frag") + os.path.join("rt_odfs/descoteaux", "eval_sh_grad_12.frag") ) # Searches a single root of a polynomial within a given interval. @@ -246,13 +246,13 @@ def sh_odf(centers, coeffs, basis_type, scales, opacity): # # return true if a root was found, false if no root exists. newton_bisection = import_fury_shader( - os.path.join("rt_odfs", "newton_bisection.frag") + os.path.join("utils", "newton_bisection.frag") ) # Finds all roots of the given polynomial in the interval [begin, end] and # writes them to out_roots. Some entries will be NO_INTERSECTION but other # than that the array is sorted. The last entry is always NO_INTERSECTION. - find_roots = import_fury_shader(os.path.join("rt_odfs", "find_roots.frag")) + find_roots = import_fury_shader(os.path.join("utils", "find_roots.frag")) # Evaluates the spherical harmonics basis in bands 0, 2, ..., SH_DEGREE. # Conventions are as in the following paper. @@ -304,22 +304,22 @@ def sh_odf(centers, coeffs, basis_type, scales, opacity): # Applies the non-linearity that maps linear RGB to sRGB linear_to_srgb = import_fury_shader( - os.path.join("rt_odfs", "linear_to_srgb.frag") + os.path.join("lighting", "linear_to_srgb.frag") ) # Inverse of linear_to_srgb() srgb_to_linear = import_fury_shader( - os.path.join("rt_odfs", "srgb_to_linear.frag") + os.path.join("lighting", "srgb_to_linear.frag") ) # Turns a linear RGB color (i.e. rec. 709) into sRGB linear_rgb_to_srgb = import_fury_shader( - os.path.join("rt_odfs", "linear_rgb_to_srgb.frag") + os.path.join("lighting", "linear_rgb_to_srgb.frag") ) # Inverse of linear_rgb_to_srgb() srgb_to_linear_rgb = import_fury_shader( - os.path.join("rt_odfs", "srgb_to_linear_rgb.frag") + os.path.join("lighting", "srgb_to_linear_rgb.frag") ) # Logarithmic tonemapping operator. Input and output are linear RGB. diff --git a/fury/shaders/rt_odfs/eval_sh_grad_10.frag b/fury/shaders/rt_odfs/eval_sh_grad_10.frag deleted file mode 100644 index 9d5feea39..000000000 --- a/fury/shaders/rt_odfs/eval_sh_grad_10.frag +++ /dev/null @@ -1,430 +0,0 @@ -void eval_sh_grad_10(out float out_shs[66], out vec3 out_grads[66], vec3 point) -{ - float x, y, z, z2, c0, s0, c1, s1, d, a, b; - x = point[0]; - y = point[1]; - z = point[2]; - z2 = z * z; - c0 = 1.0; - s0 = 0.0; - d = 0.282094792; - out_shs[0] = d; - a = z2 - 0.333333333; - d = 0.946174696 * a; - out_shs[3] = d; - b = z2 * (a - 0.266666667); - a = b - 0.257142857 * a; - d = 3.702494142 * a; - out_shs[10] = d; - b = z2 * a - 0.253968254 * b; - a = b - 0.252525253 * a; - d = 14.684485724 * a; - out_shs[21] = d; - b = z2 * a - 0.251748252 * b; - a = b - 0.251282051 * a; - d = 58.473368113 * a; - out_shs[36] = d; - b = z2 * a - 0.250980392 * b; - a = b - 0.250773994 * a; - d = 233.240148813 * a; - out_shs[55] = d; - c1 = x; - s1 = y; - d = -1.092548431 * z; - out_shs[2] = -c1 * d; - out_shs[4] = s1 * d; - out_grads[2][0] = -c0 * d; - out_grads[4][0] = s0 * d; - out_grads[2][1] = s0 * d; - out_grads[4][1] = c0 * d; - d = 1.892349392 * z; - out_grads[3][2] = d; - a = (z2 - 0.2) * z; - b = a - 0.228571429 * z; - d = -4.683325805 * b; - out_shs[9] = -c1 * d; - out_shs[11] = s1 * d; - out_grads[9][0] = -c0 * d; - out_grads[11][0] = s0 * d; - out_grads[9][1] = s0 * d; - out_grads[11][1] = c0 * d; - d = 14.809976568 * b; - out_grads[10][2] = d; - a = z2 * b - 0.238095238 * a; - b = a - 0.242424242 * b; - d = -19.226504963 * b; - out_shs[20] = -c1 * d; - out_shs[22] = s1 * d; - out_grads[20][0] = -c0 * d; - out_grads[22][0] = s0 * d; - out_grads[20][1] = s0 * d; - out_grads[22][1] = c0 * d; - d = 88.106914343 * b; - out_grads[21][2] = d; - a = z2 * b - 0.244755245 * a; - b = a - 0.246153846 * b; - d = -77.964490818 * b; - out_shs[35] = -c1 * d; - out_shs[37] = s1 * d; - out_grads[35][0] = -c0 * d; - out_grads[37][0] = s0 * d; - out_grads[35][1] = s0 * d; - out_grads[37][1] = c0 * d; - d = 467.786944906 * b; - out_grads[36][2] = d; - a = z2 * b - 0.247058824 * a; - b = a - 0.247678019 * b; - d = -314.500952502 * b; - out_shs[54] = -c1 * d; - out_shs[56] = s1 * d; - out_grads[54][0] = -c0 * d; - out_grads[56][0] = s0 * d; - out_grads[54][1] = s0 * d; - out_grads[56][1] = c0 * d; - d = 2332.401488133 * b; - out_grads[55][2] = d; - c0 = x * c1 - y * s1; - s0 = y * c1 + x * s1; - d = 0.546274215; - out_shs[1] = c0 * d; - out_shs[5] = s0 * d; - d = 1.092548431; - out_grads[1][0] = c1 * d; - out_grads[5][0] = s1 * d; - out_grads[1][1] = -s1 * d; - out_grads[5][1] = c1 * d; - d = -1.092548431; - out_grads[2][2] = -c1 * d; - out_grads[4][2] = s1 * d; - a = z2 - 0.142857143; - d = 3.311611435 * a; - out_shs[8] = c0 * d; - out_shs[12] = s0 * d; - d = 6.62322287 * a; - out_grads[8][0] = c1 * d; - out_grads[12][0] = s1 * d; - out_grads[8][1] = -s1 * d; - out_grads[12][1] = c1 * d; - d = -14.049977415 * a; - out_grads[9][2] = -c1 * d; - out_grads[11][2] = s1 * d; - b = z2 * (a - 0.19047619); - a = b - 0.212121212 * a; - d = 15.199886782 * a; - out_shs[19] = c0 * d; - out_shs[23] = s0 * d; - d = 30.399773564 * a; - out_grads[19][0] = c1 * d; - out_grads[23][0] = s1 * d; - out_grads[19][1] = -s1 * d; - out_grads[23][1] = c1 * d; - d = -96.132524816 * a; - out_grads[20][2] = -c1 * d; - out_grads[22][2] = s1 * d; - b = z2 * a - 0.223776224 * b; - a = b - 0.230769231 * a; - d = 65.229772956 * a; - out_shs[34] = c0 * d; - out_shs[38] = s0 * d; - d = 130.459545912 * a; - out_grads[34][0] = c1 * d; - out_grads[38][0] = s1 * d; - out_grads[34][1] = -s1 * d; - out_grads[38][1] = c1 * d; - d = -545.751435723 * a; - out_grads[35][2] = -c1 * d; - out_grads[37][2] = s1 * d; - b = z2 * a - 0.235294118 * b; - a = b - 0.238390093 * a; - d = 272.365814381 * a; - out_shs[53] = c0 * d; - out_shs[57] = s0 * d; - d = 544.731628762 * a; - out_grads[53][0] = c1 * d; - out_grads[57][0] = s1 * d; - out_grads[53][1] = -s1 * d; - out_grads[57][1] = c1 * d; - d = -2830.508572514 * a; - out_grads[54][2] = -c1 * d; - out_grads[56][2] = s1 * d; - c1 = x * c0 - y * s0; - s1 = y * c0 + x * s0; - d = -1.77013077 * z; - out_shs[7] = -c1 * d; - out_shs[13] = s1 * d; - d = -5.310392309 * z; - out_grads[7][0] = -c0 * d; - out_grads[13][0] = s0 * d; - out_grads[7][1] = s0 * d; - out_grads[13][1] = c0 * d; - d = 6.62322287 * z; - out_grads[8][2] = c0 * d; - out_grads[12][2] = s0 * d; - a = (z2 - 0.111111111) * z; - b = a - 0.161616162 * z; - d = -10.133257855 * b; - out_shs[18] = -c1 * d; - out_shs[24] = s1 * d; - d = -30.399773564 * b; - out_grads[18][0] = -c0 * d; - out_grads[24][0] = s0 * d; - out_grads[18][1] = s0 * d; - out_grads[24][1] = c0 * d; - d = 60.799547128 * b; - out_grads[19][2] = c0 * d; - out_grads[23][2] = s0 * d; - a = z2 * b - 0.188811189 * a; - b = a - 0.205128205 * b; - d = -48.175380057 * b; - out_shs[33] = -c1 * d; - out_shs[39] = s1 * d; - d = -144.52614017 * b; - out_grads[33][0] = -c0 * d; - out_grads[39][0] = s0 * d; - out_grads[33][1] = s0 * d; - out_grads[39][1] = c0 * d; - d = 391.378637737 * b; - out_grads[34][2] = c0 * d; - out_grads[38][2] = s0 * d; - a = z2 * b - 0.215686275 * a; - b = a - 0.222910217 * b; - d = -213.661323441 * b; - out_shs[52] = -c1 * d; - out_shs[58] = s1 * d; - d = -640.983970322 * b; - out_grads[52][0] = -c0 * d; - out_grads[58][0] = s0 * d; - out_grads[52][1] = s0 * d; - out_grads[58][1] = c0 * d; - d = 2178.926515046 * b; - out_grads[53][2] = c0 * d; - out_grads[57][2] = s0 * d; - c0 = x * c1 - y * s1; - s0 = y * c1 + x * s1; - d = 0.625835735; - out_shs[6] = c0 * d; - out_shs[14] = s0 * d; - d = 2.503342942; - out_grads[6][0] = c1 * d; - out_grads[14][0] = s1 * d; - out_grads[6][1] = -s1 * d; - out_grads[14][1] = c1 * d; - d = -1.77013077; - out_grads[7][2] = -c1 * d; - out_grads[13][2] = s1 * d; - a = z2 - 9.09090909e-02; - d = 5.550213908 * a; - out_shs[17] = c0 * d; - out_shs[25] = s0 * d; - d = 22.200855632 * a; - out_grads[17][0] = c1 * d; - out_grads[25][0] = s1 * d; - out_grads[17][1] = -s1 * d; - out_grads[25][1] = c1 * d; - d = -30.399773564 * a; - out_grads[18][2] = -c1 * d; - out_grads[24][2] = s1 * d; - b = z2 * (a - 0.13986014); - a = b - 0.169230769 * a; - d = 31.097074109 * a; - out_shs[32] = c0 * d; - out_shs[40] = s0 * d; - d = 124.388296437 * a; - out_grads[32][0] = c1 * d; - out_grads[40][0] = s1 * d; - out_grads[32][1] = -s1 * d; - out_grads[40][1] = c1 * d; - d = -240.876900283 * a; - out_grads[33][2] = -c1 * d; - out_grads[39][2] = s1 * d; - b = z2 * a - 0.188235294 * b; - a = b - 0.20123839 * a; - d = 151.081370682 * a; - out_shs[51] = c0 * d; - out_shs[59] = s0 * d; - d = 604.325482728 * a; - out_grads[51][0] = c1 * d; - out_grads[59][0] = s1 * d; - out_grads[51][1] = -s1 * d; - out_grads[59][1] = c1 * d; - d = -1495.629264084 * a; - out_grads[52][2] = -c1 * d; - out_grads[58][2] = s1 * d; - c1 = x * c0 - y * s0; - s1 = y * c0 + x * s0; - d = -2.366619162 * z; - out_shs[16] = -c1 * d; - out_shs[26] = s1 * d; - d = -11.833095811 * z; - out_grads[16][0] = -c0 * d; - out_grads[26][0] = s0 * d; - out_grads[16][1] = s0 * d; - out_grads[26][1] = c0 * d; - d = 11.100427816 * z; - out_grads[17][2] = c0 * d; - out_grads[25][2] = s0 * d; - a = (z2 - 7.69230769e-02) * z; - b = a - 0.123076923 * z; - d = -17.24955311 * b; - out_shs[31] = -c1 * d; - out_shs[41] = s1 * d; - d = -86.247765552 * b; - out_grads[31][0] = -c0 * d; - out_grads[41][0] = s0 * d; - out_grads[31][1] = s0 * d; - out_grads[41][1] = c0 * d; - d = 124.388296437 * b; - out_grads[32][2] = c0 * d; - out_grads[40][2] = s0 * d; - a = z2 * b - 0.152941176 * a; - b = a - 0.173374613 * b; - d = -95.552248675 * b; - out_shs[50] = -c1 * d; - out_shs[60] = s1 * d; - d = -477.761243376 * b; - out_grads[50][0] = -c0 * d; - out_grads[60][0] = s0 * d; - out_grads[50][1] = s0 * d; - out_grads[60][1] = c0 * d; - d = 906.488224092 * b; - out_grads[51][2] = c0 * d; - out_grads[59][2] = s0 * d; - c0 = x * c1 - y * s1; - s0 = y * c1 + x * s1; - d = 0.683184105; - out_shs[15] = c0 * d; - out_shs[27] = s0 * d; - d = 4.099104631; - out_grads[15][0] = c1 * d; - out_grads[27][0] = s1 * d; - out_grads[15][1] = -s1 * d; - out_grads[27][1] = c1 * d; - d = -2.366619162; - out_grads[16][2] = -c1 * d; - out_grads[26][2] = s1 * d; - a = z2 - 6.66666667e-02; - d = 7.984991491 * a; - out_shs[30] = c0 * d; - out_shs[42] = s0 * d; - d = 47.909948945 * a; - out_grads[30][0] = c1 * d; - out_grads[42][0] = s1 * d; - out_grads[30][1] = -s1 * d; - out_grads[42][1] = c1 * d; - d = -51.748659331 * a; - out_grads[31][2] = -c1 * d; - out_grads[41][2] = s1 * d; - b = z2 * (a - 0.109803922); - a = b - 0.139318885 * a; - d = 53.41533086 * a; - out_shs[49] = c0 * d; - out_shs[61] = s0 * d; - d = 320.491985161 * a; - out_grads[49][0] = c1 * d; - out_grads[61][0] = s1 * d; - out_grads[49][1] = -s1 * d; - out_grads[61][1] = c1 * d; - d = -477.761243376 * a; - out_grads[50][2] = -c1 * d; - out_grads[60][2] = s1 * d; - c1 = x * c0 - y * s0; - s1 = y * c0 + x * s0; - d = -2.915706641 * z; - out_shs[29] = -c1 * d; - out_shs[43] = s1 * d; - d = -20.409946485 * z; - out_grads[29][0] = -c0 * d; - out_grads[43][0] = s0 * d; - out_grads[29][1] = s0 * d; - out_grads[43][1] = c0 * d; - d = 15.969982982 * z; - out_grads[30][2] = c0 * d; - out_grads[42][2] = s0 * d; - a = (z2 - 5.88235294e-02) * z; - b = a - 9.90712074e-02 * z; - d = -25.910241313 * b; - out_shs[48] = -c1 * d; - out_shs[62] = s1 * d; - d = -181.371689194 * b; - out_grads[48][0] = -c0 * d; - out_grads[62][0] = s0 * d; - out_grads[48][1] = s0 * d; - out_grads[62][1] = c0 * d; - d = 213.661323441 * b; - out_grads[49][2] = c0 * d; - out_grads[61][2] = s0 * d; - c0 = x * c1 - y * s1; - s0 = y * c1 + x * s1; - d = 0.72892666; - out_shs[28] = c0 * d; - out_shs[44] = s0 * d; - d = 5.831413281; - out_grads[28][0] = c1 * d; - out_grads[44][0] = s1 * d; - out_grads[28][1] = -s1 * d; - out_grads[44][1] = c1 * d; - d = -2.915706641; - out_grads[29][2] = -c1 * d; - out_grads[43][2] = s1 * d; - a = z2 - 5.26315789e-02; - d = 10.577811722 * a; - out_shs[47] = c0 * d; - out_shs[63] = s0 * d; - d = 84.622493774 * a; - out_grads[47][0] = c1 * d; - out_grads[63][0] = s1 * d; - out_grads[47][1] = -s1 * d; - out_grads[63][1] = c1 * d; - d = -77.73072394 * a; - out_grads[48][2] = -c1 * d; - out_grads[62][2] = s1 * d; - c1 = x * c0 - y * s0; - s1 = y * c0 + x * s0; - d = -3.4318953 * z; - out_shs[46] = -c1 * d; - out_shs[64] = s1 * d; - d = -30.887057699 * z; - out_grads[46][0] = -c0 * d; - out_grads[64][0] = s0 * d; - out_grads[46][1] = s0 * d; - out_grads[64][1] = c0 * d; - d = 21.155623443 * z; - out_grads[47][2] = c0 * d; - out_grads[63][2] = s0 * d; - c0 = x * c1 - y * s1; - s0 = y * c1 + x * s1; - d = 0.767395118; - out_shs[45] = c0 * d; - out_shs[65] = s0 * d; - d = 7.673951182; - out_grads[45][0] = c1 * d; - out_grads[65][0] = s1 * d; - out_grads[45][1] = -s1 * d; - out_grads[65][1] = c1 * d; - d = -3.4318953; - out_grads[46][2] = -c1 * d; - out_grads[64][2] = s1 * d; - out_grads[0][0] = 0.0; - out_grads[0][1] = 0.0; - out_grads[0][2] = 0.0; - out_grads[1][2] = 0.0; - out_grads[3][0] = 0.0; - out_grads[3][1] = 0.0; - out_grads[5][2] = 0.0; - out_grads[6][2] = 0.0; - out_grads[10][0] = 0.0; - out_grads[10][1] = 0.0; - out_grads[14][2] = 0.0; - out_grads[15][2] = 0.0; - out_grads[21][0] = 0.0; - out_grads[21][1] = 0.0; - out_grads[27][2] = 0.0; - out_grads[28][2] = 0.0; - out_grads[36][0] = 0.0; - out_grads[36][1] = 0.0; - out_grads[44][2] = 0.0; - out_grads[45][2] = 0.0; - out_grads[55][0] = 0.0; - out_grads[55][1] = 0.0; - out_grads[65][2] = 0.0; -} diff --git a/fury/shaders/rt_odfs/eval_sh_grad_12.frag b/fury/shaders/rt_odfs/eval_sh_grad_12.frag deleted file mode 100644 index f7ff069bc..000000000 --- a/fury/shaders/rt_odfs/eval_sh_grad_12.frag +++ /dev/null @@ -1,591 +0,0 @@ -void eval_sh_grad_12(out float out_shs[91], out vec3 out_grads[91], vec3 point) -{ - float x, y, z, z2, c0, s0, c1, s1, d, a, b; - x = point[0]; - y = point[1]; - z = point[2]; - z2 = z * z; - c0 = 1.0; - s0 = 0.0; - d = 0.282094792; - out_shs[0] = d; - a = z2 - 0.333333333; - d = 0.946174696 * a; - out_shs[3] = d; - b = z2 * (a - 0.266666667); - a = b - 0.257142857 * a; - d = 3.702494142 * a; - out_shs[10] = d; - b = z2 * a - 0.253968254 * b; - a = b - 0.252525253 * a; - d = 14.684485724 * a; - out_shs[21] = d; - b = z2 * a - 0.251748252 * b; - a = b - 0.251282051 * a; - d = 58.473368113 * a; - out_shs[36] = d; - b = z2 * a - 0.250980392 * b; - a = b - 0.250773994 * a; - d = 233.240148813 * a; - out_shs[55] = d; - b = z2 * a - 0.250626566 * b; - a = b - 0.250517598 * a; - d = 931.186918633 * a; - out_shs[78] = d; - c1 = x; - s1 = y; - d = -1.092548431 * z; - out_shs[2] = -c1 * d; - out_shs[4] = s1 * d; - out_grads[2][0] = -c0 * d; - out_grads[4][0] = s0 * d; - out_grads[2][1] = s0 * d; - out_grads[4][1] = c0 * d; - d = 1.892349392 * z; - out_grads[3][2] = d; - a = (z2 - 0.2) * z; - b = a - 0.228571429 * z; - d = -4.683325805 * b; - out_shs[9] = -c1 * d; - out_shs[11] = s1 * d; - out_grads[9][0] = -c0 * d; - out_grads[11][0] = s0 * d; - out_grads[9][1] = s0 * d; - out_grads[11][1] = c0 * d; - d = 14.809976568 * b; - out_grads[10][2] = d; - a = z2 * b - 0.238095238 * a; - b = a - 0.242424242 * b; - d = -19.226504963 * b; - out_shs[20] = -c1 * d; - out_shs[22] = s1 * d; - out_grads[20][0] = -c0 * d; - out_grads[22][0] = s0 * d; - out_grads[20][1] = s0 * d; - out_grads[22][1] = c0 * d; - d = 88.106914343 * b; - out_grads[21][2] = d; - a = z2 * b - 0.244755245 * a; - b = a - 0.246153846 * b; - d = -77.964490818 * b; - out_shs[35] = -c1 * d; - out_shs[37] = s1 * d; - out_grads[35][0] = -c0 * d; - out_grads[37][0] = s0 * d; - out_grads[35][1] = s0 * d; - out_grads[37][1] = c0 * d; - d = 467.786944906 * b; - out_grads[36][2] = d; - a = z2 * b - 0.247058824 * a; - b = a - 0.247678019 * b; - d = -314.500952502 * b; - out_shs[54] = -c1 * d; - out_shs[56] = s1 * d; - out_grads[54][0] = -c0 * d; - out_grads[56][0] = s0 * d; - out_grads[54][1] = s0 * d; - out_grads[56][1] = c0 * d; - d = 2332.401488133 * b; - out_grads[55][2] = d; - a = z2 * b - 0.248120301 * a; - b = a - 0.248447205 * b; - d = -1265.233874957 * b; - out_shs[77] = -c1 * d; - out_shs[79] = s1 * d; - out_grads[77][0] = -c0 * d; - out_grads[79][0] = s0 * d; - out_grads[77][1] = s0 * d; - out_grads[79][1] = c0 * d; - d = 11174.243023595 * b; - out_grads[78][2] = d; - c0 = x * c1 - y * s1; - s0 = y * c1 + x * s1; - d = 0.546274215; - out_shs[1] = c0 * d; - out_shs[5] = s0 * d; - d = 1.092548431; - out_grads[1][0] = c1 * d; - out_grads[5][0] = s1 * d; - out_grads[1][1] = -s1 * d; - out_grads[5][1] = c1 * d; - d = -1.092548431; - out_grads[2][2] = -c1 * d; - out_grads[4][2] = s1 * d; - a = z2 - 0.142857143; - d = 3.311611435 * a; - out_shs[8] = c0 * d; - out_shs[12] = s0 * d; - d = 6.62322287 * a; - out_grads[8][0] = c1 * d; - out_grads[12][0] = s1 * d; - out_grads[8][1] = -s1 * d; - out_grads[12][1] = c1 * d; - d = -14.049977415 * a; - out_grads[9][2] = -c1 * d; - out_grads[11][2] = s1 * d; - b = z2 * (a - 0.19047619); - a = b - 0.212121212 * a; - d = 15.199886782 * a; - out_shs[19] = c0 * d; - out_shs[23] = s0 * d; - d = 30.399773564 * a; - out_grads[19][0] = c1 * d; - out_grads[23][0] = s1 * d; - out_grads[19][1] = -s1 * d; - out_grads[23][1] = c1 * d; - d = -96.132524816 * a; - out_grads[20][2] = -c1 * d; - out_grads[22][2] = s1 * d; - b = z2 * a - 0.223776224 * b; - a = b - 0.230769231 * a; - d = 65.229772956 * a; - out_shs[34] = c0 * d; - out_shs[38] = s0 * d; - d = 130.459545912 * a; - out_grads[34][0] = c1 * d; - out_grads[38][0] = s1 * d; - out_grads[34][1] = -s1 * d; - out_grads[38][1] = c1 * d; - d = -545.751435723 * a; - out_grads[35][2] = -c1 * d; - out_grads[37][2] = s1 * d; - b = z2 * a - 0.235294118 * b; - a = b - 0.238390093 * a; - d = 272.365814381 * a; - out_shs[53] = c0 * d; - out_shs[57] = s0 * d; - d = 544.731628762 * a; - out_grads[53][0] = c1 * d; - out_grads[57][0] = s1 * d; - out_grads[53][1] = -s1 * d; - out_grads[57][1] = c1 * d; - d = -2830.508572514 * a; - out_grads[54][2] = -c1 * d; - out_grads[56][2] = s1 * d; - b = z2 * a - 0.240601504 * b; - a = b - 0.242236025 * a; - d = 1121.509962433 * a; - out_shs[76] = c0 * d; - out_shs[80] = s0 * d; - d = 2243.019924866 * a; - out_grads[76][0] = c1 * d; - out_grads[80][0] = s1 * d; - out_grads[76][1] = -s1 * d; - out_grads[80][1] = c1 * d; - d = -13917.572624524 * a; - out_grads[77][2] = -c1 * d; - out_grads[79][2] = s1 * d; - c1 = x * c0 - y * s0; - s1 = y * c0 + x * s0; - d = -1.77013077 * z; - out_shs[7] = -c1 * d; - out_shs[13] = s1 * d; - d = -5.310392309 * z; - out_grads[7][0] = -c0 * d; - out_grads[13][0] = s0 * d; - out_grads[7][1] = s0 * d; - out_grads[13][1] = c0 * d; - d = 6.62322287 * z; - out_grads[8][2] = c0 * d; - out_grads[12][2] = s0 * d; - a = (z2 - 0.111111111) * z; - b = a - 0.161616162 * z; - d = -10.133257855 * b; - out_shs[18] = -c1 * d; - out_shs[24] = s1 * d; - d = -30.399773564 * b; - out_grads[18][0] = -c0 * d; - out_grads[24][0] = s0 * d; - out_grads[18][1] = s0 * d; - out_grads[24][1] = c0 * d; - d = 60.799547128 * b; - out_grads[19][2] = c0 * d; - out_grads[23][2] = s0 * d; - a = z2 * b - 0.188811189 * a; - b = a - 0.205128205 * b; - d = -48.175380057 * b; - out_shs[33] = -c1 * d; - out_shs[39] = s1 * d; - d = -144.52614017 * b; - out_grads[33][0] = -c0 * d; - out_grads[39][0] = s0 * d; - out_grads[33][1] = s0 * d; - out_grads[39][1] = c0 * d; - d = 391.378637737 * b; - out_grads[34][2] = c0 * d; - out_grads[38][2] = s0 * d; - a = z2 * b - 0.215686275 * a; - b = a - 0.222910217 * b; - d = -213.661323441 * b; - out_shs[52] = -c1 * d; - out_shs[58] = s1 * d; - d = -640.983970322 * b; - out_grads[52][0] = -c0 * d; - out_grads[58][0] = s0 * d; - out_grads[52][1] = s0 * d; - out_grads[58][1] = c0 * d; - d = 2178.926515046 * b; - out_grads[53][2] = c0 * d; - out_grads[57][2] = s0 * d; - a = z2 * b - 0.228070175 * a; - b = a - 0.231884058 * b; - d = -915.709049803 * b; - out_shs[75] = -c1 * d; - out_shs[81] = s1 * d; - d = -2747.127149409 * b; - out_grads[75][0] = -c0 * d; - out_grads[81][0] = s0 * d; - out_grads[75][1] = s0 * d; - out_grads[81][1] = c0 * d; - d = 11215.099624332 * b; - out_grads[76][2] = c0 * d; - out_grads[80][2] = s0 * d; - c0 = x * c1 - y * s1; - s0 = y * c1 + x * s1; - d = 0.625835735; - out_shs[6] = c0 * d; - out_shs[14] = s0 * d; - d = 2.503342942; - out_grads[6][0] = c1 * d; - out_grads[14][0] = s1 * d; - out_grads[6][1] = -s1 * d; - out_grads[14][1] = c1 * d; - d = -1.77013077; - out_grads[7][2] = -c1 * d; - out_grads[13][2] = s1 * d; - a = z2 - 9.09090909e-02; - d = 5.550213908 * a; - out_shs[17] = c0 * d; - out_shs[25] = s0 * d; - d = 22.200855632 * a; - out_grads[17][0] = c1 * d; - out_grads[25][0] = s1 * d; - out_grads[17][1] = -s1 * d; - out_grads[25][1] = c1 * d; - d = -30.399773564 * a; - out_grads[18][2] = -c1 * d; - out_grads[24][2] = s1 * d; - b = z2 * (a - 0.13986014); - a = b - 0.169230769 * a; - d = 31.097074109 * a; - out_shs[32] = c0 * d; - out_shs[40] = s0 * d; - d = 124.388296437 * a; - out_grads[32][0] = c1 * d; - out_grads[40][0] = s1 * d; - out_grads[32][1] = -s1 * d; - out_grads[40][1] = c1 * d; - d = -240.876900283 * a; - out_grads[33][2] = -c1 * d; - out_grads[39][2] = s1 * d; - b = z2 * a - 0.188235294 * b; - a = b - 0.20123839 * a; - d = 151.081370682 * a; - out_shs[51] = c0 * d; - out_shs[59] = s0 * d; - d = 604.325482728 * a; - out_grads[51][0] = c1 * d; - out_grads[59][0] = s1 * d; - out_grads[51][1] = -s1 * d; - out_grads[59][1] = c1 * d; - d = -1495.629264084 * a; - out_grads[52][2] = -c1 * d; - out_grads[58][2] = s1 * d; - b = z2 * a - 0.210526316 * b; - a = b - 0.217391304 * a; - d = 686.781787352 * a; - out_shs[74] = c0 * d; - out_shs[82] = s0 * d; - d = 2747.127149409 * a; - out_grads[74][0] = c1 * d; - out_grads[82][0] = s1 * d; - out_grads[74][1] = -s1 * d; - out_grads[82][1] = c1 * d; - d = -8241.381448228 * a; - out_grads[75][2] = -c1 * d; - out_grads[81][2] = s1 * d; - c1 = x * c0 - y * s0; - s1 = y * c0 + x * s0; - d = -2.366619162 * z; - out_shs[16] = -c1 * d; - out_shs[26] = s1 * d; - d = -11.833095811 * z; - out_grads[16][0] = -c0 * d; - out_grads[26][0] = s0 * d; - out_grads[16][1] = s0 * d; - out_grads[26][1] = c0 * d; - d = 11.100427816 * z; - out_grads[17][2] = c0 * d; - out_grads[25][2] = s0 * d; - a = (z2 - 7.69230769e-02) * z; - b = a - 0.123076923 * z; - d = -17.24955311 * b; - out_shs[31] = -c1 * d; - out_shs[41] = s1 * d; - d = -86.247765552 * b; - out_grads[31][0] = -c0 * d; - out_grads[41][0] = s0 * d; - out_grads[31][1] = s0 * d; - out_grads[41][1] = c0 * d; - d = 124.388296437 * b; - out_grads[32][2] = c0 * d; - out_grads[40][2] = s0 * d; - a = z2 * b - 0.152941176 * a; - b = a - 0.173374613 * b; - d = -95.552248675 * b; - out_shs[50] = -c1 * d; - out_shs[60] = s1 * d; - d = -477.761243376 * b; - out_grads[50][0] = -c0 * d; - out_grads[60][0] = s0 * d; - out_grads[50][1] = s0 * d; - out_grads[60][1] = c0 * d; - d = 906.488224092 * b; - out_grads[51][2] = c0 * d; - out_grads[59][2] = s0 * d; - a = z2 * b - 0.187969925 * a; - b = a - 0.198757764 * b; - d = -471.12841933 * b; - out_shs[73] = -c1 * d; - out_shs[83] = s1 * d; - d = -2355.642096651 * b; - out_grads[73][0] = -c0 * d; - out_grads[83][0] = s0 * d; - out_grads[73][1] = s0 * d; - out_grads[83][1] = c0 * d; - d = 5494.254298819 * b; - out_grads[74][2] = c0 * d; - out_grads[82][2] = s0 * d; - c0 = x * c1 - y * s1; - s0 = y * c1 + x * s1; - d = 0.683184105; - out_shs[15] = c0 * d; - out_shs[27] = s0 * d; - d = 4.099104631; - out_grads[15][0] = c1 * d; - out_grads[27][0] = s1 * d; - out_grads[15][1] = -s1 * d; - out_grads[27][1] = c1 * d; - d = -2.366619162; - out_grads[16][2] = -c1 * d; - out_grads[26][2] = s1 * d; - a = z2 - 6.66666667e-02; - d = 7.984991491 * a; - out_shs[30] = c0 * d; - out_shs[42] = s0 * d; - d = 47.909948945 * a; - out_grads[30][0] = c1 * d; - out_grads[42][0] = s1 * d; - out_grads[30][1] = -s1 * d; - out_grads[42][1] = c1 * d; - d = -51.748659331 * a; - out_grads[31][2] = -c1 * d; - out_grads[41][2] = s1 * d; - b = z2 * (a - 0.109803922); - a = b - 0.139318885 * a; - d = 53.41533086 * a; - out_shs[49] = c0 * d; - out_shs[61] = s0 * d; - d = 320.491985161 * a; - out_grads[49][0] = c1 * d; - out_grads[61][0] = s1 * d; - out_grads[49][1] = -s1 * d; - out_grads[61][1] = c1 * d; - d = -477.761243376 * a; - out_grads[50][2] = -c1 * d; - out_grads[60][2] = s1 * d; - b = z2 * a - 0.160401003 * b; - a = b - 0.175983437 * a; - d = 293.800188384 * a; - out_shs[72] = c0 * d; - out_shs[84] = s0 * d; - d = 1762.801130306 * a; - out_grads[72][0] = c1 * d; - out_grads[84][0] = s1 * d; - out_grads[72][1] = -s1 * d; - out_grads[84][1] = c1 * d; - d = -3297.898935312 * a; - out_grads[73][2] = -c1 * d; - out_grads[83][2] = s1 * d; - c1 = x * c0 - y * s0; - s1 = y * c0 + x * s0; - d = -2.915706641 * z; - out_shs[29] = -c1 * d; - out_shs[43] = s1 * d; - d = -20.409946485 * z; - out_grads[29][0] = -c0 * d; - out_grads[43][0] = s0 * d; - out_grads[29][1] = s0 * d; - out_grads[43][1] = c0 * d; - d = 15.969982982 * z; - out_grads[30][2] = c0 * d; - out_grads[42][2] = s0 * d; - a = (z2 - 5.88235294e-02) * z; - b = a - 9.90712074e-02 * z; - d = -25.910241313 * b; - out_shs[48] = -c1 * d; - out_shs[62] = s1 * d; - d = -181.371689194 * b; - out_grads[48][0] = -c0 * d; - out_grads[62][0] = s0 * d; - out_grads[48][1] = s0 * d; - out_grads[62][1] = c0 * d; - d = 213.661323441 * b; - out_grads[49][2] = c0 * d; - out_grads[61][2] = s0 * d; - a = z2 * b - 0.127819549 * a; - b = a - 0.149068323 * b; - d = -165.101452729 * b; - out_shs[71] = -c1 * d; - out_shs[85] = s1 * d; - d = -1155.7101691 * b; - out_grads[71][0] = -c0 * d; - out_grads[85][0] = s0 * d; - out_grads[71][1] = s0 * d; - out_grads[85][1] = c0 * d; - d = 1762.801130306 * b; - out_grads[72][2] = c0 * d; - out_grads[84][2] = s0 * d; - c0 = x * c1 - y * s1; - s0 = y * c1 + x * s1; - d = 0.72892666; - out_shs[28] = c0 * d; - out_shs[44] = s0 * d; - d = 5.831413281; - out_grads[28][0] = c1 * d; - out_grads[44][0] = s1 * d; - out_grads[28][1] = -s1 * d; - out_grads[44][1] = c1 * d; - d = -2.915706641; - out_grads[29][2] = -c1 * d; - out_grads[43][2] = s1 * d; - a = z2 - 5.26315789e-02; - d = 10.577811722 * a; - out_shs[47] = c0 * d; - out_shs[63] = s0 * d; - d = 84.622493774 * a; - out_grads[47][0] = c1 * d; - out_grads[63][0] = s1 * d; - out_grads[47][1] = -s1 * d; - out_grads[63][1] = c1 * d; - d = -77.73072394 * a; - out_grads[48][2] = -c1 * d; - out_grads[62][2] = s1 * d; - b = z2 * (a - 9.02255639e-02); - a = b - 0.118012422 * a; - d = 82.550726364 * a; - out_shs[70] = c0 * d; - out_shs[86] = s0 * d; - d = 660.405810914 * a; - out_grads[70][0] = c1 * d; - out_grads[86][0] = s1 * d; - out_grads[70][1] = -s1 * d; - out_grads[86][1] = c1 * d; - d = -825.507263643 * a; - out_grads[71][2] = -c1 * d; - out_grads[85][2] = s1 * d; - c1 = x * c0 - y * s0; - s1 = y * c0 + x * s0; - d = -3.4318953 * z; - out_shs[46] = -c1 * d; - out_shs[64] = s1 * d; - d = -30.887057699 * z; - out_grads[46][0] = -c0 * d; - out_grads[64][0] = s0 * d; - out_grads[46][1] = s0 * d; - out_grads[64][1] = c0 * d; - d = 21.155623443 * z; - out_grads[47][2] = c0 * d; - out_grads[63][2] = s0 * d; - a = (z2 - 4.76190476e-02) * z; - b = a - 8.2815735e-02 * z; - d = -36.028090689 * b; - out_shs[69] = -c1 * d; - out_shs[87] = s1 * d; - d = -324.252816204 * b; - out_grads[69][0] = -c0 * d; - out_grads[87][0] = s0 * d; - out_grads[69][1] = s0 * d; - out_grads[87][1] = c0 * d; - d = 330.202905457 * b; - out_grads[70][2] = c0 * d; - out_grads[86][2] = s0 * d; - c0 = x * c1 - y * s1; - s0 = y * c1 + x * s1; - d = 0.767395118; - out_shs[45] = c0 * d; - out_shs[65] = s0 * d; - d = 7.673951182; - out_grads[45][0] = c1 * d; - out_grads[65][0] = s1 * d; - out_grads[45][1] = -s1 * d; - out_grads[65][1] = c1 * d; - d = -3.4318953; - out_grads[46][2] = -c1 * d; - out_grads[64][2] = s1 * d; - a = z2 - 4.34782609e-02; - d = 13.3042542 * a; - out_shs[68] = c0 * d; - out_shs[88] = s0 * d; - d = 133.042542003 * a; - out_grads[68][0] = c1 * d; - out_grads[88][0] = s1 * d; - out_grads[68][1] = -s1 * d; - out_grads[88][1] = c1 * d; - d = -108.084272068 * a; - out_grads[69][2] = -c1 * d; - out_grads[87][2] = s1 * d; - c1 = x * c0 - y * s0; - s1 = y * c0 + x * s0; - d = -3.923210529 * z; - out_shs[67] = -c1 * d; - out_shs[89] = s1 * d; - d = -43.155315818 * z; - out_grads[67][0] = -c0 * d; - out_grads[89][0] = s0 * d; - out_grads[67][1] = s0 * d; - out_grads[89][1] = c0 * d; - d = 26.608508401 * z; - out_grads[68][2] = c0 * d; - out_grads[88][2] = s0 * d; - c0 = x * c1 - y * s1; - s0 = y * c1 + x * s1; - d = 0.800821996; - out_shs[66] = c0 * d; - out_shs[90] = s0 * d; - d = 9.609863949; - out_grads[66][0] = c1 * d; - out_grads[90][0] = s1 * d; - out_grads[66][1] = -s1 * d; - out_grads[90][1] = c1 * d; - d = -3.923210529; - out_grads[67][2] = -c1 * d; - out_grads[89][2] = s1 * d; - out_grads[0][0] = 0.0; - out_grads[0][1] = 0.0; - out_grads[0][2] = 0.0; - out_grads[1][2] = 0.0; - out_grads[3][0] = 0.0; - out_grads[3][1] = 0.0; - out_grads[5][2] = 0.0; - out_grads[6][2] = 0.0; - out_grads[10][0] = 0.0; - out_grads[10][1] = 0.0; - out_grads[14][2] = 0.0; - out_grads[15][2] = 0.0; - out_grads[21][0] = 0.0; - out_grads[21][1] = 0.0; - out_grads[27][2] = 0.0; - out_grads[28][2] = 0.0; - out_grads[36][0] = 0.0; - out_grads[36][1] = 0.0; - out_grads[44][2] = 0.0; - out_grads[45][2] = 0.0; - out_grads[55][0] = 0.0; - out_grads[55][1] = 0.0; - out_grads[65][2] = 0.0; - out_grads[66][2] = 0.0; - out_grads[78][0] = 0.0; - out_grads[78][1] = 0.0; - out_grads[90][2] = 0.0; -} diff --git a/fury/shaders/rt_odfs/eval_sh_grad_8.frag b/fury/shaders/rt_odfs/eval_sh_grad_8.frag deleted file mode 100644 index b0a40d0a7..000000000 --- a/fury/shaders/rt_odfs/eval_sh_grad_8.frag +++ /dev/null @@ -1,295 +0,0 @@ -void eval_sh_grad_8(out float out_shs[45], out vec3 out_grads[45], vec3 point) -{ - float x, y, z, z2, c0, s0, c1, s1, d, a, b; - x = point[0]; - y = point[1]; - z = point[2]; - z2 = z * z; - c0 = 1.0; - s0 = 0.0; - d = 0.282094792; - out_shs[0] = d; - a = z2 - 0.333333333; - d = 0.946174696 * a; - out_shs[3] = d; - b = z2 * (a - 0.266666667); - a = b - 0.257142857 * a; - d = 3.702494142 * a; - out_shs[10] = d; - b = z2 * a - 0.253968254 * b; - a = b - 0.252525253 * a; - d = 14.684485724 * a; - out_shs[21] = d; - b = z2 * a - 0.251748252 * b; - a = b - 0.251282051 * a; - d = 58.473368113 * a; - out_shs[36] = d; - c1 = x; - s1 = y; - d = -1.092548431 * z; - out_shs[2] = -c1 * d; - out_shs[4] = s1 * d; - out_grads[2][0] = -c0 * d; - out_grads[4][0] = s0 * d; - out_grads[2][1] = s0 * d; - out_grads[4][1] = c0 * d; - d = 1.892349392 * z; - out_grads[3][2] = d; - a = (z2 - 0.2) * z; - b = a - 0.228571429 * z; - d = -4.683325805 * b; - out_shs[9] = -c1 * d; - out_shs[11] = s1 * d; - out_grads[9][0] = -c0 * d; - out_grads[11][0] = s0 * d; - out_grads[9][1] = s0 * d; - out_grads[11][1] = c0 * d; - d = 14.809976568 * b; - out_grads[10][2] = d; - a = z2 * b - 0.238095238 * a; - b = a - 0.242424242 * b; - d = -19.226504963 * b; - out_shs[20] = -c1 * d; - out_shs[22] = s1 * d; - out_grads[20][0] = -c0 * d; - out_grads[22][0] = s0 * d; - out_grads[20][1] = s0 * d; - out_grads[22][1] = c0 * d; - d = 88.106914343 * b; - out_grads[21][2] = d; - a = z2 * b - 0.244755245 * a; - b = a - 0.246153846 * b; - d = -77.964490818 * b; - out_shs[35] = -c1 * d; - out_shs[37] = s1 * d; - out_grads[35][0] = -c0 * d; - out_grads[37][0] = s0 * d; - out_grads[35][1] = s0 * d; - out_grads[37][1] = c0 * d; - d = 467.786944906 * b; - out_grads[36][2] = d; - c0 = x * c1 - y * s1; - s0 = y * c1 + x * s1; - d = 0.546274215; - out_shs[1] = c0 * d; - out_shs[5] = s0 * d; - d = 1.092548431; - out_grads[1][0] = c1 * d; - out_grads[5][0] = s1 * d; - out_grads[1][1] = -s1 * d; - out_grads[5][1] = c1 * d; - d = -1.092548431; - out_grads[2][2] = -c1 * d; - out_grads[4][2] = s1 * d; - a = z2 - 0.142857143; - d = 3.311611435 * a; - out_shs[8] = c0 * d; - out_shs[12] = s0 * d; - d = 6.62322287 * a; - out_grads[8][0] = c1 * d; - out_grads[12][0] = s1 * d; - out_grads[8][1] = -s1 * d; - out_grads[12][1] = c1 * d; - d = -14.049977415 * a; - out_grads[9][2] = -c1 * d; - out_grads[11][2] = s1 * d; - b = z2 * (a - 0.19047619); - a = b - 0.212121212 * a; - d = 15.199886782 * a; - out_shs[19] = c0 * d; - out_shs[23] = s0 * d; - d = 30.399773564 * a; - out_grads[19][0] = c1 * d; - out_grads[23][0] = s1 * d; - out_grads[19][1] = -s1 * d; - out_grads[23][1] = c1 * d; - d = -96.132524816 * a; - out_grads[20][2] = -c1 * d; - out_grads[22][2] = s1 * d; - b = z2 * a - 0.223776224 * b; - a = b - 0.230769231 * a; - d = 65.229772956 * a; - out_shs[34] = c0 * d; - out_shs[38] = s0 * d; - d = 130.459545912 * a; - out_grads[34][0] = c1 * d; - out_grads[38][0] = s1 * d; - out_grads[34][1] = -s1 * d; - out_grads[38][1] = c1 * d; - d = -545.751435723 * a; - out_grads[35][2] = -c1 * d; - out_grads[37][2] = s1 * d; - c1 = x * c0 - y * s0; - s1 = y * c0 + x * s0; - d = -1.77013077 * z; - out_shs[7] = -c1 * d; - out_shs[13] = s1 * d; - d = -5.310392309 * z; - out_grads[7][0] = -c0 * d; - out_grads[13][0] = s0 * d; - out_grads[7][1] = s0 * d; - out_grads[13][1] = c0 * d; - d = 6.62322287 * z; - out_grads[8][2] = c0 * d; - out_grads[12][2] = s0 * d; - a = (z2 - 0.111111111) * z; - b = a - 0.161616162 * z; - d = -10.133257855 * b; - out_shs[18] = -c1 * d; - out_shs[24] = s1 * d; - d = -30.399773564 * b; - out_grads[18][0] = -c0 * d; - out_grads[24][0] = s0 * d; - out_grads[18][1] = s0 * d; - out_grads[24][1] = c0 * d; - d = 60.799547128 * b; - out_grads[19][2] = c0 * d; - out_grads[23][2] = s0 * d; - a = z2 * b - 0.188811189 * a; - b = a - 0.205128205 * b; - d = -48.175380057 * b; - out_shs[33] = -c1 * d; - out_shs[39] = s1 * d; - d = -144.52614017 * b; - out_grads[33][0] = -c0 * d; - out_grads[39][0] = s0 * d; - out_grads[33][1] = s0 * d; - out_grads[39][1] = c0 * d; - d = 391.378637737 * b; - out_grads[34][2] = c0 * d; - out_grads[38][2] = s0 * d; - c0 = x * c1 - y * s1; - s0 = y * c1 + x * s1; - d = 0.625835735; - out_shs[6] = c0 * d; - out_shs[14] = s0 * d; - d = 2.503342942; - out_grads[6][0] = c1 * d; - out_grads[14][0] = s1 * d; - out_grads[6][1] = -s1 * d; - out_grads[14][1] = c1 * d; - d = -1.77013077; - out_grads[7][2] = -c1 * d; - out_grads[13][2] = s1 * d; - a = z2 - 9.09090909e-02; - d = 5.550213908 * a; - out_shs[17] = c0 * d; - out_shs[25] = s0 * d; - d = 22.200855632 * a; - out_grads[17][0] = c1 * d; - out_grads[25][0] = s1 * d; - out_grads[17][1] = -s1 * d; - out_grads[25][1] = c1 * d; - d = -30.399773564 * a; - out_grads[18][2] = -c1 * d; - out_grads[24][2] = s1 * d; - b = z2 * (a - 0.13986014); - a = b - 0.169230769 * a; - d = 31.097074109 * a; - out_shs[32] = c0 * d; - out_shs[40] = s0 * d; - d = 124.388296437 * a; - out_grads[32][0] = c1 * d; - out_grads[40][0] = s1 * d; - out_grads[32][1] = -s1 * d; - out_grads[40][1] = c1 * d; - d = -240.876900283 * a; - out_grads[33][2] = -c1 * d; - out_grads[39][2] = s1 * d; - c1 = x * c0 - y * s0; - s1 = y * c0 + x * s0; - d = -2.366619162 * z; - out_shs[16] = -c1 * d; - out_shs[26] = s1 * d; - d = -11.833095811 * z; - out_grads[16][0] = -c0 * d; - out_grads[26][0] = s0 * d; - out_grads[16][1] = s0 * d; - out_grads[26][1] = c0 * d; - d = 11.100427816 * z; - out_grads[17][2] = c0 * d; - out_grads[25][2] = s0 * d; - a = (z2 - 7.69230769e-02) * z; - b = a - 0.123076923 * z; - d = -17.24955311 * b; - out_shs[31] = -c1 * d; - out_shs[41] = s1 * d; - d = -86.247765552 * b; - out_grads[31][0] = -c0 * d; - out_grads[41][0] = s0 * d; - out_grads[31][1] = s0 * d; - out_grads[41][1] = c0 * d; - d = 124.388296437 * b; - out_grads[32][2] = c0 * d; - out_grads[40][2] = s0 * d; - c0 = x * c1 - y * s1; - s0 = y * c1 + x * s1; - d = 0.683184105; - out_shs[15] = c0 * d; - out_shs[27] = s0 * d; - d = 4.099104631; - out_grads[15][0] = c1 * d; - out_grads[27][0] = s1 * d; - out_grads[15][1] = -s1 * d; - out_grads[27][1] = c1 * d; - d = -2.366619162; - out_grads[16][2] = -c1 * d; - out_grads[26][2] = s1 * d; - a = z2 - 6.66666667e-02; - d = 7.984991491 * a; - out_shs[30] = c0 * d; - out_shs[42] = s0 * d; - d = 47.909948945 * a; - out_grads[30][0] = c1 * d; - out_grads[42][0] = s1 * d; - out_grads[30][1] = -s1 * d; - out_grads[42][1] = c1 * d; - d = -51.748659331 * a; - out_grads[31][2] = -c1 * d; - out_grads[41][2] = s1 * d; - c1 = x * c0 - y * s0; - s1 = y * c0 + x * s0; - d = -2.915706641 * z; - out_shs[29] = -c1 * d; - out_shs[43] = s1 * d; - d = -20.409946485 * z; - out_grads[29][0] = -c0 * d; - out_grads[43][0] = s0 * d; - out_grads[29][1] = s0 * d; - out_grads[43][1] = c0 * d; - d = 15.969982982 * z; - out_grads[30][2] = c0 * d; - out_grads[42][2] = s0 * d; - c0 = x * c1 - y * s1; - s0 = y * c1 + x * s1; - d = 0.72892666; - out_shs[28] = c0 * d; - out_shs[44] = s0 * d; - d = 5.831413281; - out_grads[28][0] = c1 * d; - out_grads[44][0] = s1 * d; - out_grads[28][1] = -s1 * d; - out_grads[44][1] = c1 * d; - d = -2.915706641; - out_grads[29][2] = -c1 * d; - out_grads[43][2] = s1 * d; - out_grads[0][0] = 0.0; - out_grads[0][1] = 0.0; - out_grads[0][2] = 0.0; - out_grads[1][2] = 0.0; - out_grads[3][0] = 0.0; - out_grads[3][1] = 0.0; - out_grads[5][2] = 0.0; - out_grads[6][2] = 0.0; - out_grads[10][0] = 0.0; - out_grads[10][1] = 0.0; - out_grads[14][2] = 0.0; - out_grads[15][2] = 0.0; - out_grads[21][0] = 0.0; - out_grads[21][1] = 0.0; - out_grads[27][2] = 0.0; - out_grads[28][2] = 0.0; - out_grads[36][0] = 0.0; - out_grads[36][1] = 0.0; - out_grads[44][2] = 0.0; -} diff --git a/fury/shaders/rt_odfs/find_roots.frag b/fury/shaders/rt_odfs/find_roots.frag deleted file mode 100644 index e5b80f7a4..000000000 --- a/fury/shaders/rt_odfs/find_roots.frag +++ /dev/null @@ -1,82 +0,0 @@ -void find_roots(out float out_roots[MAX_DEGREE + 1], float poly[MAX_DEGREE + 1], float begin, float end) { - float tolerance = (end - begin) * 1.0e-4; - // Construct the quadratic derivative of the polynomial. We divide each - // derivative by the factorial of its order, such that the constant - // coefficient can be copied directly from poly. That is a safeguard - // against overflow and makes it easier to avoid spilling below. The - // factors happen to be binomial coefficients then. - float derivative[MAX_DEGREE + 1]; - derivative[0] = poly[MAX_DEGREE - 2]; - derivative[1] = float(MAX_DEGREE - 1) * poly[MAX_DEGREE - 1]; - derivative[2] = (0.5 * float((MAX_DEGREE - 1) * MAX_DEGREE)) * poly[MAX_DEGREE - 0]; - _unroll_ - for (int i = 3; i != MAX_DEGREE + 1; ++i) - derivative[i] = 0.0; - // Compute its two roots using the quadratic formula - float discriminant = derivative[1] * derivative[1] - 4.0 * derivative[0] * derivative[2]; - if (discriminant >= 0.0) { - float sqrt_discriminant = sqrt(discriminant); - float scaled_root = derivative[1] + ((derivative[1] > 0.0) ? sqrt_discriminant : (-sqrt_discriminant)); - float root_0 = clamp(-2.0 * derivative[0] / scaled_root, begin, end); - float root_1 = clamp(-0.5 * scaled_root / derivative[2], begin, end); - out_roots[MAX_DEGREE - 2] = min(root_0, root_1); - out_roots[MAX_DEGREE - 1] = max(root_0, root_1); - } - else { - // Indicate that the cubic derivative has a single root - out_roots[MAX_DEGREE - 2] = begin; - out_roots[MAX_DEGREE - 1] = begin; - } - // The last entry in the root array is set to end to make it easier to - // iterate over relevant intervals, all untouched roots are set to begin - out_roots[MAX_DEGREE] = end; - _unroll_ - for (int i = 0; i != MAX_DEGREE - 2; ++i) - out_roots[i] = begin; - // Work your way up to derivatives of higher degree until you reach the - // polynomial itself. This implementation may seem peculiar: It always - // treats the derivative as though it had degree MAX_DEGREE and it - // constructs the derivatives in a contrived way. Changing that would - // reduce the number of arithmetic instructions roughly by a factor of two. - // However, it would also cause register spilling, which has a far more - // negative impact on the overall run time. Profiling indicates that the - // current implementation has no spilling whatsoever. - _loop_ - for (int degree = 3; degree != MAX_DEGREE + 1; ++degree) { - // Take the integral of the previous derivative (scaled such that the - // constant coefficient can still be copied directly from poly) - float prev_derivative_order = float(MAX_DEGREE + 1 - degree); - _unroll_ - for (int i = MAX_DEGREE; i != 0; --i) - derivative[i] = derivative[i - 1] * (prev_derivative_order * (1.0 / float(i))); - // Copy the constant coefficient without causing spilling. This part - // would be harder if the derivative were not scaled the way it is. - _unroll_ - for (int i = 0; i != MAX_DEGREE - 2; ++i) - derivative[0] = (degree == MAX_DEGREE - i) ? poly[i] : derivative[0]; - // Determine the value of this derivative at begin - float begin_value = derivative[MAX_DEGREE]; - _unroll_ - for (int i = MAX_DEGREE - 1; i != -1; --i) - begin_value = begin_value * begin + derivative[i]; - // Iterate over the intervals where roots may be found - _unroll_ - for (int i = 0; i != MAX_DEGREE; ++i) { - if (i < MAX_DEGREE - degree) - continue; - float current_begin = out_roots[i]; - float current_end = out_roots[i + 1]; - // Try to find a root - float root; - if (newton_bisection(root, begin_value, derivative, current_begin, current_end, begin_value, tolerance)) - out_roots[i] = root; - else if (degree < MAX_DEGREE) - // Create an empty interval for the next iteration - out_roots[i] = out_roots[i - 1]; - else - out_roots[i] = NO_INTERSECTION; - } - } - // We no longer need this array entry - out_roots[MAX_DEGREE] = NO_INTERSECTION; -} diff --git a/fury/shaders/rt_odfs/linear_rgb_to_srgb.frag b/fury/shaders/rt_odfs/linear_rgb_to_srgb.frag deleted file mode 100644 index d1c72c83b..000000000 --- a/fury/shaders/rt_odfs/linear_rgb_to_srgb.frag +++ /dev/null @@ -1,4 +0,0 @@ -vec3 linear_rgb_to_srgb(vec3 linear) -{ - return vec3(linear_to_srgb(linear.r), linear_to_srgb(linear.g), linear_to_srgb(linear.b)); -} diff --git a/fury/shaders/rt_odfs/linear_to_srgb.frag b/fury/shaders/rt_odfs/linear_to_srgb.frag deleted file mode 100644 index ac686853c..000000000 --- a/fury/shaders/rt_odfs/linear_to_srgb.frag +++ /dev/null @@ -1,4 +0,0 @@ -float linear_to_srgb(float linear) -{ - return (linear <= 0.0031308) ? (12.92 * linear) : (1.055 * pow(linear, 1.0 / 2.4) - 0.055); -} diff --git a/fury/shaders/rt_odfs/newton_bisection.frag b/fury/shaders/rt_odfs/newton_bisection.frag deleted file mode 100644 index 3f4b7f81f..000000000 --- a/fury/shaders/rt_odfs/newton_bisection.frag +++ /dev/null @@ -1,47 +0,0 @@ -bool newton_bisection(out float out_root, out float out_end_value, - float poly[MAX_DEGREE + 1], float begin, float end, - float begin_value, float error_tolerance) -{ - if (begin == end) { - out_end_value = begin_value; - return false; - } - // Evaluate the polynomial at the end of the interval - out_end_value = poly[MAX_DEGREE]; - _unroll_ - for (int i = MAX_DEGREE - 1; i != -1; --i) - out_end_value = out_end_value * end + poly[i]; - // If the values at both ends have the same non-zero sign, there is no root - if (begin_value * out_end_value > 0.0) - return false; - // Otherwise, we find the root iteratively using Newton bisection (with - // bounded iteration count) - float current = 0.5 * (begin + end); - _loop_ - for (int i = 0; i != 90; ++i) { - // Evaluate the polynomial and its derivative - float value = poly[MAX_DEGREE] * current + poly[MAX_DEGREE - 1]; - float derivative = poly[MAX_DEGREE]; - _unroll_ - for (int j = MAX_DEGREE - 2; j != -1; --j) { - derivative = derivative * current + value; - value = value * current + poly[j]; - } - // Shorten the interval - bool right = begin_value * value > 0.0; - begin = right ? current : begin; - end = right ? end : current; - // Apply Newton's method - float guess = current - value / derivative; - // Pick a guess - float middle = 0.5 * (begin + end); - float next = (guess >= begin && guess <= end) ? guess : middle; - // Move along or terminate - bool done = abs(next - current) < error_tolerance; - current = next; - if (done) - break; - } - out_root = current; - return true; -} diff --git a/fury/shaders/rt_odfs/srgb_to_linear.frag b/fury/shaders/rt_odfs/srgb_to_linear.frag deleted file mode 100644 index 78c765c20..000000000 --- a/fury/shaders/rt_odfs/srgb_to_linear.frag +++ /dev/null @@ -1,4 +0,0 @@ -float srgb_to_linear(float non_linear) -{ - return (non_linear <= 0.04045) ? ((1.0 / 12.92) * non_linear) : pow(non_linear * (1.0 / 1.055) + 0.055 / 1.055, 2.4); -} diff --git a/fury/shaders/rt_odfs/srgb_to_linear_rgb.frag b/fury/shaders/rt_odfs/srgb_to_linear_rgb.frag deleted file mode 100644 index e4c2ef22a..000000000 --- a/fury/shaders/rt_odfs/srgb_to_linear_rgb.frag +++ /dev/null @@ -1,4 +0,0 @@ -vec3 srgb_to_linear_rgb(vec3 srgb) -{ - return vec3(srgb_to_linear(srgb.r), srgb_to_linear(srgb.g), srgb_to_linear(srgb.b)); -} diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_10 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_10 copy.frag new file mode 100644 index 000000000..c9e6b0d8d --- /dev/null +++ b/fury/shaders/rt_odfs/tournier/eval_sh_grad_10 copy.frag @@ -0,0 +1,430 @@ +void eval_sh_grad_10(out float out_shs[66], out vec3 out_grads[66], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + b = z2 * a - 0.250980392 * b; + a = b - 0.250773994 * a; + d = 233.240148813 * a; + out_shs[55] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + out_grads[4][0] = c0 * d; + out_grads[2][0] = s0 * d; + out_grads[4][1] = s0 * d; + out_grads[2][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + out_grads[11][0] = c0 * d; + out_grads[9][0] = s0 * d; + out_grads[11][1] = s0 * d; + out_grads[9][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[22] = c1 * d; + out_shs[20] = s1 * d; + out_grads[22][0] = c0 * d; + out_grads[20][0] = s0 * d; + out_grads[22][1] = s0 * d; + out_grads[20][1] = c0 * d; + d = 88.106914343 * b; + out_grads[21][2] = d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[37] = c1 * d; + out_shs[35] = s1 * d; + out_grads[37][0] = c0 * d; + out_grads[35][0] = s0 * d; + out_grads[37][1] = s0 * d; + out_grads[35][1] = c0 * d; + d = 467.786944906 * b; + out_grads[36][2] = d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + out_shs[56] = c1 * d; + out_shs[54] = s1 * d; + out_grads[56][0] = c0 * d; + out_grads[54][0] = s0 * d; + out_grads[56][1] = s0 * d; + out_grads[54][1] = c0 * d; + d = 2332.401488133 * b; + out_grads[55][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + d = 1.092548431; + out_grads[5][0] = c1 * d; + out_grads[1][0] = s1 * d; + out_grads[5][1] = -s1 * d; + out_grads[1][1] = c1 * d; + d = -1.092548431; + out_grads[4][2] = c1 * d; + out_grads[2][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + d = 6.62322287 * a; + out_grads[12][0] = c1 * d; + out_grads[8][0] = s1 * d; + out_grads[12][1] = -s1 * d; + out_grads[8][1] = c1 * d; + d = -14.049977415 * a; + out_grads[11][2] = c1 * d; + out_grads[9][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[23] = c0 * d; + out_shs[19] = s0 * d; + d = 30.399773564 * a; + out_grads[23][0] = c1 * d; + out_grads[19][0] = s1 * d; + out_grads[23][1] = -s1 * d; + out_grads[19][1] = c1 * d; + d = -96.132524816 * a; + out_grads[22][2] = c1 * d; + out_grads[20][2] = s1 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[38] = c0 * d; + out_shs[34] = s0 * d; + d = 130.459545912 * a; + out_grads[38][0] = c1 * d; + out_grads[34][0] = s1 * d; + out_grads[38][1] = -s1 * d; + out_grads[34][1] = c1 * d; + d = -545.751435723 * a; + out_grads[37][2] = c1 * d; + out_grads[35][2] = s1 * d; + b = z2 * a - 0.235294118 * b; + a = b - 0.238390093 * a; + d = 272.365814381 * a; + out_shs[57] = c0 * d; + out_shs[53] = s0 * d; + d = 544.731628762 * a; + out_grads[57][0] = c1 * d; + out_grads[53][0] = s1 * d; + out_grads[57][1] = -s1 * d; + out_grads[53][1] = c1 * d; + d = -2830.508572514 * a; + out_grads[56][2] = c1 * d; + out_grads[54][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; + d = -5.310392309 * z; + out_grads[13][0] = c0 * d; + out_grads[7][0] = s0 * d; + out_grads[13][1] = s0 * d; + out_grads[7][1] = c0 * d; + d = 6.62322287 * z; + out_grads[12][2] = c0 * d; + out_grads[8][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[24] = c1 * d; + out_shs[18] = s1 * d; + d = -30.399773564 * b; + out_grads[24][0] = c0 * d; + out_grads[18][0] = s0 * d; + out_grads[24][1] = s0 * d; + out_grads[18][1] = c0 * d; + d = 60.799547128 * b; + out_grads[23][2] = c0 * d; + out_grads[19][2] = s0 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[39] = c1 * d; + out_shs[33] = s1 * d; + d = -144.52614017 * b; + out_grads[39][0] = c0 * d; + out_grads[33][0] = s0 * d; + out_grads[39][1] = s0 * d; + out_grads[33][1] = c0 * d; + d = 391.378637737 * b; + out_grads[38][2] = c0 * d; + out_grads[34][2] = s0 * d; + a = z2 * b - 0.215686275 * a; + b = a - 0.222910217 * b; + d = -213.661323441 * b; + out_shs[58] = c1 * d; + out_shs[52] = s1 * d; + d = -640.983970322 * b; + out_grads[58][0] = c0 * d; + out_grads[52][0] = s0 * d; + out_grads[58][1] = s0 * d; + out_grads[52][1] = c0 * d; + d = 2178.926515046 * b; + out_grads[57][2] = c0 * d; + out_grads[53][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; + d = 2.503342942; + out_grads[14][0] = c1 * d; + out_grads[6][0] = s1 * d; + out_grads[14][1] = -s1 * d; + out_grads[6][1] = c1 * d; + d = -1.77013077; + out_grads[13][2] = c1 * d; + out_grads[7][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[25] = c0 * d; + out_shs[17] = s0 * d; + d = 22.200855632 * a; + out_grads[25][0] = c1 * d; + out_grads[17][0] = s1 * d; + out_grads[25][1] = -s1 * d; + out_grads[17][1] = c1 * d; + d = -30.399773564 * a; + out_grads[24][2] = c1 * d; + out_grads[18][2] = s1 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[40] = c0 * d; + out_shs[32] = s0 * d; + d = 124.388296437 * a; + out_grads[40][0] = c1 * d; + out_grads[32][0] = s1 * d; + out_grads[40][1] = -s1 * d; + out_grads[32][1] = c1 * d; + d = -240.876900283 * a; + out_grads[39][2] = c1 * d; + out_grads[33][2] = s1 * d; + b = z2 * a - 0.188235294 * b; + a = b - 0.20123839 * a; + d = 151.081370682 * a; + out_shs[59] = c0 * d; + out_shs[51] = s0 * d; + d = 604.325482728 * a; + out_grads[59][0] = c1 * d; + out_grads[51][0] = s1 * d; + out_grads[59][1] = -s1 * d; + out_grads[51][1] = c1 * d; + d = -1495.629264084 * a; + out_grads[58][2] = c1 * d; + out_grads[52][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[26] = c1 * d; + out_shs[16] = s1 * d; + d = -11.833095811 * z; + out_grads[26][0] = c0 * d; + out_grads[16][0] = s0 * d; + out_grads[26][1] = s0 * d; + out_grads[16][1] = c0 * d; + d = 11.100427816 * z; + out_grads[25][2] = c0 * d; + out_grads[17][2] = s0 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[41] = c1 * d; + out_shs[31] = s1 * d; + d = -86.247765552 * b; + out_grads[41][0] = c0 * d; + out_grads[31][0] = s0 * d; + out_grads[41][1] = s0 * d; + out_grads[31][1] = c0 * d; + d = 124.388296437 * b; + out_grads[40][2] = c0 * d; + out_grads[32][2] = s0 * d; + a = z2 * b - 0.152941176 * a; + b = a - 0.173374613 * b; + d = -95.552248675 * b; + out_shs[60] = c1 * d; + out_shs[50] = s1 * d; + d = -477.761243376 * b; + out_grads[60][0] = c0 * d; + out_grads[50][0] = s0 * d; + out_grads[60][1] = s0 * d; + out_grads[50][1] = c0 * d; + d = 906.488224092 * b; + out_grads[59][2] = c0 * d; + out_grads[51][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[27] = c0 * d; + out_shs[15] = s0 * d; + d = 4.099104631; + out_grads[27][0] = c1 * d; + out_grads[15][0] = s1 * d; + out_grads[27][1] = -s1 * d; + out_grads[15][1] = c1 * d; + d = -2.366619162; + out_grads[26][2] = c1 * d; + out_grads[16][2] = s1 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[42] = c0 * d; + out_shs[30] = s0 * d; + d = 47.909948945 * a; + out_grads[42][0] = c1 * d; + out_grads[30][0] = s1 * d; + out_grads[42][1] = -s1 * d; + out_grads[30][1] = c1 * d; + d = -51.748659331 * a; + out_grads[41][2] = c1 * d; + out_grads[31][2] = s1 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + out_shs[61] = c0 * d; + out_shs[49] = s0 * d; + d = 320.491985161 * a; + out_grads[61][0] = c1 * d; + out_grads[49][0] = s1 * d; + out_grads[61][1] = -s1 * d; + out_grads[49][1] = c1 * d; + d = -477.761243376 * a; + out_grads[60][2] = c1 * d; + out_grads[50][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[43] = c1 * d; + out_shs[29] = s1 * d; + d = -20.409946485 * z; + out_grads[43][0] = c0 * d; + out_grads[29][0] = s0 * d; + out_grads[43][1] = s0 * d; + out_grads[29][1] = c0 * d; + d = 15.969982982 * z; + out_grads[42][2] = c0 * d; + out_grads[30][2] = s0 * d; + a = (z2 - 5.88235294e-02) * z; + b = a - 9.90712074e-02 * z; + d = -25.910241313 * b; + out_shs[62] = c1 * d; + out_shs[48] = s1 * d; + d = -181.371689194 * b; + out_grads[62][0] = c0 * d; + out_grads[48][0] = s0 * d; + out_grads[62][1] = s0 * d; + out_grads[48][1] = c0 * d; + d = 213.661323441 * b; + out_grads[61][2] = c0 * d; + out_grads[49][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[44] = c0 * d; + out_shs[28] = s0 * d; + d = 5.831413281; + out_grads[44][0] = c1 * d; + out_grads[28][0] = s1 * d; + out_grads[44][1] = -s1 * d; + out_grads[28][1] = c1 * d; + d = -2.915706641; + out_grads[43][2] = c1 * d; + out_grads[29][2] = s1 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + out_shs[63] = c0 * d; + out_shs[47] = s0 * d; + d = 84.622493774 * a; + out_grads[63][0] = c1 * d; + out_grads[47][0] = s1 * d; + out_grads[63][1] = -s1 * d; + out_grads[47][1] = c1 * d; + d = -77.73072394 * a; + out_grads[62][2] = c1 * d; + out_grads[48][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + out_shs[64] = c1 * d; + out_shs[46] = s1 * d; + d = -30.887057699 * z; + out_grads[64][0] = c0 * d; + out_grads[46][0] = s0 * d; + out_grads[64][1] = s0 * d; + out_grads[46][1] = c0 * d; + d = 21.155623443 * z; + out_grads[63][2] = c0 * d; + out_grads[47][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + out_shs[65] = c0 * d; + out_shs[45] = s0 * d; + d = 7.673951182; + out_grads[65][0] = c1 * d; + out_grads[45][0] = s1 * d; + out_grads[65][1] = -s1 * d; + out_grads[45][1] = c1 * d; + d = -3.4318953; + out_grads[64][2] = c1 * d; + out_grads[46][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; + out_grads[6][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[14][2] = 0.0; + out_grads[15][2] = 0.0; + out_grads[21][0] = 0.0; + out_grads[21][1] = 0.0; + out_grads[27][2] = 0.0; + out_grads[28][2] = 0.0; + out_grads[36][0] = 0.0; + out_grads[36][1] = 0.0; + out_grads[44][2] = 0.0; + out_grads[45][2] = 0.0; + out_grads[55][0] = 0.0; + out_grads[55][1] = 0.0; + out_grads[65][2] = 0.0; +} diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_12 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_12 copy.frag new file mode 100644 index 000000000..35c2a3617 --- /dev/null +++ b/fury/shaders/rt_odfs/tournier/eval_sh_grad_12 copy.frag @@ -0,0 +1,591 @@ +void eval_sh_grad_12(out float out_shs[91], out vec3 out_grads[91], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + b = z2 * a - 0.250980392 * b; + a = b - 0.250773994 * a; + d = 233.240148813 * a; + out_shs[55] = d; + b = z2 * a - 0.250626566 * b; + a = b - 0.250517598 * a; + d = 931.186918633 * a; + out_shs[78] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + out_grads[4][0] = c0 * d; + out_grads[2][0] = s0 * d; + out_grads[4][1] = s0 * d; + out_grads[2][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + out_grads[11][0] = c0 * d; + out_grads[9][0] = s0 * d; + out_grads[11][1] = s0 * d; + out_grads[9][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[22] = c1 * d; + out_shs[20] = s1 * d; + out_grads[22][0] = c0 * d; + out_grads[20][0] = s0 * d; + out_grads[22][1] = s0 * d; + out_grads[20][1] = c0 * d; + d = 88.106914343 * b; + out_grads[21][2] = d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[37] = c1 * d; + out_shs[35] = s1 * d; + out_grads[37][0] = c0 * d; + out_grads[35][0] = s0 * d; + out_grads[37][1] = s0 * d; + out_grads[35][1] = c0 * d; + d = 467.786944906 * b; + out_grads[36][2] = d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + out_shs[56] = c1 * d; + out_shs[54] = s1 * d; + out_grads[56][0] = c0 * d; + out_grads[54][0] = s0 * d; + out_grads[56][1] = s0 * d; + out_grads[54][1] = c0 * d; + d = 2332.401488133 * b; + out_grads[55][2] = d; + a = z2 * b - 0.248120301 * a; + b = a - 0.248447205 * b; + d = -1265.233874957 * b; + out_shs[79] = c1 * d; + out_shs[77] = s1 * d; + out_grads[79][0] = c0 * d; + out_grads[77][0] = s0 * d; + out_grads[79][1] = s0 * d; + out_grads[77][1] = c0 * d; + d = 11174.243023595 * b; + out_grads[78][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + d = 1.092548431; + out_grads[5][0] = c1 * d; + out_grads[1][0] = s1 * d; + out_grads[5][1] = -s1 * d; + out_grads[1][1] = c1 * d; + d = -1.092548431; + out_grads[4][2] = c1 * d; + out_grads[2][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + d = 6.62322287 * a; + out_grads[12][0] = c1 * d; + out_grads[8][0] = s1 * d; + out_grads[12][1] = -s1 * d; + out_grads[8][1] = c1 * d; + d = -14.049977415 * a; + out_grads[11][2] = c1 * d; + out_grads[9][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[23] = c0 * d; + out_shs[19] = s0 * d; + d = 30.399773564 * a; + out_grads[23][0] = c1 * d; + out_grads[19][0] = s1 * d; + out_grads[23][1] = -s1 * d; + out_grads[19][1] = c1 * d; + d = -96.132524816 * a; + out_grads[22][2] = c1 * d; + out_grads[20][2] = s1 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[38] = c0 * d; + out_shs[34] = s0 * d; + d = 130.459545912 * a; + out_grads[38][0] = c1 * d; + out_grads[34][0] = s1 * d; + out_grads[38][1] = -s1 * d; + out_grads[34][1] = c1 * d; + d = -545.751435723 * a; + out_grads[37][2] = c1 * d; + out_grads[35][2] = s1 * d; + b = z2 * a - 0.235294118 * b; + a = b - 0.238390093 * a; + d = 272.365814381 * a; + out_shs[57] = c0 * d; + out_shs[53] = s0 * d; + d = 544.731628762 * a; + out_grads[57][0] = c1 * d; + out_grads[53][0] = s1 * d; + out_grads[57][1] = -s1 * d; + out_grads[53][1] = c1 * d; + d = -2830.508572514 * a; + out_grads[56][2] = c1 * d; + out_grads[54][2] = s1 * d; + b = z2 * a - 0.240601504 * b; + a = b - 0.242236025 * a; + d = 1121.509962433 * a; + out_shs[80] = c0 * d; + out_shs[76] = s0 * d; + d = 2243.019924866 * a; + out_grads[80][0] = c1 * d; + out_grads[76][0] = s1 * d; + out_grads[80][1] = -s1 * d; + out_grads[76][1] = c1 * d; + d = -13917.572624524 * a; + out_grads[79][2] = c1 * d; + out_grads[77][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; + d = -5.310392309 * z; + out_grads[13][0] = c0 * d; + out_grads[7][0] = s0 * d; + out_grads[13][1] = s0 * d; + out_grads[7][1] = c0 * d; + d = 6.62322287 * z; + out_grads[12][2] = c0 * d; + out_grads[8][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[24] = c1 * d; + out_shs[18] = s1 * d; + d = -30.399773564 * b; + out_grads[24][0] = c0 * d; + out_grads[18][0] = s0 * d; + out_grads[24][1] = s0 * d; + out_grads[18][1] = c0 * d; + d = 60.799547128 * b; + out_grads[23][2] = c0 * d; + out_grads[19][2] = s0 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[39] = c1 * d; + out_shs[33] = s1 * d; + d = -144.52614017 * b; + out_grads[39][0] = c0 * d; + out_grads[33][0] = s0 * d; + out_grads[39][1] = s0 * d; + out_grads[33][1] = c0 * d; + d = 391.378637737 * b; + out_grads[38][2] = c0 * d; + out_grads[34][2] = s0 * d; + a = z2 * b - 0.215686275 * a; + b = a - 0.222910217 * b; + d = -213.661323441 * b; + out_shs[58] = c1 * d; + out_shs[52] = s1 * d; + d = -640.983970322 * b; + out_grads[58][0] = c0 * d; + out_grads[52][0] = s0 * d; + out_grads[58][1] = s0 * d; + out_grads[52][1] = c0 * d; + d = 2178.926515046 * b; + out_grads[57][2] = c0 * d; + out_grads[53][2] = s0 * d; + a = z2 * b - 0.228070175 * a; + b = a - 0.231884058 * b; + d = -915.709049803 * b; + out_shs[81] = c1 * d; + out_shs[75] = s1 * d; + d = -2747.127149409 * b; + out_grads[81][0] = c0 * d; + out_grads[75][0] = s0 * d; + out_grads[81][1] = s0 * d; + out_grads[75][1] = c0 * d; + d = 11215.099624332 * b; + out_grads[80][2] = c0 * d; + out_grads[76][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; + d = 2.503342942; + out_grads[14][0] = c1 * d; + out_grads[6][0] = s1 * d; + out_grads[14][1] = -s1 * d; + out_grads[6][1] = c1 * d; + d = -1.77013077; + out_grads[13][2] = c1 * d; + out_grads[7][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[25] = c0 * d; + out_shs[17] = s0 * d; + d = 22.200855632 * a; + out_grads[25][0] = c1 * d; + out_grads[17][0] = s1 * d; + out_grads[25][1] = -s1 * d; + out_grads[17][1] = c1 * d; + d = -30.399773564 * a; + out_grads[24][2] = c1 * d; + out_grads[18][2] = s1 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[40] = c0 * d; + out_shs[32] = s0 * d; + d = 124.388296437 * a; + out_grads[40][0] = c1 * d; + out_grads[32][0] = s1 * d; + out_grads[40][1] = -s1 * d; + out_grads[32][1] = c1 * d; + d = -240.876900283 * a; + out_grads[39][2] = c1 * d; + out_grads[33][2] = s1 * d; + b = z2 * a - 0.188235294 * b; + a = b - 0.20123839 * a; + d = 151.081370682 * a; + out_shs[59] = c0 * d; + out_shs[51] = s0 * d; + d = 604.325482728 * a; + out_grads[59][0] = c1 * d; + out_grads[51][0] = s1 * d; + out_grads[59][1] = -s1 * d; + out_grads[51][1] = c1 * d; + d = -1495.629264084 * a; + out_grads[58][2] = c1 * d; + out_grads[52][2] = s1 * d; + b = z2 * a - 0.210526316 * b; + a = b - 0.217391304 * a; + d = 686.781787352 * a; + out_shs[82] = c0 * d; + out_shs[74] = s0 * d; + d = 2747.127149409 * a; + out_grads[82][0] = c1 * d; + out_grads[74][0] = s1 * d; + out_grads[82][1] = -s1 * d; + out_grads[74][1] = c1 * d; + d = -8241.381448228 * a; + out_grads[81][2] = -c1 * d; + out_grads[75][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[26] = c1 * d; + out_shs[16] = s1 * d; + d = -11.833095811 * z; + out_grads[26][0] = c0 * d; + out_grads[16][0] = s0 * d; + out_grads[26][1] = s0 * d; + out_grads[16][1] = c0 * d; + d = 11.100427816 * z; + out_grads[25][2] = c0 * d; + out_grads[17][2] = s0 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[41] = c1 * d; + out_shs[31] = s1 * d; + d = -86.247765552 * b; + out_grads[41][0] = c0 * d; + out_grads[31][0] = s0 * d; + out_grads[41][1] = s0 * d; + out_grads[31][1] = c0 * d; + d = 124.388296437 * b; + out_grads[40][2] = c0 * d; + out_grads[32][2] = s0 * d; + a = z2 * b - 0.152941176 * a; + b = a - 0.173374613 * b; + d = -95.552248675 * b; + out_shs[60] = c1 * d; + out_shs[50] = s1 * d; + d = -477.761243376 * b; + out_grads[60][0] = c0 * d; + out_grads[50][0] = s0 * d; + out_grads[60][1] = s0 * d; + out_grads[50][1] = c0 * d; + d = 906.488224092 * b; + out_grads[59][2] = c0 * d; + out_grads[51][2] = s0 * d; + a = z2 * b - 0.187969925 * a; + b = a - 0.198757764 * b; + d = -471.12841933 * b; + out_shs[83] = c1 * d; + out_shs[73] = s1 * d; + d = -2355.642096651 * b; + out_grads[83][0] = c0 * d; + out_grads[73][0] = s0 * d; + out_grads[83][1] = s0 * d; + out_grads[73][1] = c0 * d; + d = 5494.254298819 * b; + out_grads[82][2] = c0 * d; + out_grads[74][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[27] = c0 * d; + out_shs[15] = s0 * d; + d = 4.099104631; + out_grads[27][0] = c1 * d; + out_grads[15][0] = s1 * d; + out_grads[27][1] = -s1 * d; + out_grads[15][1] = c1 * d; + d = -2.366619162; + out_grads[26][2] = c1 * d; + out_grads[16][2] = s1 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[42] = c0 * d; + out_shs[30] = s0 * d; + d = 47.909948945 * a; + out_grads[42][0] = c1 * d; + out_grads[30][0] = s1 * d; + out_grads[42][1] = -s1 * d; + out_grads[30][1] = c1 * d; + d = -51.748659331 * a; + out_grads[41][2] = c1 * d; + out_grads[31][2] = s1 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + out_shs[61] = c0 * d; + out_shs[49] = s0 * d; + d = 320.491985161 * a; + out_grads[61][0] = c1 * d; + out_grads[49][0] = s1 * d; + out_grads[61][1] = -s1 * d; + out_grads[49][1] = c1 * d; + d = -477.761243376 * a; + out_grads[60][2] = c1 * d; + out_grads[50][2] = s1 * d; + b = z2 * a - 0.160401003 * b; + a = b - 0.175983437 * a; + d = 293.800188384 * a; + out_shs[84] = c0 * d; + out_shs[72] = s0 * d; + d = 1762.801130306 * a; + out_grads[84][0] = c1 * d; + out_grads[72][0] = s1 * d; + out_grads[84][1] = -s1 * d; + out_grads[72][1] = c1 * d; + d = -3297.898935312 * a; + out_grads[83][2] = c1 * d; + out_grads[73][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[43] = c1 * d; + out_shs[29] = s1 * d; + d = -20.409946485 * z; + out_grads[43][0] = c0 * d; + out_grads[29][0] = s0 * d; + out_grads[43][1] = s0 * d; + out_grads[29][1] = c0 * d; + d = 15.969982982 * z; + out_grads[42][2] = c0 * d; + out_grads[30][2] = s0 * d; + a = (z2 - 5.88235294e-02) * z; + b = a - 9.90712074e-02 * z; + d = -25.910241313 * b; + out_shs[62] = c1 * d; + out_shs[48] = s1 * d; + d = -181.371689194 * b; + out_grads[62][0] = c0 * d; + out_grads[48][0] = s0 * d; + out_grads[62][1] = s0 * d; + out_grads[48][1] = c0 * d; + d = 213.661323441 * b; + out_grads[61][2] = c0 * d; + out_grads[49][2] = s0 * d; + a = z2 * b - 0.127819549 * a; + b = a - 0.149068323 * b; + d = -165.101452729 * b; + out_shs[85] = c1 * d; + out_shs[71] = s1 * d; + d = -1155.7101691 * b; + out_grads[85][0] = c0 * d; + out_grads[71][0] = s0 * d; + out_grads[85][1] = s0 * d; + out_grads[71][1] = c0 * d; + d = 1762.801130306 * b; + out_grads[84][2] = c0 * d; + out_grads[72][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[44] = c0 * d; + out_shs[28] = s0 * d; + d = 5.831413281; + out_grads[44][0] = c1 * d; + out_grads[28][0] = s1 * d; + out_grads[44][1] = -s1 * d; + out_grads[28][1] = c1 * d; + d = -2.915706641; + out_grads[43][2] = c1 * d; + out_grads[29][2] = s1 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + out_shs[63] = c0 * d; + out_shs[47] = s0 * d; + d = 84.622493774 * a; + out_grads[63][0] = c1 * d; + out_grads[47][0] = s1 * d; + out_grads[63][1] = -s1 * d; + out_grads[47][1] = c1 * d; + d = -77.73072394 * a; + out_grads[62][2] = c1 * d; + out_grads[48][2] = s1 * d; + b = z2 * (a - 9.02255639e-02); + a = b - 0.118012422 * a; + d = 82.550726364 * a; + out_shs[86] = c0 * d; + out_shs[70] = s0 * d; + d = 660.405810914 * a; + out_grads[86][0] = c1 * d; + out_grads[70][0] = s1 * d; + out_grads[86][1] = -s1 * d; + out_grads[70][1] = c1 * d; + d = -825.507263643 * a; + out_grads[85][2] = c1 * d; + out_grads[71][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + out_shs[64] = c1 * d; + out_shs[46] = s1 * d; + d = -30.887057699 * z; + out_grads[64][0] = c0 * d; + out_grads[46][0] = s0 * d; + out_grads[64][1] = s0 * d; + out_grads[46][1] = c0 * d; + d = 21.155623443 * z; + out_grads[63][2] = c0 * d; + out_grads[47][2] = s0 * d; + a = (z2 - 4.76190476e-02) * z; + b = a - 8.2815735e-02 * z; + d = -36.028090689 * b; + out_shs[87] = c1 * d; + out_shs[69] = s1 * d; + d = -324.252816204 * b; + out_grads[87][0] = c0 * d; + out_grads[69][0] = s0 * d; + out_grads[87][1] = s0 * d; + out_grads[69][1] = c0 * d; + d = 330.202905457 * b; + out_grads[86][2] = c0 * d; + out_grads[70][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + out_shs[65] = c0 * d; + out_shs[45] = s0 * d; + d = 7.673951182; + out_grads[65][0] = c1 * d; + out_grads[45][0] = s1 * d; + out_grads[65][1] = -s1 * d; + out_grads[45][1] = c1 * d; + d = -3.4318953; + out_grads[64][2] = c1 * d; + out_grads[46][2] = s1 * d; + a = z2 - 4.34782609e-02; + d = 13.3042542 * a; + out_shs[88] = c0 * d; + out_shs[68] = s0 * d; + d = 133.042542003 * a; + out_grads[88][0] = c1 * d; + out_grads[68][0] = s1 * d; + out_grads[88][1] = -s1 * d; + out_grads[68][1] = c1 * d; + d = -108.084272068 * a; + out_grads[87][2] = c1 * d; + out_grads[69][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.923210529 * z; + out_shs[89] = c1 * d; + out_shs[67] = s1 * d; + d = -43.155315818 * z; + out_grads[89][0] = c0 * d; + out_grads[67][0] = s0 * d; + out_grads[89][1] = s0 * d; + out_grads[67][1] = c0 * d; + d = 26.608508401 * z; + out_grads[88][2] = c0 * d; + out_grads[68][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.800821996; + out_shs[90] = c0 * d; + out_shs[66] = s0 * d; + d = 9.609863949; + out_grads[90][0] = c1 * d; + out_grads[66][0] = s1 * d; + out_grads[90][1] = -s1 * d; + out_grads[66][1] = c1 * d; + d = -3.923210529; + out_grads[89][2] = c1 * d; + out_grads[67][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; + out_grads[6][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[14][2] = 0.0; + out_grads[15][2] = 0.0; + out_grads[21][0] = 0.0; + out_grads[21][1] = 0.0; + out_grads[27][2] = 0.0; + out_grads[28][2] = 0.0; + out_grads[36][0] = 0.0; + out_grads[36][1] = 0.0; + out_grads[44][2] = 0.0; + out_grads[45][2] = 0.0; + out_grads[55][0] = 0.0; + out_grads[55][1] = 0.0; + out_grads[65][2] = 0.0; + out_grads[66][2] = 0.0; + out_grads[78][0] = 0.0; + out_grads[78][1] = 0.0; + out_grads[90][2] = 0.0; +} diff --git a/fury/shaders/rt_odfs/eval_sh_grad_2.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_2 copy.frag similarity index 69% rename from fury/shaders/rt_odfs/eval_sh_grad_2.frag rename to fury/shaders/rt_odfs/tournier/eval_sh_grad_2 copy.frag index 7004bd528..277a0e07a 100644 --- a/fury/shaders/rt_odfs/eval_sh_grad_2.frag +++ b/fury/shaders/rt_odfs/tournier/eval_sh_grad_2 copy.frag @@ -15,32 +15,32 @@ void eval_sh_grad_2(out float out_shs[6], out vec3 out_grads[6], vec3 point) c1 = x; s1 = y; d = -1.092548431 * z; - out_shs[2] = -c1 * d; - out_shs[4] = s1 * d; - out_grads[2][0] = -c0 * d; - out_grads[4][0] = s0 * d; - out_grads[2][1] = s0 * d; - out_grads[4][1] = c0 * d; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + out_grads[4][0] = c0 * d; + out_grads[2][0] = s0 * d; + out_grads[4][1] = s0 * d; + out_grads[2][1] = c0 * d; d = 1.892349392 * z; out_grads[3][2] = d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.546274215; - out_shs[1] = c0 * d; - out_shs[5] = s0 * d; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; d = 1.092548431; out_grads[1][0] = c1 * d; out_grads[5][0] = s1 * d; - out_grads[1][1] = -s1 * d; - out_grads[5][1] = c1 * d; + out_grads[5][1] = -s1 * d; + out_grads[1][1] = c1 * d; d = -1.092548431; - out_grads[2][2] = -c1 * d; - out_grads[4][2] = s1 * d; + out_grads[4][2] = c1 * d; + out_grads[2][2] = s1 * d; out_grads[0][0] = 0.0; out_grads[0][1] = 0.0; out_grads[0][2] = 0.0; - out_grads[1][2] = 0.0; + out_grads[5][2] = 0.0; out_grads[3][0] = 0.0; out_grads[3][1] = 0.0; - out_grads[5][2] = 0.0; + out_grads[1][2] = 0.0; } diff --git a/fury/shaders/rt_odfs/eval_sh_grad_4.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_4 copy.frag similarity index 54% rename from fury/shaders/rt_odfs/eval_sh_grad_4.frag rename to fury/shaders/rt_odfs/tournier/eval_sh_grad_4 copy.frag index 715302f39..c85847a5b 100644 --- a/fury/shaders/rt_odfs/eval_sh_grad_4.frag +++ b/fury/shaders/rt_odfs/tournier/eval_sh_grad_4 copy.frag @@ -19,85 +19,85 @@ void eval_sh_grad_4(out float out_shs[15], out vec3 out_grads[15], vec3 point) c1 = x; s1 = y; d = -1.092548431 * z; - out_shs[2] = -c1 * d; - out_shs[4] = s1 * d; - out_grads[2][0] = -c0 * d; - out_grads[4][0] = s0 * d; - out_grads[2][1] = s0 * d; - out_grads[4][1] = c0 * d; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + out_grads[4][0] = c0 * d; + out_grads[2][0] = s0 * d; + out_grads[4][1] = s0 * d; + out_grads[2][1] = c0 * d; d = 1.892349392 * z; out_grads[3][2] = d; a = (z2 - 0.2) * z; b = a - 0.228571429 * z; d = -4.683325805 * b; - out_shs[9] = -c1 * d; - out_shs[11] = s1 * d; - out_grads[9][0] = -c0 * d; - out_grads[11][0] = s0 * d; - out_grads[9][1] = s0 * d; - out_grads[11][1] = c0 * d; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + out_grads[11][0] = c0 * d; + out_grads[9][0] = s0 * d; + out_grads[11][1] = s0 * d; + out_grads[9][1] = c0 * d; d = 14.809976568 * b; out_grads[10][2] = d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.546274215; - out_shs[1] = c0 * d; - out_shs[5] = s0 * d; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; d = 1.092548431; - out_grads[1][0] = c1 * d; - out_grads[5][0] = s1 * d; - out_grads[1][1] = -s1 * d; - out_grads[5][1] = c1 * d; + out_grads[5][0] = c1 * d; + out_grads[1][0] = s1 * d; + out_grads[5][1] = -s1 * d; + out_grads[1][1] = c1 * d; d = -1.092548431; - out_grads[2][2] = -c1 * d; - out_grads[4][2] = s1 * d; + out_grads[4][2] = c1 * d; + out_grads[2][2] = s1 * d; a = z2 - 0.142857143; d = 3.311611435 * a; - out_shs[8] = c0 * d; - out_shs[12] = s0 * d; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; d = 6.62322287 * a; - out_grads[8][0] = c1 * d; - out_grads[12][0] = s1 * d; - out_grads[8][1] = -s1 * d; - out_grads[12][1] = c1 * d; + out_grads[12][0] = c1 * d; + out_grads[8][0] = s1 * d; + out_grads[12][1] = -s1 * d; + out_grads[8][1] = c1 * d; d = -14.049977415 * a; - out_grads[9][2] = -c1 * d; - out_grads[11][2] = s1 * d; + out_grads[11][2] = c1 * d; + out_grads[9][2] = s1 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -1.77013077 * z; - out_shs[7] = -c1 * d; - out_shs[13] = s1 * d; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; d = -5.310392309 * z; - out_grads[7][0] = -c0 * d; - out_grads[13][0] = s0 * d; - out_grads[7][1] = s0 * d; - out_grads[13][1] = c0 * d; + out_grads[13][0] = c0 * d; + out_grads[7][0] = s0 * d; + out_grads[13][1] = s0 * d; + out_grads[7][1] = c0 * d; d = 6.62322287 * z; - out_grads[8][2] = c0 * d; - out_grads[12][2] = s0 * d; + out_grads[12][2] = c0 * d; + out_grads[8][2] = s0 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.625835735; - out_shs[6] = c0 * d; - out_shs[14] = s0 * d; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; d = 2.503342942; - out_grads[6][0] = c1 * d; - out_grads[14][0] = s1 * d; - out_grads[6][1] = -s1 * d; - out_grads[14][1] = c1 * d; + out_grads[14][0] = c1 * d; + out_grads[6][0] = s1 * d; + out_grads[14][1] = -s1 * d; + out_grads[6][1] = c1 * d; d = -1.77013077; - out_grads[7][2] = -c1 * d; - out_grads[13][2] = s1 * d; + out_grads[13][2] = c1 * d; + out_grads[7][2] = s1 * d; out_grads[0][0] = 0.0; out_grads[0][1] = 0.0; out_grads[0][2] = 0.0; - out_grads[1][2] = 0.0; + out_grads[5][2] = 0.0; out_grads[3][0] = 0.0; out_grads[3][1] = 0.0; - out_grads[5][2] = 0.0; - out_grads[6][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[14][2] = 0.0; out_grads[10][0] = 0.0; out_grads[10][1] = 0.0; - out_grads[14][2] = 0.0; + out_grads[6][2] = 0.0; } diff --git a/fury/shaders/rt_odfs/eval_sh_grad_6.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_6 copy.frag similarity index 50% rename from fury/shaders/rt_odfs/eval_sh_grad_6.frag rename to fury/shaders/rt_odfs/tournier/eval_sh_grad_6 copy.frag index fa240c3a5..617413bc9 100644 --- a/fury/shaders/rt_odfs/eval_sh_grad_6.frag +++ b/fury/shaders/rt_odfs/tournier/eval_sh_grad_6 copy.frag @@ -23,164 +23,164 @@ void eval_sh_grad_6(out float out_shs[28], out vec3 out_grads[28], vec3 point) c1 = x; s1 = y; d = -1.092548431 * z; - out_shs[2] = -c1 * d; - out_shs[4] = s1 * d; - out_grads[2][0] = -c0 * d; - out_grads[4][0] = s0 * d; - out_grads[2][1] = s0 * d; - out_grads[4][1] = c0 * d; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + out_grads[4][0] = c0 * d; + out_grads[2][0] = s0 * d; + out_grads[4][1] = s0 * d; + out_grads[2][1] = c0 * d; d = 1.892349392 * z; out_grads[3][2] = d; a = (z2 - 0.2) * z; b = a - 0.228571429 * z; d = -4.683325805 * b; - out_shs[9] = -c1 * d; - out_shs[11] = s1 * d; - out_grads[9][0] = -c0 * d; - out_grads[11][0] = s0 * d; - out_grads[9][1] = s0 * d; - out_grads[11][1] = c0 * d; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + out_grads[11][0] = c0 * d; + out_grads[9][0] = s0 * d; + out_grads[11][1] = s0 * d; + out_grads[9][1] = c0 * d; d = 14.809976568 * b; out_grads[10][2] = d; a = z2 * b - 0.238095238 * a; b = a - 0.242424242 * b; d = -19.226504963 * b; - out_shs[20] = -c1 * d; - out_shs[22] = s1 * d; - out_grads[20][0] = -c0 * d; - out_grads[22][0] = s0 * d; - out_grads[20][1] = s0 * d; - out_grads[22][1] = c0 * d; + out_shs[22] = c1 * d; + out_shs[20] = s1 * d; + out_grads[22][0] = c0 * d; + out_grads[20][0] = s0 * d; + out_grads[22][1] = s0 * d; + out_grads[20][1] = c0 * d; d = 88.106914343 * b; out_grads[21][2] = d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.546274215; - out_shs[1] = c0 * d; - out_shs[5] = s0 * d; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; d = 1.092548431; - out_grads[1][0] = c1 * d; - out_grads[5][0] = s1 * d; - out_grads[1][1] = -s1 * d; - out_grads[5][1] = c1 * d; + out_grads[5][0] = c1 * d; + out_grads[1][0] = s1 * d; + out_grads[5][1] = -s1 * d; + out_grads[1][1] = c1 * d; d = -1.092548431; - out_grads[2][2] = -c1 * d; - out_grads[4][2] = s1 * d; + out_grads[4][2] = c1 * d; + out_grads[2][2] = s1 * d; a = z2 - 0.142857143; d = 3.311611435 * a; - out_shs[8] = c0 * d; - out_shs[12] = s0 * d; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; d = 6.62322287 * a; - out_grads[8][0] = c1 * d; - out_grads[12][0] = s1 * d; - out_grads[8][1] = -s1 * d; - out_grads[12][1] = c1 * d; + out_grads[12][0] = c1 * d; + out_grads[8][0] = s1 * d; + out_grads[12][1] = -s1 * d; + out_grads[8][1] = c1 * d; d = -14.049977415 * a; - out_grads[9][2] = -c1 * d; - out_grads[11][2] = s1 * d; + out_grads[11][2] = c1 * d; + out_grads[9][2] = s1 * d; b = z2 * (a - 0.19047619); a = b - 0.212121212 * a; d = 15.199886782 * a; - out_shs[19] = c0 * d; - out_shs[23] = s0 * d; + out_shs[23] = c0 * d; + out_shs[19] = s0 * d; d = 30.399773564 * a; - out_grads[19][0] = c1 * d; - out_grads[23][0] = s1 * d; - out_grads[19][1] = -s1 * d; - out_grads[23][1] = c1 * d; + out_grads[23][0] = c1 * d; + out_grads[19][0] = s1 * d; + out_grads[23][1] = -s1 * d; + out_grads[19][1] = c1 * d; d = -96.132524816 * a; - out_grads[20][2] = -c1 * d; - out_grads[22][2] = s1 * d; + out_grads[22][2] = c1 * d; + out_grads[20][2] = s1 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -1.77013077 * z; - out_shs[7] = -c1 * d; - out_shs[13] = s1 * d; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; d = -5.310392309 * z; - out_grads[7][0] = -c0 * d; - out_grads[13][0] = s0 * d; - out_grads[7][1] = s0 * d; - out_grads[13][1] = c0 * d; + out_grads[13][0] = c0 * d; + out_grads[7][0] = s0 * d; + out_grads[13][1] = s0 * d; + out_grads[7][1] = c0 * d; d = 6.62322287 * z; - out_grads[8][2] = c0 * d; - out_grads[12][2] = s0 * d; + out_grads[12][2] = c0 * d; + out_grads[8][2] = s0 * d; a = (z2 - 0.111111111) * z; b = a - 0.161616162 * z; d = -10.133257855 * b; - out_shs[18] = -c1 * d; - out_shs[24] = s1 * d; + out_shs[24] = c1 * d; + out_shs[18] = s1 * d; d = -30.399773564 * b; - out_grads[18][0] = -c0 * d; - out_grads[24][0] = s0 * d; - out_grads[18][1] = s0 * d; - out_grads[24][1] = c0 * d; + out_grads[24][0] = c0 * d; + out_grads[18][0] = s0 * d; + out_grads[24][1] = s0 * d; + out_grads[18][1] = c0 * d; d = 60.799547128 * b; - out_grads[19][2] = c0 * d; - out_grads[23][2] = s0 * d; + out_grads[23][2] = c0 * d; + out_grads[19][2] = s0 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.625835735; - out_shs[6] = c0 * d; - out_shs[14] = s0 * d; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; d = 2.503342942; - out_grads[6][0] = c1 * d; - out_grads[14][0] = s1 * d; - out_grads[6][1] = -s1 * d; - out_grads[14][1] = c1 * d; + out_grads[14][0] = c1 * d; + out_grads[6][0] = s1 * d; + out_grads[14][1] = -s1 * d; + out_grads[6][1] = c1 * d; d = -1.77013077; - out_grads[7][2] = -c1 * d; - out_grads[13][2] = s1 * d; + out_grads[13][2] = c1 * d; + out_grads[7][2] = s1 * d; a = z2 - 9.09090909e-02; d = 5.550213908 * a; - out_shs[17] = c0 * d; - out_shs[25] = s0 * d; + out_shs[25] = c0 * d; + out_shs[17] = s0 * d; d = 22.200855632 * a; - out_grads[17][0] = c1 * d; - out_grads[25][0] = s1 * d; - out_grads[17][1] = -s1 * d; - out_grads[25][1] = c1 * d; + out_grads[25][0] = c1 * d; + out_grads[17][0] = s1 * d; + out_grads[25][1] = -s1 * d; + out_grads[17][1] = c1 * d; d = -30.399773564 * a; - out_grads[18][2] = -c1 * d; - out_grads[24][2] = s1 * d; + out_grads[24][2] = c1 * d; + out_grads[18][2] = s1 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -2.366619162 * z; - out_shs[16] = -c1 * d; - out_shs[26] = s1 * d; + out_shs[26] = c1 * d; + out_shs[16] = s1 * d; d = -11.833095811 * z; - out_grads[16][0] = -c0 * d; - out_grads[26][0] = s0 * d; - out_grads[16][1] = s0 * d; - out_grads[26][1] = c0 * d; + out_grads[26][0] = c0 * d; + out_grads[16][0] = s0 * d; + out_grads[26][1] = s0 * d; + out_grads[16][1] = c0 * d; d = 11.100427816 * z; - out_grads[17][2] = c0 * d; - out_grads[25][2] = s0 * d; + out_grads[25][2] = c0 * d; + out_grads[17][2] = s0 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.683184105; - out_shs[15] = c0 * d; - out_shs[27] = s0 * d; + out_shs[27] = c0 * d; + out_shs[15] = s0 * d; d = 4.099104631; - out_grads[15][0] = c1 * d; - out_grads[27][0] = s1 * d; - out_grads[15][1] = -s1 * d; - out_grads[27][1] = c1 * d; + out_grads[27][0] = c1 * d; + out_grads[15][0] = s1 * d; + out_grads[27][1] = -s1 * d; + out_grads[15][1] = c1 * d; d = -2.366619162; - out_grads[16][2] = -c1 * d; - out_grads[26][2] = s1 * d; + out_grads[26][2] = c1 * d; + out_grads[16][2] = s1 * d; out_grads[0][0] = 0.0; out_grads[0][1] = 0.0; out_grads[0][2] = 0.0; - out_grads[1][2] = 0.0; + out_grads[5][2] = 0.0; out_grads[3][0] = 0.0; out_grads[3][1] = 0.0; - out_grads[5][2] = 0.0; - out_grads[6][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[14][2] = 0.0; out_grads[10][0] = 0.0; out_grads[10][1] = 0.0; - out_grads[14][2] = 0.0; - out_grads[15][2] = 0.0; + out_grads[6][2] = 0.0; + out_grads[27][2] = 0.0; out_grads[21][0] = 0.0; out_grads[21][1] = 0.0; - out_grads[27][2] = 0.0; + out_grads[15][2] = 0.0; } diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_8 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_8 copy.frag new file mode 100644 index 000000000..712b2dc29 --- /dev/null +++ b/fury/shaders/rt_odfs/tournier/eval_sh_grad_8 copy.frag @@ -0,0 +1,295 @@ +void eval_sh_grad_8(out float out_shs[45], out vec3 out_grads[45], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + out_grads[4][0] = c0 * d; + out_grads[2][0] = s0 * d; + out_grads[4][1] = s0 * d; + out_grads[2][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + out_grads[11][0] = c0 * d; + out_grads[9][0] = s0 * d; + out_grads[11][1] = s0 * d; + out_grads[9][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[22] = c1 * d; + out_shs[20] = s1 * d; + out_grads[22][0] = c0 * d; + out_grads[20][0] = s0 * d; + out_grads[22][1] = s0 * d; + out_grads[20][1] = c0 * d; + d = 88.106914343 * b; + out_grads[21][2] = d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[37] = c1 * d; + out_shs[35] = s1 * d; + out_grads[37][0] = c0 * d; + out_grads[35][0] = s0 * d; + out_grads[37][1] = s0 * d; + out_grads[35][1] = c0 * d; + d = 467.786944906 * b; + out_grads[36][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + d = 1.092548431; + out_grads[5][0] = c1 * d; + out_grads[1][0] = s1 * d; + out_grads[5][1] = -s1 * d; + out_grads[1][1] = c1 * d; + d = -1.092548431; + out_grads[4][2] = c1 * d; + out_grads[2][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + d = 6.62322287 * a; + out_grads[12][0] = c1 * d; + out_grads[8][0] = s1 * d; + out_grads[12][1] = -s1 * d; + out_grads[8][1] = c1 * d; + d = -14.049977415 * a; + out_grads[11][2] = c1 * d; + out_grads[9][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[23] = c0 * d; + out_shs[19] = s0 * d; + d = 30.399773564 * a; + out_grads[23][0] = c1 * d; + out_grads[19][0] = s1 * d; + out_grads[23][1] = -s1 * d; + out_grads[19][1] = c1 * d; + d = -96.132524816 * a; + out_grads[22][2] = c1 * d; + out_grads[20][2] = s1 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[38] = c0 * d; + out_shs[34] = s0 * d; + d = 130.459545912 * a; + out_grads[38][0] = c1 * d; + out_grads[34][0] = s1 * d; + out_grads[38][1] = -s1 * d; + out_grads[34][1] = c1 * d; + d = -545.751435723 * a; + out_grads[37][2] = c1 * d; + out_grads[35][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; + d = -5.310392309 * z; + out_grads[13][0] = c0 * d; + out_grads[7][0] = s0 * d; + out_grads[13][1] = s0 * d; + out_grads[7][1] = c0 * d; + d = 6.62322287 * z; + out_grads[12][2] = c0 * d; + out_grads[8][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[24] = c1 * d; + out_shs[18] = s1 * d; + d = -30.399773564 * b; + out_grads[24][0] = c0 * d; + out_grads[18][0] = s0 * d; + out_grads[24][1] = s0 * d; + out_grads[18][1] = c0 * d; + d = 60.799547128 * b; + out_grads[23][2] = c0 * d; + out_grads[19][2] = s0 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[39] = c1 * d; + out_shs[33] = s1 * d; + d = -144.52614017 * b; + out_grads[39][0] = c0 * d; + out_grads[33][0] = s0 * d; + out_grads[39][1] = s0 * d; + out_grads[33][1] = c0 * d; + d = 391.378637737 * b; + out_grads[38][2] = c0 * d; + out_grads[34][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; + d = 2.503342942; + out_grads[14][0] = c1 * d; + out_grads[6][0] = s1 * d; + out_grads[14][1] = -s1 * d; + out_grads[6][1] = c1 * d; + d = -1.77013077; + out_grads[13][2] = c1 * d; + out_grads[7][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[25] = c0 * d; + out_shs[17] = s0 * d; + d = 22.200855632 * a; + out_grads[25][0] = c1 * d; + out_grads[17][0] = s1 * d; + out_grads[25][1] = -s1 * d; + out_grads[17][1] = c1 * d; + d = -30.399773564 * a; + out_grads[24][2] = c1 * d; + out_grads[18][2] = s1 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[40] = c0 * d; + out_shs[32] = s0 * d; + d = 124.388296437 * a; + out_grads[40][0] = c1 * d; + out_grads[32][0] = s1 * d; + out_grads[40][1] = -s1 * d; + out_grads[32][1] = c1 * d; + d = -240.876900283 * a; + out_grads[39][2] = c1 * d; + out_grads[33][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[26] = c1 * d; + out_shs[16] = s1 * d; + d = -11.833095811 * z; + out_grads[26][0] = c0 * d; + out_grads[16][0] = s0 * d; + out_grads[26][1] = s0 * d; + out_grads[16][1] = c0 * d; + d = 11.100427816 * z; + out_grads[25][2] = c0 * d; + out_grads[17][2] = s0 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[41] = c1 * d; + out_shs[31] = s1 * d; + d = -86.247765552 * b; + out_grads[41][0] = c0 * d; + out_grads[31][0] = s0 * d; + out_grads[41][1] = s0 * d; + out_grads[31][1] = c0 * d; + d = 124.388296437 * b; + out_grads[40][2] = c0 * d; + out_grads[32][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[27] = c0 * d; + out_shs[15] = s0 * d; + d = 4.099104631; + out_grads[27][0] = c1 * d; + out_grads[15][0] = s1 * d; + out_grads[27][1] = -s1 * d; + out_grads[15][1] = c1 * d; + d = -2.366619162; + out_grads[26][2] = c1 * d; + out_grads[16][2] = s1 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[42] = c0 * d; + out_shs[30] = s0 * d; + d = 47.909948945 * a; + out_grads[42][0] = c1 * d; + out_grads[30][0] = s1 * d; + out_grads[42][1] = -s1 * d; + out_grads[30][1] = c1 * d; + d = -51.748659331 * a; + out_grads[41][2] = c1 * d; + out_grads[31][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[43] = c1 * d; + out_shs[29] = s1 * d; + d = -20.409946485 * z; + out_grads[43][0] = c0 * d; + out_grads[29][0] = s0 * d; + out_grads[43][1] = s0 * d; + out_grads[29][1] = c0 * d; + d = 15.969982982 * z; + out_grads[42][2] = c0 * d; + out_grads[30][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[44] = c0 * d; + out_shs[28] = s0 * d; + d = 5.831413281; + out_grads[44][0] = c1 * d; + out_grads[28][0] = s1 * d; + out_grads[44][1] = -s1 * d; + out_grads[28][1] = c1 * d; + d = -2.915706641; + out_grads[43][2] = c1 * d; + out_grads[29][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[5][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[1][2] = 0.0; + out_grads[14][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[6][2] = 0.0; + out_grads[27][2] = 0.0; + out_grads[21][0] = 0.0; + out_grads[21][1] = 0.0; + out_grads[15][2] = 0.0; + out_grads[44][2] = 0.0; + out_grads[36][0] = 0.0; + out_grads[36][1] = 0.0; + out_grads[28][2] = 0.0; +} From dd1665336063d6a629910e2bbeafed17f7b165a9 Mon Sep 17 00:00:00 2001 From: tvcastillod Date: Fri, 1 Mar 2024 11:39:22 -0500 Subject: [PATCH 099/118] added degree param --- .../SH-ODF experimental/odf_example.py | 37 +- fury/actors/odf.py | 74 +-- .../tournier/eval_sh_grad_10 copy.frag | 430 ------------- .../tournier/eval_sh_grad_12 copy.frag | 591 ------------------ .../rt_odfs/tournier/eval_sh_grad_2 copy.frag | 46 -- .../rt_odfs/tournier/eval_sh_grad_4 copy.frag | 103 --- .../rt_odfs/tournier/eval_sh_grad_6 copy.frag | 186 ------ .../rt_odfs/tournier/eval_sh_grad_8 copy.frag | 295 --------- 8 files changed, 53 insertions(+), 1709 deletions(-) delete mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_grad_10 copy.frag delete mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_grad_12 copy.frag delete mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_grad_2 copy.frag delete mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_grad_4 copy.frag delete mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_grad_6 copy.frag delete mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_grad_8 copy.frag diff --git a/docs/experimental/SH-ODF experimental/odf_example.py b/docs/experimental/SH-ODF experimental/odf_example.py index e16858211..50978942d 100644 --- a/docs/experimental/SH-ODF experimental/odf_example.py +++ b/docs/experimental/SH-ODF experimental/odf_example.py @@ -20,8 +20,39 @@ x, y, z, s = coeffs.shape coeffs = coeffs[:, :, :].reshape((x * y * z, s)) - n_glyphs = coeffs.shape[0] - - odf_actor = actor.odf(centers=centers, coeffs=coeffs, scales=1.0) + + #''' + coeffs = np.array([ + [ + -0.2739740312099, 0.2526670396328, 1.8922271728516, 0.2878578901291, + -0.5339795947075, -0.2620058953762, 0.1580424904823, 0.0329004973173, + -0.1322413831949, -0.1332057565451, 1.0894461870193, -0.6319401264191, + -0.0416776277125, -1.0772529840469, 0.1423762738705, 0.7941166162491, + 0.7490307092667, -0.3428381681442, 0.1024847552180, -0.0219132602215, + 0.0499043911695, 0.2162453681231, 0.0921059995890, -0.2611238956451, + 0.2549301385880, -0.4534865319729, 0.1922748684883, -0.6200597286224, + -0.0532187558711, -0.3569841980934, 0.0293972902000, -0.1977960765362, + -0.1058669015765, 0.2372217923403, -0.1856198310852, -0.3373193442822, + -0.0750469490886, 0.2146576642990, -0.0490148440003, 0.1288588196039, + 0.3173974752426, 0.1990085393190, -0.1736343950033, -0.0482443645597, + 0.1749017387629, -0.0151847425660, 0.0418366046081, 0.0863263587216, + -0.0649211244490, 0.0126096132283, 0.0545089217982, -0.0275142164626, + 0.0399986574832, -0.0468244261610, -0.1292105653111, -0.0786858322658, + -0.0663828464882, 0.0382439706831, -0.0041550330365, -0.0502800566338, + -0.0732471630735, 0.0181751900972, -0.0090119333757, -0.0604443282359, + -0.1469985252752, -0.0534046899715, -0.0896672753415, -0.0130841364808, + -0.0112942893801, 0.0272257498541, 0.0626717616331, -0.0222197983050, + -0.0018541504308, -0.1653251944056, 0.0409697402846, 0.0749921454327, + -0.0282830872616, 0.0006909458525, 0.0625599842287, 0.0812529816082, + 0.0914693020772, -0.1197222726745, 0.0376277453183, -0.0832617004142, + -0.0482175038043, -0.0839003635737, -0.0349423908400, 0.1204519568256, + 0.0783745984003, 0.0297401205976, -0.0505947662525 + ] + ]) + centers= np.array([0, 0, 0]) + #''' + + odf_actor = actor.odf(centers=centers, coeffs=coeffs, scales=1.0, + basis_type='descoteaux', degree=6) show_man.scene.add(odf_actor) show_man.start() \ No newline at end of file diff --git a/fury/actors/odf.py b/fury/actors/odf.py index e8a762c55..139567a56 100644 --- a/fury/actors/odf.py +++ b/fury/actors/odf.py @@ -32,14 +32,13 @@ def uv_calculations(n): return uvs def minmax_norm(data): - min = data.min(axis=1) max = data.max(axis=1) return np.array([(data[i] - min[i]) / (max[i] - min[i]) for i in range(data.shape[0])]) -def sh_odf(centers, coeffs, basis_type, scales, opacity): +def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): """ Visualize one or many ODFs with different features. @@ -53,6 +52,9 @@ def sh_odf(centers, coeffs, basis_type, scales, opacity): Type of basis (descoteaux, tournier) 'descoteaux' for the default ``descoteaux07`` DYPY basis. 'tournier' for the default ``tournier07` DYPY basis. + degree: int, optional + Index of the highest used band of the spherical harmonics basis. Must + be even, at least 2 and at most 12. scales : float or ndarray (N, ) ODFs size. opacity : float @@ -108,7 +110,7 @@ def sh_odf(centers, coeffs, basis_type, scales, opacity): # The number of coefficients is associated to the order of the SH odf_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniformf( - "numCoeffs", 15 + "numCoeffs", ((degree + 1) * (degree + 2)) / 2 ) # Start of shader implementation @@ -142,7 +144,7 @@ def sh_odf(centers, coeffs, basis_type, scales, opacity): # The index of the highest used band of the spherical harmonics basis. Must # be even, at least 2 and at most 12. - def_sh_degree = "#define SH_DEGREE 4" + def_sh_degree = "#define SH_DEGREE " + str(degree) # The number of spherical harmonics basis functions def_sh_count = "#define SH_COUNT (((SH_DEGREE + 1) * (SH_DEGREE + 2)) / 2)" @@ -187,47 +189,14 @@ def sh_odf(centers, coeffs, basis_type, scales, opacity): coeffs_norm = import_fury_shader(os.path.join("utils", "minmax_norm.glsl")) - eval_sh_2 = import_fury_shader( - os.path.join("rt_odfs", basis_type, "eval_sh_2.frag")) - - eval_sh_4 = import_fury_shader( - os.path.join("rt_odfs", basis_type, "eval_sh_4.frag")) - - eval_sh_6 = import_fury_shader( - os.path.join("rt_odfs", basis_type, "eval_sh_6.frag")) - - eval_sh_8 = import_fury_shader( - os.path.join("rt_odfs", basis_type, "eval_sh_8.frag")) - - eval_sh_10 = import_fury_shader( - os.path.join("rt_odfs", basis_type, "eval_sh_10.frag")) - - eval_sh_12 = import_fury_shader( - os.path.join("rt_odfs", basis_type, "eval_sh_12.frag")) - - eval_sh_grad_2 = import_fury_shader( - os.path.join("rt_odfs/descoteaux", "eval_sh_grad_2.frag") - ) - - eval_sh_grad_4 = import_fury_shader( - os.path.join("rt_odfs/descoteaux", "eval_sh_grad_4.frag") - ) - - eval_sh_grad_6 = import_fury_shader( - os.path.join("rt_odfs/descoteaux", "eval_sh_grad_6.frag") - ) - - eval_sh_grad_8 = import_fury_shader( - os.path.join("rt_odfs/descoteaux", "eval_sh_grad_8.frag") - ) - - eval_sh_grad_10 = import_fury_shader( - os.path.join("rt_odfs/descoteaux", "eval_sh_grad_10.frag") - ) - - eval_sh_grad_12 = import_fury_shader( - os.path.join("rt_odfs/descoteaux", "eval_sh_grad_12.frag") - ) + eval_sh_list = '' + for i in range (2, degree+1, 2): + eval_sh = import_fury_shader( + os.path.join("rt_odfs", basis_type, 'eval_sh_' + str(i) + '.frag')) + eval_sh_grad = import_fury_shader( + os.path.join("rt_odfs", basis_type, + 'eval_sh_grad_' + str(i) + '.frag')) + eval_sh_list = eval_sh_list + '\n\n' + eval_sh + '\n\n' + eval_sh_grad # Searches a single root of a polynomial within a given interval. # param out_root The location of the found root. @@ -334,13 +303,10 @@ def sh_odf(centers, coeffs, basis_type, scales, opacity): fs_dec = compose_shader([ def_sh_degree, def_sh_count, def_max_degree, def_gl_ext_control_flow_attributes, def_no_intersection, def_pis, - fs_vs_vars, coeffs_norm, eval_sh_2, eval_sh_4, eval_sh_6, eval_sh_8, - eval_sh_10, eval_sh_12, eval_sh_grad_2, eval_sh_grad_4, eval_sh_grad_6, - eval_sh_grad_8, eval_sh_grad_10, eval_sh_grad_12, newton_bisection, - find_roots, eval_sh, eval_sh_grad, get_inv_vandermonde, - ray_sh_glyph_intersections, get_sh_glyph_normal, blinn_phong_model, - linear_to_srgb, srgb_to_linear, linear_rgb_to_srgb, srgb_to_linear_rgb, - tonemap + fs_vs_vars, coeffs_norm, eval_sh_list, newton_bisection, find_roots, + eval_sh, eval_sh_grad, get_inv_vandermonde, ray_sh_glyph_intersections, + get_sh_glyph_normal, blinn_phong_model, linear_to_srgb, srgb_to_linear, + linear_rgb_to_srgb, srgb_to_linear_rgb, tonemap ]) # fmt: on @@ -351,7 +317,6 @@ def sh_odf(centers, coeffs, basis_type, scales, opacity): # Ray origin is the camera position in world space ray_origin = "vec3 ro = camPosMCVSOutput;" - # TODO: Check aspect for automatic scaling # Ray direction is the normalized difference between the fragment and the # camera position/ray origin ray_direction = "vec3 rd = normalize(pnt - ro);" @@ -392,7 +357,7 @@ def sh_odf(centers, coeffs, basis_type, scales, opacity): break; } } - """ + """ # Evaluate shading for a directional light directional_light = \ @@ -404,7 +369,6 @@ def sh_odf(centers, coeffs, basis_type, scales, opacity): vec3 colorDir = srgb_to_linear_rgb(abs(normalize(intersection))); float attenuation = dot(ld, normal); color = blinnPhongIllumModel( - //attenuation, lightColor0, diffuseColor, specularPower, attenuation, lightColor0, colorDir, specularPower, specularColor, ambientColor); } else { diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_10 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_10 copy.frag deleted file mode 100644 index c9e6b0d8d..000000000 --- a/fury/shaders/rt_odfs/tournier/eval_sh_grad_10 copy.frag +++ /dev/null @@ -1,430 +0,0 @@ -void eval_sh_grad_10(out float out_shs[66], out vec3 out_grads[66], vec3 point) -{ - float x, y, z, z2, c0, s0, c1, s1, d, a, b; - x = point[0]; - y = point[1]; - z = point[2]; - z2 = z * z; - c0 = 1.0; - s0 = 0.0; - d = 0.282094792; - out_shs[0] = d; - a = z2 - 0.333333333; - d = 0.946174696 * a; - out_shs[3] = d; - b = z2 * (a - 0.266666667); - a = b - 0.257142857 * a; - d = 3.702494142 * a; - out_shs[10] = d; - b = z2 * a - 0.253968254 * b; - a = b - 0.252525253 * a; - d = 14.684485724 * a; - out_shs[21] = d; - b = z2 * a - 0.251748252 * b; - a = b - 0.251282051 * a; - d = 58.473368113 * a; - out_shs[36] = d; - b = z2 * a - 0.250980392 * b; - a = b - 0.250773994 * a; - d = 233.240148813 * a; - out_shs[55] = d; - c1 = x; - s1 = y; - d = -1.092548431 * z; - out_shs[4] = c1 * d; - out_shs[2] = s1 * d; - out_grads[4][0] = c0 * d; - out_grads[2][0] = s0 * d; - out_grads[4][1] = s0 * d; - out_grads[2][1] = c0 * d; - d = 1.892349392 * z; - out_grads[3][2] = d; - a = (z2 - 0.2) * z; - b = a - 0.228571429 * z; - d = -4.683325805 * b; - out_shs[11] = c1 * d; - out_shs[9] = s1 * d; - out_grads[11][0] = c0 * d; - out_grads[9][0] = s0 * d; - out_grads[11][1] = s0 * d; - out_grads[9][1] = c0 * d; - d = 14.809976568 * b; - out_grads[10][2] = d; - a = z2 * b - 0.238095238 * a; - b = a - 0.242424242 * b; - d = -19.226504963 * b; - out_shs[22] = c1 * d; - out_shs[20] = s1 * d; - out_grads[22][0] = c0 * d; - out_grads[20][0] = s0 * d; - out_grads[22][1] = s0 * d; - out_grads[20][1] = c0 * d; - d = 88.106914343 * b; - out_grads[21][2] = d; - a = z2 * b - 0.244755245 * a; - b = a - 0.246153846 * b; - d = -77.964490818 * b; - out_shs[37] = c1 * d; - out_shs[35] = s1 * d; - out_grads[37][0] = c0 * d; - out_grads[35][0] = s0 * d; - out_grads[37][1] = s0 * d; - out_grads[35][1] = c0 * d; - d = 467.786944906 * b; - out_grads[36][2] = d; - a = z2 * b - 0.247058824 * a; - b = a - 0.247678019 * b; - d = -314.500952502 * b; - out_shs[56] = c1 * d; - out_shs[54] = s1 * d; - out_grads[56][0] = c0 * d; - out_grads[54][0] = s0 * d; - out_grads[56][1] = s0 * d; - out_grads[54][1] = c0 * d; - d = 2332.401488133 * b; - out_grads[55][2] = d; - c0 = x * c1 - y * s1; - s0 = y * c1 + x * s1; - d = 0.546274215; - out_shs[5] = c0 * d; - out_shs[1] = s0 * d; - d = 1.092548431; - out_grads[5][0] = c1 * d; - out_grads[1][0] = s1 * d; - out_grads[5][1] = -s1 * d; - out_grads[1][1] = c1 * d; - d = -1.092548431; - out_grads[4][2] = c1 * d; - out_grads[2][2] = s1 * d; - a = z2 - 0.142857143; - d = 3.311611435 * a; - out_shs[12] = c0 * d; - out_shs[8] = s0 * d; - d = 6.62322287 * a; - out_grads[12][0] = c1 * d; - out_grads[8][0] = s1 * d; - out_grads[12][1] = -s1 * d; - out_grads[8][1] = c1 * d; - d = -14.049977415 * a; - out_grads[11][2] = c1 * d; - out_grads[9][2] = s1 * d; - b = z2 * (a - 0.19047619); - a = b - 0.212121212 * a; - d = 15.199886782 * a; - out_shs[23] = c0 * d; - out_shs[19] = s0 * d; - d = 30.399773564 * a; - out_grads[23][0] = c1 * d; - out_grads[19][0] = s1 * d; - out_grads[23][1] = -s1 * d; - out_grads[19][1] = c1 * d; - d = -96.132524816 * a; - out_grads[22][2] = c1 * d; - out_grads[20][2] = s1 * d; - b = z2 * a - 0.223776224 * b; - a = b - 0.230769231 * a; - d = 65.229772956 * a; - out_shs[38] = c0 * d; - out_shs[34] = s0 * d; - d = 130.459545912 * a; - out_grads[38][0] = c1 * d; - out_grads[34][0] = s1 * d; - out_grads[38][1] = -s1 * d; - out_grads[34][1] = c1 * d; - d = -545.751435723 * a; - out_grads[37][2] = c1 * d; - out_grads[35][2] = s1 * d; - b = z2 * a - 0.235294118 * b; - a = b - 0.238390093 * a; - d = 272.365814381 * a; - out_shs[57] = c0 * d; - out_shs[53] = s0 * d; - d = 544.731628762 * a; - out_grads[57][0] = c1 * d; - out_grads[53][0] = s1 * d; - out_grads[57][1] = -s1 * d; - out_grads[53][1] = c1 * d; - d = -2830.508572514 * a; - out_grads[56][2] = c1 * d; - out_grads[54][2] = s1 * d; - c1 = x * c0 - y * s0; - s1 = y * c0 + x * s0; - d = -1.77013077 * z; - out_shs[13] = c1 * d; - out_shs[7] = s1 * d; - d = -5.310392309 * z; - out_grads[13][0] = c0 * d; - out_grads[7][0] = s0 * d; - out_grads[13][1] = s0 * d; - out_grads[7][1] = c0 * d; - d = 6.62322287 * z; - out_grads[12][2] = c0 * d; - out_grads[8][2] = s0 * d; - a = (z2 - 0.111111111) * z; - b = a - 0.161616162 * z; - d = -10.133257855 * b; - out_shs[24] = c1 * d; - out_shs[18] = s1 * d; - d = -30.399773564 * b; - out_grads[24][0] = c0 * d; - out_grads[18][0] = s0 * d; - out_grads[24][1] = s0 * d; - out_grads[18][1] = c0 * d; - d = 60.799547128 * b; - out_grads[23][2] = c0 * d; - out_grads[19][2] = s0 * d; - a = z2 * b - 0.188811189 * a; - b = a - 0.205128205 * b; - d = -48.175380057 * b; - out_shs[39] = c1 * d; - out_shs[33] = s1 * d; - d = -144.52614017 * b; - out_grads[39][0] = c0 * d; - out_grads[33][0] = s0 * d; - out_grads[39][1] = s0 * d; - out_grads[33][1] = c0 * d; - d = 391.378637737 * b; - out_grads[38][2] = c0 * d; - out_grads[34][2] = s0 * d; - a = z2 * b - 0.215686275 * a; - b = a - 0.222910217 * b; - d = -213.661323441 * b; - out_shs[58] = c1 * d; - out_shs[52] = s1 * d; - d = -640.983970322 * b; - out_grads[58][0] = c0 * d; - out_grads[52][0] = s0 * d; - out_grads[58][1] = s0 * d; - out_grads[52][1] = c0 * d; - d = 2178.926515046 * b; - out_grads[57][2] = c0 * d; - out_grads[53][2] = s0 * d; - c0 = x * c1 - y * s1; - s0 = y * c1 + x * s1; - d = 0.625835735; - out_shs[14] = c0 * d; - out_shs[6] = s0 * d; - d = 2.503342942; - out_grads[14][0] = c1 * d; - out_grads[6][0] = s1 * d; - out_grads[14][1] = -s1 * d; - out_grads[6][1] = c1 * d; - d = -1.77013077; - out_grads[13][2] = c1 * d; - out_grads[7][2] = s1 * d; - a = z2 - 9.09090909e-02; - d = 5.550213908 * a; - out_shs[25] = c0 * d; - out_shs[17] = s0 * d; - d = 22.200855632 * a; - out_grads[25][0] = c1 * d; - out_grads[17][0] = s1 * d; - out_grads[25][1] = -s1 * d; - out_grads[17][1] = c1 * d; - d = -30.399773564 * a; - out_grads[24][2] = c1 * d; - out_grads[18][2] = s1 * d; - b = z2 * (a - 0.13986014); - a = b - 0.169230769 * a; - d = 31.097074109 * a; - out_shs[40] = c0 * d; - out_shs[32] = s0 * d; - d = 124.388296437 * a; - out_grads[40][0] = c1 * d; - out_grads[32][0] = s1 * d; - out_grads[40][1] = -s1 * d; - out_grads[32][1] = c1 * d; - d = -240.876900283 * a; - out_grads[39][2] = c1 * d; - out_grads[33][2] = s1 * d; - b = z2 * a - 0.188235294 * b; - a = b - 0.20123839 * a; - d = 151.081370682 * a; - out_shs[59] = c0 * d; - out_shs[51] = s0 * d; - d = 604.325482728 * a; - out_grads[59][0] = c1 * d; - out_grads[51][0] = s1 * d; - out_grads[59][1] = -s1 * d; - out_grads[51][1] = c1 * d; - d = -1495.629264084 * a; - out_grads[58][2] = c1 * d; - out_grads[52][2] = s1 * d; - c1 = x * c0 - y * s0; - s1 = y * c0 + x * s0; - d = -2.366619162 * z; - out_shs[26] = c1 * d; - out_shs[16] = s1 * d; - d = -11.833095811 * z; - out_grads[26][0] = c0 * d; - out_grads[16][0] = s0 * d; - out_grads[26][1] = s0 * d; - out_grads[16][1] = c0 * d; - d = 11.100427816 * z; - out_grads[25][2] = c0 * d; - out_grads[17][2] = s0 * d; - a = (z2 - 7.69230769e-02) * z; - b = a - 0.123076923 * z; - d = -17.24955311 * b; - out_shs[41] = c1 * d; - out_shs[31] = s1 * d; - d = -86.247765552 * b; - out_grads[41][0] = c0 * d; - out_grads[31][0] = s0 * d; - out_grads[41][1] = s0 * d; - out_grads[31][1] = c0 * d; - d = 124.388296437 * b; - out_grads[40][2] = c0 * d; - out_grads[32][2] = s0 * d; - a = z2 * b - 0.152941176 * a; - b = a - 0.173374613 * b; - d = -95.552248675 * b; - out_shs[60] = c1 * d; - out_shs[50] = s1 * d; - d = -477.761243376 * b; - out_grads[60][0] = c0 * d; - out_grads[50][0] = s0 * d; - out_grads[60][1] = s0 * d; - out_grads[50][1] = c0 * d; - d = 906.488224092 * b; - out_grads[59][2] = c0 * d; - out_grads[51][2] = s0 * d; - c0 = x * c1 - y * s1; - s0 = y * c1 + x * s1; - d = 0.683184105; - out_shs[27] = c0 * d; - out_shs[15] = s0 * d; - d = 4.099104631; - out_grads[27][0] = c1 * d; - out_grads[15][0] = s1 * d; - out_grads[27][1] = -s1 * d; - out_grads[15][1] = c1 * d; - d = -2.366619162; - out_grads[26][2] = c1 * d; - out_grads[16][2] = s1 * d; - a = z2 - 6.66666667e-02; - d = 7.984991491 * a; - out_shs[42] = c0 * d; - out_shs[30] = s0 * d; - d = 47.909948945 * a; - out_grads[42][0] = c1 * d; - out_grads[30][0] = s1 * d; - out_grads[42][1] = -s1 * d; - out_grads[30][1] = c1 * d; - d = -51.748659331 * a; - out_grads[41][2] = c1 * d; - out_grads[31][2] = s1 * d; - b = z2 * (a - 0.109803922); - a = b - 0.139318885 * a; - d = 53.41533086 * a; - out_shs[61] = c0 * d; - out_shs[49] = s0 * d; - d = 320.491985161 * a; - out_grads[61][0] = c1 * d; - out_grads[49][0] = s1 * d; - out_grads[61][1] = -s1 * d; - out_grads[49][1] = c1 * d; - d = -477.761243376 * a; - out_grads[60][2] = c1 * d; - out_grads[50][2] = s1 * d; - c1 = x * c0 - y * s0; - s1 = y * c0 + x * s0; - d = -2.915706641 * z; - out_shs[43] = c1 * d; - out_shs[29] = s1 * d; - d = -20.409946485 * z; - out_grads[43][0] = c0 * d; - out_grads[29][0] = s0 * d; - out_grads[43][1] = s0 * d; - out_grads[29][1] = c0 * d; - d = 15.969982982 * z; - out_grads[42][2] = c0 * d; - out_grads[30][2] = s0 * d; - a = (z2 - 5.88235294e-02) * z; - b = a - 9.90712074e-02 * z; - d = -25.910241313 * b; - out_shs[62] = c1 * d; - out_shs[48] = s1 * d; - d = -181.371689194 * b; - out_grads[62][0] = c0 * d; - out_grads[48][0] = s0 * d; - out_grads[62][1] = s0 * d; - out_grads[48][1] = c0 * d; - d = 213.661323441 * b; - out_grads[61][2] = c0 * d; - out_grads[49][2] = s0 * d; - c0 = x * c1 - y * s1; - s0 = y * c1 + x * s1; - d = 0.72892666; - out_shs[44] = c0 * d; - out_shs[28] = s0 * d; - d = 5.831413281; - out_grads[44][0] = c1 * d; - out_grads[28][0] = s1 * d; - out_grads[44][1] = -s1 * d; - out_grads[28][1] = c1 * d; - d = -2.915706641; - out_grads[43][2] = c1 * d; - out_grads[29][2] = s1 * d; - a = z2 - 5.26315789e-02; - d = 10.577811722 * a; - out_shs[63] = c0 * d; - out_shs[47] = s0 * d; - d = 84.622493774 * a; - out_grads[63][0] = c1 * d; - out_grads[47][0] = s1 * d; - out_grads[63][1] = -s1 * d; - out_grads[47][1] = c1 * d; - d = -77.73072394 * a; - out_grads[62][2] = c1 * d; - out_grads[48][2] = s1 * d; - c1 = x * c0 - y * s0; - s1 = y * c0 + x * s0; - d = -3.4318953 * z; - out_shs[64] = c1 * d; - out_shs[46] = s1 * d; - d = -30.887057699 * z; - out_grads[64][0] = c0 * d; - out_grads[46][0] = s0 * d; - out_grads[64][1] = s0 * d; - out_grads[46][1] = c0 * d; - d = 21.155623443 * z; - out_grads[63][2] = c0 * d; - out_grads[47][2] = s0 * d; - c0 = x * c1 - y * s1; - s0 = y * c1 + x * s1; - d = 0.767395118; - out_shs[65] = c0 * d; - out_shs[45] = s0 * d; - d = 7.673951182; - out_grads[65][0] = c1 * d; - out_grads[45][0] = s1 * d; - out_grads[65][1] = -s1 * d; - out_grads[45][1] = c1 * d; - d = -3.4318953; - out_grads[64][2] = c1 * d; - out_grads[46][2] = s1 * d; - out_grads[0][0] = 0.0; - out_grads[0][1] = 0.0; - out_grads[0][2] = 0.0; - out_grads[1][2] = 0.0; - out_grads[3][0] = 0.0; - out_grads[3][1] = 0.0; - out_grads[5][2] = 0.0; - out_grads[6][2] = 0.0; - out_grads[10][0] = 0.0; - out_grads[10][1] = 0.0; - out_grads[14][2] = 0.0; - out_grads[15][2] = 0.0; - out_grads[21][0] = 0.0; - out_grads[21][1] = 0.0; - out_grads[27][2] = 0.0; - out_grads[28][2] = 0.0; - out_grads[36][0] = 0.0; - out_grads[36][1] = 0.0; - out_grads[44][2] = 0.0; - out_grads[45][2] = 0.0; - out_grads[55][0] = 0.0; - out_grads[55][1] = 0.0; - out_grads[65][2] = 0.0; -} diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_12 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_12 copy.frag deleted file mode 100644 index 35c2a3617..000000000 --- a/fury/shaders/rt_odfs/tournier/eval_sh_grad_12 copy.frag +++ /dev/null @@ -1,591 +0,0 @@ -void eval_sh_grad_12(out float out_shs[91], out vec3 out_grads[91], vec3 point) -{ - float x, y, z, z2, c0, s0, c1, s1, d, a, b; - x = point[0]; - y = point[1]; - z = point[2]; - z2 = z * z; - c0 = 1.0; - s0 = 0.0; - d = 0.282094792; - out_shs[0] = d; - a = z2 - 0.333333333; - d = 0.946174696 * a; - out_shs[3] = d; - b = z2 * (a - 0.266666667); - a = b - 0.257142857 * a; - d = 3.702494142 * a; - out_shs[10] = d; - b = z2 * a - 0.253968254 * b; - a = b - 0.252525253 * a; - d = 14.684485724 * a; - out_shs[21] = d; - b = z2 * a - 0.251748252 * b; - a = b - 0.251282051 * a; - d = 58.473368113 * a; - out_shs[36] = d; - b = z2 * a - 0.250980392 * b; - a = b - 0.250773994 * a; - d = 233.240148813 * a; - out_shs[55] = d; - b = z2 * a - 0.250626566 * b; - a = b - 0.250517598 * a; - d = 931.186918633 * a; - out_shs[78] = d; - c1 = x; - s1 = y; - d = -1.092548431 * z; - out_shs[4] = c1 * d; - out_shs[2] = s1 * d; - out_grads[4][0] = c0 * d; - out_grads[2][0] = s0 * d; - out_grads[4][1] = s0 * d; - out_grads[2][1] = c0 * d; - d = 1.892349392 * z; - out_grads[3][2] = d; - a = (z2 - 0.2) * z; - b = a - 0.228571429 * z; - d = -4.683325805 * b; - out_shs[11] = c1 * d; - out_shs[9] = s1 * d; - out_grads[11][0] = c0 * d; - out_grads[9][0] = s0 * d; - out_grads[11][1] = s0 * d; - out_grads[9][1] = c0 * d; - d = 14.809976568 * b; - out_grads[10][2] = d; - a = z2 * b - 0.238095238 * a; - b = a - 0.242424242 * b; - d = -19.226504963 * b; - out_shs[22] = c1 * d; - out_shs[20] = s1 * d; - out_grads[22][0] = c0 * d; - out_grads[20][0] = s0 * d; - out_grads[22][1] = s0 * d; - out_grads[20][1] = c0 * d; - d = 88.106914343 * b; - out_grads[21][2] = d; - a = z2 * b - 0.244755245 * a; - b = a - 0.246153846 * b; - d = -77.964490818 * b; - out_shs[37] = c1 * d; - out_shs[35] = s1 * d; - out_grads[37][0] = c0 * d; - out_grads[35][0] = s0 * d; - out_grads[37][1] = s0 * d; - out_grads[35][1] = c0 * d; - d = 467.786944906 * b; - out_grads[36][2] = d; - a = z2 * b - 0.247058824 * a; - b = a - 0.247678019 * b; - d = -314.500952502 * b; - out_shs[56] = c1 * d; - out_shs[54] = s1 * d; - out_grads[56][0] = c0 * d; - out_grads[54][0] = s0 * d; - out_grads[56][1] = s0 * d; - out_grads[54][1] = c0 * d; - d = 2332.401488133 * b; - out_grads[55][2] = d; - a = z2 * b - 0.248120301 * a; - b = a - 0.248447205 * b; - d = -1265.233874957 * b; - out_shs[79] = c1 * d; - out_shs[77] = s1 * d; - out_grads[79][0] = c0 * d; - out_grads[77][0] = s0 * d; - out_grads[79][1] = s0 * d; - out_grads[77][1] = c0 * d; - d = 11174.243023595 * b; - out_grads[78][2] = d; - c0 = x * c1 - y * s1; - s0 = y * c1 + x * s1; - d = 0.546274215; - out_shs[5] = c0 * d; - out_shs[1] = s0 * d; - d = 1.092548431; - out_grads[5][0] = c1 * d; - out_grads[1][0] = s1 * d; - out_grads[5][1] = -s1 * d; - out_grads[1][1] = c1 * d; - d = -1.092548431; - out_grads[4][2] = c1 * d; - out_grads[2][2] = s1 * d; - a = z2 - 0.142857143; - d = 3.311611435 * a; - out_shs[12] = c0 * d; - out_shs[8] = s0 * d; - d = 6.62322287 * a; - out_grads[12][0] = c1 * d; - out_grads[8][0] = s1 * d; - out_grads[12][1] = -s1 * d; - out_grads[8][1] = c1 * d; - d = -14.049977415 * a; - out_grads[11][2] = c1 * d; - out_grads[9][2] = s1 * d; - b = z2 * (a - 0.19047619); - a = b - 0.212121212 * a; - d = 15.199886782 * a; - out_shs[23] = c0 * d; - out_shs[19] = s0 * d; - d = 30.399773564 * a; - out_grads[23][0] = c1 * d; - out_grads[19][0] = s1 * d; - out_grads[23][1] = -s1 * d; - out_grads[19][1] = c1 * d; - d = -96.132524816 * a; - out_grads[22][2] = c1 * d; - out_grads[20][2] = s1 * d; - b = z2 * a - 0.223776224 * b; - a = b - 0.230769231 * a; - d = 65.229772956 * a; - out_shs[38] = c0 * d; - out_shs[34] = s0 * d; - d = 130.459545912 * a; - out_grads[38][0] = c1 * d; - out_grads[34][0] = s1 * d; - out_grads[38][1] = -s1 * d; - out_grads[34][1] = c1 * d; - d = -545.751435723 * a; - out_grads[37][2] = c1 * d; - out_grads[35][2] = s1 * d; - b = z2 * a - 0.235294118 * b; - a = b - 0.238390093 * a; - d = 272.365814381 * a; - out_shs[57] = c0 * d; - out_shs[53] = s0 * d; - d = 544.731628762 * a; - out_grads[57][0] = c1 * d; - out_grads[53][0] = s1 * d; - out_grads[57][1] = -s1 * d; - out_grads[53][1] = c1 * d; - d = -2830.508572514 * a; - out_grads[56][2] = c1 * d; - out_grads[54][2] = s1 * d; - b = z2 * a - 0.240601504 * b; - a = b - 0.242236025 * a; - d = 1121.509962433 * a; - out_shs[80] = c0 * d; - out_shs[76] = s0 * d; - d = 2243.019924866 * a; - out_grads[80][0] = c1 * d; - out_grads[76][0] = s1 * d; - out_grads[80][1] = -s1 * d; - out_grads[76][1] = c1 * d; - d = -13917.572624524 * a; - out_grads[79][2] = c1 * d; - out_grads[77][2] = s1 * d; - c1 = x * c0 - y * s0; - s1 = y * c0 + x * s0; - d = -1.77013077 * z; - out_shs[13] = c1 * d; - out_shs[7] = s1 * d; - d = -5.310392309 * z; - out_grads[13][0] = c0 * d; - out_grads[7][0] = s0 * d; - out_grads[13][1] = s0 * d; - out_grads[7][1] = c0 * d; - d = 6.62322287 * z; - out_grads[12][2] = c0 * d; - out_grads[8][2] = s0 * d; - a = (z2 - 0.111111111) * z; - b = a - 0.161616162 * z; - d = -10.133257855 * b; - out_shs[24] = c1 * d; - out_shs[18] = s1 * d; - d = -30.399773564 * b; - out_grads[24][0] = c0 * d; - out_grads[18][0] = s0 * d; - out_grads[24][1] = s0 * d; - out_grads[18][1] = c0 * d; - d = 60.799547128 * b; - out_grads[23][2] = c0 * d; - out_grads[19][2] = s0 * d; - a = z2 * b - 0.188811189 * a; - b = a - 0.205128205 * b; - d = -48.175380057 * b; - out_shs[39] = c1 * d; - out_shs[33] = s1 * d; - d = -144.52614017 * b; - out_grads[39][0] = c0 * d; - out_grads[33][0] = s0 * d; - out_grads[39][1] = s0 * d; - out_grads[33][1] = c0 * d; - d = 391.378637737 * b; - out_grads[38][2] = c0 * d; - out_grads[34][2] = s0 * d; - a = z2 * b - 0.215686275 * a; - b = a - 0.222910217 * b; - d = -213.661323441 * b; - out_shs[58] = c1 * d; - out_shs[52] = s1 * d; - d = -640.983970322 * b; - out_grads[58][0] = c0 * d; - out_grads[52][0] = s0 * d; - out_grads[58][1] = s0 * d; - out_grads[52][1] = c0 * d; - d = 2178.926515046 * b; - out_grads[57][2] = c0 * d; - out_grads[53][2] = s0 * d; - a = z2 * b - 0.228070175 * a; - b = a - 0.231884058 * b; - d = -915.709049803 * b; - out_shs[81] = c1 * d; - out_shs[75] = s1 * d; - d = -2747.127149409 * b; - out_grads[81][0] = c0 * d; - out_grads[75][0] = s0 * d; - out_grads[81][1] = s0 * d; - out_grads[75][1] = c0 * d; - d = 11215.099624332 * b; - out_grads[80][2] = c0 * d; - out_grads[76][2] = s0 * d; - c0 = x * c1 - y * s1; - s0 = y * c1 + x * s1; - d = 0.625835735; - out_shs[14] = c0 * d; - out_shs[6] = s0 * d; - d = 2.503342942; - out_grads[14][0] = c1 * d; - out_grads[6][0] = s1 * d; - out_grads[14][1] = -s1 * d; - out_grads[6][1] = c1 * d; - d = -1.77013077; - out_grads[13][2] = c1 * d; - out_grads[7][2] = s1 * d; - a = z2 - 9.09090909e-02; - d = 5.550213908 * a; - out_shs[25] = c0 * d; - out_shs[17] = s0 * d; - d = 22.200855632 * a; - out_grads[25][0] = c1 * d; - out_grads[17][0] = s1 * d; - out_grads[25][1] = -s1 * d; - out_grads[17][1] = c1 * d; - d = -30.399773564 * a; - out_grads[24][2] = c1 * d; - out_grads[18][2] = s1 * d; - b = z2 * (a - 0.13986014); - a = b - 0.169230769 * a; - d = 31.097074109 * a; - out_shs[40] = c0 * d; - out_shs[32] = s0 * d; - d = 124.388296437 * a; - out_grads[40][0] = c1 * d; - out_grads[32][0] = s1 * d; - out_grads[40][1] = -s1 * d; - out_grads[32][1] = c1 * d; - d = -240.876900283 * a; - out_grads[39][2] = c1 * d; - out_grads[33][2] = s1 * d; - b = z2 * a - 0.188235294 * b; - a = b - 0.20123839 * a; - d = 151.081370682 * a; - out_shs[59] = c0 * d; - out_shs[51] = s0 * d; - d = 604.325482728 * a; - out_grads[59][0] = c1 * d; - out_grads[51][0] = s1 * d; - out_grads[59][1] = -s1 * d; - out_grads[51][1] = c1 * d; - d = -1495.629264084 * a; - out_grads[58][2] = c1 * d; - out_grads[52][2] = s1 * d; - b = z2 * a - 0.210526316 * b; - a = b - 0.217391304 * a; - d = 686.781787352 * a; - out_shs[82] = c0 * d; - out_shs[74] = s0 * d; - d = 2747.127149409 * a; - out_grads[82][0] = c1 * d; - out_grads[74][0] = s1 * d; - out_grads[82][1] = -s1 * d; - out_grads[74][1] = c1 * d; - d = -8241.381448228 * a; - out_grads[81][2] = -c1 * d; - out_grads[75][2] = s1 * d; - c1 = x * c0 - y * s0; - s1 = y * c0 + x * s0; - d = -2.366619162 * z; - out_shs[26] = c1 * d; - out_shs[16] = s1 * d; - d = -11.833095811 * z; - out_grads[26][0] = c0 * d; - out_grads[16][0] = s0 * d; - out_grads[26][1] = s0 * d; - out_grads[16][1] = c0 * d; - d = 11.100427816 * z; - out_grads[25][2] = c0 * d; - out_grads[17][2] = s0 * d; - a = (z2 - 7.69230769e-02) * z; - b = a - 0.123076923 * z; - d = -17.24955311 * b; - out_shs[41] = c1 * d; - out_shs[31] = s1 * d; - d = -86.247765552 * b; - out_grads[41][0] = c0 * d; - out_grads[31][0] = s0 * d; - out_grads[41][1] = s0 * d; - out_grads[31][1] = c0 * d; - d = 124.388296437 * b; - out_grads[40][2] = c0 * d; - out_grads[32][2] = s0 * d; - a = z2 * b - 0.152941176 * a; - b = a - 0.173374613 * b; - d = -95.552248675 * b; - out_shs[60] = c1 * d; - out_shs[50] = s1 * d; - d = -477.761243376 * b; - out_grads[60][0] = c0 * d; - out_grads[50][0] = s0 * d; - out_grads[60][1] = s0 * d; - out_grads[50][1] = c0 * d; - d = 906.488224092 * b; - out_grads[59][2] = c0 * d; - out_grads[51][2] = s0 * d; - a = z2 * b - 0.187969925 * a; - b = a - 0.198757764 * b; - d = -471.12841933 * b; - out_shs[83] = c1 * d; - out_shs[73] = s1 * d; - d = -2355.642096651 * b; - out_grads[83][0] = c0 * d; - out_grads[73][0] = s0 * d; - out_grads[83][1] = s0 * d; - out_grads[73][1] = c0 * d; - d = 5494.254298819 * b; - out_grads[82][2] = c0 * d; - out_grads[74][2] = s0 * d; - c0 = x * c1 - y * s1; - s0 = y * c1 + x * s1; - d = 0.683184105; - out_shs[27] = c0 * d; - out_shs[15] = s0 * d; - d = 4.099104631; - out_grads[27][0] = c1 * d; - out_grads[15][0] = s1 * d; - out_grads[27][1] = -s1 * d; - out_grads[15][1] = c1 * d; - d = -2.366619162; - out_grads[26][2] = c1 * d; - out_grads[16][2] = s1 * d; - a = z2 - 6.66666667e-02; - d = 7.984991491 * a; - out_shs[42] = c0 * d; - out_shs[30] = s0 * d; - d = 47.909948945 * a; - out_grads[42][0] = c1 * d; - out_grads[30][0] = s1 * d; - out_grads[42][1] = -s1 * d; - out_grads[30][1] = c1 * d; - d = -51.748659331 * a; - out_grads[41][2] = c1 * d; - out_grads[31][2] = s1 * d; - b = z2 * (a - 0.109803922); - a = b - 0.139318885 * a; - d = 53.41533086 * a; - out_shs[61] = c0 * d; - out_shs[49] = s0 * d; - d = 320.491985161 * a; - out_grads[61][0] = c1 * d; - out_grads[49][0] = s1 * d; - out_grads[61][1] = -s1 * d; - out_grads[49][1] = c1 * d; - d = -477.761243376 * a; - out_grads[60][2] = c1 * d; - out_grads[50][2] = s1 * d; - b = z2 * a - 0.160401003 * b; - a = b - 0.175983437 * a; - d = 293.800188384 * a; - out_shs[84] = c0 * d; - out_shs[72] = s0 * d; - d = 1762.801130306 * a; - out_grads[84][0] = c1 * d; - out_grads[72][0] = s1 * d; - out_grads[84][1] = -s1 * d; - out_grads[72][1] = c1 * d; - d = -3297.898935312 * a; - out_grads[83][2] = c1 * d; - out_grads[73][2] = s1 * d; - c1 = x * c0 - y * s0; - s1 = y * c0 + x * s0; - d = -2.915706641 * z; - out_shs[43] = c1 * d; - out_shs[29] = s1 * d; - d = -20.409946485 * z; - out_grads[43][0] = c0 * d; - out_grads[29][0] = s0 * d; - out_grads[43][1] = s0 * d; - out_grads[29][1] = c0 * d; - d = 15.969982982 * z; - out_grads[42][2] = c0 * d; - out_grads[30][2] = s0 * d; - a = (z2 - 5.88235294e-02) * z; - b = a - 9.90712074e-02 * z; - d = -25.910241313 * b; - out_shs[62] = c1 * d; - out_shs[48] = s1 * d; - d = -181.371689194 * b; - out_grads[62][0] = c0 * d; - out_grads[48][0] = s0 * d; - out_grads[62][1] = s0 * d; - out_grads[48][1] = c0 * d; - d = 213.661323441 * b; - out_grads[61][2] = c0 * d; - out_grads[49][2] = s0 * d; - a = z2 * b - 0.127819549 * a; - b = a - 0.149068323 * b; - d = -165.101452729 * b; - out_shs[85] = c1 * d; - out_shs[71] = s1 * d; - d = -1155.7101691 * b; - out_grads[85][0] = c0 * d; - out_grads[71][0] = s0 * d; - out_grads[85][1] = s0 * d; - out_grads[71][1] = c0 * d; - d = 1762.801130306 * b; - out_grads[84][2] = c0 * d; - out_grads[72][2] = s0 * d; - c0 = x * c1 - y * s1; - s0 = y * c1 + x * s1; - d = 0.72892666; - out_shs[44] = c0 * d; - out_shs[28] = s0 * d; - d = 5.831413281; - out_grads[44][0] = c1 * d; - out_grads[28][0] = s1 * d; - out_grads[44][1] = -s1 * d; - out_grads[28][1] = c1 * d; - d = -2.915706641; - out_grads[43][2] = c1 * d; - out_grads[29][2] = s1 * d; - a = z2 - 5.26315789e-02; - d = 10.577811722 * a; - out_shs[63] = c0 * d; - out_shs[47] = s0 * d; - d = 84.622493774 * a; - out_grads[63][0] = c1 * d; - out_grads[47][0] = s1 * d; - out_grads[63][1] = -s1 * d; - out_grads[47][1] = c1 * d; - d = -77.73072394 * a; - out_grads[62][2] = c1 * d; - out_grads[48][2] = s1 * d; - b = z2 * (a - 9.02255639e-02); - a = b - 0.118012422 * a; - d = 82.550726364 * a; - out_shs[86] = c0 * d; - out_shs[70] = s0 * d; - d = 660.405810914 * a; - out_grads[86][0] = c1 * d; - out_grads[70][0] = s1 * d; - out_grads[86][1] = -s1 * d; - out_grads[70][1] = c1 * d; - d = -825.507263643 * a; - out_grads[85][2] = c1 * d; - out_grads[71][2] = s1 * d; - c1 = x * c0 - y * s0; - s1 = y * c0 + x * s0; - d = -3.4318953 * z; - out_shs[64] = c1 * d; - out_shs[46] = s1 * d; - d = -30.887057699 * z; - out_grads[64][0] = c0 * d; - out_grads[46][0] = s0 * d; - out_grads[64][1] = s0 * d; - out_grads[46][1] = c0 * d; - d = 21.155623443 * z; - out_grads[63][2] = c0 * d; - out_grads[47][2] = s0 * d; - a = (z2 - 4.76190476e-02) * z; - b = a - 8.2815735e-02 * z; - d = -36.028090689 * b; - out_shs[87] = c1 * d; - out_shs[69] = s1 * d; - d = -324.252816204 * b; - out_grads[87][0] = c0 * d; - out_grads[69][0] = s0 * d; - out_grads[87][1] = s0 * d; - out_grads[69][1] = c0 * d; - d = 330.202905457 * b; - out_grads[86][2] = c0 * d; - out_grads[70][2] = s0 * d; - c0 = x * c1 - y * s1; - s0 = y * c1 + x * s1; - d = 0.767395118; - out_shs[65] = c0 * d; - out_shs[45] = s0 * d; - d = 7.673951182; - out_grads[65][0] = c1 * d; - out_grads[45][0] = s1 * d; - out_grads[65][1] = -s1 * d; - out_grads[45][1] = c1 * d; - d = -3.4318953; - out_grads[64][2] = c1 * d; - out_grads[46][2] = s1 * d; - a = z2 - 4.34782609e-02; - d = 13.3042542 * a; - out_shs[88] = c0 * d; - out_shs[68] = s0 * d; - d = 133.042542003 * a; - out_grads[88][0] = c1 * d; - out_grads[68][0] = s1 * d; - out_grads[88][1] = -s1 * d; - out_grads[68][1] = c1 * d; - d = -108.084272068 * a; - out_grads[87][2] = c1 * d; - out_grads[69][2] = s1 * d; - c1 = x * c0 - y * s0; - s1 = y * c0 + x * s0; - d = -3.923210529 * z; - out_shs[89] = c1 * d; - out_shs[67] = s1 * d; - d = -43.155315818 * z; - out_grads[89][0] = c0 * d; - out_grads[67][0] = s0 * d; - out_grads[89][1] = s0 * d; - out_grads[67][1] = c0 * d; - d = 26.608508401 * z; - out_grads[88][2] = c0 * d; - out_grads[68][2] = s0 * d; - c0 = x * c1 - y * s1; - s0 = y * c1 + x * s1; - d = 0.800821996; - out_shs[90] = c0 * d; - out_shs[66] = s0 * d; - d = 9.609863949; - out_grads[90][0] = c1 * d; - out_grads[66][0] = s1 * d; - out_grads[90][1] = -s1 * d; - out_grads[66][1] = c1 * d; - d = -3.923210529; - out_grads[89][2] = c1 * d; - out_grads[67][2] = s1 * d; - out_grads[0][0] = 0.0; - out_grads[0][1] = 0.0; - out_grads[0][2] = 0.0; - out_grads[1][2] = 0.0; - out_grads[3][0] = 0.0; - out_grads[3][1] = 0.0; - out_grads[5][2] = 0.0; - out_grads[6][2] = 0.0; - out_grads[10][0] = 0.0; - out_grads[10][1] = 0.0; - out_grads[14][2] = 0.0; - out_grads[15][2] = 0.0; - out_grads[21][0] = 0.0; - out_grads[21][1] = 0.0; - out_grads[27][2] = 0.0; - out_grads[28][2] = 0.0; - out_grads[36][0] = 0.0; - out_grads[36][1] = 0.0; - out_grads[44][2] = 0.0; - out_grads[45][2] = 0.0; - out_grads[55][0] = 0.0; - out_grads[55][1] = 0.0; - out_grads[65][2] = 0.0; - out_grads[66][2] = 0.0; - out_grads[78][0] = 0.0; - out_grads[78][1] = 0.0; - out_grads[90][2] = 0.0; -} diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_2 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_2 copy.frag deleted file mode 100644 index 277a0e07a..000000000 --- a/fury/shaders/rt_odfs/tournier/eval_sh_grad_2 copy.frag +++ /dev/null @@ -1,46 +0,0 @@ -void eval_sh_grad_2(out float out_shs[6], out vec3 out_grads[6], vec3 point) -{ - float x, y, z, z2, c0, s0, c1, s1, d, a; - x = point[0]; - y = point[1]; - z = point[2]; - z2 = z * z; - c0 = 1.0; - s0 = 0.0; - d = 0.282094792; - out_shs[0] = d; - a = z2 - 0.333333333; - d = 0.946174696 * a; - out_shs[3] = d; - c1 = x; - s1 = y; - d = -1.092548431 * z; - out_shs[4] = c1 * d; - out_shs[2] = s1 * d; - out_grads[4][0] = c0 * d; - out_grads[2][0] = s0 * d; - out_grads[4][1] = s0 * d; - out_grads[2][1] = c0 * d; - d = 1.892349392 * z; - out_grads[3][2] = d; - c0 = x * c1 - y * s1; - s0 = y * c1 + x * s1; - d = 0.546274215; - out_shs[5] = c0 * d; - out_shs[1] = s0 * d; - d = 1.092548431; - out_grads[1][0] = c1 * d; - out_grads[5][0] = s1 * d; - out_grads[5][1] = -s1 * d; - out_grads[1][1] = c1 * d; - d = -1.092548431; - out_grads[4][2] = c1 * d; - out_grads[2][2] = s1 * d; - out_grads[0][0] = 0.0; - out_grads[0][1] = 0.0; - out_grads[0][2] = 0.0; - out_grads[5][2] = 0.0; - out_grads[3][0] = 0.0; - out_grads[3][1] = 0.0; - out_grads[1][2] = 0.0; -} diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_4 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_4 copy.frag deleted file mode 100644 index c85847a5b..000000000 --- a/fury/shaders/rt_odfs/tournier/eval_sh_grad_4 copy.frag +++ /dev/null @@ -1,103 +0,0 @@ -void eval_sh_grad_4(out float out_shs[15], out vec3 out_grads[15], vec3 point) -{ - float x, y, z, z2, c0, s0, c1, s1, d, a, b; - x = point[0]; - y = point[1]; - z = point[2]; - z2 = z * z; - c0 = 1.0; - s0 = 0.0; - d = 0.282094792; - out_shs[0] = d; - a = z2 - 0.333333333; - d = 0.946174696 * a; - out_shs[3] = d; - b = z2 * (a - 0.266666667); - a = b - 0.257142857 * a; - d = 3.702494142 * a; - out_shs[10] = d; - c1 = x; - s1 = y; - d = -1.092548431 * z; - out_shs[4] = c1 * d; - out_shs[2] = s1 * d; - out_grads[4][0] = c0 * d; - out_grads[2][0] = s0 * d; - out_grads[4][1] = s0 * d; - out_grads[2][1] = c0 * d; - d = 1.892349392 * z; - out_grads[3][2] = d; - a = (z2 - 0.2) * z; - b = a - 0.228571429 * z; - d = -4.683325805 * b; - out_shs[11] = c1 * d; - out_shs[9] = s1 * d; - out_grads[11][0] = c0 * d; - out_grads[9][0] = s0 * d; - out_grads[11][1] = s0 * d; - out_grads[9][1] = c0 * d; - d = 14.809976568 * b; - out_grads[10][2] = d; - c0 = x * c1 - y * s1; - s0 = y * c1 + x * s1; - d = 0.546274215; - out_shs[5] = c0 * d; - out_shs[1] = s0 * d; - d = 1.092548431; - out_grads[5][0] = c1 * d; - out_grads[1][0] = s1 * d; - out_grads[5][1] = -s1 * d; - out_grads[1][1] = c1 * d; - d = -1.092548431; - out_grads[4][2] = c1 * d; - out_grads[2][2] = s1 * d; - a = z2 - 0.142857143; - d = 3.311611435 * a; - out_shs[12] = c0 * d; - out_shs[8] = s0 * d; - d = 6.62322287 * a; - out_grads[12][0] = c1 * d; - out_grads[8][0] = s1 * d; - out_grads[12][1] = -s1 * d; - out_grads[8][1] = c1 * d; - d = -14.049977415 * a; - out_grads[11][2] = c1 * d; - out_grads[9][2] = s1 * d; - c1 = x * c0 - y * s0; - s1 = y * c0 + x * s0; - d = -1.77013077 * z; - out_shs[13] = c1 * d; - out_shs[7] = s1 * d; - d = -5.310392309 * z; - out_grads[13][0] = c0 * d; - out_grads[7][0] = s0 * d; - out_grads[13][1] = s0 * d; - out_grads[7][1] = c0 * d; - d = 6.62322287 * z; - out_grads[12][2] = c0 * d; - out_grads[8][2] = s0 * d; - c0 = x * c1 - y * s1; - s0 = y * c1 + x * s1; - d = 0.625835735; - out_shs[14] = c0 * d; - out_shs[6] = s0 * d; - d = 2.503342942; - out_grads[14][0] = c1 * d; - out_grads[6][0] = s1 * d; - out_grads[14][1] = -s1 * d; - out_grads[6][1] = c1 * d; - d = -1.77013077; - out_grads[13][2] = c1 * d; - out_grads[7][2] = s1 * d; - out_grads[0][0] = 0.0; - out_grads[0][1] = 0.0; - out_grads[0][2] = 0.0; - out_grads[5][2] = 0.0; - out_grads[3][0] = 0.0; - out_grads[3][1] = 0.0; - out_grads[1][2] = 0.0; - out_grads[14][2] = 0.0; - out_grads[10][0] = 0.0; - out_grads[10][1] = 0.0; - out_grads[6][2] = 0.0; -} diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_6 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_6 copy.frag deleted file mode 100644 index 617413bc9..000000000 --- a/fury/shaders/rt_odfs/tournier/eval_sh_grad_6 copy.frag +++ /dev/null @@ -1,186 +0,0 @@ -void eval_sh_grad_6(out float out_shs[28], out vec3 out_grads[28], vec3 point) -{ - float x, y, z, z2, c0, s0, c1, s1, d, a, b; - x = point[0]; - y = point[1]; - z = point[2]; - z2 = z * z; - c0 = 1.0; - s0 = 0.0; - d = 0.282094792; - out_shs[0] = d; - a = z2 - 0.333333333; - d = 0.946174696 * a; - out_shs[3] = d; - b = z2 * (a - 0.266666667); - a = b - 0.257142857 * a; - d = 3.702494142 * a; - out_shs[10] = d; - b = z2 * a - 0.253968254 * b; - a = b - 0.252525253 * a; - d = 14.684485724 * a; - out_shs[21] = d; - c1 = x; - s1 = y; - d = -1.092548431 * z; - out_shs[4] = c1 * d; - out_shs[2] = s1 * d; - out_grads[4][0] = c0 * d; - out_grads[2][0] = s0 * d; - out_grads[4][1] = s0 * d; - out_grads[2][1] = c0 * d; - d = 1.892349392 * z; - out_grads[3][2] = d; - a = (z2 - 0.2) * z; - b = a - 0.228571429 * z; - d = -4.683325805 * b; - out_shs[11] = c1 * d; - out_shs[9] = s1 * d; - out_grads[11][0] = c0 * d; - out_grads[9][0] = s0 * d; - out_grads[11][1] = s0 * d; - out_grads[9][1] = c0 * d; - d = 14.809976568 * b; - out_grads[10][2] = d; - a = z2 * b - 0.238095238 * a; - b = a - 0.242424242 * b; - d = -19.226504963 * b; - out_shs[22] = c1 * d; - out_shs[20] = s1 * d; - out_grads[22][0] = c0 * d; - out_grads[20][0] = s0 * d; - out_grads[22][1] = s0 * d; - out_grads[20][1] = c0 * d; - d = 88.106914343 * b; - out_grads[21][2] = d; - c0 = x * c1 - y * s1; - s0 = y * c1 + x * s1; - d = 0.546274215; - out_shs[5] = c0 * d; - out_shs[1] = s0 * d; - d = 1.092548431; - out_grads[5][0] = c1 * d; - out_grads[1][0] = s1 * d; - out_grads[5][1] = -s1 * d; - out_grads[1][1] = c1 * d; - d = -1.092548431; - out_grads[4][2] = c1 * d; - out_grads[2][2] = s1 * d; - a = z2 - 0.142857143; - d = 3.311611435 * a; - out_shs[12] = c0 * d; - out_shs[8] = s0 * d; - d = 6.62322287 * a; - out_grads[12][0] = c1 * d; - out_grads[8][0] = s1 * d; - out_grads[12][1] = -s1 * d; - out_grads[8][1] = c1 * d; - d = -14.049977415 * a; - out_grads[11][2] = c1 * d; - out_grads[9][2] = s1 * d; - b = z2 * (a - 0.19047619); - a = b - 0.212121212 * a; - d = 15.199886782 * a; - out_shs[23] = c0 * d; - out_shs[19] = s0 * d; - d = 30.399773564 * a; - out_grads[23][0] = c1 * d; - out_grads[19][0] = s1 * d; - out_grads[23][1] = -s1 * d; - out_grads[19][1] = c1 * d; - d = -96.132524816 * a; - out_grads[22][2] = c1 * d; - out_grads[20][2] = s1 * d; - c1 = x * c0 - y * s0; - s1 = y * c0 + x * s0; - d = -1.77013077 * z; - out_shs[13] = c1 * d; - out_shs[7] = s1 * d; - d = -5.310392309 * z; - out_grads[13][0] = c0 * d; - out_grads[7][0] = s0 * d; - out_grads[13][1] = s0 * d; - out_grads[7][1] = c0 * d; - d = 6.62322287 * z; - out_grads[12][2] = c0 * d; - out_grads[8][2] = s0 * d; - a = (z2 - 0.111111111) * z; - b = a - 0.161616162 * z; - d = -10.133257855 * b; - out_shs[24] = c1 * d; - out_shs[18] = s1 * d; - d = -30.399773564 * b; - out_grads[24][0] = c0 * d; - out_grads[18][0] = s0 * d; - out_grads[24][1] = s0 * d; - out_grads[18][1] = c0 * d; - d = 60.799547128 * b; - out_grads[23][2] = c0 * d; - out_grads[19][2] = s0 * d; - c0 = x * c1 - y * s1; - s0 = y * c1 + x * s1; - d = 0.625835735; - out_shs[14] = c0 * d; - out_shs[6] = s0 * d; - d = 2.503342942; - out_grads[14][0] = c1 * d; - out_grads[6][0] = s1 * d; - out_grads[14][1] = -s1 * d; - out_grads[6][1] = c1 * d; - d = -1.77013077; - out_grads[13][2] = c1 * d; - out_grads[7][2] = s1 * d; - a = z2 - 9.09090909e-02; - d = 5.550213908 * a; - out_shs[25] = c0 * d; - out_shs[17] = s0 * d; - d = 22.200855632 * a; - out_grads[25][0] = c1 * d; - out_grads[17][0] = s1 * d; - out_grads[25][1] = -s1 * d; - out_grads[17][1] = c1 * d; - d = -30.399773564 * a; - out_grads[24][2] = c1 * d; - out_grads[18][2] = s1 * d; - c1 = x * c0 - y * s0; - s1 = y * c0 + x * s0; - d = -2.366619162 * z; - out_shs[26] = c1 * d; - out_shs[16] = s1 * d; - d = -11.833095811 * z; - out_grads[26][0] = c0 * d; - out_grads[16][0] = s0 * d; - out_grads[26][1] = s0 * d; - out_grads[16][1] = c0 * d; - d = 11.100427816 * z; - out_grads[25][2] = c0 * d; - out_grads[17][2] = s0 * d; - c0 = x * c1 - y * s1; - s0 = y * c1 + x * s1; - d = 0.683184105; - out_shs[27] = c0 * d; - out_shs[15] = s0 * d; - d = 4.099104631; - out_grads[27][0] = c1 * d; - out_grads[15][0] = s1 * d; - out_grads[27][1] = -s1 * d; - out_grads[15][1] = c1 * d; - d = -2.366619162; - out_grads[26][2] = c1 * d; - out_grads[16][2] = s1 * d; - out_grads[0][0] = 0.0; - out_grads[0][1] = 0.0; - out_grads[0][2] = 0.0; - out_grads[5][2] = 0.0; - out_grads[3][0] = 0.0; - out_grads[3][1] = 0.0; - out_grads[1][2] = 0.0; - out_grads[14][2] = 0.0; - out_grads[10][0] = 0.0; - out_grads[10][1] = 0.0; - out_grads[6][2] = 0.0; - out_grads[27][2] = 0.0; - out_grads[21][0] = 0.0; - out_grads[21][1] = 0.0; - out_grads[15][2] = 0.0; -} diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_8 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_8 copy.frag deleted file mode 100644 index 712b2dc29..000000000 --- a/fury/shaders/rt_odfs/tournier/eval_sh_grad_8 copy.frag +++ /dev/null @@ -1,295 +0,0 @@ -void eval_sh_grad_8(out float out_shs[45], out vec3 out_grads[45], vec3 point) -{ - float x, y, z, z2, c0, s0, c1, s1, d, a, b; - x = point[0]; - y = point[1]; - z = point[2]; - z2 = z * z; - c0 = 1.0; - s0 = 0.0; - d = 0.282094792; - out_shs[0] = d; - a = z2 - 0.333333333; - d = 0.946174696 * a; - out_shs[3] = d; - b = z2 * (a - 0.266666667); - a = b - 0.257142857 * a; - d = 3.702494142 * a; - out_shs[10] = d; - b = z2 * a - 0.253968254 * b; - a = b - 0.252525253 * a; - d = 14.684485724 * a; - out_shs[21] = d; - b = z2 * a - 0.251748252 * b; - a = b - 0.251282051 * a; - d = 58.473368113 * a; - out_shs[36] = d; - c1 = x; - s1 = y; - d = -1.092548431 * z; - out_shs[4] = c1 * d; - out_shs[2] = s1 * d; - out_grads[4][0] = c0 * d; - out_grads[2][0] = s0 * d; - out_grads[4][1] = s0 * d; - out_grads[2][1] = c0 * d; - d = 1.892349392 * z; - out_grads[3][2] = d; - a = (z2 - 0.2) * z; - b = a - 0.228571429 * z; - d = -4.683325805 * b; - out_shs[11] = c1 * d; - out_shs[9] = s1 * d; - out_grads[11][0] = c0 * d; - out_grads[9][0] = s0 * d; - out_grads[11][1] = s0 * d; - out_grads[9][1] = c0 * d; - d = 14.809976568 * b; - out_grads[10][2] = d; - a = z2 * b - 0.238095238 * a; - b = a - 0.242424242 * b; - d = -19.226504963 * b; - out_shs[22] = c1 * d; - out_shs[20] = s1 * d; - out_grads[22][0] = c0 * d; - out_grads[20][0] = s0 * d; - out_grads[22][1] = s0 * d; - out_grads[20][1] = c0 * d; - d = 88.106914343 * b; - out_grads[21][2] = d; - a = z2 * b - 0.244755245 * a; - b = a - 0.246153846 * b; - d = -77.964490818 * b; - out_shs[37] = c1 * d; - out_shs[35] = s1 * d; - out_grads[37][0] = c0 * d; - out_grads[35][0] = s0 * d; - out_grads[37][1] = s0 * d; - out_grads[35][1] = c0 * d; - d = 467.786944906 * b; - out_grads[36][2] = d; - c0 = x * c1 - y * s1; - s0 = y * c1 + x * s1; - d = 0.546274215; - out_shs[5] = c0 * d; - out_shs[1] = s0 * d; - d = 1.092548431; - out_grads[5][0] = c1 * d; - out_grads[1][0] = s1 * d; - out_grads[5][1] = -s1 * d; - out_grads[1][1] = c1 * d; - d = -1.092548431; - out_grads[4][2] = c1 * d; - out_grads[2][2] = s1 * d; - a = z2 - 0.142857143; - d = 3.311611435 * a; - out_shs[12] = c0 * d; - out_shs[8] = s0 * d; - d = 6.62322287 * a; - out_grads[12][0] = c1 * d; - out_grads[8][0] = s1 * d; - out_grads[12][1] = -s1 * d; - out_grads[8][1] = c1 * d; - d = -14.049977415 * a; - out_grads[11][2] = c1 * d; - out_grads[9][2] = s1 * d; - b = z2 * (a - 0.19047619); - a = b - 0.212121212 * a; - d = 15.199886782 * a; - out_shs[23] = c0 * d; - out_shs[19] = s0 * d; - d = 30.399773564 * a; - out_grads[23][0] = c1 * d; - out_grads[19][0] = s1 * d; - out_grads[23][1] = -s1 * d; - out_grads[19][1] = c1 * d; - d = -96.132524816 * a; - out_grads[22][2] = c1 * d; - out_grads[20][2] = s1 * d; - b = z2 * a - 0.223776224 * b; - a = b - 0.230769231 * a; - d = 65.229772956 * a; - out_shs[38] = c0 * d; - out_shs[34] = s0 * d; - d = 130.459545912 * a; - out_grads[38][0] = c1 * d; - out_grads[34][0] = s1 * d; - out_grads[38][1] = -s1 * d; - out_grads[34][1] = c1 * d; - d = -545.751435723 * a; - out_grads[37][2] = c1 * d; - out_grads[35][2] = s1 * d; - c1 = x * c0 - y * s0; - s1 = y * c0 + x * s0; - d = -1.77013077 * z; - out_shs[13] = c1 * d; - out_shs[7] = s1 * d; - d = -5.310392309 * z; - out_grads[13][0] = c0 * d; - out_grads[7][0] = s0 * d; - out_grads[13][1] = s0 * d; - out_grads[7][1] = c0 * d; - d = 6.62322287 * z; - out_grads[12][2] = c0 * d; - out_grads[8][2] = s0 * d; - a = (z2 - 0.111111111) * z; - b = a - 0.161616162 * z; - d = -10.133257855 * b; - out_shs[24] = c1 * d; - out_shs[18] = s1 * d; - d = -30.399773564 * b; - out_grads[24][0] = c0 * d; - out_grads[18][0] = s0 * d; - out_grads[24][1] = s0 * d; - out_grads[18][1] = c0 * d; - d = 60.799547128 * b; - out_grads[23][2] = c0 * d; - out_grads[19][2] = s0 * d; - a = z2 * b - 0.188811189 * a; - b = a - 0.205128205 * b; - d = -48.175380057 * b; - out_shs[39] = c1 * d; - out_shs[33] = s1 * d; - d = -144.52614017 * b; - out_grads[39][0] = c0 * d; - out_grads[33][0] = s0 * d; - out_grads[39][1] = s0 * d; - out_grads[33][1] = c0 * d; - d = 391.378637737 * b; - out_grads[38][2] = c0 * d; - out_grads[34][2] = s0 * d; - c0 = x * c1 - y * s1; - s0 = y * c1 + x * s1; - d = 0.625835735; - out_shs[14] = c0 * d; - out_shs[6] = s0 * d; - d = 2.503342942; - out_grads[14][0] = c1 * d; - out_grads[6][0] = s1 * d; - out_grads[14][1] = -s1 * d; - out_grads[6][1] = c1 * d; - d = -1.77013077; - out_grads[13][2] = c1 * d; - out_grads[7][2] = s1 * d; - a = z2 - 9.09090909e-02; - d = 5.550213908 * a; - out_shs[25] = c0 * d; - out_shs[17] = s0 * d; - d = 22.200855632 * a; - out_grads[25][0] = c1 * d; - out_grads[17][0] = s1 * d; - out_grads[25][1] = -s1 * d; - out_grads[17][1] = c1 * d; - d = -30.399773564 * a; - out_grads[24][2] = c1 * d; - out_grads[18][2] = s1 * d; - b = z2 * (a - 0.13986014); - a = b - 0.169230769 * a; - d = 31.097074109 * a; - out_shs[40] = c0 * d; - out_shs[32] = s0 * d; - d = 124.388296437 * a; - out_grads[40][0] = c1 * d; - out_grads[32][0] = s1 * d; - out_grads[40][1] = -s1 * d; - out_grads[32][1] = c1 * d; - d = -240.876900283 * a; - out_grads[39][2] = c1 * d; - out_grads[33][2] = s1 * d; - c1 = x * c0 - y * s0; - s1 = y * c0 + x * s0; - d = -2.366619162 * z; - out_shs[26] = c1 * d; - out_shs[16] = s1 * d; - d = -11.833095811 * z; - out_grads[26][0] = c0 * d; - out_grads[16][0] = s0 * d; - out_grads[26][1] = s0 * d; - out_grads[16][1] = c0 * d; - d = 11.100427816 * z; - out_grads[25][2] = c0 * d; - out_grads[17][2] = s0 * d; - a = (z2 - 7.69230769e-02) * z; - b = a - 0.123076923 * z; - d = -17.24955311 * b; - out_shs[41] = c1 * d; - out_shs[31] = s1 * d; - d = -86.247765552 * b; - out_grads[41][0] = c0 * d; - out_grads[31][0] = s0 * d; - out_grads[41][1] = s0 * d; - out_grads[31][1] = c0 * d; - d = 124.388296437 * b; - out_grads[40][2] = c0 * d; - out_grads[32][2] = s0 * d; - c0 = x * c1 - y * s1; - s0 = y * c1 + x * s1; - d = 0.683184105; - out_shs[27] = c0 * d; - out_shs[15] = s0 * d; - d = 4.099104631; - out_grads[27][0] = c1 * d; - out_grads[15][0] = s1 * d; - out_grads[27][1] = -s1 * d; - out_grads[15][1] = c1 * d; - d = -2.366619162; - out_grads[26][2] = c1 * d; - out_grads[16][2] = s1 * d; - a = z2 - 6.66666667e-02; - d = 7.984991491 * a; - out_shs[42] = c0 * d; - out_shs[30] = s0 * d; - d = 47.909948945 * a; - out_grads[42][0] = c1 * d; - out_grads[30][0] = s1 * d; - out_grads[42][1] = -s1 * d; - out_grads[30][1] = c1 * d; - d = -51.748659331 * a; - out_grads[41][2] = c1 * d; - out_grads[31][2] = s1 * d; - c1 = x * c0 - y * s0; - s1 = y * c0 + x * s0; - d = -2.915706641 * z; - out_shs[43] = c1 * d; - out_shs[29] = s1 * d; - d = -20.409946485 * z; - out_grads[43][0] = c0 * d; - out_grads[29][0] = s0 * d; - out_grads[43][1] = s0 * d; - out_grads[29][1] = c0 * d; - d = 15.969982982 * z; - out_grads[42][2] = c0 * d; - out_grads[30][2] = s0 * d; - c0 = x * c1 - y * s1; - s0 = y * c1 + x * s1; - d = 0.72892666; - out_shs[44] = c0 * d; - out_shs[28] = s0 * d; - d = 5.831413281; - out_grads[44][0] = c1 * d; - out_grads[28][0] = s1 * d; - out_grads[44][1] = -s1 * d; - out_grads[28][1] = c1 * d; - d = -2.915706641; - out_grads[43][2] = c1 * d; - out_grads[29][2] = s1 * d; - out_grads[0][0] = 0.0; - out_grads[0][1] = 0.0; - out_grads[0][2] = 0.0; - out_grads[5][2] = 0.0; - out_grads[3][0] = 0.0; - out_grads[3][1] = 0.0; - out_grads[1][2] = 0.0; - out_grads[14][2] = 0.0; - out_grads[10][0] = 0.0; - out_grads[10][1] = 0.0; - out_grads[6][2] = 0.0; - out_grads[27][2] = 0.0; - out_grads[21][0] = 0.0; - out_grads[21][1] = 0.0; - out_grads[15][2] = 0.0; - out_grads[44][2] = 0.0; - out_grads[36][0] = 0.0; - out_grads[36][1] = 0.0; - out_grads[28][2] = 0.0; -} From 59971b763c0c59c328113f6e10f3f09de723e30d Mon Sep 17 00:00:00 2001 From: tvcastillod Date: Wed, 6 Mar 2024 18:05:58 -0500 Subject: [PATCH 100/118] adjusted the degree setting --- .../experimental/SH-ODF experimental/odf_example.py | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/docs/experimental/SH-ODF experimental/odf_example.py b/docs/experimental/SH-ODF experimental/odf_example.py index 50978942d..c31dac722 100644 --- a/docs/experimental/SH-ODF experimental/odf_example.py +++ b/docs/experimental/SH-ODF experimental/odf_example.py @@ -35,18 +35,7 @@ -0.1058669015765, 0.2372217923403, -0.1856198310852, -0.3373193442822, -0.0750469490886, 0.2146576642990, -0.0490148440003, 0.1288588196039, 0.3173974752426, 0.1990085393190, -0.1736343950033, -0.0482443645597, - 0.1749017387629, -0.0151847425660, 0.0418366046081, 0.0863263587216, - -0.0649211244490, 0.0126096132283, 0.0545089217982, -0.0275142164626, - 0.0399986574832, -0.0468244261610, -0.1292105653111, -0.0786858322658, - -0.0663828464882, 0.0382439706831, -0.0041550330365, -0.0502800566338, - -0.0732471630735, 0.0181751900972, -0.0090119333757, -0.0604443282359, - -0.1469985252752, -0.0534046899715, -0.0896672753415, -0.0130841364808, - -0.0112942893801, 0.0272257498541, 0.0626717616331, -0.0222197983050, - -0.0018541504308, -0.1653251944056, 0.0409697402846, 0.0749921454327, - -0.0282830872616, 0.0006909458525, 0.0625599842287, 0.0812529816082, - 0.0914693020772, -0.1197222726745, 0.0376277453183, -0.0832617004142, - -0.0482175038043, -0.0839003635737, -0.0349423908400, 0.1204519568256, - 0.0783745984003, 0.0297401205976, -0.0505947662525 + 0.1749017387629 ] ]) centers= np.array([0, 0, 0]) From 390ce0107f9785b6edc5c197828d4a30c6a4fd51 Mon Sep 17 00:00:00 2001 From: tvcastillod Date: Mon, 18 Mar 2024 13:07:16 -0500 Subject: [PATCH 101/118] added tests --- .../SH-ODF experimental/odf_example.py | 47 ---------------- fury/actor.py | 2 +- fury/actors/odf.py | 54 ++++++------------- 3 files changed, 18 insertions(+), 85 deletions(-) delete mode 100644 docs/experimental/SH-ODF experimental/odf_example.py diff --git a/docs/experimental/SH-ODF experimental/odf_example.py b/docs/experimental/SH-ODF experimental/odf_example.py deleted file mode 100644 index c31dac722..000000000 --- a/docs/experimental/SH-ODF experimental/odf_example.py +++ /dev/null @@ -1,47 +0,0 @@ -import os - -import numpy as np -from dipy.data.fetcher import dipy_home -from dipy.io.image import load_nifti - -from fury import actor, window - -if __name__ == "__main__": - show_man = window.ShowManager(size=(1280, 720)) - - dataset_dir = os.path.join(dipy_home, "stanford_hardi") - - coeffs, affine = load_nifti("docs\experimental\SH-ODF experimental\coefs_odf.nii") - - valid_mask = np.abs(coeffs).max(axis=(-1)) > 0 - indices = np.nonzero(valid_mask) - - centers = np.asarray(indices).T - - x, y, z, s = coeffs.shape - coeffs = coeffs[:, :, :].reshape((x * y * z, s)) - - #''' - coeffs = np.array([ - [ - -0.2739740312099, 0.2526670396328, 1.8922271728516, 0.2878578901291, - -0.5339795947075, -0.2620058953762, 0.1580424904823, 0.0329004973173, - -0.1322413831949, -0.1332057565451, 1.0894461870193, -0.6319401264191, - -0.0416776277125, -1.0772529840469, 0.1423762738705, 0.7941166162491, - 0.7490307092667, -0.3428381681442, 0.1024847552180, -0.0219132602215, - 0.0499043911695, 0.2162453681231, 0.0921059995890, -0.2611238956451, - 0.2549301385880, -0.4534865319729, 0.1922748684883, -0.6200597286224, - -0.0532187558711, -0.3569841980934, 0.0293972902000, -0.1977960765362, - -0.1058669015765, 0.2372217923403, -0.1856198310852, -0.3373193442822, - -0.0750469490886, 0.2146576642990, -0.0490148440003, 0.1288588196039, - 0.3173974752426, 0.1990085393190, -0.1736343950033, -0.0482443645597, - 0.1749017387629 - ] - ]) - centers= np.array([0, 0, 0]) - #''' - - odf_actor = actor.odf(centers=centers, coeffs=coeffs, scales=1.0, - basis_type='descoteaux', degree=6) - show_man.scene.add(odf_actor) - show_man.start() \ No newline at end of file diff --git a/fury/actor.py b/fury/actor.py index 90438a7ce..3e44c7bc5 100644 --- a/fury/actor.py +++ b/fury/actor.py @@ -4104,7 +4104,7 @@ def odf( elif scales.size != centers.shape[0]: scales = np.concatenate( (scales, np.ones(centers.shape[0] - scales.shape[0])), axis=None) - + total = np.sum(abs(coeffs), axis=1) coeffs = np.dot(np.diag(1 / total * scales), coeffs) * 1.7 diff --git a/fury/actors/odf.py b/fury/actors/odf.py index 139567a56..938cae791 100644 --- a/fury/actors/odf.py +++ b/fury/actors/odf.py @@ -10,33 +10,13 @@ import_fury_shader, shader_to_actor, ) -from fury.utils import numpy_to_vtk_image_data, set_polydata_tcoords - -def uv_calculations(n): - uvs = [] - for i in range(0, n): - a = (n - (i + 1)) / n - b = (n - i) / n - uvs.extend( - [ - [0.001, a + 0.001], - [0.001, b - 0.001], - [0.999, b - 0.001], - [0.999, a + 0.001], - [0.001, a + 0.001], - [0.001, b - 0.001], - [0.999, b - 0.001], - [0.999, a + 0.001], - ] - ) - return uvs - -def minmax_norm(data): - min = data.min(axis=1) - max = data.max(axis=1) - return np.array([(data[i] - min[i]) / (max[i] - min[i]) - for i in range(data.shape[0])]) - +from fury.utils import ( + numpy_to_vtk_image_data, + set_polydata_tcoords, + minmax_norm +) +from fury.texture.utils import uv_calculations + def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): """ @@ -75,9 +55,9 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): minmax = np.array([coeffs.min(axis=1), coeffs.max(axis=1)]).T big_minmax = np.repeat(minmax, 8, axis=0) attribute_to_actor(odf_actor, big_minmax, "minmax") - + # The coefficient data is stored in a texture to be passed to the shaders. - + # Data is normalized to a range of 0 to 1. arr = minmax_norm(coeffs) # Data is turned into values within the RGB color range, and then coverted @@ -92,8 +72,7 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): # Texture is associated with the actor odf_actor.GetProperty().SetTexture("texture0", texture) - - + odf_actor_pd = odf_actor.GetMapper().GetInput() n_glyphs = coeffs.shape[0] @@ -101,6 +80,7 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): uv_vals = np.array(uv_calculations(n_glyphs)) num_pnts = uv_vals.shape[0] + # Definition of texture coordinates to be associated with the actor. t_coords = FloatArray() t_coords.SetNumberOfComponents(2) t_coords.SetNumberOfTuples(num_pnts) @@ -112,9 +92,9 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): odf_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniformf( "numCoeffs", ((degree + 1) * (degree + 2)) / 2 ) - + # Start of shader implementation - + vs_dec = \ """ in vec3 center; @@ -188,13 +168,13 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): """ coeffs_norm = import_fury_shader(os.path.join("utils", "minmax_norm.glsl")) - + eval_sh_list = '' - for i in range (2, degree+1, 2): + for i in range(2, degree+1, 2): eval_sh = import_fury_shader( os.path.join("rt_odfs", basis_type, 'eval_sh_' + str(i) + '.frag')) eval_sh_grad = import_fury_shader( - os.path.join("rt_odfs", basis_type, + os.path.join("rt_odfs", basis_type, 'eval_sh_grad_' + str(i) + '.frag')) eval_sh_list = eval_sh_list + '\n\n' + eval_sh + '\n\n' + eval_sh_grad @@ -388,5 +368,5 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): ]) shader_to_actor(odf_actor, "fragment", impl_code=fs_impl, block="picking") - + return odf_actor \ No newline at end of file From ecca0f6526d9aefc37719a68c63b2fd802b55089 Mon Sep 17 00:00:00 2001 From: tvcastillod Date: Fri, 29 Mar 2024 10:15:18 -0500 Subject: [PATCH 102/118] adjustments on tests and parameter validation --- fury/actors/odf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fury/actors/odf.py b/fury/actors/odf.py index 938cae791..5e8fbe4d4 100644 --- a/fury/actors/odf.py +++ b/fury/actors/odf.py @@ -369,4 +369,4 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): shader_to_actor(odf_actor, "fragment", impl_code=fs_impl, block="picking") - return odf_actor \ No newline at end of file + return odf_actor From 800658189e3735d3cc5cf2599fcb2a92d3d30bcb Mon Sep 17 00:00:00 2001 From: tvcastillod Date: Tue, 16 Apr 2024 09:49:44 -0500 Subject: [PATCH 103/118] reorganized and refactored odf actor --- fury/actors/odf.py | 62 +++++++++++++++-------------- fury/shaders/utils/minmax_norm.glsl | 6 +-- 2 files changed, 36 insertions(+), 32 deletions(-) diff --git a/fury/actors/odf.py b/fury/actors/odf.py index 5e8fbe4d4..2f2b07f39 100644 --- a/fury/actors/odf.py +++ b/fury/actors/odf.py @@ -18,7 +18,7 @@ from fury.texture.utils import uv_calculations -def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): +def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): """ Visualize one or many ODFs with different features. @@ -28,7 +28,7 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): ODFs positions. coeffs : ndarray 2D ODFs array in SH coefficients. - basis_type: str, optional + sh_basis: str, optional Type of basis (descoteaux, tournier) 'descoteaux' for the default ``descoteaux07`` DYPY basis. 'tournier' for the default ``tournier07` DYPY basis. @@ -56,11 +56,26 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): big_minmax = np.repeat(minmax, 8, axis=0) attribute_to_actor(odf_actor, big_minmax, "minmax") + odf_actor_pd = odf_actor.GetMapper().GetInput() + + n_glyphs = coeffs.shape[0] + # Coordinates to locate the data of each glyph in the texture. + uv_vals = np.array(uv_calculations(n_glyphs)) + num_pnts = uv_vals.shape[0] + + # Definition of texture coordinates to be associated with the actor. + t_coords = FloatArray() + t_coords.SetNumberOfComponents(2) + t_coords.SetNumberOfTuples(num_pnts) + [t_coords.SetTuple(i, uv_vals[i]) for i in range(num_pnts)] + + set_polydata_tcoords(odf_actor_pd, t_coords) + # The coefficient data is stored in a texture to be passed to the shaders. # Data is normalized to a range of 0 to 1. arr = minmax_norm(coeffs) - # Data is turned into values within the RGB color range, and then coverted + # Data is turned into values within the RGB color range, and then converted # into a vtk image data. arr *= 255 grid = numpy_to_vtk_image_data(arr.astype(np.uint8)) @@ -73,21 +88,6 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): # Texture is associated with the actor odf_actor.GetProperty().SetTexture("texture0", texture) - odf_actor_pd = odf_actor.GetMapper().GetInput() - - n_glyphs = coeffs.shape[0] - # Coordinates to locate the data of each glyph in the texture. - uv_vals = np.array(uv_calculations(n_glyphs)) - num_pnts = uv_vals.shape[0] - - # Definition of texture coordinates to be associated with the actor. - t_coords = FloatArray() - t_coords.SetNumberOfComponents(2) - t_coords.SetNumberOfTuples(num_pnts) - [t_coords.SetTuple(i, uv_vals[i]) for i in range(num_pnts)] - - set_polydata_tcoords(odf_actor_pd, t_coords) - # The number of coefficients is associated to the order of the SH odf_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniformf( "numCoeffs", ((degree + 1) * (degree + 2)) / 2 @@ -169,14 +169,19 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): coeffs_norm = import_fury_shader(os.path.join("utils", "minmax_norm.glsl")) - eval_sh_list = '' - for i in range(2, degree+1, 2): + eval_sh_composed = "" + for i in range(2, degree + 1, 2): #PUT sh_degree eval_sh = import_fury_shader( - os.path.join("rt_odfs", basis_type, 'eval_sh_' + str(i) + '.frag')) + os.path.join("rt_odfs", sh_basis, "eval_sh_" + str(i) + ".frag") + ) eval_sh_grad = import_fury_shader( - os.path.join("rt_odfs", basis_type, - 'eval_sh_grad_' + str(i) + '.frag')) - eval_sh_list = eval_sh_list + '\n\n' + eval_sh + '\n\n' + eval_sh_grad + os.path.join( + "rt_odfs", sh_basis, "eval_sh_grad_" + str(i) + ".frag" + ) + ) + eval_sh_composed = compose_shader( + [eval_sh_composed, eval_sh, eval_sh_grad] + ) # Searches a single root of a polynomial within a given interval. # param out_root The location of the found root. @@ -283,7 +288,7 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): fs_dec = compose_shader([ def_sh_degree, def_sh_count, def_max_degree, def_gl_ext_control_flow_attributes, def_no_intersection, def_pis, - fs_vs_vars, coeffs_norm, eval_sh_list, newton_bisection, find_roots, + fs_vs_vars, coeffs_norm, eval_sh_composed, newton_bisection, find_roots, eval_sh, eval_sh_grad, get_inv_vandermonde, ray_sh_glyph_intersections, get_sh_glyph_normal, blinn_phong_model, linear_to_srgb, srgb_to_linear, linear_rgb_to_srgb, srgb_to_linear_rgb, tonemap @@ -311,10 +316,9 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): float i = 1 / (numCoeffs * 2); float sh_coeffs[SH_COUNT]; for(int j=0; j Date: Fri, 23 Feb 2024 09:29:11 -0500 Subject: [PATCH 104/118] added odf actor implementation --- .../SH-ODF experimental/odf_example.py | 31 + fury/actors/odf.py | 428 +++++++++++++ .../rt_odfs/descoteaux/eval_sh_10.frag | 175 ++++++ .../rt_odfs/descoteaux/eval_sh_12.frag | 238 +++++++ .../shaders/rt_odfs/descoteaux/eval_sh_2.frag | 23 + .../shaders/rt_odfs/descoteaux/eval_sh_4.frag | 46 ++ .../shaders/rt_odfs/descoteaux/eval_sh_6.frag | 79 +++ .../shaders/rt_odfs/descoteaux/eval_sh_8.frag | 122 ++++ fury/shaders/rt_odfs/eval_sh.frag | 16 + fury/shaders/rt_odfs/eval_sh_grad.frag | 16 + fury/shaders/rt_odfs/eval_sh_grad_10.frag | 430 +++++++++++++ fury/shaders/rt_odfs/eval_sh_grad_12.frag | 591 ++++++++++++++++++ fury/shaders/rt_odfs/eval_sh_grad_2.frag | 46 ++ fury/shaders/rt_odfs/eval_sh_grad_4.frag | 103 +++ fury/shaders/rt_odfs/eval_sh_grad_6.frag | 186 ++++++ fury/shaders/rt_odfs/eval_sh_grad_8.frag | 295 +++++++++ fury/shaders/rt_odfs/find_roots.frag | 82 +++ fury/shaders/rt_odfs/get_inv_vandermonde.frag | 58 ++ fury/shaders/rt_odfs/get_sh_glyph_normal.frag | 16 + .../shaders/rt_odfs/gltf_dielectric_brdf.frag | 41 ++ fury/shaders/rt_odfs/linear_rgb_to_srgb.frag | 4 + fury/shaders/rt_odfs/linear_to_srgb.frag | 4 + fury/shaders/rt_odfs/newton_bisection.frag | 47 ++ .../rt_odfs/ray_sh_glyph_intersections.frag | 81 +++ fury/shaders/rt_odfs/srgb_to_linear.frag | 4 + fury/shaders/rt_odfs/srgb_to_linear_rgb.frag | 4 + fury/shaders/rt_odfs/tonemap.frag | 5 + fury/shaders/rt_odfs/tournier/eval_sh_10.frag | 175 ++++++ fury/shaders/rt_odfs/tournier/eval_sh_12.frag | 238 +++++++ fury/shaders/rt_odfs/tournier/eval_sh_2.frag | 23 + fury/shaders/rt_odfs/tournier/eval_sh_4.frag | 46 ++ fury/shaders/rt_odfs/tournier/eval_sh_6.frag | 79 +++ fury/shaders/rt_odfs/tournier/eval_sh_8.frag | 122 ++++ fury/shaders/utils/minmax_norm.glsl | 4 + 34 files changed, 3858 insertions(+) create mode 100644 docs/experimental/SH-ODF experimental/odf_example.py create mode 100644 fury/actors/odf.py create mode 100644 fury/shaders/rt_odfs/descoteaux/eval_sh_10.frag create mode 100644 fury/shaders/rt_odfs/descoteaux/eval_sh_12.frag create mode 100644 fury/shaders/rt_odfs/descoteaux/eval_sh_2.frag create mode 100644 fury/shaders/rt_odfs/descoteaux/eval_sh_4.frag create mode 100644 fury/shaders/rt_odfs/descoteaux/eval_sh_6.frag create mode 100644 fury/shaders/rt_odfs/descoteaux/eval_sh_8.frag create mode 100644 fury/shaders/rt_odfs/eval_sh.frag create mode 100644 fury/shaders/rt_odfs/eval_sh_grad.frag create mode 100644 fury/shaders/rt_odfs/eval_sh_grad_10.frag create mode 100644 fury/shaders/rt_odfs/eval_sh_grad_12.frag create mode 100644 fury/shaders/rt_odfs/eval_sh_grad_2.frag create mode 100644 fury/shaders/rt_odfs/eval_sh_grad_4.frag create mode 100644 fury/shaders/rt_odfs/eval_sh_grad_6.frag create mode 100644 fury/shaders/rt_odfs/eval_sh_grad_8.frag create mode 100644 fury/shaders/rt_odfs/find_roots.frag create mode 100644 fury/shaders/rt_odfs/get_inv_vandermonde.frag create mode 100644 fury/shaders/rt_odfs/get_sh_glyph_normal.frag create mode 100644 fury/shaders/rt_odfs/gltf_dielectric_brdf.frag create mode 100644 fury/shaders/rt_odfs/linear_rgb_to_srgb.frag create mode 100644 fury/shaders/rt_odfs/linear_to_srgb.frag create mode 100644 fury/shaders/rt_odfs/newton_bisection.frag create mode 100644 fury/shaders/rt_odfs/ray_sh_glyph_intersections.frag create mode 100644 fury/shaders/rt_odfs/srgb_to_linear.frag create mode 100644 fury/shaders/rt_odfs/srgb_to_linear_rgb.frag create mode 100644 fury/shaders/rt_odfs/tonemap.frag create mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_10.frag create mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_12.frag create mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_2.frag create mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_4.frag create mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_6.frag create mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_8.frag create mode 100644 fury/shaders/utils/minmax_norm.glsl diff --git a/docs/experimental/SH-ODF experimental/odf_example.py b/docs/experimental/SH-ODF experimental/odf_example.py new file mode 100644 index 000000000..3b6c60469 --- /dev/null +++ b/docs/experimental/SH-ODF experimental/odf_example.py @@ -0,0 +1,31 @@ +import os + +import numpy as np +from dipy.data.fetcher import dipy_home +from dipy.io.image import load_nifti + +from fury import actor, window + +if __name__ == "__main__": + show_man = window.ShowManager(size=(1280, 720)) + + dataset_dir = os.path.join(dipy_home, "stanford_hardi") + + coeffs, affine = load_nifti("docs\experimental\SH-ODF experimental\coefs_odf.nii") + + valid_mask = np.abs(coeffs).max(axis=(-1)) > 0 + indices = np.nonzero(valid_mask) + + centers = np.asarray(indices).T + + x, y, z, s = coeffs.shape + coeffs = coeffs[:, :, :].reshape((x * y * z, s)) + n_glyphs = coeffs.shape[0] + + max_val = coeffs.min(axis=1) + total = np.sum(abs(coeffs), axis=1) + coeffs = np.dot(np.diag(1 / total), coeffs) * 1.7 + + odf_actor = actor.odf(centers=centers, coeffs=coeffs) + show_man.scene.add(odf_actor) + show_man.start() \ No newline at end of file diff --git a/fury/actors/odf.py b/fury/actors/odf.py new file mode 100644 index 000000000..a6d991033 --- /dev/null +++ b/fury/actors/odf.py @@ -0,0 +1,428 @@ +import os + +import numpy as np + +from fury import actor +from fury.lib import FloatArray, Texture +from fury.shaders import ( + attribute_to_actor, + compose_shader, + import_fury_shader, + shader_to_actor, +) +from fury.utils import numpy_to_vtk_image_data, set_polydata_tcoords + +def uv_calculations(n): + uvs = [] + for i in range(0, n): + a = (n - (i + 1)) / n + b = (n - i) / n + uvs.extend( + [ + [0.001, a + 0.001], + [0.001, b - 0.001], + [0.999, b - 0.001], + [0.999, a + 0.001], + [0.001, a + 0.001], + [0.001, b - 0.001], + [0.999, b - 0.001], + [0.999, a + 0.001], + ] + ) + return uvs + +def minmax_norm(data): + + min = data.min(axis=1) + max = data.max(axis=1) + return np.array([(data[i] - min[i]) / (max[i] - min[i]) + for i in range(data.shape[0])]) + + +def sh_odf(centers, coeffs, basis_type, scales, opacity): + """ + Visualize one or many ODFs with different features. + + Parameters + ---------- + centers : ndarray(N, 3) + ODFs positions. + coeffs : ndarray + 2D ODFs array in SH coefficients. + basis_type: str, optional + Type of basis (descoteaux, tournier) + 'descoteaux' for the default ``descoteaux07`` DYPY basis. + 'tournier' for the default ``tournier07` DYPY basis. + scales : float or ndarray (N, ) + ODFs size. + opacity : float + Takes values from 0 (fully transparent) to 1 (opaque). + + Returns + ------- + box_actor: Actor + + """ + odf_actor = actor.box(centers=centers, scales=scales) + odf_actor.GetMapper().SetVBOShiftScaleMethod(False) + odf_actor.GetProperty().SetOpacity(opacity) + + big_centers = np.repeat(centers, 8, axis=0) + attribute_to_actor(odf_actor, big_centers, "center") + + minmax = np.array([coeffs.min(axis=1), coeffs.max(axis=1)]).T + big_minmax = np.repeat(minmax, 8, axis=0) + attribute_to_actor(odf_actor, big_minmax, "minmax") + + # The coefficient data is stored in a texture to be passed to the shaders. + + # Data is normalized to a range of 0 to 1. + arr = minmax_norm(coeffs) + # Data is turned into values within the RGB color range, and then coverted + # into a vtk image data. + arr *= 255 + grid = numpy_to_vtk_image_data(arr.astype(np.uint8)) + + # Vtk image data is associated to a texture. + texture = Texture() + texture.SetInputDataObject(grid) + texture.Update() + + # Texture is associated with the actor + odf_actor.GetProperty().SetTexture("texture0", texture) + + + odf_actor_pd = odf_actor.GetMapper().GetInput() + + n_glyphs = coeffs.shape[0] + # Coordinates to locate the data of each glyph in the texture. + uv_vals = np.array(uv_calculations(n_glyphs)) + num_pnts = uv_vals.shape[0] + + t_coords = FloatArray() + t_coords.SetNumberOfComponents(2) + t_coords.SetNumberOfTuples(num_pnts) + [t_coords.SetTuple(i, uv_vals[i]) for i in range(num_pnts)] + + set_polydata_tcoords(odf_actor_pd, t_coords) + + # The number of coefficients is associated to the order of the SH + odf_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniformf( + "numCoeffs", 15 + ) + + # Start of shader implementation + + vs_dec = \ + """ + in vec3 center; + in vec2 minmax; + + out vec4 vertexMCVSOutput; + out vec3 centerMCVSOutput; + out vec2 minmaxVSOutput; + out vec3 camPosMCVSOutput; + out vec3 camRightMCVSOutput; + out vec3 camUpMCVSOutput; + """ + + vs_impl = \ + """ + vertexMCVSOutput = vertexMC; + centerMCVSOutput = center; + minmaxVSOutput = minmax; + camPosMCVSOutput = -MCVCMatrix[3].xyz * mat3(MCVCMatrix); + camRightMCVSOutput = vec3( + MCVCMatrix[0][0], MCVCMatrix[1][0], MCVCMatrix[2][0]); + camUpMCVSOutput = vec3( + MCVCMatrix[0][1], MCVCMatrix[1][1], MCVCMatrix[2][1]); + """ + + shader_to_actor(odf_actor, "vertex", decl_code=vs_dec, impl_code=vs_impl) + + # The index of the highest used band of the spherical harmonics basis. Must + # be even, at least 2 and at most 12. + def_sh_degree = "#define SH_DEGREE 4" + + # The number of spherical harmonics basis functions + def_sh_count = "#define SH_COUNT (((SH_DEGREE + 1) * (SH_DEGREE + 2)) / 2)" + + # Degree of polynomials for which we have to find roots + def_max_degree = "#define MAX_DEGREE (2 * SH_DEGREE + 2)" + + # If GL_EXT_control_flow_attributes is available, these defines should be + # defined as [[unroll]] and [[loop]] to give reasonable hints to the + # compiler. That avoids register spilling, which makes execution + # considerably faster. + def_gl_ext_control_flow_attributes = \ + """ + #ifndef _unroll_ + #define _unroll_ + #endif + #ifndef _loop_ + #define _loop_ + #endif + """ + + # When there are fewer intersections/roots than theoretically possible, + # some array entries are set to this value + def_no_intersection = "#define NO_INTERSECTION 3.4e38" + + # pi and its reciprocal + def_pis = \ + """ + #define M_PI 3.141592653589793238462643 + #define M_INV_PI 0.318309886183790671537767526745 + """ + + fs_vs_vars = \ + """ + in vec4 vertexMCVSOutput; + in vec3 centerMCVSOutput; + in vec2 minmaxVSOutput; + in vec3 camPosMCVSOutput; + in vec3 camRightMCVSOutput; + in vec3 camUpMCVSOutput; + """ + + coeffs_norm = import_fury_shader(os.path.join("utils", "minmax_norm.glsl")) + + eval_sh_2 = import_fury_shader( + os.path.join("rt_odfs", basis_type, "eval_sh_2.frag")) + + eval_sh_4 = import_fury_shader( + os.path.join("rt_odfs", basis_type, "eval_sh_4.frag")) + + eval_sh_6 = import_fury_shader( + os.path.join("rt_odfs", basis_type, "eval_sh_6.frag")) + + eval_sh_8 = import_fury_shader( + os.path.join("rt_odfs", basis_type, "eval_sh_8.frag")) + + eval_sh_10 = import_fury_shader( + os.path.join("rt_odfs", basis_type, "eval_sh_10.frag")) + + eval_sh_12 = import_fury_shader( + os.path.join("rt_odfs", basis_type, "eval_sh_12.frag")) + + eval_sh_grad_2 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_2.frag") + ) + + eval_sh_grad_4 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_4.frag") + ) + + eval_sh_grad_6 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_6.frag") + ) + + eval_sh_grad_8 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_8.frag") + ) + + eval_sh_grad_10 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_10.frag") + ) + + eval_sh_grad_12 = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad_12.frag") + ) + + # Searches a single root of a polynomial within a given interval. + # param out_root The location of the found root. + # param out_end_value The value of the given polynomial at end. + # param poly Coefficients of the polynomial for which a root should be + # found. + # Coefficient poly[i] is multiplied by x^i. + # param begin The beginning of an interval where the polynomial is + # monotonic. + # param end The end of said interval. + # param begin_value The value of the given polynomial at begin. + # param error_tolerance The error tolerance for the returned root + # location. + # Typically the error will be much lower but in theory it can be + # bigger. + # + # return true if a root was found, false if no root exists. + newton_bisection = import_fury_shader( + os.path.join("rt_odfs", "newton_bisection.frag") + ) + + # Finds all roots of the given polynomial in the interval [begin, end] and + # writes them to out_roots. Some entries will be NO_INTERSECTION but other + # than that the array is sorted. The last entry is always NO_INTERSECTION. + find_roots = import_fury_shader(os.path.join("rt_odfs", "find_roots.frag")) + + # Evaluates the spherical harmonics basis in bands 0, 2, ..., SH_DEGREE. + # Conventions are as in the following paper. + # M. Descoteaux, E. Angelino, S. Fitzgibbons, and R. Deriche. Regularized, + # fast, and robust analytical q-ball imaging. Magnetic Resonance in + # Medicine, 58(3), 2007. https://doi.org/10.1002/mrm.21277 + # param out_shs Values of SH basis functions in bands 0, 2, ..., + # SH_DEGREE in this order. + # param point The point on the unit sphere where the basis should be + # evaluated. + eval_sh = import_fury_shader(os.path.join("rt_odfs", "eval_sh.frag")) + + # Evaluates the gradient of each basis function given by eval_sh() and the + # basis itself + eval_sh_grad = import_fury_shader( + os.path.join("rt_odfs", "eval_sh_grad.frag") + ) + + # Outputs a matrix that turns equidistant samples on the unit circle of a + # homogeneous polynomial into coefficients of that polynomial. + get_inv_vandermonde = import_fury_shader( + os.path.join("rt_odfs", "get_inv_vandermonde.frag") + ) + + # Determines all intersections between a ray and a spherical harmonics + # glyph. + # param out_ray_params The ray parameters at intersection points. The + # points themselves are at ray_origin + out_ray_params[i] * ray_dir. + # Some entries may be NO_INTERSECTION but other than that the array + # is sorted. + # param sh_coeffs SH_COUNT spherical harmonic coefficients defining the + # glyph. Their exact meaning is defined by eval_sh(). + # param ray_origin The origin of the ray, relative to the glyph center. + # param ray_dir The normalized direction vector of the ray. + ray_sh_glyph_intersections = import_fury_shader( + os.path.join("rt_odfs", "ray_sh_glyph_intersections.frag") + ) + + # Provides a normalized normal vector for a spherical harmonics glyph. + # param sh_coeffs SH_COUNT spherical harmonic coefficients defining the + # glyph. Their exact meaning is defined by eval_sh(). + # param point A point on the surface of the glyph, relative to its + # center. + # + # return A normalized surface normal pointing away from the origin. + get_sh_glyph_normal = import_fury_shader( + os.path.join("rt_odfs", "get_sh_glyph_normal.frag") + ) + + # Applies the non-linearity that maps linear RGB to sRGB + linear_to_srgb = import_fury_shader( + os.path.join("rt_odfs", "linear_to_srgb.frag") + ) + + # Inverse of linear_to_srgb() + srgb_to_linear = import_fury_shader( + os.path.join("rt_odfs", "srgb_to_linear.frag") + ) + + # Turns a linear RGB color (i.e. rec. 709) into sRGB + linear_rgb_to_srgb = import_fury_shader( + os.path.join("rt_odfs", "linear_rgb_to_srgb.frag") + ) + + # Inverse of linear_rgb_to_srgb() + srgb_to_linear_rgb = import_fury_shader( + os.path.join("rt_odfs", "srgb_to_linear_rgb.frag") + ) + + # Logarithmic tonemapping operator. Input and output are linear RGB. + tonemap = import_fury_shader(os.path.join("rt_odfs", "tonemap.frag")) + + # Blinn-Phong illumination model + blinn_phong_model = import_fury_shader( + os.path.join("lighting", "blinn_phong_model.frag") + ) + + # fmt: off + fs_dec = compose_shader([ + def_sh_degree, def_sh_count, def_max_degree, + def_gl_ext_control_flow_attributes, def_no_intersection, def_pis, + fs_vs_vars, coeffs_norm, eval_sh_2, eval_sh_4, eval_sh_6, eval_sh_8, + eval_sh_10, eval_sh_12, eval_sh_grad_2, eval_sh_grad_4, eval_sh_grad_6, + eval_sh_grad_8, eval_sh_grad_10, eval_sh_grad_12, newton_bisection, + find_roots, eval_sh, eval_sh_grad, get_inv_vandermonde, + ray_sh_glyph_intersections, get_sh_glyph_normal, blinn_phong_model, + linear_to_srgb, srgb_to_linear, linear_rgb_to_srgb, srgb_to_linear_rgb, + tonemap + ]) + # fmt: on + + shader_to_actor(odf_actor, "fragment", decl_code=fs_dec) + + point_from_vs = "vec3 pnt = vertexMCVSOutput.xyz;" + + # Ray origin is the camera position in world space + ray_origin = "vec3 ro = camPosMCVSOutput;" + + # TODO: Check aspect for automatic scaling + # Ray direction is the normalized difference between the fragment and the + # camera position/ray origin + ray_direction = "vec3 rd = normalize(pnt - ro);" + + # Light direction in a retroreflective model is the normalized difference + # between the camera position/ray origin and the fragment + light_direction = "vec3 ld = normalize(ro - pnt);" + + # Define SH coefficients (measured up to band 8, noise beyond that) + sh_coeffs = \ + """ + float i = 1 / (numCoeffs * 2); + float sh_coeffs[SH_COUNT]; + for(int j=0; j 0.0) { + first_ray_param = ray_params[i]; + break; + } + } + """ + + # Evaluate shading for a directional light + directional_light = \ + """ + vec3 color = vec3(1.); + if (first_ray_param != NO_INTERSECTION) { + vec3 intersection = ro - centerMCVSOutput + first_ray_param * rd; + vec3 normal = get_sh_glyph_normal(sh_coeffs, intersection); + vec3 colorDir = srgb_to_linear_rgb(abs(normalize(intersection))); + float attenuation = dot(ld, normal); + color = blinnPhongIllumModel( + //attenuation, lightColor0, diffuseColor, specularPower, + attenuation, lightColor0, colorDir, specularPower, + specularColor, ambientColor); + } else { + discard; + } + """ + + frag_output = \ + """ + vec3 out_color = linear_rgb_to_srgb(tonemap(color)); + fragOutput0 = vec4(out_color, opacity); + """ + + fs_impl = compose_shader([ + point_from_vs, ray_origin, ray_direction, light_direction, sh_coeffs, + intersection_test, first_intersection, directional_light, frag_output + ]) + + shader_to_actor(odf_actor, "fragment", impl_code=fs_impl, block="picking") + + return odf_actor \ No newline at end of file diff --git a/fury/shaders/rt_odfs/descoteaux/eval_sh_10.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_10.frag new file mode 100644 index 000000000..178033cae --- /dev/null +++ b/fury/shaders/rt_odfs/descoteaux/eval_sh_10.frag @@ -0,0 +1,175 @@ +void eval_sh_10(out float out_shs[66], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + b = z2 * a - 0.250980392 * b; + a = b - 0.250773994 * a; + d = 233.240148813 * a; + out_shs[55] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[20] = -c1 * d; + out_shs[22] = s1 * d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[35] = -c1 * d; + out_shs[37] = s1 * d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + out_shs[54] = -c1 * d; + out_shs[56] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[19] = c0 * d; + out_shs[23] = s0 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[34] = c0 * d; + out_shs[38] = s0 * d; + b = z2 * a - 0.235294118 * b; + a = b - 0.238390093 * a; + d = 272.365814381 * a; + out_shs[53] = c0 * d; + out_shs[57] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[18] = -c1 * d; + out_shs[24] = s1 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[33] = -c1 * d; + out_shs[39] = s1 * d; + a = z2 * b - 0.215686275 * a; + b = a - 0.222910217 * b; + d = -213.661323441 * b; + out_shs[52] = -c1 * d; + out_shs[58] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[17] = c0 * d; + out_shs[25] = s0 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[32] = c0 * d; + out_shs[40] = s0 * d; + b = z2 * a - 0.188235294 * b; + a = b - 0.20123839 * a; + d = 151.081370682 * a; + out_shs[51] = c0 * d; + out_shs[59] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[16] = -c1 * d; + out_shs[26] = s1 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[31] = -c1 * d; + out_shs[41] = s1 * d; + a = z2 * b - 0.152941176 * a; + b = a - 0.173374613 * b; + d = -95.552248675 * b; + out_shs[50] = -c1 * d; + out_shs[60] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[15] = c0 * d; + out_shs[27] = s0 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[30] = c0 * d; + out_shs[42] = s0 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + out_shs[49] = c0 * d; + out_shs[61] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[29] = -c1 * d; + out_shs[43] = s1 * d; + a = (z2 - 5.88235294e-02) * z; + b = a - 9.90712074e-02 * z; + d = -25.910241313 * b; + out_shs[48] = -c1 * d; + out_shs[62] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[28] = c0 * d; + out_shs[44] = s0 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + out_shs[47] = c0 * d; + out_shs[63] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + out_shs[46] = -c1 * d; + out_shs[64] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + out_shs[45] = c0 * d; + out_shs[65] = s0 * d; +} diff --git a/fury/shaders/rt_odfs/descoteaux/eval_sh_12.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_12.frag new file mode 100644 index 000000000..f1a6d85e9 --- /dev/null +++ b/fury/shaders/rt_odfs/descoteaux/eval_sh_12.frag @@ -0,0 +1,238 @@ +void eval_sh_12(out float out_shs[91], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + b = z2 * a - 0.250980392 * b; + a = b - 0.250773994 * a; + d = 233.240148813 * a; + out_shs[55] = d; + b = z2 * a - 0.250626566 * b; + a = b - 0.250517598 * a; + d = 931.186918633 * a; + out_shs[78] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[20] = -c1 * d; + out_shs[22] = s1 * d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[35] = -c1 * d; + out_shs[37] = s1 * d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + out_shs[54] = -c1 * d; + out_shs[56] = s1 * d; + a = z2 * b - 0.248120301 * a; + b = a - 0.248447205 * b; + d = -1265.233874957 * b; + out_shs[77] = -c1 * d; + out_shs[79] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[19] = c0 * d; + out_shs[23] = s0 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[34] = c0 * d; + out_shs[38] = s0 * d; + b = z2 * a - 0.235294118 * b; + a = b - 0.238390093 * a; + d = 272.365814381 * a; + out_shs[53] = c0 * d; + out_shs[57] = s0 * d; + b = z2 * a - 0.240601504 * b; + a = b - 0.242236025 * a; + d = 1121.509962433 * a; + out_shs[76] = c0 * d; + out_shs[80] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[18] = -c1 * d; + out_shs[24] = s1 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[33] = -c1 * d; + out_shs[39] = s1 * d; + a = z2 * b - 0.215686275 * a; + b = a - 0.222910217 * b; + d = -213.661323441 * b; + out_shs[52] = -c1 * d; + out_shs[58] = s1 * d; + a = z2 * b - 0.228070175 * a; + b = a - 0.231884058 * b; + d = -915.709049803 * b; + out_shs[75] = -c1 * d; + out_shs[81] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[17] = c0 * d; + out_shs[25] = s0 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[32] = c0 * d; + out_shs[40] = s0 * d; + b = z2 * a - 0.188235294 * b; + a = b - 0.20123839 * a; + d = 151.081370682 * a; + out_shs[51] = c0 * d; + out_shs[59] = s0 * d; + b = z2 * a - 0.210526316 * b; + a = b - 0.217391304 * a; + d = 686.781787352 * a; + out_shs[74] = c0 * d; + out_shs[82] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[16] = -c1 * d; + out_shs[26] = s1 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[31] = -c1 * d; + out_shs[41] = s1 * d; + a = z2 * b - 0.152941176 * a; + b = a - 0.173374613 * b; + d = -95.552248675 * b; + out_shs[50] = -c1 * d; + out_shs[60] = s1 * d; + a = z2 * b - 0.187969925 * a; + b = a - 0.198757764 * b; + d = -471.12841933 * b; + out_shs[73] = -c1 * d; + out_shs[83] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[15] = c0 * d; + out_shs[27] = s0 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[30] = c0 * d; + out_shs[42] = s0 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + out_shs[49] = c0 * d; + out_shs[61] = s0 * d; + b = z2 * a - 0.160401003 * b; + a = b - 0.175983437 * a; + d = 293.800188384 * a; + out_shs[72] = c0 * d; + out_shs[84] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[29] = -c1 * d; + out_shs[43] = s1 * d; + a = (z2 - 5.88235294e-02) * z; + b = a - 9.90712074e-02 * z; + d = -25.910241313 * b; + out_shs[48] = -c1 * d; + out_shs[62] = s1 * d; + a = z2 * b - 0.127819549 * a; + b = a - 0.149068323 * b; + d = -165.101452729 * b; + out_shs[71] = -c1 * d; + out_shs[85] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[28] = c0 * d; + out_shs[44] = s0 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + out_shs[47] = c0 * d; + out_shs[63] = s0 * d; + b = z2 * (a - 9.02255639e-02); + a = b - 0.118012422 * a; + d = 82.550726364 * a; + out_shs[70] = c0 * d; + out_shs[86] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + out_shs[46] = -c1 * d; + out_shs[64] = s1 * d; + a = (z2 - 4.76190476e-02) * z; + b = a - 8.2815735e-02 * z; + d = -36.028090689 * b; + out_shs[69] = -c1 * d; + out_shs[87] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + out_shs[45] = c0 * d; + out_shs[65] = s0 * d; + a = z2 - 4.34782609e-02; + d = 13.3042542 * a; + out_shs[68] = c0 * d; + out_shs[88] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.923210529 * z; + out_shs[67] = -c1 * d; + out_shs[89] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.800821996; + out_shs[66] = c0 * d; + out_shs[90] = s0 * d; +} diff --git a/fury/shaders/rt_odfs/descoteaux/eval_sh_2.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_2.frag new file mode 100644 index 000000000..c15510b74 --- /dev/null +++ b/fury/shaders/rt_odfs/descoteaux/eval_sh_2.frag @@ -0,0 +1,23 @@ +void eval_sh_2(out float out_shs[6], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; +} diff --git a/fury/shaders/rt_odfs/descoteaux/eval_sh_4.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_4.frag new file mode 100644 index 000000000..975fac054 --- /dev/null +++ b/fury/shaders/rt_odfs/descoteaux/eval_sh_4.frag @@ -0,0 +1,46 @@ +void eval_sh_4(out float out_shs[15], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; +} diff --git a/fury/shaders/rt_odfs/descoteaux/eval_sh_6.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_6.frag new file mode 100644 index 000000000..6cbd1bcf1 --- /dev/null +++ b/fury/shaders/rt_odfs/descoteaux/eval_sh_6.frag @@ -0,0 +1,79 @@ +void eval_sh_6(out float out_shs[28], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[20] = -c1 * d; + out_shs[22] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[19] = c0 * d; + out_shs[23] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[18] = -c1 * d; + out_shs[24] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[17] = c0 * d; + out_shs[25] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[16] = -c1 * d; + out_shs[26] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[15] = c0 * d; + out_shs[27] = s0 * d; +} diff --git a/fury/shaders/rt_odfs/descoteaux/eval_sh_8.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_8.frag new file mode 100644 index 000000000..6e79b2b16 --- /dev/null +++ b/fury/shaders/rt_odfs/descoteaux/eval_sh_8.frag @@ -0,0 +1,122 @@ +void eval_sh_8(out float out_shs[45], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[20] = -c1 * d; + out_shs[22] = s1 * d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[35] = -c1 * d; + out_shs[37] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[19] = c0 * d; + out_shs[23] = s0 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[34] = c0 * d; + out_shs[38] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[18] = -c1 * d; + out_shs[24] = s1 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[33] = -c1 * d; + out_shs[39] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[17] = c0 * d; + out_shs[25] = s0 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[32] = c0 * d; + out_shs[40] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[16] = -c1 * d; + out_shs[26] = s1 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[31] = -c1 * d; + out_shs[41] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[15] = c0 * d; + out_shs[27] = s0 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[30] = c0 * d; + out_shs[42] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[29] = -c1 * d; + out_shs[43] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[28] = c0 * d; + out_shs[44] = s0 * d; +} diff --git a/fury/shaders/rt_odfs/eval_sh.frag b/fury/shaders/rt_odfs/eval_sh.frag new file mode 100644 index 000000000..e3810af25 --- /dev/null +++ b/fury/shaders/rt_odfs/eval_sh.frag @@ -0,0 +1,16 @@ +void eval_sh(out float out_shs[SH_COUNT], vec3 point) +{ + #if SH_DEGREE == 2 + eval_sh_2(out_shs, point); + #elif SH_DEGREE == 4 + eval_sh_4(out_shs, point); + #elif SH_DEGREE == 6 + eval_sh_6(out_shs, point); + #elif SH_DEGREE == 8 + eval_sh_8(out_shs, point); + #elif SH_DEGREE == 10 + eval_sh_10(out_shs, point); + #elif SH_DEGREE == 12 + eval_sh_12(out_shs, point); + #endif +} diff --git a/fury/shaders/rt_odfs/eval_sh_grad.frag b/fury/shaders/rt_odfs/eval_sh_grad.frag new file mode 100644 index 000000000..c318dbd6c --- /dev/null +++ b/fury/shaders/rt_odfs/eval_sh_grad.frag @@ -0,0 +1,16 @@ +void eval_sh_grad(out float out_shs[SH_COUNT], out vec3 out_grads[SH_COUNT], vec3 point) +{ + #if SH_DEGREE == 2 + eval_sh_grad_2(out_shs, out_grads, point); + #elif SH_DEGREE == 4 + eval_sh_grad_4(out_shs, out_grads, point); + #elif SH_DEGREE == 6 + eval_sh_grad_6(out_shs, out_grads, point); + #elif SH_DEGREE == 8 + eval_sh_grad_8(out_shs, out_grads, point); + #elif SH_DEGREE == 10 + eval_sh_grad_10(out_shs, out_grads, point); + #elif SH_DEGREE == 12 + eval_sh_grad_12(out_shs, out_grads, point); + #endif +} diff --git a/fury/shaders/rt_odfs/eval_sh_grad_10.frag b/fury/shaders/rt_odfs/eval_sh_grad_10.frag new file mode 100644 index 000000000..9d5feea39 --- /dev/null +++ b/fury/shaders/rt_odfs/eval_sh_grad_10.frag @@ -0,0 +1,430 @@ +void eval_sh_grad_10(out float out_shs[66], out vec3 out_grads[66], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + b = z2 * a - 0.250980392 * b; + a = b - 0.250773994 * a; + d = 233.240148813 * a; + out_shs[55] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + out_grads[2][0] = -c0 * d; + out_grads[4][0] = s0 * d; + out_grads[2][1] = s0 * d; + out_grads[4][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + out_grads[9][0] = -c0 * d; + out_grads[11][0] = s0 * d; + out_grads[9][1] = s0 * d; + out_grads[11][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[20] = -c1 * d; + out_shs[22] = s1 * d; + out_grads[20][0] = -c0 * d; + out_grads[22][0] = s0 * d; + out_grads[20][1] = s0 * d; + out_grads[22][1] = c0 * d; + d = 88.106914343 * b; + out_grads[21][2] = d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[35] = -c1 * d; + out_shs[37] = s1 * d; + out_grads[35][0] = -c0 * d; + out_grads[37][0] = s0 * d; + out_grads[35][1] = s0 * d; + out_grads[37][1] = c0 * d; + d = 467.786944906 * b; + out_grads[36][2] = d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + out_shs[54] = -c1 * d; + out_shs[56] = s1 * d; + out_grads[54][0] = -c0 * d; + out_grads[56][0] = s0 * d; + out_grads[54][1] = s0 * d; + out_grads[56][1] = c0 * d; + d = 2332.401488133 * b; + out_grads[55][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + d = 1.092548431; + out_grads[1][0] = c1 * d; + out_grads[5][0] = s1 * d; + out_grads[1][1] = -s1 * d; + out_grads[5][1] = c1 * d; + d = -1.092548431; + out_grads[2][2] = -c1 * d; + out_grads[4][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + d = 6.62322287 * a; + out_grads[8][0] = c1 * d; + out_grads[12][0] = s1 * d; + out_grads[8][1] = -s1 * d; + out_grads[12][1] = c1 * d; + d = -14.049977415 * a; + out_grads[9][2] = -c1 * d; + out_grads[11][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[19] = c0 * d; + out_shs[23] = s0 * d; + d = 30.399773564 * a; + out_grads[19][0] = c1 * d; + out_grads[23][0] = s1 * d; + out_grads[19][1] = -s1 * d; + out_grads[23][1] = c1 * d; + d = -96.132524816 * a; + out_grads[20][2] = -c1 * d; + out_grads[22][2] = s1 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[34] = c0 * d; + out_shs[38] = s0 * d; + d = 130.459545912 * a; + out_grads[34][0] = c1 * d; + out_grads[38][0] = s1 * d; + out_grads[34][1] = -s1 * d; + out_grads[38][1] = c1 * d; + d = -545.751435723 * a; + out_grads[35][2] = -c1 * d; + out_grads[37][2] = s1 * d; + b = z2 * a - 0.235294118 * b; + a = b - 0.238390093 * a; + d = 272.365814381 * a; + out_shs[53] = c0 * d; + out_shs[57] = s0 * d; + d = 544.731628762 * a; + out_grads[53][0] = c1 * d; + out_grads[57][0] = s1 * d; + out_grads[53][1] = -s1 * d; + out_grads[57][1] = c1 * d; + d = -2830.508572514 * a; + out_grads[54][2] = -c1 * d; + out_grads[56][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + d = -5.310392309 * z; + out_grads[7][0] = -c0 * d; + out_grads[13][0] = s0 * d; + out_grads[7][1] = s0 * d; + out_grads[13][1] = c0 * d; + d = 6.62322287 * z; + out_grads[8][2] = c0 * d; + out_grads[12][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[18] = -c1 * d; + out_shs[24] = s1 * d; + d = -30.399773564 * b; + out_grads[18][0] = -c0 * d; + out_grads[24][0] = s0 * d; + out_grads[18][1] = s0 * d; + out_grads[24][1] = c0 * d; + d = 60.799547128 * b; + out_grads[19][2] = c0 * d; + out_grads[23][2] = s0 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[33] = -c1 * d; + out_shs[39] = s1 * d; + d = -144.52614017 * b; + out_grads[33][0] = -c0 * d; + out_grads[39][0] = s0 * d; + out_grads[33][1] = s0 * d; + out_grads[39][1] = c0 * d; + d = 391.378637737 * b; + out_grads[34][2] = c0 * d; + out_grads[38][2] = s0 * d; + a = z2 * b - 0.215686275 * a; + b = a - 0.222910217 * b; + d = -213.661323441 * b; + out_shs[52] = -c1 * d; + out_shs[58] = s1 * d; + d = -640.983970322 * b; + out_grads[52][0] = -c0 * d; + out_grads[58][0] = s0 * d; + out_grads[52][1] = s0 * d; + out_grads[58][1] = c0 * d; + d = 2178.926515046 * b; + out_grads[53][2] = c0 * d; + out_grads[57][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + d = 2.503342942; + out_grads[6][0] = c1 * d; + out_grads[14][0] = s1 * d; + out_grads[6][1] = -s1 * d; + out_grads[14][1] = c1 * d; + d = -1.77013077; + out_grads[7][2] = -c1 * d; + out_grads[13][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[17] = c0 * d; + out_shs[25] = s0 * d; + d = 22.200855632 * a; + out_grads[17][0] = c1 * d; + out_grads[25][0] = s1 * d; + out_grads[17][1] = -s1 * d; + out_grads[25][1] = c1 * d; + d = -30.399773564 * a; + out_grads[18][2] = -c1 * d; + out_grads[24][2] = s1 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[32] = c0 * d; + out_shs[40] = s0 * d; + d = 124.388296437 * a; + out_grads[32][0] = c1 * d; + out_grads[40][0] = s1 * d; + out_grads[32][1] = -s1 * d; + out_grads[40][1] = c1 * d; + d = -240.876900283 * a; + out_grads[33][2] = -c1 * d; + out_grads[39][2] = s1 * d; + b = z2 * a - 0.188235294 * b; + a = b - 0.20123839 * a; + d = 151.081370682 * a; + out_shs[51] = c0 * d; + out_shs[59] = s0 * d; + d = 604.325482728 * a; + out_grads[51][0] = c1 * d; + out_grads[59][0] = s1 * d; + out_grads[51][1] = -s1 * d; + out_grads[59][1] = c1 * d; + d = -1495.629264084 * a; + out_grads[52][2] = -c1 * d; + out_grads[58][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[16] = -c1 * d; + out_shs[26] = s1 * d; + d = -11.833095811 * z; + out_grads[16][0] = -c0 * d; + out_grads[26][0] = s0 * d; + out_grads[16][1] = s0 * d; + out_grads[26][1] = c0 * d; + d = 11.100427816 * z; + out_grads[17][2] = c0 * d; + out_grads[25][2] = s0 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[31] = -c1 * d; + out_shs[41] = s1 * d; + d = -86.247765552 * b; + out_grads[31][0] = -c0 * d; + out_grads[41][0] = s0 * d; + out_grads[31][1] = s0 * d; + out_grads[41][1] = c0 * d; + d = 124.388296437 * b; + out_grads[32][2] = c0 * d; + out_grads[40][2] = s0 * d; + a = z2 * b - 0.152941176 * a; + b = a - 0.173374613 * b; + d = -95.552248675 * b; + out_shs[50] = -c1 * d; + out_shs[60] = s1 * d; + d = -477.761243376 * b; + out_grads[50][0] = -c0 * d; + out_grads[60][0] = s0 * d; + out_grads[50][1] = s0 * d; + out_grads[60][1] = c0 * d; + d = 906.488224092 * b; + out_grads[51][2] = c0 * d; + out_grads[59][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[15] = c0 * d; + out_shs[27] = s0 * d; + d = 4.099104631; + out_grads[15][0] = c1 * d; + out_grads[27][0] = s1 * d; + out_grads[15][1] = -s1 * d; + out_grads[27][1] = c1 * d; + d = -2.366619162; + out_grads[16][2] = -c1 * d; + out_grads[26][2] = s1 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[30] = c0 * d; + out_shs[42] = s0 * d; + d = 47.909948945 * a; + out_grads[30][0] = c1 * d; + out_grads[42][0] = s1 * d; + out_grads[30][1] = -s1 * d; + out_grads[42][1] = c1 * d; + d = -51.748659331 * a; + out_grads[31][2] = -c1 * d; + out_grads[41][2] = s1 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + out_shs[49] = c0 * d; + out_shs[61] = s0 * d; + d = 320.491985161 * a; + out_grads[49][0] = c1 * d; + out_grads[61][0] = s1 * d; + out_grads[49][1] = -s1 * d; + out_grads[61][1] = c1 * d; + d = -477.761243376 * a; + out_grads[50][2] = -c1 * d; + out_grads[60][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[29] = -c1 * d; + out_shs[43] = s1 * d; + d = -20.409946485 * z; + out_grads[29][0] = -c0 * d; + out_grads[43][0] = s0 * d; + out_grads[29][1] = s0 * d; + out_grads[43][1] = c0 * d; + d = 15.969982982 * z; + out_grads[30][2] = c0 * d; + out_grads[42][2] = s0 * d; + a = (z2 - 5.88235294e-02) * z; + b = a - 9.90712074e-02 * z; + d = -25.910241313 * b; + out_shs[48] = -c1 * d; + out_shs[62] = s1 * d; + d = -181.371689194 * b; + out_grads[48][0] = -c0 * d; + out_grads[62][0] = s0 * d; + out_grads[48][1] = s0 * d; + out_grads[62][1] = c0 * d; + d = 213.661323441 * b; + out_grads[49][2] = c0 * d; + out_grads[61][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[28] = c0 * d; + out_shs[44] = s0 * d; + d = 5.831413281; + out_grads[28][0] = c1 * d; + out_grads[44][0] = s1 * d; + out_grads[28][1] = -s1 * d; + out_grads[44][1] = c1 * d; + d = -2.915706641; + out_grads[29][2] = -c1 * d; + out_grads[43][2] = s1 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + out_shs[47] = c0 * d; + out_shs[63] = s0 * d; + d = 84.622493774 * a; + out_grads[47][0] = c1 * d; + out_grads[63][0] = s1 * d; + out_grads[47][1] = -s1 * d; + out_grads[63][1] = c1 * d; + d = -77.73072394 * a; + out_grads[48][2] = -c1 * d; + out_grads[62][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + out_shs[46] = -c1 * d; + out_shs[64] = s1 * d; + d = -30.887057699 * z; + out_grads[46][0] = -c0 * d; + out_grads[64][0] = s0 * d; + out_grads[46][1] = s0 * d; + out_grads[64][1] = c0 * d; + d = 21.155623443 * z; + out_grads[47][2] = c0 * d; + out_grads[63][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + out_shs[45] = c0 * d; + out_shs[65] = s0 * d; + d = 7.673951182; + out_grads[45][0] = c1 * d; + out_grads[65][0] = s1 * d; + out_grads[45][1] = -s1 * d; + out_grads[65][1] = c1 * d; + d = -3.4318953; + out_grads[46][2] = -c1 * d; + out_grads[64][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; + out_grads[6][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[14][2] = 0.0; + out_grads[15][2] = 0.0; + out_grads[21][0] = 0.0; + out_grads[21][1] = 0.0; + out_grads[27][2] = 0.0; + out_grads[28][2] = 0.0; + out_grads[36][0] = 0.0; + out_grads[36][1] = 0.0; + out_grads[44][2] = 0.0; + out_grads[45][2] = 0.0; + out_grads[55][0] = 0.0; + out_grads[55][1] = 0.0; + out_grads[65][2] = 0.0; +} diff --git a/fury/shaders/rt_odfs/eval_sh_grad_12.frag b/fury/shaders/rt_odfs/eval_sh_grad_12.frag new file mode 100644 index 000000000..f7ff069bc --- /dev/null +++ b/fury/shaders/rt_odfs/eval_sh_grad_12.frag @@ -0,0 +1,591 @@ +void eval_sh_grad_12(out float out_shs[91], out vec3 out_grads[91], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + b = z2 * a - 0.250980392 * b; + a = b - 0.250773994 * a; + d = 233.240148813 * a; + out_shs[55] = d; + b = z2 * a - 0.250626566 * b; + a = b - 0.250517598 * a; + d = 931.186918633 * a; + out_shs[78] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + out_grads[2][0] = -c0 * d; + out_grads[4][0] = s0 * d; + out_grads[2][1] = s0 * d; + out_grads[4][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + out_grads[9][0] = -c0 * d; + out_grads[11][0] = s0 * d; + out_grads[9][1] = s0 * d; + out_grads[11][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[20] = -c1 * d; + out_shs[22] = s1 * d; + out_grads[20][0] = -c0 * d; + out_grads[22][0] = s0 * d; + out_grads[20][1] = s0 * d; + out_grads[22][1] = c0 * d; + d = 88.106914343 * b; + out_grads[21][2] = d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[35] = -c1 * d; + out_shs[37] = s1 * d; + out_grads[35][0] = -c0 * d; + out_grads[37][0] = s0 * d; + out_grads[35][1] = s0 * d; + out_grads[37][1] = c0 * d; + d = 467.786944906 * b; + out_grads[36][2] = d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + out_shs[54] = -c1 * d; + out_shs[56] = s1 * d; + out_grads[54][0] = -c0 * d; + out_grads[56][0] = s0 * d; + out_grads[54][1] = s0 * d; + out_grads[56][1] = c0 * d; + d = 2332.401488133 * b; + out_grads[55][2] = d; + a = z2 * b - 0.248120301 * a; + b = a - 0.248447205 * b; + d = -1265.233874957 * b; + out_shs[77] = -c1 * d; + out_shs[79] = s1 * d; + out_grads[77][0] = -c0 * d; + out_grads[79][0] = s0 * d; + out_grads[77][1] = s0 * d; + out_grads[79][1] = c0 * d; + d = 11174.243023595 * b; + out_grads[78][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + d = 1.092548431; + out_grads[1][0] = c1 * d; + out_grads[5][0] = s1 * d; + out_grads[1][1] = -s1 * d; + out_grads[5][1] = c1 * d; + d = -1.092548431; + out_grads[2][2] = -c1 * d; + out_grads[4][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + d = 6.62322287 * a; + out_grads[8][0] = c1 * d; + out_grads[12][0] = s1 * d; + out_grads[8][1] = -s1 * d; + out_grads[12][1] = c1 * d; + d = -14.049977415 * a; + out_grads[9][2] = -c1 * d; + out_grads[11][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[19] = c0 * d; + out_shs[23] = s0 * d; + d = 30.399773564 * a; + out_grads[19][0] = c1 * d; + out_grads[23][0] = s1 * d; + out_grads[19][1] = -s1 * d; + out_grads[23][1] = c1 * d; + d = -96.132524816 * a; + out_grads[20][2] = -c1 * d; + out_grads[22][2] = s1 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[34] = c0 * d; + out_shs[38] = s0 * d; + d = 130.459545912 * a; + out_grads[34][0] = c1 * d; + out_grads[38][0] = s1 * d; + out_grads[34][1] = -s1 * d; + out_grads[38][1] = c1 * d; + d = -545.751435723 * a; + out_grads[35][2] = -c1 * d; + out_grads[37][2] = s1 * d; + b = z2 * a - 0.235294118 * b; + a = b - 0.238390093 * a; + d = 272.365814381 * a; + out_shs[53] = c0 * d; + out_shs[57] = s0 * d; + d = 544.731628762 * a; + out_grads[53][0] = c1 * d; + out_grads[57][0] = s1 * d; + out_grads[53][1] = -s1 * d; + out_grads[57][1] = c1 * d; + d = -2830.508572514 * a; + out_grads[54][2] = -c1 * d; + out_grads[56][2] = s1 * d; + b = z2 * a - 0.240601504 * b; + a = b - 0.242236025 * a; + d = 1121.509962433 * a; + out_shs[76] = c0 * d; + out_shs[80] = s0 * d; + d = 2243.019924866 * a; + out_grads[76][0] = c1 * d; + out_grads[80][0] = s1 * d; + out_grads[76][1] = -s1 * d; + out_grads[80][1] = c1 * d; + d = -13917.572624524 * a; + out_grads[77][2] = -c1 * d; + out_grads[79][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + d = -5.310392309 * z; + out_grads[7][0] = -c0 * d; + out_grads[13][0] = s0 * d; + out_grads[7][1] = s0 * d; + out_grads[13][1] = c0 * d; + d = 6.62322287 * z; + out_grads[8][2] = c0 * d; + out_grads[12][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[18] = -c1 * d; + out_shs[24] = s1 * d; + d = -30.399773564 * b; + out_grads[18][0] = -c0 * d; + out_grads[24][0] = s0 * d; + out_grads[18][1] = s0 * d; + out_grads[24][1] = c0 * d; + d = 60.799547128 * b; + out_grads[19][2] = c0 * d; + out_grads[23][2] = s0 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[33] = -c1 * d; + out_shs[39] = s1 * d; + d = -144.52614017 * b; + out_grads[33][0] = -c0 * d; + out_grads[39][0] = s0 * d; + out_grads[33][1] = s0 * d; + out_grads[39][1] = c0 * d; + d = 391.378637737 * b; + out_grads[34][2] = c0 * d; + out_grads[38][2] = s0 * d; + a = z2 * b - 0.215686275 * a; + b = a - 0.222910217 * b; + d = -213.661323441 * b; + out_shs[52] = -c1 * d; + out_shs[58] = s1 * d; + d = -640.983970322 * b; + out_grads[52][0] = -c0 * d; + out_grads[58][0] = s0 * d; + out_grads[52][1] = s0 * d; + out_grads[58][1] = c0 * d; + d = 2178.926515046 * b; + out_grads[53][2] = c0 * d; + out_grads[57][2] = s0 * d; + a = z2 * b - 0.228070175 * a; + b = a - 0.231884058 * b; + d = -915.709049803 * b; + out_shs[75] = -c1 * d; + out_shs[81] = s1 * d; + d = -2747.127149409 * b; + out_grads[75][0] = -c0 * d; + out_grads[81][0] = s0 * d; + out_grads[75][1] = s0 * d; + out_grads[81][1] = c0 * d; + d = 11215.099624332 * b; + out_grads[76][2] = c0 * d; + out_grads[80][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + d = 2.503342942; + out_grads[6][0] = c1 * d; + out_grads[14][0] = s1 * d; + out_grads[6][1] = -s1 * d; + out_grads[14][1] = c1 * d; + d = -1.77013077; + out_grads[7][2] = -c1 * d; + out_grads[13][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[17] = c0 * d; + out_shs[25] = s0 * d; + d = 22.200855632 * a; + out_grads[17][0] = c1 * d; + out_grads[25][0] = s1 * d; + out_grads[17][1] = -s1 * d; + out_grads[25][1] = c1 * d; + d = -30.399773564 * a; + out_grads[18][2] = -c1 * d; + out_grads[24][2] = s1 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[32] = c0 * d; + out_shs[40] = s0 * d; + d = 124.388296437 * a; + out_grads[32][0] = c1 * d; + out_grads[40][0] = s1 * d; + out_grads[32][1] = -s1 * d; + out_grads[40][1] = c1 * d; + d = -240.876900283 * a; + out_grads[33][2] = -c1 * d; + out_grads[39][2] = s1 * d; + b = z2 * a - 0.188235294 * b; + a = b - 0.20123839 * a; + d = 151.081370682 * a; + out_shs[51] = c0 * d; + out_shs[59] = s0 * d; + d = 604.325482728 * a; + out_grads[51][0] = c1 * d; + out_grads[59][0] = s1 * d; + out_grads[51][1] = -s1 * d; + out_grads[59][1] = c1 * d; + d = -1495.629264084 * a; + out_grads[52][2] = -c1 * d; + out_grads[58][2] = s1 * d; + b = z2 * a - 0.210526316 * b; + a = b - 0.217391304 * a; + d = 686.781787352 * a; + out_shs[74] = c0 * d; + out_shs[82] = s0 * d; + d = 2747.127149409 * a; + out_grads[74][0] = c1 * d; + out_grads[82][0] = s1 * d; + out_grads[74][1] = -s1 * d; + out_grads[82][1] = c1 * d; + d = -8241.381448228 * a; + out_grads[75][2] = -c1 * d; + out_grads[81][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[16] = -c1 * d; + out_shs[26] = s1 * d; + d = -11.833095811 * z; + out_grads[16][0] = -c0 * d; + out_grads[26][0] = s0 * d; + out_grads[16][1] = s0 * d; + out_grads[26][1] = c0 * d; + d = 11.100427816 * z; + out_grads[17][2] = c0 * d; + out_grads[25][2] = s0 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[31] = -c1 * d; + out_shs[41] = s1 * d; + d = -86.247765552 * b; + out_grads[31][0] = -c0 * d; + out_grads[41][0] = s0 * d; + out_grads[31][1] = s0 * d; + out_grads[41][1] = c0 * d; + d = 124.388296437 * b; + out_grads[32][2] = c0 * d; + out_grads[40][2] = s0 * d; + a = z2 * b - 0.152941176 * a; + b = a - 0.173374613 * b; + d = -95.552248675 * b; + out_shs[50] = -c1 * d; + out_shs[60] = s1 * d; + d = -477.761243376 * b; + out_grads[50][0] = -c0 * d; + out_grads[60][0] = s0 * d; + out_grads[50][1] = s0 * d; + out_grads[60][1] = c0 * d; + d = 906.488224092 * b; + out_grads[51][2] = c0 * d; + out_grads[59][2] = s0 * d; + a = z2 * b - 0.187969925 * a; + b = a - 0.198757764 * b; + d = -471.12841933 * b; + out_shs[73] = -c1 * d; + out_shs[83] = s1 * d; + d = -2355.642096651 * b; + out_grads[73][0] = -c0 * d; + out_grads[83][0] = s0 * d; + out_grads[73][1] = s0 * d; + out_grads[83][1] = c0 * d; + d = 5494.254298819 * b; + out_grads[74][2] = c0 * d; + out_grads[82][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[15] = c0 * d; + out_shs[27] = s0 * d; + d = 4.099104631; + out_grads[15][0] = c1 * d; + out_grads[27][0] = s1 * d; + out_grads[15][1] = -s1 * d; + out_grads[27][1] = c1 * d; + d = -2.366619162; + out_grads[16][2] = -c1 * d; + out_grads[26][2] = s1 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[30] = c0 * d; + out_shs[42] = s0 * d; + d = 47.909948945 * a; + out_grads[30][0] = c1 * d; + out_grads[42][0] = s1 * d; + out_grads[30][1] = -s1 * d; + out_grads[42][1] = c1 * d; + d = -51.748659331 * a; + out_grads[31][2] = -c1 * d; + out_grads[41][2] = s1 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + out_shs[49] = c0 * d; + out_shs[61] = s0 * d; + d = 320.491985161 * a; + out_grads[49][0] = c1 * d; + out_grads[61][0] = s1 * d; + out_grads[49][1] = -s1 * d; + out_grads[61][1] = c1 * d; + d = -477.761243376 * a; + out_grads[50][2] = -c1 * d; + out_grads[60][2] = s1 * d; + b = z2 * a - 0.160401003 * b; + a = b - 0.175983437 * a; + d = 293.800188384 * a; + out_shs[72] = c0 * d; + out_shs[84] = s0 * d; + d = 1762.801130306 * a; + out_grads[72][0] = c1 * d; + out_grads[84][0] = s1 * d; + out_grads[72][1] = -s1 * d; + out_grads[84][1] = c1 * d; + d = -3297.898935312 * a; + out_grads[73][2] = -c1 * d; + out_grads[83][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[29] = -c1 * d; + out_shs[43] = s1 * d; + d = -20.409946485 * z; + out_grads[29][0] = -c0 * d; + out_grads[43][0] = s0 * d; + out_grads[29][1] = s0 * d; + out_grads[43][1] = c0 * d; + d = 15.969982982 * z; + out_grads[30][2] = c0 * d; + out_grads[42][2] = s0 * d; + a = (z2 - 5.88235294e-02) * z; + b = a - 9.90712074e-02 * z; + d = -25.910241313 * b; + out_shs[48] = -c1 * d; + out_shs[62] = s1 * d; + d = -181.371689194 * b; + out_grads[48][0] = -c0 * d; + out_grads[62][0] = s0 * d; + out_grads[48][1] = s0 * d; + out_grads[62][1] = c0 * d; + d = 213.661323441 * b; + out_grads[49][2] = c0 * d; + out_grads[61][2] = s0 * d; + a = z2 * b - 0.127819549 * a; + b = a - 0.149068323 * b; + d = -165.101452729 * b; + out_shs[71] = -c1 * d; + out_shs[85] = s1 * d; + d = -1155.7101691 * b; + out_grads[71][0] = -c0 * d; + out_grads[85][0] = s0 * d; + out_grads[71][1] = s0 * d; + out_grads[85][1] = c0 * d; + d = 1762.801130306 * b; + out_grads[72][2] = c0 * d; + out_grads[84][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[28] = c0 * d; + out_shs[44] = s0 * d; + d = 5.831413281; + out_grads[28][0] = c1 * d; + out_grads[44][0] = s1 * d; + out_grads[28][1] = -s1 * d; + out_grads[44][1] = c1 * d; + d = -2.915706641; + out_grads[29][2] = -c1 * d; + out_grads[43][2] = s1 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + out_shs[47] = c0 * d; + out_shs[63] = s0 * d; + d = 84.622493774 * a; + out_grads[47][0] = c1 * d; + out_grads[63][0] = s1 * d; + out_grads[47][1] = -s1 * d; + out_grads[63][1] = c1 * d; + d = -77.73072394 * a; + out_grads[48][2] = -c1 * d; + out_grads[62][2] = s1 * d; + b = z2 * (a - 9.02255639e-02); + a = b - 0.118012422 * a; + d = 82.550726364 * a; + out_shs[70] = c0 * d; + out_shs[86] = s0 * d; + d = 660.405810914 * a; + out_grads[70][0] = c1 * d; + out_grads[86][0] = s1 * d; + out_grads[70][1] = -s1 * d; + out_grads[86][1] = c1 * d; + d = -825.507263643 * a; + out_grads[71][2] = -c1 * d; + out_grads[85][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + out_shs[46] = -c1 * d; + out_shs[64] = s1 * d; + d = -30.887057699 * z; + out_grads[46][0] = -c0 * d; + out_grads[64][0] = s0 * d; + out_grads[46][1] = s0 * d; + out_grads[64][1] = c0 * d; + d = 21.155623443 * z; + out_grads[47][2] = c0 * d; + out_grads[63][2] = s0 * d; + a = (z2 - 4.76190476e-02) * z; + b = a - 8.2815735e-02 * z; + d = -36.028090689 * b; + out_shs[69] = -c1 * d; + out_shs[87] = s1 * d; + d = -324.252816204 * b; + out_grads[69][0] = -c0 * d; + out_grads[87][0] = s0 * d; + out_grads[69][1] = s0 * d; + out_grads[87][1] = c0 * d; + d = 330.202905457 * b; + out_grads[70][2] = c0 * d; + out_grads[86][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + out_shs[45] = c0 * d; + out_shs[65] = s0 * d; + d = 7.673951182; + out_grads[45][0] = c1 * d; + out_grads[65][0] = s1 * d; + out_grads[45][1] = -s1 * d; + out_grads[65][1] = c1 * d; + d = -3.4318953; + out_grads[46][2] = -c1 * d; + out_grads[64][2] = s1 * d; + a = z2 - 4.34782609e-02; + d = 13.3042542 * a; + out_shs[68] = c0 * d; + out_shs[88] = s0 * d; + d = 133.042542003 * a; + out_grads[68][0] = c1 * d; + out_grads[88][0] = s1 * d; + out_grads[68][1] = -s1 * d; + out_grads[88][1] = c1 * d; + d = -108.084272068 * a; + out_grads[69][2] = -c1 * d; + out_grads[87][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.923210529 * z; + out_shs[67] = -c1 * d; + out_shs[89] = s1 * d; + d = -43.155315818 * z; + out_grads[67][0] = -c0 * d; + out_grads[89][0] = s0 * d; + out_grads[67][1] = s0 * d; + out_grads[89][1] = c0 * d; + d = 26.608508401 * z; + out_grads[68][2] = c0 * d; + out_grads[88][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.800821996; + out_shs[66] = c0 * d; + out_shs[90] = s0 * d; + d = 9.609863949; + out_grads[66][0] = c1 * d; + out_grads[90][0] = s1 * d; + out_grads[66][1] = -s1 * d; + out_grads[90][1] = c1 * d; + d = -3.923210529; + out_grads[67][2] = -c1 * d; + out_grads[89][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; + out_grads[6][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[14][2] = 0.0; + out_grads[15][2] = 0.0; + out_grads[21][0] = 0.0; + out_grads[21][1] = 0.0; + out_grads[27][2] = 0.0; + out_grads[28][2] = 0.0; + out_grads[36][0] = 0.0; + out_grads[36][1] = 0.0; + out_grads[44][2] = 0.0; + out_grads[45][2] = 0.0; + out_grads[55][0] = 0.0; + out_grads[55][1] = 0.0; + out_grads[65][2] = 0.0; + out_grads[66][2] = 0.0; + out_grads[78][0] = 0.0; + out_grads[78][1] = 0.0; + out_grads[90][2] = 0.0; +} diff --git a/fury/shaders/rt_odfs/eval_sh_grad_2.frag b/fury/shaders/rt_odfs/eval_sh_grad_2.frag new file mode 100644 index 000000000..7004bd528 --- /dev/null +++ b/fury/shaders/rt_odfs/eval_sh_grad_2.frag @@ -0,0 +1,46 @@ +void eval_sh_grad_2(out float out_shs[6], out vec3 out_grads[6], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + out_grads[2][0] = -c0 * d; + out_grads[4][0] = s0 * d; + out_grads[2][1] = s0 * d; + out_grads[4][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + d = 1.092548431; + out_grads[1][0] = c1 * d; + out_grads[5][0] = s1 * d; + out_grads[1][1] = -s1 * d; + out_grads[5][1] = c1 * d; + d = -1.092548431; + out_grads[2][2] = -c1 * d; + out_grads[4][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; +} diff --git a/fury/shaders/rt_odfs/eval_sh_grad_4.frag b/fury/shaders/rt_odfs/eval_sh_grad_4.frag new file mode 100644 index 000000000..715302f39 --- /dev/null +++ b/fury/shaders/rt_odfs/eval_sh_grad_4.frag @@ -0,0 +1,103 @@ +void eval_sh_grad_4(out float out_shs[15], out vec3 out_grads[15], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + out_grads[2][0] = -c0 * d; + out_grads[4][0] = s0 * d; + out_grads[2][1] = s0 * d; + out_grads[4][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + out_grads[9][0] = -c0 * d; + out_grads[11][0] = s0 * d; + out_grads[9][1] = s0 * d; + out_grads[11][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + d = 1.092548431; + out_grads[1][0] = c1 * d; + out_grads[5][0] = s1 * d; + out_grads[1][1] = -s1 * d; + out_grads[5][1] = c1 * d; + d = -1.092548431; + out_grads[2][2] = -c1 * d; + out_grads[4][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + d = 6.62322287 * a; + out_grads[8][0] = c1 * d; + out_grads[12][0] = s1 * d; + out_grads[8][1] = -s1 * d; + out_grads[12][1] = c1 * d; + d = -14.049977415 * a; + out_grads[9][2] = -c1 * d; + out_grads[11][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + d = -5.310392309 * z; + out_grads[7][0] = -c0 * d; + out_grads[13][0] = s0 * d; + out_grads[7][1] = s0 * d; + out_grads[13][1] = c0 * d; + d = 6.62322287 * z; + out_grads[8][2] = c0 * d; + out_grads[12][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + d = 2.503342942; + out_grads[6][0] = c1 * d; + out_grads[14][0] = s1 * d; + out_grads[6][1] = -s1 * d; + out_grads[14][1] = c1 * d; + d = -1.77013077; + out_grads[7][2] = -c1 * d; + out_grads[13][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; + out_grads[6][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[14][2] = 0.0; +} diff --git a/fury/shaders/rt_odfs/eval_sh_grad_6.frag b/fury/shaders/rt_odfs/eval_sh_grad_6.frag new file mode 100644 index 000000000..fa240c3a5 --- /dev/null +++ b/fury/shaders/rt_odfs/eval_sh_grad_6.frag @@ -0,0 +1,186 @@ +void eval_sh_grad_6(out float out_shs[28], out vec3 out_grads[28], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + out_grads[2][0] = -c0 * d; + out_grads[4][0] = s0 * d; + out_grads[2][1] = s0 * d; + out_grads[4][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + out_grads[9][0] = -c0 * d; + out_grads[11][0] = s0 * d; + out_grads[9][1] = s0 * d; + out_grads[11][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[20] = -c1 * d; + out_shs[22] = s1 * d; + out_grads[20][0] = -c0 * d; + out_grads[22][0] = s0 * d; + out_grads[20][1] = s0 * d; + out_grads[22][1] = c0 * d; + d = 88.106914343 * b; + out_grads[21][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + d = 1.092548431; + out_grads[1][0] = c1 * d; + out_grads[5][0] = s1 * d; + out_grads[1][1] = -s1 * d; + out_grads[5][1] = c1 * d; + d = -1.092548431; + out_grads[2][2] = -c1 * d; + out_grads[4][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + d = 6.62322287 * a; + out_grads[8][0] = c1 * d; + out_grads[12][0] = s1 * d; + out_grads[8][1] = -s1 * d; + out_grads[12][1] = c1 * d; + d = -14.049977415 * a; + out_grads[9][2] = -c1 * d; + out_grads[11][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[19] = c0 * d; + out_shs[23] = s0 * d; + d = 30.399773564 * a; + out_grads[19][0] = c1 * d; + out_grads[23][0] = s1 * d; + out_grads[19][1] = -s1 * d; + out_grads[23][1] = c1 * d; + d = -96.132524816 * a; + out_grads[20][2] = -c1 * d; + out_grads[22][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + d = -5.310392309 * z; + out_grads[7][0] = -c0 * d; + out_grads[13][0] = s0 * d; + out_grads[7][1] = s0 * d; + out_grads[13][1] = c0 * d; + d = 6.62322287 * z; + out_grads[8][2] = c0 * d; + out_grads[12][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[18] = -c1 * d; + out_shs[24] = s1 * d; + d = -30.399773564 * b; + out_grads[18][0] = -c0 * d; + out_grads[24][0] = s0 * d; + out_grads[18][1] = s0 * d; + out_grads[24][1] = c0 * d; + d = 60.799547128 * b; + out_grads[19][2] = c0 * d; + out_grads[23][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + d = 2.503342942; + out_grads[6][0] = c1 * d; + out_grads[14][0] = s1 * d; + out_grads[6][1] = -s1 * d; + out_grads[14][1] = c1 * d; + d = -1.77013077; + out_grads[7][2] = -c1 * d; + out_grads[13][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[17] = c0 * d; + out_shs[25] = s0 * d; + d = 22.200855632 * a; + out_grads[17][0] = c1 * d; + out_grads[25][0] = s1 * d; + out_grads[17][1] = -s1 * d; + out_grads[25][1] = c1 * d; + d = -30.399773564 * a; + out_grads[18][2] = -c1 * d; + out_grads[24][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[16] = -c1 * d; + out_shs[26] = s1 * d; + d = -11.833095811 * z; + out_grads[16][0] = -c0 * d; + out_grads[26][0] = s0 * d; + out_grads[16][1] = s0 * d; + out_grads[26][1] = c0 * d; + d = 11.100427816 * z; + out_grads[17][2] = c0 * d; + out_grads[25][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[15] = c0 * d; + out_shs[27] = s0 * d; + d = 4.099104631; + out_grads[15][0] = c1 * d; + out_grads[27][0] = s1 * d; + out_grads[15][1] = -s1 * d; + out_grads[27][1] = c1 * d; + d = -2.366619162; + out_grads[16][2] = -c1 * d; + out_grads[26][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; + out_grads[6][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[14][2] = 0.0; + out_grads[15][2] = 0.0; + out_grads[21][0] = 0.0; + out_grads[21][1] = 0.0; + out_grads[27][2] = 0.0; +} diff --git a/fury/shaders/rt_odfs/eval_sh_grad_8.frag b/fury/shaders/rt_odfs/eval_sh_grad_8.frag new file mode 100644 index 000000000..b0a40d0a7 --- /dev/null +++ b/fury/shaders/rt_odfs/eval_sh_grad_8.frag @@ -0,0 +1,295 @@ +void eval_sh_grad_8(out float out_shs[45], out vec3 out_grads[45], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[2] = -c1 * d; + out_shs[4] = s1 * d; + out_grads[2][0] = -c0 * d; + out_grads[4][0] = s0 * d; + out_grads[2][1] = s0 * d; + out_grads[4][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[9] = -c1 * d; + out_shs[11] = s1 * d; + out_grads[9][0] = -c0 * d; + out_grads[11][0] = s0 * d; + out_grads[9][1] = s0 * d; + out_grads[11][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[20] = -c1 * d; + out_shs[22] = s1 * d; + out_grads[20][0] = -c0 * d; + out_grads[22][0] = s0 * d; + out_grads[20][1] = s0 * d; + out_grads[22][1] = c0 * d; + d = 88.106914343 * b; + out_grads[21][2] = d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[35] = -c1 * d; + out_shs[37] = s1 * d; + out_grads[35][0] = -c0 * d; + out_grads[37][0] = s0 * d; + out_grads[35][1] = s0 * d; + out_grads[37][1] = c0 * d; + d = 467.786944906 * b; + out_grads[36][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[1] = c0 * d; + out_shs[5] = s0 * d; + d = 1.092548431; + out_grads[1][0] = c1 * d; + out_grads[5][0] = s1 * d; + out_grads[1][1] = -s1 * d; + out_grads[5][1] = c1 * d; + d = -1.092548431; + out_grads[2][2] = -c1 * d; + out_grads[4][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[8] = c0 * d; + out_shs[12] = s0 * d; + d = 6.62322287 * a; + out_grads[8][0] = c1 * d; + out_grads[12][0] = s1 * d; + out_grads[8][1] = -s1 * d; + out_grads[12][1] = c1 * d; + d = -14.049977415 * a; + out_grads[9][2] = -c1 * d; + out_grads[11][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[19] = c0 * d; + out_shs[23] = s0 * d; + d = 30.399773564 * a; + out_grads[19][0] = c1 * d; + out_grads[23][0] = s1 * d; + out_grads[19][1] = -s1 * d; + out_grads[23][1] = c1 * d; + d = -96.132524816 * a; + out_grads[20][2] = -c1 * d; + out_grads[22][2] = s1 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[34] = c0 * d; + out_shs[38] = s0 * d; + d = 130.459545912 * a; + out_grads[34][0] = c1 * d; + out_grads[38][0] = s1 * d; + out_grads[34][1] = -s1 * d; + out_grads[38][1] = c1 * d; + d = -545.751435723 * a; + out_grads[35][2] = -c1 * d; + out_grads[37][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[7] = -c1 * d; + out_shs[13] = s1 * d; + d = -5.310392309 * z; + out_grads[7][0] = -c0 * d; + out_grads[13][0] = s0 * d; + out_grads[7][1] = s0 * d; + out_grads[13][1] = c0 * d; + d = 6.62322287 * z; + out_grads[8][2] = c0 * d; + out_grads[12][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[18] = -c1 * d; + out_shs[24] = s1 * d; + d = -30.399773564 * b; + out_grads[18][0] = -c0 * d; + out_grads[24][0] = s0 * d; + out_grads[18][1] = s0 * d; + out_grads[24][1] = c0 * d; + d = 60.799547128 * b; + out_grads[19][2] = c0 * d; + out_grads[23][2] = s0 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[33] = -c1 * d; + out_shs[39] = s1 * d; + d = -144.52614017 * b; + out_grads[33][0] = -c0 * d; + out_grads[39][0] = s0 * d; + out_grads[33][1] = s0 * d; + out_grads[39][1] = c0 * d; + d = 391.378637737 * b; + out_grads[34][2] = c0 * d; + out_grads[38][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[6] = c0 * d; + out_shs[14] = s0 * d; + d = 2.503342942; + out_grads[6][0] = c1 * d; + out_grads[14][0] = s1 * d; + out_grads[6][1] = -s1 * d; + out_grads[14][1] = c1 * d; + d = -1.77013077; + out_grads[7][2] = -c1 * d; + out_grads[13][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[17] = c0 * d; + out_shs[25] = s0 * d; + d = 22.200855632 * a; + out_grads[17][0] = c1 * d; + out_grads[25][0] = s1 * d; + out_grads[17][1] = -s1 * d; + out_grads[25][1] = c1 * d; + d = -30.399773564 * a; + out_grads[18][2] = -c1 * d; + out_grads[24][2] = s1 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[32] = c0 * d; + out_shs[40] = s0 * d; + d = 124.388296437 * a; + out_grads[32][0] = c1 * d; + out_grads[40][0] = s1 * d; + out_grads[32][1] = -s1 * d; + out_grads[40][1] = c1 * d; + d = -240.876900283 * a; + out_grads[33][2] = -c1 * d; + out_grads[39][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[16] = -c1 * d; + out_shs[26] = s1 * d; + d = -11.833095811 * z; + out_grads[16][0] = -c0 * d; + out_grads[26][0] = s0 * d; + out_grads[16][1] = s0 * d; + out_grads[26][1] = c0 * d; + d = 11.100427816 * z; + out_grads[17][2] = c0 * d; + out_grads[25][2] = s0 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[31] = -c1 * d; + out_shs[41] = s1 * d; + d = -86.247765552 * b; + out_grads[31][0] = -c0 * d; + out_grads[41][0] = s0 * d; + out_grads[31][1] = s0 * d; + out_grads[41][1] = c0 * d; + d = 124.388296437 * b; + out_grads[32][2] = c0 * d; + out_grads[40][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[15] = c0 * d; + out_shs[27] = s0 * d; + d = 4.099104631; + out_grads[15][0] = c1 * d; + out_grads[27][0] = s1 * d; + out_grads[15][1] = -s1 * d; + out_grads[27][1] = c1 * d; + d = -2.366619162; + out_grads[16][2] = -c1 * d; + out_grads[26][2] = s1 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[30] = c0 * d; + out_shs[42] = s0 * d; + d = 47.909948945 * a; + out_grads[30][0] = c1 * d; + out_grads[42][0] = s1 * d; + out_grads[30][1] = -s1 * d; + out_grads[42][1] = c1 * d; + d = -51.748659331 * a; + out_grads[31][2] = -c1 * d; + out_grads[41][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[29] = -c1 * d; + out_shs[43] = s1 * d; + d = -20.409946485 * z; + out_grads[29][0] = -c0 * d; + out_grads[43][0] = s0 * d; + out_grads[29][1] = s0 * d; + out_grads[43][1] = c0 * d; + d = 15.969982982 * z; + out_grads[30][2] = c0 * d; + out_grads[42][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[28] = c0 * d; + out_shs[44] = s0 * d; + d = 5.831413281; + out_grads[28][0] = c1 * d; + out_grads[44][0] = s1 * d; + out_grads[28][1] = -s1 * d; + out_grads[44][1] = c1 * d; + d = -2.915706641; + out_grads[29][2] = -c1 * d; + out_grads[43][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; + out_grads[6][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[14][2] = 0.0; + out_grads[15][2] = 0.0; + out_grads[21][0] = 0.0; + out_grads[21][1] = 0.0; + out_grads[27][2] = 0.0; + out_grads[28][2] = 0.0; + out_grads[36][0] = 0.0; + out_grads[36][1] = 0.0; + out_grads[44][2] = 0.0; +} diff --git a/fury/shaders/rt_odfs/find_roots.frag b/fury/shaders/rt_odfs/find_roots.frag new file mode 100644 index 000000000..e5b80f7a4 --- /dev/null +++ b/fury/shaders/rt_odfs/find_roots.frag @@ -0,0 +1,82 @@ +void find_roots(out float out_roots[MAX_DEGREE + 1], float poly[MAX_DEGREE + 1], float begin, float end) { + float tolerance = (end - begin) * 1.0e-4; + // Construct the quadratic derivative of the polynomial. We divide each + // derivative by the factorial of its order, such that the constant + // coefficient can be copied directly from poly. That is a safeguard + // against overflow and makes it easier to avoid spilling below. The + // factors happen to be binomial coefficients then. + float derivative[MAX_DEGREE + 1]; + derivative[0] = poly[MAX_DEGREE - 2]; + derivative[1] = float(MAX_DEGREE - 1) * poly[MAX_DEGREE - 1]; + derivative[2] = (0.5 * float((MAX_DEGREE - 1) * MAX_DEGREE)) * poly[MAX_DEGREE - 0]; + _unroll_ + for (int i = 3; i != MAX_DEGREE + 1; ++i) + derivative[i] = 0.0; + // Compute its two roots using the quadratic formula + float discriminant = derivative[1] * derivative[1] - 4.0 * derivative[0] * derivative[2]; + if (discriminant >= 0.0) { + float sqrt_discriminant = sqrt(discriminant); + float scaled_root = derivative[1] + ((derivative[1] > 0.0) ? sqrt_discriminant : (-sqrt_discriminant)); + float root_0 = clamp(-2.0 * derivative[0] / scaled_root, begin, end); + float root_1 = clamp(-0.5 * scaled_root / derivative[2], begin, end); + out_roots[MAX_DEGREE - 2] = min(root_0, root_1); + out_roots[MAX_DEGREE - 1] = max(root_0, root_1); + } + else { + // Indicate that the cubic derivative has a single root + out_roots[MAX_DEGREE - 2] = begin; + out_roots[MAX_DEGREE - 1] = begin; + } + // The last entry in the root array is set to end to make it easier to + // iterate over relevant intervals, all untouched roots are set to begin + out_roots[MAX_DEGREE] = end; + _unroll_ + for (int i = 0; i != MAX_DEGREE - 2; ++i) + out_roots[i] = begin; + // Work your way up to derivatives of higher degree until you reach the + // polynomial itself. This implementation may seem peculiar: It always + // treats the derivative as though it had degree MAX_DEGREE and it + // constructs the derivatives in a contrived way. Changing that would + // reduce the number of arithmetic instructions roughly by a factor of two. + // However, it would also cause register spilling, which has a far more + // negative impact on the overall run time. Profiling indicates that the + // current implementation has no spilling whatsoever. + _loop_ + for (int degree = 3; degree != MAX_DEGREE + 1; ++degree) { + // Take the integral of the previous derivative (scaled such that the + // constant coefficient can still be copied directly from poly) + float prev_derivative_order = float(MAX_DEGREE + 1 - degree); + _unroll_ + for (int i = MAX_DEGREE; i != 0; --i) + derivative[i] = derivative[i - 1] * (prev_derivative_order * (1.0 / float(i))); + // Copy the constant coefficient without causing spilling. This part + // would be harder if the derivative were not scaled the way it is. + _unroll_ + for (int i = 0; i != MAX_DEGREE - 2; ++i) + derivative[0] = (degree == MAX_DEGREE - i) ? poly[i] : derivative[0]; + // Determine the value of this derivative at begin + float begin_value = derivative[MAX_DEGREE]; + _unroll_ + for (int i = MAX_DEGREE - 1; i != -1; --i) + begin_value = begin_value * begin + derivative[i]; + // Iterate over the intervals where roots may be found + _unroll_ + for (int i = 0; i != MAX_DEGREE; ++i) { + if (i < MAX_DEGREE - degree) + continue; + float current_begin = out_roots[i]; + float current_end = out_roots[i + 1]; + // Try to find a root + float root; + if (newton_bisection(root, begin_value, derivative, current_begin, current_end, begin_value, tolerance)) + out_roots[i] = root; + else if (degree < MAX_DEGREE) + // Create an empty interval for the next iteration + out_roots[i] = out_roots[i - 1]; + else + out_roots[i] = NO_INTERSECTION; + } + } + // We no longer need this array entry + out_roots[MAX_DEGREE] = NO_INTERSECTION; +} diff --git a/fury/shaders/rt_odfs/get_inv_vandermonde.frag b/fury/shaders/rt_odfs/get_inv_vandermonde.frag new file mode 100644 index 000000000..4c7f521c0 --- /dev/null +++ b/fury/shaders/rt_odfs/get_inv_vandermonde.frag @@ -0,0 +1,58 @@ +void get_inv_vandermonde(out float v[(SH_DEGREE + 1) * (SH_DEGREE + 1)]) +{ + #if SH_DEGREE == 2 + v[0*3 + 0] = -0.3333333333; v[0*3 + 1] = 0.6666666667; v[0*3 + 2] = 0.6666666667; + v[1*3 + 0] = -0.0; v[1*3 + 1] = 1.1547005384; v[1*3 + 2] = -1.1547005384; + v[2*3 + 0] = 1.0; v[2*3 + 1] = 0.0; v[2*3 + 2] = 0.0; + #elif SH_DEGREE == 4 + v[0*5 + 0] = 0.2; v[0*5 + 1] = -0.2472135955; v[0*5 + 2] = 0.6472135955; v[0*5 + 3] = 0.6472135955; v[0*5 + 4] = -0.2472135955; + v[1*5 + 0] = 0.0; v[1*5 + 1] = -0.1796111906; v[1*5 + 2] = 1.9919186279; v[1*5 + 3] = -1.9919186279; v[1*5 + 4] = 0.1796111906; + v[2*5 + 0] = -2.0; v[2*5 + 1] = 2.3416407865; v[2*5 + 2] = -0.3416407865; v[2*5 + 3] = -0.3416407865; v[2*5 + 4] = 2.3416407865; + v[3*5 + 0] = -0.0; v[3*5 + 1] = 1.7013016167; v[3*5 + 2] = -1.0514622242; v[3*5 + 3] = 1.0514622242; v[3*5 + 4] = -1.7013016167; + v[4*5 + 0] = 1.0; v[4*5 + 1] = 0.0; v[4*5 + 2] = 0.0; v[4*5 + 3] = 0.0; v[4*5 + 4] = 0.0; + #elif SH_DEGREE == 6 + v[0*7 + 0] = -0.1428571429; v[0*7 + 1] = 0.1585594663; v[0*7 + 2] = -0.2291250674; v[0*7 + 3] = 0.6419941725; v[0*7 + 4] = 0.6419941725; v[0*7 + 5] = -0.2291250674; v[0*7 + 6] = 0.1585594663; + v[1*7 + 0] = -0.0; v[1*7 + 1] = 0.0763582145; v[1*7 + 2] = -0.2873137468; v[1*7 + 3] = 2.8127602518; v[1*7 + 4] = -2.8127602518; v[1*7 + 5] = 0.2873137468; v[1*7 + 6] = -0.0763582145; + v[2*7 + 0] = 3.0; v[2*7 + 1] = -3.2929766145; v[2*7 + 2] = 4.4513463718; v[2*7 + 3] = -1.1583697574; v[2*7 + 4] = -1.1583697574; v[2*7 + 5] = 4.4513463718; v[2*7 + 6] = -3.2929766145; + v[3*7 + 0] = 0.0; v[3*7 + 1] = -1.5858139579; v[3*7 + 2] = 5.5818117995; v[3*7 + 3] = -5.0751495106; v[3*7 + 4] = 5.0751495106; v[3*7 + 5] = -5.5818117995; v[3*7 + 6] = 1.5858139579; + v[4*7 + 0] = -5.0; v[4*7 + 1] = 4.7858935686; v[4*7 + 2] = -1.0200067492; v[4*7 + 3] = 0.2341131806; v[4*7 + 4] = 0.2341131806; v[4*7 + 5] = -1.0200067492; v[4*7 + 6] = 4.7858935686; + v[5*7 + 0] = -0.0; v[5*7 + 1] = 2.3047648710; v[5*7 + 2] = -1.2790480077; v[5*7 + 3] = 1.0257168633; v[5*7 + 4] = -1.0257168633; v[5*7 + 5] = 1.2790480077; v[5*7 + 6] = -2.3047648710; + v[6*7 + 0] = 1.0; v[6*7 + 1] = 0.0; v[6*7 + 2] = 0.0; v[6*7 + 3] = 0.0; v[6*7 + 4] = 0.0; v[6*7 + 5] = 0.0; v[6*7 + 6] = 0.0; + #elif SH_DEGREE == 8 + v[0*9 + 0] = 0.1111111111; v[0*9 + 1] = -0.1182419747; v[0*9 + 2] = 0.1450452544; v[0*9 + 3] = -0.2222222222; v[0*9 + 4] = 0.6398633870; v[0*9 + 5] = 0.6398633870; v[0*9 + 6] = -0.2222222222; v[0*9 + 7] = 0.1450452544; v[0*9 + 8] = -0.1182419747; + v[1*9 + 0] = 0.0; v[1*9 + 1] = -0.0430365592; v[1*9 + 2] = 0.1217074194; v[1*9 + 3] = -0.3849001795; v[1*9 + 4] = 3.6288455938; v[1*9 + 5] = -3.6288455938; v[1*9 + 6] = 0.3849001795; v[1*9 + 7] = -0.1217074194; v[1*9 + 8] = 0.0430365592; + v[2*9 + 0] = -4.0; v[2*9 + 1] = 4.2410470634; v[2*9 + 2] = -5.1195045066; v[2*9 + 3] = 7.3333333333; v[2*9 + 4] = -2.4548758901; v[2*9 + 5] = -2.4548758901; v[2*9 + 6] = 7.3333333333; v[2*9 + 7] = -5.1195045066; v[2*9 + 8] = 4.2410470634; + v[3*9 + 0] = -0.0; v[3*9 + 1] = 1.5436148932; v[3*9 + 2] = -4.2957743433; v[3*9 + 3] = 12.7017059222; v[3*9 + 4] = -13.9222930051; v[3*9 + 5] = 13.9222930051; v[3*9 + 6] = -12.7017059222; v[3*9 + 7] = 4.2957743433; v[3*9 + 8] = -1.5436148932; + v[4*9 + 0] = 14.0; v[4*9 + 1] = -14.3366589404; v[4*9 + 2] = 14.6711193836; v[4*9 + 3] = -6.0; v[4*9 + 4] = 1.6655395568; v[4*9 + 5] = 1.6655395568; v[4*9 + 6] = -6.0; v[4*9 + 7] = 14.6711193836; v[4*9 + 8] = -14.3366589404; + v[5*9 + 0] = 0.0; v[5*9 + 1] = -5.2181171131; v[5*9 + 2] = 12.3105308637; v[5*9 + 3] = -10.3923048454; v[5*9 + 4] = 9.4457442082; v[5*9 + 5] = -9.4457442082; v[5*9 + 6] = 10.3923048454; v[5*9 + 7] = -12.3105308637; v[5*9 + 8] = 5.2181171131; + v[6*9 + 0] = -9.3333333333; v[6*9 + 1] = 8.0330865684; v[6*9 + 2] = -1.8540394597; v[6*9 + 3] = 0.6666666667; v[6*9 + 4] = -0.1790471086; v[6*9 + 5] = -0.1790471086; v[6*9 + 6] = 0.6666666667; v[6*9 + 7] = -1.8540394597; v[6*9 + 8] = 8.0330865684; + v[7*9 + 0] = -0.0; v[7*9 + 1] = 2.9238044002; v[7*9 + 2] = -1.5557238269; v[7*9 + 3] = 1.1547005384; v[7*9 + 4] = -1.0154266119; v[7*9 + 5] = 1.0154266119; v[7*9 + 6] = -1.1547005384; v[7*9 + 7] = 1.5557238269; v[7*9 + 8] = -2.9238044002; + v[8*9 + 0] = 1.0; v[8*9 + 1] = 0.0; v[8*9 + 2] = 0.0; v[8*9 + 3] = 0.0; v[8*9 + 4] = 0.0; v[8*9 + 5] = 0.0; v[8*9 + 6] = 0.0; v[8*9 + 7] = 0.0; v[8*9 + 8] = 0.0; + #elif SH_DEGREE == 10 + v[0*11 + 0] = -0.0909090909; v[0*11 + 1] = 0.0947470106; v[0*11 + 2] = -0.1080638444; v[0*11 + 3] = 0.1388220215; v[0*11 + 4] = -0.2188392043; v[0*11 + 5] = 0.6387885621; v[0*11 + 6] = 0.6387885621; v[0*11 + 7] = -0.2188392043; v[0*11 + 8] = 0.1388220215; v[0*11 + 9] = -0.1080638444; v[0*11 + 10] = 0.0947470106; + v[1*11 + 0] = -0.0; v[1*11 + 1] = 0.0278202324; v[1*11 + 2] = -0.0694484159; v[1*11 + 3] = 0.1602091533; v[1*11 + 4] = -0.4791910159; v[1*11 + 5] = 4.4428720384; v[1*11 + 6] = -4.4428720384; v[1*11 + 7] = 0.4791910159; v[1*11 + 8] = -0.1602091533; v[1*11 + 9] = 0.0694484159; v[1*11 + 10] = -0.0278202324; + v[2*11 + 0] = 5.0; v[2*11 + 1] = -5.2029168239; v[2*11 + 2] = 5.8988796576; v[2*11 + 3] = -7.4503199653; v[2*11 + 4] = 10.9868742757; v[2*11 + 5] = -4.2325171441; v[2*11 + 6] = -4.2325171441; v[2*11 + 7] = 10.9868742757; v[2*11 + 8] = -7.4503199653; v[2*11 + 9] = 5.8988796576; v[2*11 + 10] = -5.2029168239; + v[3*11 + 0] = 0.0; v[3*11 + 1] = -1.5277142200; v[3*11 + 2] = 3.7909797649; v[3*11 + 3] = -8.5981275876; v[3*11 + 4] = 24.0578988657; v[3*11 + 5] = -29.4378033460; v[3*11 + 6] = 29.4378033460; v[3*11 + 7] = -24.0578988657; v[3*11 + 8] = 8.5981275876; v[3*11 + 9] = -3.7909797649; v[3*11 + 10] = 1.5277142200; + v[4*11 + 0] = -30.0; v[4*11 + 1] = 30.8179361182; v[4*11 + 2] = -33.2247539061; v[4*11 + 3] = 35.8884989085; v[4*11 + 4] = -19.5374870834; v[4*11 + 5] = 6.0558059629; v[4*11 + 6] = 6.0558059629; v[4*11 + 7] = -19.5374870834; v[4*11 + 8] = 35.8884989085; v[4*11 + 9] = -33.2247539061; v[4*11 + 10] = 30.8179361182; + v[5*11 + 0] = -0.0; v[5*11 + 1] = 9.0489625020; v[5*11 + 2] = -21.3522528115; v[5*11 + 3] = 41.4175356200; v[5*11 + 4] = -42.7811292411; v[5*11 + 5] = 42.1190556280; v[5*11 + 6] = -42.1190556280; v[5*11 + 7] = 42.7811292411; v[5*11 + 8] = -41.4175356200; v[5*11 + 9] = 21.3522528115; v[5*11 + 10] = -9.0489625020; + v[6*11 + 0] = 42.0; v[6*11 + 1] = -41.1161037573; v[6*11 + 2] = 36.2032364762; v[6*11 + 3] = -16.3373898141; v[6*11 + 4] = 7.4261062994; v[6*11 + 5] = -2.1758492042; v[6*11 + 6] = -2.1758492042; v[6*11 + 7] = 7.4261062994; v[6*11 + 8] = -16.3373898141; v[6*11 + 9] = 36.2032364762; v[6*11 + 10] = -41.1161037573; + v[7*11 + 0] = 0.0; v[7*11 + 1] = -12.0727773496; v[7*11 + 2] = 23.2664073304; v[7*11 + 3] = -18.8543529304; v[7*11 + 4] = 16.2609045881; v[7*11 + 5] = -15.1333636234; v[7*11 + 6] = 15.1333636234; v[7*11 + 7] = -16.2609045881; v[7*11 + 8] = 18.8543529304; v[7*11 + 9] = -23.2664073304; v[7*11 + 10] = 12.0727773496; + v[8*11 + 0] = -15.0; v[8*11 + 1] = 12.0883694702; v[8*11 + 2] = -2.8781222629; v[8*11 + 3] = 1.1465503415; v[8*11 + 4] = -0.5020543475; v[8*11 + 5] = 0.1452567988; v[8*11 + 6] = 0.1452567988; v[8*11 + 7] = -0.5020543475; v[8*11 + 8] = 1.1465503415; v[8*11 + 9] = -2.8781222629; v[8*11 + 10] = 12.0883694702; + v[9*11 + 0] = -0.0; v[9*11 + 1] = 3.5494655329; v[9*11 + 2] = -1.8496568659; v[9*11 + 3] = 1.3231896304; v[9*11 + 4] = -1.0993456751; v[9*11 + 5] = 1.0102832265; v[9*11 + 6] = -1.0102832265; v[9*11 + 7] = 1.0993456751; v[9*11 + 8] = -1.3231896304; v[9*11 + 9] = 1.8496568659; v[9*11 + 10] = -3.5494655329; + v[10*11 + 0] = 1.0; v[10*11 + 1] = 0.0; v[10*11 + 2] = 0.0; v[10*11 + 3] = 0.0; v[10*11 + 4] = 0.0; v[10*11 + 5] = 0.0; v[10*11 + 6] = 0.0; v[10*11 + 7] = 0.0; v[10*11 + 8] = 0.0; v[10*11 + 9] = 0.0; v[10*11 + 10] = 0.0; + #elif SH_DEGREE == 12 + v[0*13 + 0] = 0.0769230769; v[0*13 + 1] = -0.0792252178; v[0*13 + 2] = 0.0868739663; v[0*13 + 3] = -0.1027681661; v[0*13 + 4] = 0.1354125166; v[0*13 + 5] = -0.2169261613; v[0*13 + 6] = 0.6381715239; v[0*13 + 7] = 0.6381715239; v[0*13 + 8] = -0.2169261613; v[0*13 + 9] = 0.1354125166; v[0*13 + 10] = -0.1027681661; v[0*13 + 11] = 0.0868739663; v[0*13 + 12] = -0.0792252178; + v[1*13 + 0] = -0.0; v[1*13 + 1] = -0.0195272624; v[1*13 + 2] = 0.0455949748; v[1*13 + 3] = -0.0910446506; v[1*13 + 4] = 0.1961788986; v[1*13 + 5] = -0.5719872785; v[1*13 + 6] = 5.2558153553; v[1*13 + 7] = -5.2558153553; v[1*13 + 8] = 0.5719872785; v[1*13 + 9] = -0.1961788986; v[1*13 + 10] = 0.0910446506; v[1*13 + 11] = -0.0455949748; v[1*13 + 12] = 0.0195272624; + v[2*13 + 0] = -6.0; v[2*13 + 1] = 6.1747539478; v[2*13 + 2] = -6.7522392818; v[2*13 + 3] = 7.9352584366; v[2*13 + 4] = -10.2779620900; v[2*13 + 5] = 15.4120340799; v[2*13 + 6] = -6.4918450925; v[2*13 + 7] = -6.4918450925; v[2*13 + 8] = 15.4120340799; v[2*13 + 9] = -10.2779620900; v[2*13 + 10] = 7.9352584366; v[2*13 + 11] = -6.7522392818; v[2*13 + 12] = 6.1747539478; + v[3*13 + 0] = -0.0; v[3*13 + 1] = 1.5219401578; v[3*13 + 2] = -3.5438485554; v[3*13 + 3] = 7.0300255289; v[3*13 + 4] = -14.8901987371; v[3*13 + 5] = 40.6381940129; v[3*13 + 6] = -53.4651544987; v[3*13 + 7] = 53.4651544987; v[3*13 + 8] = -40.6381940129; v[3*13 + 9] = 14.8901987371; v[3*13 + 10] = -7.0300255289; v[3*13 + 11] = 3.5438485554; v[3*13 + 12] = -1.5219401578; + v[4*13 + 0] = 55.0; v[4*13 + 1] = -56.2709061445; v[4*13 + 2] = 60.2549306937; v[4*13 + 3] = -67.2511796347; v[4*13 + 4] = 75.2477722397; v[4*13 + 5] = -47.9480941911; v[4*13 + 6] = 15.9674770369; v[4*13 + 7] = 15.9674770369; v[4*13 + 8] = -47.9480941911; v[4*13 + 9] = 75.2477722397; v[4*13 + 10] = -67.2511796347; v[4*13 + 11] = 60.2549306937; v[4*13 + 12] = -56.2709061445; + v[5*13 + 0] = 0.0; v[5*13 + 1] = -13.8695326974; v[5*13 + 2] = 31.6242271914; v[5*13 + 3] = -59.5793462127; v[5*13 + 4] = 109.0152185187; v[5*13 + 5] = -126.4287338180; v[5*13 + 6] = 131.5040045727; v[5*13 + 7] = -131.5040045727; v[5*13 + 8] = 126.4287338180; v[5*13 + 9] = -109.0152185187; v[5*13 + 10] = 59.5793462127; v[5*13 + 11] = -31.6242271914; v[5*13 + 12] = 13.8695326974; + v[6*13 + 0] = -132.0; v[6*13 + 1] = 132.5319409049; v[6*13 + 2] = -132.4780513404; v[6*13 + 3] = 123.5674782081; v[6*13 + 4] = -74.4320682907; v[6*13 + 5] = 38.8801193717; v[6*13 + 6] = -12.0694188537; v[6*13 + 7] = -12.0694188537; v[6*13 + 8] = 38.8801193717; v[6*13 + 9] = -74.4320682907; v[6*13 + 10] = 123.5674782081; v[6*13 + 11] = -132.4780513404; v[6*13 + 12] = 132.5319409049; + v[7*13 + 0] = -0.0; v[7*13 + 1] = 32.6661895777; v[7*13 + 2] = -69.5298450306; v[7*13 + 3] = 109.4712331409; v[7*13 + 4] = -107.8334673306; v[7*13 + 5] = 102.5184492897; v[7*13 + 6] = -99.4006071501; v[7*13 + 7] = 99.4006071501; v[7*13 + 8] = -102.5184492897; v[7*13 + 9] = 107.8334673306; v[7*13 + 10] = -109.4712331409; v[7*13 + 11] = 69.5298450306; v[7*13 + 12] = -32.6661895777; + v[8*13 + 0] = 99.0; v[8*13 + 1] = -93.9113626635; v[8*13 + 2] = 75.3147168618; v[8*13 + 3] = -35.2795800772; v[8*13 + 4] = 18.0521608541; v[8*13 + 5] = -8.8650350126; v[8*13 + 6] = 2.6891000373; v[8*13 + 7] = 2.6891000373; v[8*13 + 8] = -8.8650350126; v[8*13 + 9] = 18.0521608541; v[8*13 + 10] = -35.2795800772; v[8*13 + 11] = 75.3147168618; v[8*13 + 12] = -93.9113626635; + v[9*13 + 0] = 0.0; v[9*13 + 1] = -23.1470719837; v[9*13 + 2] = 39.5282127035; v[9*13 + 3] = -31.2549806126; v[9*13 + 4] = 26.1530700733; v[9*13 + 5] = -23.3751762359; v[9*13 + 6] = 22.1467313083; v[9*13 + 7] = -22.1467313083; v[9*13 + 8] = 23.3751762359; v[9*13 + 9] = -26.1530700733; v[9*13 + 10] = 31.2549806126; v[9*13 + 11] = -39.5282127035; v[9*13 + 12] = 23.1470719837; + v[10*13 + 0] = -22.0; v[10*13 + 1] = 16.9531714429; v[10*13 + 2] = -4.0999479387; v[10*13 + 3] = 1.7021989010; v[10*13 + 4] = -0.8387165175; v[10*13 + 5] = 0.4056079008; v[10*13 + 6] = -0.1223137885; v[10*13 + 7] = -0.1223137885; v[10*13 + 8] = 0.4056079008; v[10*13 + 9] = -0.8387165175; v[10*13 + 10] = 1.7021989010; v[10*13 + 11] = -4.0999479387; v[10*13 + 12] = 16.9531714429; + v[11*13 + 0] = -0.0; v[11*13 + 1] = 4.1785814689; v[11*13 + 2] = -2.1518186743; v[11*13 + 3] = 1.5080166355; v[11*13 + 4] = -1.2150906493; v[11*13 + 5] = 1.0695001374; v[11*13 + 6] = -1.0073446769; v[11*13 + 7] = 1.0073446769; v[11*13 + 8] = -1.0695001374; v[11*13 + 9] = 1.2150906493; v[11*13 + 10] = -1.5080166355; v[11*13 + 11] = 2.1518186743; v[11*13 + 12] = -4.1785814689; + v[12*13 + 0] = 1.0; v[12*13 + 1] = 0.0; v[12*13 + 2] = 0.0; v[12*13 + 3] = 0.0; v[12*13 + 4] = 0.0; v[12*13 + 5] = 0.0; v[12*13 + 6] = 0.0; v[12*13 + 7] = 0.0; v[12*13 + 8] = 0.0; v[12*13 + 9] = 0.0; v[12*13 + 10] = 0.0; v[12*13 + 11] = 0.0; v[12*13 + 12] = 0.0; + #endif +} diff --git a/fury/shaders/rt_odfs/get_sh_glyph_normal.frag b/fury/shaders/rt_odfs/get_sh_glyph_normal.frag new file mode 100644 index 000000000..4831fb8b4 --- /dev/null +++ b/fury/shaders/rt_odfs/get_sh_glyph_normal.frag @@ -0,0 +1,16 @@ +vec3 get_sh_glyph_normal(float sh_coeffs[SH_COUNT], vec3 point) +{ + float shs[SH_COUNT]; + vec3 grads[SH_COUNT]; + float length_inv = inversesqrt(dot(point, point)); + vec3 normalized = point * length_inv; + eval_sh_grad(shs, grads, normalized); + float value = 0.0; + vec3 grad = vec3(0.0); + _unroll_ + for (int i = 0; i != SH_COUNT; ++i) { + value += sh_coeffs[i] * shs[i]; + grad += sh_coeffs[i] * grads[i]; + } + return normalize(point - (value * length_inv) * (grad - dot(grad, normalized) * normalized)); +} diff --git a/fury/shaders/rt_odfs/gltf_dielectric_brdf.frag b/fury/shaders/rt_odfs/gltf_dielectric_brdf.frag new file mode 100644 index 000000000..465ab2266 --- /dev/null +++ b/fury/shaders/rt_odfs/gltf_dielectric_brdf.frag @@ -0,0 +1,41 @@ +vec3 gltf_dielectric_brdf(vec3 incoming, vec3 outgoing, vec3 normal, float roughness, vec3 base_color) +{ + float ni = dot(normal, incoming); + float no = dot(normal, outgoing); + // Early out if incoming or outgoing direction are below the horizon + if (ni <= 0.0 || no <= 0.0) + return vec3(0.0); + // Save some work by not actually computing the half-vector. If the half- + // vector were h, ih = dot(incoming, h) and + // sqrt(nh_ih_2 / ih_2) = dot(normal, h). + float ih_2 = dot(incoming, outgoing) * 0.5 + 0.5; + float sum = ni + no; + float nh_ih_2 = 0.25 * sum * sum; + float ih = sqrt(ih_2); + + // Evaluate the GGX normal distribution function + float roughness_2 = roughness * roughness; + float roughness_4 = roughness_2 * roughness_2; + float roughness_flip = 1.0 - roughness_4; + float denominator = ih_2 - nh_ih_2 * roughness_flip; + float ggx = (roughness_4 * M_INV_PI * ih_2) / (denominator * denominator); + // Evaluate the "visibility" (i.e. masking-shadowing times geometry terms) + float vi = ni + sqrt(roughness_4 + roughness_flip * ni * ni); + float vo = no + sqrt(roughness_4 + roughness_flip * no * no); + float v = 1.0 / (vi * vo); + // That completes the specular BRDF + float specular = v * ggx; + + // The diffuse BRDF is Lambertian + vec3 diffuse = M_INV_PI * base_color; + + // Evaluate the Fresnel term using the Fresnel-Schlick approximation + const float ior = 1.5; + const float f0 = ((1.0 - ior) / (1.0 + ior)) * ((1.0 - ior) / (1.0 + ior)); + float ih_flip = 1.0 - ih; + float ih_flip_2 = ih_flip * ih_flip; + float fresnel = f0 + (1.0 - f0) * ih_flip * ih_flip_2 * ih_flip_2; + + // Mix the two components + return mix(diffuse, vec3(specular), fresnel); +} diff --git a/fury/shaders/rt_odfs/linear_rgb_to_srgb.frag b/fury/shaders/rt_odfs/linear_rgb_to_srgb.frag new file mode 100644 index 000000000..d1c72c83b --- /dev/null +++ b/fury/shaders/rt_odfs/linear_rgb_to_srgb.frag @@ -0,0 +1,4 @@ +vec3 linear_rgb_to_srgb(vec3 linear) +{ + return vec3(linear_to_srgb(linear.r), linear_to_srgb(linear.g), linear_to_srgb(linear.b)); +} diff --git a/fury/shaders/rt_odfs/linear_to_srgb.frag b/fury/shaders/rt_odfs/linear_to_srgb.frag new file mode 100644 index 000000000..ac686853c --- /dev/null +++ b/fury/shaders/rt_odfs/linear_to_srgb.frag @@ -0,0 +1,4 @@ +float linear_to_srgb(float linear) +{ + return (linear <= 0.0031308) ? (12.92 * linear) : (1.055 * pow(linear, 1.0 / 2.4) - 0.055); +} diff --git a/fury/shaders/rt_odfs/newton_bisection.frag b/fury/shaders/rt_odfs/newton_bisection.frag new file mode 100644 index 000000000..3f4b7f81f --- /dev/null +++ b/fury/shaders/rt_odfs/newton_bisection.frag @@ -0,0 +1,47 @@ +bool newton_bisection(out float out_root, out float out_end_value, + float poly[MAX_DEGREE + 1], float begin, float end, + float begin_value, float error_tolerance) +{ + if (begin == end) { + out_end_value = begin_value; + return false; + } + // Evaluate the polynomial at the end of the interval + out_end_value = poly[MAX_DEGREE]; + _unroll_ + for (int i = MAX_DEGREE - 1; i != -1; --i) + out_end_value = out_end_value * end + poly[i]; + // If the values at both ends have the same non-zero sign, there is no root + if (begin_value * out_end_value > 0.0) + return false; + // Otherwise, we find the root iteratively using Newton bisection (with + // bounded iteration count) + float current = 0.5 * (begin + end); + _loop_ + for (int i = 0; i != 90; ++i) { + // Evaluate the polynomial and its derivative + float value = poly[MAX_DEGREE] * current + poly[MAX_DEGREE - 1]; + float derivative = poly[MAX_DEGREE]; + _unroll_ + for (int j = MAX_DEGREE - 2; j != -1; --j) { + derivative = derivative * current + value; + value = value * current + poly[j]; + } + // Shorten the interval + bool right = begin_value * value > 0.0; + begin = right ? current : begin; + end = right ? end : current; + // Apply Newton's method + float guess = current - value / derivative; + // Pick a guess + float middle = 0.5 * (begin + end); + float next = (guess >= begin && guess <= end) ? guess : middle; + // Move along or terminate + bool done = abs(next - current) < error_tolerance; + current = next; + if (done) + break; + } + out_root = current; + return true; +} diff --git a/fury/shaders/rt_odfs/ray_sh_glyph_intersections.frag b/fury/shaders/rt_odfs/ray_sh_glyph_intersections.frag new file mode 100644 index 000000000..a47dbbfc4 --- /dev/null +++ b/fury/shaders/rt_odfs/ray_sh_glyph_intersections.frag @@ -0,0 +1,81 @@ +void ray_sh_glyph_intersections(out float out_ray_params[MAX_DEGREE], float sh_coeffs[SH_COUNT], vec3 ray_origin, vec3 ray_dir) +{ + // Determine the direction from the glyph center to the closest point on + // the ray + float dir_dot_origin = dot(ray_dir, ray_origin); + vec3 closest_dir = normalize(ray_origin - dir_dot_origin * ray_dir); + // Evaluate the SH polynomial at SH_DEGREE + 1 points. That is enough to + // know its value everywhere along the ray. + float sh_values[SH_DEGREE + 1]; + _unroll_ + for (int i = 0; i != SH_DEGREE + 1; ++i) { + vec3 point = cos(float(i) * (M_PI / float(SH_DEGREE + 1))) * ray_dir + + sin(float(i) * (M_PI / float(SH_DEGREE + 1))) * closest_dir; + float shs[SH_COUNT]; + eval_sh(shs, point); + sh_values[i] = 0.0; + _unroll_ + for (int j = 0; j != SH_COUNT; ++j) + sh_values[i] += sh_coeffs[j] * shs[j]; + } + // Compute coefficients of the SH polynomial along the ray in the + // coordinate frame given by ray_dir and closest_dir + float radius_poly[SH_DEGREE + 1]; + float inv_vander[(SH_DEGREE + 1) * (SH_DEGREE + 1)]; + get_inv_vandermonde(inv_vander); + _unroll_ + for (int i = 0; i != SH_DEGREE + 1; ++i) { + radius_poly[i] = 0.0; + _unroll_ + for (int j = 0; j != SH_DEGREE + 1; ++j) + radius_poly[i] += inv_vander[i * (SH_DEGREE + 1) + j] * sh_values[j]; + } + // Compute a bounding circle around the glyph in the relevant plane + float radius_max = 0.0; + _unroll_ + for (int i = 0; i != SH_DEGREE + 1; ++i) { + float bound = sqrt(pow(float(i), float(i)) * pow(float(SH_DEGREE - i), float(SH_DEGREE - i)) / pow(float(SH_DEGREE), float(SH_DEGREE))); + // Workaround for buggy compilers where 0^0 is 0 + bound = (i == 0 || i == SH_DEGREE) ? 1.0 : bound; + radius_max += bound * abs(radius_poly[i]); + } + // Figure out the interval, where (if at all) the ray intersects the circle + float closest_dot_origin = dot(closest_dir, ray_origin); + if (radius_max < abs(closest_dot_origin)) { + _unroll_ + for (int i = 0; i != MAX_DEGREE; ++i) + out_ray_params[i] = NO_INTERSECTION; + return; + } + float radius_over_dot = radius_max / closest_dot_origin; + float u_max = sqrt(radius_over_dot * radius_over_dot - 1.0); + // Take the square of radius_poly + float poly[MAX_DEGREE + 1]; + _unroll_ + for (int i = 0; i != MAX_DEGREE + 1; ++i) + poly[i] = 0.0; + _unroll_ + for (int i = 0; i != SH_DEGREE + 1; ++i) + _unroll_ + for (int j = 0; j != SH_DEGREE + 1; ++j) + poly[i + j] += radius_poly[i] * radius_poly[j]; + // Subtract the scaled (2 * SH_DEGREE + 2)-th power of the distance to the + // glyph center + float dot_sq = closest_dot_origin * closest_dot_origin; + float binomial = 1.0; + _unroll_ + for (int i = 0; i != SH_DEGREE + 2; ++i) { + poly[2 * i] -= binomial * dot_sq; + // Update the binomial coefficient using a recurrence relation + binomial *= float(SH_DEGREE + 1 - i) / float(i + 1); + } + // Find roots of the polynomial within the relevant bounds + float roots[MAX_DEGREE + 1]; + find_roots(roots, poly, -u_max, u_max); + // Convert them back to the original coordinate frame (i.e. ray parameters) + _unroll_ + for (int i = 0; i != MAX_DEGREE; ++i) + out_ray_params[i] = (roots[i] != NO_INTERSECTION) + ? (roots[i] * closest_dot_origin - dir_dot_origin) + : NO_INTERSECTION; +} diff --git a/fury/shaders/rt_odfs/srgb_to_linear.frag b/fury/shaders/rt_odfs/srgb_to_linear.frag new file mode 100644 index 000000000..78c765c20 --- /dev/null +++ b/fury/shaders/rt_odfs/srgb_to_linear.frag @@ -0,0 +1,4 @@ +float srgb_to_linear(float non_linear) +{ + return (non_linear <= 0.04045) ? ((1.0 / 12.92) * non_linear) : pow(non_linear * (1.0 / 1.055) + 0.055 / 1.055, 2.4); +} diff --git a/fury/shaders/rt_odfs/srgb_to_linear_rgb.frag b/fury/shaders/rt_odfs/srgb_to_linear_rgb.frag new file mode 100644 index 000000000..e4c2ef22a --- /dev/null +++ b/fury/shaders/rt_odfs/srgb_to_linear_rgb.frag @@ -0,0 +1,4 @@ +vec3 srgb_to_linear_rgb(vec3 srgb) +{ + return vec3(srgb_to_linear(srgb.r), srgb_to_linear(srgb.g), srgb_to_linear(srgb.b)); +} diff --git a/fury/shaders/rt_odfs/tonemap.frag b/fury/shaders/rt_odfs/tonemap.frag new file mode 100644 index 000000000..dd6cdcacb --- /dev/null +++ b/fury/shaders/rt_odfs/tonemap.frag @@ -0,0 +1,5 @@ +vec3 tonemap(vec3 linear) +{ + float max_channel = max(max(1.0, linear.r), max(linear.g, linear.b)); + return linear * ((1.0 - 0.02 * log2(max_channel)) / max_channel); +} diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_10.frag b/fury/shaders/rt_odfs/tournier/eval_sh_10.frag new file mode 100644 index 000000000..bac867d98 --- /dev/null +++ b/fury/shaders/rt_odfs/tournier/eval_sh_10.frag @@ -0,0 +1,175 @@ +void eval_sh_10(out float out_shs[66], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + b = z2 * a - 0.250980392 * b; + a = b - 0.250773994 * a; + d = 233.240148813 * a; + out_shs[55] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[22] = c1 * d; + out_shs[20] = s1 * d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[37] = c1 * d; + out_shs[35] = s1 * d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + out_shs[56] = c1 * d; + out_shs[54] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[23] = c0 * d; + out_shs[19] = s0 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[38] = c0 * d; + out_shs[34] = s0 * d; + b = z2 * a - 0.235294118 * b; + a = b - 0.238390093 * a; + d = 272.365814381 * a; + out_shs[57] = c0 * d; + out_shs[53] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[24] = c1 * d; + out_shs[18] = s1 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[39] = c1 * d; + out_shs[33] = s1 * d; + a = z2 * b - 0.215686275 * a; + b = a - 0.222910217 * b; + d = -213.661323441 * b; + out_shs[58] = c1 * d; + out_shs[52] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[25] = c0 * d; + out_shs[17] = s0 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[40] = c0 * d; + out_shs[32] = s0 * d; + b = z2 * a - 0.188235294 * b; + a = b - 0.20123839 * a; + d = 151.081370682 * a; + out_shs[59] = c0 * d; + out_shs[51] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[26] = c1 * d; + out_shs[16] = s1 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[41] = c1 * d; + out_shs[31] = s1 * d; + a = z2 * b - 0.152941176 * a; + b = a - 0.173374613 * b; + d = -95.552248675 * b; + out_shs[60] = c1 * d; + out_shs[50] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[27] = c0 * d; + out_shs[15] = s0 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[42] = c0 * d; + out_shs[30] = s0 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + out_shs[61] = c0 * d; + out_shs[49] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[43] = c1 * d; + out_shs[29] = s1 * d; + a = (z2 - 5.88235294e-02) * z; + b = a - 9.90712074e-02 * z; + d = -25.910241313 * b; + out_shs[62] = c1 * d; + out_shs[48] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[44] = c0 * d; + out_shs[28] = s0 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + out_shs[63] = c0 * d; + out_shs[47] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + out_shs[64] = c1 * d; + out_shs[46] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + out_shs[65] = c0 * d; + out_shs[45] = s0 * d; +} diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_12.frag b/fury/shaders/rt_odfs/tournier/eval_sh_12.frag new file mode 100644 index 000000000..3bad86fd4 --- /dev/null +++ b/fury/shaders/rt_odfs/tournier/eval_sh_12.frag @@ -0,0 +1,238 @@ +void eval_sh_12(out float out_shs[91], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + b = z2 * a - 0.250980392 * b; + a = b - 0.250773994 * a; + d = 233.240148813 * a; + out_shs[55] = d; + b = z2 * a - 0.250626566 * b; + a = b - 0.250517598 * a; + d = 931.186918633 * a; + out_shs[78] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[22] = c1 * d; + out_shs[20] = s1 * d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[37] = c1 * d; + out_shs[35] = s1 * d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + out_shs[56] = c1 * d; + out_shs[54] = s1 * d; + a = z2 * b - 0.248120301 * a; + b = a - 0.248447205 * b; + d = -1265.233874957 * b; + out_shs[79] = c1 * d; + out_shs[77] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[23] = c0 * d; + out_shs[19] = s0 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[38] = c0 * d; + out_shs[34] = s0 * d; + b = z2 * a - 0.235294118 * b; + a = b - 0.238390093 * a; + d = 272.365814381 * a; + out_shs[57] = c0 * d; + out_shs[53] = s0 * d; + b = z2 * a - 0.240601504 * b; + a = b - 0.242236025 * a; + d = 1121.509962433 * a; + out_shs[80] = c0 * d; + out_shs[76] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[24] = c1 * d; + out_shs[18] = s1 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[39] = c1 * d; + out_shs[33] = s1 * d; + a = z2 * b - 0.215686275 * a; + b = a - 0.222910217 * b; + d = -213.661323441 * b; + out_shs[58] = c1 * d; + out_shs[52] = s1 * d; + a = z2 * b - 0.228070175 * a; + b = a - 0.231884058 * b; + d = -915.709049803 * b; + out_shs[81] = c1 * d; + out_shs[75] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[25] = c0 * d; + out_shs[17] = s0 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[40] = c0 * d; + out_shs[32] = s0 * d; + b = z2 * a - 0.188235294 * b; + a = b - 0.20123839 * a; + d = 151.081370682 * a; + out_shs[59] = c0 * d; + out_shs[51] = s0 * d; + b = z2 * a - 0.210526316 * b; + a = b - 0.217391304 * a; + d = 686.781787352 * a; + out_shs[82] = c0 * d; + out_shs[74] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[26] = c1 * d; + out_shs[16] = s1 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[41] = c1 * d; + out_shs[31] = s1 * d; + a = z2 * b - 0.152941176 * a; + b = a - 0.173374613 * b; + d = -95.552248675 * b; + out_shs[60] = c1 * d; + out_shs[50] = s1 * d; + a = z2 * b - 0.187969925 * a; + b = a - 0.198757764 * b; + d = -471.12841933 * b; + out_shs[83] = c1 * d; + out_shs[73] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[27] = c0 * d; + out_shs[15] = s0 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[42] = c0 * d; + out_shs[30] = s0 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + out_shs[61] = c0 * d; + out_shs[49] = s0 * d; + b = z2 * a - 0.160401003 * b; + a = b - 0.175983437 * a; + d = 293.800188384 * a; + out_shs[84] = c0 * d; + out_shs[72] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[43] = c1 * d; + out_shs[29] = s1 * d; + a = (z2 - 5.88235294e-02) * z; + b = a - 9.90712074e-02 * z; + d = -25.910241313 * b; + out_shs[62] = c1 * d; + out_shs[48] = s1 * d; + a = z2 * b - 0.127819549 * a; + b = a - 0.149068323 * b; + d = -165.101452729 * b; + out_shs[85] = c1 * d; + out_shs[71] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[44] = c0 * d; + out_shs[28] = s0 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + out_shs[63] = c0 * d; + out_shs[47] = s0 * d; + b = z2 * (a - 9.02255639e-02); + a = b - 0.118012422 * a; + d = 82.550726364 * a; + out_shs[86] = c0 * d; + out_shs[70] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + out_shs[64] = c1 * d; + out_shs[46] = s1 * d; + a = (z2 - 4.76190476e-02) * z; + b = a - 8.2815735e-02 * z; + d = -36.028090689 * b; + out_shs[87] = c1 * d; + out_shs[69] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + out_shs[65] = c0 * d; + out_shs[45] = s0 * d; + a = z2 - 4.34782609e-02; + d = 13.3042542 * a; + out_shs[88] = c0 * d; + out_shs[68] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.923210529 * z; + out_shs[89] = c1 * d; + out_shs[67] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.800821996; + out_shs[90] = c0 * d; + out_shs[66] = s0 * d; +} diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_2.frag b/fury/shaders/rt_odfs/tournier/eval_sh_2.frag new file mode 100644 index 000000000..a70493a22 --- /dev/null +++ b/fury/shaders/rt_odfs/tournier/eval_sh_2.frag @@ -0,0 +1,23 @@ +void eval_sh_2(out float out_shs[6], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; +} diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_4.frag b/fury/shaders/rt_odfs/tournier/eval_sh_4.frag new file mode 100644 index 000000000..15335ccad --- /dev/null +++ b/fury/shaders/rt_odfs/tournier/eval_sh_4.frag @@ -0,0 +1,46 @@ +void eval_sh_4(out float out_shs[15], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; +} diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_6.frag b/fury/shaders/rt_odfs/tournier/eval_sh_6.frag new file mode 100644 index 000000000..1051361dd --- /dev/null +++ b/fury/shaders/rt_odfs/tournier/eval_sh_6.frag @@ -0,0 +1,79 @@ +void eval_sh_6(out float out_shs[28], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[22] = c1 * d; + out_shs[20] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[23] = c0 * d; + out_shs[19] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[24] = c1 * d; + out_shs[18] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[25] = c0 * d; + out_shs[17] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[26] = c1 * d; + out_shs[16] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[27] = c0 * d; + out_shs[15] = s0 * d; +} diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_8.frag b/fury/shaders/rt_odfs/tournier/eval_sh_8.frag new file mode 100644 index 000000000..93c32e613 --- /dev/null +++ b/fury/shaders/rt_odfs/tournier/eval_sh_8.frag @@ -0,0 +1,122 @@ +void eval_sh_8(out float out_shs[45], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[22] = c1 * d; + out_shs[20] = s1 * d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[37] = c1 * d; + out_shs[35] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[23] = c0 * d; + out_shs[19] = s0 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[38] = c0 * d; + out_shs[34] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[24] = c1 * d; + out_shs[18] = s1 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[39] = c1 * d; + out_shs[33] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[25] = c0 * d; + out_shs[17] = s0 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[40] = c0 * d; + out_shs[32] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[26] = c1 * d; + out_shs[16] = s1 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[41] = c1 * d; + out_shs[31] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[27] = c0 * d; + out_shs[15] = s0 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[42] = c0 * d; + out_shs[30] = s0 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[43] = c1 * d; + out_shs[29] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[44] = c0 * d; + out_shs[28] = s0 * d; +} diff --git a/fury/shaders/utils/minmax_norm.glsl b/fury/shaders/utils/minmax_norm.glsl new file mode 100644 index 000000000..7992b53c7 --- /dev/null +++ b/fury/shaders/utils/minmax_norm.glsl @@ -0,0 +1,4 @@ +float coeffsNorm(float coef, float min, float max, float a, float b) +{ + return (coef - min) * ((b - a) / (max - min)) + a; +} \ No newline at end of file From a0d8ecca2386312443bdc3d2925aa0355bf16a7a Mon Sep 17 00:00:00 2001 From: tvcastillod Date: Fri, 23 Feb 2024 11:19:51 -0500 Subject: [PATCH 105/118] adjusted scaling --- docs/experimental/SH-ODF experimental/odf_example.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/docs/experimental/SH-ODF experimental/odf_example.py b/docs/experimental/SH-ODF experimental/odf_example.py index 3b6c60469..e16858211 100644 --- a/docs/experimental/SH-ODF experimental/odf_example.py +++ b/docs/experimental/SH-ODF experimental/odf_example.py @@ -22,10 +22,6 @@ coeffs = coeffs[:, :, :].reshape((x * y * z, s)) n_glyphs = coeffs.shape[0] - max_val = coeffs.min(axis=1) - total = np.sum(abs(coeffs), axis=1) - coeffs = np.dot(np.diag(1 / total), coeffs) * 1.7 - - odf_actor = actor.odf(centers=centers, coeffs=coeffs) + odf_actor = actor.odf(centers=centers, coeffs=coeffs, scales=1.0) show_man.scene.add(odf_actor) show_man.start() \ No newline at end of file From 0fa1db8d05ab3070e9377527a49dfaca81baad18 Mon Sep 17 00:00:00 2001 From: tvcastillod Date: Tue, 27 Feb 2024 13:01:14 -0500 Subject: [PATCH 106/118] reorganized files --- fury/actors/odf.py | 24 +- .../linear_rgb_to_srgb.frag | 0 .../{rt_odfs => lighting}/linear_to_srgb.frag | 0 .../{rt_odfs => lighting}/srgb_to_linear.frag | 0 .../srgb_to_linear_rgb.frag | 0 .../{ => descoteaux}/eval_sh_grad_10.frag | 0 .../{ => descoteaux}/eval_sh_grad_12.frag | 0 .../{ => descoteaux}/eval_sh_grad_2.frag | 0 .../{ => descoteaux}/eval_sh_grad_4.frag | 0 .../{ => descoteaux}/eval_sh_grad_6.frag | 0 .../{ => descoteaux}/eval_sh_grad_8.frag | 0 .../tournier/eval_sh_grad_10 copy.frag | 430 +++++++++++++ .../tournier/eval_sh_grad_12 copy.frag | 591 ++++++++++++++++++ .../rt_odfs/tournier/eval_sh_grad_2 copy.frag | 46 ++ .../rt_odfs/tournier/eval_sh_grad_4 copy.frag | 103 +++ .../rt_odfs/tournier/eval_sh_grad_6 copy.frag | 186 ++++++ .../rt_odfs/tournier/eval_sh_grad_8 copy.frag | 295 +++++++++ .../{rt_odfs => utils}/find_roots.frag | 0 .../{rt_odfs => utils}/newton_bisection.frag | 0 19 files changed, 1663 insertions(+), 12 deletions(-) rename fury/shaders/{rt_odfs => lighting}/linear_rgb_to_srgb.frag (100%) rename fury/shaders/{rt_odfs => lighting}/linear_to_srgb.frag (100%) rename fury/shaders/{rt_odfs => lighting}/srgb_to_linear.frag (100%) rename fury/shaders/{rt_odfs => lighting}/srgb_to_linear_rgb.frag (100%) rename fury/shaders/rt_odfs/{ => descoteaux}/eval_sh_grad_10.frag (100%) rename fury/shaders/rt_odfs/{ => descoteaux}/eval_sh_grad_12.frag (100%) rename fury/shaders/rt_odfs/{ => descoteaux}/eval_sh_grad_2.frag (100%) rename fury/shaders/rt_odfs/{ => descoteaux}/eval_sh_grad_4.frag (100%) rename fury/shaders/rt_odfs/{ => descoteaux}/eval_sh_grad_6.frag (100%) rename fury/shaders/rt_odfs/{ => descoteaux}/eval_sh_grad_8.frag (100%) create mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_grad_10 copy.frag create mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_grad_12 copy.frag create mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_grad_2 copy.frag create mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_grad_4 copy.frag create mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_grad_6 copy.frag create mode 100644 fury/shaders/rt_odfs/tournier/eval_sh_grad_8 copy.frag rename fury/shaders/{rt_odfs => utils}/find_roots.frag (100%) rename fury/shaders/{rt_odfs => utils}/newton_bisection.frag (100%) diff --git a/fury/actors/odf.py b/fury/actors/odf.py index a6d991033..e8a762c55 100644 --- a/fury/actors/odf.py +++ b/fury/actors/odf.py @@ -206,27 +206,27 @@ def sh_odf(centers, coeffs, basis_type, scales, opacity): os.path.join("rt_odfs", basis_type, "eval_sh_12.frag")) eval_sh_grad_2 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_2.frag") + os.path.join("rt_odfs/descoteaux", "eval_sh_grad_2.frag") ) eval_sh_grad_4 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_4.frag") + os.path.join("rt_odfs/descoteaux", "eval_sh_grad_4.frag") ) eval_sh_grad_6 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_6.frag") + os.path.join("rt_odfs/descoteaux", "eval_sh_grad_6.frag") ) eval_sh_grad_8 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_8.frag") + os.path.join("rt_odfs/descoteaux", "eval_sh_grad_8.frag") ) eval_sh_grad_10 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_10.frag") + os.path.join("rt_odfs/descoteaux", "eval_sh_grad_10.frag") ) eval_sh_grad_12 = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad_12.frag") + os.path.join("rt_odfs/descoteaux", "eval_sh_grad_12.frag") ) # Searches a single root of a polynomial within a given interval. @@ -246,13 +246,13 @@ def sh_odf(centers, coeffs, basis_type, scales, opacity): # # return true if a root was found, false if no root exists. newton_bisection = import_fury_shader( - os.path.join("rt_odfs", "newton_bisection.frag") + os.path.join("utils", "newton_bisection.frag") ) # Finds all roots of the given polynomial in the interval [begin, end] and # writes them to out_roots. Some entries will be NO_INTERSECTION but other # than that the array is sorted. The last entry is always NO_INTERSECTION. - find_roots = import_fury_shader(os.path.join("rt_odfs", "find_roots.frag")) + find_roots = import_fury_shader(os.path.join("utils", "find_roots.frag")) # Evaluates the spherical harmonics basis in bands 0, 2, ..., SH_DEGREE. # Conventions are as in the following paper. @@ -304,22 +304,22 @@ def sh_odf(centers, coeffs, basis_type, scales, opacity): # Applies the non-linearity that maps linear RGB to sRGB linear_to_srgb = import_fury_shader( - os.path.join("rt_odfs", "linear_to_srgb.frag") + os.path.join("lighting", "linear_to_srgb.frag") ) # Inverse of linear_to_srgb() srgb_to_linear = import_fury_shader( - os.path.join("rt_odfs", "srgb_to_linear.frag") + os.path.join("lighting", "srgb_to_linear.frag") ) # Turns a linear RGB color (i.e. rec. 709) into sRGB linear_rgb_to_srgb = import_fury_shader( - os.path.join("rt_odfs", "linear_rgb_to_srgb.frag") + os.path.join("lighting", "linear_rgb_to_srgb.frag") ) # Inverse of linear_rgb_to_srgb() srgb_to_linear_rgb = import_fury_shader( - os.path.join("rt_odfs", "srgb_to_linear_rgb.frag") + os.path.join("lighting", "srgb_to_linear_rgb.frag") ) # Logarithmic tonemapping operator. Input and output are linear RGB. diff --git a/fury/shaders/rt_odfs/linear_rgb_to_srgb.frag b/fury/shaders/lighting/linear_rgb_to_srgb.frag similarity index 100% rename from fury/shaders/rt_odfs/linear_rgb_to_srgb.frag rename to fury/shaders/lighting/linear_rgb_to_srgb.frag diff --git a/fury/shaders/rt_odfs/linear_to_srgb.frag b/fury/shaders/lighting/linear_to_srgb.frag similarity index 100% rename from fury/shaders/rt_odfs/linear_to_srgb.frag rename to fury/shaders/lighting/linear_to_srgb.frag diff --git a/fury/shaders/rt_odfs/srgb_to_linear.frag b/fury/shaders/lighting/srgb_to_linear.frag similarity index 100% rename from fury/shaders/rt_odfs/srgb_to_linear.frag rename to fury/shaders/lighting/srgb_to_linear.frag diff --git a/fury/shaders/rt_odfs/srgb_to_linear_rgb.frag b/fury/shaders/lighting/srgb_to_linear_rgb.frag similarity index 100% rename from fury/shaders/rt_odfs/srgb_to_linear_rgb.frag rename to fury/shaders/lighting/srgb_to_linear_rgb.frag diff --git a/fury/shaders/rt_odfs/eval_sh_grad_10.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_10.frag similarity index 100% rename from fury/shaders/rt_odfs/eval_sh_grad_10.frag rename to fury/shaders/rt_odfs/descoteaux/eval_sh_grad_10.frag diff --git a/fury/shaders/rt_odfs/eval_sh_grad_12.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_12.frag similarity index 100% rename from fury/shaders/rt_odfs/eval_sh_grad_12.frag rename to fury/shaders/rt_odfs/descoteaux/eval_sh_grad_12.frag diff --git a/fury/shaders/rt_odfs/eval_sh_grad_2.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_2.frag similarity index 100% rename from fury/shaders/rt_odfs/eval_sh_grad_2.frag rename to fury/shaders/rt_odfs/descoteaux/eval_sh_grad_2.frag diff --git a/fury/shaders/rt_odfs/eval_sh_grad_4.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_4.frag similarity index 100% rename from fury/shaders/rt_odfs/eval_sh_grad_4.frag rename to fury/shaders/rt_odfs/descoteaux/eval_sh_grad_4.frag diff --git a/fury/shaders/rt_odfs/eval_sh_grad_6.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_6.frag similarity index 100% rename from fury/shaders/rt_odfs/eval_sh_grad_6.frag rename to fury/shaders/rt_odfs/descoteaux/eval_sh_grad_6.frag diff --git a/fury/shaders/rt_odfs/eval_sh_grad_8.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_8.frag similarity index 100% rename from fury/shaders/rt_odfs/eval_sh_grad_8.frag rename to fury/shaders/rt_odfs/descoteaux/eval_sh_grad_8.frag diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_10 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_10 copy.frag new file mode 100644 index 000000000..c9e6b0d8d --- /dev/null +++ b/fury/shaders/rt_odfs/tournier/eval_sh_grad_10 copy.frag @@ -0,0 +1,430 @@ +void eval_sh_grad_10(out float out_shs[66], out vec3 out_grads[66], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + b = z2 * a - 0.250980392 * b; + a = b - 0.250773994 * a; + d = 233.240148813 * a; + out_shs[55] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + out_grads[4][0] = c0 * d; + out_grads[2][0] = s0 * d; + out_grads[4][1] = s0 * d; + out_grads[2][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + out_grads[11][0] = c0 * d; + out_grads[9][0] = s0 * d; + out_grads[11][1] = s0 * d; + out_grads[9][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[22] = c1 * d; + out_shs[20] = s1 * d; + out_grads[22][0] = c0 * d; + out_grads[20][0] = s0 * d; + out_grads[22][1] = s0 * d; + out_grads[20][1] = c0 * d; + d = 88.106914343 * b; + out_grads[21][2] = d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[37] = c1 * d; + out_shs[35] = s1 * d; + out_grads[37][0] = c0 * d; + out_grads[35][0] = s0 * d; + out_grads[37][1] = s0 * d; + out_grads[35][1] = c0 * d; + d = 467.786944906 * b; + out_grads[36][2] = d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + out_shs[56] = c1 * d; + out_shs[54] = s1 * d; + out_grads[56][0] = c0 * d; + out_grads[54][0] = s0 * d; + out_grads[56][1] = s0 * d; + out_grads[54][1] = c0 * d; + d = 2332.401488133 * b; + out_grads[55][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + d = 1.092548431; + out_grads[5][0] = c1 * d; + out_grads[1][0] = s1 * d; + out_grads[5][1] = -s1 * d; + out_grads[1][1] = c1 * d; + d = -1.092548431; + out_grads[4][2] = c1 * d; + out_grads[2][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + d = 6.62322287 * a; + out_grads[12][0] = c1 * d; + out_grads[8][0] = s1 * d; + out_grads[12][1] = -s1 * d; + out_grads[8][1] = c1 * d; + d = -14.049977415 * a; + out_grads[11][2] = c1 * d; + out_grads[9][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[23] = c0 * d; + out_shs[19] = s0 * d; + d = 30.399773564 * a; + out_grads[23][0] = c1 * d; + out_grads[19][0] = s1 * d; + out_grads[23][1] = -s1 * d; + out_grads[19][1] = c1 * d; + d = -96.132524816 * a; + out_grads[22][2] = c1 * d; + out_grads[20][2] = s1 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[38] = c0 * d; + out_shs[34] = s0 * d; + d = 130.459545912 * a; + out_grads[38][0] = c1 * d; + out_grads[34][0] = s1 * d; + out_grads[38][1] = -s1 * d; + out_grads[34][1] = c1 * d; + d = -545.751435723 * a; + out_grads[37][2] = c1 * d; + out_grads[35][2] = s1 * d; + b = z2 * a - 0.235294118 * b; + a = b - 0.238390093 * a; + d = 272.365814381 * a; + out_shs[57] = c0 * d; + out_shs[53] = s0 * d; + d = 544.731628762 * a; + out_grads[57][0] = c1 * d; + out_grads[53][0] = s1 * d; + out_grads[57][1] = -s1 * d; + out_grads[53][1] = c1 * d; + d = -2830.508572514 * a; + out_grads[56][2] = c1 * d; + out_grads[54][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; + d = -5.310392309 * z; + out_grads[13][0] = c0 * d; + out_grads[7][0] = s0 * d; + out_grads[13][1] = s0 * d; + out_grads[7][1] = c0 * d; + d = 6.62322287 * z; + out_grads[12][2] = c0 * d; + out_grads[8][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[24] = c1 * d; + out_shs[18] = s1 * d; + d = -30.399773564 * b; + out_grads[24][0] = c0 * d; + out_grads[18][0] = s0 * d; + out_grads[24][1] = s0 * d; + out_grads[18][1] = c0 * d; + d = 60.799547128 * b; + out_grads[23][2] = c0 * d; + out_grads[19][2] = s0 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[39] = c1 * d; + out_shs[33] = s1 * d; + d = -144.52614017 * b; + out_grads[39][0] = c0 * d; + out_grads[33][0] = s0 * d; + out_grads[39][1] = s0 * d; + out_grads[33][1] = c0 * d; + d = 391.378637737 * b; + out_grads[38][2] = c0 * d; + out_grads[34][2] = s0 * d; + a = z2 * b - 0.215686275 * a; + b = a - 0.222910217 * b; + d = -213.661323441 * b; + out_shs[58] = c1 * d; + out_shs[52] = s1 * d; + d = -640.983970322 * b; + out_grads[58][0] = c0 * d; + out_grads[52][0] = s0 * d; + out_grads[58][1] = s0 * d; + out_grads[52][1] = c0 * d; + d = 2178.926515046 * b; + out_grads[57][2] = c0 * d; + out_grads[53][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; + d = 2.503342942; + out_grads[14][0] = c1 * d; + out_grads[6][0] = s1 * d; + out_grads[14][1] = -s1 * d; + out_grads[6][1] = c1 * d; + d = -1.77013077; + out_grads[13][2] = c1 * d; + out_grads[7][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[25] = c0 * d; + out_shs[17] = s0 * d; + d = 22.200855632 * a; + out_grads[25][0] = c1 * d; + out_grads[17][0] = s1 * d; + out_grads[25][1] = -s1 * d; + out_grads[17][1] = c1 * d; + d = -30.399773564 * a; + out_grads[24][2] = c1 * d; + out_grads[18][2] = s1 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[40] = c0 * d; + out_shs[32] = s0 * d; + d = 124.388296437 * a; + out_grads[40][0] = c1 * d; + out_grads[32][0] = s1 * d; + out_grads[40][1] = -s1 * d; + out_grads[32][1] = c1 * d; + d = -240.876900283 * a; + out_grads[39][2] = c1 * d; + out_grads[33][2] = s1 * d; + b = z2 * a - 0.188235294 * b; + a = b - 0.20123839 * a; + d = 151.081370682 * a; + out_shs[59] = c0 * d; + out_shs[51] = s0 * d; + d = 604.325482728 * a; + out_grads[59][0] = c1 * d; + out_grads[51][0] = s1 * d; + out_grads[59][1] = -s1 * d; + out_grads[51][1] = c1 * d; + d = -1495.629264084 * a; + out_grads[58][2] = c1 * d; + out_grads[52][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[26] = c1 * d; + out_shs[16] = s1 * d; + d = -11.833095811 * z; + out_grads[26][0] = c0 * d; + out_grads[16][0] = s0 * d; + out_grads[26][1] = s0 * d; + out_grads[16][1] = c0 * d; + d = 11.100427816 * z; + out_grads[25][2] = c0 * d; + out_grads[17][2] = s0 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[41] = c1 * d; + out_shs[31] = s1 * d; + d = -86.247765552 * b; + out_grads[41][0] = c0 * d; + out_grads[31][0] = s0 * d; + out_grads[41][1] = s0 * d; + out_grads[31][1] = c0 * d; + d = 124.388296437 * b; + out_grads[40][2] = c0 * d; + out_grads[32][2] = s0 * d; + a = z2 * b - 0.152941176 * a; + b = a - 0.173374613 * b; + d = -95.552248675 * b; + out_shs[60] = c1 * d; + out_shs[50] = s1 * d; + d = -477.761243376 * b; + out_grads[60][0] = c0 * d; + out_grads[50][0] = s0 * d; + out_grads[60][1] = s0 * d; + out_grads[50][1] = c0 * d; + d = 906.488224092 * b; + out_grads[59][2] = c0 * d; + out_grads[51][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[27] = c0 * d; + out_shs[15] = s0 * d; + d = 4.099104631; + out_grads[27][0] = c1 * d; + out_grads[15][0] = s1 * d; + out_grads[27][1] = -s1 * d; + out_grads[15][1] = c1 * d; + d = -2.366619162; + out_grads[26][2] = c1 * d; + out_grads[16][2] = s1 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[42] = c0 * d; + out_shs[30] = s0 * d; + d = 47.909948945 * a; + out_grads[42][0] = c1 * d; + out_grads[30][0] = s1 * d; + out_grads[42][1] = -s1 * d; + out_grads[30][1] = c1 * d; + d = -51.748659331 * a; + out_grads[41][2] = c1 * d; + out_grads[31][2] = s1 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + out_shs[61] = c0 * d; + out_shs[49] = s0 * d; + d = 320.491985161 * a; + out_grads[61][0] = c1 * d; + out_grads[49][0] = s1 * d; + out_grads[61][1] = -s1 * d; + out_grads[49][1] = c1 * d; + d = -477.761243376 * a; + out_grads[60][2] = c1 * d; + out_grads[50][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[43] = c1 * d; + out_shs[29] = s1 * d; + d = -20.409946485 * z; + out_grads[43][0] = c0 * d; + out_grads[29][0] = s0 * d; + out_grads[43][1] = s0 * d; + out_grads[29][1] = c0 * d; + d = 15.969982982 * z; + out_grads[42][2] = c0 * d; + out_grads[30][2] = s0 * d; + a = (z2 - 5.88235294e-02) * z; + b = a - 9.90712074e-02 * z; + d = -25.910241313 * b; + out_shs[62] = c1 * d; + out_shs[48] = s1 * d; + d = -181.371689194 * b; + out_grads[62][0] = c0 * d; + out_grads[48][0] = s0 * d; + out_grads[62][1] = s0 * d; + out_grads[48][1] = c0 * d; + d = 213.661323441 * b; + out_grads[61][2] = c0 * d; + out_grads[49][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[44] = c0 * d; + out_shs[28] = s0 * d; + d = 5.831413281; + out_grads[44][0] = c1 * d; + out_grads[28][0] = s1 * d; + out_grads[44][1] = -s1 * d; + out_grads[28][1] = c1 * d; + d = -2.915706641; + out_grads[43][2] = c1 * d; + out_grads[29][2] = s1 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + out_shs[63] = c0 * d; + out_shs[47] = s0 * d; + d = 84.622493774 * a; + out_grads[63][0] = c1 * d; + out_grads[47][0] = s1 * d; + out_grads[63][1] = -s1 * d; + out_grads[47][1] = c1 * d; + d = -77.73072394 * a; + out_grads[62][2] = c1 * d; + out_grads[48][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + out_shs[64] = c1 * d; + out_shs[46] = s1 * d; + d = -30.887057699 * z; + out_grads[64][0] = c0 * d; + out_grads[46][0] = s0 * d; + out_grads[64][1] = s0 * d; + out_grads[46][1] = c0 * d; + d = 21.155623443 * z; + out_grads[63][2] = c0 * d; + out_grads[47][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + out_shs[65] = c0 * d; + out_shs[45] = s0 * d; + d = 7.673951182; + out_grads[65][0] = c1 * d; + out_grads[45][0] = s1 * d; + out_grads[65][1] = -s1 * d; + out_grads[45][1] = c1 * d; + d = -3.4318953; + out_grads[64][2] = c1 * d; + out_grads[46][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; + out_grads[6][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[14][2] = 0.0; + out_grads[15][2] = 0.0; + out_grads[21][0] = 0.0; + out_grads[21][1] = 0.0; + out_grads[27][2] = 0.0; + out_grads[28][2] = 0.0; + out_grads[36][0] = 0.0; + out_grads[36][1] = 0.0; + out_grads[44][2] = 0.0; + out_grads[45][2] = 0.0; + out_grads[55][0] = 0.0; + out_grads[55][1] = 0.0; + out_grads[65][2] = 0.0; +} diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_12 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_12 copy.frag new file mode 100644 index 000000000..35c2a3617 --- /dev/null +++ b/fury/shaders/rt_odfs/tournier/eval_sh_grad_12 copy.frag @@ -0,0 +1,591 @@ +void eval_sh_grad_12(out float out_shs[91], out vec3 out_grads[91], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + b = z2 * a - 0.250980392 * b; + a = b - 0.250773994 * a; + d = 233.240148813 * a; + out_shs[55] = d; + b = z2 * a - 0.250626566 * b; + a = b - 0.250517598 * a; + d = 931.186918633 * a; + out_shs[78] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + out_grads[4][0] = c0 * d; + out_grads[2][0] = s0 * d; + out_grads[4][1] = s0 * d; + out_grads[2][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + out_grads[11][0] = c0 * d; + out_grads[9][0] = s0 * d; + out_grads[11][1] = s0 * d; + out_grads[9][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[22] = c1 * d; + out_shs[20] = s1 * d; + out_grads[22][0] = c0 * d; + out_grads[20][0] = s0 * d; + out_grads[22][1] = s0 * d; + out_grads[20][1] = c0 * d; + d = 88.106914343 * b; + out_grads[21][2] = d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[37] = c1 * d; + out_shs[35] = s1 * d; + out_grads[37][0] = c0 * d; + out_grads[35][0] = s0 * d; + out_grads[37][1] = s0 * d; + out_grads[35][1] = c0 * d; + d = 467.786944906 * b; + out_grads[36][2] = d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + out_shs[56] = c1 * d; + out_shs[54] = s1 * d; + out_grads[56][0] = c0 * d; + out_grads[54][0] = s0 * d; + out_grads[56][1] = s0 * d; + out_grads[54][1] = c0 * d; + d = 2332.401488133 * b; + out_grads[55][2] = d; + a = z2 * b - 0.248120301 * a; + b = a - 0.248447205 * b; + d = -1265.233874957 * b; + out_shs[79] = c1 * d; + out_shs[77] = s1 * d; + out_grads[79][0] = c0 * d; + out_grads[77][0] = s0 * d; + out_grads[79][1] = s0 * d; + out_grads[77][1] = c0 * d; + d = 11174.243023595 * b; + out_grads[78][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + d = 1.092548431; + out_grads[5][0] = c1 * d; + out_grads[1][0] = s1 * d; + out_grads[5][1] = -s1 * d; + out_grads[1][1] = c1 * d; + d = -1.092548431; + out_grads[4][2] = c1 * d; + out_grads[2][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + d = 6.62322287 * a; + out_grads[12][0] = c1 * d; + out_grads[8][0] = s1 * d; + out_grads[12][1] = -s1 * d; + out_grads[8][1] = c1 * d; + d = -14.049977415 * a; + out_grads[11][2] = c1 * d; + out_grads[9][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[23] = c0 * d; + out_shs[19] = s0 * d; + d = 30.399773564 * a; + out_grads[23][0] = c1 * d; + out_grads[19][0] = s1 * d; + out_grads[23][1] = -s1 * d; + out_grads[19][1] = c1 * d; + d = -96.132524816 * a; + out_grads[22][2] = c1 * d; + out_grads[20][2] = s1 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[38] = c0 * d; + out_shs[34] = s0 * d; + d = 130.459545912 * a; + out_grads[38][0] = c1 * d; + out_grads[34][0] = s1 * d; + out_grads[38][1] = -s1 * d; + out_grads[34][1] = c1 * d; + d = -545.751435723 * a; + out_grads[37][2] = c1 * d; + out_grads[35][2] = s1 * d; + b = z2 * a - 0.235294118 * b; + a = b - 0.238390093 * a; + d = 272.365814381 * a; + out_shs[57] = c0 * d; + out_shs[53] = s0 * d; + d = 544.731628762 * a; + out_grads[57][0] = c1 * d; + out_grads[53][0] = s1 * d; + out_grads[57][1] = -s1 * d; + out_grads[53][1] = c1 * d; + d = -2830.508572514 * a; + out_grads[56][2] = c1 * d; + out_grads[54][2] = s1 * d; + b = z2 * a - 0.240601504 * b; + a = b - 0.242236025 * a; + d = 1121.509962433 * a; + out_shs[80] = c0 * d; + out_shs[76] = s0 * d; + d = 2243.019924866 * a; + out_grads[80][0] = c1 * d; + out_grads[76][0] = s1 * d; + out_grads[80][1] = -s1 * d; + out_grads[76][1] = c1 * d; + d = -13917.572624524 * a; + out_grads[79][2] = c1 * d; + out_grads[77][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; + d = -5.310392309 * z; + out_grads[13][0] = c0 * d; + out_grads[7][0] = s0 * d; + out_grads[13][1] = s0 * d; + out_grads[7][1] = c0 * d; + d = 6.62322287 * z; + out_grads[12][2] = c0 * d; + out_grads[8][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[24] = c1 * d; + out_shs[18] = s1 * d; + d = -30.399773564 * b; + out_grads[24][0] = c0 * d; + out_grads[18][0] = s0 * d; + out_grads[24][1] = s0 * d; + out_grads[18][1] = c0 * d; + d = 60.799547128 * b; + out_grads[23][2] = c0 * d; + out_grads[19][2] = s0 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[39] = c1 * d; + out_shs[33] = s1 * d; + d = -144.52614017 * b; + out_grads[39][0] = c0 * d; + out_grads[33][0] = s0 * d; + out_grads[39][1] = s0 * d; + out_grads[33][1] = c0 * d; + d = 391.378637737 * b; + out_grads[38][2] = c0 * d; + out_grads[34][2] = s0 * d; + a = z2 * b - 0.215686275 * a; + b = a - 0.222910217 * b; + d = -213.661323441 * b; + out_shs[58] = c1 * d; + out_shs[52] = s1 * d; + d = -640.983970322 * b; + out_grads[58][0] = c0 * d; + out_grads[52][0] = s0 * d; + out_grads[58][1] = s0 * d; + out_grads[52][1] = c0 * d; + d = 2178.926515046 * b; + out_grads[57][2] = c0 * d; + out_grads[53][2] = s0 * d; + a = z2 * b - 0.228070175 * a; + b = a - 0.231884058 * b; + d = -915.709049803 * b; + out_shs[81] = c1 * d; + out_shs[75] = s1 * d; + d = -2747.127149409 * b; + out_grads[81][0] = c0 * d; + out_grads[75][0] = s0 * d; + out_grads[81][1] = s0 * d; + out_grads[75][1] = c0 * d; + d = 11215.099624332 * b; + out_grads[80][2] = c0 * d; + out_grads[76][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; + d = 2.503342942; + out_grads[14][0] = c1 * d; + out_grads[6][0] = s1 * d; + out_grads[14][1] = -s1 * d; + out_grads[6][1] = c1 * d; + d = -1.77013077; + out_grads[13][2] = c1 * d; + out_grads[7][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[25] = c0 * d; + out_shs[17] = s0 * d; + d = 22.200855632 * a; + out_grads[25][0] = c1 * d; + out_grads[17][0] = s1 * d; + out_grads[25][1] = -s1 * d; + out_grads[17][1] = c1 * d; + d = -30.399773564 * a; + out_grads[24][2] = c1 * d; + out_grads[18][2] = s1 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[40] = c0 * d; + out_shs[32] = s0 * d; + d = 124.388296437 * a; + out_grads[40][0] = c1 * d; + out_grads[32][0] = s1 * d; + out_grads[40][1] = -s1 * d; + out_grads[32][1] = c1 * d; + d = -240.876900283 * a; + out_grads[39][2] = c1 * d; + out_grads[33][2] = s1 * d; + b = z2 * a - 0.188235294 * b; + a = b - 0.20123839 * a; + d = 151.081370682 * a; + out_shs[59] = c0 * d; + out_shs[51] = s0 * d; + d = 604.325482728 * a; + out_grads[59][0] = c1 * d; + out_grads[51][0] = s1 * d; + out_grads[59][1] = -s1 * d; + out_grads[51][1] = c1 * d; + d = -1495.629264084 * a; + out_grads[58][2] = c1 * d; + out_grads[52][2] = s1 * d; + b = z2 * a - 0.210526316 * b; + a = b - 0.217391304 * a; + d = 686.781787352 * a; + out_shs[82] = c0 * d; + out_shs[74] = s0 * d; + d = 2747.127149409 * a; + out_grads[82][0] = c1 * d; + out_grads[74][0] = s1 * d; + out_grads[82][1] = -s1 * d; + out_grads[74][1] = c1 * d; + d = -8241.381448228 * a; + out_grads[81][2] = -c1 * d; + out_grads[75][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[26] = c1 * d; + out_shs[16] = s1 * d; + d = -11.833095811 * z; + out_grads[26][0] = c0 * d; + out_grads[16][0] = s0 * d; + out_grads[26][1] = s0 * d; + out_grads[16][1] = c0 * d; + d = 11.100427816 * z; + out_grads[25][2] = c0 * d; + out_grads[17][2] = s0 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[41] = c1 * d; + out_shs[31] = s1 * d; + d = -86.247765552 * b; + out_grads[41][0] = c0 * d; + out_grads[31][0] = s0 * d; + out_grads[41][1] = s0 * d; + out_grads[31][1] = c0 * d; + d = 124.388296437 * b; + out_grads[40][2] = c0 * d; + out_grads[32][2] = s0 * d; + a = z2 * b - 0.152941176 * a; + b = a - 0.173374613 * b; + d = -95.552248675 * b; + out_shs[60] = c1 * d; + out_shs[50] = s1 * d; + d = -477.761243376 * b; + out_grads[60][0] = c0 * d; + out_grads[50][0] = s0 * d; + out_grads[60][1] = s0 * d; + out_grads[50][1] = c0 * d; + d = 906.488224092 * b; + out_grads[59][2] = c0 * d; + out_grads[51][2] = s0 * d; + a = z2 * b - 0.187969925 * a; + b = a - 0.198757764 * b; + d = -471.12841933 * b; + out_shs[83] = c1 * d; + out_shs[73] = s1 * d; + d = -2355.642096651 * b; + out_grads[83][0] = c0 * d; + out_grads[73][0] = s0 * d; + out_grads[83][1] = s0 * d; + out_grads[73][1] = c0 * d; + d = 5494.254298819 * b; + out_grads[82][2] = c0 * d; + out_grads[74][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[27] = c0 * d; + out_shs[15] = s0 * d; + d = 4.099104631; + out_grads[27][0] = c1 * d; + out_grads[15][0] = s1 * d; + out_grads[27][1] = -s1 * d; + out_grads[15][1] = c1 * d; + d = -2.366619162; + out_grads[26][2] = c1 * d; + out_grads[16][2] = s1 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[42] = c0 * d; + out_shs[30] = s0 * d; + d = 47.909948945 * a; + out_grads[42][0] = c1 * d; + out_grads[30][0] = s1 * d; + out_grads[42][1] = -s1 * d; + out_grads[30][1] = c1 * d; + d = -51.748659331 * a; + out_grads[41][2] = c1 * d; + out_grads[31][2] = s1 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + out_shs[61] = c0 * d; + out_shs[49] = s0 * d; + d = 320.491985161 * a; + out_grads[61][0] = c1 * d; + out_grads[49][0] = s1 * d; + out_grads[61][1] = -s1 * d; + out_grads[49][1] = c1 * d; + d = -477.761243376 * a; + out_grads[60][2] = c1 * d; + out_grads[50][2] = s1 * d; + b = z2 * a - 0.160401003 * b; + a = b - 0.175983437 * a; + d = 293.800188384 * a; + out_shs[84] = c0 * d; + out_shs[72] = s0 * d; + d = 1762.801130306 * a; + out_grads[84][0] = c1 * d; + out_grads[72][0] = s1 * d; + out_grads[84][1] = -s1 * d; + out_grads[72][1] = c1 * d; + d = -3297.898935312 * a; + out_grads[83][2] = c1 * d; + out_grads[73][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[43] = c1 * d; + out_shs[29] = s1 * d; + d = -20.409946485 * z; + out_grads[43][0] = c0 * d; + out_grads[29][0] = s0 * d; + out_grads[43][1] = s0 * d; + out_grads[29][1] = c0 * d; + d = 15.969982982 * z; + out_grads[42][2] = c0 * d; + out_grads[30][2] = s0 * d; + a = (z2 - 5.88235294e-02) * z; + b = a - 9.90712074e-02 * z; + d = -25.910241313 * b; + out_shs[62] = c1 * d; + out_shs[48] = s1 * d; + d = -181.371689194 * b; + out_grads[62][0] = c0 * d; + out_grads[48][0] = s0 * d; + out_grads[62][1] = s0 * d; + out_grads[48][1] = c0 * d; + d = 213.661323441 * b; + out_grads[61][2] = c0 * d; + out_grads[49][2] = s0 * d; + a = z2 * b - 0.127819549 * a; + b = a - 0.149068323 * b; + d = -165.101452729 * b; + out_shs[85] = c1 * d; + out_shs[71] = s1 * d; + d = -1155.7101691 * b; + out_grads[85][0] = c0 * d; + out_grads[71][0] = s0 * d; + out_grads[85][1] = s0 * d; + out_grads[71][1] = c0 * d; + d = 1762.801130306 * b; + out_grads[84][2] = c0 * d; + out_grads[72][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[44] = c0 * d; + out_shs[28] = s0 * d; + d = 5.831413281; + out_grads[44][0] = c1 * d; + out_grads[28][0] = s1 * d; + out_grads[44][1] = -s1 * d; + out_grads[28][1] = c1 * d; + d = -2.915706641; + out_grads[43][2] = c1 * d; + out_grads[29][2] = s1 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + out_shs[63] = c0 * d; + out_shs[47] = s0 * d; + d = 84.622493774 * a; + out_grads[63][0] = c1 * d; + out_grads[47][0] = s1 * d; + out_grads[63][1] = -s1 * d; + out_grads[47][1] = c1 * d; + d = -77.73072394 * a; + out_grads[62][2] = c1 * d; + out_grads[48][2] = s1 * d; + b = z2 * (a - 9.02255639e-02); + a = b - 0.118012422 * a; + d = 82.550726364 * a; + out_shs[86] = c0 * d; + out_shs[70] = s0 * d; + d = 660.405810914 * a; + out_grads[86][0] = c1 * d; + out_grads[70][0] = s1 * d; + out_grads[86][1] = -s1 * d; + out_grads[70][1] = c1 * d; + d = -825.507263643 * a; + out_grads[85][2] = c1 * d; + out_grads[71][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + out_shs[64] = c1 * d; + out_shs[46] = s1 * d; + d = -30.887057699 * z; + out_grads[64][0] = c0 * d; + out_grads[46][0] = s0 * d; + out_grads[64][1] = s0 * d; + out_grads[46][1] = c0 * d; + d = 21.155623443 * z; + out_grads[63][2] = c0 * d; + out_grads[47][2] = s0 * d; + a = (z2 - 4.76190476e-02) * z; + b = a - 8.2815735e-02 * z; + d = -36.028090689 * b; + out_shs[87] = c1 * d; + out_shs[69] = s1 * d; + d = -324.252816204 * b; + out_grads[87][0] = c0 * d; + out_grads[69][0] = s0 * d; + out_grads[87][1] = s0 * d; + out_grads[69][1] = c0 * d; + d = 330.202905457 * b; + out_grads[86][2] = c0 * d; + out_grads[70][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + out_shs[65] = c0 * d; + out_shs[45] = s0 * d; + d = 7.673951182; + out_grads[65][0] = c1 * d; + out_grads[45][0] = s1 * d; + out_grads[65][1] = -s1 * d; + out_grads[45][1] = c1 * d; + d = -3.4318953; + out_grads[64][2] = c1 * d; + out_grads[46][2] = s1 * d; + a = z2 - 4.34782609e-02; + d = 13.3042542 * a; + out_shs[88] = c0 * d; + out_shs[68] = s0 * d; + d = 133.042542003 * a; + out_grads[88][0] = c1 * d; + out_grads[68][0] = s1 * d; + out_grads[88][1] = -s1 * d; + out_grads[68][1] = c1 * d; + d = -108.084272068 * a; + out_grads[87][2] = c1 * d; + out_grads[69][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.923210529 * z; + out_shs[89] = c1 * d; + out_shs[67] = s1 * d; + d = -43.155315818 * z; + out_grads[89][0] = c0 * d; + out_grads[67][0] = s0 * d; + out_grads[89][1] = s0 * d; + out_grads[67][1] = c0 * d; + d = 26.608508401 * z; + out_grads[88][2] = c0 * d; + out_grads[68][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.800821996; + out_shs[90] = c0 * d; + out_shs[66] = s0 * d; + d = 9.609863949; + out_grads[90][0] = c1 * d; + out_grads[66][0] = s1 * d; + out_grads[90][1] = -s1 * d; + out_grads[66][1] = c1 * d; + d = -3.923210529; + out_grads[89][2] = c1 * d; + out_grads[67][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[1][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[5][2] = 0.0; + out_grads[6][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[14][2] = 0.0; + out_grads[15][2] = 0.0; + out_grads[21][0] = 0.0; + out_grads[21][1] = 0.0; + out_grads[27][2] = 0.0; + out_grads[28][2] = 0.0; + out_grads[36][0] = 0.0; + out_grads[36][1] = 0.0; + out_grads[44][2] = 0.0; + out_grads[45][2] = 0.0; + out_grads[55][0] = 0.0; + out_grads[55][1] = 0.0; + out_grads[65][2] = 0.0; + out_grads[66][2] = 0.0; + out_grads[78][0] = 0.0; + out_grads[78][1] = 0.0; + out_grads[90][2] = 0.0; +} diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_2 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_2 copy.frag new file mode 100644 index 000000000..277a0e07a --- /dev/null +++ b/fury/shaders/rt_odfs/tournier/eval_sh_grad_2 copy.frag @@ -0,0 +1,46 @@ +void eval_sh_grad_2(out float out_shs[6], out vec3 out_grads[6], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + out_grads[4][0] = c0 * d; + out_grads[2][0] = s0 * d; + out_grads[4][1] = s0 * d; + out_grads[2][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + d = 1.092548431; + out_grads[1][0] = c1 * d; + out_grads[5][0] = s1 * d; + out_grads[5][1] = -s1 * d; + out_grads[1][1] = c1 * d; + d = -1.092548431; + out_grads[4][2] = c1 * d; + out_grads[2][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[5][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[1][2] = 0.0; +} diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_4 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_4 copy.frag new file mode 100644 index 000000000..c85847a5b --- /dev/null +++ b/fury/shaders/rt_odfs/tournier/eval_sh_grad_4 copy.frag @@ -0,0 +1,103 @@ +void eval_sh_grad_4(out float out_shs[15], out vec3 out_grads[15], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + out_grads[4][0] = c0 * d; + out_grads[2][0] = s0 * d; + out_grads[4][1] = s0 * d; + out_grads[2][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + out_grads[11][0] = c0 * d; + out_grads[9][0] = s0 * d; + out_grads[11][1] = s0 * d; + out_grads[9][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + d = 1.092548431; + out_grads[5][0] = c1 * d; + out_grads[1][0] = s1 * d; + out_grads[5][1] = -s1 * d; + out_grads[1][1] = c1 * d; + d = -1.092548431; + out_grads[4][2] = c1 * d; + out_grads[2][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + d = 6.62322287 * a; + out_grads[12][0] = c1 * d; + out_grads[8][0] = s1 * d; + out_grads[12][1] = -s1 * d; + out_grads[8][1] = c1 * d; + d = -14.049977415 * a; + out_grads[11][2] = c1 * d; + out_grads[9][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; + d = -5.310392309 * z; + out_grads[13][0] = c0 * d; + out_grads[7][0] = s0 * d; + out_grads[13][1] = s0 * d; + out_grads[7][1] = c0 * d; + d = 6.62322287 * z; + out_grads[12][2] = c0 * d; + out_grads[8][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; + d = 2.503342942; + out_grads[14][0] = c1 * d; + out_grads[6][0] = s1 * d; + out_grads[14][1] = -s1 * d; + out_grads[6][1] = c1 * d; + d = -1.77013077; + out_grads[13][2] = c1 * d; + out_grads[7][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[5][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[1][2] = 0.0; + out_grads[14][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[6][2] = 0.0; +} diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_6 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_6 copy.frag new file mode 100644 index 000000000..617413bc9 --- /dev/null +++ b/fury/shaders/rt_odfs/tournier/eval_sh_grad_6 copy.frag @@ -0,0 +1,186 @@ +void eval_sh_grad_6(out float out_shs[28], out vec3 out_grads[28], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + out_grads[4][0] = c0 * d; + out_grads[2][0] = s0 * d; + out_grads[4][1] = s0 * d; + out_grads[2][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + out_grads[11][0] = c0 * d; + out_grads[9][0] = s0 * d; + out_grads[11][1] = s0 * d; + out_grads[9][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[22] = c1 * d; + out_shs[20] = s1 * d; + out_grads[22][0] = c0 * d; + out_grads[20][0] = s0 * d; + out_grads[22][1] = s0 * d; + out_grads[20][1] = c0 * d; + d = 88.106914343 * b; + out_grads[21][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + d = 1.092548431; + out_grads[5][0] = c1 * d; + out_grads[1][0] = s1 * d; + out_grads[5][1] = -s1 * d; + out_grads[1][1] = c1 * d; + d = -1.092548431; + out_grads[4][2] = c1 * d; + out_grads[2][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + d = 6.62322287 * a; + out_grads[12][0] = c1 * d; + out_grads[8][0] = s1 * d; + out_grads[12][1] = -s1 * d; + out_grads[8][1] = c1 * d; + d = -14.049977415 * a; + out_grads[11][2] = c1 * d; + out_grads[9][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[23] = c0 * d; + out_shs[19] = s0 * d; + d = 30.399773564 * a; + out_grads[23][0] = c1 * d; + out_grads[19][0] = s1 * d; + out_grads[23][1] = -s1 * d; + out_grads[19][1] = c1 * d; + d = -96.132524816 * a; + out_grads[22][2] = c1 * d; + out_grads[20][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; + d = -5.310392309 * z; + out_grads[13][0] = c0 * d; + out_grads[7][0] = s0 * d; + out_grads[13][1] = s0 * d; + out_grads[7][1] = c0 * d; + d = 6.62322287 * z; + out_grads[12][2] = c0 * d; + out_grads[8][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[24] = c1 * d; + out_shs[18] = s1 * d; + d = -30.399773564 * b; + out_grads[24][0] = c0 * d; + out_grads[18][0] = s0 * d; + out_grads[24][1] = s0 * d; + out_grads[18][1] = c0 * d; + d = 60.799547128 * b; + out_grads[23][2] = c0 * d; + out_grads[19][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; + d = 2.503342942; + out_grads[14][0] = c1 * d; + out_grads[6][0] = s1 * d; + out_grads[14][1] = -s1 * d; + out_grads[6][1] = c1 * d; + d = -1.77013077; + out_grads[13][2] = c1 * d; + out_grads[7][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[25] = c0 * d; + out_shs[17] = s0 * d; + d = 22.200855632 * a; + out_grads[25][0] = c1 * d; + out_grads[17][0] = s1 * d; + out_grads[25][1] = -s1 * d; + out_grads[17][1] = c1 * d; + d = -30.399773564 * a; + out_grads[24][2] = c1 * d; + out_grads[18][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[26] = c1 * d; + out_shs[16] = s1 * d; + d = -11.833095811 * z; + out_grads[26][0] = c0 * d; + out_grads[16][0] = s0 * d; + out_grads[26][1] = s0 * d; + out_grads[16][1] = c0 * d; + d = 11.100427816 * z; + out_grads[25][2] = c0 * d; + out_grads[17][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[27] = c0 * d; + out_shs[15] = s0 * d; + d = 4.099104631; + out_grads[27][0] = c1 * d; + out_grads[15][0] = s1 * d; + out_grads[27][1] = -s1 * d; + out_grads[15][1] = c1 * d; + d = -2.366619162; + out_grads[26][2] = c1 * d; + out_grads[16][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[5][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[1][2] = 0.0; + out_grads[14][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[6][2] = 0.0; + out_grads[27][2] = 0.0; + out_grads[21][0] = 0.0; + out_grads[21][1] = 0.0; + out_grads[15][2] = 0.0; +} diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_8 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_8 copy.frag new file mode 100644 index 000000000..712b2dc29 --- /dev/null +++ b/fury/shaders/rt_odfs/tournier/eval_sh_grad_8 copy.frag @@ -0,0 +1,295 @@ +void eval_sh_grad_8(out float out_shs[45], out vec3 out_grads[45], vec3 point) +{ + float x, y, z, z2, c0, s0, c1, s1, d, a, b; + x = point[0]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + d = 0.282094792; + out_shs[0] = d; + a = z2 - 0.333333333; + d = 0.946174696 * a; + out_shs[3] = d; + b = z2 * (a - 0.266666667); + a = b - 0.257142857 * a; + d = 3.702494142 * a; + out_shs[10] = d; + b = z2 * a - 0.253968254 * b; + a = b - 0.252525253 * a; + d = 14.684485724 * a; + out_shs[21] = d; + b = z2 * a - 0.251748252 * b; + a = b - 0.251282051 * a; + d = 58.473368113 * a; + out_shs[36] = d; + c1 = x; + s1 = y; + d = -1.092548431 * z; + out_shs[4] = c1 * d; + out_shs[2] = s1 * d; + out_grads[4][0] = c0 * d; + out_grads[2][0] = s0 * d; + out_grads[4][1] = s0 * d; + out_grads[2][1] = c0 * d; + d = 1.892349392 * z; + out_grads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + out_shs[11] = c1 * d; + out_shs[9] = s1 * d; + out_grads[11][0] = c0 * d; + out_grads[9][0] = s0 * d; + out_grads[11][1] = s0 * d; + out_grads[9][1] = c0 * d; + d = 14.809976568 * b; + out_grads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + out_shs[22] = c1 * d; + out_shs[20] = s1 * d; + out_grads[22][0] = c0 * d; + out_grads[20][0] = s0 * d; + out_grads[22][1] = s0 * d; + out_grads[20][1] = c0 * d; + d = 88.106914343 * b; + out_grads[21][2] = d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + out_shs[37] = c1 * d; + out_shs[35] = s1 * d; + out_grads[37][0] = c0 * d; + out_grads[35][0] = s0 * d; + out_grads[37][1] = s0 * d; + out_grads[35][1] = c0 * d; + d = 467.786944906 * b; + out_grads[36][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + out_shs[5] = c0 * d; + out_shs[1] = s0 * d; + d = 1.092548431; + out_grads[5][0] = c1 * d; + out_grads[1][0] = s1 * d; + out_grads[5][1] = -s1 * d; + out_grads[1][1] = c1 * d; + d = -1.092548431; + out_grads[4][2] = c1 * d; + out_grads[2][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + out_shs[12] = c0 * d; + out_shs[8] = s0 * d; + d = 6.62322287 * a; + out_grads[12][0] = c1 * d; + out_grads[8][0] = s1 * d; + out_grads[12][1] = -s1 * d; + out_grads[8][1] = c1 * d; + d = -14.049977415 * a; + out_grads[11][2] = c1 * d; + out_grads[9][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + out_shs[23] = c0 * d; + out_shs[19] = s0 * d; + d = 30.399773564 * a; + out_grads[23][0] = c1 * d; + out_grads[19][0] = s1 * d; + out_grads[23][1] = -s1 * d; + out_grads[19][1] = c1 * d; + d = -96.132524816 * a; + out_grads[22][2] = c1 * d; + out_grads[20][2] = s1 * d; + b = z2 * a - 0.223776224 * b; + a = b - 0.230769231 * a; + d = 65.229772956 * a; + out_shs[38] = c0 * d; + out_shs[34] = s0 * d; + d = 130.459545912 * a; + out_grads[38][0] = c1 * d; + out_grads[34][0] = s1 * d; + out_grads[38][1] = -s1 * d; + out_grads[34][1] = c1 * d; + d = -545.751435723 * a; + out_grads[37][2] = c1 * d; + out_grads[35][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + out_shs[13] = c1 * d; + out_shs[7] = s1 * d; + d = -5.310392309 * z; + out_grads[13][0] = c0 * d; + out_grads[7][0] = s0 * d; + out_grads[13][1] = s0 * d; + out_grads[7][1] = c0 * d; + d = 6.62322287 * z; + out_grads[12][2] = c0 * d; + out_grads[8][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + out_shs[24] = c1 * d; + out_shs[18] = s1 * d; + d = -30.399773564 * b; + out_grads[24][0] = c0 * d; + out_grads[18][0] = s0 * d; + out_grads[24][1] = s0 * d; + out_grads[18][1] = c0 * d; + d = 60.799547128 * b; + out_grads[23][2] = c0 * d; + out_grads[19][2] = s0 * d; + a = z2 * b - 0.188811189 * a; + b = a - 0.205128205 * b; + d = -48.175380057 * b; + out_shs[39] = c1 * d; + out_shs[33] = s1 * d; + d = -144.52614017 * b; + out_grads[39][0] = c0 * d; + out_grads[33][0] = s0 * d; + out_grads[39][1] = s0 * d; + out_grads[33][1] = c0 * d; + d = 391.378637737 * b; + out_grads[38][2] = c0 * d; + out_grads[34][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + out_shs[14] = c0 * d; + out_shs[6] = s0 * d; + d = 2.503342942; + out_grads[14][0] = c1 * d; + out_grads[6][0] = s1 * d; + out_grads[14][1] = -s1 * d; + out_grads[6][1] = c1 * d; + d = -1.77013077; + out_grads[13][2] = c1 * d; + out_grads[7][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + out_shs[25] = c0 * d; + out_shs[17] = s0 * d; + d = 22.200855632 * a; + out_grads[25][0] = c1 * d; + out_grads[17][0] = s1 * d; + out_grads[25][1] = -s1 * d; + out_grads[17][1] = c1 * d; + d = -30.399773564 * a; + out_grads[24][2] = c1 * d; + out_grads[18][2] = s1 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + out_shs[40] = c0 * d; + out_shs[32] = s0 * d; + d = 124.388296437 * a; + out_grads[40][0] = c1 * d; + out_grads[32][0] = s1 * d; + out_grads[40][1] = -s1 * d; + out_grads[32][1] = c1 * d; + d = -240.876900283 * a; + out_grads[39][2] = c1 * d; + out_grads[33][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + out_shs[26] = c1 * d; + out_shs[16] = s1 * d; + d = -11.833095811 * z; + out_grads[26][0] = c0 * d; + out_grads[16][0] = s0 * d; + out_grads[26][1] = s0 * d; + out_grads[16][1] = c0 * d; + d = 11.100427816 * z; + out_grads[25][2] = c0 * d; + out_grads[17][2] = s0 * d; + a = (z2 - 7.69230769e-02) * z; + b = a - 0.123076923 * z; + d = -17.24955311 * b; + out_shs[41] = c1 * d; + out_shs[31] = s1 * d; + d = -86.247765552 * b; + out_grads[41][0] = c0 * d; + out_grads[31][0] = s0 * d; + out_grads[41][1] = s0 * d; + out_grads[31][1] = c0 * d; + d = 124.388296437 * b; + out_grads[40][2] = c0 * d; + out_grads[32][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + out_shs[27] = c0 * d; + out_shs[15] = s0 * d; + d = 4.099104631; + out_grads[27][0] = c1 * d; + out_grads[15][0] = s1 * d; + out_grads[27][1] = -s1 * d; + out_grads[15][1] = c1 * d; + d = -2.366619162; + out_grads[26][2] = c1 * d; + out_grads[16][2] = s1 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + out_shs[42] = c0 * d; + out_shs[30] = s0 * d; + d = 47.909948945 * a; + out_grads[42][0] = c1 * d; + out_grads[30][0] = s1 * d; + out_grads[42][1] = -s1 * d; + out_grads[30][1] = c1 * d; + d = -51.748659331 * a; + out_grads[41][2] = c1 * d; + out_grads[31][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + out_shs[43] = c1 * d; + out_shs[29] = s1 * d; + d = -20.409946485 * z; + out_grads[43][0] = c0 * d; + out_grads[29][0] = s0 * d; + out_grads[43][1] = s0 * d; + out_grads[29][1] = c0 * d; + d = 15.969982982 * z; + out_grads[42][2] = c0 * d; + out_grads[30][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + out_shs[44] = c0 * d; + out_shs[28] = s0 * d; + d = 5.831413281; + out_grads[44][0] = c1 * d; + out_grads[28][0] = s1 * d; + out_grads[44][1] = -s1 * d; + out_grads[28][1] = c1 * d; + d = -2.915706641; + out_grads[43][2] = c1 * d; + out_grads[29][2] = s1 * d; + out_grads[0][0] = 0.0; + out_grads[0][1] = 0.0; + out_grads[0][2] = 0.0; + out_grads[5][2] = 0.0; + out_grads[3][0] = 0.0; + out_grads[3][1] = 0.0; + out_grads[1][2] = 0.0; + out_grads[14][2] = 0.0; + out_grads[10][0] = 0.0; + out_grads[10][1] = 0.0; + out_grads[6][2] = 0.0; + out_grads[27][2] = 0.0; + out_grads[21][0] = 0.0; + out_grads[21][1] = 0.0; + out_grads[15][2] = 0.0; + out_grads[44][2] = 0.0; + out_grads[36][0] = 0.0; + out_grads[36][1] = 0.0; + out_grads[28][2] = 0.0; +} diff --git a/fury/shaders/rt_odfs/find_roots.frag b/fury/shaders/utils/find_roots.frag similarity index 100% rename from fury/shaders/rt_odfs/find_roots.frag rename to fury/shaders/utils/find_roots.frag diff --git a/fury/shaders/rt_odfs/newton_bisection.frag b/fury/shaders/utils/newton_bisection.frag similarity index 100% rename from fury/shaders/rt_odfs/newton_bisection.frag rename to fury/shaders/utils/newton_bisection.frag From 49aeedac6c2190c09a5890228ca2df30cb9db995 Mon Sep 17 00:00:00 2001 From: tvcastillod Date: Fri, 1 Mar 2024 11:39:22 -0500 Subject: [PATCH 107/118] added degree param --- .../SH-ODF experimental/odf_example.py | 37 +++++++++- fury/actors/odf.py | 74 +++++-------------- ...grad_10 copy.frag => eval_sh_grad_10.frag} | 0 ...grad_12 copy.frag => eval_sh_grad_12.frag} | 0 ...h_grad_2 copy.frag => eval_sh_grad_2.frag} | 0 ...h_grad_4 copy.frag => eval_sh_grad_4.frag} | 0 ...h_grad_6 copy.frag => eval_sh_grad_6.frag} | 0 ...h_grad_8 copy.frag => eval_sh_grad_8.frag} | 0 8 files changed, 53 insertions(+), 58 deletions(-) rename fury/shaders/rt_odfs/tournier/{eval_sh_grad_10 copy.frag => eval_sh_grad_10.frag} (100%) rename fury/shaders/rt_odfs/tournier/{eval_sh_grad_12 copy.frag => eval_sh_grad_12.frag} (100%) rename fury/shaders/rt_odfs/tournier/{eval_sh_grad_2 copy.frag => eval_sh_grad_2.frag} (100%) rename fury/shaders/rt_odfs/tournier/{eval_sh_grad_4 copy.frag => eval_sh_grad_4.frag} (100%) rename fury/shaders/rt_odfs/tournier/{eval_sh_grad_6 copy.frag => eval_sh_grad_6.frag} (100%) rename fury/shaders/rt_odfs/tournier/{eval_sh_grad_8 copy.frag => eval_sh_grad_8.frag} (100%) diff --git a/docs/experimental/SH-ODF experimental/odf_example.py b/docs/experimental/SH-ODF experimental/odf_example.py index e16858211..50978942d 100644 --- a/docs/experimental/SH-ODF experimental/odf_example.py +++ b/docs/experimental/SH-ODF experimental/odf_example.py @@ -20,8 +20,39 @@ x, y, z, s = coeffs.shape coeffs = coeffs[:, :, :].reshape((x * y * z, s)) - n_glyphs = coeffs.shape[0] - - odf_actor = actor.odf(centers=centers, coeffs=coeffs, scales=1.0) + + #''' + coeffs = np.array([ + [ + -0.2739740312099, 0.2526670396328, 1.8922271728516, 0.2878578901291, + -0.5339795947075, -0.2620058953762, 0.1580424904823, 0.0329004973173, + -0.1322413831949, -0.1332057565451, 1.0894461870193, -0.6319401264191, + -0.0416776277125, -1.0772529840469, 0.1423762738705, 0.7941166162491, + 0.7490307092667, -0.3428381681442, 0.1024847552180, -0.0219132602215, + 0.0499043911695, 0.2162453681231, 0.0921059995890, -0.2611238956451, + 0.2549301385880, -0.4534865319729, 0.1922748684883, -0.6200597286224, + -0.0532187558711, -0.3569841980934, 0.0293972902000, -0.1977960765362, + -0.1058669015765, 0.2372217923403, -0.1856198310852, -0.3373193442822, + -0.0750469490886, 0.2146576642990, -0.0490148440003, 0.1288588196039, + 0.3173974752426, 0.1990085393190, -0.1736343950033, -0.0482443645597, + 0.1749017387629, -0.0151847425660, 0.0418366046081, 0.0863263587216, + -0.0649211244490, 0.0126096132283, 0.0545089217982, -0.0275142164626, + 0.0399986574832, -0.0468244261610, -0.1292105653111, -0.0786858322658, + -0.0663828464882, 0.0382439706831, -0.0041550330365, -0.0502800566338, + -0.0732471630735, 0.0181751900972, -0.0090119333757, -0.0604443282359, + -0.1469985252752, -0.0534046899715, -0.0896672753415, -0.0130841364808, + -0.0112942893801, 0.0272257498541, 0.0626717616331, -0.0222197983050, + -0.0018541504308, -0.1653251944056, 0.0409697402846, 0.0749921454327, + -0.0282830872616, 0.0006909458525, 0.0625599842287, 0.0812529816082, + 0.0914693020772, -0.1197222726745, 0.0376277453183, -0.0832617004142, + -0.0482175038043, -0.0839003635737, -0.0349423908400, 0.1204519568256, + 0.0783745984003, 0.0297401205976, -0.0505947662525 + ] + ]) + centers= np.array([0, 0, 0]) + #''' + + odf_actor = actor.odf(centers=centers, coeffs=coeffs, scales=1.0, + basis_type='descoteaux', degree=6) show_man.scene.add(odf_actor) show_man.start() \ No newline at end of file diff --git a/fury/actors/odf.py b/fury/actors/odf.py index e8a762c55..139567a56 100644 --- a/fury/actors/odf.py +++ b/fury/actors/odf.py @@ -32,14 +32,13 @@ def uv_calculations(n): return uvs def minmax_norm(data): - min = data.min(axis=1) max = data.max(axis=1) return np.array([(data[i] - min[i]) / (max[i] - min[i]) for i in range(data.shape[0])]) -def sh_odf(centers, coeffs, basis_type, scales, opacity): +def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): """ Visualize one or many ODFs with different features. @@ -53,6 +52,9 @@ def sh_odf(centers, coeffs, basis_type, scales, opacity): Type of basis (descoteaux, tournier) 'descoteaux' for the default ``descoteaux07`` DYPY basis. 'tournier' for the default ``tournier07` DYPY basis. + degree: int, optional + Index of the highest used band of the spherical harmonics basis. Must + be even, at least 2 and at most 12. scales : float or ndarray (N, ) ODFs size. opacity : float @@ -108,7 +110,7 @@ def sh_odf(centers, coeffs, basis_type, scales, opacity): # The number of coefficients is associated to the order of the SH odf_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniformf( - "numCoeffs", 15 + "numCoeffs", ((degree + 1) * (degree + 2)) / 2 ) # Start of shader implementation @@ -142,7 +144,7 @@ def sh_odf(centers, coeffs, basis_type, scales, opacity): # The index of the highest used band of the spherical harmonics basis. Must # be even, at least 2 and at most 12. - def_sh_degree = "#define SH_DEGREE 4" + def_sh_degree = "#define SH_DEGREE " + str(degree) # The number of spherical harmonics basis functions def_sh_count = "#define SH_COUNT (((SH_DEGREE + 1) * (SH_DEGREE + 2)) / 2)" @@ -187,47 +189,14 @@ def sh_odf(centers, coeffs, basis_type, scales, opacity): coeffs_norm = import_fury_shader(os.path.join("utils", "minmax_norm.glsl")) - eval_sh_2 = import_fury_shader( - os.path.join("rt_odfs", basis_type, "eval_sh_2.frag")) - - eval_sh_4 = import_fury_shader( - os.path.join("rt_odfs", basis_type, "eval_sh_4.frag")) - - eval_sh_6 = import_fury_shader( - os.path.join("rt_odfs", basis_type, "eval_sh_6.frag")) - - eval_sh_8 = import_fury_shader( - os.path.join("rt_odfs", basis_type, "eval_sh_8.frag")) - - eval_sh_10 = import_fury_shader( - os.path.join("rt_odfs", basis_type, "eval_sh_10.frag")) - - eval_sh_12 = import_fury_shader( - os.path.join("rt_odfs", basis_type, "eval_sh_12.frag")) - - eval_sh_grad_2 = import_fury_shader( - os.path.join("rt_odfs/descoteaux", "eval_sh_grad_2.frag") - ) - - eval_sh_grad_4 = import_fury_shader( - os.path.join("rt_odfs/descoteaux", "eval_sh_grad_4.frag") - ) - - eval_sh_grad_6 = import_fury_shader( - os.path.join("rt_odfs/descoteaux", "eval_sh_grad_6.frag") - ) - - eval_sh_grad_8 = import_fury_shader( - os.path.join("rt_odfs/descoteaux", "eval_sh_grad_8.frag") - ) - - eval_sh_grad_10 = import_fury_shader( - os.path.join("rt_odfs/descoteaux", "eval_sh_grad_10.frag") - ) - - eval_sh_grad_12 = import_fury_shader( - os.path.join("rt_odfs/descoteaux", "eval_sh_grad_12.frag") - ) + eval_sh_list = '' + for i in range (2, degree+1, 2): + eval_sh = import_fury_shader( + os.path.join("rt_odfs", basis_type, 'eval_sh_' + str(i) + '.frag')) + eval_sh_grad = import_fury_shader( + os.path.join("rt_odfs", basis_type, + 'eval_sh_grad_' + str(i) + '.frag')) + eval_sh_list = eval_sh_list + '\n\n' + eval_sh + '\n\n' + eval_sh_grad # Searches a single root of a polynomial within a given interval. # param out_root The location of the found root. @@ -334,13 +303,10 @@ def sh_odf(centers, coeffs, basis_type, scales, opacity): fs_dec = compose_shader([ def_sh_degree, def_sh_count, def_max_degree, def_gl_ext_control_flow_attributes, def_no_intersection, def_pis, - fs_vs_vars, coeffs_norm, eval_sh_2, eval_sh_4, eval_sh_6, eval_sh_8, - eval_sh_10, eval_sh_12, eval_sh_grad_2, eval_sh_grad_4, eval_sh_grad_6, - eval_sh_grad_8, eval_sh_grad_10, eval_sh_grad_12, newton_bisection, - find_roots, eval_sh, eval_sh_grad, get_inv_vandermonde, - ray_sh_glyph_intersections, get_sh_glyph_normal, blinn_phong_model, - linear_to_srgb, srgb_to_linear, linear_rgb_to_srgb, srgb_to_linear_rgb, - tonemap + fs_vs_vars, coeffs_norm, eval_sh_list, newton_bisection, find_roots, + eval_sh, eval_sh_grad, get_inv_vandermonde, ray_sh_glyph_intersections, + get_sh_glyph_normal, blinn_phong_model, linear_to_srgb, srgb_to_linear, + linear_rgb_to_srgb, srgb_to_linear_rgb, tonemap ]) # fmt: on @@ -351,7 +317,6 @@ def sh_odf(centers, coeffs, basis_type, scales, opacity): # Ray origin is the camera position in world space ray_origin = "vec3 ro = camPosMCVSOutput;" - # TODO: Check aspect for automatic scaling # Ray direction is the normalized difference between the fragment and the # camera position/ray origin ray_direction = "vec3 rd = normalize(pnt - ro);" @@ -392,7 +357,7 @@ def sh_odf(centers, coeffs, basis_type, scales, opacity): break; } } - """ + """ # Evaluate shading for a directional light directional_light = \ @@ -404,7 +369,6 @@ def sh_odf(centers, coeffs, basis_type, scales, opacity): vec3 colorDir = srgb_to_linear_rgb(abs(normalize(intersection))); float attenuation = dot(ld, normal); color = blinnPhongIllumModel( - //attenuation, lightColor0, diffuseColor, specularPower, attenuation, lightColor0, colorDir, specularPower, specularColor, ambientColor); } else { diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_10 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_10.frag similarity index 100% rename from fury/shaders/rt_odfs/tournier/eval_sh_grad_10 copy.frag rename to fury/shaders/rt_odfs/tournier/eval_sh_grad_10.frag diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_12 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_12.frag similarity index 100% rename from fury/shaders/rt_odfs/tournier/eval_sh_grad_12 copy.frag rename to fury/shaders/rt_odfs/tournier/eval_sh_grad_12.frag diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_2 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_2.frag similarity index 100% rename from fury/shaders/rt_odfs/tournier/eval_sh_grad_2 copy.frag rename to fury/shaders/rt_odfs/tournier/eval_sh_grad_2.frag diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_4 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_4.frag similarity index 100% rename from fury/shaders/rt_odfs/tournier/eval_sh_grad_4 copy.frag rename to fury/shaders/rt_odfs/tournier/eval_sh_grad_4.frag diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_6 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_6.frag similarity index 100% rename from fury/shaders/rt_odfs/tournier/eval_sh_grad_6 copy.frag rename to fury/shaders/rt_odfs/tournier/eval_sh_grad_6.frag diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_8 copy.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_8.frag similarity index 100% rename from fury/shaders/rt_odfs/tournier/eval_sh_grad_8 copy.frag rename to fury/shaders/rt_odfs/tournier/eval_sh_grad_8.frag From a2539d25e366ef74dee6b386270cab79213a27e1 Mon Sep 17 00:00:00 2001 From: tvcastillod Date: Wed, 6 Mar 2024 18:05:58 -0500 Subject: [PATCH 108/118] adjusted the degree setting --- .../experimental/SH-ODF experimental/odf_example.py | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/docs/experimental/SH-ODF experimental/odf_example.py b/docs/experimental/SH-ODF experimental/odf_example.py index 50978942d..c31dac722 100644 --- a/docs/experimental/SH-ODF experimental/odf_example.py +++ b/docs/experimental/SH-ODF experimental/odf_example.py @@ -35,18 +35,7 @@ -0.1058669015765, 0.2372217923403, -0.1856198310852, -0.3373193442822, -0.0750469490886, 0.2146576642990, -0.0490148440003, 0.1288588196039, 0.3173974752426, 0.1990085393190, -0.1736343950033, -0.0482443645597, - 0.1749017387629, -0.0151847425660, 0.0418366046081, 0.0863263587216, - -0.0649211244490, 0.0126096132283, 0.0545089217982, -0.0275142164626, - 0.0399986574832, -0.0468244261610, -0.1292105653111, -0.0786858322658, - -0.0663828464882, 0.0382439706831, -0.0041550330365, -0.0502800566338, - -0.0732471630735, 0.0181751900972, -0.0090119333757, -0.0604443282359, - -0.1469985252752, -0.0534046899715, -0.0896672753415, -0.0130841364808, - -0.0112942893801, 0.0272257498541, 0.0626717616331, -0.0222197983050, - -0.0018541504308, -0.1653251944056, 0.0409697402846, 0.0749921454327, - -0.0282830872616, 0.0006909458525, 0.0625599842287, 0.0812529816082, - 0.0914693020772, -0.1197222726745, 0.0376277453183, -0.0832617004142, - -0.0482175038043, -0.0839003635737, -0.0349423908400, 0.1204519568256, - 0.0783745984003, 0.0297401205976, -0.0505947662525 + 0.1749017387629 ] ]) centers= np.array([0, 0, 0]) From 6f95e7aa9e22e4f2333400a4f797e648a66d2083 Mon Sep 17 00:00:00 2001 From: tvcastillod Date: Mon, 18 Mar 2024 13:07:16 -0500 Subject: [PATCH 109/118] added tests --- .../SH-ODF experimental/odf_example.py | 47 ----------- fury/actor.py | 79 +++++++++++++++++++ fury/actors/odf.py | 54 ++++--------- fury/tests/test_actors.py | 73 +++++++++++++++++ fury/tests/test_utils.py | 21 +++++ fury/texture/utils.py | 18 +++++ fury/utils.py | 33 ++++++++ 7 files changed, 241 insertions(+), 84 deletions(-) delete mode 100644 docs/experimental/SH-ODF experimental/odf_example.py create mode 100644 fury/texture/utils.py diff --git a/docs/experimental/SH-ODF experimental/odf_example.py b/docs/experimental/SH-ODF experimental/odf_example.py deleted file mode 100644 index c31dac722..000000000 --- a/docs/experimental/SH-ODF experimental/odf_example.py +++ /dev/null @@ -1,47 +0,0 @@ -import os - -import numpy as np -from dipy.data.fetcher import dipy_home -from dipy.io.image import load_nifti - -from fury import actor, window - -if __name__ == "__main__": - show_man = window.ShowManager(size=(1280, 720)) - - dataset_dir = os.path.join(dipy_home, "stanford_hardi") - - coeffs, affine = load_nifti("docs\experimental\SH-ODF experimental\coefs_odf.nii") - - valid_mask = np.abs(coeffs).max(axis=(-1)) > 0 - indices = np.nonzero(valid_mask) - - centers = np.asarray(indices).T - - x, y, z, s = coeffs.shape - coeffs = coeffs[:, :, :].reshape((x * y * z, s)) - - #''' - coeffs = np.array([ - [ - -0.2739740312099, 0.2526670396328, 1.8922271728516, 0.2878578901291, - -0.5339795947075, -0.2620058953762, 0.1580424904823, 0.0329004973173, - -0.1322413831949, -0.1332057565451, 1.0894461870193, -0.6319401264191, - -0.0416776277125, -1.0772529840469, 0.1423762738705, 0.7941166162491, - 0.7490307092667, -0.3428381681442, 0.1024847552180, -0.0219132602215, - 0.0499043911695, 0.2162453681231, 0.0921059995890, -0.2611238956451, - 0.2549301385880, -0.4534865319729, 0.1922748684883, -0.6200597286224, - -0.0532187558711, -0.3569841980934, 0.0293972902000, -0.1977960765362, - -0.1058669015765, 0.2372217923403, -0.1856198310852, -0.3373193442822, - -0.0750469490886, 0.2146576642990, -0.0490148440003, 0.1288588196039, - 0.3173974752426, 0.1990085393190, -0.1736343950033, -0.0482443645597, - 0.1749017387629 - ] - ]) - centers= np.array([0, 0, 0]) - #''' - - odf_actor = actor.odf(centers=centers, coeffs=coeffs, scales=1.0, - basis_type='descoteaux', degree=6) - show_man.scene.add(odf_actor) - show_man.start() \ No newline at end of file diff --git a/fury/actor.py b/fury/actor.py index 3d552ae3a..488d72fb3 100644 --- a/fury/actor.py +++ b/fury/actor.py @@ -4019,3 +4019,82 @@ def uncertainty_cone( angles = main_dir_uncertainty(evals, evecs, signal, sigma, b_matrix) return double_cone(centers, evecs, angles, colors, scales, opacity) + + +def odf( + centers, + coeffs, + degree=None, + basis_type='descoteaux', + scales=1.0, + opacity=1.0 +): + """ + VTK actor for visualizing ODFs given an array of spherical harmonics (SH) + coefficients. + + Parameters + ---------- + centers : ndarray(N, 3) + ODFs positions. + coeffs : ndarray + 2D ODFs array in SH coefficients. + degree: int, optional + Index of the highest used band of the spherical harmonics basis. Must + be even, at least 2 and at most 12. If None the degree is set based on + the number of SH coefficients given. + basis_type: str, optional + Type of basis (descoteaux, tournier) + 'descoteaux' for the default ``descoteaux07`` DYPY basis. + 'tournier' for the default ``tournier07` DYPY basis. + scales : float or ndarray (N, ) + ODFs size. + opacity : float + Takes values from 0 (fully transparent) to 1 (opaque). + + Returns + ------- + odf: Actor + + """ + + if not isinstance(centers, np.ndarray): + centers = np.array(centers) + if centers.ndim == 1: + centers = np.array([centers]) + + if not isinstance(coeffs, np.ndarray): + coeffs = np.array(coeffs) + if coeffs.ndim == 1: + coeffs = np.array([coeffs]) + if coeffs.shape[0] != centers.shape[0]: + raise ValueError('number of odf glyphs defined does not match with ' + 'number of centers') + + coeffs_given = coeffs.shape[-1] + if degree is None: + degree = int((np.sqrt(8 * coeffs_given + 1) - 3)/2) + elif degree % 2 != 0: + raise ValueError('degree must be even') + coeffs_needed = int(((degree + 1) * (degree + 2)) / 2) + if coeffs_given < coeffs_needed: + print('Not enough number of coefficient for SH of degree {0}. ' + 'Expected at least {1}'.format(degree, coeffs_needed)) + degree = int((np.sqrt(8 * coeffs_given + 1) - 3)/2) + if (degree % 2 != 0): + degree -= 1 + coeffs_needed = int(((degree + 1) * (degree + 2)) / 2) + coeffs = coeffs[:, :coeffs_needed] + + if not isinstance(scales, np.ndarray): + scales = np.array(scales) + if scales.size == 1: + scales = np.repeat(scales, centers.shape[0]) + elif scales.size != centers.shape[0]: + scales = np.concatenate( + (scales, np.ones(centers.shape[0] - scales.shape[0])), axis=None) + + total = np.sum(abs(coeffs), axis=1) + coeffs = np.dot(np.diag(1 / total * scales), coeffs) * 1.7 + + return sh_odf(centers, coeffs, degree, basis_type, scales, opacity) diff --git a/fury/actors/odf.py b/fury/actors/odf.py index 139567a56..938cae791 100644 --- a/fury/actors/odf.py +++ b/fury/actors/odf.py @@ -10,33 +10,13 @@ import_fury_shader, shader_to_actor, ) -from fury.utils import numpy_to_vtk_image_data, set_polydata_tcoords - -def uv_calculations(n): - uvs = [] - for i in range(0, n): - a = (n - (i + 1)) / n - b = (n - i) / n - uvs.extend( - [ - [0.001, a + 0.001], - [0.001, b - 0.001], - [0.999, b - 0.001], - [0.999, a + 0.001], - [0.001, a + 0.001], - [0.001, b - 0.001], - [0.999, b - 0.001], - [0.999, a + 0.001], - ] - ) - return uvs - -def minmax_norm(data): - min = data.min(axis=1) - max = data.max(axis=1) - return np.array([(data[i] - min[i]) / (max[i] - min[i]) - for i in range(data.shape[0])]) - +from fury.utils import ( + numpy_to_vtk_image_data, + set_polydata_tcoords, + minmax_norm +) +from fury.texture.utils import uv_calculations + def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): """ @@ -75,9 +55,9 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): minmax = np.array([coeffs.min(axis=1), coeffs.max(axis=1)]).T big_minmax = np.repeat(minmax, 8, axis=0) attribute_to_actor(odf_actor, big_minmax, "minmax") - + # The coefficient data is stored in a texture to be passed to the shaders. - + # Data is normalized to a range of 0 to 1. arr = minmax_norm(coeffs) # Data is turned into values within the RGB color range, and then coverted @@ -92,8 +72,7 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): # Texture is associated with the actor odf_actor.GetProperty().SetTexture("texture0", texture) - - + odf_actor_pd = odf_actor.GetMapper().GetInput() n_glyphs = coeffs.shape[0] @@ -101,6 +80,7 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): uv_vals = np.array(uv_calculations(n_glyphs)) num_pnts = uv_vals.shape[0] + # Definition of texture coordinates to be associated with the actor. t_coords = FloatArray() t_coords.SetNumberOfComponents(2) t_coords.SetNumberOfTuples(num_pnts) @@ -112,9 +92,9 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): odf_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniformf( "numCoeffs", ((degree + 1) * (degree + 2)) / 2 ) - + # Start of shader implementation - + vs_dec = \ """ in vec3 center; @@ -188,13 +168,13 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): """ coeffs_norm = import_fury_shader(os.path.join("utils", "minmax_norm.glsl")) - + eval_sh_list = '' - for i in range (2, degree+1, 2): + for i in range(2, degree+1, 2): eval_sh = import_fury_shader( os.path.join("rt_odfs", basis_type, 'eval_sh_' + str(i) + '.frag')) eval_sh_grad = import_fury_shader( - os.path.join("rt_odfs", basis_type, + os.path.join("rt_odfs", basis_type, 'eval_sh_grad_' + str(i) + '.frag')) eval_sh_list = eval_sh_list + '\n\n' + eval_sh + '\n\n' + eval_sh_grad @@ -388,5 +368,5 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): ]) shader_to_actor(odf_actor, "fragment", impl_code=fs_impl, block="picking") - + return odf_actor \ No newline at end of file diff --git a/fury/tests/test_actors.py b/fury/tests/test_actors.py index 4f6b2b5df..1ddde3b68 100644 --- a/fury/tests/test_actors.py +++ b/fury/tests/test_actors.py @@ -1950,3 +1950,76 @@ def test_actors_primitives_count(): primitives_count = test_case[2] act = act_func(**args) npt.assert_equal(primitives_count_from_actor(act), primitives_count) + + +def test_odf_actor(interactive=False): + # number of odf glyphs does not match with number of centers + centers = np.array([[0, -1, 0]]) + coeffs = np.array([[0.282, 0.152, -0.040, -0.112, -0.045, 0.149], + [0.285, 0.097, -0.115, 0.125, -0.001, 0.003]]) + npt.assert_raises(ValueError, actor.odf, centers, coeffs) + + scene = window.Scene() + centers = np.array([[0, -1, 0], [1, -1, 0], [2, -1, 0]]) + coeffs = np.array([ + [0.2820735, 0.15236554, -0.04038717, -0.11270988, -0.04532376, + 0.14921817, 0.00257928, 0.0040734, -0.05313807, 0.03486542, + 0.04083064, 0.02105767, -0.04389586, -0.04302812, 0.1048641], + [0.28549338, 0.0978267, -0.11544838, 0.12525354, -0.00126003, + 0.00320594, 0.04744155, -0.07141446, 0.03211689, 0.04711322, + 0.08064896, 0.00154299, 0.00086506, 0.00162543, -0.00444893], + [0.28208936, -0.13133252, -0.04701012, -0.06303016, -0.0468775, + 0.02348355, 0.03991898, 0.02587433, 0.02645416, 0.00668765, + 0.00890633, 0.02189304, 0.00387415, 0.01665629, -0.01427194] + ]) + odf_actor = actor.odf(centers=centers, coeffs=coeffs) + scene.add(odf_actor) + + if interactive: + window.show(scene) + + report = window.analyze_scene(scene) + npt.assert_equal(report.actors, 1) + scene.clear() + + # given degree is not even + npt.assert_raises(ValueError, actor.odf, centers, coeffs, degree=3) + + centers= np.array([0, 0, 0]) + coeffs = np.array([ + [-0.2739740312099, 0.2526670396328, 1.8922271728516, 0.2878578901291, + -0.5339795947075, -0.2620058953762, 0.1580424904823, 0.0329004973173, + -0.1322413831949, -0.1332057565451, 1.0894461870193, -0.6319401264191, + -0.0416776277125, -1.0772529840469, 0.1423762738705, 0.7941166162491, + 0.7490307092667, -0.3428381681442, 0.1024847552180, -0.0219132602215, + 0.0499043911695, 0.2162453681231, 0.0921059995890, -0.2611238956451, + 0.2549301385880,-0.4534865319729, 0.1922748684883, -0.6200597286224] + ]) + odf_actor = actor.odf(centers=centers, coeffs=coeffs, degree=6) + scene.add(odf_actor) + + if interactive: + window.show(scene) + + report = window.analyze_scene(scene) + npt.assert_equal(report.actors, 1) + scene.clear() + + odf_actor = actor.odf(centers=centers, coeffs=coeffs, degree=4) + scene.add(odf_actor) + + if interactive: + window.show(scene) + + report = window.analyze_scene(scene) + npt.assert_equal(report.actors, 1) + scene.clear() + + odf_actor = actor.odf(centers=centers, coeffs=coeffs, degree=8) + scene.add(odf_actor) + + if interactive: + window.show(scene) + + npt.assert_equal(report.actors, 1) + scene.clear() diff --git a/fury/tests/test_utils.py b/fury/tests/test_utils.py index e7c347438..6f3b793ab 100644 --- a/fury/tests/test_utils.py +++ b/fury/tests/test_utils.py @@ -54,6 +54,7 @@ update_surface_actor_colors, vertices_from_actor, vtk_matrix_to_numpy, + minmax_norm, ) dipy, have_dipy, _ = optional_package("dipy") @@ -970,3 +971,23 @@ def test_set_actor_origin(): utils.set_actor_origin(cube) centered_cube_vertices = np.copy(vertices_from_actor(cube)) npt.assert_array_equal(orig_vert, centered_cube_vertices) + + +def test_minmax_normalization(): + data = np.array([[1, 2, -1, 3], [4, -1, 3, 5], [-1, 9, 8, 0]]) + + actual = minmax_norm(data, axis=0) + expected = np.array([[0.4, 0.3, 0, 0.6], [1, 0, 0.444, 1], [0, 1, 1, 0]]) + npt.assert_array_almost_equal(actual, expected, decimal=3) + actual = minmax_norm(data, axis=1) + expected = np.array([[0.5, 0.75, 0, 1], [0.833, 0, 0.666, 1], + [0, 1, 0.9, 0.1]]) + npt.assert_array_almost_equal(actual, expected, decimal=3) + + data2 = np.array([1, 3, 9, 6]) + actual2 = minmax_norm(data2, axis=0) + expected2 = np.array([[1, 3, 9, 6]]) + npt.assert_array_equal(actual2, expected2) + actual2 = minmax_norm(data2, axis=1) + expected2 = np.array([[0, 0.25 , 1, 0.625]]) + npt.assert_array_almost_equal(actual2, expected2, decimal=3) diff --git a/fury/texture/utils.py b/fury/texture/utils.py new file mode 100644 index 000000000..b75bebde5 --- /dev/null +++ b/fury/texture/utils.py @@ -0,0 +1,18 @@ +def uv_calculations(n): + uvs = [] + for i in range(0, n): + a = (n - (i + 1)) / n + b = (n - i) / n + uvs.extend( + [ + [0.001, a + 0.001], + [0.001, b - 0.001], + [0.999, b - 0.001], + [0.999, a + 0.001], + [0.001, a + 0.001], + [0.001, b - 0.001], + [0.999, b - 0.001], + [0.999, a + 0.001], + ] + ) + return uvs \ No newline at end of file diff --git a/fury/utils.py b/fury/utils.py index cb5d0671f..089108826 100644 --- a/fury/utils.py +++ b/fury/utils.py @@ -1622,3 +1622,36 @@ def set_actor_origin(actor, *, center=None): center = np.mean(vertices) vertices[:] -= center update_actor(actor) + + +def minmax_norm(data, axis=1): + """Returns the min-max normalization of data + + Parameters + ---------- + data: ndarray + 2D array + axis: int + axis for the function to be applied on + + Returns + ------- + output : ndarray + + """ + + if not isinstance(data, np.ndarray): + data = np.array(data) + if data.ndim == 1: + data = np.array([data]) + elif data.ndim > 2: + raise ValueError('the dimension of the array must be 2.') + + min = data.min(axis=axis) + max = data.max(axis=axis) + if np.array_equal(min, max): + return data + if (axis == 0): + return (data - min)/(max - min) + if (axis == 1): + return (data - min[:, None])/(max - min)[:, None] From f2204f0b13013123eedcb0a4fdde96672360ab11 Mon Sep 17 00:00:00 2001 From: tvcastillod Date: Fri, 29 Mar 2024 10:15:18 -0500 Subject: [PATCH 110/118] adjustments on tests and parameter validation --- fury/actor.py | 49 +++++++++++++++++++------------- fury/actors/odf.py | 2 +- fury/tests/test_actors.py | 22 +++++++------- fury/tests/test_utils.py | 14 +++++++-- fury/texture/tests/__init__.py | 0 fury/texture/tests/test_utils.py | 41 ++++++++++++++++++++++++++ fury/texture/utils.py | 15 +++++++++- fury/utils.py | 12 ++++---- 8 files changed, 115 insertions(+), 40 deletions(-) create mode 100644 fury/texture/tests/__init__.py create mode 100644 fury/texture/tests/test_utils.py diff --git a/fury/actor.py b/fury/actor.py index 488d72fb3..075050f68 100644 --- a/fury/actor.py +++ b/fury/actor.py @@ -4030,15 +4030,16 @@ def odf( opacity=1.0 ): """ - VTK actor for visualizing ODFs given an array of spherical harmonics (SH) - coefficients. + FURY actor for visualizing Orientation Distribution Functions (ODFs) given + an array of Spherical Harmonics (SH) coefficients. Parameters ---------- centers : ndarray(N, 3) ODFs positions. - coeffs : ndarray - 2D ODFs array in SH coefficients. + coeffs : (N, M) or (N, 6) or (N, 15) or (N, 28) or (N, 45) or (N, 66) or + (N, 91) ndarray. + Corresponding SH coefficients for the ODFs. degree: int, optional Index of the highest used band of the spherical harmonics basis. Must be even, at least 2 and at most 12. If None the degree is set based on @@ -4062,29 +4063,39 @@ def odf( centers = np.array(centers) if centers.ndim == 1: centers = np.array([centers]) - + if not isinstance(coeffs, np.ndarray): coeffs = np.array(coeffs) - if coeffs.ndim == 1: - coeffs = np.array([coeffs]) + if coeffs.ndim != 2: + if coeffs.ndim == 1: + coeffs = np.array([coeffs]) + else: + raise ValueError('coeffs should be a 2D array.') if coeffs.shape[0] != centers.shape[0]: raise ValueError('number of odf glyphs defined does not match with ' 'number of centers') coeffs_given = coeffs.shape[-1] + max_degree = int((np.sqrt(8 * coeffs_given + 1) - 3) / 2) if degree is None: - degree = int((np.sqrt(8 * coeffs_given + 1) - 3)/2) - elif degree % 2 != 0: - raise ValueError('degree must be even') - coeffs_needed = int(((degree + 1) * (degree + 2)) / 2) - if coeffs_given < coeffs_needed: - print('Not enough number of coefficient for SH of degree {0}. ' - 'Expected at least {1}'.format(degree, coeffs_needed)) - degree = int((np.sqrt(8 * coeffs_given + 1) - 3)/2) - if (degree % 2 != 0): - degree -= 1 - coeffs_needed = int(((degree + 1) * (degree + 2)) / 2) - coeffs = coeffs[:, :coeffs_needed] + degree = max_degree + else: + if degree % 2 != 0: + warnings.warn('Invalid degree value. Degree must be a positive ' + 'even number lower or equal to 12. Ignoring passed ' + 'value and using maximum degree supported by the ' + 'number of SH coefficients.') + degree = max_degree + else: + coeffs_needed = int(((degree + 1) * (degree + 2)) / 2) + if coeffs_given < coeffs_needed: + warnings.warn('Not enough number of coefficient for SH of ' + 'degree {0}, expected at least {1}. Ignoring ' + 'passed value and using maximum degree supported ' + 'by the number of SH coefficients.' + .format(degree, coeffs_needed)) + degree = max_degree + coeffs = coeffs[:, :int(((degree + 1) * (degree + 2)) / 2)] if not isinstance(scales, np.ndarray): scales = np.array(scales) diff --git a/fury/actors/odf.py b/fury/actors/odf.py index 938cae791..5e8fbe4d4 100644 --- a/fury/actors/odf.py +++ b/fury/actors/odf.py @@ -369,4 +369,4 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): shader_to_actor(odf_actor, "fragment", impl_code=fs_impl, block="picking") - return odf_actor \ No newline at end of file + return odf_actor diff --git a/fury/tests/test_actors.py b/fury/tests/test_actors.py index 1ddde3b68..043cc0992 100644 --- a/fury/tests/test_actors.py +++ b/fury/tests/test_actors.py @@ -1958,7 +1958,7 @@ def test_odf_actor(interactive=False): coeffs = np.array([[0.282, 0.152, -0.040, -0.112, -0.045, 0.149], [0.285, 0.097, -0.115, 0.125, -0.001, 0.003]]) npt.assert_raises(ValueError, actor.odf, centers, coeffs) - + scene = window.Scene() centers = np.array([[0, -1, 0], [1, -1, 0], [2, -1, 0]]) coeffs = np.array([ @@ -1981,11 +1981,11 @@ def test_odf_actor(interactive=False): report = window.analyze_scene(scene) npt.assert_equal(report.actors, 1) scene.clear() - + # given degree is not even - npt.assert_raises(ValueError, actor.odf, centers, coeffs, degree=3) + npt.assert_warns(UserWarning, actor.odf, centers, coeffs, 3) - centers= np.array([0, 0, 0]) + centers = np.array([0, 0, 0]) coeffs = np.array([ [-0.2739740312099, 0.2526670396328, 1.8922271728516, 0.2878578901291, -0.5339795947075, -0.2620058953762, 0.1580424904823, 0.0329004973173, @@ -1993,7 +1993,7 @@ def test_odf_actor(interactive=False): -0.0416776277125, -1.0772529840469, 0.1423762738705, 0.7941166162491, 0.7490307092667, -0.3428381681442, 0.1024847552180, -0.0219132602215, 0.0499043911695, 0.2162453681231, 0.0921059995890, -0.2611238956451, - 0.2549301385880,-0.4534865319729, 0.1922748684883, -0.6200597286224] + 0.2549301385880, -0.4534865319729, 0.1922748684883, -0.6200597286224] ]) odf_actor = actor.odf(centers=centers, coeffs=coeffs, degree=6) scene.add(odf_actor) @@ -2007,19 +2007,21 @@ def test_odf_actor(interactive=False): odf_actor = actor.odf(centers=centers, coeffs=coeffs, degree=4) scene.add(odf_actor) - + if interactive: window.show(scene) - + report = window.analyze_scene(scene) npt.assert_equal(report.actors, 1) scene.clear() - + odf_actor = actor.odf(centers=centers, coeffs=coeffs, degree=8) + # not enough coefficients for given degree + npt.assert_warns(UserWarning, actor.odf, centers, coeffs, 8) scene.add(odf_actor) - + if interactive: window.show(scene) - + npt.assert_equal(report.actors, 1) scene.clear() diff --git a/fury/tests/test_utils.py b/fury/tests/test_utils.py index 6f3b793ab..f1758fa95 100644 --- a/fury/tests/test_utils.py +++ b/fury/tests/test_utils.py @@ -974,13 +974,21 @@ def test_set_actor_origin(): def test_minmax_normalization(): - data = np.array([[1, 2, -1, 3], [4, -1, 3, 5], [-1, 9, 8, 0]]) + data1d = np.array([2, -2, 5, -1, 8]) + actual_data1d = minmax_norm(data1d) + expected_data1d = np.array([[0.4, 0. , 0.7, 0.1, 1. ]]) + npt.assert_array_almost_equal(actual_data1d, expected_data1d, decimal=1) + + data3d = np.array([[[2, 7, 7, 9], [2, -1, -3, 5]], + [[-4, 5, 6, 0], [1, 1, -9, 3]]]) + npt.assert_raises(ValueError, utils.minmax_norm, data3d) + data = np.array([[1, 2, -1, 3], [4, -1, 3, 5], [-1, 9, 8, 0]]) actual = minmax_norm(data, axis=0) expected = np.array([[0.4, 0.3, 0, 0.6], [1, 0, 0.444, 1], [0, 1, 1, 0]]) npt.assert_array_almost_equal(actual, expected, decimal=3) actual = minmax_norm(data, axis=1) - expected = np.array([[0.5, 0.75, 0, 1], [0.833, 0, 0.666, 1], + expected = np.array([[0.5, 0.75, 0, 1], [0.833, 0, 0.666, 1], [0, 1, 0.9, 0.1]]) npt.assert_array_almost_equal(actual, expected, decimal=3) @@ -989,5 +997,5 @@ def test_minmax_normalization(): expected2 = np.array([[1, 3, 9, 6]]) npt.assert_array_equal(actual2, expected2) actual2 = minmax_norm(data2, axis=1) - expected2 = np.array([[0, 0.25 , 1, 0.625]]) + expected2 = np.array([[0, 0.25, 1, 0.625]]) npt.assert_array_almost_equal(actual2, expected2, decimal=3) diff --git a/fury/texture/tests/__init__.py b/fury/texture/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/fury/texture/tests/test_utils.py b/fury/texture/tests/test_utils.py new file mode 100644 index 000000000..71f108596 --- /dev/null +++ b/fury/texture/tests/test_utils.py @@ -0,0 +1,41 @@ +import numpy as np +import numpy.testing as npt +from fury.texture.utils import uv_calculations + +def test_uv_calculations(): + uv_coords = uv_calculations(1) + expected_uv1 = np.array([ + [0.001, 0.001], [0.001, 0.999], [0.999, 0.999], [0.999, 0.001], + [0.001, 0.001], [0.001, 0.999], [0.999, 0.999], [0.999, 0.001] + ]) + npt.assert_array_almost_equal(uv_coords, expected_uv1, decimal=3) + + uv_coords = uv_calculations(3) + expected_uv3 = np.array([ + [0.001, 0.667], [0.001, 0.999], [0.999, 0.999], [0.999, 0.667], + [0.001, 0.667], [0.001, 0.999], [0.999, 0.999], [0.999, 0.667], + [0.001, 0.334], [0.001, 0.665], [0.999, 0.665], [0.999, 0.334], + [0.001, 0.334], [0.001, 0.665], [0.999, 0.665], [0.999, 0.334], + [0.001, 0.001], [0.001, 0.332], [0.999, 0.332], [0.999, 0.001], + [0.001, 0.001], [0.001, 0.332], [0.999, 0.332], [0.999, 0.001] + ]) + npt.assert_array_almost_equal(uv_coords, expected_uv3, decimal=3) + + uv_coords = uv_calculations(7) + expected_uv7 = np.array([ + [0.001, 0.858], [0.001, 0.999], [0.999, 0.999], [0.999, 0.858], + [0.001, 0.858], [0.001, 0.999], [0.999, 0.999], [0.999, 0.858], + [0.001, 0.715], [0.001, 0.856], [0.999, 0.856], [0.999, 0.715], + [0.001, 0.715], [0.001, 0.856], [0.999, 0.856], [0.999, 0.715], + [0.001, 0.572], [0.001, 0.713], [0.999, 0.713], [0.999, 0.572], + [0.001, 0.572], [0.001, 0.713], [0.999, 0.713], [0.999, 0.572], + [0.001, 0.429], [0.001, 0.570], [0.999, 0.570], [0.999, 0.429], + [0.001, 0.429], [0.001, 0.570], [0.999, 0.570], [0.999, 0.429], + [0.001, 0.286], [0.001, 0.427], [0.999, 0.427], [0.999, 0.286], + [0.001, 0.286], [0.001, 0.427], [0.999, 0.427], [0.999, 0.286], + [0.001, 0.143], [0.001, 0.284], [0.999, 0.284], [0.999, 0.143], + [0.001, 0.143], [0.001, 0.284], [0.999, 0.284], [0.999, 0.143], + [0.001, 0.001], [0.001, 0.141], [0.999, 0.141], [0.999, 0.001], + [0.001, 0.001], [0.001, 0.141], [0.999, 0.141], [0.999, 0.001] + ]) + npt.assert_array_almost_equal(uv_coords, expected_uv7, decimal=3) diff --git a/fury/texture/utils.py b/fury/texture/utils.py index b75bebde5..25da3a714 100644 --- a/fury/texture/utils.py +++ b/fury/texture/utils.py @@ -1,4 +1,17 @@ def uv_calculations(n): + """Return UV coordinates based on the number of elements. + + Parameters + ---------- + n : int + number of elements. + + Returns + ------- + uvs : ndrray + UV coordinates for each element. + + """ uvs = [] for i in range(0, n): a = (n - (i + 1)) / n @@ -15,4 +28,4 @@ def uv_calculations(n): [0.999, a + 0.001], ] ) - return uvs \ No newline at end of file + return uvs diff --git a/fury/utils.py b/fury/utils.py index 089108826..2b170a2a2 100644 --- a/fury/utils.py +++ b/fury/utils.py @@ -1625,7 +1625,7 @@ def set_actor_origin(actor, *, center=None): def minmax_norm(data, axis=1): - """Returns the min-max normalization of data + """Returns the min-max normalization of data along an axis. Parameters ---------- @@ -1647,11 +1647,11 @@ def minmax_norm(data, axis=1): elif data.ndim > 2: raise ValueError('the dimension of the array must be 2.') - min = data.min(axis=axis) - max = data.max(axis=axis) - if np.array_equal(min, max): + minimum = data.min(axis=axis) + maximum = data.max(axis=axis) + if np.array_equal(minimum, maximum): return data if (axis == 0): - return (data - min)/(max - min) + return (data - minimum)/(maximum - minimum) if (axis == 1): - return (data - min[:, None])/(max - min)[:, None] + return (data - minimum[:, None])/(maximum - minimum)[:, None] From 2ee1422409df76606676f723ba4f5041247e0450 Mon Sep 17 00:00:00 2001 From: tvcastillod Date: Tue, 16 Apr 2024 09:49:44 -0500 Subject: [PATCH 111/118] reorganized and refactored odf actor --- fury/actor.py | 6 +-- fury/actors/odf.py | 62 +++++++++++++++-------------- fury/shaders/utils/minmax_norm.glsl | 6 +-- 3 files changed, 39 insertions(+), 35 deletions(-) diff --git a/fury/actor.py b/fury/actor.py index 075050f68..681b4e018 100644 --- a/fury/actor.py +++ b/fury/actor.py @@ -4025,7 +4025,7 @@ def odf( centers, coeffs, degree=None, - basis_type='descoteaux', + sh_basis='descoteaux', scales=1.0, opacity=1.0 ): @@ -4044,7 +4044,7 @@ def odf( Index of the highest used band of the spherical harmonics basis. Must be even, at least 2 and at most 12. If None the degree is set based on the number of SH coefficients given. - basis_type: str, optional + sh_basis: str, optional Type of basis (descoteaux, tournier) 'descoteaux' for the default ``descoteaux07`` DYPY basis. 'tournier' for the default ``tournier07` DYPY basis. @@ -4108,4 +4108,4 @@ def odf( total = np.sum(abs(coeffs), axis=1) coeffs = np.dot(np.diag(1 / total * scales), coeffs) * 1.7 - return sh_odf(centers, coeffs, degree, basis_type, scales, opacity) + return sh_odf(centers, coeffs, degree, sh_basis, scales, opacity) diff --git a/fury/actors/odf.py b/fury/actors/odf.py index 5e8fbe4d4..2f2b07f39 100644 --- a/fury/actors/odf.py +++ b/fury/actors/odf.py @@ -18,7 +18,7 @@ from fury.texture.utils import uv_calculations -def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): +def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): """ Visualize one or many ODFs with different features. @@ -28,7 +28,7 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): ODFs positions. coeffs : ndarray 2D ODFs array in SH coefficients. - basis_type: str, optional + sh_basis: str, optional Type of basis (descoteaux, tournier) 'descoteaux' for the default ``descoteaux07`` DYPY basis. 'tournier' for the default ``tournier07` DYPY basis. @@ -56,11 +56,26 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): big_minmax = np.repeat(minmax, 8, axis=0) attribute_to_actor(odf_actor, big_minmax, "minmax") + odf_actor_pd = odf_actor.GetMapper().GetInput() + + n_glyphs = coeffs.shape[0] + # Coordinates to locate the data of each glyph in the texture. + uv_vals = np.array(uv_calculations(n_glyphs)) + num_pnts = uv_vals.shape[0] + + # Definition of texture coordinates to be associated with the actor. + t_coords = FloatArray() + t_coords.SetNumberOfComponents(2) + t_coords.SetNumberOfTuples(num_pnts) + [t_coords.SetTuple(i, uv_vals[i]) for i in range(num_pnts)] + + set_polydata_tcoords(odf_actor_pd, t_coords) + # The coefficient data is stored in a texture to be passed to the shaders. # Data is normalized to a range of 0 to 1. arr = minmax_norm(coeffs) - # Data is turned into values within the RGB color range, and then coverted + # Data is turned into values within the RGB color range, and then converted # into a vtk image data. arr *= 255 grid = numpy_to_vtk_image_data(arr.astype(np.uint8)) @@ -73,21 +88,6 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): # Texture is associated with the actor odf_actor.GetProperty().SetTexture("texture0", texture) - odf_actor_pd = odf_actor.GetMapper().GetInput() - - n_glyphs = coeffs.shape[0] - # Coordinates to locate the data of each glyph in the texture. - uv_vals = np.array(uv_calculations(n_glyphs)) - num_pnts = uv_vals.shape[0] - - # Definition of texture coordinates to be associated with the actor. - t_coords = FloatArray() - t_coords.SetNumberOfComponents(2) - t_coords.SetNumberOfTuples(num_pnts) - [t_coords.SetTuple(i, uv_vals[i]) for i in range(num_pnts)] - - set_polydata_tcoords(odf_actor_pd, t_coords) - # The number of coefficients is associated to the order of the SH odf_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniformf( "numCoeffs", ((degree + 1) * (degree + 2)) / 2 @@ -169,14 +169,19 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): coeffs_norm = import_fury_shader(os.path.join("utils", "minmax_norm.glsl")) - eval_sh_list = '' - for i in range(2, degree+1, 2): + eval_sh_composed = "" + for i in range(2, degree + 1, 2): #PUT sh_degree eval_sh = import_fury_shader( - os.path.join("rt_odfs", basis_type, 'eval_sh_' + str(i) + '.frag')) + os.path.join("rt_odfs", sh_basis, "eval_sh_" + str(i) + ".frag") + ) eval_sh_grad = import_fury_shader( - os.path.join("rt_odfs", basis_type, - 'eval_sh_grad_' + str(i) + '.frag')) - eval_sh_list = eval_sh_list + '\n\n' + eval_sh + '\n\n' + eval_sh_grad + os.path.join( + "rt_odfs", sh_basis, "eval_sh_grad_" + str(i) + ".frag" + ) + ) + eval_sh_composed = compose_shader( + [eval_sh_composed, eval_sh, eval_sh_grad] + ) # Searches a single root of a polynomial within a given interval. # param out_root The location of the found root. @@ -283,7 +288,7 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): fs_dec = compose_shader([ def_sh_degree, def_sh_count, def_max_degree, def_gl_ext_control_flow_attributes, def_no_intersection, def_pis, - fs_vs_vars, coeffs_norm, eval_sh_list, newton_bisection, find_roots, + fs_vs_vars, coeffs_norm, eval_sh_composed, newton_bisection, find_roots, eval_sh, eval_sh_grad, get_inv_vandermonde, ray_sh_glyph_intersections, get_sh_glyph_normal, blinn_phong_model, linear_to_srgb, srgb_to_linear, linear_rgb_to_srgb, srgb_to_linear_rgb, tonemap @@ -311,10 +316,9 @@ def sh_odf(centers, coeffs, degree, basis_type, scales, opacity): float i = 1 / (numCoeffs * 2); float sh_coeffs[SH_COUNT]; for(int j=0; j Date: Mon, 26 Aug 2024 16:47:09 -0500 Subject: [PATCH 112/118] adjusted odf actor and added example --- .../SH-ODF_experimental/example_odf.py | 47 +++++++++ fury/actor.py | 97 +------------------ 2 files changed, 48 insertions(+), 96 deletions(-) create mode 100644 docs/experimental/SH-ODF_experimental/example_odf.py diff --git a/docs/experimental/SH-ODF_experimental/example_odf.py b/docs/experimental/SH-ODF_experimental/example_odf.py new file mode 100644 index 000000000..f4eb8949e --- /dev/null +++ b/docs/experimental/SH-ODF_experimental/example_odf.py @@ -0,0 +1,47 @@ +import os + +import numpy as np +from dipy.data.fetcher import dipy_home +from dipy.io.image import load_nifti + +from fury import actor, window + +if __name__ == "__main__": + show_man = window.ShowManager(size=(1280, 720)) + + dataset_dir = os.path.join(dipy_home, "stanford_hardi") + + coeffs, affine = load_nifti("docs\experimental\SH-ODF_experimental\odf_debug_sh_coeffs_9x11x45(8).nii") + + valid_mask = np.abs(coeffs).max(axis=(-1)) > 0 + indices = np.nonzero(valid_mask) + + centers = np.asarray(indices).T + + x, y, z, s = coeffs.shape + coeffs = coeffs[:, :, :].reshape((x * y * z, s)) + + ''' + coeffs = np.array([ + [ + -0.2739740312099, 0.2526670396328, 1.8922271728516, 0.2878578901291, + -0.5339795947075, -0.2620058953762, 0.1580424904823, 0.0329004973173, + -0.1322413831949, -0.1332057565451, 1.0894461870193, -0.6319401264191, + -0.0416776277125, -1.0772529840469, 0.1423762738705, 0.7941166162491, + 0.7490307092667, -0.3428381681442, 0.1024847552180, -0.0219132602215, + 0.0499043911695, 0.2162453681231, 0.0921059995890, -0.2611238956451, + 0.2549301385880, -0.4534865319729, 0.1922748684883, -0.6200597286224, + -0.0532187558711, -0.3569841980934, 0.0293972902000, -0.1977960765362, + -0.1058669015765, 0.2372217923403, -0.1856198310852, -0.3373193442822, + -0.0750469490886, 0.2146576642990, -0.0490148440003, 0.1288588196039, + 0.3173974752426, 0.1990085393190, -0.1736343950033, -0.0482443645597, + 0.1749017387629 + ] + ]) + centers= np.array([0, 0, 0]) + ''' + + odf_actor = actor.odf(centers=centers, coeffs=coeffs, scales=1.0, + sh_basis='descoteaux', degree=2) + show_man.scene.add(odf_actor) + show_man.start() \ No newline at end of file diff --git a/fury/actor.py b/fury/actor.py index a2db5a149..8f520cd7e 100644 --- a/fury/actor.py +++ b/fury/actor.py @@ -14,6 +14,7 @@ main_dir_uncertainty, tensor_ellipsoid, ) +from fury.actors.odf import sh_odf from fury.colormap import colormap_lookup_table from fury.decorators import warn_on_args_to_kwargs from fury.io import load_image @@ -4108,100 +4109,4 @@ def odf( total = np.sum(abs(coeffs), axis=1) coeffs = np.dot(np.diag(1 / total * scales), coeffs) * 1.7 -<<<<<<< HEAD -======= - total = np.sum(abs(coeffs), axis=1) - coeffs = np.dot(np.diag(1 / total * scales), coeffs) * 1.7 - - return sh_odf(centers, coeffs, degree, sh_basis, scales, opacity) - - -def odf( - centers, - coeffs, - degree=None, - sh_basis='descoteaux', - scales=1.0, - opacity=1.0 -): - """ - FURY actor for visualizing Orientation Distribution Functions (ODFs) given - an array of Spherical Harmonics (SH) coefficients. - - Parameters - ---------- - centers : ndarray(N, 3) - ODFs positions. - coeffs : (N, M) or (N, 6) or (N, 15) or (N, 28) or (N, 45) or (N, 66) or - (N, 91) ndarray. - Corresponding SH coefficients for the ODFs. - degree: int, optional - Index of the highest used band of the spherical harmonics basis. Must - be even, at least 2 and at most 12. If None the degree is set based on - the number of SH coefficients given. - sh_basis: str, optional - Type of basis (descoteaux, tournier) - 'descoteaux' for the default ``descoteaux07`` DYPY basis. - 'tournier' for the default ``tournier07` DYPY basis. - scales : float or ndarray (N, ) - ODFs size. - opacity : float - Takes values from 0 (fully transparent) to 1 (opaque). - - Returns - ------- - odf: Actor - - """ - - if not isinstance(centers, np.ndarray): - centers = np.array(centers) - if centers.ndim == 1: - centers = np.array([centers]) - - if not isinstance(coeffs, np.ndarray): - coeffs = np.array(coeffs) - if coeffs.ndim != 2: - if coeffs.ndim == 1: - coeffs = np.array([coeffs]) - else: - raise ValueError('coeffs should be a 2D array.') - if coeffs.shape[0] != centers.shape[0]: - raise ValueError('number of odf glyphs defined does not match with ' - 'number of centers') - - coeffs_given = coeffs.shape[-1] - max_degree = int((np.sqrt(8 * coeffs_given + 1) - 3) / 2) - if degree is None: - degree = max_degree - else: - if degree % 2 != 0: - warnings.warn('Invalid degree value. Degree must be a positive ' - 'even number lower or equal to 12. Ignoring passed ' - 'value and using maximum degree supported by the ' - 'number of SH coefficients.') - degree = max_degree - else: - coeffs_needed = int(((degree + 1) * (degree + 2)) / 2) - if coeffs_given < coeffs_needed: - warnings.warn('Not enough number of coefficient for SH of ' - 'degree {0}, expected at least {1}. Ignoring ' - 'passed value and using maximum degree supported ' - 'by the number of SH coefficients.' - .format(degree, coeffs_needed)) - degree = max_degree - coeffs = coeffs[:, :int(((degree + 1) * (degree + 2)) / 2)] - - if not isinstance(scales, np.ndarray): - scales = np.array(scales) - if scales.size == 1: - scales = np.repeat(scales, centers.shape[0]) - elif scales.size != centers.shape[0]: - scales = np.concatenate( - (scales, np.ones(centers.shape[0] - scales.shape[0])), axis=None) - - total = np.sum(abs(coeffs), axis=1) - coeffs = np.dot(np.diag(1 / total * scales), coeffs) * 1.7 - ->>>>>>> 5a6d1f656e1bf5d55c473b0ceb8f07fbc0ce5cf3 return sh_odf(centers, coeffs, degree, sh_basis, scales, opacity) From fc30cd9dbdefe8798f570df623c8c93b4cb48411 Mon Sep 17 00:00:00 2001 From: tvcastillod Date: Wed, 28 Aug 2024 13:06:19 -0500 Subject: [PATCH 113/118] adjustments on variables name and handle degree with uniform --- .../SH-ODF_experimental/example_odf.py | 6 +- fury/actor.py | 27 +- fury/actors/odf.py | 54 +- fury/shaders/lighting/linear_rgb_to_srgb.frag | 4 +- fury/shaders/lighting/linear_to_srgb.frag | 2 +- fury/shaders/lighting/srgb_to_linear.frag | 4 +- fury/shaders/lighting/srgb_to_linear_rgb.frag | 4 +- .../rt_odfs/descoteaux/eval_sh_10.frag | 134 ++-- .../rt_odfs/descoteaux/eval_sh_12.frag | 184 ++--- .../shaders/rt_odfs/descoteaux/eval_sh_2.frag | 14 +- .../shaders/rt_odfs/descoteaux/eval_sh_4.frag | 32 +- .../shaders/rt_odfs/descoteaux/eval_sh_6.frag | 58 +- .../shaders/rt_odfs/descoteaux/eval_sh_8.frag | 92 +-- .../rt_odfs/descoteaux/eval_sh_grad_10.frag | 530 ++++++------- .../rt_odfs/descoteaux/eval_sh_grad_12.frag | 730 +++++++++--------- .../rt_odfs/descoteaux/eval_sh_grad_2.frag | 50 +- .../rt_odfs/descoteaux/eval_sh_grad_4.frag | 122 +-- .../rt_odfs/descoteaux/eval_sh_grad_6.frag | 226 +++--- .../rt_odfs/descoteaux/eval_sh_grad_8.frag | 362 ++++----- fury/shaders/rt_odfs/eval_sh.frag | 74 +- fury/shaders/rt_odfs/eval_sh_grad.frag | 72 +- fury/shaders/rt_odfs/get_inv_vandermonde.frag | 147 ++-- fury/shaders/rt_odfs/get_sh_glyph_normal.frag | 16 +- .../shaders/rt_odfs/gltf_dielectric_brdf.frag | 41 - .../rt_odfs/ray_sh_glyph_intersections.frag | 93 +-- fury/shaders/rt_odfs/tournier/eval_sh_10.frag | 134 ++-- fury/shaders/rt_odfs/tournier/eval_sh_12.frag | 184 ++--- fury/shaders/rt_odfs/tournier/eval_sh_2.frag | 14 +- fury/shaders/rt_odfs/tournier/eval_sh_4.frag | 32 +- fury/shaders/rt_odfs/tournier/eval_sh_6.frag | 58 +- fury/shaders/rt_odfs/tournier/eval_sh_8.frag | 92 +-- .../rt_odfs/tournier/eval_sh_grad_10.frag | 530 ++++++------- .../rt_odfs/tournier/eval_sh_grad_12.frag | 730 +++++++++--------- .../rt_odfs/tournier/eval_sh_grad_2.frag | 50 +- .../rt_odfs/tournier/eval_sh_grad_4.frag | 122 +-- .../rt_odfs/tournier/eval_sh_grad_6.frag | 226 +++--- .../rt_odfs/tournier/eval_sh_grad_8.frag | 362 ++++----- fury/shaders/utils/find_roots.frag | 58 +- fury/shaders/utils/newton_bisection.frag | 26 +- 39 files changed, 2889 insertions(+), 2807 deletions(-) delete mode 100644 fury/shaders/rt_odfs/gltf_dielectric_brdf.frag diff --git a/docs/experimental/SH-ODF_experimental/example_odf.py b/docs/experimental/SH-ODF_experimental/example_odf.py index f4eb8949e..ac43687b4 100644 --- a/docs/experimental/SH-ODF_experimental/example_odf.py +++ b/docs/experimental/SH-ODF_experimental/example_odf.py @@ -21,7 +21,7 @@ x, y, z, s = coeffs.shape coeffs = coeffs[:, :, :].reshape((x * y * z, s)) - ''' + #''' coeffs = np.array([ [ -0.2739740312099, 0.2526670396328, 1.8922271728516, 0.2878578901291, @@ -39,9 +39,9 @@ ] ]) centers= np.array([0, 0, 0]) - ''' + #''' odf_actor = actor.odf(centers=centers, coeffs=coeffs, scales=1.0, - sh_basis='descoteaux', degree=2) + sh_basis='descoteaux') show_man.scene.add(odf_actor) show_man.start() \ No newline at end of file diff --git a/fury/actor.py b/fury/actor.py index 8f520cd7e..d8d9f75a9 100644 --- a/fury/actor.py +++ b/fury/actor.py @@ -4025,7 +4025,6 @@ def uncertainty_cone( def odf( centers, coeffs, - degree=None, sh_basis='descoteaux', scales=1.0, opacity=1.0 @@ -4041,10 +4040,6 @@ def odf( coeffs : (N, M) or (N, 6) or (N, 15) or (N, 28) or (N, 45) or (N, 66) or (N, 91) ndarray. Corresponding SH coefficients for the ODFs. - degree: int, optional - Index of the highest used band of the spherical harmonics basis. Must - be even, at least 2 and at most 12. If None the degree is set based on - the number of SH coefficients given. sh_basis: str, optional Type of basis (descoteaux, tournier) 'descoteaux' for the default ``descoteaux07`` DYPY basis. @@ -4077,27 +4072,9 @@ def odf( 'number of centers') coeffs_given = coeffs.shape[-1] - max_degree = int((np.sqrt(8 * coeffs_given + 1) - 3) / 2) - if degree is None: - degree = max_degree - else: - if degree % 2 != 0: - warnings.warn('Invalid degree value. Degree must be a positive ' - 'even number lower or equal to 12. Ignoring passed ' - 'value and using maximum degree supported by the ' - 'number of SH coefficients.') - degree = max_degree - else: - coeffs_needed = int(((degree + 1) * (degree + 2)) / 2) - if coeffs_given < coeffs_needed: - warnings.warn('Not enough number of coefficient for SH of ' - 'degree {0}, expected at least {1}. Ignoring ' - 'passed value and using maximum degree supported ' - 'by the number of SH coefficients.' - .format(degree, coeffs_needed)) - degree = max_degree + degree = int((np.sqrt(8 * coeffs_given + 1) - 3) / 2) + if (degree%2 != 0): degree -= 1 coeffs = coeffs[:, :int(((degree + 1) * (degree + 2)) / 2)] - if not isinstance(scales, np.ndarray): scales = np.array(scales) if scales.size == 1: diff --git a/fury/actors/odf.py b/fury/actors/odf.py index 2f2b07f39..58b659507 100644 --- a/fury/actors/odf.py +++ b/fury/actors/odf.py @@ -88,18 +88,27 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): # Texture is associated with the actor odf_actor.GetProperty().SetTexture("texture0", texture) + max_num_coeffs = coeffs.shape[-1] + max_sh_degree = int((np.sqrt(8 * max_num_coeffs + 1) - 3) / 2) + max_poly_degree = 2 * max_sh_degree + 2 + viz_sh_degree = max_sh_degree + # The number of coefficients is associated to the order of the SH odf_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniformf( - "numCoeffs", ((degree + 1) * (degree + 2)) / 2 + "shDegree", viz_sh_degree ) # Start of shader implementation vs_dec = \ """ + uniform float shDegree; + in vec3 center; in vec2 minmax; + flat out float numCoeffsVSOutput; + flat out float maxPolyDegreeVSOutput; out vec4 vertexMCVSOutput; out vec3 centerMCVSOutput; out vec2 minmaxVSOutput; @@ -110,6 +119,8 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): vs_impl = \ """ + numCoeffsVSOutput = (shDegree + 1) * (shDegree + 2) / 2; + maxPolyDegreeVSOutput = 2 * shDegree + 2; vertexMCVSOutput = vertexMC; centerMCVSOutput = center; minmaxVSOutput = minmax; @@ -124,13 +135,13 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): # The index of the highest used band of the spherical harmonics basis. Must # be even, at least 2 and at most 12. - def_sh_degree = "#define SH_DEGREE " + str(degree) + def_sh_degree = f"#define SH_DEGREE {max_sh_degree}" # The number of spherical harmonics basis functions - def_sh_count = "#define SH_COUNT (((SH_DEGREE + 1) * (SH_DEGREE + 2)) / 2)" + def_sh_count = f"#define SH_COUNT {max_num_coeffs}" # Degree of polynomials for which we have to find roots - def_max_degree = "#define MAX_DEGREE (2 * SH_DEGREE + 2)" + def_max_degree = f"#define MAX_DEGREE {max_poly_degree}" # If GL_EXT_control_flow_attributes is available, these defines should be # defined as [[unroll]] and [[loop]] to give reasonable hints to the @@ -159,6 +170,8 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): fs_vs_vars = \ """ + flat in float numCoeffsVSOutput; + flat in float maxPolyDegreeVSOutput; in vec4 vertexMCVSOutput; in vec3 centerMCVSOutput; in vec2 minmaxVSOutput; @@ -170,7 +183,7 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): coeffs_norm = import_fury_shader(os.path.join("utils", "minmax_norm.glsl")) eval_sh_composed = "" - for i in range(2, degree + 1, 2): #PUT sh_degree + for i in range(2, max_sh_degree + 1, 2): eval_sh = import_fury_shader( os.path.join("rt_odfs", sh_basis, "eval_sh_" + str(i) + ".frag") ) @@ -213,7 +226,7 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): # M. Descoteaux, E. Angelino, S. Fitzgibbons, and R. Deriche. Regularized, # fast, and robust analytical q-ball imaging. Magnetic Resonance in # Medicine, 58(3), 2007. https://doi.org/10.1002/mrm.21277 - # param out_shs Values of SH basis functions in bands 0, 2, ..., + # param outSH Values of SH basis functions in bands 0, 2, ..., # SH_DEGREE in this order. # param point The point on the unit sphere where the basis should be # evaluated. @@ -313,12 +326,15 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): # Define SH coefficients (measured up to band 8, noise beyond that) sh_coeffs = \ """ - float i = 1 / (numCoeffs * 2); + float i = 1 / (numCoeffsVSOutput * 2); float sh_coeffs[SH_COUNT]; - for(int j=0; j 0.0) { first_ray_param = ray_params[i]; break; @@ -349,9 +369,9 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): vec3 color = vec3(1.); if (first_ray_param != NO_INTERSECTION) { vec3 intersection = ro - centerMCVSOutput + first_ray_param * rd; - vec3 normal = get_sh_glyph_normal(sh_coeffs, intersection); - vec3 colorDir = srgb_to_linear_rgb(abs(normalize(intersection))); - float attenuation = dot(ld, normal); + vec3 normal = getShGlyphNormal(sh_coeffs, intersection, int(shDegree), int(numCoeffsVSOutput)); + vec3 colorDir = srgbToLinearRgb(abs(normalize(intersection))); + float attenuation = ld.z;//dot(ld, normal); color = blinnPhongIllumModel( attenuation, lightColor0, colorDir, specularPower, specularColor, ambientColor); @@ -362,7 +382,7 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): frag_output = \ """ - vec3 out_color = linear_rgb_to_srgb(tonemap(color)); + vec3 out_color = linearRgbToSrgb(tonemap(color)); fragOutput0 = vec4(out_color, opacity); """ diff --git a/fury/shaders/lighting/linear_rgb_to_srgb.frag b/fury/shaders/lighting/linear_rgb_to_srgb.frag index d1c72c83b..901aad0d2 100644 --- a/fury/shaders/lighting/linear_rgb_to_srgb.frag +++ b/fury/shaders/lighting/linear_rgb_to_srgb.frag @@ -1,4 +1,4 @@ -vec3 linear_rgb_to_srgb(vec3 linear) +vec3 linearRgbToSrgb(vec3 linear) { - return vec3(linear_to_srgb(linear.r), linear_to_srgb(linear.g), linear_to_srgb(linear.b)); + return vec3(linearToSrgb(linear.r), linearToSrgb(linear.g), linearToSrgb(linear.b)); } diff --git a/fury/shaders/lighting/linear_to_srgb.frag b/fury/shaders/lighting/linear_to_srgb.frag index ac686853c..7a3773c01 100644 --- a/fury/shaders/lighting/linear_to_srgb.frag +++ b/fury/shaders/lighting/linear_to_srgb.frag @@ -1,4 +1,4 @@ -float linear_to_srgb(float linear) +float linearToSrgb(float linear) { return (linear <= 0.0031308) ? (12.92 * linear) : (1.055 * pow(linear, 1.0 / 2.4) - 0.055); } diff --git a/fury/shaders/lighting/srgb_to_linear.frag b/fury/shaders/lighting/srgb_to_linear.frag index 78c765c20..5240d4b9d 100644 --- a/fury/shaders/lighting/srgb_to_linear.frag +++ b/fury/shaders/lighting/srgb_to_linear.frag @@ -1,4 +1,4 @@ -float srgb_to_linear(float non_linear) +float srgbToLinear(float nonLinear) { - return (non_linear <= 0.04045) ? ((1.0 / 12.92) * non_linear) : pow(non_linear * (1.0 / 1.055) + 0.055 / 1.055, 2.4); + return (nonLinear <= 0.04045) ? ((1.0 / 12.92) * nonLinear) : pow(nonLinear * (1.0 / 1.055) + 0.055 / 1.055, 2.4); } diff --git a/fury/shaders/lighting/srgb_to_linear_rgb.frag b/fury/shaders/lighting/srgb_to_linear_rgb.frag index e4c2ef22a..0c47f780b 100644 --- a/fury/shaders/lighting/srgb_to_linear_rgb.frag +++ b/fury/shaders/lighting/srgb_to_linear_rgb.frag @@ -1,4 +1,4 @@ -vec3 srgb_to_linear_rgb(vec3 srgb) +vec3 srgbToLinearRgb(vec3 srgb) { - return vec3(srgb_to_linear(srgb.r), srgb_to_linear(srgb.g), srgb_to_linear(srgb.b)); + return vec3(srgbToLinear(srgb.r), srgbToLinear(srgb.g), srgbToLinear(srgb.b)); } diff --git a/fury/shaders/rt_odfs/descoteaux/eval_sh_10.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_10.frag index 178033cae..f12ad5881 100644 --- a/fury/shaders/rt_odfs/descoteaux/eval_sh_10.frag +++ b/fury/shaders/rt_odfs/descoteaux/eval_sh_10.frag @@ -1,4 +1,4 @@ -void eval_sh_10(out float out_shs[66], vec3 point) +void evalSH10(out float outSH[66], vec3 point) { float x, y, z, z2, c0, s0, c1, s1, d, a, b; x = point[0]; @@ -6,170 +6,170 @@ void eval_sh_10(out float out_shs[66], vec3 point) z = point[2]; z2 = z * z; d = 0.282094792; - out_shs[0] = d; + outSH[0] = d; a = z2 - 0.333333333; d = 0.946174696 * a; - out_shs[3] = d; + outSH[3] = d; b = z2 * (a - 0.266666667); a = b - 0.257142857 * a; d = 3.702494142 * a; - out_shs[10] = d; + outSH[10] = d; b = z2 * a - 0.253968254 * b; a = b - 0.252525253 * a; d = 14.684485724 * a; - out_shs[21] = d; + outSH[21] = d; b = z2 * a - 0.251748252 * b; a = b - 0.251282051 * a; d = 58.473368113 * a; - out_shs[36] = d; + outSH[36] = d; b = z2 * a - 0.250980392 * b; a = b - 0.250773994 * a; d = 233.240148813 * a; - out_shs[55] = d; + outSH[55] = d; c1 = x; s1 = y; d = -1.092548431 * z; - out_shs[2] = -c1 * d; - out_shs[4] = s1 * d; + outSH[2] = -c1 * d; + outSH[4] = s1 * d; a = (z2 - 0.2) * z; b = a - 0.228571429 * z; d = -4.683325805 * b; - out_shs[9] = -c1 * d; - out_shs[11] = s1 * d; + outSH[9] = -c1 * d; + outSH[11] = s1 * d; a = z2 * b - 0.238095238 * a; b = a - 0.242424242 * b; d = -19.226504963 * b; - out_shs[20] = -c1 * d; - out_shs[22] = s1 * d; + outSH[20] = -c1 * d; + outSH[22] = s1 * d; a = z2 * b - 0.244755245 * a; b = a - 0.246153846 * b; d = -77.964490818 * b; - out_shs[35] = -c1 * d; - out_shs[37] = s1 * d; + outSH[35] = -c1 * d; + outSH[37] = s1 * d; a = z2 * b - 0.247058824 * a; b = a - 0.247678019 * b; d = -314.500952502 * b; - out_shs[54] = -c1 * d; - out_shs[56] = s1 * d; + outSH[54] = -c1 * d; + outSH[56] = s1 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.546274215; - out_shs[1] = c0 * d; - out_shs[5] = s0 * d; + outSH[1] = c0 * d; + outSH[5] = s0 * d; a = z2 - 0.142857143; d = 3.311611435 * a; - out_shs[8] = c0 * d; - out_shs[12] = s0 * d; + outSH[8] = c0 * d; + outSH[12] = s0 * d; b = z2 * (a - 0.19047619); a = b - 0.212121212 * a; d = 15.199886782 * a; - out_shs[19] = c0 * d; - out_shs[23] = s0 * d; + outSH[19] = c0 * d; + outSH[23] = s0 * d; b = z2 * a - 0.223776224 * b; a = b - 0.230769231 * a; d = 65.229772956 * a; - out_shs[34] = c0 * d; - out_shs[38] = s0 * d; + outSH[34] = c0 * d; + outSH[38] = s0 * d; b = z2 * a - 0.235294118 * b; a = b - 0.238390093 * a; d = 272.365814381 * a; - out_shs[53] = c0 * d; - out_shs[57] = s0 * d; + outSH[53] = c0 * d; + outSH[57] = s0 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -1.77013077 * z; - out_shs[7] = -c1 * d; - out_shs[13] = s1 * d; + outSH[7] = -c1 * d; + outSH[13] = s1 * d; a = (z2 - 0.111111111) * z; b = a - 0.161616162 * z; d = -10.133257855 * b; - out_shs[18] = -c1 * d; - out_shs[24] = s1 * d; + outSH[18] = -c1 * d; + outSH[24] = s1 * d; a = z2 * b - 0.188811189 * a; b = a - 0.205128205 * b; d = -48.175380057 * b; - out_shs[33] = -c1 * d; - out_shs[39] = s1 * d; + outSH[33] = -c1 * d; + outSH[39] = s1 * d; a = z2 * b - 0.215686275 * a; b = a - 0.222910217 * b; d = -213.661323441 * b; - out_shs[52] = -c1 * d; - out_shs[58] = s1 * d; + outSH[52] = -c1 * d; + outSH[58] = s1 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.625835735; - out_shs[6] = c0 * d; - out_shs[14] = s0 * d; + outSH[6] = c0 * d; + outSH[14] = s0 * d; a = z2 - 9.09090909e-02; d = 5.550213908 * a; - out_shs[17] = c0 * d; - out_shs[25] = s0 * d; + outSH[17] = c0 * d; + outSH[25] = s0 * d; b = z2 * (a - 0.13986014); a = b - 0.169230769 * a; d = 31.097074109 * a; - out_shs[32] = c0 * d; - out_shs[40] = s0 * d; + outSH[32] = c0 * d; + outSH[40] = s0 * d; b = z2 * a - 0.188235294 * b; a = b - 0.20123839 * a; d = 151.081370682 * a; - out_shs[51] = c0 * d; - out_shs[59] = s0 * d; + outSH[51] = c0 * d; + outSH[59] = s0 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -2.366619162 * z; - out_shs[16] = -c1 * d; - out_shs[26] = s1 * d; + outSH[16] = -c1 * d; + outSH[26] = s1 * d; a = (z2 - 7.69230769e-02) * z; b = a - 0.123076923 * z; d = -17.24955311 * b; - out_shs[31] = -c1 * d; - out_shs[41] = s1 * d; + outSH[31] = -c1 * d; + outSH[41] = s1 * d; a = z2 * b - 0.152941176 * a; b = a - 0.173374613 * b; d = -95.552248675 * b; - out_shs[50] = -c1 * d; - out_shs[60] = s1 * d; + outSH[50] = -c1 * d; + outSH[60] = s1 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.683184105; - out_shs[15] = c0 * d; - out_shs[27] = s0 * d; + outSH[15] = c0 * d; + outSH[27] = s0 * d; a = z2 - 6.66666667e-02; d = 7.984991491 * a; - out_shs[30] = c0 * d; - out_shs[42] = s0 * d; + outSH[30] = c0 * d; + outSH[42] = s0 * d; b = z2 * (a - 0.109803922); a = b - 0.139318885 * a; d = 53.41533086 * a; - out_shs[49] = c0 * d; - out_shs[61] = s0 * d; + outSH[49] = c0 * d; + outSH[61] = s0 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -2.915706641 * z; - out_shs[29] = -c1 * d; - out_shs[43] = s1 * d; + outSH[29] = -c1 * d; + outSH[43] = s1 * d; a = (z2 - 5.88235294e-02) * z; b = a - 9.90712074e-02 * z; d = -25.910241313 * b; - out_shs[48] = -c1 * d; - out_shs[62] = s1 * d; + outSH[48] = -c1 * d; + outSH[62] = s1 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.72892666; - out_shs[28] = c0 * d; - out_shs[44] = s0 * d; + outSH[28] = c0 * d; + outSH[44] = s0 * d; a = z2 - 5.26315789e-02; d = 10.577811722 * a; - out_shs[47] = c0 * d; - out_shs[63] = s0 * d; + outSH[47] = c0 * d; + outSH[63] = s0 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -3.4318953 * z; - out_shs[46] = -c1 * d; - out_shs[64] = s1 * d; + outSH[46] = -c1 * d; + outSH[64] = s1 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.767395118; - out_shs[45] = c0 * d; - out_shs[65] = s0 * d; + outSH[45] = c0 * d; + outSH[65] = s0 * d; } diff --git a/fury/shaders/rt_odfs/descoteaux/eval_sh_12.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_12.frag index f1a6d85e9..93a0da982 100644 --- a/fury/shaders/rt_odfs/descoteaux/eval_sh_12.frag +++ b/fury/shaders/rt_odfs/descoteaux/eval_sh_12.frag @@ -1,4 +1,4 @@ -void eval_sh_12(out float out_shs[91], vec3 point) +void evalSH12(out float outSH[91], vec3 point) { float x, y, z, z2, c0, s0, c1, s1, d, a, b; x = point[0]; @@ -6,233 +6,233 @@ void eval_sh_12(out float out_shs[91], vec3 point) z = point[2]; z2 = z * z; d = 0.282094792; - out_shs[0] = d; + outSH[0] = d; a = z2 - 0.333333333; d = 0.946174696 * a; - out_shs[3] = d; + outSH[3] = d; b = z2 * (a - 0.266666667); a = b - 0.257142857 * a; d = 3.702494142 * a; - out_shs[10] = d; + outSH[10] = d; b = z2 * a - 0.253968254 * b; a = b - 0.252525253 * a; d = 14.684485724 * a; - out_shs[21] = d; + outSH[21] = d; b = z2 * a - 0.251748252 * b; a = b - 0.251282051 * a; d = 58.473368113 * a; - out_shs[36] = d; + outSH[36] = d; b = z2 * a - 0.250980392 * b; a = b - 0.250773994 * a; d = 233.240148813 * a; - out_shs[55] = d; + outSH[55] = d; b = z2 * a - 0.250626566 * b; a = b - 0.250517598 * a; d = 931.186918633 * a; - out_shs[78] = d; + outSH[78] = d; c1 = x; s1 = y; d = -1.092548431 * z; - out_shs[2] = -c1 * d; - out_shs[4] = s1 * d; + outSH[2] = -c1 * d; + outSH[4] = s1 * d; a = (z2 - 0.2) * z; b = a - 0.228571429 * z; d = -4.683325805 * b; - out_shs[9] = -c1 * d; - out_shs[11] = s1 * d; + outSH[9] = -c1 * d; + outSH[11] = s1 * d; a = z2 * b - 0.238095238 * a; b = a - 0.242424242 * b; d = -19.226504963 * b; - out_shs[20] = -c1 * d; - out_shs[22] = s1 * d; + outSH[20] = -c1 * d; + outSH[22] = s1 * d; a = z2 * b - 0.244755245 * a; b = a - 0.246153846 * b; d = -77.964490818 * b; - out_shs[35] = -c1 * d; - out_shs[37] = s1 * d; + outSH[35] = -c1 * d; + outSH[37] = s1 * d; a = z2 * b - 0.247058824 * a; b = a - 0.247678019 * b; d = -314.500952502 * b; - out_shs[54] = -c1 * d; - out_shs[56] = s1 * d; + outSH[54] = -c1 * d; + outSH[56] = s1 * d; a = z2 * b - 0.248120301 * a; b = a - 0.248447205 * b; d = -1265.233874957 * b; - out_shs[77] = -c1 * d; - out_shs[79] = s1 * d; + outSH[77] = -c1 * d; + outSH[79] = s1 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.546274215; - out_shs[1] = c0 * d; - out_shs[5] = s0 * d; + outSH[1] = c0 * d; + outSH[5] = s0 * d; a = z2 - 0.142857143; d = 3.311611435 * a; - out_shs[8] = c0 * d; - out_shs[12] = s0 * d; + outSH[8] = c0 * d; + outSH[12] = s0 * d; b = z2 * (a - 0.19047619); a = b - 0.212121212 * a; d = 15.199886782 * a; - out_shs[19] = c0 * d; - out_shs[23] = s0 * d; + outSH[19] = c0 * d; + outSH[23] = s0 * d; b = z2 * a - 0.223776224 * b; a = b - 0.230769231 * a; d = 65.229772956 * a; - out_shs[34] = c0 * d; - out_shs[38] = s0 * d; + outSH[34] = c0 * d; + outSH[38] = s0 * d; b = z2 * a - 0.235294118 * b; a = b - 0.238390093 * a; d = 272.365814381 * a; - out_shs[53] = c0 * d; - out_shs[57] = s0 * d; + outSH[53] = c0 * d; + outSH[57] = s0 * d; b = z2 * a - 0.240601504 * b; a = b - 0.242236025 * a; d = 1121.509962433 * a; - out_shs[76] = c0 * d; - out_shs[80] = s0 * d; + outSH[76] = c0 * d; + outSH[80] = s0 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -1.77013077 * z; - out_shs[7] = -c1 * d; - out_shs[13] = s1 * d; + outSH[7] = -c1 * d; + outSH[13] = s1 * d; a = (z2 - 0.111111111) * z; b = a - 0.161616162 * z; d = -10.133257855 * b; - out_shs[18] = -c1 * d; - out_shs[24] = s1 * d; + outSH[18] = -c1 * d; + outSH[24] = s1 * d; a = z2 * b - 0.188811189 * a; b = a - 0.205128205 * b; d = -48.175380057 * b; - out_shs[33] = -c1 * d; - out_shs[39] = s1 * d; + outSH[33] = -c1 * d; + outSH[39] = s1 * d; a = z2 * b - 0.215686275 * a; b = a - 0.222910217 * b; d = -213.661323441 * b; - out_shs[52] = -c1 * d; - out_shs[58] = s1 * d; + outSH[52] = -c1 * d; + outSH[58] = s1 * d; a = z2 * b - 0.228070175 * a; b = a - 0.231884058 * b; d = -915.709049803 * b; - out_shs[75] = -c1 * d; - out_shs[81] = s1 * d; + outSH[75] = -c1 * d; + outSH[81] = s1 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.625835735; - out_shs[6] = c0 * d; - out_shs[14] = s0 * d; + outSH[6] = c0 * d; + outSH[14] = s0 * d; a = z2 - 9.09090909e-02; d = 5.550213908 * a; - out_shs[17] = c0 * d; - out_shs[25] = s0 * d; + outSH[17] = c0 * d; + outSH[25] = s0 * d; b = z2 * (a - 0.13986014); a = b - 0.169230769 * a; d = 31.097074109 * a; - out_shs[32] = c0 * d; - out_shs[40] = s0 * d; + outSH[32] = c0 * d; + outSH[40] = s0 * d; b = z2 * a - 0.188235294 * b; a = b - 0.20123839 * a; d = 151.081370682 * a; - out_shs[51] = c0 * d; - out_shs[59] = s0 * d; + outSH[51] = c0 * d; + outSH[59] = s0 * d; b = z2 * a - 0.210526316 * b; a = b - 0.217391304 * a; d = 686.781787352 * a; - out_shs[74] = c0 * d; - out_shs[82] = s0 * d; + outSH[74] = c0 * d; + outSH[82] = s0 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -2.366619162 * z; - out_shs[16] = -c1 * d; - out_shs[26] = s1 * d; + outSH[16] = -c1 * d; + outSH[26] = s1 * d; a = (z2 - 7.69230769e-02) * z; b = a - 0.123076923 * z; d = -17.24955311 * b; - out_shs[31] = -c1 * d; - out_shs[41] = s1 * d; + outSH[31] = -c1 * d; + outSH[41] = s1 * d; a = z2 * b - 0.152941176 * a; b = a - 0.173374613 * b; d = -95.552248675 * b; - out_shs[50] = -c1 * d; - out_shs[60] = s1 * d; + outSH[50] = -c1 * d; + outSH[60] = s1 * d; a = z2 * b - 0.187969925 * a; b = a - 0.198757764 * b; d = -471.12841933 * b; - out_shs[73] = -c1 * d; - out_shs[83] = s1 * d; + outSH[73] = -c1 * d; + outSH[83] = s1 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.683184105; - out_shs[15] = c0 * d; - out_shs[27] = s0 * d; + outSH[15] = c0 * d; + outSH[27] = s0 * d; a = z2 - 6.66666667e-02; d = 7.984991491 * a; - out_shs[30] = c0 * d; - out_shs[42] = s0 * d; + outSH[30] = c0 * d; + outSH[42] = s0 * d; b = z2 * (a - 0.109803922); a = b - 0.139318885 * a; d = 53.41533086 * a; - out_shs[49] = c0 * d; - out_shs[61] = s0 * d; + outSH[49] = c0 * d; + outSH[61] = s0 * d; b = z2 * a - 0.160401003 * b; a = b - 0.175983437 * a; d = 293.800188384 * a; - out_shs[72] = c0 * d; - out_shs[84] = s0 * d; + outSH[72] = c0 * d; + outSH[84] = s0 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -2.915706641 * z; - out_shs[29] = -c1 * d; - out_shs[43] = s1 * d; + outSH[29] = -c1 * d; + outSH[43] = s1 * d; a = (z2 - 5.88235294e-02) * z; b = a - 9.90712074e-02 * z; d = -25.910241313 * b; - out_shs[48] = -c1 * d; - out_shs[62] = s1 * d; + outSH[48] = -c1 * d; + outSH[62] = s1 * d; a = z2 * b - 0.127819549 * a; b = a - 0.149068323 * b; d = -165.101452729 * b; - out_shs[71] = -c1 * d; - out_shs[85] = s1 * d; + outSH[71] = -c1 * d; + outSH[85] = s1 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.72892666; - out_shs[28] = c0 * d; - out_shs[44] = s0 * d; + outSH[28] = c0 * d; + outSH[44] = s0 * d; a = z2 - 5.26315789e-02; d = 10.577811722 * a; - out_shs[47] = c0 * d; - out_shs[63] = s0 * d; + outSH[47] = c0 * d; + outSH[63] = s0 * d; b = z2 * (a - 9.02255639e-02); a = b - 0.118012422 * a; d = 82.550726364 * a; - out_shs[70] = c0 * d; - out_shs[86] = s0 * d; + outSH[70] = c0 * d; + outSH[86] = s0 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -3.4318953 * z; - out_shs[46] = -c1 * d; - out_shs[64] = s1 * d; + outSH[46] = -c1 * d; + outSH[64] = s1 * d; a = (z2 - 4.76190476e-02) * z; b = a - 8.2815735e-02 * z; d = -36.028090689 * b; - out_shs[69] = -c1 * d; - out_shs[87] = s1 * d; + outSH[69] = -c1 * d; + outSH[87] = s1 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.767395118; - out_shs[45] = c0 * d; - out_shs[65] = s0 * d; + outSH[45] = c0 * d; + outSH[65] = s0 * d; a = z2 - 4.34782609e-02; d = 13.3042542 * a; - out_shs[68] = c0 * d; - out_shs[88] = s0 * d; + outSH[68] = c0 * d; + outSH[88] = s0 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -3.923210529 * z; - out_shs[67] = -c1 * d; - out_shs[89] = s1 * d; + outSH[67] = -c1 * d; + outSH[89] = s1 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.800821996; - out_shs[66] = c0 * d; - out_shs[90] = s0 * d; + outSH[66] = c0 * d; + outSH[90] = s0 * d; } diff --git a/fury/shaders/rt_odfs/descoteaux/eval_sh_2.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_2.frag index c15510b74..77c9b62bb 100644 --- a/fury/shaders/rt_odfs/descoteaux/eval_sh_2.frag +++ b/fury/shaders/rt_odfs/descoteaux/eval_sh_2.frag @@ -1,4 +1,4 @@ -void eval_sh_2(out float out_shs[6], vec3 point) +void evalSH2(out float outSH[6], vec3 point) { float x, y, z, z2, c0, s0, c1, s1, d, a; x = point[0]; @@ -6,18 +6,18 @@ void eval_sh_2(out float out_shs[6], vec3 point) z = point[2]; z2 = z * z; d = 0.282094792; - out_shs[0] = d; + outSH[0] = d; a = z2 - 0.333333333; d = 0.946174696 * a; - out_shs[3] = d; + outSH[3] = d; c1 = x; s1 = y; d = -1.092548431 * z; - out_shs[2] = -c1 * d; - out_shs[4] = s1 * d; + outSH[2] = -c1 * d; + outSH[4] = s1 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.546274215; - out_shs[1] = c0 * d; - out_shs[5] = s0 * d; + outSH[1] = c0 * d; + outSH[5] = s0 * d; } diff --git a/fury/shaders/rt_odfs/descoteaux/eval_sh_4.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_4.frag index 975fac054..2c1b927c3 100644 --- a/fury/shaders/rt_odfs/descoteaux/eval_sh_4.frag +++ b/fury/shaders/rt_odfs/descoteaux/eval_sh_4.frag @@ -1,4 +1,4 @@ -void eval_sh_4(out float out_shs[15], vec3 point) +void evalSH4(out float outSH[15], vec3 point) { float x, y, z, z2, c0, s0, c1, s1, d, a, b; x = point[0]; @@ -6,41 +6,41 @@ void eval_sh_4(out float out_shs[15], vec3 point) z = point[2]; z2 = z * z; d = 0.282094792; - out_shs[0] = d; + outSH[0] = d; a = z2 - 0.333333333; d = 0.946174696 * a; - out_shs[3] = d; + outSH[3] = d; b = z2 * (a - 0.266666667); a = b - 0.257142857 * a; d = 3.702494142 * a; - out_shs[10] = d; + outSH[10] = d; c1 = x; s1 = y; d = -1.092548431 * z; - out_shs[2] = -c1 * d; - out_shs[4] = s1 * d; + outSH[2] = -c1 * d; + outSH[4] = s1 * d; a = (z2 - 0.2) * z; b = a - 0.228571429 * z; d = -4.683325805 * b; - out_shs[9] = -c1 * d; - out_shs[11] = s1 * d; + outSH[9] = -c1 * d; + outSH[11] = s1 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.546274215; - out_shs[1] = c0 * d; - out_shs[5] = s0 * d; + outSH[1] = c0 * d; + outSH[5] = s0 * d; a = z2 - 0.142857143; d = 3.311611435 * a; - out_shs[8] = c0 * d; - out_shs[12] = s0 * d; + outSH[8] = c0 * d; + outSH[12] = s0 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -1.77013077 * z; - out_shs[7] = -c1 * d; - out_shs[13] = s1 * d; + outSH[7] = -c1 * d; + outSH[13] = s1 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.625835735; - out_shs[6] = c0 * d; - out_shs[14] = s0 * d; + outSH[6] = c0 * d; + outSH[14] = s0 * d; } diff --git a/fury/shaders/rt_odfs/descoteaux/eval_sh_6.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_6.frag index 6cbd1bcf1..e080626a2 100644 --- a/fury/shaders/rt_odfs/descoteaux/eval_sh_6.frag +++ b/fury/shaders/rt_odfs/descoteaux/eval_sh_6.frag @@ -1,4 +1,4 @@ -void eval_sh_6(out float out_shs[28], vec3 point) +void evalSH6(out float outSH[28], vec3 point) { float x, y, z, z2, c0, s0, c1, s1, d, a, b; x = point[0]; @@ -6,74 +6,74 @@ void eval_sh_6(out float out_shs[28], vec3 point) z = point[2]; z2 = z * z; d = 0.282094792; - out_shs[0] = d; + outSH[0] = d; a = z2 - 0.333333333; d = 0.946174696 * a; - out_shs[3] = d; + outSH[3] = d; b = z2 * (a - 0.266666667); a = b - 0.257142857 * a; d = 3.702494142 * a; - out_shs[10] = d; + outSH[10] = d; b = z2 * a - 0.253968254 * b; a = b - 0.252525253 * a; d = 14.684485724 * a; - out_shs[21] = d; + outSH[21] = d; c1 = x; s1 = y; d = -1.092548431 * z; - out_shs[2] = -c1 * d; - out_shs[4] = s1 * d; + outSH[2] = -c1 * d; + outSH[4] = s1 * d; a = (z2 - 0.2) * z; b = a - 0.228571429 * z; d = -4.683325805 * b; - out_shs[9] = -c1 * d; - out_shs[11] = s1 * d; + outSH[9] = -c1 * d; + outSH[11] = s1 * d; a = z2 * b - 0.238095238 * a; b = a - 0.242424242 * b; d = -19.226504963 * b; - out_shs[20] = -c1 * d; - out_shs[22] = s1 * d; + outSH[20] = -c1 * d; + outSH[22] = s1 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.546274215; - out_shs[1] = c0 * d; - out_shs[5] = s0 * d; + outSH[1] = c0 * d; + outSH[5] = s0 * d; a = z2 - 0.142857143; d = 3.311611435 * a; - out_shs[8] = c0 * d; - out_shs[12] = s0 * d; + outSH[8] = c0 * d; + outSH[12] = s0 * d; b = z2 * (a - 0.19047619); a = b - 0.212121212 * a; d = 15.199886782 * a; - out_shs[19] = c0 * d; - out_shs[23] = s0 * d; + outSH[19] = c0 * d; + outSH[23] = s0 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -1.77013077 * z; - out_shs[7] = -c1 * d; - out_shs[13] = s1 * d; + outSH[7] = -c1 * d; + outSH[13] = s1 * d; a = (z2 - 0.111111111) * z; b = a - 0.161616162 * z; d = -10.133257855 * b; - out_shs[18] = -c1 * d; - out_shs[24] = s1 * d; + outSH[18] = -c1 * d; + outSH[24] = s1 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.625835735; - out_shs[6] = c0 * d; - out_shs[14] = s0 * d; + outSH[6] = c0 * d; + outSH[14] = s0 * d; a = z2 - 9.09090909e-02; d = 5.550213908 * a; - out_shs[17] = c0 * d; - out_shs[25] = s0 * d; + outSH[17] = c0 * d; + outSH[25] = s0 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -2.366619162 * z; - out_shs[16] = -c1 * d; - out_shs[26] = s1 * d; + outSH[16] = -c1 * d; + outSH[26] = s1 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.683184105; - out_shs[15] = c0 * d; - out_shs[27] = s0 * d; + outSH[15] = c0 * d; + outSH[27] = s0 * d; } diff --git a/fury/shaders/rt_odfs/descoteaux/eval_sh_8.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_8.frag index 6e79b2b16..a88190d35 100644 --- a/fury/shaders/rt_odfs/descoteaux/eval_sh_8.frag +++ b/fury/shaders/rt_odfs/descoteaux/eval_sh_8.frag @@ -1,4 +1,4 @@ -void eval_sh_8(out float out_shs[45], vec3 point) +void evalSH8(out float outSH[45], vec3 point) { float x, y, z, z2, c0, s0, c1, s1, d, a, b; x = point[0]; @@ -6,117 +6,117 @@ void eval_sh_8(out float out_shs[45], vec3 point) z = point[2]; z2 = z * z; d = 0.282094792; - out_shs[0] = d; + outSH[0] = d; a = z2 - 0.333333333; d = 0.946174696 * a; - out_shs[3] = d; + outSH[3] = d; b = z2 * (a - 0.266666667); a = b - 0.257142857 * a; d = 3.702494142 * a; - out_shs[10] = d; + outSH[10] = d; b = z2 * a - 0.253968254 * b; a = b - 0.252525253 * a; d = 14.684485724 * a; - out_shs[21] = d; + outSH[21] = d; b = z2 * a - 0.251748252 * b; a = b - 0.251282051 * a; d = 58.473368113 * a; - out_shs[36] = d; + outSH[36] = d; c1 = x; s1 = y; d = -1.092548431 * z; - out_shs[2] = -c1 * d; - out_shs[4] = s1 * d; + outSH[2] = -c1 * d; + outSH[4] = s1 * d; a = (z2 - 0.2) * z; b = a - 0.228571429 * z; d = -4.683325805 * b; - out_shs[9] = -c1 * d; - out_shs[11] = s1 * d; + outSH[9] = -c1 * d; + outSH[11] = s1 * d; a = z2 * b - 0.238095238 * a; b = a - 0.242424242 * b; d = -19.226504963 * b; - out_shs[20] = -c1 * d; - out_shs[22] = s1 * d; + outSH[20] = -c1 * d; + outSH[22] = s1 * d; a = z2 * b - 0.244755245 * a; b = a - 0.246153846 * b; d = -77.964490818 * b; - out_shs[35] = -c1 * d; - out_shs[37] = s1 * d; + outSH[35] = -c1 * d; + outSH[37] = s1 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.546274215; - out_shs[1] = c0 * d; - out_shs[5] = s0 * d; + outSH[1] = c0 * d; + outSH[5] = s0 * d; a = z2 - 0.142857143; d = 3.311611435 * a; - out_shs[8] = c0 * d; - out_shs[12] = s0 * d; + outSH[8] = c0 * d; + outSH[12] = s0 * d; b = z2 * (a - 0.19047619); a = b - 0.212121212 * a; d = 15.199886782 * a; - out_shs[19] = c0 * d; - out_shs[23] = s0 * d; + outSH[19] = c0 * d; + outSH[23] = s0 * d; b = z2 * a - 0.223776224 * b; a = b - 0.230769231 * a; d = 65.229772956 * a; - out_shs[34] = c0 * d; - out_shs[38] = s0 * d; + outSH[34] = c0 * d; + outSH[38] = s0 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -1.77013077 * z; - out_shs[7] = -c1 * d; - out_shs[13] = s1 * d; + outSH[7] = -c1 * d; + outSH[13] = s1 * d; a = (z2 - 0.111111111) * z; b = a - 0.161616162 * z; d = -10.133257855 * b; - out_shs[18] = -c1 * d; - out_shs[24] = s1 * d; + outSH[18] = -c1 * d; + outSH[24] = s1 * d; a = z2 * b - 0.188811189 * a; b = a - 0.205128205 * b; d = -48.175380057 * b; - out_shs[33] = -c1 * d; - out_shs[39] = s1 * d; + outSH[33] = -c1 * d; + outSH[39] = s1 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.625835735; - out_shs[6] = c0 * d; - out_shs[14] = s0 * d; + outSH[6] = c0 * d; + outSH[14] = s0 * d; a = z2 - 9.09090909e-02; d = 5.550213908 * a; - out_shs[17] = c0 * d; - out_shs[25] = s0 * d; + outSH[17] = c0 * d; + outSH[25] = s0 * d; b = z2 * (a - 0.13986014); a = b - 0.169230769 * a; d = 31.097074109 * a; - out_shs[32] = c0 * d; - out_shs[40] = s0 * d; + outSH[32] = c0 * d; + outSH[40] = s0 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -2.366619162 * z; - out_shs[16] = -c1 * d; - out_shs[26] = s1 * d; + outSH[16] = -c1 * d; + outSH[26] = s1 * d; a = (z2 - 7.69230769e-02) * z; b = a - 0.123076923 * z; d = -17.24955311 * b; - out_shs[31] = -c1 * d; - out_shs[41] = s1 * d; + outSH[31] = -c1 * d; + outSH[41] = s1 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.683184105; - out_shs[15] = c0 * d; - out_shs[27] = s0 * d; + outSH[15] = c0 * d; + outSH[27] = s0 * d; a = z2 - 6.66666667e-02; d = 7.984991491 * a; - out_shs[30] = c0 * d; - out_shs[42] = s0 * d; + outSH[30] = c0 * d; + outSH[42] = s0 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -2.915706641 * z; - out_shs[29] = -c1 * d; - out_shs[43] = s1 * d; + outSH[29] = -c1 * d; + outSH[43] = s1 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.72892666; - out_shs[28] = c0 * d; - out_shs[44] = s0 * d; + outSH[28] = c0 * d; + outSH[44] = s0 * d; } diff --git a/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_10.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_10.frag index 9d5feea39..bed7ce26f 100644 --- a/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_10.frag +++ b/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_10.frag @@ -1,4 +1,4 @@ -void eval_sh_grad_10(out float out_shs[66], out vec3 out_grads[66], vec3 point) +void evalShGrad10(out float outSH[66], out vec3 outGrads[66], vec3 point) { float x, y, z, z2, c0, s0, c1, s1, d, a, b; x = point[0]; @@ -8,423 +8,423 @@ void eval_sh_grad_10(out float out_shs[66], out vec3 out_grads[66], vec3 point) c0 = 1.0; s0 = 0.0; d = 0.282094792; - out_shs[0] = d; + outSH[0] = d; a = z2 - 0.333333333; d = 0.946174696 * a; - out_shs[3] = d; + outSH[3] = d; b = z2 * (a - 0.266666667); a = b - 0.257142857 * a; d = 3.702494142 * a; - out_shs[10] = d; + outSH[10] = d; b = z2 * a - 0.253968254 * b; a = b - 0.252525253 * a; d = 14.684485724 * a; - out_shs[21] = d; + outSH[21] = d; b = z2 * a - 0.251748252 * b; a = b - 0.251282051 * a; d = 58.473368113 * a; - out_shs[36] = d; + outSH[36] = d; b = z2 * a - 0.250980392 * b; a = b - 0.250773994 * a; d = 233.240148813 * a; - out_shs[55] = d; + outSH[55] = d; c1 = x; s1 = y; d = -1.092548431 * z; - out_shs[2] = -c1 * d; - out_shs[4] = s1 * d; - out_grads[2][0] = -c0 * d; - out_grads[4][0] = s0 * d; - out_grads[2][1] = s0 * d; - out_grads[4][1] = c0 * d; + outSH[2] = -c1 * d; + outSH[4] = s1 * d; + outGrads[2][0] = -c0 * d; + outGrads[4][0] = s0 * d; + outGrads[2][1] = s0 * d; + outGrads[4][1] = c0 * d; d = 1.892349392 * z; - out_grads[3][2] = d; + outGrads[3][2] = d; a = (z2 - 0.2) * z; b = a - 0.228571429 * z; d = -4.683325805 * b; - out_shs[9] = -c1 * d; - out_shs[11] = s1 * d; - out_grads[9][0] = -c0 * d; - out_grads[11][0] = s0 * d; - out_grads[9][1] = s0 * d; - out_grads[11][1] = c0 * d; + outSH[9] = -c1 * d; + outSH[11] = s1 * d; + outGrads[9][0] = -c0 * d; + outGrads[11][0] = s0 * d; + outGrads[9][1] = s0 * d; + outGrads[11][1] = c0 * d; d = 14.809976568 * b; - out_grads[10][2] = d; + outGrads[10][2] = d; a = z2 * b - 0.238095238 * a; b = a - 0.242424242 * b; d = -19.226504963 * b; - out_shs[20] = -c1 * d; - out_shs[22] = s1 * d; - out_grads[20][0] = -c0 * d; - out_grads[22][0] = s0 * d; - out_grads[20][1] = s0 * d; - out_grads[22][1] = c0 * d; + outSH[20] = -c1 * d; + outSH[22] = s1 * d; + outGrads[20][0] = -c0 * d; + outGrads[22][0] = s0 * d; + outGrads[20][1] = s0 * d; + outGrads[22][1] = c0 * d; d = 88.106914343 * b; - out_grads[21][2] = d; + outGrads[21][2] = d; a = z2 * b - 0.244755245 * a; b = a - 0.246153846 * b; d = -77.964490818 * b; - out_shs[35] = -c1 * d; - out_shs[37] = s1 * d; - out_grads[35][0] = -c0 * d; - out_grads[37][0] = s0 * d; - out_grads[35][1] = s0 * d; - out_grads[37][1] = c0 * d; + outSH[35] = -c1 * d; + outSH[37] = s1 * d; + outGrads[35][0] = -c0 * d; + outGrads[37][0] = s0 * d; + outGrads[35][1] = s0 * d; + outGrads[37][1] = c0 * d; d = 467.786944906 * b; - out_grads[36][2] = d; + outGrads[36][2] = d; a = z2 * b - 0.247058824 * a; b = a - 0.247678019 * b; d = -314.500952502 * b; - out_shs[54] = -c1 * d; - out_shs[56] = s1 * d; - out_grads[54][0] = -c0 * d; - out_grads[56][0] = s0 * d; - out_grads[54][1] = s0 * d; - out_grads[56][1] = c0 * d; + outSH[54] = -c1 * d; + outSH[56] = s1 * d; + outGrads[54][0] = -c0 * d; + outGrads[56][0] = s0 * d; + outGrads[54][1] = s0 * d; + outGrads[56][1] = c0 * d; d = 2332.401488133 * b; - out_grads[55][2] = d; + outGrads[55][2] = d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.546274215; - out_shs[1] = c0 * d; - out_shs[5] = s0 * d; + outSH[1] = c0 * d; + outSH[5] = s0 * d; d = 1.092548431; - out_grads[1][0] = c1 * d; - out_grads[5][0] = s1 * d; - out_grads[1][1] = -s1 * d; - out_grads[5][1] = c1 * d; + outGrads[1][0] = c1 * d; + outGrads[5][0] = s1 * d; + outGrads[1][1] = -s1 * d; + outGrads[5][1] = c1 * d; d = -1.092548431; - out_grads[2][2] = -c1 * d; - out_grads[4][2] = s1 * d; + outGrads[2][2] = -c1 * d; + outGrads[4][2] = s1 * d; a = z2 - 0.142857143; d = 3.311611435 * a; - out_shs[8] = c0 * d; - out_shs[12] = s0 * d; + outSH[8] = c0 * d; + outSH[12] = s0 * d; d = 6.62322287 * a; - out_grads[8][0] = c1 * d; - out_grads[12][0] = s1 * d; - out_grads[8][1] = -s1 * d; - out_grads[12][1] = c1 * d; + outGrads[8][0] = c1 * d; + outGrads[12][0] = s1 * d; + outGrads[8][1] = -s1 * d; + outGrads[12][1] = c1 * d; d = -14.049977415 * a; - out_grads[9][2] = -c1 * d; - out_grads[11][2] = s1 * d; + outGrads[9][2] = -c1 * d; + outGrads[11][2] = s1 * d; b = z2 * (a - 0.19047619); a = b - 0.212121212 * a; d = 15.199886782 * a; - out_shs[19] = c0 * d; - out_shs[23] = s0 * d; + outSH[19] = c0 * d; + outSH[23] = s0 * d; d = 30.399773564 * a; - out_grads[19][0] = c1 * d; - out_grads[23][0] = s1 * d; - out_grads[19][1] = -s1 * d; - out_grads[23][1] = c1 * d; + outGrads[19][0] = c1 * d; + outGrads[23][0] = s1 * d; + outGrads[19][1] = -s1 * d; + outGrads[23][1] = c1 * d; d = -96.132524816 * a; - out_grads[20][2] = -c1 * d; - out_grads[22][2] = s1 * d; + outGrads[20][2] = -c1 * d; + outGrads[22][2] = s1 * d; b = z2 * a - 0.223776224 * b; a = b - 0.230769231 * a; d = 65.229772956 * a; - out_shs[34] = c0 * d; - out_shs[38] = s0 * d; + outSH[34] = c0 * d; + outSH[38] = s0 * d; d = 130.459545912 * a; - out_grads[34][0] = c1 * d; - out_grads[38][0] = s1 * d; - out_grads[34][1] = -s1 * d; - out_grads[38][1] = c1 * d; + outGrads[34][0] = c1 * d; + outGrads[38][0] = s1 * d; + outGrads[34][1] = -s1 * d; + outGrads[38][1] = c1 * d; d = -545.751435723 * a; - out_grads[35][2] = -c1 * d; - out_grads[37][2] = s1 * d; + outGrads[35][2] = -c1 * d; + outGrads[37][2] = s1 * d; b = z2 * a - 0.235294118 * b; a = b - 0.238390093 * a; d = 272.365814381 * a; - out_shs[53] = c0 * d; - out_shs[57] = s0 * d; + outSH[53] = c0 * d; + outSH[57] = s0 * d; d = 544.731628762 * a; - out_grads[53][0] = c1 * d; - out_grads[57][0] = s1 * d; - out_grads[53][1] = -s1 * d; - out_grads[57][1] = c1 * d; + outGrads[53][0] = c1 * d; + outGrads[57][0] = s1 * d; + outGrads[53][1] = -s1 * d; + outGrads[57][1] = c1 * d; d = -2830.508572514 * a; - out_grads[54][2] = -c1 * d; - out_grads[56][2] = s1 * d; + outGrads[54][2] = -c1 * d; + outGrads[56][2] = s1 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -1.77013077 * z; - out_shs[7] = -c1 * d; - out_shs[13] = s1 * d; + outSH[7] = -c1 * d; + outSH[13] = s1 * d; d = -5.310392309 * z; - out_grads[7][0] = -c0 * d; - out_grads[13][0] = s0 * d; - out_grads[7][1] = s0 * d; - out_grads[13][1] = c0 * d; + outGrads[7][0] = -c0 * d; + outGrads[13][0] = s0 * d; + outGrads[7][1] = s0 * d; + outGrads[13][1] = c0 * d; d = 6.62322287 * z; - out_grads[8][2] = c0 * d; - out_grads[12][2] = s0 * d; + outGrads[8][2] = c0 * d; + outGrads[12][2] = s0 * d; a = (z2 - 0.111111111) * z; b = a - 0.161616162 * z; d = -10.133257855 * b; - out_shs[18] = -c1 * d; - out_shs[24] = s1 * d; + outSH[18] = -c1 * d; + outSH[24] = s1 * d; d = -30.399773564 * b; - out_grads[18][0] = -c0 * d; - out_grads[24][0] = s0 * d; - out_grads[18][1] = s0 * d; - out_grads[24][1] = c0 * d; + outGrads[18][0] = -c0 * d; + outGrads[24][0] = s0 * d; + outGrads[18][1] = s0 * d; + outGrads[24][1] = c0 * d; d = 60.799547128 * b; - out_grads[19][2] = c0 * d; - out_grads[23][2] = s0 * d; + outGrads[19][2] = c0 * d; + outGrads[23][2] = s0 * d; a = z2 * b - 0.188811189 * a; b = a - 0.205128205 * b; d = -48.175380057 * b; - out_shs[33] = -c1 * d; - out_shs[39] = s1 * d; + outSH[33] = -c1 * d; + outSH[39] = s1 * d; d = -144.52614017 * b; - out_grads[33][0] = -c0 * d; - out_grads[39][0] = s0 * d; - out_grads[33][1] = s0 * d; - out_grads[39][1] = c0 * d; + outGrads[33][0] = -c0 * d; + outGrads[39][0] = s0 * d; + outGrads[33][1] = s0 * d; + outGrads[39][1] = c0 * d; d = 391.378637737 * b; - out_grads[34][2] = c0 * d; - out_grads[38][2] = s0 * d; + outGrads[34][2] = c0 * d; + outGrads[38][2] = s0 * d; a = z2 * b - 0.215686275 * a; b = a - 0.222910217 * b; d = -213.661323441 * b; - out_shs[52] = -c1 * d; - out_shs[58] = s1 * d; + outSH[52] = -c1 * d; + outSH[58] = s1 * d; d = -640.983970322 * b; - out_grads[52][0] = -c0 * d; - out_grads[58][0] = s0 * d; - out_grads[52][1] = s0 * d; - out_grads[58][1] = c0 * d; + outGrads[52][0] = -c0 * d; + outGrads[58][0] = s0 * d; + outGrads[52][1] = s0 * d; + outGrads[58][1] = c0 * d; d = 2178.926515046 * b; - out_grads[53][2] = c0 * d; - out_grads[57][2] = s0 * d; + outGrads[53][2] = c0 * d; + outGrads[57][2] = s0 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.625835735; - out_shs[6] = c0 * d; - out_shs[14] = s0 * d; + outSH[6] = c0 * d; + outSH[14] = s0 * d; d = 2.503342942; - out_grads[6][0] = c1 * d; - out_grads[14][0] = s1 * d; - out_grads[6][1] = -s1 * d; - out_grads[14][1] = c1 * d; + outGrads[6][0] = c1 * d; + outGrads[14][0] = s1 * d; + outGrads[6][1] = -s1 * d; + outGrads[14][1] = c1 * d; d = -1.77013077; - out_grads[7][2] = -c1 * d; - out_grads[13][2] = s1 * d; + outGrads[7][2] = -c1 * d; + outGrads[13][2] = s1 * d; a = z2 - 9.09090909e-02; d = 5.550213908 * a; - out_shs[17] = c0 * d; - out_shs[25] = s0 * d; + outSH[17] = c0 * d; + outSH[25] = s0 * d; d = 22.200855632 * a; - out_grads[17][0] = c1 * d; - out_grads[25][0] = s1 * d; - out_grads[17][1] = -s1 * d; - out_grads[25][1] = c1 * d; + outGrads[17][0] = c1 * d; + outGrads[25][0] = s1 * d; + outGrads[17][1] = -s1 * d; + outGrads[25][1] = c1 * d; d = -30.399773564 * a; - out_grads[18][2] = -c1 * d; - out_grads[24][2] = s1 * d; + outGrads[18][2] = -c1 * d; + outGrads[24][2] = s1 * d; b = z2 * (a - 0.13986014); a = b - 0.169230769 * a; d = 31.097074109 * a; - out_shs[32] = c0 * d; - out_shs[40] = s0 * d; + outSH[32] = c0 * d; + outSH[40] = s0 * d; d = 124.388296437 * a; - out_grads[32][0] = c1 * d; - out_grads[40][0] = s1 * d; - out_grads[32][1] = -s1 * d; - out_grads[40][1] = c1 * d; + outGrads[32][0] = c1 * d; + outGrads[40][0] = s1 * d; + outGrads[32][1] = -s1 * d; + outGrads[40][1] = c1 * d; d = -240.876900283 * a; - out_grads[33][2] = -c1 * d; - out_grads[39][2] = s1 * d; + outGrads[33][2] = -c1 * d; + outGrads[39][2] = s1 * d; b = z2 * a - 0.188235294 * b; a = b - 0.20123839 * a; d = 151.081370682 * a; - out_shs[51] = c0 * d; - out_shs[59] = s0 * d; + outSH[51] = c0 * d; + outSH[59] = s0 * d; d = 604.325482728 * a; - out_grads[51][0] = c1 * d; - out_grads[59][0] = s1 * d; - out_grads[51][1] = -s1 * d; - out_grads[59][1] = c1 * d; + outGrads[51][0] = c1 * d; + outGrads[59][0] = s1 * d; + outGrads[51][1] = -s1 * d; + outGrads[59][1] = c1 * d; d = -1495.629264084 * a; - out_grads[52][2] = -c1 * d; - out_grads[58][2] = s1 * d; + outGrads[52][2] = -c1 * d; + outGrads[58][2] = s1 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -2.366619162 * z; - out_shs[16] = -c1 * d; - out_shs[26] = s1 * d; + outSH[16] = -c1 * d; + outSH[26] = s1 * d; d = -11.833095811 * z; - out_grads[16][0] = -c0 * d; - out_grads[26][0] = s0 * d; - out_grads[16][1] = s0 * d; - out_grads[26][1] = c0 * d; + outGrads[16][0] = -c0 * d; + outGrads[26][0] = s0 * d; + outGrads[16][1] = s0 * d; + outGrads[26][1] = c0 * d; d = 11.100427816 * z; - out_grads[17][2] = c0 * d; - out_grads[25][2] = s0 * d; + outGrads[17][2] = c0 * d; + outGrads[25][2] = s0 * d; a = (z2 - 7.69230769e-02) * z; b = a - 0.123076923 * z; d = -17.24955311 * b; - out_shs[31] = -c1 * d; - out_shs[41] = s1 * d; + outSH[31] = -c1 * d; + outSH[41] = s1 * d; d = -86.247765552 * b; - out_grads[31][0] = -c0 * d; - out_grads[41][0] = s0 * d; - out_grads[31][1] = s0 * d; - out_grads[41][1] = c0 * d; + outGrads[31][0] = -c0 * d; + outGrads[41][0] = s0 * d; + outGrads[31][1] = s0 * d; + outGrads[41][1] = c0 * d; d = 124.388296437 * b; - out_grads[32][2] = c0 * d; - out_grads[40][2] = s0 * d; + outGrads[32][2] = c0 * d; + outGrads[40][2] = s0 * d; a = z2 * b - 0.152941176 * a; b = a - 0.173374613 * b; d = -95.552248675 * b; - out_shs[50] = -c1 * d; - out_shs[60] = s1 * d; + outSH[50] = -c1 * d; + outSH[60] = s1 * d; d = -477.761243376 * b; - out_grads[50][0] = -c0 * d; - out_grads[60][0] = s0 * d; - out_grads[50][1] = s0 * d; - out_grads[60][1] = c0 * d; + outGrads[50][0] = -c0 * d; + outGrads[60][0] = s0 * d; + outGrads[50][1] = s0 * d; + outGrads[60][1] = c0 * d; d = 906.488224092 * b; - out_grads[51][2] = c0 * d; - out_grads[59][2] = s0 * d; + outGrads[51][2] = c0 * d; + outGrads[59][2] = s0 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.683184105; - out_shs[15] = c0 * d; - out_shs[27] = s0 * d; + outSH[15] = c0 * d; + outSH[27] = s0 * d; d = 4.099104631; - out_grads[15][0] = c1 * d; - out_grads[27][0] = s1 * d; - out_grads[15][1] = -s1 * d; - out_grads[27][1] = c1 * d; + outGrads[15][0] = c1 * d; + outGrads[27][0] = s1 * d; + outGrads[15][1] = -s1 * d; + outGrads[27][1] = c1 * d; d = -2.366619162; - out_grads[16][2] = -c1 * d; - out_grads[26][2] = s1 * d; + outGrads[16][2] = -c1 * d; + outGrads[26][2] = s1 * d; a = z2 - 6.66666667e-02; d = 7.984991491 * a; - out_shs[30] = c0 * d; - out_shs[42] = s0 * d; + outSH[30] = c0 * d; + outSH[42] = s0 * d; d = 47.909948945 * a; - out_grads[30][0] = c1 * d; - out_grads[42][0] = s1 * d; - out_grads[30][1] = -s1 * d; - out_grads[42][1] = c1 * d; + outGrads[30][0] = c1 * d; + outGrads[42][0] = s1 * d; + outGrads[30][1] = -s1 * d; + outGrads[42][1] = c1 * d; d = -51.748659331 * a; - out_grads[31][2] = -c1 * d; - out_grads[41][2] = s1 * d; + outGrads[31][2] = -c1 * d; + outGrads[41][2] = s1 * d; b = z2 * (a - 0.109803922); a = b - 0.139318885 * a; d = 53.41533086 * a; - out_shs[49] = c0 * d; - out_shs[61] = s0 * d; + outSH[49] = c0 * d; + outSH[61] = s0 * d; d = 320.491985161 * a; - out_grads[49][0] = c1 * d; - out_grads[61][0] = s1 * d; - out_grads[49][1] = -s1 * d; - out_grads[61][1] = c1 * d; + outGrads[49][0] = c1 * d; + outGrads[61][0] = s1 * d; + outGrads[49][1] = -s1 * d; + outGrads[61][1] = c1 * d; d = -477.761243376 * a; - out_grads[50][2] = -c1 * d; - out_grads[60][2] = s1 * d; + outGrads[50][2] = -c1 * d; + outGrads[60][2] = s1 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -2.915706641 * z; - out_shs[29] = -c1 * d; - out_shs[43] = s1 * d; + outSH[29] = -c1 * d; + outSH[43] = s1 * d; d = -20.409946485 * z; - out_grads[29][0] = -c0 * d; - out_grads[43][0] = s0 * d; - out_grads[29][1] = s0 * d; - out_grads[43][1] = c0 * d; + outGrads[29][0] = -c0 * d; + outGrads[43][0] = s0 * d; + outGrads[29][1] = s0 * d; + outGrads[43][1] = c0 * d; d = 15.969982982 * z; - out_grads[30][2] = c0 * d; - out_grads[42][2] = s0 * d; + outGrads[30][2] = c0 * d; + outGrads[42][2] = s0 * d; a = (z2 - 5.88235294e-02) * z; b = a - 9.90712074e-02 * z; d = -25.910241313 * b; - out_shs[48] = -c1 * d; - out_shs[62] = s1 * d; + outSH[48] = -c1 * d; + outSH[62] = s1 * d; d = -181.371689194 * b; - out_grads[48][0] = -c0 * d; - out_grads[62][0] = s0 * d; - out_grads[48][1] = s0 * d; - out_grads[62][1] = c0 * d; + outGrads[48][0] = -c0 * d; + outGrads[62][0] = s0 * d; + outGrads[48][1] = s0 * d; + outGrads[62][1] = c0 * d; d = 213.661323441 * b; - out_grads[49][2] = c0 * d; - out_grads[61][2] = s0 * d; + outGrads[49][2] = c0 * d; + outGrads[61][2] = s0 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.72892666; - out_shs[28] = c0 * d; - out_shs[44] = s0 * d; + outSH[28] = c0 * d; + outSH[44] = s0 * d; d = 5.831413281; - out_grads[28][0] = c1 * d; - out_grads[44][0] = s1 * d; - out_grads[28][1] = -s1 * d; - out_grads[44][1] = c1 * d; + outGrads[28][0] = c1 * d; + outGrads[44][0] = s1 * d; + outGrads[28][1] = -s1 * d; + outGrads[44][1] = c1 * d; d = -2.915706641; - out_grads[29][2] = -c1 * d; - out_grads[43][2] = s1 * d; + outGrads[29][2] = -c1 * d; + outGrads[43][2] = s1 * d; a = z2 - 5.26315789e-02; d = 10.577811722 * a; - out_shs[47] = c0 * d; - out_shs[63] = s0 * d; + outSH[47] = c0 * d; + outSH[63] = s0 * d; d = 84.622493774 * a; - out_grads[47][0] = c1 * d; - out_grads[63][0] = s1 * d; - out_grads[47][1] = -s1 * d; - out_grads[63][1] = c1 * d; + outGrads[47][0] = c1 * d; + outGrads[63][0] = s1 * d; + outGrads[47][1] = -s1 * d; + outGrads[63][1] = c1 * d; d = -77.73072394 * a; - out_grads[48][2] = -c1 * d; - out_grads[62][2] = s1 * d; + outGrads[48][2] = -c1 * d; + outGrads[62][2] = s1 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -3.4318953 * z; - out_shs[46] = -c1 * d; - out_shs[64] = s1 * d; + outSH[46] = -c1 * d; + outSH[64] = s1 * d; d = -30.887057699 * z; - out_grads[46][0] = -c0 * d; - out_grads[64][0] = s0 * d; - out_grads[46][1] = s0 * d; - out_grads[64][1] = c0 * d; + outGrads[46][0] = -c0 * d; + outGrads[64][0] = s0 * d; + outGrads[46][1] = s0 * d; + outGrads[64][1] = c0 * d; d = 21.155623443 * z; - out_grads[47][2] = c0 * d; - out_grads[63][2] = s0 * d; + outGrads[47][2] = c0 * d; + outGrads[63][2] = s0 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.767395118; - out_shs[45] = c0 * d; - out_shs[65] = s0 * d; + outSH[45] = c0 * d; + outSH[65] = s0 * d; d = 7.673951182; - out_grads[45][0] = c1 * d; - out_grads[65][0] = s1 * d; - out_grads[45][1] = -s1 * d; - out_grads[65][1] = c1 * d; + outGrads[45][0] = c1 * d; + outGrads[65][0] = s1 * d; + outGrads[45][1] = -s1 * d; + outGrads[65][1] = c1 * d; d = -3.4318953; - out_grads[46][2] = -c1 * d; - out_grads[64][2] = s1 * d; - out_grads[0][0] = 0.0; - out_grads[0][1] = 0.0; - out_grads[0][2] = 0.0; - out_grads[1][2] = 0.0; - out_grads[3][0] = 0.0; - out_grads[3][1] = 0.0; - out_grads[5][2] = 0.0; - out_grads[6][2] = 0.0; - out_grads[10][0] = 0.0; - out_grads[10][1] = 0.0; - out_grads[14][2] = 0.0; - out_grads[15][2] = 0.0; - out_grads[21][0] = 0.0; - out_grads[21][1] = 0.0; - out_grads[27][2] = 0.0; - out_grads[28][2] = 0.0; - out_grads[36][0] = 0.0; - out_grads[36][1] = 0.0; - out_grads[44][2] = 0.0; - out_grads[45][2] = 0.0; - out_grads[55][0] = 0.0; - out_grads[55][1] = 0.0; - out_grads[65][2] = 0.0; + outGrads[46][2] = -c1 * d; + outGrads[64][2] = s1 * d; + outGrads[0][0] = 0.0; + outGrads[0][1] = 0.0; + outGrads[0][2] = 0.0; + outGrads[1][2] = 0.0; + outGrads[3][0] = 0.0; + outGrads[3][1] = 0.0; + outGrads[5][2] = 0.0; + outGrads[6][2] = 0.0; + outGrads[10][0] = 0.0; + outGrads[10][1] = 0.0; + outGrads[14][2] = 0.0; + outGrads[15][2] = 0.0; + outGrads[21][0] = 0.0; + outGrads[21][1] = 0.0; + outGrads[27][2] = 0.0; + outGrads[28][2] = 0.0; + outGrads[36][0] = 0.0; + outGrads[36][1] = 0.0; + outGrads[44][2] = 0.0; + outGrads[45][2] = 0.0; + outGrads[55][0] = 0.0; + outGrads[55][1] = 0.0; + outGrads[65][2] = 0.0; } diff --git a/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_12.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_12.frag index f7ff069bc..7b391a77c 100644 --- a/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_12.frag +++ b/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_12.frag @@ -1,4 +1,4 @@ -void eval_sh_grad_12(out float out_shs[91], out vec3 out_grads[91], vec3 point) +void evalShGrad12(out float outSH[91], out vec3 outGrads[91], vec3 point) { float x, y, z, z2, c0, s0, c1, s1, d, a, b; x = point[0]; @@ -8,584 +8,584 @@ void eval_sh_grad_12(out float out_shs[91], out vec3 out_grads[91], vec3 point) c0 = 1.0; s0 = 0.0; d = 0.282094792; - out_shs[0] = d; + outSH[0] = d; a = z2 - 0.333333333; d = 0.946174696 * a; - out_shs[3] = d; + outSH[3] = d; b = z2 * (a - 0.266666667); a = b - 0.257142857 * a; d = 3.702494142 * a; - out_shs[10] = d; + outSH[10] = d; b = z2 * a - 0.253968254 * b; a = b - 0.252525253 * a; d = 14.684485724 * a; - out_shs[21] = d; + outSH[21] = d; b = z2 * a - 0.251748252 * b; a = b - 0.251282051 * a; d = 58.473368113 * a; - out_shs[36] = d; + outSH[36] = d; b = z2 * a - 0.250980392 * b; a = b - 0.250773994 * a; d = 233.240148813 * a; - out_shs[55] = d; + outSH[55] = d; b = z2 * a - 0.250626566 * b; a = b - 0.250517598 * a; d = 931.186918633 * a; - out_shs[78] = d; + outSH[78] = d; c1 = x; s1 = y; d = -1.092548431 * z; - out_shs[2] = -c1 * d; - out_shs[4] = s1 * d; - out_grads[2][0] = -c0 * d; - out_grads[4][0] = s0 * d; - out_grads[2][1] = s0 * d; - out_grads[4][1] = c0 * d; + outSH[2] = -c1 * d; + outSH[4] = s1 * d; + outGrads[2][0] = -c0 * d; + outGrads[4][0] = s0 * d; + outGrads[2][1] = s0 * d; + outGrads[4][1] = c0 * d; d = 1.892349392 * z; - out_grads[3][2] = d; + outGrads[3][2] = d; a = (z2 - 0.2) * z; b = a - 0.228571429 * z; d = -4.683325805 * b; - out_shs[9] = -c1 * d; - out_shs[11] = s1 * d; - out_grads[9][0] = -c0 * d; - out_grads[11][0] = s0 * d; - out_grads[9][1] = s0 * d; - out_grads[11][1] = c0 * d; + outSH[9] = -c1 * d; + outSH[11] = s1 * d; + outGrads[9][0] = -c0 * d; + outGrads[11][0] = s0 * d; + outGrads[9][1] = s0 * d; + outGrads[11][1] = c0 * d; d = 14.809976568 * b; - out_grads[10][2] = d; + outGrads[10][2] = d; a = z2 * b - 0.238095238 * a; b = a - 0.242424242 * b; d = -19.226504963 * b; - out_shs[20] = -c1 * d; - out_shs[22] = s1 * d; - out_grads[20][0] = -c0 * d; - out_grads[22][0] = s0 * d; - out_grads[20][1] = s0 * d; - out_grads[22][1] = c0 * d; + outSH[20] = -c1 * d; + outSH[22] = s1 * d; + outGrads[20][0] = -c0 * d; + outGrads[22][0] = s0 * d; + outGrads[20][1] = s0 * d; + outGrads[22][1] = c0 * d; d = 88.106914343 * b; - out_grads[21][2] = d; + outGrads[21][2] = d; a = z2 * b - 0.244755245 * a; b = a - 0.246153846 * b; d = -77.964490818 * b; - out_shs[35] = -c1 * d; - out_shs[37] = s1 * d; - out_grads[35][0] = -c0 * d; - out_grads[37][0] = s0 * d; - out_grads[35][1] = s0 * d; - out_grads[37][1] = c0 * d; + outSH[35] = -c1 * d; + outSH[37] = s1 * d; + outGrads[35][0] = -c0 * d; + outGrads[37][0] = s0 * d; + outGrads[35][1] = s0 * d; + outGrads[37][1] = c0 * d; d = 467.786944906 * b; - out_grads[36][2] = d; + outGrads[36][2] = d; a = z2 * b - 0.247058824 * a; b = a - 0.247678019 * b; d = -314.500952502 * b; - out_shs[54] = -c1 * d; - out_shs[56] = s1 * d; - out_grads[54][0] = -c0 * d; - out_grads[56][0] = s0 * d; - out_grads[54][1] = s0 * d; - out_grads[56][1] = c0 * d; + outSH[54] = -c1 * d; + outSH[56] = s1 * d; + outGrads[54][0] = -c0 * d; + outGrads[56][0] = s0 * d; + outGrads[54][1] = s0 * d; + outGrads[56][1] = c0 * d; d = 2332.401488133 * b; - out_grads[55][2] = d; + outGrads[55][2] = d; a = z2 * b - 0.248120301 * a; b = a - 0.248447205 * b; d = -1265.233874957 * b; - out_shs[77] = -c1 * d; - out_shs[79] = s1 * d; - out_grads[77][0] = -c0 * d; - out_grads[79][0] = s0 * d; - out_grads[77][1] = s0 * d; - out_grads[79][1] = c0 * d; + outSH[77] = -c1 * d; + outSH[79] = s1 * d; + outGrads[77][0] = -c0 * d; + outGrads[79][0] = s0 * d; + outGrads[77][1] = s0 * d; + outGrads[79][1] = c0 * d; d = 11174.243023595 * b; - out_grads[78][2] = d; + outGrads[78][2] = d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.546274215; - out_shs[1] = c0 * d; - out_shs[5] = s0 * d; + outSH[1] = c0 * d; + outSH[5] = s0 * d; d = 1.092548431; - out_grads[1][0] = c1 * d; - out_grads[5][0] = s1 * d; - out_grads[1][1] = -s1 * d; - out_grads[5][1] = c1 * d; + outGrads[1][0] = c1 * d; + outGrads[5][0] = s1 * d; + outGrads[1][1] = -s1 * d; + outGrads[5][1] = c1 * d; d = -1.092548431; - out_grads[2][2] = -c1 * d; - out_grads[4][2] = s1 * d; + outGrads[2][2] = -c1 * d; + outGrads[4][2] = s1 * d; a = z2 - 0.142857143; d = 3.311611435 * a; - out_shs[8] = c0 * d; - out_shs[12] = s0 * d; + outSH[8] = c0 * d; + outSH[12] = s0 * d; d = 6.62322287 * a; - out_grads[8][0] = c1 * d; - out_grads[12][0] = s1 * d; - out_grads[8][1] = -s1 * d; - out_grads[12][1] = c1 * d; + outGrads[8][0] = c1 * d; + outGrads[12][0] = s1 * d; + outGrads[8][1] = -s1 * d; + outGrads[12][1] = c1 * d; d = -14.049977415 * a; - out_grads[9][2] = -c1 * d; - out_grads[11][2] = s1 * d; + outGrads[9][2] = -c1 * d; + outGrads[11][2] = s1 * d; b = z2 * (a - 0.19047619); a = b - 0.212121212 * a; d = 15.199886782 * a; - out_shs[19] = c0 * d; - out_shs[23] = s0 * d; + outSH[19] = c0 * d; + outSH[23] = s0 * d; d = 30.399773564 * a; - out_grads[19][0] = c1 * d; - out_grads[23][0] = s1 * d; - out_grads[19][1] = -s1 * d; - out_grads[23][1] = c1 * d; + outGrads[19][0] = c1 * d; + outGrads[23][0] = s1 * d; + outGrads[19][1] = -s1 * d; + outGrads[23][1] = c1 * d; d = -96.132524816 * a; - out_grads[20][2] = -c1 * d; - out_grads[22][2] = s1 * d; + outGrads[20][2] = -c1 * d; + outGrads[22][2] = s1 * d; b = z2 * a - 0.223776224 * b; a = b - 0.230769231 * a; d = 65.229772956 * a; - out_shs[34] = c0 * d; - out_shs[38] = s0 * d; + outSH[34] = c0 * d; + outSH[38] = s0 * d; d = 130.459545912 * a; - out_grads[34][0] = c1 * d; - out_grads[38][0] = s1 * d; - out_grads[34][1] = -s1 * d; - out_grads[38][1] = c1 * d; + outGrads[34][0] = c1 * d; + outGrads[38][0] = s1 * d; + outGrads[34][1] = -s1 * d; + outGrads[38][1] = c1 * d; d = -545.751435723 * a; - out_grads[35][2] = -c1 * d; - out_grads[37][2] = s1 * d; + outGrads[35][2] = -c1 * d; + outGrads[37][2] = s1 * d; b = z2 * a - 0.235294118 * b; a = b - 0.238390093 * a; d = 272.365814381 * a; - out_shs[53] = c0 * d; - out_shs[57] = s0 * d; + outSH[53] = c0 * d; + outSH[57] = s0 * d; d = 544.731628762 * a; - out_grads[53][0] = c1 * d; - out_grads[57][0] = s1 * d; - out_grads[53][1] = -s1 * d; - out_grads[57][1] = c1 * d; + outGrads[53][0] = c1 * d; + outGrads[57][0] = s1 * d; + outGrads[53][1] = -s1 * d; + outGrads[57][1] = c1 * d; d = -2830.508572514 * a; - out_grads[54][2] = -c1 * d; - out_grads[56][2] = s1 * d; + outGrads[54][2] = -c1 * d; + outGrads[56][2] = s1 * d; b = z2 * a - 0.240601504 * b; a = b - 0.242236025 * a; d = 1121.509962433 * a; - out_shs[76] = c0 * d; - out_shs[80] = s0 * d; + outSH[76] = c0 * d; + outSH[80] = s0 * d; d = 2243.019924866 * a; - out_grads[76][0] = c1 * d; - out_grads[80][0] = s1 * d; - out_grads[76][1] = -s1 * d; - out_grads[80][1] = c1 * d; + outGrads[76][0] = c1 * d; + outGrads[80][0] = s1 * d; + outGrads[76][1] = -s1 * d; + outGrads[80][1] = c1 * d; d = -13917.572624524 * a; - out_grads[77][2] = -c1 * d; - out_grads[79][2] = s1 * d; + outGrads[77][2] = -c1 * d; + outGrads[79][2] = s1 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -1.77013077 * z; - out_shs[7] = -c1 * d; - out_shs[13] = s1 * d; + outSH[7] = -c1 * d; + outSH[13] = s1 * d; d = -5.310392309 * z; - out_grads[7][0] = -c0 * d; - out_grads[13][0] = s0 * d; - out_grads[7][1] = s0 * d; - out_grads[13][1] = c0 * d; + outGrads[7][0] = -c0 * d; + outGrads[13][0] = s0 * d; + outGrads[7][1] = s0 * d; + outGrads[13][1] = c0 * d; d = 6.62322287 * z; - out_grads[8][2] = c0 * d; - out_grads[12][2] = s0 * d; + outGrads[8][2] = c0 * d; + outGrads[12][2] = s0 * d; a = (z2 - 0.111111111) * z; b = a - 0.161616162 * z; d = -10.133257855 * b; - out_shs[18] = -c1 * d; - out_shs[24] = s1 * d; + outSH[18] = -c1 * d; + outSH[24] = s1 * d; d = -30.399773564 * b; - out_grads[18][0] = -c0 * d; - out_grads[24][0] = s0 * d; - out_grads[18][1] = s0 * d; - out_grads[24][1] = c0 * d; + outGrads[18][0] = -c0 * d; + outGrads[24][0] = s0 * d; + outGrads[18][1] = s0 * d; + outGrads[24][1] = c0 * d; d = 60.799547128 * b; - out_grads[19][2] = c0 * d; - out_grads[23][2] = s0 * d; + outGrads[19][2] = c0 * d; + outGrads[23][2] = s0 * d; a = z2 * b - 0.188811189 * a; b = a - 0.205128205 * b; d = -48.175380057 * b; - out_shs[33] = -c1 * d; - out_shs[39] = s1 * d; + outSH[33] = -c1 * d; + outSH[39] = s1 * d; d = -144.52614017 * b; - out_grads[33][0] = -c0 * d; - out_grads[39][0] = s0 * d; - out_grads[33][1] = s0 * d; - out_grads[39][1] = c0 * d; + outGrads[33][0] = -c0 * d; + outGrads[39][0] = s0 * d; + outGrads[33][1] = s0 * d; + outGrads[39][1] = c0 * d; d = 391.378637737 * b; - out_grads[34][2] = c0 * d; - out_grads[38][2] = s0 * d; + outGrads[34][2] = c0 * d; + outGrads[38][2] = s0 * d; a = z2 * b - 0.215686275 * a; b = a - 0.222910217 * b; d = -213.661323441 * b; - out_shs[52] = -c1 * d; - out_shs[58] = s1 * d; + outSH[52] = -c1 * d; + outSH[58] = s1 * d; d = -640.983970322 * b; - out_grads[52][0] = -c0 * d; - out_grads[58][0] = s0 * d; - out_grads[52][1] = s0 * d; - out_grads[58][1] = c0 * d; + outGrads[52][0] = -c0 * d; + outGrads[58][0] = s0 * d; + outGrads[52][1] = s0 * d; + outGrads[58][1] = c0 * d; d = 2178.926515046 * b; - out_grads[53][2] = c0 * d; - out_grads[57][2] = s0 * d; + outGrads[53][2] = c0 * d; + outGrads[57][2] = s0 * d; a = z2 * b - 0.228070175 * a; b = a - 0.231884058 * b; d = -915.709049803 * b; - out_shs[75] = -c1 * d; - out_shs[81] = s1 * d; + outSH[75] = -c1 * d; + outSH[81] = s1 * d; d = -2747.127149409 * b; - out_grads[75][0] = -c0 * d; - out_grads[81][0] = s0 * d; - out_grads[75][1] = s0 * d; - out_grads[81][1] = c0 * d; + outGrads[75][0] = -c0 * d; + outGrads[81][0] = s0 * d; + outGrads[75][1] = s0 * d; + outGrads[81][1] = c0 * d; d = 11215.099624332 * b; - out_grads[76][2] = c0 * d; - out_grads[80][2] = s0 * d; + outGrads[76][2] = c0 * d; + outGrads[80][2] = s0 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.625835735; - out_shs[6] = c0 * d; - out_shs[14] = s0 * d; + outSH[6] = c0 * d; + outSH[14] = s0 * d; d = 2.503342942; - out_grads[6][0] = c1 * d; - out_grads[14][0] = s1 * d; - out_grads[6][1] = -s1 * d; - out_grads[14][1] = c1 * d; + outGrads[6][0] = c1 * d; + outGrads[14][0] = s1 * d; + outGrads[6][1] = -s1 * d; + outGrads[14][1] = c1 * d; d = -1.77013077; - out_grads[7][2] = -c1 * d; - out_grads[13][2] = s1 * d; + outGrads[7][2] = -c1 * d; + outGrads[13][2] = s1 * d; a = z2 - 9.09090909e-02; d = 5.550213908 * a; - out_shs[17] = c0 * d; - out_shs[25] = s0 * d; + outSH[17] = c0 * d; + outSH[25] = s0 * d; d = 22.200855632 * a; - out_grads[17][0] = c1 * d; - out_grads[25][0] = s1 * d; - out_grads[17][1] = -s1 * d; - out_grads[25][1] = c1 * d; + outGrads[17][0] = c1 * d; + outGrads[25][0] = s1 * d; + outGrads[17][1] = -s1 * d; + outGrads[25][1] = c1 * d; d = -30.399773564 * a; - out_grads[18][2] = -c1 * d; - out_grads[24][2] = s1 * d; + outGrads[18][2] = -c1 * d; + outGrads[24][2] = s1 * d; b = z2 * (a - 0.13986014); a = b - 0.169230769 * a; d = 31.097074109 * a; - out_shs[32] = c0 * d; - out_shs[40] = s0 * d; + outSH[32] = c0 * d; + outSH[40] = s0 * d; d = 124.388296437 * a; - out_grads[32][0] = c1 * d; - out_grads[40][0] = s1 * d; - out_grads[32][1] = -s1 * d; - out_grads[40][1] = c1 * d; + outGrads[32][0] = c1 * d; + outGrads[40][0] = s1 * d; + outGrads[32][1] = -s1 * d; + outGrads[40][1] = c1 * d; d = -240.876900283 * a; - out_grads[33][2] = -c1 * d; - out_grads[39][2] = s1 * d; + outGrads[33][2] = -c1 * d; + outGrads[39][2] = s1 * d; b = z2 * a - 0.188235294 * b; a = b - 0.20123839 * a; d = 151.081370682 * a; - out_shs[51] = c0 * d; - out_shs[59] = s0 * d; + outSH[51] = c0 * d; + outSH[59] = s0 * d; d = 604.325482728 * a; - out_grads[51][0] = c1 * d; - out_grads[59][0] = s1 * d; - out_grads[51][1] = -s1 * d; - out_grads[59][1] = c1 * d; + outGrads[51][0] = c1 * d; + outGrads[59][0] = s1 * d; + outGrads[51][1] = -s1 * d; + outGrads[59][1] = c1 * d; d = -1495.629264084 * a; - out_grads[52][2] = -c1 * d; - out_grads[58][2] = s1 * d; + outGrads[52][2] = -c1 * d; + outGrads[58][2] = s1 * d; b = z2 * a - 0.210526316 * b; a = b - 0.217391304 * a; d = 686.781787352 * a; - out_shs[74] = c0 * d; - out_shs[82] = s0 * d; + outSH[74] = c0 * d; + outSH[82] = s0 * d; d = 2747.127149409 * a; - out_grads[74][0] = c1 * d; - out_grads[82][0] = s1 * d; - out_grads[74][1] = -s1 * d; - out_grads[82][1] = c1 * d; + outGrads[74][0] = c1 * d; + outGrads[82][0] = s1 * d; + outGrads[74][1] = -s1 * d; + outGrads[82][1] = c1 * d; d = -8241.381448228 * a; - out_grads[75][2] = -c1 * d; - out_grads[81][2] = s1 * d; + outGrads[75][2] = -c1 * d; + outGrads[81][2] = s1 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -2.366619162 * z; - out_shs[16] = -c1 * d; - out_shs[26] = s1 * d; + outSH[16] = -c1 * d; + outSH[26] = s1 * d; d = -11.833095811 * z; - out_grads[16][0] = -c0 * d; - out_grads[26][0] = s0 * d; - out_grads[16][1] = s0 * d; - out_grads[26][1] = c0 * d; + outGrads[16][0] = -c0 * d; + outGrads[26][0] = s0 * d; + outGrads[16][1] = s0 * d; + outGrads[26][1] = c0 * d; d = 11.100427816 * z; - out_grads[17][2] = c0 * d; - out_grads[25][2] = s0 * d; + outGrads[17][2] = c0 * d; + outGrads[25][2] = s0 * d; a = (z2 - 7.69230769e-02) * z; b = a - 0.123076923 * z; d = -17.24955311 * b; - out_shs[31] = -c1 * d; - out_shs[41] = s1 * d; + outSH[31] = -c1 * d; + outSH[41] = s1 * d; d = -86.247765552 * b; - out_grads[31][0] = -c0 * d; - out_grads[41][0] = s0 * d; - out_grads[31][1] = s0 * d; - out_grads[41][1] = c0 * d; + outGrads[31][0] = -c0 * d; + outGrads[41][0] = s0 * d; + outGrads[31][1] = s0 * d; + outGrads[41][1] = c0 * d; d = 124.388296437 * b; - out_grads[32][2] = c0 * d; - out_grads[40][2] = s0 * d; + outGrads[32][2] = c0 * d; + outGrads[40][2] = s0 * d; a = z2 * b - 0.152941176 * a; b = a - 0.173374613 * b; d = -95.552248675 * b; - out_shs[50] = -c1 * d; - out_shs[60] = s1 * d; + outSH[50] = -c1 * d; + outSH[60] = s1 * d; d = -477.761243376 * b; - out_grads[50][0] = -c0 * d; - out_grads[60][0] = s0 * d; - out_grads[50][1] = s0 * d; - out_grads[60][1] = c0 * d; + outGrads[50][0] = -c0 * d; + outGrads[60][0] = s0 * d; + outGrads[50][1] = s0 * d; + outGrads[60][1] = c0 * d; d = 906.488224092 * b; - out_grads[51][2] = c0 * d; - out_grads[59][2] = s0 * d; + outGrads[51][2] = c0 * d; + outGrads[59][2] = s0 * d; a = z2 * b - 0.187969925 * a; b = a - 0.198757764 * b; d = -471.12841933 * b; - out_shs[73] = -c1 * d; - out_shs[83] = s1 * d; + outSH[73] = -c1 * d; + outSH[83] = s1 * d; d = -2355.642096651 * b; - out_grads[73][0] = -c0 * d; - out_grads[83][0] = s0 * d; - out_grads[73][1] = s0 * d; - out_grads[83][1] = c0 * d; + outGrads[73][0] = -c0 * d; + outGrads[83][0] = s0 * d; + outGrads[73][1] = s0 * d; + outGrads[83][1] = c0 * d; d = 5494.254298819 * b; - out_grads[74][2] = c0 * d; - out_grads[82][2] = s0 * d; + outGrads[74][2] = c0 * d; + outGrads[82][2] = s0 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.683184105; - out_shs[15] = c0 * d; - out_shs[27] = s0 * d; + outSH[15] = c0 * d; + outSH[27] = s0 * d; d = 4.099104631; - out_grads[15][0] = c1 * d; - out_grads[27][0] = s1 * d; - out_grads[15][1] = -s1 * d; - out_grads[27][1] = c1 * d; + outGrads[15][0] = c1 * d; + outGrads[27][0] = s1 * d; + outGrads[15][1] = -s1 * d; + outGrads[27][1] = c1 * d; d = -2.366619162; - out_grads[16][2] = -c1 * d; - out_grads[26][2] = s1 * d; + outGrads[16][2] = -c1 * d; + outGrads[26][2] = s1 * d; a = z2 - 6.66666667e-02; d = 7.984991491 * a; - out_shs[30] = c0 * d; - out_shs[42] = s0 * d; + outSH[30] = c0 * d; + outSH[42] = s0 * d; d = 47.909948945 * a; - out_grads[30][0] = c1 * d; - out_grads[42][0] = s1 * d; - out_grads[30][1] = -s1 * d; - out_grads[42][1] = c1 * d; + outGrads[30][0] = c1 * d; + outGrads[42][0] = s1 * d; + outGrads[30][1] = -s1 * d; + outGrads[42][1] = c1 * d; d = -51.748659331 * a; - out_grads[31][2] = -c1 * d; - out_grads[41][2] = s1 * d; + outGrads[31][2] = -c1 * d; + outGrads[41][2] = s1 * d; b = z2 * (a - 0.109803922); a = b - 0.139318885 * a; d = 53.41533086 * a; - out_shs[49] = c0 * d; - out_shs[61] = s0 * d; + outSH[49] = c0 * d; + outSH[61] = s0 * d; d = 320.491985161 * a; - out_grads[49][0] = c1 * d; - out_grads[61][0] = s1 * d; - out_grads[49][1] = -s1 * d; - out_grads[61][1] = c1 * d; + outGrads[49][0] = c1 * d; + outGrads[61][0] = s1 * d; + outGrads[49][1] = -s1 * d; + outGrads[61][1] = c1 * d; d = -477.761243376 * a; - out_grads[50][2] = -c1 * d; - out_grads[60][2] = s1 * d; + outGrads[50][2] = -c1 * d; + outGrads[60][2] = s1 * d; b = z2 * a - 0.160401003 * b; a = b - 0.175983437 * a; d = 293.800188384 * a; - out_shs[72] = c0 * d; - out_shs[84] = s0 * d; + outSH[72] = c0 * d; + outSH[84] = s0 * d; d = 1762.801130306 * a; - out_grads[72][0] = c1 * d; - out_grads[84][0] = s1 * d; - out_grads[72][1] = -s1 * d; - out_grads[84][1] = c1 * d; + outGrads[72][0] = c1 * d; + outGrads[84][0] = s1 * d; + outGrads[72][1] = -s1 * d; + outGrads[84][1] = c1 * d; d = -3297.898935312 * a; - out_grads[73][2] = -c1 * d; - out_grads[83][2] = s1 * d; + outGrads[73][2] = -c1 * d; + outGrads[83][2] = s1 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -2.915706641 * z; - out_shs[29] = -c1 * d; - out_shs[43] = s1 * d; + outSH[29] = -c1 * d; + outSH[43] = s1 * d; d = -20.409946485 * z; - out_grads[29][0] = -c0 * d; - out_grads[43][0] = s0 * d; - out_grads[29][1] = s0 * d; - out_grads[43][1] = c0 * d; + outGrads[29][0] = -c0 * d; + outGrads[43][0] = s0 * d; + outGrads[29][1] = s0 * d; + outGrads[43][1] = c0 * d; d = 15.969982982 * z; - out_grads[30][2] = c0 * d; - out_grads[42][2] = s0 * d; + outGrads[30][2] = c0 * d; + outGrads[42][2] = s0 * d; a = (z2 - 5.88235294e-02) * z; b = a - 9.90712074e-02 * z; d = -25.910241313 * b; - out_shs[48] = -c1 * d; - out_shs[62] = s1 * d; + outSH[48] = -c1 * d; + outSH[62] = s1 * d; d = -181.371689194 * b; - out_grads[48][0] = -c0 * d; - out_grads[62][0] = s0 * d; - out_grads[48][1] = s0 * d; - out_grads[62][1] = c0 * d; + outGrads[48][0] = -c0 * d; + outGrads[62][0] = s0 * d; + outGrads[48][1] = s0 * d; + outGrads[62][1] = c0 * d; d = 213.661323441 * b; - out_grads[49][2] = c0 * d; - out_grads[61][2] = s0 * d; + outGrads[49][2] = c0 * d; + outGrads[61][2] = s0 * d; a = z2 * b - 0.127819549 * a; b = a - 0.149068323 * b; d = -165.101452729 * b; - out_shs[71] = -c1 * d; - out_shs[85] = s1 * d; + outSH[71] = -c1 * d; + outSH[85] = s1 * d; d = -1155.7101691 * b; - out_grads[71][0] = -c0 * d; - out_grads[85][0] = s0 * d; - out_grads[71][1] = s0 * d; - out_grads[85][1] = c0 * d; + outGrads[71][0] = -c0 * d; + outGrads[85][0] = s0 * d; + outGrads[71][1] = s0 * d; + outGrads[85][1] = c0 * d; d = 1762.801130306 * b; - out_grads[72][2] = c0 * d; - out_grads[84][2] = s0 * d; + outGrads[72][2] = c0 * d; + outGrads[84][2] = s0 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.72892666; - out_shs[28] = c0 * d; - out_shs[44] = s0 * d; + outSH[28] = c0 * d; + outSH[44] = s0 * d; d = 5.831413281; - out_grads[28][0] = c1 * d; - out_grads[44][0] = s1 * d; - out_grads[28][1] = -s1 * d; - out_grads[44][1] = c1 * d; + outGrads[28][0] = c1 * d; + outGrads[44][0] = s1 * d; + outGrads[28][1] = -s1 * d; + outGrads[44][1] = c1 * d; d = -2.915706641; - out_grads[29][2] = -c1 * d; - out_grads[43][2] = s1 * d; + outGrads[29][2] = -c1 * d; + outGrads[43][2] = s1 * d; a = z2 - 5.26315789e-02; d = 10.577811722 * a; - out_shs[47] = c0 * d; - out_shs[63] = s0 * d; + outSH[47] = c0 * d; + outSH[63] = s0 * d; d = 84.622493774 * a; - out_grads[47][0] = c1 * d; - out_grads[63][0] = s1 * d; - out_grads[47][1] = -s1 * d; - out_grads[63][1] = c1 * d; + outGrads[47][0] = c1 * d; + outGrads[63][0] = s1 * d; + outGrads[47][1] = -s1 * d; + outGrads[63][1] = c1 * d; d = -77.73072394 * a; - out_grads[48][2] = -c1 * d; - out_grads[62][2] = s1 * d; + outGrads[48][2] = -c1 * d; + outGrads[62][2] = s1 * d; b = z2 * (a - 9.02255639e-02); a = b - 0.118012422 * a; d = 82.550726364 * a; - out_shs[70] = c0 * d; - out_shs[86] = s0 * d; + outSH[70] = c0 * d; + outSH[86] = s0 * d; d = 660.405810914 * a; - out_grads[70][0] = c1 * d; - out_grads[86][0] = s1 * d; - out_grads[70][1] = -s1 * d; - out_grads[86][1] = c1 * d; + outGrads[70][0] = c1 * d; + outGrads[86][0] = s1 * d; + outGrads[70][1] = -s1 * d; + outGrads[86][1] = c1 * d; d = -825.507263643 * a; - out_grads[71][2] = -c1 * d; - out_grads[85][2] = s1 * d; + outGrads[71][2] = -c1 * d; + outGrads[85][2] = s1 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -3.4318953 * z; - out_shs[46] = -c1 * d; - out_shs[64] = s1 * d; + outSH[46] = -c1 * d; + outSH[64] = s1 * d; d = -30.887057699 * z; - out_grads[46][0] = -c0 * d; - out_grads[64][0] = s0 * d; - out_grads[46][1] = s0 * d; - out_grads[64][1] = c0 * d; + outGrads[46][0] = -c0 * d; + outGrads[64][0] = s0 * d; + outGrads[46][1] = s0 * d; + outGrads[64][1] = c0 * d; d = 21.155623443 * z; - out_grads[47][2] = c0 * d; - out_grads[63][2] = s0 * d; + outGrads[47][2] = c0 * d; + outGrads[63][2] = s0 * d; a = (z2 - 4.76190476e-02) * z; b = a - 8.2815735e-02 * z; d = -36.028090689 * b; - out_shs[69] = -c1 * d; - out_shs[87] = s1 * d; + outSH[69] = -c1 * d; + outSH[87] = s1 * d; d = -324.252816204 * b; - out_grads[69][0] = -c0 * d; - out_grads[87][0] = s0 * d; - out_grads[69][1] = s0 * d; - out_grads[87][1] = c0 * d; + outGrads[69][0] = -c0 * d; + outGrads[87][0] = s0 * d; + outGrads[69][1] = s0 * d; + outGrads[87][1] = c0 * d; d = 330.202905457 * b; - out_grads[70][2] = c0 * d; - out_grads[86][2] = s0 * d; + outGrads[70][2] = c0 * d; + outGrads[86][2] = s0 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.767395118; - out_shs[45] = c0 * d; - out_shs[65] = s0 * d; + outSH[45] = c0 * d; + outSH[65] = s0 * d; d = 7.673951182; - out_grads[45][0] = c1 * d; - out_grads[65][0] = s1 * d; - out_grads[45][1] = -s1 * d; - out_grads[65][1] = c1 * d; + outGrads[45][0] = c1 * d; + outGrads[65][0] = s1 * d; + outGrads[45][1] = -s1 * d; + outGrads[65][1] = c1 * d; d = -3.4318953; - out_grads[46][2] = -c1 * d; - out_grads[64][2] = s1 * d; + outGrads[46][2] = -c1 * d; + outGrads[64][2] = s1 * d; a = z2 - 4.34782609e-02; d = 13.3042542 * a; - out_shs[68] = c0 * d; - out_shs[88] = s0 * d; + outSH[68] = c0 * d; + outSH[88] = s0 * d; d = 133.042542003 * a; - out_grads[68][0] = c1 * d; - out_grads[88][0] = s1 * d; - out_grads[68][1] = -s1 * d; - out_grads[88][1] = c1 * d; + outGrads[68][0] = c1 * d; + outGrads[88][0] = s1 * d; + outGrads[68][1] = -s1 * d; + outGrads[88][1] = c1 * d; d = -108.084272068 * a; - out_grads[69][2] = -c1 * d; - out_grads[87][2] = s1 * d; + outGrads[69][2] = -c1 * d; + outGrads[87][2] = s1 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -3.923210529 * z; - out_shs[67] = -c1 * d; - out_shs[89] = s1 * d; + outSH[67] = -c1 * d; + outSH[89] = s1 * d; d = -43.155315818 * z; - out_grads[67][0] = -c0 * d; - out_grads[89][0] = s0 * d; - out_grads[67][1] = s0 * d; - out_grads[89][1] = c0 * d; + outGrads[67][0] = -c0 * d; + outGrads[89][0] = s0 * d; + outGrads[67][1] = s0 * d; + outGrads[89][1] = c0 * d; d = 26.608508401 * z; - out_grads[68][2] = c0 * d; - out_grads[88][2] = s0 * d; + outGrads[68][2] = c0 * d; + outGrads[88][2] = s0 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.800821996; - out_shs[66] = c0 * d; - out_shs[90] = s0 * d; + outSH[66] = c0 * d; + outSH[90] = s0 * d; d = 9.609863949; - out_grads[66][0] = c1 * d; - out_grads[90][0] = s1 * d; - out_grads[66][1] = -s1 * d; - out_grads[90][1] = c1 * d; + outGrads[66][0] = c1 * d; + outGrads[90][0] = s1 * d; + outGrads[66][1] = -s1 * d; + outGrads[90][1] = c1 * d; d = -3.923210529; - out_grads[67][2] = -c1 * d; - out_grads[89][2] = s1 * d; - out_grads[0][0] = 0.0; - out_grads[0][1] = 0.0; - out_grads[0][2] = 0.0; - out_grads[1][2] = 0.0; - out_grads[3][0] = 0.0; - out_grads[3][1] = 0.0; - out_grads[5][2] = 0.0; - out_grads[6][2] = 0.0; - out_grads[10][0] = 0.0; - out_grads[10][1] = 0.0; - out_grads[14][2] = 0.0; - out_grads[15][2] = 0.0; - out_grads[21][0] = 0.0; - out_grads[21][1] = 0.0; - out_grads[27][2] = 0.0; - out_grads[28][2] = 0.0; - out_grads[36][0] = 0.0; - out_grads[36][1] = 0.0; - out_grads[44][2] = 0.0; - out_grads[45][2] = 0.0; - out_grads[55][0] = 0.0; - out_grads[55][1] = 0.0; - out_grads[65][2] = 0.0; - out_grads[66][2] = 0.0; - out_grads[78][0] = 0.0; - out_grads[78][1] = 0.0; - out_grads[90][2] = 0.0; + outGrads[67][2] = -c1 * d; + outGrads[89][2] = s1 * d; + outGrads[0][0] = 0.0; + outGrads[0][1] = 0.0; + outGrads[0][2] = 0.0; + outGrads[1][2] = 0.0; + outGrads[3][0] = 0.0; + outGrads[3][1] = 0.0; + outGrads[5][2] = 0.0; + outGrads[6][2] = 0.0; + outGrads[10][0] = 0.0; + outGrads[10][1] = 0.0; + outGrads[14][2] = 0.0; + outGrads[15][2] = 0.0; + outGrads[21][0] = 0.0; + outGrads[21][1] = 0.0; + outGrads[27][2] = 0.0; + outGrads[28][2] = 0.0; + outGrads[36][0] = 0.0; + outGrads[36][1] = 0.0; + outGrads[44][2] = 0.0; + outGrads[45][2] = 0.0; + outGrads[55][0] = 0.0; + outGrads[55][1] = 0.0; + outGrads[65][2] = 0.0; + outGrads[66][2] = 0.0; + outGrads[78][0] = 0.0; + outGrads[78][1] = 0.0; + outGrads[90][2] = 0.0; } diff --git a/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_2.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_2.frag index 7004bd528..315b5ae0f 100644 --- a/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_2.frag +++ b/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_2.frag @@ -1,4 +1,4 @@ -void eval_sh_grad_2(out float out_shs[6], out vec3 out_grads[6], vec3 point) +void evalShGrad2(out float outSH[6], out vec3 outGrads[6], vec3 point) { float x, y, z, z2, c0, s0, c1, s1, d, a; x = point[0]; @@ -8,39 +8,39 @@ void eval_sh_grad_2(out float out_shs[6], out vec3 out_grads[6], vec3 point) c0 = 1.0; s0 = 0.0; d = 0.282094792; - out_shs[0] = d; + outSH[0] = d; a = z2 - 0.333333333; d = 0.946174696 * a; - out_shs[3] = d; + outSH[3] = d; c1 = x; s1 = y; d = -1.092548431 * z; - out_shs[2] = -c1 * d; - out_shs[4] = s1 * d; - out_grads[2][0] = -c0 * d; - out_grads[4][0] = s0 * d; - out_grads[2][1] = s0 * d; - out_grads[4][1] = c0 * d; + outSH[2] = -c1 * d; + outSH[4] = s1 * d; + outGrads[2][0] = -c0 * d; + outGrads[4][0] = s0 * d; + outGrads[2][1] = s0 * d; + outGrads[4][1] = c0 * d; d = 1.892349392 * z; - out_grads[3][2] = d; + outGrads[3][2] = d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.546274215; - out_shs[1] = c0 * d; - out_shs[5] = s0 * d; + outSH[1] = c0 * d; + outSH[5] = s0 * d; d = 1.092548431; - out_grads[1][0] = c1 * d; - out_grads[5][0] = s1 * d; - out_grads[1][1] = -s1 * d; - out_grads[5][1] = c1 * d; + outGrads[1][0] = c1 * d; + outGrads[5][0] = s1 * d; + outGrads[1][1] = -s1 * d; + outGrads[5][1] = c1 * d; d = -1.092548431; - out_grads[2][2] = -c1 * d; - out_grads[4][2] = s1 * d; - out_grads[0][0] = 0.0; - out_grads[0][1] = 0.0; - out_grads[0][2] = 0.0; - out_grads[1][2] = 0.0; - out_grads[3][0] = 0.0; - out_grads[3][1] = 0.0; - out_grads[5][2] = 0.0; + outGrads[2][2] = -c1 * d; + outGrads[4][2] = s1 * d; + outGrads[0][0] = 0.0; + outGrads[0][1] = 0.0; + outGrads[0][2] = 0.0; + outGrads[1][2] = 0.0; + outGrads[3][0] = 0.0; + outGrads[3][1] = 0.0; + outGrads[5][2] = 0.0; } diff --git a/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_4.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_4.frag index 715302f39..30b16e7a4 100644 --- a/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_4.frag +++ b/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_4.frag @@ -1,4 +1,4 @@ -void eval_sh_grad_4(out float out_shs[15], out vec3 out_grads[15], vec3 point) +void evalShGrad4(out float outSH[15], out vec3 outGrads[15], vec3 point) { float x, y, z, z2, c0, s0, c1, s1, d, a, b; x = point[0]; @@ -8,96 +8,96 @@ void eval_sh_grad_4(out float out_shs[15], out vec3 out_grads[15], vec3 point) c0 = 1.0; s0 = 0.0; d = 0.282094792; - out_shs[0] = d; + outSH[0] = d; a = z2 - 0.333333333; d = 0.946174696 * a; - out_shs[3] = d; + outSH[3] = d; b = z2 * (a - 0.266666667); a = b - 0.257142857 * a; d = 3.702494142 * a; - out_shs[10] = d; + outSH[10] = d; c1 = x; s1 = y; d = -1.092548431 * z; - out_shs[2] = -c1 * d; - out_shs[4] = s1 * d; - out_grads[2][0] = -c0 * d; - out_grads[4][0] = s0 * d; - out_grads[2][1] = s0 * d; - out_grads[4][1] = c0 * d; + outSH[2] = -c1 * d; + outSH[4] = s1 * d; + outGrads[2][0] = -c0 * d; + outGrads[4][0] = s0 * d; + outGrads[2][1] = s0 * d; + outGrads[4][1] = c0 * d; d = 1.892349392 * z; - out_grads[3][2] = d; + outGrads[3][2] = d; a = (z2 - 0.2) * z; b = a - 0.228571429 * z; d = -4.683325805 * b; - out_shs[9] = -c1 * d; - out_shs[11] = s1 * d; - out_grads[9][0] = -c0 * d; - out_grads[11][0] = s0 * d; - out_grads[9][1] = s0 * d; - out_grads[11][1] = c0 * d; + outSH[9] = -c1 * d; + outSH[11] = s1 * d; + outGrads[9][0] = -c0 * d; + outGrads[11][0] = s0 * d; + outGrads[9][1] = s0 * d; + outGrads[11][1] = c0 * d; d = 14.809976568 * b; - out_grads[10][2] = d; + outGrads[10][2] = d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.546274215; - out_shs[1] = c0 * d; - out_shs[5] = s0 * d; + outSH[1] = c0 * d; + outSH[5] = s0 * d; d = 1.092548431; - out_grads[1][0] = c1 * d; - out_grads[5][0] = s1 * d; - out_grads[1][1] = -s1 * d; - out_grads[5][1] = c1 * d; + outGrads[1][0] = c1 * d; + outGrads[5][0] = s1 * d; + outGrads[1][1] = -s1 * d; + outGrads[5][1] = c1 * d; d = -1.092548431; - out_grads[2][2] = -c1 * d; - out_grads[4][2] = s1 * d; + outGrads[2][2] = -c1 * d; + outGrads[4][2] = s1 * d; a = z2 - 0.142857143; d = 3.311611435 * a; - out_shs[8] = c0 * d; - out_shs[12] = s0 * d; + outSH[8] = c0 * d; + outSH[12] = s0 * d; d = 6.62322287 * a; - out_grads[8][0] = c1 * d; - out_grads[12][0] = s1 * d; - out_grads[8][1] = -s1 * d; - out_grads[12][1] = c1 * d; + outGrads[8][0] = c1 * d; + outGrads[12][0] = s1 * d; + outGrads[8][1] = -s1 * d; + outGrads[12][1] = c1 * d; d = -14.049977415 * a; - out_grads[9][2] = -c1 * d; - out_grads[11][2] = s1 * d; + outGrads[9][2] = -c1 * d; + outGrads[11][2] = s1 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -1.77013077 * z; - out_shs[7] = -c1 * d; - out_shs[13] = s1 * d; + outSH[7] = -c1 * d; + outSH[13] = s1 * d; d = -5.310392309 * z; - out_grads[7][0] = -c0 * d; - out_grads[13][0] = s0 * d; - out_grads[7][1] = s0 * d; - out_grads[13][1] = c0 * d; + outGrads[7][0] = -c0 * d; + outGrads[13][0] = s0 * d; + outGrads[7][1] = s0 * d; + outGrads[13][1] = c0 * d; d = 6.62322287 * z; - out_grads[8][2] = c0 * d; - out_grads[12][2] = s0 * d; + outGrads[8][2] = c0 * d; + outGrads[12][2] = s0 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.625835735; - out_shs[6] = c0 * d; - out_shs[14] = s0 * d; + outSH[6] = c0 * d; + outSH[14] = s0 * d; d = 2.503342942; - out_grads[6][0] = c1 * d; - out_grads[14][0] = s1 * d; - out_grads[6][1] = -s1 * d; - out_grads[14][1] = c1 * d; + outGrads[6][0] = c1 * d; + outGrads[14][0] = s1 * d; + outGrads[6][1] = -s1 * d; + outGrads[14][1] = c1 * d; d = -1.77013077; - out_grads[7][2] = -c1 * d; - out_grads[13][2] = s1 * d; - out_grads[0][0] = 0.0; - out_grads[0][1] = 0.0; - out_grads[0][2] = 0.0; - out_grads[1][2] = 0.0; - out_grads[3][0] = 0.0; - out_grads[3][1] = 0.0; - out_grads[5][2] = 0.0; - out_grads[6][2] = 0.0; - out_grads[10][0] = 0.0; - out_grads[10][1] = 0.0; - out_grads[14][2] = 0.0; + outGrads[7][2] = -c1 * d; + outGrads[13][2] = s1 * d; + outGrads[0][0] = 0.0; + outGrads[0][1] = 0.0; + outGrads[0][2] = 0.0; + outGrads[1][2] = 0.0; + outGrads[3][0] = 0.0; + outGrads[3][1] = 0.0; + outGrads[5][2] = 0.0; + outGrads[6][2] = 0.0; + outGrads[10][0] = 0.0; + outGrads[10][1] = 0.0; + outGrads[14][2] = 0.0; } diff --git a/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_6.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_6.frag index fa240c3a5..95970b168 100644 --- a/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_6.frag +++ b/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_6.frag @@ -1,4 +1,4 @@ -void eval_sh_grad_6(out float out_shs[28], out vec3 out_grads[28], vec3 point) +void evalShGrad6(out float outSH[28], out vec3 outGrads[28], vec3 point) { float x, y, z, z2, c0, s0, c1, s1, d, a, b; x = point[0]; @@ -8,179 +8,179 @@ void eval_sh_grad_6(out float out_shs[28], out vec3 out_grads[28], vec3 point) c0 = 1.0; s0 = 0.0; d = 0.282094792; - out_shs[0] = d; + outSH[0] = d; a = z2 - 0.333333333; d = 0.946174696 * a; - out_shs[3] = d; + outSH[3] = d; b = z2 * (a - 0.266666667); a = b - 0.257142857 * a; d = 3.702494142 * a; - out_shs[10] = d; + outSH[10] = d; b = z2 * a - 0.253968254 * b; a = b - 0.252525253 * a; d = 14.684485724 * a; - out_shs[21] = d; + outSH[21] = d; c1 = x; s1 = y; d = -1.092548431 * z; - out_shs[2] = -c1 * d; - out_shs[4] = s1 * d; - out_grads[2][0] = -c0 * d; - out_grads[4][0] = s0 * d; - out_grads[2][1] = s0 * d; - out_grads[4][1] = c0 * d; + outSH[2] = -c1 * d; + outSH[4] = s1 * d; + outGrads[2][0] = -c0 * d; + outGrads[4][0] = s0 * d; + outGrads[2][1] = s0 * d; + outGrads[4][1] = c0 * d; d = 1.892349392 * z; - out_grads[3][2] = d; + outGrads[3][2] = d; a = (z2 - 0.2) * z; b = a - 0.228571429 * z; d = -4.683325805 * b; - out_shs[9] = -c1 * d; - out_shs[11] = s1 * d; - out_grads[9][0] = -c0 * d; - out_grads[11][0] = s0 * d; - out_grads[9][1] = s0 * d; - out_grads[11][1] = c0 * d; + outSH[9] = -c1 * d; + outSH[11] = s1 * d; + outGrads[9][0] = -c0 * d; + outGrads[11][0] = s0 * d; + outGrads[9][1] = s0 * d; + outGrads[11][1] = c0 * d; d = 14.809976568 * b; - out_grads[10][2] = d; + outGrads[10][2] = d; a = z2 * b - 0.238095238 * a; b = a - 0.242424242 * b; d = -19.226504963 * b; - out_shs[20] = -c1 * d; - out_shs[22] = s1 * d; - out_grads[20][0] = -c0 * d; - out_grads[22][0] = s0 * d; - out_grads[20][1] = s0 * d; - out_grads[22][1] = c0 * d; + outSH[20] = -c1 * d; + outSH[22] = s1 * d; + outGrads[20][0] = -c0 * d; + outGrads[22][0] = s0 * d; + outGrads[20][1] = s0 * d; + outGrads[22][1] = c0 * d; d = 88.106914343 * b; - out_grads[21][2] = d; + outGrads[21][2] = d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.546274215; - out_shs[1] = c0 * d; - out_shs[5] = s0 * d; + outSH[1] = c0 * d; + outSH[5] = s0 * d; d = 1.092548431; - out_grads[1][0] = c1 * d; - out_grads[5][0] = s1 * d; - out_grads[1][1] = -s1 * d; - out_grads[5][1] = c1 * d; + outGrads[1][0] = c1 * d; + outGrads[5][0] = s1 * d; + outGrads[1][1] = -s1 * d; + outGrads[5][1] = c1 * d; d = -1.092548431; - out_grads[2][2] = -c1 * d; - out_grads[4][2] = s1 * d; + outGrads[2][2] = -c1 * d; + outGrads[4][2] = s1 * d; a = z2 - 0.142857143; d = 3.311611435 * a; - out_shs[8] = c0 * d; - out_shs[12] = s0 * d; + outSH[8] = c0 * d; + outSH[12] = s0 * d; d = 6.62322287 * a; - out_grads[8][0] = c1 * d; - out_grads[12][0] = s1 * d; - out_grads[8][1] = -s1 * d; - out_grads[12][1] = c1 * d; + outGrads[8][0] = c1 * d; + outGrads[12][0] = s1 * d; + outGrads[8][1] = -s1 * d; + outGrads[12][1] = c1 * d; d = -14.049977415 * a; - out_grads[9][2] = -c1 * d; - out_grads[11][2] = s1 * d; + outGrads[9][2] = -c1 * d; + outGrads[11][2] = s1 * d; b = z2 * (a - 0.19047619); a = b - 0.212121212 * a; d = 15.199886782 * a; - out_shs[19] = c0 * d; - out_shs[23] = s0 * d; + outSH[19] = c0 * d; + outSH[23] = s0 * d; d = 30.399773564 * a; - out_grads[19][0] = c1 * d; - out_grads[23][0] = s1 * d; - out_grads[19][1] = -s1 * d; - out_grads[23][1] = c1 * d; + outGrads[19][0] = c1 * d; + outGrads[23][0] = s1 * d; + outGrads[19][1] = -s1 * d; + outGrads[23][1] = c1 * d; d = -96.132524816 * a; - out_grads[20][2] = -c1 * d; - out_grads[22][2] = s1 * d; + outGrads[20][2] = -c1 * d; + outGrads[22][2] = s1 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -1.77013077 * z; - out_shs[7] = -c1 * d; - out_shs[13] = s1 * d; + outSH[7] = -c1 * d; + outSH[13] = s1 * d; d = -5.310392309 * z; - out_grads[7][0] = -c0 * d; - out_grads[13][0] = s0 * d; - out_grads[7][1] = s0 * d; - out_grads[13][1] = c0 * d; + outGrads[7][0] = -c0 * d; + outGrads[13][0] = s0 * d; + outGrads[7][1] = s0 * d; + outGrads[13][1] = c0 * d; d = 6.62322287 * z; - out_grads[8][2] = c0 * d; - out_grads[12][2] = s0 * d; + outGrads[8][2] = c0 * d; + outGrads[12][2] = s0 * d; a = (z2 - 0.111111111) * z; b = a - 0.161616162 * z; d = -10.133257855 * b; - out_shs[18] = -c1 * d; - out_shs[24] = s1 * d; + outSH[18] = -c1 * d; + outSH[24] = s1 * d; d = -30.399773564 * b; - out_grads[18][0] = -c0 * d; - out_grads[24][0] = s0 * d; - out_grads[18][1] = s0 * d; - out_grads[24][1] = c0 * d; + outGrads[18][0] = -c0 * d; + outGrads[24][0] = s0 * d; + outGrads[18][1] = s0 * d; + outGrads[24][1] = c0 * d; d = 60.799547128 * b; - out_grads[19][2] = c0 * d; - out_grads[23][2] = s0 * d; + outGrads[19][2] = c0 * d; + outGrads[23][2] = s0 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.625835735; - out_shs[6] = c0 * d; - out_shs[14] = s0 * d; + outSH[6] = c0 * d; + outSH[14] = s0 * d; d = 2.503342942; - out_grads[6][0] = c1 * d; - out_grads[14][0] = s1 * d; - out_grads[6][1] = -s1 * d; - out_grads[14][1] = c1 * d; + outGrads[6][0] = c1 * d; + outGrads[14][0] = s1 * d; + outGrads[6][1] = -s1 * d; + outGrads[14][1] = c1 * d; d = -1.77013077; - out_grads[7][2] = -c1 * d; - out_grads[13][2] = s1 * d; + outGrads[7][2] = -c1 * d; + outGrads[13][2] = s1 * d; a = z2 - 9.09090909e-02; d = 5.550213908 * a; - out_shs[17] = c0 * d; - out_shs[25] = s0 * d; + outSH[17] = c0 * d; + outSH[25] = s0 * d; d = 22.200855632 * a; - out_grads[17][0] = c1 * d; - out_grads[25][0] = s1 * d; - out_grads[17][1] = -s1 * d; - out_grads[25][1] = c1 * d; + outGrads[17][0] = c1 * d; + outGrads[25][0] = s1 * d; + outGrads[17][1] = -s1 * d; + outGrads[25][1] = c1 * d; d = -30.399773564 * a; - out_grads[18][2] = -c1 * d; - out_grads[24][2] = s1 * d; + outGrads[18][2] = -c1 * d; + outGrads[24][2] = s1 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -2.366619162 * z; - out_shs[16] = -c1 * d; - out_shs[26] = s1 * d; + outSH[16] = -c1 * d; + outSH[26] = s1 * d; d = -11.833095811 * z; - out_grads[16][0] = -c0 * d; - out_grads[26][0] = s0 * d; - out_grads[16][1] = s0 * d; - out_grads[26][1] = c0 * d; + outGrads[16][0] = -c0 * d; + outGrads[26][0] = s0 * d; + outGrads[16][1] = s0 * d; + outGrads[26][1] = c0 * d; d = 11.100427816 * z; - out_grads[17][2] = c0 * d; - out_grads[25][2] = s0 * d; + outGrads[17][2] = c0 * d; + outGrads[25][2] = s0 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.683184105; - out_shs[15] = c0 * d; - out_shs[27] = s0 * d; + outSH[15] = c0 * d; + outSH[27] = s0 * d; d = 4.099104631; - out_grads[15][0] = c1 * d; - out_grads[27][0] = s1 * d; - out_grads[15][1] = -s1 * d; - out_grads[27][1] = c1 * d; + outGrads[15][0] = c1 * d; + outGrads[27][0] = s1 * d; + outGrads[15][1] = -s1 * d; + outGrads[27][1] = c1 * d; d = -2.366619162; - out_grads[16][2] = -c1 * d; - out_grads[26][2] = s1 * d; - out_grads[0][0] = 0.0; - out_grads[0][1] = 0.0; - out_grads[0][2] = 0.0; - out_grads[1][2] = 0.0; - out_grads[3][0] = 0.0; - out_grads[3][1] = 0.0; - out_grads[5][2] = 0.0; - out_grads[6][2] = 0.0; - out_grads[10][0] = 0.0; - out_grads[10][1] = 0.0; - out_grads[14][2] = 0.0; - out_grads[15][2] = 0.0; - out_grads[21][0] = 0.0; - out_grads[21][1] = 0.0; - out_grads[27][2] = 0.0; + outGrads[16][2] = -c1 * d; + outGrads[26][2] = s1 * d; + outGrads[0][0] = 0.0; + outGrads[0][1] = 0.0; + outGrads[0][2] = 0.0; + outGrads[1][2] = 0.0; + outGrads[3][0] = 0.0; + outGrads[3][1] = 0.0; + outGrads[5][2] = 0.0; + outGrads[6][2] = 0.0; + outGrads[10][0] = 0.0; + outGrads[10][1] = 0.0; + outGrads[14][2] = 0.0; + outGrads[15][2] = 0.0; + outGrads[21][0] = 0.0; + outGrads[21][1] = 0.0; + outGrads[27][2] = 0.0; } diff --git a/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_8.frag b/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_8.frag index b0a40d0a7..9e788bd24 100644 --- a/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_8.frag +++ b/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_8.frag @@ -1,4 +1,4 @@ -void eval_sh_grad_8(out float out_shs[45], out vec3 out_grads[45], vec3 point) +void evalShGrad8(out float outSH[45], out vec3 outGrads[45], vec3 point) { float x, y, z, z2, c0, s0, c1, s1, d, a, b; x = point[0]; @@ -8,288 +8,288 @@ void eval_sh_grad_8(out float out_shs[45], out vec3 out_grads[45], vec3 point) c0 = 1.0; s0 = 0.0; d = 0.282094792; - out_shs[0] = d; + outSH[0] = d; a = z2 - 0.333333333; d = 0.946174696 * a; - out_shs[3] = d; + outSH[3] = d; b = z2 * (a - 0.266666667); a = b - 0.257142857 * a; d = 3.702494142 * a; - out_shs[10] = d; + outSH[10] = d; b = z2 * a - 0.253968254 * b; a = b - 0.252525253 * a; d = 14.684485724 * a; - out_shs[21] = d; + outSH[21] = d; b = z2 * a - 0.251748252 * b; a = b - 0.251282051 * a; d = 58.473368113 * a; - out_shs[36] = d; + outSH[36] = d; c1 = x; s1 = y; d = -1.092548431 * z; - out_shs[2] = -c1 * d; - out_shs[4] = s1 * d; - out_grads[2][0] = -c0 * d; - out_grads[4][0] = s0 * d; - out_grads[2][1] = s0 * d; - out_grads[4][1] = c0 * d; + outSH[2] = -c1 * d; + outSH[4] = s1 * d; + outGrads[2][0] = -c0 * d; + outGrads[4][0] = s0 * d; + outGrads[2][1] = s0 * d; + outGrads[4][1] = c0 * d; d = 1.892349392 * z; - out_grads[3][2] = d; + outGrads[3][2] = d; a = (z2 - 0.2) * z; b = a - 0.228571429 * z; d = -4.683325805 * b; - out_shs[9] = -c1 * d; - out_shs[11] = s1 * d; - out_grads[9][0] = -c0 * d; - out_grads[11][0] = s0 * d; - out_grads[9][1] = s0 * d; - out_grads[11][1] = c0 * d; + outSH[9] = -c1 * d; + outSH[11] = s1 * d; + outGrads[9][0] = -c0 * d; + outGrads[11][0] = s0 * d; + outGrads[9][1] = s0 * d; + outGrads[11][1] = c0 * d; d = 14.809976568 * b; - out_grads[10][2] = d; + outGrads[10][2] = d; a = z2 * b - 0.238095238 * a; b = a - 0.242424242 * b; d = -19.226504963 * b; - out_shs[20] = -c1 * d; - out_shs[22] = s1 * d; - out_grads[20][0] = -c0 * d; - out_grads[22][0] = s0 * d; - out_grads[20][1] = s0 * d; - out_grads[22][1] = c0 * d; + outSH[20] = -c1 * d; + outSH[22] = s1 * d; + outGrads[20][0] = -c0 * d; + outGrads[22][0] = s0 * d; + outGrads[20][1] = s0 * d; + outGrads[22][1] = c0 * d; d = 88.106914343 * b; - out_grads[21][2] = d; + outGrads[21][2] = d; a = z2 * b - 0.244755245 * a; b = a - 0.246153846 * b; d = -77.964490818 * b; - out_shs[35] = -c1 * d; - out_shs[37] = s1 * d; - out_grads[35][0] = -c0 * d; - out_grads[37][0] = s0 * d; - out_grads[35][1] = s0 * d; - out_grads[37][1] = c0 * d; + outSH[35] = -c1 * d; + outSH[37] = s1 * d; + outGrads[35][0] = -c0 * d; + outGrads[37][0] = s0 * d; + outGrads[35][1] = s0 * d; + outGrads[37][1] = c0 * d; d = 467.786944906 * b; - out_grads[36][2] = d; + outGrads[36][2] = d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.546274215; - out_shs[1] = c0 * d; - out_shs[5] = s0 * d; + outSH[1] = c0 * d; + outSH[5] = s0 * d; d = 1.092548431; - out_grads[1][0] = c1 * d; - out_grads[5][0] = s1 * d; - out_grads[1][1] = -s1 * d; - out_grads[5][1] = c1 * d; + outGrads[1][0] = c1 * d; + outGrads[5][0] = s1 * d; + outGrads[1][1] = -s1 * d; + outGrads[5][1] = c1 * d; d = -1.092548431; - out_grads[2][2] = -c1 * d; - out_grads[4][2] = s1 * d; + outGrads[2][2] = -c1 * d; + outGrads[4][2] = s1 * d; a = z2 - 0.142857143; d = 3.311611435 * a; - out_shs[8] = c0 * d; - out_shs[12] = s0 * d; + outSH[8] = c0 * d; + outSH[12] = s0 * d; d = 6.62322287 * a; - out_grads[8][0] = c1 * d; - out_grads[12][0] = s1 * d; - out_grads[8][1] = -s1 * d; - out_grads[12][1] = c1 * d; + outGrads[8][0] = c1 * d; + outGrads[12][0] = s1 * d; + outGrads[8][1] = -s1 * d; + outGrads[12][1] = c1 * d; d = -14.049977415 * a; - out_grads[9][2] = -c1 * d; - out_grads[11][2] = s1 * d; + outGrads[9][2] = -c1 * d; + outGrads[11][2] = s1 * d; b = z2 * (a - 0.19047619); a = b - 0.212121212 * a; d = 15.199886782 * a; - out_shs[19] = c0 * d; - out_shs[23] = s0 * d; + outSH[19] = c0 * d; + outSH[23] = s0 * d; d = 30.399773564 * a; - out_grads[19][0] = c1 * d; - out_grads[23][0] = s1 * d; - out_grads[19][1] = -s1 * d; - out_grads[23][1] = c1 * d; + outGrads[19][0] = c1 * d; + outGrads[23][0] = s1 * d; + outGrads[19][1] = -s1 * d; + outGrads[23][1] = c1 * d; d = -96.132524816 * a; - out_grads[20][2] = -c1 * d; - out_grads[22][2] = s1 * d; + outGrads[20][2] = -c1 * d; + outGrads[22][2] = s1 * d; b = z2 * a - 0.223776224 * b; a = b - 0.230769231 * a; d = 65.229772956 * a; - out_shs[34] = c0 * d; - out_shs[38] = s0 * d; + outSH[34] = c0 * d; + outSH[38] = s0 * d; d = 130.459545912 * a; - out_grads[34][0] = c1 * d; - out_grads[38][0] = s1 * d; - out_grads[34][1] = -s1 * d; - out_grads[38][1] = c1 * d; + outGrads[34][0] = c1 * d; + outGrads[38][0] = s1 * d; + outGrads[34][1] = -s1 * d; + outGrads[38][1] = c1 * d; d = -545.751435723 * a; - out_grads[35][2] = -c1 * d; - out_grads[37][2] = s1 * d; + outGrads[35][2] = -c1 * d; + outGrads[37][2] = s1 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -1.77013077 * z; - out_shs[7] = -c1 * d; - out_shs[13] = s1 * d; + outSH[7] = -c1 * d; + outSH[13] = s1 * d; d = -5.310392309 * z; - out_grads[7][0] = -c0 * d; - out_grads[13][0] = s0 * d; - out_grads[7][1] = s0 * d; - out_grads[13][1] = c0 * d; + outGrads[7][0] = -c0 * d; + outGrads[13][0] = s0 * d; + outGrads[7][1] = s0 * d; + outGrads[13][1] = c0 * d; d = 6.62322287 * z; - out_grads[8][2] = c0 * d; - out_grads[12][2] = s0 * d; + outGrads[8][2] = c0 * d; + outGrads[12][2] = s0 * d; a = (z2 - 0.111111111) * z; b = a - 0.161616162 * z; d = -10.133257855 * b; - out_shs[18] = -c1 * d; - out_shs[24] = s1 * d; + outSH[18] = -c1 * d; + outSH[24] = s1 * d; d = -30.399773564 * b; - out_grads[18][0] = -c0 * d; - out_grads[24][0] = s0 * d; - out_grads[18][1] = s0 * d; - out_grads[24][1] = c0 * d; + outGrads[18][0] = -c0 * d; + outGrads[24][0] = s0 * d; + outGrads[18][1] = s0 * d; + outGrads[24][1] = c0 * d; d = 60.799547128 * b; - out_grads[19][2] = c0 * d; - out_grads[23][2] = s0 * d; + outGrads[19][2] = c0 * d; + outGrads[23][2] = s0 * d; a = z2 * b - 0.188811189 * a; b = a - 0.205128205 * b; d = -48.175380057 * b; - out_shs[33] = -c1 * d; - out_shs[39] = s1 * d; + outSH[33] = -c1 * d; + outSH[39] = s1 * d; d = -144.52614017 * b; - out_grads[33][0] = -c0 * d; - out_grads[39][0] = s0 * d; - out_grads[33][1] = s0 * d; - out_grads[39][1] = c0 * d; + outGrads[33][0] = -c0 * d; + outGrads[39][0] = s0 * d; + outGrads[33][1] = s0 * d; + outGrads[39][1] = c0 * d; d = 391.378637737 * b; - out_grads[34][2] = c0 * d; - out_grads[38][2] = s0 * d; + outGrads[34][2] = c0 * d; + outGrads[38][2] = s0 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.625835735; - out_shs[6] = c0 * d; - out_shs[14] = s0 * d; + outSH[6] = c0 * d; + outSH[14] = s0 * d; d = 2.503342942; - out_grads[6][0] = c1 * d; - out_grads[14][0] = s1 * d; - out_grads[6][1] = -s1 * d; - out_grads[14][1] = c1 * d; + outGrads[6][0] = c1 * d; + outGrads[14][0] = s1 * d; + outGrads[6][1] = -s1 * d; + outGrads[14][1] = c1 * d; d = -1.77013077; - out_grads[7][2] = -c1 * d; - out_grads[13][2] = s1 * d; + outGrads[7][2] = -c1 * d; + outGrads[13][2] = s1 * d; a = z2 - 9.09090909e-02; d = 5.550213908 * a; - out_shs[17] = c0 * d; - out_shs[25] = s0 * d; + outSH[17] = c0 * d; + outSH[25] = s0 * d; d = 22.200855632 * a; - out_grads[17][0] = c1 * d; - out_grads[25][0] = s1 * d; - out_grads[17][1] = -s1 * d; - out_grads[25][1] = c1 * d; + outGrads[17][0] = c1 * d; + outGrads[25][0] = s1 * d; + outGrads[17][1] = -s1 * d; + outGrads[25][1] = c1 * d; d = -30.399773564 * a; - out_grads[18][2] = -c1 * d; - out_grads[24][2] = s1 * d; + outGrads[18][2] = -c1 * d; + outGrads[24][2] = s1 * d; b = z2 * (a - 0.13986014); a = b - 0.169230769 * a; d = 31.097074109 * a; - out_shs[32] = c0 * d; - out_shs[40] = s0 * d; + outSH[32] = c0 * d; + outSH[40] = s0 * d; d = 124.388296437 * a; - out_grads[32][0] = c1 * d; - out_grads[40][0] = s1 * d; - out_grads[32][1] = -s1 * d; - out_grads[40][1] = c1 * d; + outGrads[32][0] = c1 * d; + outGrads[40][0] = s1 * d; + outGrads[32][1] = -s1 * d; + outGrads[40][1] = c1 * d; d = -240.876900283 * a; - out_grads[33][2] = -c1 * d; - out_grads[39][2] = s1 * d; + outGrads[33][2] = -c1 * d; + outGrads[39][2] = s1 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -2.366619162 * z; - out_shs[16] = -c1 * d; - out_shs[26] = s1 * d; + outSH[16] = -c1 * d; + outSH[26] = s1 * d; d = -11.833095811 * z; - out_grads[16][0] = -c0 * d; - out_grads[26][0] = s0 * d; - out_grads[16][1] = s0 * d; - out_grads[26][1] = c0 * d; + outGrads[16][0] = -c0 * d; + outGrads[26][0] = s0 * d; + outGrads[16][1] = s0 * d; + outGrads[26][1] = c0 * d; d = 11.100427816 * z; - out_grads[17][2] = c0 * d; - out_grads[25][2] = s0 * d; + outGrads[17][2] = c0 * d; + outGrads[25][2] = s0 * d; a = (z2 - 7.69230769e-02) * z; b = a - 0.123076923 * z; d = -17.24955311 * b; - out_shs[31] = -c1 * d; - out_shs[41] = s1 * d; + outSH[31] = -c1 * d; + outSH[41] = s1 * d; d = -86.247765552 * b; - out_grads[31][0] = -c0 * d; - out_grads[41][0] = s0 * d; - out_grads[31][1] = s0 * d; - out_grads[41][1] = c0 * d; + outGrads[31][0] = -c0 * d; + outGrads[41][0] = s0 * d; + outGrads[31][1] = s0 * d; + outGrads[41][1] = c0 * d; d = 124.388296437 * b; - out_grads[32][2] = c0 * d; - out_grads[40][2] = s0 * d; + outGrads[32][2] = c0 * d; + outGrads[40][2] = s0 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.683184105; - out_shs[15] = c0 * d; - out_shs[27] = s0 * d; + outSH[15] = c0 * d; + outSH[27] = s0 * d; d = 4.099104631; - out_grads[15][0] = c1 * d; - out_grads[27][0] = s1 * d; - out_grads[15][1] = -s1 * d; - out_grads[27][1] = c1 * d; + outGrads[15][0] = c1 * d; + outGrads[27][0] = s1 * d; + outGrads[15][1] = -s1 * d; + outGrads[27][1] = c1 * d; d = -2.366619162; - out_grads[16][2] = -c1 * d; - out_grads[26][2] = s1 * d; + outGrads[16][2] = -c1 * d; + outGrads[26][2] = s1 * d; a = z2 - 6.66666667e-02; d = 7.984991491 * a; - out_shs[30] = c0 * d; - out_shs[42] = s0 * d; + outSH[30] = c0 * d; + outSH[42] = s0 * d; d = 47.909948945 * a; - out_grads[30][0] = c1 * d; - out_grads[42][0] = s1 * d; - out_grads[30][1] = -s1 * d; - out_grads[42][1] = c1 * d; + outGrads[30][0] = c1 * d; + outGrads[42][0] = s1 * d; + outGrads[30][1] = -s1 * d; + outGrads[42][1] = c1 * d; d = -51.748659331 * a; - out_grads[31][2] = -c1 * d; - out_grads[41][2] = s1 * d; + outGrads[31][2] = -c1 * d; + outGrads[41][2] = s1 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -2.915706641 * z; - out_shs[29] = -c1 * d; - out_shs[43] = s1 * d; + outSH[29] = -c1 * d; + outSH[43] = s1 * d; d = -20.409946485 * z; - out_grads[29][0] = -c0 * d; - out_grads[43][0] = s0 * d; - out_grads[29][1] = s0 * d; - out_grads[43][1] = c0 * d; + outGrads[29][0] = -c0 * d; + outGrads[43][0] = s0 * d; + outGrads[29][1] = s0 * d; + outGrads[43][1] = c0 * d; d = 15.969982982 * z; - out_grads[30][2] = c0 * d; - out_grads[42][2] = s0 * d; + outGrads[30][2] = c0 * d; + outGrads[42][2] = s0 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.72892666; - out_shs[28] = c0 * d; - out_shs[44] = s0 * d; + outSH[28] = c0 * d; + outSH[44] = s0 * d; d = 5.831413281; - out_grads[28][0] = c1 * d; - out_grads[44][0] = s1 * d; - out_grads[28][1] = -s1 * d; - out_grads[44][1] = c1 * d; + outGrads[28][0] = c1 * d; + outGrads[44][0] = s1 * d; + outGrads[28][1] = -s1 * d; + outGrads[44][1] = c1 * d; d = -2.915706641; - out_grads[29][2] = -c1 * d; - out_grads[43][2] = s1 * d; - out_grads[0][0] = 0.0; - out_grads[0][1] = 0.0; - out_grads[0][2] = 0.0; - out_grads[1][2] = 0.0; - out_grads[3][0] = 0.0; - out_grads[3][1] = 0.0; - out_grads[5][2] = 0.0; - out_grads[6][2] = 0.0; - out_grads[10][0] = 0.0; - out_grads[10][1] = 0.0; - out_grads[14][2] = 0.0; - out_grads[15][2] = 0.0; - out_grads[21][0] = 0.0; - out_grads[21][1] = 0.0; - out_grads[27][2] = 0.0; - out_grads[28][2] = 0.0; - out_grads[36][0] = 0.0; - out_grads[36][1] = 0.0; - out_grads[44][2] = 0.0; + outGrads[29][2] = -c1 * d; + outGrads[43][2] = s1 * d; + outGrads[0][0] = 0.0; + outGrads[0][1] = 0.0; + outGrads[0][2] = 0.0; + outGrads[1][2] = 0.0; + outGrads[3][0] = 0.0; + outGrads[3][1] = 0.0; + outGrads[5][2] = 0.0; + outGrads[6][2] = 0.0; + outGrads[10][0] = 0.0; + outGrads[10][1] = 0.0; + outGrads[14][2] = 0.0; + outGrads[15][2] = 0.0; + outGrads[21][0] = 0.0; + outGrads[21][1] = 0.0; + outGrads[27][2] = 0.0; + outGrads[28][2] = 0.0; + outGrads[36][0] = 0.0; + outGrads[36][1] = 0.0; + outGrads[44][2] = 0.0; } diff --git a/fury/shaders/rt_odfs/eval_sh.frag b/fury/shaders/rt_odfs/eval_sh.frag index e3810af25..fac4b17d8 100644 --- a/fury/shaders/rt_odfs/eval_sh.frag +++ b/fury/shaders/rt_odfs/eval_sh.frag @@ -1,16 +1,58 @@ -void eval_sh(out float out_shs[SH_COUNT], vec3 point) -{ - #if SH_DEGREE == 2 - eval_sh_2(out_shs, point); - #elif SH_DEGREE == 4 - eval_sh_4(out_shs, point); - #elif SH_DEGREE == 6 - eval_sh_6(out_shs, point); - #elif SH_DEGREE == 8 - eval_sh_8(out_shs, point); - #elif SH_DEGREE == 10 - eval_sh_10(out_shs, point); - #elif SH_DEGREE == 12 - eval_sh_12(out_shs, point); - #endif -} +void evalSH(out float outSH[SH_COUNT], vec3 point, int shDegree, + int numCoeffs) + { + if (shDegree == 2) + { + float tmpOutSH[6]; + #if SH_DEGREE == 2 + evalSH2(tmpOutSH, point); + #endif + for (int i = 0; i != numCoeffs; ++i) + outSH[i] = tmpOutSH[i]; + } + else if (shDegree == 4) + { + float tmpOutSH[15]; + #if SH_DEGREE == 4 + evalSH4(tmpOutSH, point); + #endif + for (int i = 0; i != numCoeffs; ++i) + outSH[i] = tmpOutSH[i]; + } + else if (shDegree == 6) + { + float tmpOutSH[28]; + #if SH_DEGREE == 6 + evalSH6(tmpOutSH, point); + #endif + for (int i = 0; i != numCoeffs; ++i) + outSH[i] = tmpOutSH[i]; + } + else if (shDegree == 8) + { + float tmpOutSH[45]; + #if SH_DEGREE == 8 + evalSH8(tmpOutSH, point); + #endif + for (int i = 0; i != numCoeffs; ++i) + outSH[i] = tmpOutSH[i]; + } + else if (shDegree == 10) + { + float tmpOutSH[66]; + #if SH_DEGREE == 10 + evalSH10(tmpOutSH, point); + #endif + for (int i = 0; i != numCoeffs; ++i) + outSH[i] = tmpOutSH[i]; + } + else if (shDegree == 12) + { + float tmpOutSH[91]; + #if SH_DEGREE == 12 + evalSH12(tmpOutSH, point); + #endif + for (int i = 0; i != numCoeffs; ++i) + outSH[i] = tmpOutSH[i]; + } + } \ No newline at end of file diff --git a/fury/shaders/rt_odfs/eval_sh_grad.frag b/fury/shaders/rt_odfs/eval_sh_grad.frag index c318dbd6c..cfb3fc862 100644 --- a/fury/shaders/rt_odfs/eval_sh_grad.frag +++ b/fury/shaders/rt_odfs/eval_sh_grad.frag @@ -1,16 +1,60 @@ -void eval_sh_grad(out float out_shs[SH_COUNT], out vec3 out_grads[SH_COUNT], vec3 point) +void evalShGrad(out float outSH[SH_COUNT], out vec3 outGrads[SH_COUNT], vec3 point, int shDegree, + int numCoeffs) { - #if SH_DEGREE == 2 - eval_sh_grad_2(out_shs, out_grads, point); - #elif SH_DEGREE == 4 - eval_sh_grad_4(out_shs, out_grads, point); - #elif SH_DEGREE == 6 - eval_sh_grad_6(out_shs, out_grads, point); - #elif SH_DEGREE == 8 - eval_sh_grad_8(out_shs, out_grads, point); - #elif SH_DEGREE == 10 - eval_sh_grad_10(out_shs, out_grads, point); - #elif SH_DEGREE == 12 - eval_sh_grad_12(out_shs, out_grads, point); - #endif + if (shDegree == 2) + { + float tmpOutSH[6]; + float tmpOutGrads[6]; + #if SH_DEGREE == 2 + evalShGrad2(tmpOutSH, outGrads, point); + #endif + for (int i = 0; i != numCoeffs; ++i) + outSH[i] = tmpOutSH[i]; + + } + else if (shDegree == 4) + { + float tmpOutSH[15]; + #if SH_DEGREE == 4 + evalShGrad4(tmpOutSH, outGrads, point); + #endif + for (int i = 0; i != numCoeffs; ++i) + outSH[i] = tmpOutSH[i]; + } + else if (shDegree == 6) + { + float tmpOutSH[28]; + #if SH_DEGREE == 6 + evalShGrad6(tmpOutSH, outGrads, point); + #endif + for (int i = 0; i != numCoeffs; ++i) + outSH[i] = tmpOutSH[i]; + } + else if (shDegree == 8) + { + float tmpOutSH[45]; + #if SH_DEGREE == 8 + evalShGrad8(tmpOutSH, outGrads, point); + #endif + for (int i = 0; i != numCoeffs; ++i) + outSH[i] = tmpOutSH[i]; + } + else if (shDegree == 10) + { + float tmpOutSH[66]; + #if SH_DEGREE == 10 + evalShGrad10(tmpOutSH, outGrads, point); + #endif + for (int i = 0; i != numCoeffs; ++i) + outSH[i] = tmpOutSH[i]; + } + else if (shDegree == 12) + { + float tmpOutSH[91]; + #if SH_DEGREE == 12 + evalShGrad12(tmpOutSH, outGrads, point); + #endif + for (int i = 0; i != numCoeffs; ++i) + outSH[i] = tmpOutSH[i]; + } } diff --git a/fury/shaders/rt_odfs/get_inv_vandermonde.frag b/fury/shaders/rt_odfs/get_inv_vandermonde.frag index 4c7f521c0..988cd5783 100644 --- a/fury/shaders/rt_odfs/get_inv_vandermonde.frag +++ b/fury/shaders/rt_odfs/get_inv_vandermonde.frag @@ -1,58 +1,93 @@ -void get_inv_vandermonde(out float v[(SH_DEGREE + 1) * (SH_DEGREE + 1)]) +void getInvVandermonde(out float v[(SH_DEGREE + 1) * (SH_DEGREE + 1)], int shDegree) { - #if SH_DEGREE == 2 - v[0*3 + 0] = -0.3333333333; v[0*3 + 1] = 0.6666666667; v[0*3 + 2] = 0.6666666667; - v[1*3 + 0] = -0.0; v[1*3 + 1] = 1.1547005384; v[1*3 + 2] = -1.1547005384; - v[2*3 + 0] = 1.0; v[2*3 + 1] = 0.0; v[2*3 + 2] = 0.0; - #elif SH_DEGREE == 4 - v[0*5 + 0] = 0.2; v[0*5 + 1] = -0.2472135955; v[0*5 + 2] = 0.6472135955; v[0*5 + 3] = 0.6472135955; v[0*5 + 4] = -0.2472135955; - v[1*5 + 0] = 0.0; v[1*5 + 1] = -0.1796111906; v[1*5 + 2] = 1.9919186279; v[1*5 + 3] = -1.9919186279; v[1*5 + 4] = 0.1796111906; - v[2*5 + 0] = -2.0; v[2*5 + 1] = 2.3416407865; v[2*5 + 2] = -0.3416407865; v[2*5 + 3] = -0.3416407865; v[2*5 + 4] = 2.3416407865; - v[3*5 + 0] = -0.0; v[3*5 + 1] = 1.7013016167; v[3*5 + 2] = -1.0514622242; v[3*5 + 3] = 1.0514622242; v[3*5 + 4] = -1.7013016167; - v[4*5 + 0] = 1.0; v[4*5 + 1] = 0.0; v[4*5 + 2] = 0.0; v[4*5 + 3] = 0.0; v[4*5 + 4] = 0.0; - #elif SH_DEGREE == 6 - v[0*7 + 0] = -0.1428571429; v[0*7 + 1] = 0.1585594663; v[0*7 + 2] = -0.2291250674; v[0*7 + 3] = 0.6419941725; v[0*7 + 4] = 0.6419941725; v[0*7 + 5] = -0.2291250674; v[0*7 + 6] = 0.1585594663; - v[1*7 + 0] = -0.0; v[1*7 + 1] = 0.0763582145; v[1*7 + 2] = -0.2873137468; v[1*7 + 3] = 2.8127602518; v[1*7 + 4] = -2.8127602518; v[1*7 + 5] = 0.2873137468; v[1*7 + 6] = -0.0763582145; - v[2*7 + 0] = 3.0; v[2*7 + 1] = -3.2929766145; v[2*7 + 2] = 4.4513463718; v[2*7 + 3] = -1.1583697574; v[2*7 + 4] = -1.1583697574; v[2*7 + 5] = 4.4513463718; v[2*7 + 6] = -3.2929766145; - v[3*7 + 0] = 0.0; v[3*7 + 1] = -1.5858139579; v[3*7 + 2] = 5.5818117995; v[3*7 + 3] = -5.0751495106; v[3*7 + 4] = 5.0751495106; v[3*7 + 5] = -5.5818117995; v[3*7 + 6] = 1.5858139579; - v[4*7 + 0] = -5.0; v[4*7 + 1] = 4.7858935686; v[4*7 + 2] = -1.0200067492; v[4*7 + 3] = 0.2341131806; v[4*7 + 4] = 0.2341131806; v[4*7 + 5] = -1.0200067492; v[4*7 + 6] = 4.7858935686; - v[5*7 + 0] = -0.0; v[5*7 + 1] = 2.3047648710; v[5*7 + 2] = -1.2790480077; v[5*7 + 3] = 1.0257168633; v[5*7 + 4] = -1.0257168633; v[5*7 + 5] = 1.2790480077; v[5*7 + 6] = -2.3047648710; - v[6*7 + 0] = 1.0; v[6*7 + 1] = 0.0; v[6*7 + 2] = 0.0; v[6*7 + 3] = 0.0; v[6*7 + 4] = 0.0; v[6*7 + 5] = 0.0; v[6*7 + 6] = 0.0; - #elif SH_DEGREE == 8 - v[0*9 + 0] = 0.1111111111; v[0*9 + 1] = -0.1182419747; v[0*9 + 2] = 0.1450452544; v[0*9 + 3] = -0.2222222222; v[0*9 + 4] = 0.6398633870; v[0*9 + 5] = 0.6398633870; v[0*9 + 6] = -0.2222222222; v[0*9 + 7] = 0.1450452544; v[0*9 + 8] = -0.1182419747; - v[1*9 + 0] = 0.0; v[1*9 + 1] = -0.0430365592; v[1*9 + 2] = 0.1217074194; v[1*9 + 3] = -0.3849001795; v[1*9 + 4] = 3.6288455938; v[1*9 + 5] = -3.6288455938; v[1*9 + 6] = 0.3849001795; v[1*9 + 7] = -0.1217074194; v[1*9 + 8] = 0.0430365592; - v[2*9 + 0] = -4.0; v[2*9 + 1] = 4.2410470634; v[2*9 + 2] = -5.1195045066; v[2*9 + 3] = 7.3333333333; v[2*9 + 4] = -2.4548758901; v[2*9 + 5] = -2.4548758901; v[2*9 + 6] = 7.3333333333; v[2*9 + 7] = -5.1195045066; v[2*9 + 8] = 4.2410470634; - v[3*9 + 0] = -0.0; v[3*9 + 1] = 1.5436148932; v[3*9 + 2] = -4.2957743433; v[3*9 + 3] = 12.7017059222; v[3*9 + 4] = -13.9222930051; v[3*9 + 5] = 13.9222930051; v[3*9 + 6] = -12.7017059222; v[3*9 + 7] = 4.2957743433; v[3*9 + 8] = -1.5436148932; - v[4*9 + 0] = 14.0; v[4*9 + 1] = -14.3366589404; v[4*9 + 2] = 14.6711193836; v[4*9 + 3] = -6.0; v[4*9 + 4] = 1.6655395568; v[4*9 + 5] = 1.6655395568; v[4*9 + 6] = -6.0; v[4*9 + 7] = 14.6711193836; v[4*9 + 8] = -14.3366589404; - v[5*9 + 0] = 0.0; v[5*9 + 1] = -5.2181171131; v[5*9 + 2] = 12.3105308637; v[5*9 + 3] = -10.3923048454; v[5*9 + 4] = 9.4457442082; v[5*9 + 5] = -9.4457442082; v[5*9 + 6] = 10.3923048454; v[5*9 + 7] = -12.3105308637; v[5*9 + 8] = 5.2181171131; - v[6*9 + 0] = -9.3333333333; v[6*9 + 1] = 8.0330865684; v[6*9 + 2] = -1.8540394597; v[6*9 + 3] = 0.6666666667; v[6*9 + 4] = -0.1790471086; v[6*9 + 5] = -0.1790471086; v[6*9 + 6] = 0.6666666667; v[6*9 + 7] = -1.8540394597; v[6*9 + 8] = 8.0330865684; - v[7*9 + 0] = -0.0; v[7*9 + 1] = 2.9238044002; v[7*9 + 2] = -1.5557238269; v[7*9 + 3] = 1.1547005384; v[7*9 + 4] = -1.0154266119; v[7*9 + 5] = 1.0154266119; v[7*9 + 6] = -1.1547005384; v[7*9 + 7] = 1.5557238269; v[7*9 + 8] = -2.9238044002; - v[8*9 + 0] = 1.0; v[8*9 + 1] = 0.0; v[8*9 + 2] = 0.0; v[8*9 + 3] = 0.0; v[8*9 + 4] = 0.0; v[8*9 + 5] = 0.0; v[8*9 + 6] = 0.0; v[8*9 + 7] = 0.0; v[8*9 + 8] = 0.0; - #elif SH_DEGREE == 10 - v[0*11 + 0] = -0.0909090909; v[0*11 + 1] = 0.0947470106; v[0*11 + 2] = -0.1080638444; v[0*11 + 3] = 0.1388220215; v[0*11 + 4] = -0.2188392043; v[0*11 + 5] = 0.6387885621; v[0*11 + 6] = 0.6387885621; v[0*11 + 7] = -0.2188392043; v[0*11 + 8] = 0.1388220215; v[0*11 + 9] = -0.1080638444; v[0*11 + 10] = 0.0947470106; - v[1*11 + 0] = -0.0; v[1*11 + 1] = 0.0278202324; v[1*11 + 2] = -0.0694484159; v[1*11 + 3] = 0.1602091533; v[1*11 + 4] = -0.4791910159; v[1*11 + 5] = 4.4428720384; v[1*11 + 6] = -4.4428720384; v[1*11 + 7] = 0.4791910159; v[1*11 + 8] = -0.1602091533; v[1*11 + 9] = 0.0694484159; v[1*11 + 10] = -0.0278202324; - v[2*11 + 0] = 5.0; v[2*11 + 1] = -5.2029168239; v[2*11 + 2] = 5.8988796576; v[2*11 + 3] = -7.4503199653; v[2*11 + 4] = 10.9868742757; v[2*11 + 5] = -4.2325171441; v[2*11 + 6] = -4.2325171441; v[2*11 + 7] = 10.9868742757; v[2*11 + 8] = -7.4503199653; v[2*11 + 9] = 5.8988796576; v[2*11 + 10] = -5.2029168239; - v[3*11 + 0] = 0.0; v[3*11 + 1] = -1.5277142200; v[3*11 + 2] = 3.7909797649; v[3*11 + 3] = -8.5981275876; v[3*11 + 4] = 24.0578988657; v[3*11 + 5] = -29.4378033460; v[3*11 + 6] = 29.4378033460; v[3*11 + 7] = -24.0578988657; v[3*11 + 8] = 8.5981275876; v[3*11 + 9] = -3.7909797649; v[3*11 + 10] = 1.5277142200; - v[4*11 + 0] = -30.0; v[4*11 + 1] = 30.8179361182; v[4*11 + 2] = -33.2247539061; v[4*11 + 3] = 35.8884989085; v[4*11 + 4] = -19.5374870834; v[4*11 + 5] = 6.0558059629; v[4*11 + 6] = 6.0558059629; v[4*11 + 7] = -19.5374870834; v[4*11 + 8] = 35.8884989085; v[4*11 + 9] = -33.2247539061; v[4*11 + 10] = 30.8179361182; - v[5*11 + 0] = -0.0; v[5*11 + 1] = 9.0489625020; v[5*11 + 2] = -21.3522528115; v[5*11 + 3] = 41.4175356200; v[5*11 + 4] = -42.7811292411; v[5*11 + 5] = 42.1190556280; v[5*11 + 6] = -42.1190556280; v[5*11 + 7] = 42.7811292411; v[5*11 + 8] = -41.4175356200; v[5*11 + 9] = 21.3522528115; v[5*11 + 10] = -9.0489625020; - v[6*11 + 0] = 42.0; v[6*11 + 1] = -41.1161037573; v[6*11 + 2] = 36.2032364762; v[6*11 + 3] = -16.3373898141; v[6*11 + 4] = 7.4261062994; v[6*11 + 5] = -2.1758492042; v[6*11 + 6] = -2.1758492042; v[6*11 + 7] = 7.4261062994; v[6*11 + 8] = -16.3373898141; v[6*11 + 9] = 36.2032364762; v[6*11 + 10] = -41.1161037573; - v[7*11 + 0] = 0.0; v[7*11 + 1] = -12.0727773496; v[7*11 + 2] = 23.2664073304; v[7*11 + 3] = -18.8543529304; v[7*11 + 4] = 16.2609045881; v[7*11 + 5] = -15.1333636234; v[7*11 + 6] = 15.1333636234; v[7*11 + 7] = -16.2609045881; v[7*11 + 8] = 18.8543529304; v[7*11 + 9] = -23.2664073304; v[7*11 + 10] = 12.0727773496; - v[8*11 + 0] = -15.0; v[8*11 + 1] = 12.0883694702; v[8*11 + 2] = -2.8781222629; v[8*11 + 3] = 1.1465503415; v[8*11 + 4] = -0.5020543475; v[8*11 + 5] = 0.1452567988; v[8*11 + 6] = 0.1452567988; v[8*11 + 7] = -0.5020543475; v[8*11 + 8] = 1.1465503415; v[8*11 + 9] = -2.8781222629; v[8*11 + 10] = 12.0883694702; - v[9*11 + 0] = -0.0; v[9*11 + 1] = 3.5494655329; v[9*11 + 2] = -1.8496568659; v[9*11 + 3] = 1.3231896304; v[9*11 + 4] = -1.0993456751; v[9*11 + 5] = 1.0102832265; v[9*11 + 6] = -1.0102832265; v[9*11 + 7] = 1.0993456751; v[9*11 + 8] = -1.3231896304; v[9*11 + 9] = 1.8496568659; v[9*11 + 10] = -3.5494655329; - v[10*11 + 0] = 1.0; v[10*11 + 1] = 0.0; v[10*11 + 2] = 0.0; v[10*11 + 3] = 0.0; v[10*11 + 4] = 0.0; v[10*11 + 5] = 0.0; v[10*11 + 6] = 0.0; v[10*11 + 7] = 0.0; v[10*11 + 8] = 0.0; v[10*11 + 9] = 0.0; v[10*11 + 10] = 0.0; - #elif SH_DEGREE == 12 - v[0*13 + 0] = 0.0769230769; v[0*13 + 1] = -0.0792252178; v[0*13 + 2] = 0.0868739663; v[0*13 + 3] = -0.1027681661; v[0*13 + 4] = 0.1354125166; v[0*13 + 5] = -0.2169261613; v[0*13 + 6] = 0.6381715239; v[0*13 + 7] = 0.6381715239; v[0*13 + 8] = -0.2169261613; v[0*13 + 9] = 0.1354125166; v[0*13 + 10] = -0.1027681661; v[0*13 + 11] = 0.0868739663; v[0*13 + 12] = -0.0792252178; - v[1*13 + 0] = -0.0; v[1*13 + 1] = -0.0195272624; v[1*13 + 2] = 0.0455949748; v[1*13 + 3] = -0.0910446506; v[1*13 + 4] = 0.1961788986; v[1*13 + 5] = -0.5719872785; v[1*13 + 6] = 5.2558153553; v[1*13 + 7] = -5.2558153553; v[1*13 + 8] = 0.5719872785; v[1*13 + 9] = -0.1961788986; v[1*13 + 10] = 0.0910446506; v[1*13 + 11] = -0.0455949748; v[1*13 + 12] = 0.0195272624; - v[2*13 + 0] = -6.0; v[2*13 + 1] = 6.1747539478; v[2*13 + 2] = -6.7522392818; v[2*13 + 3] = 7.9352584366; v[2*13 + 4] = -10.2779620900; v[2*13 + 5] = 15.4120340799; v[2*13 + 6] = -6.4918450925; v[2*13 + 7] = -6.4918450925; v[2*13 + 8] = 15.4120340799; v[2*13 + 9] = -10.2779620900; v[2*13 + 10] = 7.9352584366; v[2*13 + 11] = -6.7522392818; v[2*13 + 12] = 6.1747539478; - v[3*13 + 0] = -0.0; v[3*13 + 1] = 1.5219401578; v[3*13 + 2] = -3.5438485554; v[3*13 + 3] = 7.0300255289; v[3*13 + 4] = -14.8901987371; v[3*13 + 5] = 40.6381940129; v[3*13 + 6] = -53.4651544987; v[3*13 + 7] = 53.4651544987; v[3*13 + 8] = -40.6381940129; v[3*13 + 9] = 14.8901987371; v[3*13 + 10] = -7.0300255289; v[3*13 + 11] = 3.5438485554; v[3*13 + 12] = -1.5219401578; - v[4*13 + 0] = 55.0; v[4*13 + 1] = -56.2709061445; v[4*13 + 2] = 60.2549306937; v[4*13 + 3] = -67.2511796347; v[4*13 + 4] = 75.2477722397; v[4*13 + 5] = -47.9480941911; v[4*13 + 6] = 15.9674770369; v[4*13 + 7] = 15.9674770369; v[4*13 + 8] = -47.9480941911; v[4*13 + 9] = 75.2477722397; v[4*13 + 10] = -67.2511796347; v[4*13 + 11] = 60.2549306937; v[4*13 + 12] = -56.2709061445; - v[5*13 + 0] = 0.0; v[5*13 + 1] = -13.8695326974; v[5*13 + 2] = 31.6242271914; v[5*13 + 3] = -59.5793462127; v[5*13 + 4] = 109.0152185187; v[5*13 + 5] = -126.4287338180; v[5*13 + 6] = 131.5040045727; v[5*13 + 7] = -131.5040045727; v[5*13 + 8] = 126.4287338180; v[5*13 + 9] = -109.0152185187; v[5*13 + 10] = 59.5793462127; v[5*13 + 11] = -31.6242271914; v[5*13 + 12] = 13.8695326974; - v[6*13 + 0] = -132.0; v[6*13 + 1] = 132.5319409049; v[6*13 + 2] = -132.4780513404; v[6*13 + 3] = 123.5674782081; v[6*13 + 4] = -74.4320682907; v[6*13 + 5] = 38.8801193717; v[6*13 + 6] = -12.0694188537; v[6*13 + 7] = -12.0694188537; v[6*13 + 8] = 38.8801193717; v[6*13 + 9] = -74.4320682907; v[6*13 + 10] = 123.5674782081; v[6*13 + 11] = -132.4780513404; v[6*13 + 12] = 132.5319409049; - v[7*13 + 0] = -0.0; v[7*13 + 1] = 32.6661895777; v[7*13 + 2] = -69.5298450306; v[7*13 + 3] = 109.4712331409; v[7*13 + 4] = -107.8334673306; v[7*13 + 5] = 102.5184492897; v[7*13 + 6] = -99.4006071501; v[7*13 + 7] = 99.4006071501; v[7*13 + 8] = -102.5184492897; v[7*13 + 9] = 107.8334673306; v[7*13 + 10] = -109.4712331409; v[7*13 + 11] = 69.5298450306; v[7*13 + 12] = -32.6661895777; - v[8*13 + 0] = 99.0; v[8*13 + 1] = -93.9113626635; v[8*13 + 2] = 75.3147168618; v[8*13 + 3] = -35.2795800772; v[8*13 + 4] = 18.0521608541; v[8*13 + 5] = -8.8650350126; v[8*13 + 6] = 2.6891000373; v[8*13 + 7] = 2.6891000373; v[8*13 + 8] = -8.8650350126; v[8*13 + 9] = 18.0521608541; v[8*13 + 10] = -35.2795800772; v[8*13 + 11] = 75.3147168618; v[8*13 + 12] = -93.9113626635; - v[9*13 + 0] = 0.0; v[9*13 + 1] = -23.1470719837; v[9*13 + 2] = 39.5282127035; v[9*13 + 3] = -31.2549806126; v[9*13 + 4] = 26.1530700733; v[9*13 + 5] = -23.3751762359; v[9*13 + 6] = 22.1467313083; v[9*13 + 7] = -22.1467313083; v[9*13 + 8] = 23.3751762359; v[9*13 + 9] = -26.1530700733; v[9*13 + 10] = 31.2549806126; v[9*13 + 11] = -39.5282127035; v[9*13 + 12] = 23.1470719837; - v[10*13 + 0] = -22.0; v[10*13 + 1] = 16.9531714429; v[10*13 + 2] = -4.0999479387; v[10*13 + 3] = 1.7021989010; v[10*13 + 4] = -0.8387165175; v[10*13 + 5] = 0.4056079008; v[10*13 + 6] = -0.1223137885; v[10*13 + 7] = -0.1223137885; v[10*13 + 8] = 0.4056079008; v[10*13 + 9] = -0.8387165175; v[10*13 + 10] = 1.7021989010; v[10*13 + 11] = -4.0999479387; v[10*13 + 12] = 16.9531714429; - v[11*13 + 0] = -0.0; v[11*13 + 1] = 4.1785814689; v[11*13 + 2] = -2.1518186743; v[11*13 + 3] = 1.5080166355; v[11*13 + 4] = -1.2150906493; v[11*13 + 5] = 1.0695001374; v[11*13 + 6] = -1.0073446769; v[11*13 + 7] = 1.0073446769; v[11*13 + 8] = -1.0695001374; v[11*13 + 9] = 1.2150906493; v[11*13 + 10] = -1.5080166355; v[11*13 + 11] = 2.1518186743; v[11*13 + 12] = -4.1785814689; - v[12*13 + 0] = 1.0; v[12*13 + 1] = 0.0; v[12*13 + 2] = 0.0; v[12*13 + 3] = 0.0; v[12*13 + 4] = 0.0; v[12*13 + 5] = 0.0; v[12*13 + 6] = 0.0; v[12*13 + 7] = 0.0; v[12*13 + 8] = 0.0; v[12*13 + 9] = 0.0; v[12*13 + 10] = 0.0; v[12*13 + 11] = 0.0; v[12*13 + 12] = 0.0; - #endif + if (shDegree == 2) + { + float tmpV[9]; + tmpV[0*3 + 0] = -0.3333333333; tmpV[0*3 + 1] = 0.6666666667; tmpV[0*3 + 2] = 0.6666666667; + tmpV[1*3 + 0] = -0.0; tmpV[1*3 + 1] = 1.1547005384; tmpV[1*3 + 2] = -1.1547005384; + tmpV[2*3 + 0] = 1.0; tmpV[2*3 + 1] = 0.0; tmpV[2*3 + 2] = 0.0; + int tmpVLength = (shDegree + 1) * (shDegree + 1); + for (int i = 0; i != tmpVLength; ++i) + v[i] = tmpV[i]; + } + else if (shDegree == 4) + { + float tmpV[25]; + tmpV[0*5 + 0] = 0.2; tmpV[0*5 + 1] = -0.2472135955; tmpV[0*5 + 2] = 0.6472135955; tmpV[0*5 + 3] = 0.6472135955; tmpV[0*5 + 4] = -0.2472135955; + tmpV[1*5 + 0] = 0.0; tmpV[1*5 + 1] = -0.1796111906; tmpV[1*5 + 2] = 1.9919186279; tmpV[1*5 + 3] = -1.9919186279; tmpV[1*5 + 4] = 0.1796111906; + tmpV[2*5 + 0] = -2.0; tmpV[2*5 + 1] = 2.3416407865; tmpV[2*5 + 2] = -0.3416407865; tmpV[2*5 + 3] = -0.3416407865; tmpV[2*5 + 4] = 2.3416407865; + tmpV[3*5 + 0] = -0.0; tmpV[3*5 + 1] = 1.7013016167; tmpV[3*5 + 2] = -1.0514622242; tmpV[3*5 + 3] = 1.0514622242; tmpV[3*5 + 4] = -1.7013016167; + tmpV[4*5 + 0] = 1.0; tmpV[4*5 + 1] = 0.0; tmpV[4*5 + 2] = 0.0; tmpV[4*5 + 3] = 0.0; tmpV[4*5 + 4] = 0.0; + int tmpVLength = (shDegree + 1) * (shDegree + 1); + for (int i = 0; i != tmpVLength; ++i) + v[i] = tmpV[i]; + } + else if (shDegree == 6) + { + float tmpV[49]; + tmpV[0*7 + 0] = -0.1428571429; tmpV[0*7 + 1] = 0.1585594663; tmpV[0*7 + 2] = -0.2291250674; tmpV[0*7 + 3] = 0.6419941725; tmpV[0*7 + 4] = 0.6419941725; tmpV[0*7 + 5] = -0.2291250674; tmpV[0*7 + 6] = 0.1585594663; + tmpV[1*7 + 0] = -0.0; tmpV[1*7 + 1] = 0.0763582145; tmpV[1*7 + 2] = -0.2873137468; tmpV[1*7 + 3] = 2.8127602518; tmpV[1*7 + 4] = -2.8127602518; tmpV[1*7 + 5] = 0.2873137468; tmpV[1*7 + 6] = -0.0763582145; + tmpV[2*7 + 0] = 3.0; tmpV[2*7 + 1] = -3.2929766145; tmpV[2*7 + 2] = 4.4513463718; tmpV[2*7 + 3] = -1.1583697574; tmpV[2*7 + 4] = -1.1583697574; tmpV[2*7 + 5] = 4.4513463718; tmpV[2*7 + 6] = -3.2929766145; + tmpV[3*7 + 0] = 0.0; tmpV[3*7 + 1] = -1.5858139579; tmpV[3*7 + 2] = 5.5818117995; tmpV[3*7 + 3] = -5.0751495106; tmpV[3*7 + 4] = 5.0751495106; tmpV[3*7 + 5] = -5.5818117995; tmpV[3*7 + 6] = 1.5858139579; + tmpV[4*7 + 0] = -5.0; tmpV[4*7 + 1] = 4.7858935686; tmpV[4*7 + 2] = -1.0200067492; tmpV[4*7 + 3] = 0.2341131806; tmpV[4*7 + 4] = 0.2341131806; tmpV[4*7 + 5] = -1.0200067492; tmpV[4*7 + 6] = 4.7858935686; + tmpV[5*7 + 0] = -0.0; tmpV[5*7 + 1] = 2.3047648710; tmpV[5*7 + 2] = -1.2790480077; tmpV[5*7 + 3] = 1.0257168633; tmpV[5*7 + 4] = -1.0257168633; tmpV[5*7 + 5] = 1.2790480077; tmpV[5*7 + 6] = -2.3047648710; + tmpV[6*7 + 0] = 1.0; tmpV[6*7 + 1] = 0.0; tmpV[6*7 + 2] = 0.0; tmpV[6*7 + 3] = 0.0; tmpV[6*7 + 4] = 0.0; tmpV[6*7 + 5] = 0.0; tmpV[6*7 + 6] = 0.0; + int tmpVLength = (shDegree + 1) * (shDegree + 1); + for (int i = 0; i != tmpVLength; ++i) + v[i] = tmpV[i]; + } + else if (shDegree == 8) + { + float tmpV[81]; + tmpV[0*9 + 0] = 0.1111111111; tmpV[0*9 + 1] = -0.1182419747; tmpV[0*9 + 2] = 0.1450452544; tmpV[0*9 + 3] = -0.2222222222; tmpV[0*9 + 4] = 0.6398633870; tmpV[0*9 + 5] = 0.6398633870; tmpV[0*9 + 6] = -0.2222222222; tmpV[0*9 + 7] = 0.1450452544; tmpV[0*9 + 8] = -0.1182419747; + tmpV[1*9 + 0] = 0.0; tmpV[1*9 + 1] = -0.0430365592; tmpV[1*9 + 2] = 0.1217074194; tmpV[1*9 + 3] = -0.3849001795; tmpV[1*9 + 4] = 3.6288455938; tmpV[1*9 + 5] = -3.6288455938; tmpV[1*9 + 6] = 0.3849001795; tmpV[1*9 + 7] = -0.1217074194; tmpV[1*9 + 8] = 0.0430365592; + tmpV[2*9 + 0] = -4.0; tmpV[2*9 + 1] = 4.2410470634; tmpV[2*9 + 2] = -5.1195045066; tmpV[2*9 + 3] = 7.3333333333; tmpV[2*9 + 4] = -2.4548758901; tmpV[2*9 + 5] = -2.4548758901; tmpV[2*9 + 6] = 7.3333333333; tmpV[2*9 + 7] = -5.1195045066; tmpV[2*9 + 8] = 4.2410470634; + tmpV[3*9 + 0] = -0.0; tmpV[3*9 + 1] = 1.5436148932; tmpV[3*9 + 2] = -4.2957743433; tmpV[3*9 + 3] = 12.7017059222; tmpV[3*9 + 4] = -13.9222930051; tmpV[3*9 + 5] = 13.9222930051; tmpV[3*9 + 6] = -12.7017059222; tmpV[3*9 + 7] = 4.2957743433; tmpV[3*9 + 8] = -1.5436148932; + tmpV[4*9 + 0] = 14.0; tmpV[4*9 + 1] = -14.3366589404; tmpV[4*9 + 2] = 14.6711193836; tmpV[4*9 + 3] = -6.0; tmpV[4*9 + 4] = 1.6655395568; tmpV[4*9 + 5] = 1.6655395568; tmpV[4*9 + 6] = -6.0; tmpV[4*9 + 7] = 14.6711193836; tmpV[4*9 + 8] = -14.3366589404; + tmpV[5*9 + 0] = 0.0; tmpV[5*9 + 1] = -5.2181171131; tmpV[5*9 + 2] = 12.3105308637; tmpV[5*9 + 3] = -10.3923048454; tmpV[5*9 + 4] = 9.4457442082; tmpV[5*9 + 5] = -9.4457442082; tmpV[5*9 + 6] = 10.3923048454; tmpV[5*9 + 7] = -12.3105308637; tmpV[5*9 + 8] = 5.2181171131; + tmpV[6*9 + 0] = -9.3333333333; tmpV[6*9 + 1] = 8.0330865684; tmpV[6*9 + 2] = -1.8540394597; tmpV[6*9 + 3] = 0.6666666667; tmpV[6*9 + 4] = -0.1790471086; tmpV[6*9 + 5] = -0.1790471086; tmpV[6*9 + 6] = 0.6666666667; tmpV[6*9 + 7] = -1.8540394597; tmpV[6*9 + 8] = 8.0330865684; + tmpV[7*9 + 0] = -0.0; tmpV[7*9 + 1] = 2.9238044002; tmpV[7*9 + 2] = -1.5557238269; tmpV[7*9 + 3] = 1.1547005384; tmpV[7*9 + 4] = -1.0154266119; tmpV[7*9 + 5] = 1.0154266119; tmpV[7*9 + 6] = -1.1547005384; tmpV[7*9 + 7] = 1.5557238269; tmpV[7*9 + 8] = -2.9238044002; + tmpV[8*9 + 0] = 1.0; tmpV[8*9 + 1] = 0.0; tmpV[8*9 + 2] = 0.0; tmpV[8*9 + 3] = 0.0; tmpV[8*9 + 4] = 0.0; tmpV[8*9 + 5] = 0.0; tmpV[8*9 + 6] = 0.0; tmpV[8*9 + 7] = 0.0; tmpV[8*9 + 8] = 0.0; + int tmpVLength = (shDegree + 1) * (shDegree + 1); + for (int i = 0; i != tmpVLength; ++i) + v[i] = tmpV[i]; + } + else if (shDegree == 10) + { + float tmpV[121]; + tmpV[0*11 + 0] = -0.0909090909; tmpV[0*11 + 1] = 0.0947470106; tmpV[0*11 + 2] = -0.1080638444; tmpV[0*11 + 3] = 0.1388220215; tmpV[0*11 + 4] = -0.2188392043; tmpV[0*11 + 5] = 0.6387885621; tmpV[0*11 + 6] = 0.6387885621; tmpV[0*11 + 7] = -0.2188392043; tmpV[0*11 + 8] = 0.1388220215; tmpV[0*11 + 9] = -0.1080638444; tmpV[0*11 + 10] = 0.0947470106; + tmpV[1*11 + 0] = -0.0; tmpV[1*11 + 1] = 0.0278202324; tmpV[1*11 + 2] = -0.0694484159; tmpV[1*11 + 3] = 0.1602091533; tmpV[1*11 + 4] = -0.4791910159; tmpV[1*11 + 5] = 4.4428720384; tmpV[1*11 + 6] = -4.4428720384; tmpV[1*11 + 7] = 0.4791910159; tmpV[1*11 + 8] = -0.1602091533; tmpV[1*11 + 9] = 0.0694484159; tmpV[1*11 + 10] = -0.0278202324; + tmpV[2*11 + 0] = 5.0; tmpV[2*11 + 1] = -5.2029168239; tmpV[2*11 + 2] = 5.8988796576; tmpV[2*11 + 3] = -7.4503199653; tmpV[2*11 + 4] = 10.9868742757; tmpV[2*11 + 5] = -4.2325171441; tmpV[2*11 + 6] = -4.2325171441; tmpV[2*11 + 7] = 10.9868742757; tmpV[2*11 + 8] = -7.4503199653; tmpV[2*11 + 9] = 5.8988796576; tmpV[2*11 + 10] = -5.2029168239; + tmpV[3*11 + 0] = 0.0; tmpV[3*11 + 1] = -1.5277142200; tmpV[3*11 + 2] = 3.7909797649; tmpV[3*11 + 3] = -8.5981275876; tmpV[3*11 + 4] = 24.0578988657; tmpV[3*11 + 5] = -29.4378033460; tmpV[3*11 + 6] = 29.4378033460; tmpV[3*11 + 7] = -24.0578988657; tmpV[3*11 + 8] = 8.5981275876; tmpV[3*11 + 9] = -3.7909797649; tmpV[3*11 + 10] = 1.5277142200; + tmpV[4*11 + 0] = -30.0; tmpV[4*11 + 1] = 30.8179361182; tmpV[4*11 + 2] = -33.2247539061; tmpV[4*11 + 3] = 35.8884989085; tmpV[4*11 + 4] = -19.5374870834; tmpV[4*11 + 5] = 6.0558059629; tmpV[4*11 + 6] = 6.0558059629; tmpV[4*11 + 7] = -19.5374870834; tmpV[4*11 + 8] = 35.8884989085; tmpV[4*11 + 9] = -33.2247539061; tmpV[4*11 + 10] = 30.8179361182; + tmpV[5*11 + 0] = -0.0; tmpV[5*11 + 1] = 9.0489625020; tmpV[5*11 + 2] = -21.3522528115; tmpV[5*11 + 3] = 41.4175356200; tmpV[5*11 + 4] = -42.7811292411; tmpV[5*11 + 5] = 42.1190556280; tmpV[5*11 + 6] = -42.1190556280; tmpV[5*11 + 7] = 42.7811292411; tmpV[5*11 + 8] = -41.4175356200; tmpV[5*11 + 9] = 21.3522528115; tmpV[5*11 + 10] = -9.0489625020; + tmpV[6*11 + 0] = 42.0; tmpV[6*11 + 1] = -41.1161037573; tmpV[6*11 + 2] = 36.2032364762; tmpV[6*11 + 3] = -16.3373898141; tmpV[6*11 + 4] = 7.4261062994; tmpV[6*11 + 5] = -2.1758492042; tmpV[6*11 + 6] = -2.1758492042; tmpV[6*11 + 7] = 7.4261062994; tmpV[6*11 + 8] = -16.3373898141; tmpV[6*11 + 9] = 36.2032364762; tmpV[6*11 + 10] = -41.1161037573; + tmpV[7*11 + 0] = 0.0; tmpV[7*11 + 1] = -12.0727773496; tmpV[7*11 + 2] = 23.2664073304; tmpV[7*11 + 3] = -18.8543529304; tmpV[7*11 + 4] = 16.2609045881; tmpV[7*11 + 5] = -15.1333636234; tmpV[7*11 + 6] = 15.1333636234; tmpV[7*11 + 7] = -16.2609045881; tmpV[7*11 + 8] = 18.8543529304; tmpV[7*11 + 9] = -23.2664073304; tmpV[7*11 + 10] = 12.0727773496; + tmpV[8*11 + 0] = -15.0; tmpV[8*11 + 1] = 12.0883694702; tmpV[8*11 + 2] = -2.8781222629; tmpV[8*11 + 3] = 1.1465503415; tmpV[8*11 + 4] = -0.5020543475; tmpV[8*11 + 5] = 0.1452567988; tmpV[8*11 + 6] = 0.1452567988; tmpV[8*11 + 7] = -0.5020543475; tmpV[8*11 + 8] = 1.1465503415; tmpV[8*11 + 9] = -2.8781222629; tmpV[8*11 + 10] = 12.0883694702; + tmpV[9*11 + 0] = -0.0; tmpV[9*11 + 1] = 3.5494655329; tmpV[9*11 + 2] = -1.8496568659; tmpV[9*11 + 3] = 1.3231896304; tmpV[9*11 + 4] = -1.0993456751; tmpV[9*11 + 5] = 1.0102832265; tmpV[9*11 + 6] = -1.0102832265; tmpV[9*11 + 7] = 1.0993456751; tmpV[9*11 + 8] = -1.3231896304; tmpV[9*11 + 9] = 1.8496568659; tmpV[9*11 + 10] = -3.5494655329; + tmpV[10*11 + 0] = 1.0; tmpV[10*11 + 1] = 0.0; tmpV[10*11 + 2] = 0.0; tmpV[10*11 + 3] = 0.0; tmpV[10*11 + 4] = 0.0; tmpV[10*11 + 5] = 0.0; tmpV[10*11 + 6] = 0.0; tmpV[10*11 + 7] = 0.0; tmpV[10*11 + 8] = 0.0; tmpV[10*11 + 9] = 0.0; tmpV[10*11 + 10] = 0.0; + int tmpVLength = (shDegree + 1) * (shDegree + 1); + for (int i = 0; i != tmpVLength; ++i) + v[i] = tmpV[i]; + } + else if (shDegree == 12) + { + float tmpV[169]; + tmpV[0*13 + 0] = 0.0769230769; tmpV[0*13 + 1] = -0.0792252178; tmpV[0*13 + 2] = 0.0868739663; tmpV[0*13 + 3] = -0.1027681661; tmpV[0*13 + 4] = 0.1354125166; tmpV[0*13 + 5] = -0.2169261613; tmpV[0*13 + 6] = 0.6381715239; tmpV[0*13 + 7] = 0.6381715239; tmpV[0*13 + 8] = -0.2169261613; tmpV[0*13 + 9] = 0.1354125166; tmpV[0*13 + 10] = -0.1027681661; tmpV[0*13 + 11] = 0.0868739663; tmpV[0*13 + 12] = -0.0792252178; + tmpV[1*13 + 0] = -0.0; tmpV[1*13 + 1] = -0.0195272624; tmpV[1*13 + 2] = 0.0455949748; tmpV[1*13 + 3] = -0.0910446506; tmpV[1*13 + 4] = 0.1961788986; tmpV[1*13 + 5] = -0.5719872785; tmpV[1*13 + 6] = 5.2558153553; tmpV[1*13 + 7] = -5.2558153553; tmpV[1*13 + 8] = 0.5719872785; tmpV[1*13 + 9] = -0.1961788986; tmpV[1*13 + 10] = 0.0910446506; tmpV[1*13 + 11] = -0.0455949748; tmpV[1*13 + 12] = 0.0195272624; + tmpV[2*13 + 0] = -6.0; tmpV[2*13 + 1] = 6.1747539478; tmpV[2*13 + 2] = -6.7522392818; tmpV[2*13 + 3] = 7.9352584366; tmpV[2*13 + 4] = -10.2779620900; tmpV[2*13 + 5] = 15.4120340799; tmpV[2*13 + 6] = -6.4918450925; tmpV[2*13 + 7] = -6.4918450925; tmpV[2*13 + 8] = 15.4120340799; tmpV[2*13 + 9] = -10.2779620900; tmpV[2*13 + 10] = 7.9352584366; tmpV[2*13 + 11] = -6.7522392818; tmpV[2*13 + 12] = 6.1747539478; + tmpV[3*13 + 0] = -0.0; tmpV[3*13 + 1] = 1.5219401578; tmpV[3*13 + 2] = -3.5438485554; tmpV[3*13 + 3] = 7.0300255289; tmpV[3*13 + 4] = -14.8901987371; tmpV[3*13 + 5] = 40.6381940129; tmpV[3*13 + 6] = -53.4651544987; tmpV[3*13 + 7] = 53.4651544987; tmpV[3*13 + 8] = -40.6381940129; tmpV[3*13 + 9] = 14.8901987371; tmpV[3*13 + 10] = -7.0300255289; tmpV[3*13 + 11] = 3.5438485554; tmpV[3*13 + 12] = -1.5219401578; + tmpV[4*13 + 0] = 55.0; tmpV[4*13 + 1] = -56.2709061445; tmpV[4*13 + 2] = 60.2549306937; tmpV[4*13 + 3] = -67.2511796347; tmpV[4*13 + 4] = 75.2477722397; tmpV[4*13 + 5] = -47.9480941911; tmpV[4*13 + 6] = 15.9674770369; tmpV[4*13 + 7] = 15.9674770369; tmpV[4*13 + 8] = -47.9480941911; tmpV[4*13 + 9] = 75.2477722397; tmpV[4*13 + 10] = -67.2511796347; tmpV[4*13 + 11] = 60.2549306937; tmpV[4*13 + 12] = -56.2709061445; + tmpV[5*13 + 0] = 0.0; tmpV[5*13 + 1] = -13.8695326974; tmpV[5*13 + 2] = 31.6242271914; tmpV[5*13 + 3] = -59.5793462127; tmpV[5*13 + 4] = 109.0152185187; tmpV[5*13 + 5] = -126.4287338180; tmpV[5*13 + 6] = 131.5040045727; tmpV[5*13 + 7] = -131.5040045727; tmpV[5*13 + 8] = 126.4287338180; tmpV[5*13 + 9] = -109.0152185187; tmpV[5*13 + 10] = 59.5793462127; tmpV[5*13 + 11] = -31.6242271914; tmpV[5*13 + 12] = 13.8695326974; + tmpV[6*13 + 0] = -132.0; tmpV[6*13 + 1] = 132.5319409049; tmpV[6*13 + 2] = -132.4780513404; tmpV[6*13 + 3] = 123.5674782081; tmpV[6*13 + 4] = -74.4320682907; tmpV[6*13 + 5] = 38.8801193717; tmpV[6*13 + 6] = -12.0694188537; tmpV[6*13 + 7] = -12.0694188537; tmpV[6*13 + 8] = 38.8801193717; tmpV[6*13 + 9] = -74.4320682907; tmpV[6*13 + 10] = 123.5674782081; tmpV[6*13 + 11] = -132.4780513404; tmpV[6*13 + 12] = 132.5319409049; + tmpV[7*13 + 0] = -0.0; tmpV[7*13 + 1] = 32.6661895777; tmpV[7*13 + 2] = -69.5298450306; tmpV[7*13 + 3] = 109.4712331409; tmpV[7*13 + 4] = -107.8334673306; tmpV[7*13 + 5] = 102.5184492897; tmpV[7*13 + 6] = -99.4006071501; tmpV[7*13 + 7] = 99.4006071501; tmpV[7*13 + 8] = -102.5184492897; tmpV[7*13 + 9] = 107.8334673306; tmpV[7*13 + 10] = -109.4712331409; tmpV[7*13 + 11] = 69.5298450306; tmpV[7*13 + 12] = -32.6661895777; + tmpV[8*13 + 0] = 99.0; tmpV[8*13 + 1] = -93.9113626635; tmpV[8*13 + 2] = 75.3147168618; tmpV[8*13 + 3] = -35.2795800772; tmpV[8*13 + 4] = 18.0521608541; tmpV[8*13 + 5] = -8.8650350126; tmpV[8*13 + 6] = 2.6891000373; tmpV[8*13 + 7] = 2.6891000373; tmpV[8*13 + 8] = -8.8650350126; tmpV[8*13 + 9] = 18.0521608541; tmpV[8*13 + 10] = -35.2795800772; tmpV[8*13 + 11] = 75.3147168618; tmpV[8*13 + 12] = -93.9113626635; + tmpV[9*13 + 0] = 0.0; tmpV[9*13 + 1] = -23.1470719837; tmpV[9*13 + 2] = 39.5282127035; tmpV[9*13 + 3] = -31.2549806126; tmpV[9*13 + 4] = 26.1530700733; tmpV[9*13 + 5] = -23.3751762359; tmpV[9*13 + 6] = 22.1467313083; tmpV[9*13 + 7] = -22.1467313083; tmpV[9*13 + 8] = 23.3751762359; tmpV[9*13 + 9] = -26.1530700733; tmpV[9*13 + 10] = 31.2549806126; tmpV[9*13 + 11] = -39.5282127035; tmpV[9*13 + 12] = 23.1470719837; + tmpV[10*13 + 0] = -22.0; tmpV[10*13 + 1] = 16.9531714429; tmpV[10*13 + 2] = -4.0999479387; tmpV[10*13 + 3] = 1.7021989010; tmpV[10*13 + 4] = -0.8387165175; tmpV[10*13 + 5] = 0.4056079008; tmpV[10*13 + 6] = -0.1223137885; tmpV[10*13 + 7] = -0.1223137885; tmpV[10*13 + 8] = 0.4056079008; tmpV[10*13 + 9] = -0.8387165175; tmpV[10*13 + 10] = 1.7021989010; tmpV[10*13 + 11] = -4.0999479387; tmpV[10*13 + 12] = 16.9531714429; + tmpV[11*13 + 0] = -0.0; tmpV[11*13 + 1] = 4.1785814689; tmpV[11*13 + 2] = -2.1518186743; tmpV[11*13 + 3] = 1.5080166355; tmpV[11*13 + 4] = -1.2150906493; tmpV[11*13 + 5] = 1.0695001374; tmpV[11*13 + 6] = -1.0073446769; tmpV[11*13 + 7] = 1.0073446769; tmpV[11*13 + 8] = -1.0695001374; tmpV[11*13 + 9] = 1.2150906493; tmpV[11*13 + 10] = -1.5080166355; tmpV[11*13 + 11] = 2.1518186743; tmpV[11*13 + 12] = -4.1785814689; + tmpV[12*13 + 0] = 1.0; tmpV[12*13 + 1] = 0.0; tmpV[12*13 + 2] = 0.0; tmpV[12*13 + 3] = 0.0; tmpV[12*13 + 4] = 0.0; tmpV[12*13 + 5] = 0.0; tmpV[12*13 + 6] = 0.0; tmpV[12*13 + 7] = 0.0; tmpV[12*13 + 8] = 0.0; tmpV[12*13 + 9] = 0.0; tmpV[12*13 + 10] = 0.0; tmpV[12*13 + 11] = 0.0; tmpV[12*13 + 12] = 0.0; + int tmpVLength = (shDegree + 1) * (shDegree + 1); + for (int i = 0; i != tmpVLength; ++i) + v[i] = tmpV[i]; + } } diff --git a/fury/shaders/rt_odfs/get_sh_glyph_normal.frag b/fury/shaders/rt_odfs/get_sh_glyph_normal.frag index 4831fb8b4..e9717d815 100644 --- a/fury/shaders/rt_odfs/get_sh_glyph_normal.frag +++ b/fury/shaders/rt_odfs/get_sh_glyph_normal.frag @@ -1,16 +1,16 @@ -vec3 get_sh_glyph_normal(float sh_coeffs[SH_COUNT], vec3 point) +vec3 getShGlyphNormal(float shCoeffs[SH_COUNT], vec3 point, int shDegree, int numCoeffs) { float shs[SH_COUNT]; vec3 grads[SH_COUNT]; - float length_inv = inversesqrt(dot(point, point)); - vec3 normalized = point * length_inv; - eval_sh_grad(shs, grads, normalized); + float lengthInv = inversesqrt(dot(point, point)); + vec3 normalized = point * lengthInv; + evalShGrad(shs, grads, normalized, shDegree, numCoeffs); float value = 0.0; vec3 grad = vec3(0.0); _unroll_ - for (int i = 0; i != SH_COUNT; ++i) { - value += sh_coeffs[i] * shs[i]; - grad += sh_coeffs[i] * grads[i]; + for (int i = 0; i != numCoeffs; ++i) { + value += shCoeffs[i] * shs[i]; + grad += shCoeffs[i] * grads[i]; } - return normalize(point - (value * length_inv) * (grad - dot(grad, normalized) * normalized)); + return normalize(point - (value * lengthInv) * (grad - dot(grad, normalized) * normalized)); } diff --git a/fury/shaders/rt_odfs/gltf_dielectric_brdf.frag b/fury/shaders/rt_odfs/gltf_dielectric_brdf.frag deleted file mode 100644 index 465ab2266..000000000 --- a/fury/shaders/rt_odfs/gltf_dielectric_brdf.frag +++ /dev/null @@ -1,41 +0,0 @@ -vec3 gltf_dielectric_brdf(vec3 incoming, vec3 outgoing, vec3 normal, float roughness, vec3 base_color) -{ - float ni = dot(normal, incoming); - float no = dot(normal, outgoing); - // Early out if incoming or outgoing direction are below the horizon - if (ni <= 0.0 || no <= 0.0) - return vec3(0.0); - // Save some work by not actually computing the half-vector. If the half- - // vector were h, ih = dot(incoming, h) and - // sqrt(nh_ih_2 / ih_2) = dot(normal, h). - float ih_2 = dot(incoming, outgoing) * 0.5 + 0.5; - float sum = ni + no; - float nh_ih_2 = 0.25 * sum * sum; - float ih = sqrt(ih_2); - - // Evaluate the GGX normal distribution function - float roughness_2 = roughness * roughness; - float roughness_4 = roughness_2 * roughness_2; - float roughness_flip = 1.0 - roughness_4; - float denominator = ih_2 - nh_ih_2 * roughness_flip; - float ggx = (roughness_4 * M_INV_PI * ih_2) / (denominator * denominator); - // Evaluate the "visibility" (i.e. masking-shadowing times geometry terms) - float vi = ni + sqrt(roughness_4 + roughness_flip * ni * ni); - float vo = no + sqrt(roughness_4 + roughness_flip * no * no); - float v = 1.0 / (vi * vo); - // That completes the specular BRDF - float specular = v * ggx; - - // The diffuse BRDF is Lambertian - vec3 diffuse = M_INV_PI * base_color; - - // Evaluate the Fresnel term using the Fresnel-Schlick approximation - const float ior = 1.5; - const float f0 = ((1.0 - ior) / (1.0 + ior)) * ((1.0 - ior) / (1.0 + ior)); - float ih_flip = 1.0 - ih; - float ih_flip_2 = ih_flip * ih_flip; - float fresnel = f0 + (1.0 - f0) * ih_flip * ih_flip_2 * ih_flip_2; - - // Mix the two components - return mix(diffuse, vec3(specular), fresnel); -} diff --git a/fury/shaders/rt_odfs/ray_sh_glyph_intersections.frag b/fury/shaders/rt_odfs/ray_sh_glyph_intersections.frag index a47dbbfc4..fa72a1c2f 100644 --- a/fury/shaders/rt_odfs/ray_sh_glyph_intersections.frag +++ b/fury/shaders/rt_odfs/ray_sh_glyph_intersections.frag @@ -1,81 +1,86 @@ -void ray_sh_glyph_intersections(out float out_ray_params[MAX_DEGREE], float sh_coeffs[SH_COUNT], vec3 ray_origin, vec3 ray_dir) +void rayGlyphIntersections(out float outRayParams[MAX_DEGREE], float shCoeffs[SH_COUNT], + vec3 rayOri, vec3 rayDir, int shDegree, int numCoeffs, int maxPolyDegree, float pi, + float noIntersection) { // Determine the direction from the glyph center to the closest point on // the ray - float dir_dot_origin = dot(ray_dir, ray_origin); - vec3 closest_dir = normalize(ray_origin - dir_dot_origin * ray_dir); + float dotDirOri = dot(rayDir, rayOri); + vec3 closestDir = normalize(rayOri - dotDirOri * rayDir); // Evaluate the SH polynomial at SH_DEGREE + 1 points. That is enough to // know its value everywhere along the ray. - float sh_values[SH_DEGREE + 1]; + float shValues[SH_DEGREE + 1]; _unroll_ - for (int i = 0; i != SH_DEGREE + 1; ++i) { - vec3 point = cos(float(i) * (M_PI / float(SH_DEGREE + 1))) * ray_dir - + sin(float(i) * (M_PI / float(SH_DEGREE + 1))) * closest_dir; + for (int i = 0; i != shDegree + 1; ++i) { + vec3 point = cos(float(i) * (pi / float(shDegree + 1))) * rayDir + + sin(float(i) * (pi / float(shDegree + 1))) * closestDir; float shs[SH_COUNT]; - eval_sh(shs, point); - sh_values[i] = 0.0; + evalSH(shs, point, shDegree, numCoeffs); + shValues[i] = 0.0; _unroll_ - for (int j = 0; j != SH_COUNT; ++j) - sh_values[i] += sh_coeffs[j] * shs[j]; + for (int j = 0; j != numCoeffs; ++j) + shValues[i] += shCoeffs[j] * shs[j]; } // Compute coefficients of the SH polynomial along the ray in the - // coordinate frame given by ray_dir and closest_dir - float radius_poly[SH_DEGREE + 1]; - float inv_vander[(SH_DEGREE + 1) * (SH_DEGREE + 1)]; - get_inv_vandermonde(inv_vander); + // coordinate frame given by rayDir and closestDir + float radiusPoly[SH_DEGREE + 1]; + float invVander[(SH_DEGREE + 1) * (SH_DEGREE + 1)]; + getInvVandermonde(invVander, shDegree); _unroll_ - for (int i = 0; i != SH_DEGREE + 1; ++i) { - radius_poly[i] = 0.0; + for (int i = 0; i != shDegree + 1; ++i) { + radiusPoly[i] = 0.0; _unroll_ - for (int j = 0; j != SH_DEGREE + 1; ++j) - radius_poly[i] += inv_vander[i * (SH_DEGREE + 1) + j] * sh_values[j]; + for (int j = 0; j != shDegree + 1; ++j) + radiusPoly[i] += invVander[i * (shDegree + 1) + j] * shValues[j]; } // Compute a bounding circle around the glyph in the relevant plane - float radius_max = 0.0; + float radiusMax = 0.0; _unroll_ - for (int i = 0; i != SH_DEGREE + 1; ++i) { - float bound = sqrt(pow(float(i), float(i)) * pow(float(SH_DEGREE - i), float(SH_DEGREE - i)) / pow(float(SH_DEGREE), float(SH_DEGREE))); + for (int i = 0; i != shDegree + 1; ++i) { + float bound = sqrt( + pow(float(i), float(i)) * pow(float(shDegree - i), float(shDegree - i)) / + pow(float(shDegree), float(shDegree)) + ); // Workaround for buggy compilers where 0^0 is 0 - bound = (i == 0 || i == SH_DEGREE) ? 1.0 : bound; - radius_max += bound * abs(radius_poly[i]); + bound = (i == 0 || i == shDegree) ? 1.0 : bound; + radiusMax += bound * abs(radiusPoly[i]); } // Figure out the interval, where (if at all) the ray intersects the circle - float closest_dot_origin = dot(closest_dir, ray_origin); - if (radius_max < abs(closest_dot_origin)) { + float dotCloOri = dot(closestDir, rayOri); + if (radiusMax < abs(dotCloOri)) { _unroll_ - for (int i = 0; i != MAX_DEGREE; ++i) - out_ray_params[i] = NO_INTERSECTION; + for (int i = 0; i != maxPolyDegree; ++i) + outRayParams[i] = noIntersection; return; } - float radius_over_dot = radius_max / closest_dot_origin; - float u_max = sqrt(radius_over_dot * radius_over_dot - 1.0); - // Take the square of radius_poly + float radOverDot = radiusMax / dotCloOri; + float uMax = sqrt(radOverDot * radOverDot - 1.0); + // Take the square of radiusPoly float poly[MAX_DEGREE + 1]; _unroll_ - for (int i = 0; i != MAX_DEGREE + 1; ++i) + for (int i = 0; i != maxPolyDegree + 1; ++i) poly[i] = 0.0; _unroll_ - for (int i = 0; i != SH_DEGREE + 1; ++i) + for (int i = 0; i != shDegree + 1; ++i) _unroll_ - for (int j = 0; j != SH_DEGREE + 1; ++j) - poly[i + j] += radius_poly[i] * radius_poly[j]; + for (int j = 0; j != shDegree + 1; ++j) + poly[i + j] += radiusPoly[i] * radiusPoly[j]; // Subtract the scaled (2 * SH_DEGREE + 2)-th power of the distance to the // glyph center - float dot_sq = closest_dot_origin * closest_dot_origin; + float dotSq = dotCloOri * dotCloOri; float binomial = 1.0; _unroll_ - for (int i = 0; i != SH_DEGREE + 2; ++i) { - poly[2 * i] -= binomial * dot_sq; + for (int i = 0; i != shDegree + 2; ++i) { + poly[2 * i] -= binomial * dotSq; // Update the binomial coefficient using a recurrence relation - binomial *= float(SH_DEGREE + 1 - i) / float(i + 1); + binomial *= float(shDegree + 1 - i) / float(i + 1); } // Find roots of the polynomial within the relevant bounds float roots[MAX_DEGREE + 1]; - find_roots(roots, poly, -u_max, u_max); + findRoots(roots, poly, -uMax, uMax, maxPolyDegree, noIntersection); // Convert them back to the original coordinate frame (i.e. ray parameters) _unroll_ - for (int i = 0; i != MAX_DEGREE; ++i) - out_ray_params[i] = (roots[i] != NO_INTERSECTION) - ? (roots[i] * closest_dot_origin - dir_dot_origin) - : NO_INTERSECTION; + for (int i = 0; i != maxPolyDegree; ++i) + outRayParams[i] = (roots[i] != noIntersection) + ? (roots[i] * dotCloOri - dotDirOri) + : noIntersection; } diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_10.frag b/fury/shaders/rt_odfs/tournier/eval_sh_10.frag index bac867d98..d47efb629 100644 --- a/fury/shaders/rt_odfs/tournier/eval_sh_10.frag +++ b/fury/shaders/rt_odfs/tournier/eval_sh_10.frag @@ -1,4 +1,4 @@ -void eval_sh_10(out float out_shs[66], vec3 point) +void eval_sh_10(out float outSH[66], vec3 point) { float x, y, z, z2, c0, s0, c1, s1, d, a, b; x = point[0]; @@ -6,170 +6,170 @@ void eval_sh_10(out float out_shs[66], vec3 point) z = point[2]; z2 = z * z; d = 0.282094792; - out_shs[0] = d; + outSH[0] = d; a = z2 - 0.333333333; d = 0.946174696 * a; - out_shs[3] = d; + outSH[3] = d; b = z2 * (a - 0.266666667); a = b - 0.257142857 * a; d = 3.702494142 * a; - out_shs[10] = d; + outSH[10] = d; b = z2 * a - 0.253968254 * b; a = b - 0.252525253 * a; d = 14.684485724 * a; - out_shs[21] = d; + outSH[21] = d; b = z2 * a - 0.251748252 * b; a = b - 0.251282051 * a; d = 58.473368113 * a; - out_shs[36] = d; + outSH[36] = d; b = z2 * a - 0.250980392 * b; a = b - 0.250773994 * a; d = 233.240148813 * a; - out_shs[55] = d; + outSH[55] = d; c1 = x; s1 = y; d = -1.092548431 * z; - out_shs[4] = c1 * d; - out_shs[2] = s1 * d; + outSH[4] = c1 * d; + outSH[2] = s1 * d; a = (z2 - 0.2) * z; b = a - 0.228571429 * z; d = -4.683325805 * b; - out_shs[11] = c1 * d; - out_shs[9] = s1 * d; + outSH[11] = c1 * d; + outSH[9] = s1 * d; a = z2 * b - 0.238095238 * a; b = a - 0.242424242 * b; d = -19.226504963 * b; - out_shs[22] = c1 * d; - out_shs[20] = s1 * d; + outSH[22] = c1 * d; + outSH[20] = s1 * d; a = z2 * b - 0.244755245 * a; b = a - 0.246153846 * b; d = -77.964490818 * b; - out_shs[37] = c1 * d; - out_shs[35] = s1 * d; + outSH[37] = c1 * d; + outSH[35] = s1 * d; a = z2 * b - 0.247058824 * a; b = a - 0.247678019 * b; d = -314.500952502 * b; - out_shs[56] = c1 * d; - out_shs[54] = s1 * d; + outSH[56] = c1 * d; + outSH[54] = s1 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.546274215; - out_shs[5] = c0 * d; - out_shs[1] = s0 * d; + outSH[5] = c0 * d; + outSH[1] = s0 * d; a = z2 - 0.142857143; d = 3.311611435 * a; - out_shs[12] = c0 * d; - out_shs[8] = s0 * d; + outSH[12] = c0 * d; + outSH[8] = s0 * d; b = z2 * (a - 0.19047619); a = b - 0.212121212 * a; d = 15.199886782 * a; - out_shs[23] = c0 * d; - out_shs[19] = s0 * d; + outSH[23] = c0 * d; + outSH[19] = s0 * d; b = z2 * a - 0.223776224 * b; a = b - 0.230769231 * a; d = 65.229772956 * a; - out_shs[38] = c0 * d; - out_shs[34] = s0 * d; + outSH[38] = c0 * d; + outSH[34] = s0 * d; b = z2 * a - 0.235294118 * b; a = b - 0.238390093 * a; d = 272.365814381 * a; - out_shs[57] = c0 * d; - out_shs[53] = s0 * d; + outSH[57] = c0 * d; + outSH[53] = s0 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -1.77013077 * z; - out_shs[13] = c1 * d; - out_shs[7] = s1 * d; + outSH[13] = c1 * d; + outSH[7] = s1 * d; a = (z2 - 0.111111111) * z; b = a - 0.161616162 * z; d = -10.133257855 * b; - out_shs[24] = c1 * d; - out_shs[18] = s1 * d; + outSH[24] = c1 * d; + outSH[18] = s1 * d; a = z2 * b - 0.188811189 * a; b = a - 0.205128205 * b; d = -48.175380057 * b; - out_shs[39] = c1 * d; - out_shs[33] = s1 * d; + outSH[39] = c1 * d; + outSH[33] = s1 * d; a = z2 * b - 0.215686275 * a; b = a - 0.222910217 * b; d = -213.661323441 * b; - out_shs[58] = c1 * d; - out_shs[52] = s1 * d; + outSH[58] = c1 * d; + outSH[52] = s1 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.625835735; - out_shs[14] = c0 * d; - out_shs[6] = s0 * d; + outSH[14] = c0 * d; + outSH[6] = s0 * d; a = z2 - 9.09090909e-02; d = 5.550213908 * a; - out_shs[25] = c0 * d; - out_shs[17] = s0 * d; + outSH[25] = c0 * d; + outSH[17] = s0 * d; b = z2 * (a - 0.13986014); a = b - 0.169230769 * a; d = 31.097074109 * a; - out_shs[40] = c0 * d; - out_shs[32] = s0 * d; + outSH[40] = c0 * d; + outSH[32] = s0 * d; b = z2 * a - 0.188235294 * b; a = b - 0.20123839 * a; d = 151.081370682 * a; - out_shs[59] = c0 * d; - out_shs[51] = s0 * d; + outSH[59] = c0 * d; + outSH[51] = s0 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -2.366619162 * z; - out_shs[26] = c1 * d; - out_shs[16] = s1 * d; + outSH[26] = c1 * d; + outSH[16] = s1 * d; a = (z2 - 7.69230769e-02) * z; b = a - 0.123076923 * z; d = -17.24955311 * b; - out_shs[41] = c1 * d; - out_shs[31] = s1 * d; + outSH[41] = c1 * d; + outSH[31] = s1 * d; a = z2 * b - 0.152941176 * a; b = a - 0.173374613 * b; d = -95.552248675 * b; - out_shs[60] = c1 * d; - out_shs[50] = s1 * d; + outSH[60] = c1 * d; + outSH[50] = s1 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.683184105; - out_shs[27] = c0 * d; - out_shs[15] = s0 * d; + outSH[27] = c0 * d; + outSH[15] = s0 * d; a = z2 - 6.66666667e-02; d = 7.984991491 * a; - out_shs[42] = c0 * d; - out_shs[30] = s0 * d; + outSH[42] = c0 * d; + outSH[30] = s0 * d; b = z2 * (a - 0.109803922); a = b - 0.139318885 * a; d = 53.41533086 * a; - out_shs[61] = c0 * d; - out_shs[49] = s0 * d; + outSH[61] = c0 * d; + outSH[49] = s0 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -2.915706641 * z; - out_shs[43] = c1 * d; - out_shs[29] = s1 * d; + outSH[43] = c1 * d; + outSH[29] = s1 * d; a = (z2 - 5.88235294e-02) * z; b = a - 9.90712074e-02 * z; d = -25.910241313 * b; - out_shs[62] = c1 * d; - out_shs[48] = s1 * d; + outSH[62] = c1 * d; + outSH[48] = s1 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.72892666; - out_shs[44] = c0 * d; - out_shs[28] = s0 * d; + outSH[44] = c0 * d; + outSH[28] = s0 * d; a = z2 - 5.26315789e-02; d = 10.577811722 * a; - out_shs[63] = c0 * d; - out_shs[47] = s0 * d; + outSH[63] = c0 * d; + outSH[47] = s0 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -3.4318953 * z; - out_shs[64] = c1 * d; - out_shs[46] = s1 * d; + outSH[64] = c1 * d; + outSH[46] = s1 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.767395118; - out_shs[65] = c0 * d; - out_shs[45] = s0 * d; + outSH[65] = c0 * d; + outSH[45] = s0 * d; } diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_12.frag b/fury/shaders/rt_odfs/tournier/eval_sh_12.frag index 3bad86fd4..bad475582 100644 --- a/fury/shaders/rt_odfs/tournier/eval_sh_12.frag +++ b/fury/shaders/rt_odfs/tournier/eval_sh_12.frag @@ -1,4 +1,4 @@ -void eval_sh_12(out float out_shs[91], vec3 point) +void eval_sh_12(out float outSH[91], vec3 point) { float x, y, z, z2, c0, s0, c1, s1, d, a, b; x = point[0]; @@ -6,233 +6,233 @@ void eval_sh_12(out float out_shs[91], vec3 point) z = point[2]; z2 = z * z; d = 0.282094792; - out_shs[0] = d; + outSH[0] = d; a = z2 - 0.333333333; d = 0.946174696 * a; - out_shs[3] = d; + outSH[3] = d; b = z2 * (a - 0.266666667); a = b - 0.257142857 * a; d = 3.702494142 * a; - out_shs[10] = d; + outSH[10] = d; b = z2 * a - 0.253968254 * b; a = b - 0.252525253 * a; d = 14.684485724 * a; - out_shs[21] = d; + outSH[21] = d; b = z2 * a - 0.251748252 * b; a = b - 0.251282051 * a; d = 58.473368113 * a; - out_shs[36] = d; + outSH[36] = d; b = z2 * a - 0.250980392 * b; a = b - 0.250773994 * a; d = 233.240148813 * a; - out_shs[55] = d; + outSH[55] = d; b = z2 * a - 0.250626566 * b; a = b - 0.250517598 * a; d = 931.186918633 * a; - out_shs[78] = d; + outSH[78] = d; c1 = x; s1 = y; d = -1.092548431 * z; - out_shs[4] = c1 * d; - out_shs[2] = s1 * d; + outSH[4] = c1 * d; + outSH[2] = s1 * d; a = (z2 - 0.2) * z; b = a - 0.228571429 * z; d = -4.683325805 * b; - out_shs[11] = c1 * d; - out_shs[9] = s1 * d; + outSH[11] = c1 * d; + outSH[9] = s1 * d; a = z2 * b - 0.238095238 * a; b = a - 0.242424242 * b; d = -19.226504963 * b; - out_shs[22] = c1 * d; - out_shs[20] = s1 * d; + outSH[22] = c1 * d; + outSH[20] = s1 * d; a = z2 * b - 0.244755245 * a; b = a - 0.246153846 * b; d = -77.964490818 * b; - out_shs[37] = c1 * d; - out_shs[35] = s1 * d; + outSH[37] = c1 * d; + outSH[35] = s1 * d; a = z2 * b - 0.247058824 * a; b = a - 0.247678019 * b; d = -314.500952502 * b; - out_shs[56] = c1 * d; - out_shs[54] = s1 * d; + outSH[56] = c1 * d; + outSH[54] = s1 * d; a = z2 * b - 0.248120301 * a; b = a - 0.248447205 * b; d = -1265.233874957 * b; - out_shs[79] = c1 * d; - out_shs[77] = s1 * d; + outSH[79] = c1 * d; + outSH[77] = s1 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.546274215; - out_shs[5] = c0 * d; - out_shs[1] = s0 * d; + outSH[5] = c0 * d; + outSH[1] = s0 * d; a = z2 - 0.142857143; d = 3.311611435 * a; - out_shs[12] = c0 * d; - out_shs[8] = s0 * d; + outSH[12] = c0 * d; + outSH[8] = s0 * d; b = z2 * (a - 0.19047619); a = b - 0.212121212 * a; d = 15.199886782 * a; - out_shs[23] = c0 * d; - out_shs[19] = s0 * d; + outSH[23] = c0 * d; + outSH[19] = s0 * d; b = z2 * a - 0.223776224 * b; a = b - 0.230769231 * a; d = 65.229772956 * a; - out_shs[38] = c0 * d; - out_shs[34] = s0 * d; + outSH[38] = c0 * d; + outSH[34] = s0 * d; b = z2 * a - 0.235294118 * b; a = b - 0.238390093 * a; d = 272.365814381 * a; - out_shs[57] = c0 * d; - out_shs[53] = s0 * d; + outSH[57] = c0 * d; + outSH[53] = s0 * d; b = z2 * a - 0.240601504 * b; a = b - 0.242236025 * a; d = 1121.509962433 * a; - out_shs[80] = c0 * d; - out_shs[76] = s0 * d; + outSH[80] = c0 * d; + outSH[76] = s0 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -1.77013077 * z; - out_shs[13] = c1 * d; - out_shs[7] = s1 * d; + outSH[13] = c1 * d; + outSH[7] = s1 * d; a = (z2 - 0.111111111) * z; b = a - 0.161616162 * z; d = -10.133257855 * b; - out_shs[24] = c1 * d; - out_shs[18] = s1 * d; + outSH[24] = c1 * d; + outSH[18] = s1 * d; a = z2 * b - 0.188811189 * a; b = a - 0.205128205 * b; d = -48.175380057 * b; - out_shs[39] = c1 * d; - out_shs[33] = s1 * d; + outSH[39] = c1 * d; + outSH[33] = s1 * d; a = z2 * b - 0.215686275 * a; b = a - 0.222910217 * b; d = -213.661323441 * b; - out_shs[58] = c1 * d; - out_shs[52] = s1 * d; + outSH[58] = c1 * d; + outSH[52] = s1 * d; a = z2 * b - 0.228070175 * a; b = a - 0.231884058 * b; d = -915.709049803 * b; - out_shs[81] = c1 * d; - out_shs[75] = s1 * d; + outSH[81] = c1 * d; + outSH[75] = s1 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.625835735; - out_shs[14] = c0 * d; - out_shs[6] = s0 * d; + outSH[14] = c0 * d; + outSH[6] = s0 * d; a = z2 - 9.09090909e-02; d = 5.550213908 * a; - out_shs[25] = c0 * d; - out_shs[17] = s0 * d; + outSH[25] = c0 * d; + outSH[17] = s0 * d; b = z2 * (a - 0.13986014); a = b - 0.169230769 * a; d = 31.097074109 * a; - out_shs[40] = c0 * d; - out_shs[32] = s0 * d; + outSH[40] = c0 * d; + outSH[32] = s0 * d; b = z2 * a - 0.188235294 * b; a = b - 0.20123839 * a; d = 151.081370682 * a; - out_shs[59] = c0 * d; - out_shs[51] = s0 * d; + outSH[59] = c0 * d; + outSH[51] = s0 * d; b = z2 * a - 0.210526316 * b; a = b - 0.217391304 * a; d = 686.781787352 * a; - out_shs[82] = c0 * d; - out_shs[74] = s0 * d; + outSH[82] = c0 * d; + outSH[74] = s0 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -2.366619162 * z; - out_shs[26] = c1 * d; - out_shs[16] = s1 * d; + outSH[26] = c1 * d; + outSH[16] = s1 * d; a = (z2 - 7.69230769e-02) * z; b = a - 0.123076923 * z; d = -17.24955311 * b; - out_shs[41] = c1 * d; - out_shs[31] = s1 * d; + outSH[41] = c1 * d; + outSH[31] = s1 * d; a = z2 * b - 0.152941176 * a; b = a - 0.173374613 * b; d = -95.552248675 * b; - out_shs[60] = c1 * d; - out_shs[50] = s1 * d; + outSH[60] = c1 * d; + outSH[50] = s1 * d; a = z2 * b - 0.187969925 * a; b = a - 0.198757764 * b; d = -471.12841933 * b; - out_shs[83] = c1 * d; - out_shs[73] = s1 * d; + outSH[83] = c1 * d; + outSH[73] = s1 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.683184105; - out_shs[27] = c0 * d; - out_shs[15] = s0 * d; + outSH[27] = c0 * d; + outSH[15] = s0 * d; a = z2 - 6.66666667e-02; d = 7.984991491 * a; - out_shs[42] = c0 * d; - out_shs[30] = s0 * d; + outSH[42] = c0 * d; + outSH[30] = s0 * d; b = z2 * (a - 0.109803922); a = b - 0.139318885 * a; d = 53.41533086 * a; - out_shs[61] = c0 * d; - out_shs[49] = s0 * d; + outSH[61] = c0 * d; + outSH[49] = s0 * d; b = z2 * a - 0.160401003 * b; a = b - 0.175983437 * a; d = 293.800188384 * a; - out_shs[84] = c0 * d; - out_shs[72] = s0 * d; + outSH[84] = c0 * d; + outSH[72] = s0 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -2.915706641 * z; - out_shs[43] = c1 * d; - out_shs[29] = s1 * d; + outSH[43] = c1 * d; + outSH[29] = s1 * d; a = (z2 - 5.88235294e-02) * z; b = a - 9.90712074e-02 * z; d = -25.910241313 * b; - out_shs[62] = c1 * d; - out_shs[48] = s1 * d; + outSH[62] = c1 * d; + outSH[48] = s1 * d; a = z2 * b - 0.127819549 * a; b = a - 0.149068323 * b; d = -165.101452729 * b; - out_shs[85] = c1 * d; - out_shs[71] = s1 * d; + outSH[85] = c1 * d; + outSH[71] = s1 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.72892666; - out_shs[44] = c0 * d; - out_shs[28] = s0 * d; + outSH[44] = c0 * d; + outSH[28] = s0 * d; a = z2 - 5.26315789e-02; d = 10.577811722 * a; - out_shs[63] = c0 * d; - out_shs[47] = s0 * d; + outSH[63] = c0 * d; + outSH[47] = s0 * d; b = z2 * (a - 9.02255639e-02); a = b - 0.118012422 * a; d = 82.550726364 * a; - out_shs[86] = c0 * d; - out_shs[70] = s0 * d; + outSH[86] = c0 * d; + outSH[70] = s0 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -3.4318953 * z; - out_shs[64] = c1 * d; - out_shs[46] = s1 * d; + outSH[64] = c1 * d; + outSH[46] = s1 * d; a = (z2 - 4.76190476e-02) * z; b = a - 8.2815735e-02 * z; d = -36.028090689 * b; - out_shs[87] = c1 * d; - out_shs[69] = s1 * d; + outSH[87] = c1 * d; + outSH[69] = s1 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.767395118; - out_shs[65] = c0 * d; - out_shs[45] = s0 * d; + outSH[65] = c0 * d; + outSH[45] = s0 * d; a = z2 - 4.34782609e-02; d = 13.3042542 * a; - out_shs[88] = c0 * d; - out_shs[68] = s0 * d; + outSH[88] = c0 * d; + outSH[68] = s0 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -3.923210529 * z; - out_shs[89] = c1 * d; - out_shs[67] = s1 * d; + outSH[89] = c1 * d; + outSH[67] = s1 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.800821996; - out_shs[90] = c0 * d; - out_shs[66] = s0 * d; + outSH[90] = c0 * d; + outSH[66] = s0 * d; } diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_2.frag b/fury/shaders/rt_odfs/tournier/eval_sh_2.frag index a70493a22..98dfa2d0a 100644 --- a/fury/shaders/rt_odfs/tournier/eval_sh_2.frag +++ b/fury/shaders/rt_odfs/tournier/eval_sh_2.frag @@ -1,4 +1,4 @@ -void eval_sh_2(out float out_shs[6], vec3 point) +void eval_sh_2(out float outSH[6], vec3 point) { float x, y, z, z2, c0, s0, c1, s1, d, a; x = point[0]; @@ -6,18 +6,18 @@ void eval_sh_2(out float out_shs[6], vec3 point) z = point[2]; z2 = z * z; d = 0.282094792; - out_shs[0] = d; + outSH[0] = d; a = z2 - 0.333333333; d = 0.946174696 * a; - out_shs[3] = d; + outSH[3] = d; c1 = x; s1 = y; d = -1.092548431 * z; - out_shs[4] = c1 * d; - out_shs[2] = s1 * d; + outSH[4] = c1 * d; + outSH[2] = s1 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.546274215; - out_shs[5] = c0 * d; - out_shs[1] = s0 * d; + outSH[5] = c0 * d; + outSH[1] = s0 * d; } diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_4.frag b/fury/shaders/rt_odfs/tournier/eval_sh_4.frag index 15335ccad..0ea37caa4 100644 --- a/fury/shaders/rt_odfs/tournier/eval_sh_4.frag +++ b/fury/shaders/rt_odfs/tournier/eval_sh_4.frag @@ -1,4 +1,4 @@ -void eval_sh_4(out float out_shs[15], vec3 point) +void eval_sh_4(out float outSH[15], vec3 point) { float x, y, z, z2, c0, s0, c1, s1, d, a, b; x = point[0]; @@ -6,41 +6,41 @@ void eval_sh_4(out float out_shs[15], vec3 point) z = point[2]; z2 = z * z; d = 0.282094792; - out_shs[0] = d; + outSH[0] = d; a = z2 - 0.333333333; d = 0.946174696 * a; - out_shs[3] = d; + outSH[3] = d; b = z2 * (a - 0.266666667); a = b - 0.257142857 * a; d = 3.702494142 * a; - out_shs[10] = d; + outSH[10] = d; c1 = x; s1 = y; d = -1.092548431 * z; - out_shs[4] = c1 * d; - out_shs[2] = s1 * d; + outSH[4] = c1 * d; + outSH[2] = s1 * d; a = (z2 - 0.2) * z; b = a - 0.228571429 * z; d = -4.683325805 * b; - out_shs[11] = c1 * d; - out_shs[9] = s1 * d; + outSH[11] = c1 * d; + outSH[9] = s1 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.546274215; - out_shs[5] = c0 * d; - out_shs[1] = s0 * d; + outSH[5] = c0 * d; + outSH[1] = s0 * d; a = z2 - 0.142857143; d = 3.311611435 * a; - out_shs[12] = c0 * d; - out_shs[8] = s0 * d; + outSH[12] = c0 * d; + outSH[8] = s0 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -1.77013077 * z; - out_shs[13] = c1 * d; - out_shs[7] = s1 * d; + outSH[13] = c1 * d; + outSH[7] = s1 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.625835735; - out_shs[14] = c0 * d; - out_shs[6] = s0 * d; + outSH[14] = c0 * d; + outSH[6] = s0 * d; } diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_6.frag b/fury/shaders/rt_odfs/tournier/eval_sh_6.frag index 1051361dd..1d17b9b8b 100644 --- a/fury/shaders/rt_odfs/tournier/eval_sh_6.frag +++ b/fury/shaders/rt_odfs/tournier/eval_sh_6.frag @@ -1,4 +1,4 @@ -void eval_sh_6(out float out_shs[28], vec3 point) +void eval_sh_6(out float outSH[28], vec3 point) { float x, y, z, z2, c0, s0, c1, s1, d, a, b; x = point[0]; @@ -6,74 +6,74 @@ void eval_sh_6(out float out_shs[28], vec3 point) z = point[2]; z2 = z * z; d = 0.282094792; - out_shs[0] = d; + outSH[0] = d; a = z2 - 0.333333333; d = 0.946174696 * a; - out_shs[3] = d; + outSH[3] = d; b = z2 * (a - 0.266666667); a = b - 0.257142857 * a; d = 3.702494142 * a; - out_shs[10] = d; + outSH[10] = d; b = z2 * a - 0.253968254 * b; a = b - 0.252525253 * a; d = 14.684485724 * a; - out_shs[21] = d; + outSH[21] = d; c1 = x; s1 = y; d = -1.092548431 * z; - out_shs[4] = c1 * d; - out_shs[2] = s1 * d; + outSH[4] = c1 * d; + outSH[2] = s1 * d; a = (z2 - 0.2) * z; b = a - 0.228571429 * z; d = -4.683325805 * b; - out_shs[11] = c1 * d; - out_shs[9] = s1 * d; + outSH[11] = c1 * d; + outSH[9] = s1 * d; a = z2 * b - 0.238095238 * a; b = a - 0.242424242 * b; d = -19.226504963 * b; - out_shs[22] = c1 * d; - out_shs[20] = s1 * d; + outSH[22] = c1 * d; + outSH[20] = s1 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.546274215; - out_shs[5] = c0 * d; - out_shs[1] = s0 * d; + outSH[5] = c0 * d; + outSH[1] = s0 * d; a = z2 - 0.142857143; d = 3.311611435 * a; - out_shs[12] = c0 * d; - out_shs[8] = s0 * d; + outSH[12] = c0 * d; + outSH[8] = s0 * d; b = z2 * (a - 0.19047619); a = b - 0.212121212 * a; d = 15.199886782 * a; - out_shs[23] = c0 * d; - out_shs[19] = s0 * d; + outSH[23] = c0 * d; + outSH[19] = s0 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -1.77013077 * z; - out_shs[13] = c1 * d; - out_shs[7] = s1 * d; + outSH[13] = c1 * d; + outSH[7] = s1 * d; a = (z2 - 0.111111111) * z; b = a - 0.161616162 * z; d = -10.133257855 * b; - out_shs[24] = c1 * d; - out_shs[18] = s1 * d; + outSH[24] = c1 * d; + outSH[18] = s1 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.625835735; - out_shs[14] = c0 * d; - out_shs[6] = s0 * d; + outSH[14] = c0 * d; + outSH[6] = s0 * d; a = z2 - 9.09090909e-02; d = 5.550213908 * a; - out_shs[25] = c0 * d; - out_shs[17] = s0 * d; + outSH[25] = c0 * d; + outSH[17] = s0 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -2.366619162 * z; - out_shs[26] = c1 * d; - out_shs[16] = s1 * d; + outSH[26] = c1 * d; + outSH[16] = s1 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.683184105; - out_shs[27] = c0 * d; - out_shs[15] = s0 * d; + outSH[27] = c0 * d; + outSH[15] = s0 * d; } diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_8.frag b/fury/shaders/rt_odfs/tournier/eval_sh_8.frag index 93c32e613..6550fc525 100644 --- a/fury/shaders/rt_odfs/tournier/eval_sh_8.frag +++ b/fury/shaders/rt_odfs/tournier/eval_sh_8.frag @@ -1,4 +1,4 @@ -void eval_sh_8(out float out_shs[45], vec3 point) +void eval_sh_8(out float outSH[45], vec3 point) { float x, y, z, z2, c0, s0, c1, s1, d, a, b; x = point[0]; @@ -6,117 +6,117 @@ void eval_sh_8(out float out_shs[45], vec3 point) z = point[2]; z2 = z * z; d = 0.282094792; - out_shs[0] = d; + outSH[0] = d; a = z2 - 0.333333333; d = 0.946174696 * a; - out_shs[3] = d; + outSH[3] = d; b = z2 * (a - 0.266666667); a = b - 0.257142857 * a; d = 3.702494142 * a; - out_shs[10] = d; + outSH[10] = d; b = z2 * a - 0.253968254 * b; a = b - 0.252525253 * a; d = 14.684485724 * a; - out_shs[21] = d; + outSH[21] = d; b = z2 * a - 0.251748252 * b; a = b - 0.251282051 * a; d = 58.473368113 * a; - out_shs[36] = d; + outSH[36] = d; c1 = x; s1 = y; d = -1.092548431 * z; - out_shs[4] = c1 * d; - out_shs[2] = s1 * d; + outSH[4] = c1 * d; + outSH[2] = s1 * d; a = (z2 - 0.2) * z; b = a - 0.228571429 * z; d = -4.683325805 * b; - out_shs[11] = c1 * d; - out_shs[9] = s1 * d; + outSH[11] = c1 * d; + outSH[9] = s1 * d; a = z2 * b - 0.238095238 * a; b = a - 0.242424242 * b; d = -19.226504963 * b; - out_shs[22] = c1 * d; - out_shs[20] = s1 * d; + outSH[22] = c1 * d; + outSH[20] = s1 * d; a = z2 * b - 0.244755245 * a; b = a - 0.246153846 * b; d = -77.964490818 * b; - out_shs[37] = c1 * d; - out_shs[35] = s1 * d; + outSH[37] = c1 * d; + outSH[35] = s1 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.546274215; - out_shs[5] = c0 * d; - out_shs[1] = s0 * d; + outSH[5] = c0 * d; + outSH[1] = s0 * d; a = z2 - 0.142857143; d = 3.311611435 * a; - out_shs[12] = c0 * d; - out_shs[8] = s0 * d; + outSH[12] = c0 * d; + outSH[8] = s0 * d; b = z2 * (a - 0.19047619); a = b - 0.212121212 * a; d = 15.199886782 * a; - out_shs[23] = c0 * d; - out_shs[19] = s0 * d; + outSH[23] = c0 * d; + outSH[19] = s0 * d; b = z2 * a - 0.223776224 * b; a = b - 0.230769231 * a; d = 65.229772956 * a; - out_shs[38] = c0 * d; - out_shs[34] = s0 * d; + outSH[38] = c0 * d; + outSH[34] = s0 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -1.77013077 * z; - out_shs[13] = c1 * d; - out_shs[7] = s1 * d; + outSH[13] = c1 * d; + outSH[7] = s1 * d; a = (z2 - 0.111111111) * z; b = a - 0.161616162 * z; d = -10.133257855 * b; - out_shs[24] = c1 * d; - out_shs[18] = s1 * d; + outSH[24] = c1 * d; + outSH[18] = s1 * d; a = z2 * b - 0.188811189 * a; b = a - 0.205128205 * b; d = -48.175380057 * b; - out_shs[39] = c1 * d; - out_shs[33] = s1 * d; + outSH[39] = c1 * d; + outSH[33] = s1 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.625835735; - out_shs[14] = c0 * d; - out_shs[6] = s0 * d; + outSH[14] = c0 * d; + outSH[6] = s0 * d; a = z2 - 9.09090909e-02; d = 5.550213908 * a; - out_shs[25] = c0 * d; - out_shs[17] = s0 * d; + outSH[25] = c0 * d; + outSH[17] = s0 * d; b = z2 * (a - 0.13986014); a = b - 0.169230769 * a; d = 31.097074109 * a; - out_shs[40] = c0 * d; - out_shs[32] = s0 * d; + outSH[40] = c0 * d; + outSH[32] = s0 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -2.366619162 * z; - out_shs[26] = c1 * d; - out_shs[16] = s1 * d; + outSH[26] = c1 * d; + outSH[16] = s1 * d; a = (z2 - 7.69230769e-02) * z; b = a - 0.123076923 * z; d = -17.24955311 * b; - out_shs[41] = c1 * d; - out_shs[31] = s1 * d; + outSH[41] = c1 * d; + outSH[31] = s1 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.683184105; - out_shs[27] = c0 * d; - out_shs[15] = s0 * d; + outSH[27] = c0 * d; + outSH[15] = s0 * d; a = z2 - 6.66666667e-02; d = 7.984991491 * a; - out_shs[42] = c0 * d; - out_shs[30] = s0 * d; + outSH[42] = c0 * d; + outSH[30] = s0 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -2.915706641 * z; - out_shs[43] = c1 * d; - out_shs[29] = s1 * d; + outSH[43] = c1 * d; + outSH[29] = s1 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.72892666; - out_shs[44] = c0 * d; - out_shs[28] = s0 * d; + outSH[44] = c0 * d; + outSH[28] = s0 * d; } diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_10.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_10.frag index c9e6b0d8d..ace867b13 100644 --- a/fury/shaders/rt_odfs/tournier/eval_sh_grad_10.frag +++ b/fury/shaders/rt_odfs/tournier/eval_sh_grad_10.frag @@ -1,4 +1,4 @@ -void eval_sh_grad_10(out float out_shs[66], out vec3 out_grads[66], vec3 point) +void evalShGrad10(out float outSH[66], out vec3 outGrads[66], vec3 point) { float x, y, z, z2, c0, s0, c1, s1, d, a, b; x = point[0]; @@ -8,423 +8,423 @@ void eval_sh_grad_10(out float out_shs[66], out vec3 out_grads[66], vec3 point) c0 = 1.0; s0 = 0.0; d = 0.282094792; - out_shs[0] = d; + outSH[0] = d; a = z2 - 0.333333333; d = 0.946174696 * a; - out_shs[3] = d; + outSH[3] = d; b = z2 * (a - 0.266666667); a = b - 0.257142857 * a; d = 3.702494142 * a; - out_shs[10] = d; + outSH[10] = d; b = z2 * a - 0.253968254 * b; a = b - 0.252525253 * a; d = 14.684485724 * a; - out_shs[21] = d; + outSH[21] = d; b = z2 * a - 0.251748252 * b; a = b - 0.251282051 * a; d = 58.473368113 * a; - out_shs[36] = d; + outSH[36] = d; b = z2 * a - 0.250980392 * b; a = b - 0.250773994 * a; d = 233.240148813 * a; - out_shs[55] = d; + outSH[55] = d; c1 = x; s1 = y; d = -1.092548431 * z; - out_shs[4] = c1 * d; - out_shs[2] = s1 * d; - out_grads[4][0] = c0 * d; - out_grads[2][0] = s0 * d; - out_grads[4][1] = s0 * d; - out_grads[2][1] = c0 * d; + outSH[4] = c1 * d; + outSH[2] = s1 * d; + outGrads[4][0] = c0 * d; + outGrads[2][0] = s0 * d; + outGrads[4][1] = s0 * d; + outGrads[2][1] = c0 * d; d = 1.892349392 * z; - out_grads[3][2] = d; + outGrads[3][2] = d; a = (z2 - 0.2) * z; b = a - 0.228571429 * z; d = -4.683325805 * b; - out_shs[11] = c1 * d; - out_shs[9] = s1 * d; - out_grads[11][0] = c0 * d; - out_grads[9][0] = s0 * d; - out_grads[11][1] = s0 * d; - out_grads[9][1] = c0 * d; + outSH[11] = c1 * d; + outSH[9] = s1 * d; + outGrads[11][0] = c0 * d; + outGrads[9][0] = s0 * d; + outGrads[11][1] = s0 * d; + outGrads[9][1] = c0 * d; d = 14.809976568 * b; - out_grads[10][2] = d; + outGrads[10][2] = d; a = z2 * b - 0.238095238 * a; b = a - 0.242424242 * b; d = -19.226504963 * b; - out_shs[22] = c1 * d; - out_shs[20] = s1 * d; - out_grads[22][0] = c0 * d; - out_grads[20][0] = s0 * d; - out_grads[22][1] = s0 * d; - out_grads[20][1] = c0 * d; + outSH[22] = c1 * d; + outSH[20] = s1 * d; + outGrads[22][0] = c0 * d; + outGrads[20][0] = s0 * d; + outGrads[22][1] = s0 * d; + outGrads[20][1] = c0 * d; d = 88.106914343 * b; - out_grads[21][2] = d; + outGrads[21][2] = d; a = z2 * b - 0.244755245 * a; b = a - 0.246153846 * b; d = -77.964490818 * b; - out_shs[37] = c1 * d; - out_shs[35] = s1 * d; - out_grads[37][0] = c0 * d; - out_grads[35][0] = s0 * d; - out_grads[37][1] = s0 * d; - out_grads[35][1] = c0 * d; + outSH[37] = c1 * d; + outSH[35] = s1 * d; + outGrads[37][0] = c0 * d; + outGrads[35][0] = s0 * d; + outGrads[37][1] = s0 * d; + outGrads[35][1] = c0 * d; d = 467.786944906 * b; - out_grads[36][2] = d; + outGrads[36][2] = d; a = z2 * b - 0.247058824 * a; b = a - 0.247678019 * b; d = -314.500952502 * b; - out_shs[56] = c1 * d; - out_shs[54] = s1 * d; - out_grads[56][0] = c0 * d; - out_grads[54][0] = s0 * d; - out_grads[56][1] = s0 * d; - out_grads[54][1] = c0 * d; + outSH[56] = c1 * d; + outSH[54] = s1 * d; + outGrads[56][0] = c0 * d; + outGrads[54][0] = s0 * d; + outGrads[56][1] = s0 * d; + outGrads[54][1] = c0 * d; d = 2332.401488133 * b; - out_grads[55][2] = d; + outGrads[55][2] = d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.546274215; - out_shs[5] = c0 * d; - out_shs[1] = s0 * d; + outSH[5] = c0 * d; + outSH[1] = s0 * d; d = 1.092548431; - out_grads[5][0] = c1 * d; - out_grads[1][0] = s1 * d; - out_grads[5][1] = -s1 * d; - out_grads[1][1] = c1 * d; + outGrads[5][0] = c1 * d; + outGrads[1][0] = s1 * d; + outGrads[5][1] = -s1 * d; + outGrads[1][1] = c1 * d; d = -1.092548431; - out_grads[4][2] = c1 * d; - out_grads[2][2] = s1 * d; + outGrads[4][2] = c1 * d; + outGrads[2][2] = s1 * d; a = z2 - 0.142857143; d = 3.311611435 * a; - out_shs[12] = c0 * d; - out_shs[8] = s0 * d; + outSH[12] = c0 * d; + outSH[8] = s0 * d; d = 6.62322287 * a; - out_grads[12][0] = c1 * d; - out_grads[8][0] = s1 * d; - out_grads[12][1] = -s1 * d; - out_grads[8][1] = c1 * d; + outGrads[12][0] = c1 * d; + outGrads[8][0] = s1 * d; + outGrads[12][1] = -s1 * d; + outGrads[8][1] = c1 * d; d = -14.049977415 * a; - out_grads[11][2] = c1 * d; - out_grads[9][2] = s1 * d; + outGrads[11][2] = c1 * d; + outGrads[9][2] = s1 * d; b = z2 * (a - 0.19047619); a = b - 0.212121212 * a; d = 15.199886782 * a; - out_shs[23] = c0 * d; - out_shs[19] = s0 * d; + outSH[23] = c0 * d; + outSH[19] = s0 * d; d = 30.399773564 * a; - out_grads[23][0] = c1 * d; - out_grads[19][0] = s1 * d; - out_grads[23][1] = -s1 * d; - out_grads[19][1] = c1 * d; + outGrads[23][0] = c1 * d; + outGrads[19][0] = s1 * d; + outGrads[23][1] = -s1 * d; + outGrads[19][1] = c1 * d; d = -96.132524816 * a; - out_grads[22][2] = c1 * d; - out_grads[20][2] = s1 * d; + outGrads[22][2] = c1 * d; + outGrads[20][2] = s1 * d; b = z2 * a - 0.223776224 * b; a = b - 0.230769231 * a; d = 65.229772956 * a; - out_shs[38] = c0 * d; - out_shs[34] = s0 * d; + outSH[38] = c0 * d; + outSH[34] = s0 * d; d = 130.459545912 * a; - out_grads[38][0] = c1 * d; - out_grads[34][0] = s1 * d; - out_grads[38][1] = -s1 * d; - out_grads[34][1] = c1 * d; + outGrads[38][0] = c1 * d; + outGrads[34][0] = s1 * d; + outGrads[38][1] = -s1 * d; + outGrads[34][1] = c1 * d; d = -545.751435723 * a; - out_grads[37][2] = c1 * d; - out_grads[35][2] = s1 * d; + outGrads[37][2] = c1 * d; + outGrads[35][2] = s1 * d; b = z2 * a - 0.235294118 * b; a = b - 0.238390093 * a; d = 272.365814381 * a; - out_shs[57] = c0 * d; - out_shs[53] = s0 * d; + outSH[57] = c0 * d; + outSH[53] = s0 * d; d = 544.731628762 * a; - out_grads[57][0] = c1 * d; - out_grads[53][0] = s1 * d; - out_grads[57][1] = -s1 * d; - out_grads[53][1] = c1 * d; + outGrads[57][0] = c1 * d; + outGrads[53][0] = s1 * d; + outGrads[57][1] = -s1 * d; + outGrads[53][1] = c1 * d; d = -2830.508572514 * a; - out_grads[56][2] = c1 * d; - out_grads[54][2] = s1 * d; + outGrads[56][2] = c1 * d; + outGrads[54][2] = s1 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -1.77013077 * z; - out_shs[13] = c1 * d; - out_shs[7] = s1 * d; + outSH[13] = c1 * d; + outSH[7] = s1 * d; d = -5.310392309 * z; - out_grads[13][0] = c0 * d; - out_grads[7][0] = s0 * d; - out_grads[13][1] = s0 * d; - out_grads[7][1] = c0 * d; + outGrads[13][0] = c0 * d; + outGrads[7][0] = s0 * d; + outGrads[13][1] = s0 * d; + outGrads[7][1] = c0 * d; d = 6.62322287 * z; - out_grads[12][2] = c0 * d; - out_grads[8][2] = s0 * d; + outGrads[12][2] = c0 * d; + outGrads[8][2] = s0 * d; a = (z2 - 0.111111111) * z; b = a - 0.161616162 * z; d = -10.133257855 * b; - out_shs[24] = c1 * d; - out_shs[18] = s1 * d; + outSH[24] = c1 * d; + outSH[18] = s1 * d; d = -30.399773564 * b; - out_grads[24][0] = c0 * d; - out_grads[18][0] = s0 * d; - out_grads[24][1] = s0 * d; - out_grads[18][1] = c0 * d; + outGrads[24][0] = c0 * d; + outGrads[18][0] = s0 * d; + outGrads[24][1] = s0 * d; + outGrads[18][1] = c0 * d; d = 60.799547128 * b; - out_grads[23][2] = c0 * d; - out_grads[19][2] = s0 * d; + outGrads[23][2] = c0 * d; + outGrads[19][2] = s0 * d; a = z2 * b - 0.188811189 * a; b = a - 0.205128205 * b; d = -48.175380057 * b; - out_shs[39] = c1 * d; - out_shs[33] = s1 * d; + outSH[39] = c1 * d; + outSH[33] = s1 * d; d = -144.52614017 * b; - out_grads[39][0] = c0 * d; - out_grads[33][0] = s0 * d; - out_grads[39][1] = s0 * d; - out_grads[33][1] = c0 * d; + outGrads[39][0] = c0 * d; + outGrads[33][0] = s0 * d; + outGrads[39][1] = s0 * d; + outGrads[33][1] = c0 * d; d = 391.378637737 * b; - out_grads[38][2] = c0 * d; - out_grads[34][2] = s0 * d; + outGrads[38][2] = c0 * d; + outGrads[34][2] = s0 * d; a = z2 * b - 0.215686275 * a; b = a - 0.222910217 * b; d = -213.661323441 * b; - out_shs[58] = c1 * d; - out_shs[52] = s1 * d; + outSH[58] = c1 * d; + outSH[52] = s1 * d; d = -640.983970322 * b; - out_grads[58][0] = c0 * d; - out_grads[52][0] = s0 * d; - out_grads[58][1] = s0 * d; - out_grads[52][1] = c0 * d; + outGrads[58][0] = c0 * d; + outGrads[52][0] = s0 * d; + outGrads[58][1] = s0 * d; + outGrads[52][1] = c0 * d; d = 2178.926515046 * b; - out_grads[57][2] = c0 * d; - out_grads[53][2] = s0 * d; + outGrads[57][2] = c0 * d; + outGrads[53][2] = s0 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.625835735; - out_shs[14] = c0 * d; - out_shs[6] = s0 * d; + outSH[14] = c0 * d; + outSH[6] = s0 * d; d = 2.503342942; - out_grads[14][0] = c1 * d; - out_grads[6][0] = s1 * d; - out_grads[14][1] = -s1 * d; - out_grads[6][1] = c1 * d; + outGrads[14][0] = c1 * d; + outGrads[6][0] = s1 * d; + outGrads[14][1] = -s1 * d; + outGrads[6][1] = c1 * d; d = -1.77013077; - out_grads[13][2] = c1 * d; - out_grads[7][2] = s1 * d; + outGrads[13][2] = c1 * d; + outGrads[7][2] = s1 * d; a = z2 - 9.09090909e-02; d = 5.550213908 * a; - out_shs[25] = c0 * d; - out_shs[17] = s0 * d; + outSH[25] = c0 * d; + outSH[17] = s0 * d; d = 22.200855632 * a; - out_grads[25][0] = c1 * d; - out_grads[17][0] = s1 * d; - out_grads[25][1] = -s1 * d; - out_grads[17][1] = c1 * d; + outGrads[25][0] = c1 * d; + outGrads[17][0] = s1 * d; + outGrads[25][1] = -s1 * d; + outGrads[17][1] = c1 * d; d = -30.399773564 * a; - out_grads[24][2] = c1 * d; - out_grads[18][2] = s1 * d; + outGrads[24][2] = c1 * d; + outGrads[18][2] = s1 * d; b = z2 * (a - 0.13986014); a = b - 0.169230769 * a; d = 31.097074109 * a; - out_shs[40] = c0 * d; - out_shs[32] = s0 * d; + outSH[40] = c0 * d; + outSH[32] = s0 * d; d = 124.388296437 * a; - out_grads[40][0] = c1 * d; - out_grads[32][0] = s1 * d; - out_grads[40][1] = -s1 * d; - out_grads[32][1] = c1 * d; + outGrads[40][0] = c1 * d; + outGrads[32][0] = s1 * d; + outGrads[40][1] = -s1 * d; + outGrads[32][1] = c1 * d; d = -240.876900283 * a; - out_grads[39][2] = c1 * d; - out_grads[33][2] = s1 * d; + outGrads[39][2] = c1 * d; + outGrads[33][2] = s1 * d; b = z2 * a - 0.188235294 * b; a = b - 0.20123839 * a; d = 151.081370682 * a; - out_shs[59] = c0 * d; - out_shs[51] = s0 * d; + outSH[59] = c0 * d; + outSH[51] = s0 * d; d = 604.325482728 * a; - out_grads[59][0] = c1 * d; - out_grads[51][0] = s1 * d; - out_grads[59][1] = -s1 * d; - out_grads[51][1] = c1 * d; + outGrads[59][0] = c1 * d; + outGrads[51][0] = s1 * d; + outGrads[59][1] = -s1 * d; + outGrads[51][1] = c1 * d; d = -1495.629264084 * a; - out_grads[58][2] = c1 * d; - out_grads[52][2] = s1 * d; + outGrads[58][2] = c1 * d; + outGrads[52][2] = s1 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -2.366619162 * z; - out_shs[26] = c1 * d; - out_shs[16] = s1 * d; + outSH[26] = c1 * d; + outSH[16] = s1 * d; d = -11.833095811 * z; - out_grads[26][0] = c0 * d; - out_grads[16][0] = s0 * d; - out_grads[26][1] = s0 * d; - out_grads[16][1] = c0 * d; + outGrads[26][0] = c0 * d; + outGrads[16][0] = s0 * d; + outGrads[26][1] = s0 * d; + outGrads[16][1] = c0 * d; d = 11.100427816 * z; - out_grads[25][2] = c0 * d; - out_grads[17][2] = s0 * d; + outGrads[25][2] = c0 * d; + outGrads[17][2] = s0 * d; a = (z2 - 7.69230769e-02) * z; b = a - 0.123076923 * z; d = -17.24955311 * b; - out_shs[41] = c1 * d; - out_shs[31] = s1 * d; + outSH[41] = c1 * d; + outSH[31] = s1 * d; d = -86.247765552 * b; - out_grads[41][0] = c0 * d; - out_grads[31][0] = s0 * d; - out_grads[41][1] = s0 * d; - out_grads[31][1] = c0 * d; + outGrads[41][0] = c0 * d; + outGrads[31][0] = s0 * d; + outGrads[41][1] = s0 * d; + outGrads[31][1] = c0 * d; d = 124.388296437 * b; - out_grads[40][2] = c0 * d; - out_grads[32][2] = s0 * d; + outGrads[40][2] = c0 * d; + outGrads[32][2] = s0 * d; a = z2 * b - 0.152941176 * a; b = a - 0.173374613 * b; d = -95.552248675 * b; - out_shs[60] = c1 * d; - out_shs[50] = s1 * d; + outSH[60] = c1 * d; + outSH[50] = s1 * d; d = -477.761243376 * b; - out_grads[60][0] = c0 * d; - out_grads[50][0] = s0 * d; - out_grads[60][1] = s0 * d; - out_grads[50][1] = c0 * d; + outGrads[60][0] = c0 * d; + outGrads[50][0] = s0 * d; + outGrads[60][1] = s0 * d; + outGrads[50][1] = c0 * d; d = 906.488224092 * b; - out_grads[59][2] = c0 * d; - out_grads[51][2] = s0 * d; + outGrads[59][2] = c0 * d; + outGrads[51][2] = s0 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.683184105; - out_shs[27] = c0 * d; - out_shs[15] = s0 * d; + outSH[27] = c0 * d; + outSH[15] = s0 * d; d = 4.099104631; - out_grads[27][0] = c1 * d; - out_grads[15][0] = s1 * d; - out_grads[27][1] = -s1 * d; - out_grads[15][1] = c1 * d; + outGrads[27][0] = c1 * d; + outGrads[15][0] = s1 * d; + outGrads[27][1] = -s1 * d; + outGrads[15][1] = c1 * d; d = -2.366619162; - out_grads[26][2] = c1 * d; - out_grads[16][2] = s1 * d; + outGrads[26][2] = c1 * d; + outGrads[16][2] = s1 * d; a = z2 - 6.66666667e-02; d = 7.984991491 * a; - out_shs[42] = c0 * d; - out_shs[30] = s0 * d; + outSH[42] = c0 * d; + outSH[30] = s0 * d; d = 47.909948945 * a; - out_grads[42][0] = c1 * d; - out_grads[30][0] = s1 * d; - out_grads[42][1] = -s1 * d; - out_grads[30][1] = c1 * d; + outGrads[42][0] = c1 * d; + outGrads[30][0] = s1 * d; + outGrads[42][1] = -s1 * d; + outGrads[30][1] = c1 * d; d = -51.748659331 * a; - out_grads[41][2] = c1 * d; - out_grads[31][2] = s1 * d; + outGrads[41][2] = c1 * d; + outGrads[31][2] = s1 * d; b = z2 * (a - 0.109803922); a = b - 0.139318885 * a; d = 53.41533086 * a; - out_shs[61] = c0 * d; - out_shs[49] = s0 * d; + outSH[61] = c0 * d; + outSH[49] = s0 * d; d = 320.491985161 * a; - out_grads[61][0] = c1 * d; - out_grads[49][0] = s1 * d; - out_grads[61][1] = -s1 * d; - out_grads[49][1] = c1 * d; + outGrads[61][0] = c1 * d; + outGrads[49][0] = s1 * d; + outGrads[61][1] = -s1 * d; + outGrads[49][1] = c1 * d; d = -477.761243376 * a; - out_grads[60][2] = c1 * d; - out_grads[50][2] = s1 * d; + outGrads[60][2] = c1 * d; + outGrads[50][2] = s1 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -2.915706641 * z; - out_shs[43] = c1 * d; - out_shs[29] = s1 * d; + outSH[43] = c1 * d; + outSH[29] = s1 * d; d = -20.409946485 * z; - out_grads[43][0] = c0 * d; - out_grads[29][0] = s0 * d; - out_grads[43][1] = s0 * d; - out_grads[29][1] = c0 * d; + outGrads[43][0] = c0 * d; + outGrads[29][0] = s0 * d; + outGrads[43][1] = s0 * d; + outGrads[29][1] = c0 * d; d = 15.969982982 * z; - out_grads[42][2] = c0 * d; - out_grads[30][2] = s0 * d; + outGrads[42][2] = c0 * d; + outGrads[30][2] = s0 * d; a = (z2 - 5.88235294e-02) * z; b = a - 9.90712074e-02 * z; d = -25.910241313 * b; - out_shs[62] = c1 * d; - out_shs[48] = s1 * d; + outSH[62] = c1 * d; + outSH[48] = s1 * d; d = -181.371689194 * b; - out_grads[62][0] = c0 * d; - out_grads[48][0] = s0 * d; - out_grads[62][1] = s0 * d; - out_grads[48][1] = c0 * d; + outGrads[62][0] = c0 * d; + outGrads[48][0] = s0 * d; + outGrads[62][1] = s0 * d; + outGrads[48][1] = c0 * d; d = 213.661323441 * b; - out_grads[61][2] = c0 * d; - out_grads[49][2] = s0 * d; + outGrads[61][2] = c0 * d; + outGrads[49][2] = s0 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.72892666; - out_shs[44] = c0 * d; - out_shs[28] = s0 * d; + outSH[44] = c0 * d; + outSH[28] = s0 * d; d = 5.831413281; - out_grads[44][0] = c1 * d; - out_grads[28][0] = s1 * d; - out_grads[44][1] = -s1 * d; - out_grads[28][1] = c1 * d; + outGrads[44][0] = c1 * d; + outGrads[28][0] = s1 * d; + outGrads[44][1] = -s1 * d; + outGrads[28][1] = c1 * d; d = -2.915706641; - out_grads[43][2] = c1 * d; - out_grads[29][2] = s1 * d; + outGrads[43][2] = c1 * d; + outGrads[29][2] = s1 * d; a = z2 - 5.26315789e-02; d = 10.577811722 * a; - out_shs[63] = c0 * d; - out_shs[47] = s0 * d; + outSH[63] = c0 * d; + outSH[47] = s0 * d; d = 84.622493774 * a; - out_grads[63][0] = c1 * d; - out_grads[47][0] = s1 * d; - out_grads[63][1] = -s1 * d; - out_grads[47][1] = c1 * d; + outGrads[63][0] = c1 * d; + outGrads[47][0] = s1 * d; + outGrads[63][1] = -s1 * d; + outGrads[47][1] = c1 * d; d = -77.73072394 * a; - out_grads[62][2] = c1 * d; - out_grads[48][2] = s1 * d; + outGrads[62][2] = c1 * d; + outGrads[48][2] = s1 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -3.4318953 * z; - out_shs[64] = c1 * d; - out_shs[46] = s1 * d; + outSH[64] = c1 * d; + outSH[46] = s1 * d; d = -30.887057699 * z; - out_grads[64][0] = c0 * d; - out_grads[46][0] = s0 * d; - out_grads[64][1] = s0 * d; - out_grads[46][1] = c0 * d; + outGrads[64][0] = c0 * d; + outGrads[46][0] = s0 * d; + outGrads[64][1] = s0 * d; + outGrads[46][1] = c0 * d; d = 21.155623443 * z; - out_grads[63][2] = c0 * d; - out_grads[47][2] = s0 * d; + outGrads[63][2] = c0 * d; + outGrads[47][2] = s0 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.767395118; - out_shs[65] = c0 * d; - out_shs[45] = s0 * d; + outSH[65] = c0 * d; + outSH[45] = s0 * d; d = 7.673951182; - out_grads[65][0] = c1 * d; - out_grads[45][0] = s1 * d; - out_grads[65][1] = -s1 * d; - out_grads[45][1] = c1 * d; + outGrads[65][0] = c1 * d; + outGrads[45][0] = s1 * d; + outGrads[65][1] = -s1 * d; + outGrads[45][1] = c1 * d; d = -3.4318953; - out_grads[64][2] = c1 * d; - out_grads[46][2] = s1 * d; - out_grads[0][0] = 0.0; - out_grads[0][1] = 0.0; - out_grads[0][2] = 0.0; - out_grads[1][2] = 0.0; - out_grads[3][0] = 0.0; - out_grads[3][1] = 0.0; - out_grads[5][2] = 0.0; - out_grads[6][2] = 0.0; - out_grads[10][0] = 0.0; - out_grads[10][1] = 0.0; - out_grads[14][2] = 0.0; - out_grads[15][2] = 0.0; - out_grads[21][0] = 0.0; - out_grads[21][1] = 0.0; - out_grads[27][2] = 0.0; - out_grads[28][2] = 0.0; - out_grads[36][0] = 0.0; - out_grads[36][1] = 0.0; - out_grads[44][2] = 0.0; - out_grads[45][2] = 0.0; - out_grads[55][0] = 0.0; - out_grads[55][1] = 0.0; - out_grads[65][2] = 0.0; + outGrads[64][2] = c1 * d; + outGrads[46][2] = s1 * d; + outGrads[0][0] = 0.0; + outGrads[0][1] = 0.0; + outGrads[0][2] = 0.0; + outGrads[1][2] = 0.0; + outGrads[3][0] = 0.0; + outGrads[3][1] = 0.0; + outGrads[5][2] = 0.0; + outGrads[6][2] = 0.0; + outGrads[10][0] = 0.0; + outGrads[10][1] = 0.0; + outGrads[14][2] = 0.0; + outGrads[15][2] = 0.0; + outGrads[21][0] = 0.0; + outGrads[21][1] = 0.0; + outGrads[27][2] = 0.0; + outGrads[28][2] = 0.0; + outGrads[36][0] = 0.0; + outGrads[36][1] = 0.0; + outGrads[44][2] = 0.0; + outGrads[45][2] = 0.0; + outGrads[55][0] = 0.0; + outGrads[55][1] = 0.0; + outGrads[65][2] = 0.0; } diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_12.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_12.frag index 35c2a3617..9639e0789 100644 --- a/fury/shaders/rt_odfs/tournier/eval_sh_grad_12.frag +++ b/fury/shaders/rt_odfs/tournier/eval_sh_grad_12.frag @@ -1,4 +1,4 @@ -void eval_sh_grad_12(out float out_shs[91], out vec3 out_grads[91], vec3 point) +void evalShGrad12(out float outSH[91], out vec3 outGrads[91], vec3 point) { float x, y, z, z2, c0, s0, c1, s1, d, a, b; x = point[0]; @@ -8,584 +8,584 @@ void eval_sh_grad_12(out float out_shs[91], out vec3 out_grads[91], vec3 point) c0 = 1.0; s0 = 0.0; d = 0.282094792; - out_shs[0] = d; + outSH[0] = d; a = z2 - 0.333333333; d = 0.946174696 * a; - out_shs[3] = d; + outSH[3] = d; b = z2 * (a - 0.266666667); a = b - 0.257142857 * a; d = 3.702494142 * a; - out_shs[10] = d; + outSH[10] = d; b = z2 * a - 0.253968254 * b; a = b - 0.252525253 * a; d = 14.684485724 * a; - out_shs[21] = d; + outSH[21] = d; b = z2 * a - 0.251748252 * b; a = b - 0.251282051 * a; d = 58.473368113 * a; - out_shs[36] = d; + outSH[36] = d; b = z2 * a - 0.250980392 * b; a = b - 0.250773994 * a; d = 233.240148813 * a; - out_shs[55] = d; + outSH[55] = d; b = z2 * a - 0.250626566 * b; a = b - 0.250517598 * a; d = 931.186918633 * a; - out_shs[78] = d; + outSH[78] = d; c1 = x; s1 = y; d = -1.092548431 * z; - out_shs[4] = c1 * d; - out_shs[2] = s1 * d; - out_grads[4][0] = c0 * d; - out_grads[2][0] = s0 * d; - out_grads[4][1] = s0 * d; - out_grads[2][1] = c0 * d; + outSH[4] = c1 * d; + outSH[2] = s1 * d; + outGrads[4][0] = c0 * d; + outGrads[2][0] = s0 * d; + outGrads[4][1] = s0 * d; + outGrads[2][1] = c0 * d; d = 1.892349392 * z; - out_grads[3][2] = d; + outGrads[3][2] = d; a = (z2 - 0.2) * z; b = a - 0.228571429 * z; d = -4.683325805 * b; - out_shs[11] = c1 * d; - out_shs[9] = s1 * d; - out_grads[11][0] = c0 * d; - out_grads[9][0] = s0 * d; - out_grads[11][1] = s0 * d; - out_grads[9][1] = c0 * d; + outSH[11] = c1 * d; + outSH[9] = s1 * d; + outGrads[11][0] = c0 * d; + outGrads[9][0] = s0 * d; + outGrads[11][1] = s0 * d; + outGrads[9][1] = c0 * d; d = 14.809976568 * b; - out_grads[10][2] = d; + outGrads[10][2] = d; a = z2 * b - 0.238095238 * a; b = a - 0.242424242 * b; d = -19.226504963 * b; - out_shs[22] = c1 * d; - out_shs[20] = s1 * d; - out_grads[22][0] = c0 * d; - out_grads[20][0] = s0 * d; - out_grads[22][1] = s0 * d; - out_grads[20][1] = c0 * d; + outSH[22] = c1 * d; + outSH[20] = s1 * d; + outGrads[22][0] = c0 * d; + outGrads[20][0] = s0 * d; + outGrads[22][1] = s0 * d; + outGrads[20][1] = c0 * d; d = 88.106914343 * b; - out_grads[21][2] = d; + outGrads[21][2] = d; a = z2 * b - 0.244755245 * a; b = a - 0.246153846 * b; d = -77.964490818 * b; - out_shs[37] = c1 * d; - out_shs[35] = s1 * d; - out_grads[37][0] = c0 * d; - out_grads[35][0] = s0 * d; - out_grads[37][1] = s0 * d; - out_grads[35][1] = c0 * d; + outSH[37] = c1 * d; + outSH[35] = s1 * d; + outGrads[37][0] = c0 * d; + outGrads[35][0] = s0 * d; + outGrads[37][1] = s0 * d; + outGrads[35][1] = c0 * d; d = 467.786944906 * b; - out_grads[36][2] = d; + outGrads[36][2] = d; a = z2 * b - 0.247058824 * a; b = a - 0.247678019 * b; d = -314.500952502 * b; - out_shs[56] = c1 * d; - out_shs[54] = s1 * d; - out_grads[56][0] = c0 * d; - out_grads[54][0] = s0 * d; - out_grads[56][1] = s0 * d; - out_grads[54][1] = c0 * d; + outSH[56] = c1 * d; + outSH[54] = s1 * d; + outGrads[56][0] = c0 * d; + outGrads[54][0] = s0 * d; + outGrads[56][1] = s0 * d; + outGrads[54][1] = c0 * d; d = 2332.401488133 * b; - out_grads[55][2] = d; + outGrads[55][2] = d; a = z2 * b - 0.248120301 * a; b = a - 0.248447205 * b; d = -1265.233874957 * b; - out_shs[79] = c1 * d; - out_shs[77] = s1 * d; - out_grads[79][0] = c0 * d; - out_grads[77][0] = s0 * d; - out_grads[79][1] = s0 * d; - out_grads[77][1] = c0 * d; + outSH[79] = c1 * d; + outSH[77] = s1 * d; + outGrads[79][0] = c0 * d; + outGrads[77][0] = s0 * d; + outGrads[79][1] = s0 * d; + outGrads[77][1] = c0 * d; d = 11174.243023595 * b; - out_grads[78][2] = d; + outGrads[78][2] = d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.546274215; - out_shs[5] = c0 * d; - out_shs[1] = s0 * d; + outSH[5] = c0 * d; + outSH[1] = s0 * d; d = 1.092548431; - out_grads[5][0] = c1 * d; - out_grads[1][0] = s1 * d; - out_grads[5][1] = -s1 * d; - out_grads[1][1] = c1 * d; + outGrads[5][0] = c1 * d; + outGrads[1][0] = s1 * d; + outGrads[5][1] = -s1 * d; + outGrads[1][1] = c1 * d; d = -1.092548431; - out_grads[4][2] = c1 * d; - out_grads[2][2] = s1 * d; + outGrads[4][2] = c1 * d; + outGrads[2][2] = s1 * d; a = z2 - 0.142857143; d = 3.311611435 * a; - out_shs[12] = c0 * d; - out_shs[8] = s0 * d; + outSH[12] = c0 * d; + outSH[8] = s0 * d; d = 6.62322287 * a; - out_grads[12][0] = c1 * d; - out_grads[8][0] = s1 * d; - out_grads[12][1] = -s1 * d; - out_grads[8][1] = c1 * d; + outGrads[12][0] = c1 * d; + outGrads[8][0] = s1 * d; + outGrads[12][1] = -s1 * d; + outGrads[8][1] = c1 * d; d = -14.049977415 * a; - out_grads[11][2] = c1 * d; - out_grads[9][2] = s1 * d; + outGrads[11][2] = c1 * d; + outGrads[9][2] = s1 * d; b = z2 * (a - 0.19047619); a = b - 0.212121212 * a; d = 15.199886782 * a; - out_shs[23] = c0 * d; - out_shs[19] = s0 * d; + outSH[23] = c0 * d; + outSH[19] = s0 * d; d = 30.399773564 * a; - out_grads[23][0] = c1 * d; - out_grads[19][0] = s1 * d; - out_grads[23][1] = -s1 * d; - out_grads[19][1] = c1 * d; + outGrads[23][0] = c1 * d; + outGrads[19][0] = s1 * d; + outGrads[23][1] = -s1 * d; + outGrads[19][1] = c1 * d; d = -96.132524816 * a; - out_grads[22][2] = c1 * d; - out_grads[20][2] = s1 * d; + outGrads[22][2] = c1 * d; + outGrads[20][2] = s1 * d; b = z2 * a - 0.223776224 * b; a = b - 0.230769231 * a; d = 65.229772956 * a; - out_shs[38] = c0 * d; - out_shs[34] = s0 * d; + outSH[38] = c0 * d; + outSH[34] = s0 * d; d = 130.459545912 * a; - out_grads[38][0] = c1 * d; - out_grads[34][0] = s1 * d; - out_grads[38][1] = -s1 * d; - out_grads[34][1] = c1 * d; + outGrads[38][0] = c1 * d; + outGrads[34][0] = s1 * d; + outGrads[38][1] = -s1 * d; + outGrads[34][1] = c1 * d; d = -545.751435723 * a; - out_grads[37][2] = c1 * d; - out_grads[35][2] = s1 * d; + outGrads[37][2] = c1 * d; + outGrads[35][2] = s1 * d; b = z2 * a - 0.235294118 * b; a = b - 0.238390093 * a; d = 272.365814381 * a; - out_shs[57] = c0 * d; - out_shs[53] = s0 * d; + outSH[57] = c0 * d; + outSH[53] = s0 * d; d = 544.731628762 * a; - out_grads[57][0] = c1 * d; - out_grads[53][0] = s1 * d; - out_grads[57][1] = -s1 * d; - out_grads[53][1] = c1 * d; + outGrads[57][0] = c1 * d; + outGrads[53][0] = s1 * d; + outGrads[57][1] = -s1 * d; + outGrads[53][1] = c1 * d; d = -2830.508572514 * a; - out_grads[56][2] = c1 * d; - out_grads[54][2] = s1 * d; + outGrads[56][2] = c1 * d; + outGrads[54][2] = s1 * d; b = z2 * a - 0.240601504 * b; a = b - 0.242236025 * a; d = 1121.509962433 * a; - out_shs[80] = c0 * d; - out_shs[76] = s0 * d; + outSH[80] = c0 * d; + outSH[76] = s0 * d; d = 2243.019924866 * a; - out_grads[80][0] = c1 * d; - out_grads[76][0] = s1 * d; - out_grads[80][1] = -s1 * d; - out_grads[76][1] = c1 * d; + outGrads[80][0] = c1 * d; + outGrads[76][0] = s1 * d; + outGrads[80][1] = -s1 * d; + outGrads[76][1] = c1 * d; d = -13917.572624524 * a; - out_grads[79][2] = c1 * d; - out_grads[77][2] = s1 * d; + outGrads[79][2] = c1 * d; + outGrads[77][2] = s1 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -1.77013077 * z; - out_shs[13] = c1 * d; - out_shs[7] = s1 * d; + outSH[13] = c1 * d; + outSH[7] = s1 * d; d = -5.310392309 * z; - out_grads[13][0] = c0 * d; - out_grads[7][0] = s0 * d; - out_grads[13][1] = s0 * d; - out_grads[7][1] = c0 * d; + outGrads[13][0] = c0 * d; + outGrads[7][0] = s0 * d; + outGrads[13][1] = s0 * d; + outGrads[7][1] = c0 * d; d = 6.62322287 * z; - out_grads[12][2] = c0 * d; - out_grads[8][2] = s0 * d; + outGrads[12][2] = c0 * d; + outGrads[8][2] = s0 * d; a = (z2 - 0.111111111) * z; b = a - 0.161616162 * z; d = -10.133257855 * b; - out_shs[24] = c1 * d; - out_shs[18] = s1 * d; + outSH[24] = c1 * d; + outSH[18] = s1 * d; d = -30.399773564 * b; - out_grads[24][0] = c0 * d; - out_grads[18][0] = s0 * d; - out_grads[24][1] = s0 * d; - out_grads[18][1] = c0 * d; + outGrads[24][0] = c0 * d; + outGrads[18][0] = s0 * d; + outGrads[24][1] = s0 * d; + outGrads[18][1] = c0 * d; d = 60.799547128 * b; - out_grads[23][2] = c0 * d; - out_grads[19][2] = s0 * d; + outGrads[23][2] = c0 * d; + outGrads[19][2] = s0 * d; a = z2 * b - 0.188811189 * a; b = a - 0.205128205 * b; d = -48.175380057 * b; - out_shs[39] = c1 * d; - out_shs[33] = s1 * d; + outSH[39] = c1 * d; + outSH[33] = s1 * d; d = -144.52614017 * b; - out_grads[39][0] = c0 * d; - out_grads[33][0] = s0 * d; - out_grads[39][1] = s0 * d; - out_grads[33][1] = c0 * d; + outGrads[39][0] = c0 * d; + outGrads[33][0] = s0 * d; + outGrads[39][1] = s0 * d; + outGrads[33][1] = c0 * d; d = 391.378637737 * b; - out_grads[38][2] = c0 * d; - out_grads[34][2] = s0 * d; + outGrads[38][2] = c0 * d; + outGrads[34][2] = s0 * d; a = z2 * b - 0.215686275 * a; b = a - 0.222910217 * b; d = -213.661323441 * b; - out_shs[58] = c1 * d; - out_shs[52] = s1 * d; + outSH[58] = c1 * d; + outSH[52] = s1 * d; d = -640.983970322 * b; - out_grads[58][0] = c0 * d; - out_grads[52][0] = s0 * d; - out_grads[58][1] = s0 * d; - out_grads[52][1] = c0 * d; + outGrads[58][0] = c0 * d; + outGrads[52][0] = s0 * d; + outGrads[58][1] = s0 * d; + outGrads[52][1] = c0 * d; d = 2178.926515046 * b; - out_grads[57][2] = c0 * d; - out_grads[53][2] = s0 * d; + outGrads[57][2] = c0 * d; + outGrads[53][2] = s0 * d; a = z2 * b - 0.228070175 * a; b = a - 0.231884058 * b; d = -915.709049803 * b; - out_shs[81] = c1 * d; - out_shs[75] = s1 * d; + outSH[81] = c1 * d; + outSH[75] = s1 * d; d = -2747.127149409 * b; - out_grads[81][0] = c0 * d; - out_grads[75][0] = s0 * d; - out_grads[81][1] = s0 * d; - out_grads[75][1] = c0 * d; + outGrads[81][0] = c0 * d; + outGrads[75][0] = s0 * d; + outGrads[81][1] = s0 * d; + outGrads[75][1] = c0 * d; d = 11215.099624332 * b; - out_grads[80][2] = c0 * d; - out_grads[76][2] = s0 * d; + outGrads[80][2] = c0 * d; + outGrads[76][2] = s0 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.625835735; - out_shs[14] = c0 * d; - out_shs[6] = s0 * d; + outSH[14] = c0 * d; + outSH[6] = s0 * d; d = 2.503342942; - out_grads[14][0] = c1 * d; - out_grads[6][0] = s1 * d; - out_grads[14][1] = -s1 * d; - out_grads[6][1] = c1 * d; + outGrads[14][0] = c1 * d; + outGrads[6][0] = s1 * d; + outGrads[14][1] = -s1 * d; + outGrads[6][1] = c1 * d; d = -1.77013077; - out_grads[13][2] = c1 * d; - out_grads[7][2] = s1 * d; + outGrads[13][2] = c1 * d; + outGrads[7][2] = s1 * d; a = z2 - 9.09090909e-02; d = 5.550213908 * a; - out_shs[25] = c0 * d; - out_shs[17] = s0 * d; + outSH[25] = c0 * d; + outSH[17] = s0 * d; d = 22.200855632 * a; - out_grads[25][0] = c1 * d; - out_grads[17][0] = s1 * d; - out_grads[25][1] = -s1 * d; - out_grads[17][1] = c1 * d; + outGrads[25][0] = c1 * d; + outGrads[17][0] = s1 * d; + outGrads[25][1] = -s1 * d; + outGrads[17][1] = c1 * d; d = -30.399773564 * a; - out_grads[24][2] = c1 * d; - out_grads[18][2] = s1 * d; + outGrads[24][2] = c1 * d; + outGrads[18][2] = s1 * d; b = z2 * (a - 0.13986014); a = b - 0.169230769 * a; d = 31.097074109 * a; - out_shs[40] = c0 * d; - out_shs[32] = s0 * d; + outSH[40] = c0 * d; + outSH[32] = s0 * d; d = 124.388296437 * a; - out_grads[40][0] = c1 * d; - out_grads[32][0] = s1 * d; - out_grads[40][1] = -s1 * d; - out_grads[32][1] = c1 * d; + outGrads[40][0] = c1 * d; + outGrads[32][0] = s1 * d; + outGrads[40][1] = -s1 * d; + outGrads[32][1] = c1 * d; d = -240.876900283 * a; - out_grads[39][2] = c1 * d; - out_grads[33][2] = s1 * d; + outGrads[39][2] = c1 * d; + outGrads[33][2] = s1 * d; b = z2 * a - 0.188235294 * b; a = b - 0.20123839 * a; d = 151.081370682 * a; - out_shs[59] = c0 * d; - out_shs[51] = s0 * d; + outSH[59] = c0 * d; + outSH[51] = s0 * d; d = 604.325482728 * a; - out_grads[59][0] = c1 * d; - out_grads[51][0] = s1 * d; - out_grads[59][1] = -s1 * d; - out_grads[51][1] = c1 * d; + outGrads[59][0] = c1 * d; + outGrads[51][0] = s1 * d; + outGrads[59][1] = -s1 * d; + outGrads[51][1] = c1 * d; d = -1495.629264084 * a; - out_grads[58][2] = c1 * d; - out_grads[52][2] = s1 * d; + outGrads[58][2] = c1 * d; + outGrads[52][2] = s1 * d; b = z2 * a - 0.210526316 * b; a = b - 0.217391304 * a; d = 686.781787352 * a; - out_shs[82] = c0 * d; - out_shs[74] = s0 * d; + outSH[82] = c0 * d; + outSH[74] = s0 * d; d = 2747.127149409 * a; - out_grads[82][0] = c1 * d; - out_grads[74][0] = s1 * d; - out_grads[82][1] = -s1 * d; - out_grads[74][1] = c1 * d; + outGrads[82][0] = c1 * d; + outGrads[74][0] = s1 * d; + outGrads[82][1] = -s1 * d; + outGrads[74][1] = c1 * d; d = -8241.381448228 * a; - out_grads[81][2] = -c1 * d; - out_grads[75][2] = s1 * d; + outGrads[81][2] = -c1 * d; + outGrads[75][2] = s1 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -2.366619162 * z; - out_shs[26] = c1 * d; - out_shs[16] = s1 * d; + outSH[26] = c1 * d; + outSH[16] = s1 * d; d = -11.833095811 * z; - out_grads[26][0] = c0 * d; - out_grads[16][0] = s0 * d; - out_grads[26][1] = s0 * d; - out_grads[16][1] = c0 * d; + outGrads[26][0] = c0 * d; + outGrads[16][0] = s0 * d; + outGrads[26][1] = s0 * d; + outGrads[16][1] = c0 * d; d = 11.100427816 * z; - out_grads[25][2] = c0 * d; - out_grads[17][2] = s0 * d; + outGrads[25][2] = c0 * d; + outGrads[17][2] = s0 * d; a = (z2 - 7.69230769e-02) * z; b = a - 0.123076923 * z; d = -17.24955311 * b; - out_shs[41] = c1 * d; - out_shs[31] = s1 * d; + outSH[41] = c1 * d; + outSH[31] = s1 * d; d = -86.247765552 * b; - out_grads[41][0] = c0 * d; - out_grads[31][0] = s0 * d; - out_grads[41][1] = s0 * d; - out_grads[31][1] = c0 * d; + outGrads[41][0] = c0 * d; + outGrads[31][0] = s0 * d; + outGrads[41][1] = s0 * d; + outGrads[31][1] = c0 * d; d = 124.388296437 * b; - out_grads[40][2] = c0 * d; - out_grads[32][2] = s0 * d; + outGrads[40][2] = c0 * d; + outGrads[32][2] = s0 * d; a = z2 * b - 0.152941176 * a; b = a - 0.173374613 * b; d = -95.552248675 * b; - out_shs[60] = c1 * d; - out_shs[50] = s1 * d; + outSH[60] = c1 * d; + outSH[50] = s1 * d; d = -477.761243376 * b; - out_grads[60][0] = c0 * d; - out_grads[50][0] = s0 * d; - out_grads[60][1] = s0 * d; - out_grads[50][1] = c0 * d; + outGrads[60][0] = c0 * d; + outGrads[50][0] = s0 * d; + outGrads[60][1] = s0 * d; + outGrads[50][1] = c0 * d; d = 906.488224092 * b; - out_grads[59][2] = c0 * d; - out_grads[51][2] = s0 * d; + outGrads[59][2] = c0 * d; + outGrads[51][2] = s0 * d; a = z2 * b - 0.187969925 * a; b = a - 0.198757764 * b; d = -471.12841933 * b; - out_shs[83] = c1 * d; - out_shs[73] = s1 * d; + outSH[83] = c1 * d; + outSH[73] = s1 * d; d = -2355.642096651 * b; - out_grads[83][0] = c0 * d; - out_grads[73][0] = s0 * d; - out_grads[83][1] = s0 * d; - out_grads[73][1] = c0 * d; + outGrads[83][0] = c0 * d; + outGrads[73][0] = s0 * d; + outGrads[83][1] = s0 * d; + outGrads[73][1] = c0 * d; d = 5494.254298819 * b; - out_grads[82][2] = c0 * d; - out_grads[74][2] = s0 * d; + outGrads[82][2] = c0 * d; + outGrads[74][2] = s0 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.683184105; - out_shs[27] = c0 * d; - out_shs[15] = s0 * d; + outSH[27] = c0 * d; + outSH[15] = s0 * d; d = 4.099104631; - out_grads[27][0] = c1 * d; - out_grads[15][0] = s1 * d; - out_grads[27][1] = -s1 * d; - out_grads[15][1] = c1 * d; + outGrads[27][0] = c1 * d; + outGrads[15][0] = s1 * d; + outGrads[27][1] = -s1 * d; + outGrads[15][1] = c1 * d; d = -2.366619162; - out_grads[26][2] = c1 * d; - out_grads[16][2] = s1 * d; + outGrads[26][2] = c1 * d; + outGrads[16][2] = s1 * d; a = z2 - 6.66666667e-02; d = 7.984991491 * a; - out_shs[42] = c0 * d; - out_shs[30] = s0 * d; + outSH[42] = c0 * d; + outSH[30] = s0 * d; d = 47.909948945 * a; - out_grads[42][0] = c1 * d; - out_grads[30][0] = s1 * d; - out_grads[42][1] = -s1 * d; - out_grads[30][1] = c1 * d; + outGrads[42][0] = c1 * d; + outGrads[30][0] = s1 * d; + outGrads[42][1] = -s1 * d; + outGrads[30][1] = c1 * d; d = -51.748659331 * a; - out_grads[41][2] = c1 * d; - out_grads[31][2] = s1 * d; + outGrads[41][2] = c1 * d; + outGrads[31][2] = s1 * d; b = z2 * (a - 0.109803922); a = b - 0.139318885 * a; d = 53.41533086 * a; - out_shs[61] = c0 * d; - out_shs[49] = s0 * d; + outSH[61] = c0 * d; + outSH[49] = s0 * d; d = 320.491985161 * a; - out_grads[61][0] = c1 * d; - out_grads[49][0] = s1 * d; - out_grads[61][1] = -s1 * d; - out_grads[49][1] = c1 * d; + outGrads[61][0] = c1 * d; + outGrads[49][0] = s1 * d; + outGrads[61][1] = -s1 * d; + outGrads[49][1] = c1 * d; d = -477.761243376 * a; - out_grads[60][2] = c1 * d; - out_grads[50][2] = s1 * d; + outGrads[60][2] = c1 * d; + outGrads[50][2] = s1 * d; b = z2 * a - 0.160401003 * b; a = b - 0.175983437 * a; d = 293.800188384 * a; - out_shs[84] = c0 * d; - out_shs[72] = s0 * d; + outSH[84] = c0 * d; + outSH[72] = s0 * d; d = 1762.801130306 * a; - out_grads[84][0] = c1 * d; - out_grads[72][0] = s1 * d; - out_grads[84][1] = -s1 * d; - out_grads[72][1] = c1 * d; + outGrads[84][0] = c1 * d; + outGrads[72][0] = s1 * d; + outGrads[84][1] = -s1 * d; + outGrads[72][1] = c1 * d; d = -3297.898935312 * a; - out_grads[83][2] = c1 * d; - out_grads[73][2] = s1 * d; + outGrads[83][2] = c1 * d; + outGrads[73][2] = s1 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -2.915706641 * z; - out_shs[43] = c1 * d; - out_shs[29] = s1 * d; + outSH[43] = c1 * d; + outSH[29] = s1 * d; d = -20.409946485 * z; - out_grads[43][0] = c0 * d; - out_grads[29][0] = s0 * d; - out_grads[43][1] = s0 * d; - out_grads[29][1] = c0 * d; + outGrads[43][0] = c0 * d; + outGrads[29][0] = s0 * d; + outGrads[43][1] = s0 * d; + outGrads[29][1] = c0 * d; d = 15.969982982 * z; - out_grads[42][2] = c0 * d; - out_grads[30][2] = s0 * d; + outGrads[42][2] = c0 * d; + outGrads[30][2] = s0 * d; a = (z2 - 5.88235294e-02) * z; b = a - 9.90712074e-02 * z; d = -25.910241313 * b; - out_shs[62] = c1 * d; - out_shs[48] = s1 * d; + outSH[62] = c1 * d; + outSH[48] = s1 * d; d = -181.371689194 * b; - out_grads[62][0] = c0 * d; - out_grads[48][0] = s0 * d; - out_grads[62][1] = s0 * d; - out_grads[48][1] = c0 * d; + outGrads[62][0] = c0 * d; + outGrads[48][0] = s0 * d; + outGrads[62][1] = s0 * d; + outGrads[48][1] = c0 * d; d = 213.661323441 * b; - out_grads[61][2] = c0 * d; - out_grads[49][2] = s0 * d; + outGrads[61][2] = c0 * d; + outGrads[49][2] = s0 * d; a = z2 * b - 0.127819549 * a; b = a - 0.149068323 * b; d = -165.101452729 * b; - out_shs[85] = c1 * d; - out_shs[71] = s1 * d; + outSH[85] = c1 * d; + outSH[71] = s1 * d; d = -1155.7101691 * b; - out_grads[85][0] = c0 * d; - out_grads[71][0] = s0 * d; - out_grads[85][1] = s0 * d; - out_grads[71][1] = c0 * d; + outGrads[85][0] = c0 * d; + outGrads[71][0] = s0 * d; + outGrads[85][1] = s0 * d; + outGrads[71][1] = c0 * d; d = 1762.801130306 * b; - out_grads[84][2] = c0 * d; - out_grads[72][2] = s0 * d; + outGrads[84][2] = c0 * d; + outGrads[72][2] = s0 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.72892666; - out_shs[44] = c0 * d; - out_shs[28] = s0 * d; + outSH[44] = c0 * d; + outSH[28] = s0 * d; d = 5.831413281; - out_grads[44][0] = c1 * d; - out_grads[28][0] = s1 * d; - out_grads[44][1] = -s1 * d; - out_grads[28][1] = c1 * d; + outGrads[44][0] = c1 * d; + outGrads[28][0] = s1 * d; + outGrads[44][1] = -s1 * d; + outGrads[28][1] = c1 * d; d = -2.915706641; - out_grads[43][2] = c1 * d; - out_grads[29][2] = s1 * d; + outGrads[43][2] = c1 * d; + outGrads[29][2] = s1 * d; a = z2 - 5.26315789e-02; d = 10.577811722 * a; - out_shs[63] = c0 * d; - out_shs[47] = s0 * d; + outSH[63] = c0 * d; + outSH[47] = s0 * d; d = 84.622493774 * a; - out_grads[63][0] = c1 * d; - out_grads[47][0] = s1 * d; - out_grads[63][1] = -s1 * d; - out_grads[47][1] = c1 * d; + outGrads[63][0] = c1 * d; + outGrads[47][0] = s1 * d; + outGrads[63][1] = -s1 * d; + outGrads[47][1] = c1 * d; d = -77.73072394 * a; - out_grads[62][2] = c1 * d; - out_grads[48][2] = s1 * d; + outGrads[62][2] = c1 * d; + outGrads[48][2] = s1 * d; b = z2 * (a - 9.02255639e-02); a = b - 0.118012422 * a; d = 82.550726364 * a; - out_shs[86] = c0 * d; - out_shs[70] = s0 * d; + outSH[86] = c0 * d; + outSH[70] = s0 * d; d = 660.405810914 * a; - out_grads[86][0] = c1 * d; - out_grads[70][0] = s1 * d; - out_grads[86][1] = -s1 * d; - out_grads[70][1] = c1 * d; + outGrads[86][0] = c1 * d; + outGrads[70][0] = s1 * d; + outGrads[86][1] = -s1 * d; + outGrads[70][1] = c1 * d; d = -825.507263643 * a; - out_grads[85][2] = c1 * d; - out_grads[71][2] = s1 * d; + outGrads[85][2] = c1 * d; + outGrads[71][2] = s1 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -3.4318953 * z; - out_shs[64] = c1 * d; - out_shs[46] = s1 * d; + outSH[64] = c1 * d; + outSH[46] = s1 * d; d = -30.887057699 * z; - out_grads[64][0] = c0 * d; - out_grads[46][0] = s0 * d; - out_grads[64][1] = s0 * d; - out_grads[46][1] = c0 * d; + outGrads[64][0] = c0 * d; + outGrads[46][0] = s0 * d; + outGrads[64][1] = s0 * d; + outGrads[46][1] = c0 * d; d = 21.155623443 * z; - out_grads[63][2] = c0 * d; - out_grads[47][2] = s0 * d; + outGrads[63][2] = c0 * d; + outGrads[47][2] = s0 * d; a = (z2 - 4.76190476e-02) * z; b = a - 8.2815735e-02 * z; d = -36.028090689 * b; - out_shs[87] = c1 * d; - out_shs[69] = s1 * d; + outSH[87] = c1 * d; + outSH[69] = s1 * d; d = -324.252816204 * b; - out_grads[87][0] = c0 * d; - out_grads[69][0] = s0 * d; - out_grads[87][1] = s0 * d; - out_grads[69][1] = c0 * d; + outGrads[87][0] = c0 * d; + outGrads[69][0] = s0 * d; + outGrads[87][1] = s0 * d; + outGrads[69][1] = c0 * d; d = 330.202905457 * b; - out_grads[86][2] = c0 * d; - out_grads[70][2] = s0 * d; + outGrads[86][2] = c0 * d; + outGrads[70][2] = s0 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.767395118; - out_shs[65] = c0 * d; - out_shs[45] = s0 * d; + outSH[65] = c0 * d; + outSH[45] = s0 * d; d = 7.673951182; - out_grads[65][0] = c1 * d; - out_grads[45][0] = s1 * d; - out_grads[65][1] = -s1 * d; - out_grads[45][1] = c1 * d; + outGrads[65][0] = c1 * d; + outGrads[45][0] = s1 * d; + outGrads[65][1] = -s1 * d; + outGrads[45][1] = c1 * d; d = -3.4318953; - out_grads[64][2] = c1 * d; - out_grads[46][2] = s1 * d; + outGrads[64][2] = c1 * d; + outGrads[46][2] = s1 * d; a = z2 - 4.34782609e-02; d = 13.3042542 * a; - out_shs[88] = c0 * d; - out_shs[68] = s0 * d; + outSH[88] = c0 * d; + outSH[68] = s0 * d; d = 133.042542003 * a; - out_grads[88][0] = c1 * d; - out_grads[68][0] = s1 * d; - out_grads[88][1] = -s1 * d; - out_grads[68][1] = c1 * d; + outGrads[88][0] = c1 * d; + outGrads[68][0] = s1 * d; + outGrads[88][1] = -s1 * d; + outGrads[68][1] = c1 * d; d = -108.084272068 * a; - out_grads[87][2] = c1 * d; - out_grads[69][2] = s1 * d; + outGrads[87][2] = c1 * d; + outGrads[69][2] = s1 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -3.923210529 * z; - out_shs[89] = c1 * d; - out_shs[67] = s1 * d; + outSH[89] = c1 * d; + outSH[67] = s1 * d; d = -43.155315818 * z; - out_grads[89][0] = c0 * d; - out_grads[67][0] = s0 * d; - out_grads[89][1] = s0 * d; - out_grads[67][1] = c0 * d; + outGrads[89][0] = c0 * d; + outGrads[67][0] = s0 * d; + outGrads[89][1] = s0 * d; + outGrads[67][1] = c0 * d; d = 26.608508401 * z; - out_grads[88][2] = c0 * d; - out_grads[68][2] = s0 * d; + outGrads[88][2] = c0 * d; + outGrads[68][2] = s0 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.800821996; - out_shs[90] = c0 * d; - out_shs[66] = s0 * d; + outSH[90] = c0 * d; + outSH[66] = s0 * d; d = 9.609863949; - out_grads[90][0] = c1 * d; - out_grads[66][0] = s1 * d; - out_grads[90][1] = -s1 * d; - out_grads[66][1] = c1 * d; + outGrads[90][0] = c1 * d; + outGrads[66][0] = s1 * d; + outGrads[90][1] = -s1 * d; + outGrads[66][1] = c1 * d; d = -3.923210529; - out_grads[89][2] = c1 * d; - out_grads[67][2] = s1 * d; - out_grads[0][0] = 0.0; - out_grads[0][1] = 0.0; - out_grads[0][2] = 0.0; - out_grads[1][2] = 0.0; - out_grads[3][0] = 0.0; - out_grads[3][1] = 0.0; - out_grads[5][2] = 0.0; - out_grads[6][2] = 0.0; - out_grads[10][0] = 0.0; - out_grads[10][1] = 0.0; - out_grads[14][2] = 0.0; - out_grads[15][2] = 0.0; - out_grads[21][0] = 0.0; - out_grads[21][1] = 0.0; - out_grads[27][2] = 0.0; - out_grads[28][2] = 0.0; - out_grads[36][0] = 0.0; - out_grads[36][1] = 0.0; - out_grads[44][2] = 0.0; - out_grads[45][2] = 0.0; - out_grads[55][0] = 0.0; - out_grads[55][1] = 0.0; - out_grads[65][2] = 0.0; - out_grads[66][2] = 0.0; - out_grads[78][0] = 0.0; - out_grads[78][1] = 0.0; - out_grads[90][2] = 0.0; + outGrads[89][2] = c1 * d; + outGrads[67][2] = s1 * d; + outGrads[0][0] = 0.0; + outGrads[0][1] = 0.0; + outGrads[0][2] = 0.0; + outGrads[1][2] = 0.0; + outGrads[3][0] = 0.0; + outGrads[3][1] = 0.0; + outGrads[5][2] = 0.0; + outGrads[6][2] = 0.0; + outGrads[10][0] = 0.0; + outGrads[10][1] = 0.0; + outGrads[14][2] = 0.0; + outGrads[15][2] = 0.0; + outGrads[21][0] = 0.0; + outGrads[21][1] = 0.0; + outGrads[27][2] = 0.0; + outGrads[28][2] = 0.0; + outGrads[36][0] = 0.0; + outGrads[36][1] = 0.0; + outGrads[44][2] = 0.0; + outGrads[45][2] = 0.0; + outGrads[55][0] = 0.0; + outGrads[55][1] = 0.0; + outGrads[65][2] = 0.0; + outGrads[66][2] = 0.0; + outGrads[78][0] = 0.0; + outGrads[78][1] = 0.0; + outGrads[90][2] = 0.0; } diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_2.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_2.frag index 277a0e07a..cfd071515 100644 --- a/fury/shaders/rt_odfs/tournier/eval_sh_grad_2.frag +++ b/fury/shaders/rt_odfs/tournier/eval_sh_grad_2.frag @@ -1,4 +1,4 @@ -void eval_sh_grad_2(out float out_shs[6], out vec3 out_grads[6], vec3 point) +void evalShGrad2(out float outSH[6], out vec3 outGrads[6], vec3 point) { float x, y, z, z2, c0, s0, c1, s1, d, a; x = point[0]; @@ -8,39 +8,39 @@ void eval_sh_grad_2(out float out_shs[6], out vec3 out_grads[6], vec3 point) c0 = 1.0; s0 = 0.0; d = 0.282094792; - out_shs[0] = d; + outSH[0] = d; a = z2 - 0.333333333; d = 0.946174696 * a; - out_shs[3] = d; + outSH[3] = d; c1 = x; s1 = y; d = -1.092548431 * z; - out_shs[4] = c1 * d; - out_shs[2] = s1 * d; - out_grads[4][0] = c0 * d; - out_grads[2][0] = s0 * d; - out_grads[4][1] = s0 * d; - out_grads[2][1] = c0 * d; + outSH[4] = c1 * d; + outSH[2] = s1 * d; + outGrads[4][0] = c0 * d; + outGrads[2][0] = s0 * d; + outGrads[4][1] = s0 * d; + outGrads[2][1] = c0 * d; d = 1.892349392 * z; - out_grads[3][2] = d; + outGrads[3][2] = d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.546274215; - out_shs[5] = c0 * d; - out_shs[1] = s0 * d; + outSH[5] = c0 * d; + outSH[1] = s0 * d; d = 1.092548431; - out_grads[1][0] = c1 * d; - out_grads[5][0] = s1 * d; - out_grads[5][1] = -s1 * d; - out_grads[1][1] = c1 * d; + outGrads[1][0] = c1 * d; + outGrads[5][0] = s1 * d; + outGrads[5][1] = -s1 * d; + outGrads[1][1] = c1 * d; d = -1.092548431; - out_grads[4][2] = c1 * d; - out_grads[2][2] = s1 * d; - out_grads[0][0] = 0.0; - out_grads[0][1] = 0.0; - out_grads[0][2] = 0.0; - out_grads[5][2] = 0.0; - out_grads[3][0] = 0.0; - out_grads[3][1] = 0.0; - out_grads[1][2] = 0.0; + outGrads[4][2] = c1 * d; + outGrads[2][2] = s1 * d; + outGrads[0][0] = 0.0; + outGrads[0][1] = 0.0; + outGrads[0][2] = 0.0; + outGrads[5][2] = 0.0; + outGrads[3][0] = 0.0; + outGrads[3][1] = 0.0; + outGrads[1][2] = 0.0; } diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_4.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_4.frag index c85847a5b..acdb37afa 100644 --- a/fury/shaders/rt_odfs/tournier/eval_sh_grad_4.frag +++ b/fury/shaders/rt_odfs/tournier/eval_sh_grad_4.frag @@ -1,4 +1,4 @@ -void eval_sh_grad_4(out float out_shs[15], out vec3 out_grads[15], vec3 point) +void evalShGrad4(out float outSH[15], out vec3 outGrads[15], vec3 point) { float x, y, z, z2, c0, s0, c1, s1, d, a, b; x = point[0]; @@ -8,96 +8,96 @@ void eval_sh_grad_4(out float out_shs[15], out vec3 out_grads[15], vec3 point) c0 = 1.0; s0 = 0.0; d = 0.282094792; - out_shs[0] = d; + outSH[0] = d; a = z2 - 0.333333333; d = 0.946174696 * a; - out_shs[3] = d; + outSH[3] = d; b = z2 * (a - 0.266666667); a = b - 0.257142857 * a; d = 3.702494142 * a; - out_shs[10] = d; + outSH[10] = d; c1 = x; s1 = y; d = -1.092548431 * z; - out_shs[4] = c1 * d; - out_shs[2] = s1 * d; - out_grads[4][0] = c0 * d; - out_grads[2][0] = s0 * d; - out_grads[4][1] = s0 * d; - out_grads[2][1] = c0 * d; + outSH[4] = c1 * d; + outSH[2] = s1 * d; + outGrads[4][0] = c0 * d; + outGrads[2][0] = s0 * d; + outGrads[4][1] = s0 * d; + outGrads[2][1] = c0 * d; d = 1.892349392 * z; - out_grads[3][2] = d; + outGrads[3][2] = d; a = (z2 - 0.2) * z; b = a - 0.228571429 * z; d = -4.683325805 * b; - out_shs[11] = c1 * d; - out_shs[9] = s1 * d; - out_grads[11][0] = c0 * d; - out_grads[9][0] = s0 * d; - out_grads[11][1] = s0 * d; - out_grads[9][1] = c0 * d; + outSH[11] = c1 * d; + outSH[9] = s1 * d; + outGrads[11][0] = c0 * d; + outGrads[9][0] = s0 * d; + outGrads[11][1] = s0 * d; + outGrads[9][1] = c0 * d; d = 14.809976568 * b; - out_grads[10][2] = d; + outGrads[10][2] = d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.546274215; - out_shs[5] = c0 * d; - out_shs[1] = s0 * d; + outSH[5] = c0 * d; + outSH[1] = s0 * d; d = 1.092548431; - out_grads[5][0] = c1 * d; - out_grads[1][0] = s1 * d; - out_grads[5][1] = -s1 * d; - out_grads[1][1] = c1 * d; + outGrads[5][0] = c1 * d; + outGrads[1][0] = s1 * d; + outGrads[5][1] = -s1 * d; + outGrads[1][1] = c1 * d; d = -1.092548431; - out_grads[4][2] = c1 * d; - out_grads[2][2] = s1 * d; + outGrads[4][2] = c1 * d; + outGrads[2][2] = s1 * d; a = z2 - 0.142857143; d = 3.311611435 * a; - out_shs[12] = c0 * d; - out_shs[8] = s0 * d; + outSH[12] = c0 * d; + outSH[8] = s0 * d; d = 6.62322287 * a; - out_grads[12][0] = c1 * d; - out_grads[8][0] = s1 * d; - out_grads[12][1] = -s1 * d; - out_grads[8][1] = c1 * d; + outGrads[12][0] = c1 * d; + outGrads[8][0] = s1 * d; + outGrads[12][1] = -s1 * d; + outGrads[8][1] = c1 * d; d = -14.049977415 * a; - out_grads[11][2] = c1 * d; - out_grads[9][2] = s1 * d; + outGrads[11][2] = c1 * d; + outGrads[9][2] = s1 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -1.77013077 * z; - out_shs[13] = c1 * d; - out_shs[7] = s1 * d; + outSH[13] = c1 * d; + outSH[7] = s1 * d; d = -5.310392309 * z; - out_grads[13][0] = c0 * d; - out_grads[7][0] = s0 * d; - out_grads[13][1] = s0 * d; - out_grads[7][1] = c0 * d; + outGrads[13][0] = c0 * d; + outGrads[7][0] = s0 * d; + outGrads[13][1] = s0 * d; + outGrads[7][1] = c0 * d; d = 6.62322287 * z; - out_grads[12][2] = c0 * d; - out_grads[8][2] = s0 * d; + outGrads[12][2] = c0 * d; + outGrads[8][2] = s0 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.625835735; - out_shs[14] = c0 * d; - out_shs[6] = s0 * d; + outSH[14] = c0 * d; + outSH[6] = s0 * d; d = 2.503342942; - out_grads[14][0] = c1 * d; - out_grads[6][0] = s1 * d; - out_grads[14][1] = -s1 * d; - out_grads[6][1] = c1 * d; + outGrads[14][0] = c1 * d; + outGrads[6][0] = s1 * d; + outGrads[14][1] = -s1 * d; + outGrads[6][1] = c1 * d; d = -1.77013077; - out_grads[13][2] = c1 * d; - out_grads[7][2] = s1 * d; - out_grads[0][0] = 0.0; - out_grads[0][1] = 0.0; - out_grads[0][2] = 0.0; - out_grads[5][2] = 0.0; - out_grads[3][0] = 0.0; - out_grads[3][1] = 0.0; - out_grads[1][2] = 0.0; - out_grads[14][2] = 0.0; - out_grads[10][0] = 0.0; - out_grads[10][1] = 0.0; - out_grads[6][2] = 0.0; + outGrads[13][2] = c1 * d; + outGrads[7][2] = s1 * d; + outGrads[0][0] = 0.0; + outGrads[0][1] = 0.0; + outGrads[0][2] = 0.0; + outGrads[5][2] = 0.0; + outGrads[3][0] = 0.0; + outGrads[3][1] = 0.0; + outGrads[1][2] = 0.0; + outGrads[14][2] = 0.0; + outGrads[10][0] = 0.0; + outGrads[10][1] = 0.0; + outGrads[6][2] = 0.0; } diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_6.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_6.frag index 617413bc9..1a9cdb53f 100644 --- a/fury/shaders/rt_odfs/tournier/eval_sh_grad_6.frag +++ b/fury/shaders/rt_odfs/tournier/eval_sh_grad_6.frag @@ -1,4 +1,4 @@ -void eval_sh_grad_6(out float out_shs[28], out vec3 out_grads[28], vec3 point) +void evalShGrad6(out float outSH[28], out vec3 outGrads[28], vec3 point) { float x, y, z, z2, c0, s0, c1, s1, d, a, b; x = point[0]; @@ -8,179 +8,179 @@ void eval_sh_grad_6(out float out_shs[28], out vec3 out_grads[28], vec3 point) c0 = 1.0; s0 = 0.0; d = 0.282094792; - out_shs[0] = d; + outSH[0] = d; a = z2 - 0.333333333; d = 0.946174696 * a; - out_shs[3] = d; + outSH[3] = d; b = z2 * (a - 0.266666667); a = b - 0.257142857 * a; d = 3.702494142 * a; - out_shs[10] = d; + outSH[10] = d; b = z2 * a - 0.253968254 * b; a = b - 0.252525253 * a; d = 14.684485724 * a; - out_shs[21] = d; + outSH[21] = d; c1 = x; s1 = y; d = -1.092548431 * z; - out_shs[4] = c1 * d; - out_shs[2] = s1 * d; - out_grads[4][0] = c0 * d; - out_grads[2][0] = s0 * d; - out_grads[4][1] = s0 * d; - out_grads[2][1] = c0 * d; + outSH[4] = c1 * d; + outSH[2] = s1 * d; + outGrads[4][0] = c0 * d; + outGrads[2][0] = s0 * d; + outGrads[4][1] = s0 * d; + outGrads[2][1] = c0 * d; d = 1.892349392 * z; - out_grads[3][2] = d; + outGrads[3][2] = d; a = (z2 - 0.2) * z; b = a - 0.228571429 * z; d = -4.683325805 * b; - out_shs[11] = c1 * d; - out_shs[9] = s1 * d; - out_grads[11][0] = c0 * d; - out_grads[9][0] = s0 * d; - out_grads[11][1] = s0 * d; - out_grads[9][1] = c0 * d; + outSH[11] = c1 * d; + outSH[9] = s1 * d; + outGrads[11][0] = c0 * d; + outGrads[9][0] = s0 * d; + outGrads[11][1] = s0 * d; + outGrads[9][1] = c0 * d; d = 14.809976568 * b; - out_grads[10][2] = d; + outGrads[10][2] = d; a = z2 * b - 0.238095238 * a; b = a - 0.242424242 * b; d = -19.226504963 * b; - out_shs[22] = c1 * d; - out_shs[20] = s1 * d; - out_grads[22][0] = c0 * d; - out_grads[20][0] = s0 * d; - out_grads[22][1] = s0 * d; - out_grads[20][1] = c0 * d; + outSH[22] = c1 * d; + outSH[20] = s1 * d; + outGrads[22][0] = c0 * d; + outGrads[20][0] = s0 * d; + outGrads[22][1] = s0 * d; + outGrads[20][1] = c0 * d; d = 88.106914343 * b; - out_grads[21][2] = d; + outGrads[21][2] = d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.546274215; - out_shs[5] = c0 * d; - out_shs[1] = s0 * d; + outSH[5] = c0 * d; + outSH[1] = s0 * d; d = 1.092548431; - out_grads[5][0] = c1 * d; - out_grads[1][0] = s1 * d; - out_grads[5][1] = -s1 * d; - out_grads[1][1] = c1 * d; + outGrads[5][0] = c1 * d; + outGrads[1][0] = s1 * d; + outGrads[5][1] = -s1 * d; + outGrads[1][1] = c1 * d; d = -1.092548431; - out_grads[4][2] = c1 * d; - out_grads[2][2] = s1 * d; + outGrads[4][2] = c1 * d; + outGrads[2][2] = s1 * d; a = z2 - 0.142857143; d = 3.311611435 * a; - out_shs[12] = c0 * d; - out_shs[8] = s0 * d; + outSH[12] = c0 * d; + outSH[8] = s0 * d; d = 6.62322287 * a; - out_grads[12][0] = c1 * d; - out_grads[8][0] = s1 * d; - out_grads[12][1] = -s1 * d; - out_grads[8][1] = c1 * d; + outGrads[12][0] = c1 * d; + outGrads[8][0] = s1 * d; + outGrads[12][1] = -s1 * d; + outGrads[8][1] = c1 * d; d = -14.049977415 * a; - out_grads[11][2] = c1 * d; - out_grads[9][2] = s1 * d; + outGrads[11][2] = c1 * d; + outGrads[9][2] = s1 * d; b = z2 * (a - 0.19047619); a = b - 0.212121212 * a; d = 15.199886782 * a; - out_shs[23] = c0 * d; - out_shs[19] = s0 * d; + outSH[23] = c0 * d; + outSH[19] = s0 * d; d = 30.399773564 * a; - out_grads[23][0] = c1 * d; - out_grads[19][0] = s1 * d; - out_grads[23][1] = -s1 * d; - out_grads[19][1] = c1 * d; + outGrads[23][0] = c1 * d; + outGrads[19][0] = s1 * d; + outGrads[23][1] = -s1 * d; + outGrads[19][1] = c1 * d; d = -96.132524816 * a; - out_grads[22][2] = c1 * d; - out_grads[20][2] = s1 * d; + outGrads[22][2] = c1 * d; + outGrads[20][2] = s1 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -1.77013077 * z; - out_shs[13] = c1 * d; - out_shs[7] = s1 * d; + outSH[13] = c1 * d; + outSH[7] = s1 * d; d = -5.310392309 * z; - out_grads[13][0] = c0 * d; - out_grads[7][0] = s0 * d; - out_grads[13][1] = s0 * d; - out_grads[7][1] = c0 * d; + outGrads[13][0] = c0 * d; + outGrads[7][0] = s0 * d; + outGrads[13][1] = s0 * d; + outGrads[7][1] = c0 * d; d = 6.62322287 * z; - out_grads[12][2] = c0 * d; - out_grads[8][2] = s0 * d; + outGrads[12][2] = c0 * d; + outGrads[8][2] = s0 * d; a = (z2 - 0.111111111) * z; b = a - 0.161616162 * z; d = -10.133257855 * b; - out_shs[24] = c1 * d; - out_shs[18] = s1 * d; + outSH[24] = c1 * d; + outSH[18] = s1 * d; d = -30.399773564 * b; - out_grads[24][0] = c0 * d; - out_grads[18][0] = s0 * d; - out_grads[24][1] = s0 * d; - out_grads[18][1] = c0 * d; + outGrads[24][0] = c0 * d; + outGrads[18][0] = s0 * d; + outGrads[24][1] = s0 * d; + outGrads[18][1] = c0 * d; d = 60.799547128 * b; - out_grads[23][2] = c0 * d; - out_grads[19][2] = s0 * d; + outGrads[23][2] = c0 * d; + outGrads[19][2] = s0 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.625835735; - out_shs[14] = c0 * d; - out_shs[6] = s0 * d; + outSH[14] = c0 * d; + outSH[6] = s0 * d; d = 2.503342942; - out_grads[14][0] = c1 * d; - out_grads[6][0] = s1 * d; - out_grads[14][1] = -s1 * d; - out_grads[6][1] = c1 * d; + outGrads[14][0] = c1 * d; + outGrads[6][0] = s1 * d; + outGrads[14][1] = -s1 * d; + outGrads[6][1] = c1 * d; d = -1.77013077; - out_grads[13][2] = c1 * d; - out_grads[7][2] = s1 * d; + outGrads[13][2] = c1 * d; + outGrads[7][2] = s1 * d; a = z2 - 9.09090909e-02; d = 5.550213908 * a; - out_shs[25] = c0 * d; - out_shs[17] = s0 * d; + outSH[25] = c0 * d; + outSH[17] = s0 * d; d = 22.200855632 * a; - out_grads[25][0] = c1 * d; - out_grads[17][0] = s1 * d; - out_grads[25][1] = -s1 * d; - out_grads[17][1] = c1 * d; + outGrads[25][0] = c1 * d; + outGrads[17][0] = s1 * d; + outGrads[25][1] = -s1 * d; + outGrads[17][1] = c1 * d; d = -30.399773564 * a; - out_grads[24][2] = c1 * d; - out_grads[18][2] = s1 * d; + outGrads[24][2] = c1 * d; + outGrads[18][2] = s1 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -2.366619162 * z; - out_shs[26] = c1 * d; - out_shs[16] = s1 * d; + outSH[26] = c1 * d; + outSH[16] = s1 * d; d = -11.833095811 * z; - out_grads[26][0] = c0 * d; - out_grads[16][0] = s0 * d; - out_grads[26][1] = s0 * d; - out_grads[16][1] = c0 * d; + outGrads[26][0] = c0 * d; + outGrads[16][0] = s0 * d; + outGrads[26][1] = s0 * d; + outGrads[16][1] = c0 * d; d = 11.100427816 * z; - out_grads[25][2] = c0 * d; - out_grads[17][2] = s0 * d; + outGrads[25][2] = c0 * d; + outGrads[17][2] = s0 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.683184105; - out_shs[27] = c0 * d; - out_shs[15] = s0 * d; + outSH[27] = c0 * d; + outSH[15] = s0 * d; d = 4.099104631; - out_grads[27][0] = c1 * d; - out_grads[15][0] = s1 * d; - out_grads[27][1] = -s1 * d; - out_grads[15][1] = c1 * d; + outGrads[27][0] = c1 * d; + outGrads[15][0] = s1 * d; + outGrads[27][1] = -s1 * d; + outGrads[15][1] = c1 * d; d = -2.366619162; - out_grads[26][2] = c1 * d; - out_grads[16][2] = s1 * d; - out_grads[0][0] = 0.0; - out_grads[0][1] = 0.0; - out_grads[0][2] = 0.0; - out_grads[5][2] = 0.0; - out_grads[3][0] = 0.0; - out_grads[3][1] = 0.0; - out_grads[1][2] = 0.0; - out_grads[14][2] = 0.0; - out_grads[10][0] = 0.0; - out_grads[10][1] = 0.0; - out_grads[6][2] = 0.0; - out_grads[27][2] = 0.0; - out_grads[21][0] = 0.0; - out_grads[21][1] = 0.0; - out_grads[15][2] = 0.0; + outGrads[26][2] = c1 * d; + outGrads[16][2] = s1 * d; + outGrads[0][0] = 0.0; + outGrads[0][1] = 0.0; + outGrads[0][2] = 0.0; + outGrads[5][2] = 0.0; + outGrads[3][0] = 0.0; + outGrads[3][1] = 0.0; + outGrads[1][2] = 0.0; + outGrads[14][2] = 0.0; + outGrads[10][0] = 0.0; + outGrads[10][1] = 0.0; + outGrads[6][2] = 0.0; + outGrads[27][2] = 0.0; + outGrads[21][0] = 0.0; + outGrads[21][1] = 0.0; + outGrads[15][2] = 0.0; } diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_8.frag b/fury/shaders/rt_odfs/tournier/eval_sh_grad_8.frag index 712b2dc29..fbe0545db 100644 --- a/fury/shaders/rt_odfs/tournier/eval_sh_grad_8.frag +++ b/fury/shaders/rt_odfs/tournier/eval_sh_grad_8.frag @@ -1,4 +1,4 @@ -void eval_sh_grad_8(out float out_shs[45], out vec3 out_grads[45], vec3 point) +void evalShGrad8(out float outSH[45], out vec3 outGrads[45], vec3 point) { float x, y, z, z2, c0, s0, c1, s1, d, a, b; x = point[0]; @@ -8,288 +8,288 @@ void eval_sh_grad_8(out float out_shs[45], out vec3 out_grads[45], vec3 point) c0 = 1.0; s0 = 0.0; d = 0.282094792; - out_shs[0] = d; + outSH[0] = d; a = z2 - 0.333333333; d = 0.946174696 * a; - out_shs[3] = d; + outSH[3] = d; b = z2 * (a - 0.266666667); a = b - 0.257142857 * a; d = 3.702494142 * a; - out_shs[10] = d; + outSH[10] = d; b = z2 * a - 0.253968254 * b; a = b - 0.252525253 * a; d = 14.684485724 * a; - out_shs[21] = d; + outSH[21] = d; b = z2 * a - 0.251748252 * b; a = b - 0.251282051 * a; d = 58.473368113 * a; - out_shs[36] = d; + outSH[36] = d; c1 = x; s1 = y; d = -1.092548431 * z; - out_shs[4] = c1 * d; - out_shs[2] = s1 * d; - out_grads[4][0] = c0 * d; - out_grads[2][0] = s0 * d; - out_grads[4][1] = s0 * d; - out_grads[2][1] = c0 * d; + outSH[4] = c1 * d; + outSH[2] = s1 * d; + outGrads[4][0] = c0 * d; + outGrads[2][0] = s0 * d; + outGrads[4][1] = s0 * d; + outGrads[2][1] = c0 * d; d = 1.892349392 * z; - out_grads[3][2] = d; + outGrads[3][2] = d; a = (z2 - 0.2) * z; b = a - 0.228571429 * z; d = -4.683325805 * b; - out_shs[11] = c1 * d; - out_shs[9] = s1 * d; - out_grads[11][0] = c0 * d; - out_grads[9][0] = s0 * d; - out_grads[11][1] = s0 * d; - out_grads[9][1] = c0 * d; + outSH[11] = c1 * d; + outSH[9] = s1 * d; + outGrads[11][0] = c0 * d; + outGrads[9][0] = s0 * d; + outGrads[11][1] = s0 * d; + outGrads[9][1] = c0 * d; d = 14.809976568 * b; - out_grads[10][2] = d; + outGrads[10][2] = d; a = z2 * b - 0.238095238 * a; b = a - 0.242424242 * b; d = -19.226504963 * b; - out_shs[22] = c1 * d; - out_shs[20] = s1 * d; - out_grads[22][0] = c0 * d; - out_grads[20][0] = s0 * d; - out_grads[22][1] = s0 * d; - out_grads[20][1] = c0 * d; + outSH[22] = c1 * d; + outSH[20] = s1 * d; + outGrads[22][0] = c0 * d; + outGrads[20][0] = s0 * d; + outGrads[22][1] = s0 * d; + outGrads[20][1] = c0 * d; d = 88.106914343 * b; - out_grads[21][2] = d; + outGrads[21][2] = d; a = z2 * b - 0.244755245 * a; b = a - 0.246153846 * b; d = -77.964490818 * b; - out_shs[37] = c1 * d; - out_shs[35] = s1 * d; - out_grads[37][0] = c0 * d; - out_grads[35][0] = s0 * d; - out_grads[37][1] = s0 * d; - out_grads[35][1] = c0 * d; + outSH[37] = c1 * d; + outSH[35] = s1 * d; + outGrads[37][0] = c0 * d; + outGrads[35][0] = s0 * d; + outGrads[37][1] = s0 * d; + outGrads[35][1] = c0 * d; d = 467.786944906 * b; - out_grads[36][2] = d; + outGrads[36][2] = d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.546274215; - out_shs[5] = c0 * d; - out_shs[1] = s0 * d; + outSH[5] = c0 * d; + outSH[1] = s0 * d; d = 1.092548431; - out_grads[5][0] = c1 * d; - out_grads[1][0] = s1 * d; - out_grads[5][1] = -s1 * d; - out_grads[1][1] = c1 * d; + outGrads[5][0] = c1 * d; + outGrads[1][0] = s1 * d; + outGrads[5][1] = -s1 * d; + outGrads[1][1] = c1 * d; d = -1.092548431; - out_grads[4][2] = c1 * d; - out_grads[2][2] = s1 * d; + outGrads[4][2] = c1 * d; + outGrads[2][2] = s1 * d; a = z2 - 0.142857143; d = 3.311611435 * a; - out_shs[12] = c0 * d; - out_shs[8] = s0 * d; + outSH[12] = c0 * d; + outSH[8] = s0 * d; d = 6.62322287 * a; - out_grads[12][0] = c1 * d; - out_grads[8][0] = s1 * d; - out_grads[12][1] = -s1 * d; - out_grads[8][1] = c1 * d; + outGrads[12][0] = c1 * d; + outGrads[8][0] = s1 * d; + outGrads[12][1] = -s1 * d; + outGrads[8][1] = c1 * d; d = -14.049977415 * a; - out_grads[11][2] = c1 * d; - out_grads[9][2] = s1 * d; + outGrads[11][2] = c1 * d; + outGrads[9][2] = s1 * d; b = z2 * (a - 0.19047619); a = b - 0.212121212 * a; d = 15.199886782 * a; - out_shs[23] = c0 * d; - out_shs[19] = s0 * d; + outSH[23] = c0 * d; + outSH[19] = s0 * d; d = 30.399773564 * a; - out_grads[23][0] = c1 * d; - out_grads[19][0] = s1 * d; - out_grads[23][1] = -s1 * d; - out_grads[19][1] = c1 * d; + outGrads[23][0] = c1 * d; + outGrads[19][0] = s1 * d; + outGrads[23][1] = -s1 * d; + outGrads[19][1] = c1 * d; d = -96.132524816 * a; - out_grads[22][2] = c1 * d; - out_grads[20][2] = s1 * d; + outGrads[22][2] = c1 * d; + outGrads[20][2] = s1 * d; b = z2 * a - 0.223776224 * b; a = b - 0.230769231 * a; d = 65.229772956 * a; - out_shs[38] = c0 * d; - out_shs[34] = s0 * d; + outSH[38] = c0 * d; + outSH[34] = s0 * d; d = 130.459545912 * a; - out_grads[38][0] = c1 * d; - out_grads[34][0] = s1 * d; - out_grads[38][1] = -s1 * d; - out_grads[34][1] = c1 * d; + outGrads[38][0] = c1 * d; + outGrads[34][0] = s1 * d; + outGrads[38][1] = -s1 * d; + outGrads[34][1] = c1 * d; d = -545.751435723 * a; - out_grads[37][2] = c1 * d; - out_grads[35][2] = s1 * d; + outGrads[37][2] = c1 * d; + outGrads[35][2] = s1 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -1.77013077 * z; - out_shs[13] = c1 * d; - out_shs[7] = s1 * d; + outSH[13] = c1 * d; + outSH[7] = s1 * d; d = -5.310392309 * z; - out_grads[13][0] = c0 * d; - out_grads[7][0] = s0 * d; - out_grads[13][1] = s0 * d; - out_grads[7][1] = c0 * d; + outGrads[13][0] = c0 * d; + outGrads[7][0] = s0 * d; + outGrads[13][1] = s0 * d; + outGrads[7][1] = c0 * d; d = 6.62322287 * z; - out_grads[12][2] = c0 * d; - out_grads[8][2] = s0 * d; + outGrads[12][2] = c0 * d; + outGrads[8][2] = s0 * d; a = (z2 - 0.111111111) * z; b = a - 0.161616162 * z; d = -10.133257855 * b; - out_shs[24] = c1 * d; - out_shs[18] = s1 * d; + outSH[24] = c1 * d; + outSH[18] = s1 * d; d = -30.399773564 * b; - out_grads[24][0] = c0 * d; - out_grads[18][0] = s0 * d; - out_grads[24][1] = s0 * d; - out_grads[18][1] = c0 * d; + outGrads[24][0] = c0 * d; + outGrads[18][0] = s0 * d; + outGrads[24][1] = s0 * d; + outGrads[18][1] = c0 * d; d = 60.799547128 * b; - out_grads[23][2] = c0 * d; - out_grads[19][2] = s0 * d; + outGrads[23][2] = c0 * d; + outGrads[19][2] = s0 * d; a = z2 * b - 0.188811189 * a; b = a - 0.205128205 * b; d = -48.175380057 * b; - out_shs[39] = c1 * d; - out_shs[33] = s1 * d; + outSH[39] = c1 * d; + outSH[33] = s1 * d; d = -144.52614017 * b; - out_grads[39][0] = c0 * d; - out_grads[33][0] = s0 * d; - out_grads[39][1] = s0 * d; - out_grads[33][1] = c0 * d; + outGrads[39][0] = c0 * d; + outGrads[33][0] = s0 * d; + outGrads[39][1] = s0 * d; + outGrads[33][1] = c0 * d; d = 391.378637737 * b; - out_grads[38][2] = c0 * d; - out_grads[34][2] = s0 * d; + outGrads[38][2] = c0 * d; + outGrads[34][2] = s0 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.625835735; - out_shs[14] = c0 * d; - out_shs[6] = s0 * d; + outSH[14] = c0 * d; + outSH[6] = s0 * d; d = 2.503342942; - out_grads[14][0] = c1 * d; - out_grads[6][0] = s1 * d; - out_grads[14][1] = -s1 * d; - out_grads[6][1] = c1 * d; + outGrads[14][0] = c1 * d; + outGrads[6][0] = s1 * d; + outGrads[14][1] = -s1 * d; + outGrads[6][1] = c1 * d; d = -1.77013077; - out_grads[13][2] = c1 * d; - out_grads[7][2] = s1 * d; + outGrads[13][2] = c1 * d; + outGrads[7][2] = s1 * d; a = z2 - 9.09090909e-02; d = 5.550213908 * a; - out_shs[25] = c0 * d; - out_shs[17] = s0 * d; + outSH[25] = c0 * d; + outSH[17] = s0 * d; d = 22.200855632 * a; - out_grads[25][0] = c1 * d; - out_grads[17][0] = s1 * d; - out_grads[25][1] = -s1 * d; - out_grads[17][1] = c1 * d; + outGrads[25][0] = c1 * d; + outGrads[17][0] = s1 * d; + outGrads[25][1] = -s1 * d; + outGrads[17][1] = c1 * d; d = -30.399773564 * a; - out_grads[24][2] = c1 * d; - out_grads[18][2] = s1 * d; + outGrads[24][2] = c1 * d; + outGrads[18][2] = s1 * d; b = z2 * (a - 0.13986014); a = b - 0.169230769 * a; d = 31.097074109 * a; - out_shs[40] = c0 * d; - out_shs[32] = s0 * d; + outSH[40] = c0 * d; + outSH[32] = s0 * d; d = 124.388296437 * a; - out_grads[40][0] = c1 * d; - out_grads[32][0] = s1 * d; - out_grads[40][1] = -s1 * d; - out_grads[32][1] = c1 * d; + outGrads[40][0] = c1 * d; + outGrads[32][0] = s1 * d; + outGrads[40][1] = -s1 * d; + outGrads[32][1] = c1 * d; d = -240.876900283 * a; - out_grads[39][2] = c1 * d; - out_grads[33][2] = s1 * d; + outGrads[39][2] = c1 * d; + outGrads[33][2] = s1 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -2.366619162 * z; - out_shs[26] = c1 * d; - out_shs[16] = s1 * d; + outSH[26] = c1 * d; + outSH[16] = s1 * d; d = -11.833095811 * z; - out_grads[26][0] = c0 * d; - out_grads[16][0] = s0 * d; - out_grads[26][1] = s0 * d; - out_grads[16][1] = c0 * d; + outGrads[26][0] = c0 * d; + outGrads[16][0] = s0 * d; + outGrads[26][1] = s0 * d; + outGrads[16][1] = c0 * d; d = 11.100427816 * z; - out_grads[25][2] = c0 * d; - out_grads[17][2] = s0 * d; + outGrads[25][2] = c0 * d; + outGrads[17][2] = s0 * d; a = (z2 - 7.69230769e-02) * z; b = a - 0.123076923 * z; d = -17.24955311 * b; - out_shs[41] = c1 * d; - out_shs[31] = s1 * d; + outSH[41] = c1 * d; + outSH[31] = s1 * d; d = -86.247765552 * b; - out_grads[41][0] = c0 * d; - out_grads[31][0] = s0 * d; - out_grads[41][1] = s0 * d; - out_grads[31][1] = c0 * d; + outGrads[41][0] = c0 * d; + outGrads[31][0] = s0 * d; + outGrads[41][1] = s0 * d; + outGrads[31][1] = c0 * d; d = 124.388296437 * b; - out_grads[40][2] = c0 * d; - out_grads[32][2] = s0 * d; + outGrads[40][2] = c0 * d; + outGrads[32][2] = s0 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.683184105; - out_shs[27] = c0 * d; - out_shs[15] = s0 * d; + outSH[27] = c0 * d; + outSH[15] = s0 * d; d = 4.099104631; - out_grads[27][0] = c1 * d; - out_grads[15][0] = s1 * d; - out_grads[27][1] = -s1 * d; - out_grads[15][1] = c1 * d; + outGrads[27][0] = c1 * d; + outGrads[15][0] = s1 * d; + outGrads[27][1] = -s1 * d; + outGrads[15][1] = c1 * d; d = -2.366619162; - out_grads[26][2] = c1 * d; - out_grads[16][2] = s1 * d; + outGrads[26][2] = c1 * d; + outGrads[16][2] = s1 * d; a = z2 - 6.66666667e-02; d = 7.984991491 * a; - out_shs[42] = c0 * d; - out_shs[30] = s0 * d; + outSH[42] = c0 * d; + outSH[30] = s0 * d; d = 47.909948945 * a; - out_grads[42][0] = c1 * d; - out_grads[30][0] = s1 * d; - out_grads[42][1] = -s1 * d; - out_grads[30][1] = c1 * d; + outGrads[42][0] = c1 * d; + outGrads[30][0] = s1 * d; + outGrads[42][1] = -s1 * d; + outGrads[30][1] = c1 * d; d = -51.748659331 * a; - out_grads[41][2] = c1 * d; - out_grads[31][2] = s1 * d; + outGrads[41][2] = c1 * d; + outGrads[31][2] = s1 * d; c1 = x * c0 - y * s0; s1 = y * c0 + x * s0; d = -2.915706641 * z; - out_shs[43] = c1 * d; - out_shs[29] = s1 * d; + outSH[43] = c1 * d; + outSH[29] = s1 * d; d = -20.409946485 * z; - out_grads[43][0] = c0 * d; - out_grads[29][0] = s0 * d; - out_grads[43][1] = s0 * d; - out_grads[29][1] = c0 * d; + outGrads[43][0] = c0 * d; + outGrads[29][0] = s0 * d; + outGrads[43][1] = s0 * d; + outGrads[29][1] = c0 * d; d = 15.969982982 * z; - out_grads[42][2] = c0 * d; - out_grads[30][2] = s0 * d; + outGrads[42][2] = c0 * d; + outGrads[30][2] = s0 * d; c0 = x * c1 - y * s1; s0 = y * c1 + x * s1; d = 0.72892666; - out_shs[44] = c0 * d; - out_shs[28] = s0 * d; + outSH[44] = c0 * d; + outSH[28] = s0 * d; d = 5.831413281; - out_grads[44][0] = c1 * d; - out_grads[28][0] = s1 * d; - out_grads[44][1] = -s1 * d; - out_grads[28][1] = c1 * d; + outGrads[44][0] = c1 * d; + outGrads[28][0] = s1 * d; + outGrads[44][1] = -s1 * d; + outGrads[28][1] = c1 * d; d = -2.915706641; - out_grads[43][2] = c1 * d; - out_grads[29][2] = s1 * d; - out_grads[0][0] = 0.0; - out_grads[0][1] = 0.0; - out_grads[0][2] = 0.0; - out_grads[5][2] = 0.0; - out_grads[3][0] = 0.0; - out_grads[3][1] = 0.0; - out_grads[1][2] = 0.0; - out_grads[14][2] = 0.0; - out_grads[10][0] = 0.0; - out_grads[10][1] = 0.0; - out_grads[6][2] = 0.0; - out_grads[27][2] = 0.0; - out_grads[21][0] = 0.0; - out_grads[21][1] = 0.0; - out_grads[15][2] = 0.0; - out_grads[44][2] = 0.0; - out_grads[36][0] = 0.0; - out_grads[36][1] = 0.0; - out_grads[28][2] = 0.0; + outGrads[43][2] = c1 * d; + outGrads[29][2] = s1 * d; + outGrads[0][0] = 0.0; + outGrads[0][1] = 0.0; + outGrads[0][2] = 0.0; + outGrads[5][2] = 0.0; + outGrads[3][0] = 0.0; + outGrads[3][1] = 0.0; + outGrads[1][2] = 0.0; + outGrads[14][2] = 0.0; + outGrads[10][0] = 0.0; + outGrads[10][1] = 0.0; + outGrads[6][2] = 0.0; + outGrads[27][2] = 0.0; + outGrads[21][0] = 0.0; + outGrads[21][1] = 0.0; + outGrads[15][2] = 0.0; + outGrads[44][2] = 0.0; + outGrads[36][0] = 0.0; + outGrads[36][1] = 0.0; + outGrads[28][2] = 0.0; } diff --git a/fury/shaders/utils/find_roots.frag b/fury/shaders/utils/find_roots.frag index e5b80f7a4..9c69a4801 100644 --- a/fury/shaders/utils/find_roots.frag +++ b/fury/shaders/utils/find_roots.frag @@ -1,4 +1,4 @@ -void find_roots(out float out_roots[MAX_DEGREE + 1], float poly[MAX_DEGREE + 1], float begin, float end) { +void findRoots(out float outRoots[MAX_DEGREE + 1], float poly[MAX_DEGREE + 1], float begin, float end, int maxPolyDegree, float noIntersection) { float tolerance = (end - begin) * 1.0e-4; // Construct the quadratic derivative of the polynomial. We divide each // derivative by the factorial of its order, such that the constant @@ -6,11 +6,11 @@ void find_roots(out float out_roots[MAX_DEGREE + 1], float poly[MAX_DEGREE + 1], // against overflow and makes it easier to avoid spilling below. The // factors happen to be binomial coefficients then. float derivative[MAX_DEGREE + 1]; - derivative[0] = poly[MAX_DEGREE - 2]; - derivative[1] = float(MAX_DEGREE - 1) * poly[MAX_DEGREE - 1]; - derivative[2] = (0.5 * float((MAX_DEGREE - 1) * MAX_DEGREE)) * poly[MAX_DEGREE - 0]; + derivative[0] = poly[maxPolyDegree - 2]; + derivative[1] = float(maxPolyDegree - 1) * poly[maxPolyDegree - 1]; + derivative[2] = (0.5 * float((maxPolyDegree - 1) * maxPolyDegree)) * poly[maxPolyDegree - 0]; _unroll_ - for (int i = 3; i != MAX_DEGREE + 1; ++i) + for (int i = 3; i != maxPolyDegree + 1; ++i) derivative[i] = 0.0; // Compute its two roots using the quadratic formula float discriminant = derivative[1] * derivative[1] - 4.0 * derivative[0] * derivative[2]; @@ -19,20 +19,20 @@ void find_roots(out float out_roots[MAX_DEGREE + 1], float poly[MAX_DEGREE + 1], float scaled_root = derivative[1] + ((derivative[1] > 0.0) ? sqrt_discriminant : (-sqrt_discriminant)); float root_0 = clamp(-2.0 * derivative[0] / scaled_root, begin, end); float root_1 = clamp(-0.5 * scaled_root / derivative[2], begin, end); - out_roots[MAX_DEGREE - 2] = min(root_0, root_1); - out_roots[MAX_DEGREE - 1] = max(root_0, root_1); + outRoots[maxPolyDegree - 2] = min(root_0, root_1); + outRoots[maxPolyDegree - 1] = max(root_0, root_1); } else { // Indicate that the cubic derivative has a single root - out_roots[MAX_DEGREE - 2] = begin; - out_roots[MAX_DEGREE - 1] = begin; + outRoots[maxPolyDegree - 2] = begin; + outRoots[maxPolyDegree - 1] = begin; } // The last entry in the root array is set to end to make it easier to // iterate over relevant intervals, all untouched roots are set to begin - out_roots[MAX_DEGREE] = end; + outRoots[maxPolyDegree] = end; _unroll_ - for (int i = 0; i != MAX_DEGREE - 2; ++i) - out_roots[i] = begin; + for (int i = 0; i != maxPolyDegree - 2; ++i) + outRoots[i] = begin; // Work your way up to derivatives of higher degree until you reach the // polynomial itself. This implementation may seem peculiar: It always // treats the derivative as though it had degree MAX_DEGREE and it @@ -42,41 +42,41 @@ void find_roots(out float out_roots[MAX_DEGREE + 1], float poly[MAX_DEGREE + 1], // negative impact on the overall run time. Profiling indicates that the // current implementation has no spilling whatsoever. _loop_ - for (int degree = 3; degree != MAX_DEGREE + 1; ++degree) { + for (int degree = 3; degree != maxPolyDegree + 1; ++degree) { // Take the integral of the previous derivative (scaled such that the // constant coefficient can still be copied directly from poly) - float prev_derivative_order = float(MAX_DEGREE + 1 - degree); + float prev_derivative_order = float(maxPolyDegree + 1 - degree); _unroll_ - for (int i = MAX_DEGREE; i != 0; --i) + for (int i = maxPolyDegree; i != 0; --i) derivative[i] = derivative[i - 1] * (prev_derivative_order * (1.0 / float(i))); // Copy the constant coefficient without causing spilling. This part // would be harder if the derivative were not scaled the way it is. _unroll_ - for (int i = 0; i != MAX_DEGREE - 2; ++i) - derivative[0] = (degree == MAX_DEGREE - i) ? poly[i] : derivative[0]; + for (int i = 0; i != maxPolyDegree - 2; ++i) + derivative[0] = (degree == maxPolyDegree - i) ? poly[i] : derivative[0]; // Determine the value of this derivative at begin - float begin_value = derivative[MAX_DEGREE]; + float begin_value = derivative[maxPolyDegree]; _unroll_ - for (int i = MAX_DEGREE - 1; i != -1; --i) + for (int i = maxPolyDegree - 1; i != -1; --i) begin_value = begin_value * begin + derivative[i]; // Iterate over the intervals where roots may be found _unroll_ - for (int i = 0; i != MAX_DEGREE; ++i) { - if (i < MAX_DEGREE - degree) + for (int i = 0; i != maxPolyDegree; ++i) { + if (i < maxPolyDegree - degree) continue; - float current_begin = out_roots[i]; - float current_end = out_roots[i + 1]; + float current_begin = outRoots[i]; + float current_end = outRoots[i + 1]; // Try to find a root float root; - if (newton_bisection(root, begin_value, derivative, current_begin, current_end, begin_value, tolerance)) - out_roots[i] = root; - else if (degree < MAX_DEGREE) + if (newtonBisection(root, begin_value, derivative, current_begin, current_end, begin_value, tolerance, maxPolyDegree)) + outRoots[i] = root; + else if (degree < maxPolyDegree) // Create an empty interval for the next iteration - out_roots[i] = out_roots[i - 1]; + outRoots[i] = outRoots[i - 1]; else - out_roots[i] = NO_INTERSECTION; + outRoots[i] = noIntersection; } } // We no longer need this array entry - out_roots[MAX_DEGREE] = NO_INTERSECTION; + outRoots[maxPolyDegree] = noIntersection; } diff --git a/fury/shaders/utils/newton_bisection.frag b/fury/shaders/utils/newton_bisection.frag index 3f4b7f81f..2202b7c1b 100644 --- a/fury/shaders/utils/newton_bisection.frag +++ b/fury/shaders/utils/newton_bisection.frag @@ -1,18 +1,18 @@ -bool newton_bisection(out float out_root, out float out_end_value, +bool newtonBisection(out float outRoot, out float outEndValue, float poly[MAX_DEGREE + 1], float begin, float end, - float begin_value, float error_tolerance) + float beginValue, float errorTolerance, int maxPolyDegree) { if (begin == end) { - out_end_value = begin_value; + outEndValue = beginValue; return false; } // Evaluate the polynomial at the end of the interval - out_end_value = poly[MAX_DEGREE]; + outEndValue = poly[maxPolyDegree]; _unroll_ - for (int i = MAX_DEGREE - 1; i != -1; --i) - out_end_value = out_end_value * end + poly[i]; + for (int i = maxPolyDegree - 1; i != -1; --i) + outEndValue = outEndValue * end + poly[i]; // If the values at both ends have the same non-zero sign, there is no root - if (begin_value * out_end_value > 0.0) + if (beginValue * outEndValue > 0.0) return false; // Otherwise, we find the root iteratively using Newton bisection (with // bounded iteration count) @@ -20,15 +20,15 @@ bool newton_bisection(out float out_root, out float out_end_value, _loop_ for (int i = 0; i != 90; ++i) { // Evaluate the polynomial and its derivative - float value = poly[MAX_DEGREE] * current + poly[MAX_DEGREE - 1]; - float derivative = poly[MAX_DEGREE]; + float value = poly[maxPolyDegree] * current + poly[maxPolyDegree - 1]; + float derivative = poly[maxPolyDegree]; _unroll_ - for (int j = MAX_DEGREE - 2; j != -1; --j) { + for (int j = maxPolyDegree - 2; j != -1; --j) { derivative = derivative * current + value; value = value * current + poly[j]; } // Shorten the interval - bool right = begin_value * value > 0.0; + bool right = beginValue * value > 0.0; begin = right ? current : begin; end = right ? end : current; // Apply Newton's method @@ -37,11 +37,11 @@ bool newton_bisection(out float out_root, out float out_end_value, float middle = 0.5 * (begin + end); float next = (guess >= begin && guess <= end) ? guess : middle; // Move along or terminate - bool done = abs(next - current) < error_tolerance; + bool done = abs(next - current) < errorTolerance; current = next; if (done) break; } - out_root = current; + outRoot = current; return true; } From 95aa9eb71db9f09621dfd64a1a684ff9db3d0726 Mon Sep 17 00:00:00 2001 From: tvcastillod Date: Fri, 13 Sep 2024 09:28:15 -0500 Subject: [PATCH 114/118] made suggested changes --- fury/actors/odf.py | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/fury/actors/odf.py b/fury/actors/odf.py index 58b659507..1502c48cc 100644 --- a/fury/actors/odf.py +++ b/fury/actors/odf.py @@ -327,9 +327,9 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): sh_coeffs = \ """ float i = 1 / (numCoeffsVSOutput * 2); - float sh_coeffs[SH_COUNT]; + float shCoeffs[SH_COUNT]; for(int j=0; j < numCoeffsVSOutput; j++){ - sh_coeffs[j] = rescale( + shCoeffs[j] = rescale( texture( texture0, vec2(i + j / numCoeffsVSOutput, tcoordVCVSOutput.y)).x, @@ -341,9 +341,9 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): # Perform the intersection test intersection_test = \ """ - float ray_params[MAX_DEGREE]; + float rayParams[MAX_DEGREE]; rayGlyphIntersections( - ray_params, sh_coeffs, ro - centerMCVSOutput, rd, int(shDegree), + rayParams, shCoeffs, ro - centerMCVSOutput, rd, int(shDegree), int(numCoeffsVSOutput), int(maxPolyDegreeVSOutput), M_PI, NO_INTERSECTION ); @@ -352,12 +352,11 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): # Identify the first intersection first_intersection = \ """ - float first_ray_param = NO_INTERSECTION; + float firstRayParam = NO_INTERSECTION; _unroll_ - for (int i = 0; i != MAX_DEGREE; ++i) { - //for (int i = 0; i != maxPolyDegreeVSOutput; ++i) { - if (ray_params[i] != NO_INTERSECTION && ray_params[i] > 0.0) { - first_ray_param = ray_params[i]; + for (int i = 0; i != maxPolyDegreeVSOutput; ++i) { + if (rayParams[i] != NO_INTERSECTION && rayParams[i] > 0.0) { + firstRayParam = rayParams[i]; break; } } @@ -367,11 +366,11 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): directional_light = \ """ vec3 color = vec3(1.); - if (first_ray_param != NO_INTERSECTION) { - vec3 intersection = ro - centerMCVSOutput + first_ray_param * rd; - vec3 normal = getShGlyphNormal(sh_coeffs, intersection, int(shDegree), int(numCoeffsVSOutput)); + if (firstRayParam != NO_INTERSECTION) { + vec3 intersection = ro - centerMCVSOutput + firstRayParam * rd; + vec3 normal = getShGlyphNormal(shCoeffs, intersection, int(shDegree), int(numCoeffsVSOutput)); vec3 colorDir = srgbToLinearRgb(abs(normalize(intersection))); - float attenuation = ld.z;//dot(ld, normal); + float attenuation = dot(ld, normal); color = blinnPhongIllumModel( attenuation, lightColor0, colorDir, specularPower, specularColor, ambientColor); @@ -382,8 +381,8 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): frag_output = \ """ - vec3 out_color = linearRgbToSrgb(tonemap(color)); - fragOutput0 = vec4(out_color, opacity); + vec3 outColor = linearRgbToSrgb(tonemap(color)); + fragOutput0 = vec4(outColor, opacity); """ fs_impl = compose_shader([ From ca9ec16e5c18e816bcb819247be435875cbbff09 Mon Sep 17 00:00:00 2001 From: tvcastillod Date: Fri, 13 Sep 2024 10:01:31 -0500 Subject: [PATCH 115/118] adjusted odf actor test --- .../SH-ODF_experimental/example_odf.py | 47 ------------------- fury/tests/test_actors.py | 20 ++------ 2 files changed, 4 insertions(+), 63 deletions(-) delete mode 100644 docs/experimental/SH-ODF_experimental/example_odf.py diff --git a/docs/experimental/SH-ODF_experimental/example_odf.py b/docs/experimental/SH-ODF_experimental/example_odf.py deleted file mode 100644 index ac43687b4..000000000 --- a/docs/experimental/SH-ODF_experimental/example_odf.py +++ /dev/null @@ -1,47 +0,0 @@ -import os - -import numpy as np -from dipy.data.fetcher import dipy_home -from dipy.io.image import load_nifti - -from fury import actor, window - -if __name__ == "__main__": - show_man = window.ShowManager(size=(1280, 720)) - - dataset_dir = os.path.join(dipy_home, "stanford_hardi") - - coeffs, affine = load_nifti("docs\experimental\SH-ODF_experimental\odf_debug_sh_coeffs_9x11x45(8).nii") - - valid_mask = np.abs(coeffs).max(axis=(-1)) > 0 - indices = np.nonzero(valid_mask) - - centers = np.asarray(indices).T - - x, y, z, s = coeffs.shape - coeffs = coeffs[:, :, :].reshape((x * y * z, s)) - - #''' - coeffs = np.array([ - [ - -0.2739740312099, 0.2526670396328, 1.8922271728516, 0.2878578901291, - -0.5339795947075, -0.2620058953762, 0.1580424904823, 0.0329004973173, - -0.1322413831949, -0.1332057565451, 1.0894461870193, -0.6319401264191, - -0.0416776277125, -1.0772529840469, 0.1423762738705, 0.7941166162491, - 0.7490307092667, -0.3428381681442, 0.1024847552180, -0.0219132602215, - 0.0499043911695, 0.2162453681231, 0.0921059995890, -0.2611238956451, - 0.2549301385880, -0.4534865319729, 0.1922748684883, -0.6200597286224, - -0.0532187558711, -0.3569841980934, 0.0293972902000, -0.1977960765362, - -0.1058669015765, 0.2372217923403, -0.1856198310852, -0.3373193442822, - -0.0750469490886, 0.2146576642990, -0.0490148440003, 0.1288588196039, - 0.3173974752426, 0.1990085393190, -0.1736343950033, -0.0482443645597, - 0.1749017387629 - ] - ]) - centers= np.array([0, 0, 0]) - #''' - - odf_actor = actor.odf(centers=centers, coeffs=coeffs, scales=1.0, - sh_basis='descoteaux') - show_man.scene.add(odf_actor) - show_man.start() \ No newline at end of file diff --git a/fury/tests/test_actors.py b/fury/tests/test_actors.py index 043cc0992..dffd2b4fd 100644 --- a/fury/tests/test_actors.py +++ b/fury/tests/test_actors.py @@ -1982,9 +1982,6 @@ def test_odf_actor(interactive=False): npt.assert_equal(report.actors, 1) scene.clear() - # given degree is not even - npt.assert_warns(UserWarning, actor.odf, centers, coeffs, 3) - centers = np.array([0, 0, 0]) coeffs = np.array([ [-0.2739740312099, 0.2526670396328, 1.8922271728516, 0.2878578901291, @@ -1995,7 +1992,8 @@ def test_odf_actor(interactive=False): 0.0499043911695, 0.2162453681231, 0.0921059995890, -0.2611238956451, 0.2549301385880, -0.4534865319729, 0.1922748684883, -0.6200597286224] ]) - odf_actor = actor.odf(centers=centers, coeffs=coeffs, degree=6) + # odf glyph of degree 6 + odf_actor = actor.odf(centers=centers, coeffs=coeffs) scene.add(odf_actor) if interactive: @@ -2005,7 +2003,8 @@ def test_odf_actor(interactive=False): npt.assert_equal(report.actors, 1) scene.clear() - odf_actor = actor.odf(centers=centers, coeffs=coeffs, degree=4) + # odf glyph of degree 4 + odf_actor = actor.odf(centers=centers, coeffs=coeffs[:15]) scene.add(odf_actor) if interactive: @@ -2014,14 +2013,3 @@ def test_odf_actor(interactive=False): report = window.analyze_scene(scene) npt.assert_equal(report.actors, 1) scene.clear() - - odf_actor = actor.odf(centers=centers, coeffs=coeffs, degree=8) - # not enough coefficients for given degree - npt.assert_warns(UserWarning, actor.odf, centers, coeffs, 8) - scene.add(odf_actor) - - if interactive: - window.show(scene) - - npt.assert_equal(report.actors, 1) - scene.clear() From 69f38199f1ccc6d9337f7abe0a870728b33d4d0b Mon Sep 17 00:00:00 2001 From: tvcastillod Date: Fri, 20 Sep 2024 10:51:34 -0500 Subject: [PATCH 116/118] fixed format --- fury/actor.py | 5 +- fury/actors/odf.py | 31 +++++----- fury/shaders/lighting/tonemap.frag | 5 ++ .../odf}/descoteaux/eval_sh_10.frag | 0 .../odf}/descoteaux/eval_sh_12.frag | 0 .../odf}/descoteaux/eval_sh_2.frag | 0 .../odf}/descoteaux/eval_sh_4.frag | 0 .../odf}/descoteaux/eval_sh_6.frag | 0 .../odf}/descoteaux/eval_sh_8.frag | 0 .../odf}/descoteaux/eval_sh_grad_10.frag | 0 .../odf}/descoteaux/eval_sh_grad_12.frag | 0 .../odf}/descoteaux/eval_sh_grad_2.frag | 0 .../odf}/descoteaux/eval_sh_grad_4.frag | 0 .../odf}/descoteaux/eval_sh_grad_6.frag | 0 .../odf}/descoteaux/eval_sh_grad_8.frag | 0 fury/shaders/ray_tracing/odf/eval_sh.frag | 57 ++++++++++++++++++ .../odf}/eval_sh_grad.frag | 2 +- .../odf}/get_inv_vandermonde.frag | 0 .../odf}/get_sh_glyph_normal.frag | 0 .../odf}/ray_sh_glyph_intersections.frag | 0 .../odf}/tournier/eval_sh_10.frag | 2 +- .../odf}/tournier/eval_sh_12.frag | 2 +- .../odf}/tournier/eval_sh_2.frag | 2 +- .../odf}/tournier/eval_sh_4.frag | 2 +- .../odf}/tournier/eval_sh_6.frag | 2 +- .../odf}/tournier/eval_sh_8.frag | 2 +- .../odf}/tournier/eval_sh_grad_10.frag | 0 .../odf}/tournier/eval_sh_grad_12.frag | 0 .../odf}/tournier/eval_sh_grad_2.frag | 0 .../odf}/tournier/eval_sh_grad_4.frag | 0 .../odf}/tournier/eval_sh_grad_6.frag | 0 .../odf}/tournier/eval_sh_grad_8.frag | 0 fury/shaders/rt_odfs/eval_sh.frag | 58 ------------------- fury/shaders/rt_odfs/tonemap.frag | 5 -- fury/shaders/utils/find_roots.frag | 26 ++++----- fury/utils.py | 10 ++-- 36 files changed, 108 insertions(+), 103 deletions(-) create mode 100644 fury/shaders/lighting/tonemap.frag rename fury/shaders/{rt_odfs => ray_tracing/odf}/descoteaux/eval_sh_10.frag (100%) rename fury/shaders/{rt_odfs => ray_tracing/odf}/descoteaux/eval_sh_12.frag (100%) rename fury/shaders/{rt_odfs => ray_tracing/odf}/descoteaux/eval_sh_2.frag (100%) rename fury/shaders/{rt_odfs => ray_tracing/odf}/descoteaux/eval_sh_4.frag (100%) rename fury/shaders/{rt_odfs => ray_tracing/odf}/descoteaux/eval_sh_6.frag (100%) rename fury/shaders/{rt_odfs => ray_tracing/odf}/descoteaux/eval_sh_8.frag (100%) rename fury/shaders/{rt_odfs => ray_tracing/odf}/descoteaux/eval_sh_grad_10.frag (100%) rename fury/shaders/{rt_odfs => ray_tracing/odf}/descoteaux/eval_sh_grad_12.frag (100%) rename fury/shaders/{rt_odfs => ray_tracing/odf}/descoteaux/eval_sh_grad_2.frag (100%) rename fury/shaders/{rt_odfs => ray_tracing/odf}/descoteaux/eval_sh_grad_4.frag (100%) rename fury/shaders/{rt_odfs => ray_tracing/odf}/descoteaux/eval_sh_grad_6.frag (100%) rename fury/shaders/{rt_odfs => ray_tracing/odf}/descoteaux/eval_sh_grad_8.frag (100%) create mode 100644 fury/shaders/ray_tracing/odf/eval_sh.frag rename fury/shaders/{rt_odfs => ray_tracing/odf}/eval_sh_grad.frag (99%) rename fury/shaders/{rt_odfs => ray_tracing/odf}/get_inv_vandermonde.frag (100%) rename fury/shaders/{rt_odfs => ray_tracing/odf}/get_sh_glyph_normal.frag (100%) rename fury/shaders/{rt_odfs => ray_tracing/odf}/ray_sh_glyph_intersections.frag (100%) rename fury/shaders/{rt_odfs => ray_tracing/odf}/tournier/eval_sh_10.frag (98%) rename fury/shaders/{rt_odfs => ray_tracing/odf}/tournier/eval_sh_12.frag (99%) rename fury/shaders/{rt_odfs => ray_tracing/odf}/tournier/eval_sh_2.frag (90%) rename fury/shaders/{rt_odfs => ray_tracing/odf}/tournier/eval_sh_4.frag (95%) rename fury/shaders/{rt_odfs => ray_tracing/odf}/tournier/eval_sh_6.frag (97%) rename fury/shaders/{rt_odfs => ray_tracing/odf}/tournier/eval_sh_8.frag (98%) rename fury/shaders/{rt_odfs => ray_tracing/odf}/tournier/eval_sh_grad_10.frag (100%) rename fury/shaders/{rt_odfs => ray_tracing/odf}/tournier/eval_sh_grad_12.frag (100%) rename fury/shaders/{rt_odfs => ray_tracing/odf}/tournier/eval_sh_grad_2.frag (100%) rename fury/shaders/{rt_odfs => ray_tracing/odf}/tournier/eval_sh_grad_4.frag (100%) rename fury/shaders/{rt_odfs => ray_tracing/odf}/tournier/eval_sh_grad_6.frag (100%) rename fury/shaders/{rt_odfs => ray_tracing/odf}/tournier/eval_sh_grad_8.frag (100%) delete mode 100644 fury/shaders/rt_odfs/eval_sh.frag delete mode 100644 fury/shaders/rt_odfs/tonemap.frag diff --git a/fury/actor.py b/fury/actor.py index d8d9f75a9..cf9c1fe74 100644 --- a/fury/actor.py +++ b/fury/actor.py @@ -4022,9 +4022,11 @@ def uncertainty_cone( return double_cone(centers, evecs, angles, colors, scales, opacity) +@warn_on_args_to_kwargs() def odf( centers, coeffs, + *, sh_basis='descoteaux', scales=1.0, opacity=1.0 @@ -4073,7 +4075,8 @@ def odf( coeffs_given = coeffs.shape[-1] degree = int((np.sqrt(8 * coeffs_given + 1) - 3) / 2) - if (degree%2 != 0): degree -= 1 + if (degree%2 != 0): + degree -= 1 coeffs = coeffs[:, :int(((degree + 1) * (degree + 2)) / 2)] if not isinstance(scales, np.ndarray): scales = np.array(scales) diff --git a/fury/actors/odf.py b/fury/actors/odf.py index 1502c48cc..470bcb64b 100644 --- a/fury/actors/odf.py +++ b/fury/actors/odf.py @@ -57,12 +57,12 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): attribute_to_actor(odf_actor, big_minmax, "minmax") odf_actor_pd = odf_actor.GetMapper().GetInput() - + n_glyphs = coeffs.shape[0] # Coordinates to locate the data of each glyph in the texture. uv_vals = np.array(uv_calculations(n_glyphs)) num_pnts = uv_vals.shape[0] - + # Definition of texture coordinates to be associated with the actor. t_coords = FloatArray() t_coords.SetNumberOfComponents(2) @@ -70,7 +70,7 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): [t_coords.SetTuple(i, uv_vals[i]) for i in range(num_pnts)] set_polydata_tcoords(odf_actor_pd, t_coords) - + # The coefficient data is stored in a texture to be passed to the shaders. # Data is normalized to a range of 0 to 1. @@ -92,7 +92,7 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): max_sh_degree = int((np.sqrt(8 * max_num_coeffs + 1) - 3) / 2) max_poly_degree = 2 * max_sh_degree + 2 viz_sh_degree = max_sh_degree - + # The number of coefficients is associated to the order of the SH odf_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniformf( "shDegree", viz_sh_degree @@ -103,7 +103,7 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): vs_dec = \ """ uniform float shDegree; - + in vec3 center; in vec2 minmax; @@ -185,11 +185,13 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): eval_sh_composed = "" for i in range(2, max_sh_degree + 1, 2): eval_sh = import_fury_shader( - os.path.join("rt_odfs", sh_basis, "eval_sh_" + str(i) + ".frag") + os.path.join("ray_tracing", "odf", sh_basis, "eval_sh_" + str(i) + + ".frag") ) eval_sh_grad = import_fury_shader( os.path.join( - "rt_odfs", sh_basis, "eval_sh_grad_" + str(i) + ".frag" + "ray_tracing", "odf", sh_basis, "eval_sh_grad_" + str(i) + + ".frag" ) ) eval_sh_composed = compose_shader( @@ -230,18 +232,18 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): # SH_DEGREE in this order. # param point The point on the unit sphere where the basis should be # evaluated. - eval_sh = import_fury_shader(os.path.join("rt_odfs", "eval_sh.frag")) + eval_sh = import_fury_shader(os.path.join("ray_tracing", "odf", "eval_sh.frag")) # Evaluates the gradient of each basis function given by eval_sh() and the # basis itself eval_sh_grad = import_fury_shader( - os.path.join("rt_odfs", "eval_sh_grad.frag") + os.path.join("ray_tracing", "odf", "eval_sh_grad.frag") ) # Outputs a matrix that turns equidistant samples on the unit circle of a # homogeneous polynomial into coefficients of that polynomial. get_inv_vandermonde = import_fury_shader( - os.path.join("rt_odfs", "get_inv_vandermonde.frag") + os.path.join("ray_tracing", "odf", "get_inv_vandermonde.frag") ) # Determines all intersections between a ray and a spherical harmonics @@ -255,7 +257,7 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): # param ray_origin The origin of the ray, relative to the glyph center. # param ray_dir The normalized direction vector of the ray. ray_sh_glyph_intersections = import_fury_shader( - os.path.join("rt_odfs", "ray_sh_glyph_intersections.frag") + os.path.join("ray_tracing", "odf", "ray_sh_glyph_intersections.frag") ) # Provides a normalized normal vector for a spherical harmonics glyph. @@ -266,7 +268,7 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): # # return A normalized surface normal pointing away from the origin. get_sh_glyph_normal = import_fury_shader( - os.path.join("rt_odfs", "get_sh_glyph_normal.frag") + os.path.join("ray_tracing", "odf", "get_sh_glyph_normal.frag") ) # Applies the non-linearity that maps linear RGB to sRGB @@ -290,7 +292,7 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): ) # Logarithmic tonemapping operator. Input and output are linear RGB. - tonemap = import_fury_shader(os.path.join("rt_odfs", "tonemap.frag")) + tonemap = import_fury_shader(os.path.join("lighting", "tonemap.frag")) # Blinn-Phong illumination model blinn_phong_model = import_fury_shader( @@ -368,7 +370,8 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): vec3 color = vec3(1.); if (firstRayParam != NO_INTERSECTION) { vec3 intersection = ro - centerMCVSOutput + firstRayParam * rd; - vec3 normal = getShGlyphNormal(shCoeffs, intersection, int(shDegree), int(numCoeffsVSOutput)); + vec3 normal = getShGlyphNormal(shCoeffs, intersection, + int(shDegree), int(numCoeffsVSOutput)); vec3 colorDir = srgbToLinearRgb(abs(normalize(intersection))); float attenuation = dot(ld, normal); color = blinnPhongIllumModel( diff --git a/fury/shaders/lighting/tonemap.frag b/fury/shaders/lighting/tonemap.frag new file mode 100644 index 000000000..aa6002331 --- /dev/null +++ b/fury/shaders/lighting/tonemap.frag @@ -0,0 +1,5 @@ +vec3 tonemap(vec3 linear) +{ + float maxChannel = max(max(1.0, linear.r), max(linear.g, linear.b)); + return linear * ((1.0 - 0.02 * log2(maxChannel)) / maxChannel); +} diff --git a/fury/shaders/rt_odfs/descoteaux/eval_sh_10.frag b/fury/shaders/ray_tracing/odf/descoteaux/eval_sh_10.frag similarity index 100% rename from fury/shaders/rt_odfs/descoteaux/eval_sh_10.frag rename to fury/shaders/ray_tracing/odf/descoteaux/eval_sh_10.frag diff --git a/fury/shaders/rt_odfs/descoteaux/eval_sh_12.frag b/fury/shaders/ray_tracing/odf/descoteaux/eval_sh_12.frag similarity index 100% rename from fury/shaders/rt_odfs/descoteaux/eval_sh_12.frag rename to fury/shaders/ray_tracing/odf/descoteaux/eval_sh_12.frag diff --git a/fury/shaders/rt_odfs/descoteaux/eval_sh_2.frag b/fury/shaders/ray_tracing/odf/descoteaux/eval_sh_2.frag similarity index 100% rename from fury/shaders/rt_odfs/descoteaux/eval_sh_2.frag rename to fury/shaders/ray_tracing/odf/descoteaux/eval_sh_2.frag diff --git a/fury/shaders/rt_odfs/descoteaux/eval_sh_4.frag b/fury/shaders/ray_tracing/odf/descoteaux/eval_sh_4.frag similarity index 100% rename from fury/shaders/rt_odfs/descoteaux/eval_sh_4.frag rename to fury/shaders/ray_tracing/odf/descoteaux/eval_sh_4.frag diff --git a/fury/shaders/rt_odfs/descoteaux/eval_sh_6.frag b/fury/shaders/ray_tracing/odf/descoteaux/eval_sh_6.frag similarity index 100% rename from fury/shaders/rt_odfs/descoteaux/eval_sh_6.frag rename to fury/shaders/ray_tracing/odf/descoteaux/eval_sh_6.frag diff --git a/fury/shaders/rt_odfs/descoteaux/eval_sh_8.frag b/fury/shaders/ray_tracing/odf/descoteaux/eval_sh_8.frag similarity index 100% rename from fury/shaders/rt_odfs/descoteaux/eval_sh_8.frag rename to fury/shaders/ray_tracing/odf/descoteaux/eval_sh_8.frag diff --git a/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_10.frag b/fury/shaders/ray_tracing/odf/descoteaux/eval_sh_grad_10.frag similarity index 100% rename from fury/shaders/rt_odfs/descoteaux/eval_sh_grad_10.frag rename to fury/shaders/ray_tracing/odf/descoteaux/eval_sh_grad_10.frag diff --git a/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_12.frag b/fury/shaders/ray_tracing/odf/descoteaux/eval_sh_grad_12.frag similarity index 100% rename from fury/shaders/rt_odfs/descoteaux/eval_sh_grad_12.frag rename to fury/shaders/ray_tracing/odf/descoteaux/eval_sh_grad_12.frag diff --git a/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_2.frag b/fury/shaders/ray_tracing/odf/descoteaux/eval_sh_grad_2.frag similarity index 100% rename from fury/shaders/rt_odfs/descoteaux/eval_sh_grad_2.frag rename to fury/shaders/ray_tracing/odf/descoteaux/eval_sh_grad_2.frag diff --git a/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_4.frag b/fury/shaders/ray_tracing/odf/descoteaux/eval_sh_grad_4.frag similarity index 100% rename from fury/shaders/rt_odfs/descoteaux/eval_sh_grad_4.frag rename to fury/shaders/ray_tracing/odf/descoteaux/eval_sh_grad_4.frag diff --git a/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_6.frag b/fury/shaders/ray_tracing/odf/descoteaux/eval_sh_grad_6.frag similarity index 100% rename from fury/shaders/rt_odfs/descoteaux/eval_sh_grad_6.frag rename to fury/shaders/ray_tracing/odf/descoteaux/eval_sh_grad_6.frag diff --git a/fury/shaders/rt_odfs/descoteaux/eval_sh_grad_8.frag b/fury/shaders/ray_tracing/odf/descoteaux/eval_sh_grad_8.frag similarity index 100% rename from fury/shaders/rt_odfs/descoteaux/eval_sh_grad_8.frag rename to fury/shaders/ray_tracing/odf/descoteaux/eval_sh_grad_8.frag diff --git a/fury/shaders/ray_tracing/odf/eval_sh.frag b/fury/shaders/ray_tracing/odf/eval_sh.frag new file mode 100644 index 000000000..61de21272 --- /dev/null +++ b/fury/shaders/ray_tracing/odf/eval_sh.frag @@ -0,0 +1,57 @@ +void evalSH(out float outSH[SH_COUNT], vec3 point, int shDegree, int numCoeffs) +{ + if (shDegree == 2) + { + float tmpOutSH[6]; + #if SH_DEGREE == 2 + evalSH2(tmpOutSH, point); + #endif + for (int i = 0; i != numCoeffs; ++i) + outSH[i] = tmpOutSH[i]; + } + else if (shDegree == 4) + { + float tmpOutSH[15]; + #if SH_DEGREE == 4 + evalSH4(tmpOutSH, point); + #endif + for (int i = 0; i != numCoeffs; ++i) + outSH[i] = tmpOutSH[i]; + } + else if (shDegree == 6) + { + float tmpOutSH[28]; + #if SH_DEGREE == 6 + evalSH6(tmpOutSH, point); + #endif + for (int i = 0; i != numCoeffs; ++i) + outSH[i] = tmpOutSH[i]; + } + else if (shDegree == 8) + { + float tmpOutSH[45]; + #if SH_DEGREE == 8 + evalSH8(tmpOutSH, point); + #endif + for (int i = 0; i != numCoeffs; ++i) + outSH[i] = tmpOutSH[i]; + } + else if (shDegree == 10) + { + float tmpOutSH[66]; + #if SH_DEGREE == 10 + evalSH10(tmpOutSH, point); + #endif + for (int i = 0; i != numCoeffs; ++i) + outSH[i] = tmpOutSH[i]; + } + else if (shDegree == 12) + { + float tmpOutSH[91]; + #if SH_DEGREE == 12 + evalSH12(tmpOutSH, point); + #endif + for (int i = 0; i != numCoeffs; ++i) + outSH[i] = tmpOutSH[i]; + } +} diff --git a/fury/shaders/rt_odfs/eval_sh_grad.frag b/fury/shaders/ray_tracing/odf/eval_sh_grad.frag similarity index 99% rename from fury/shaders/rt_odfs/eval_sh_grad.frag rename to fury/shaders/ray_tracing/odf/eval_sh_grad.frag index cfb3fc862..30a2584e3 100644 --- a/fury/shaders/rt_odfs/eval_sh_grad.frag +++ b/fury/shaders/ray_tracing/odf/eval_sh_grad.frag @@ -10,7 +10,7 @@ void evalShGrad(out float outSH[SH_COUNT], out vec3 outGrads[SH_COUNT], vec3 poi #endif for (int i = 0; i != numCoeffs; ++i) outSH[i] = tmpOutSH[i]; - + } else if (shDegree == 4) { diff --git a/fury/shaders/rt_odfs/get_inv_vandermonde.frag b/fury/shaders/ray_tracing/odf/get_inv_vandermonde.frag similarity index 100% rename from fury/shaders/rt_odfs/get_inv_vandermonde.frag rename to fury/shaders/ray_tracing/odf/get_inv_vandermonde.frag diff --git a/fury/shaders/rt_odfs/get_sh_glyph_normal.frag b/fury/shaders/ray_tracing/odf/get_sh_glyph_normal.frag similarity index 100% rename from fury/shaders/rt_odfs/get_sh_glyph_normal.frag rename to fury/shaders/ray_tracing/odf/get_sh_glyph_normal.frag diff --git a/fury/shaders/rt_odfs/ray_sh_glyph_intersections.frag b/fury/shaders/ray_tracing/odf/ray_sh_glyph_intersections.frag similarity index 100% rename from fury/shaders/rt_odfs/ray_sh_glyph_intersections.frag rename to fury/shaders/ray_tracing/odf/ray_sh_glyph_intersections.frag diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_10.frag b/fury/shaders/ray_tracing/odf/tournier/eval_sh_10.frag similarity index 98% rename from fury/shaders/rt_odfs/tournier/eval_sh_10.frag rename to fury/shaders/ray_tracing/odf/tournier/eval_sh_10.frag index d47efb629..d5b33c189 100644 --- a/fury/shaders/rt_odfs/tournier/eval_sh_10.frag +++ b/fury/shaders/ray_tracing/odf/tournier/eval_sh_10.frag @@ -1,4 +1,4 @@ -void eval_sh_10(out float outSH[66], vec3 point) +void evalSH10(out float outSH[66], vec3 point) { float x, y, z, z2, c0, s0, c1, s1, d, a, b; x = point[0]; diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_12.frag b/fury/shaders/ray_tracing/odf/tournier/eval_sh_12.frag similarity index 99% rename from fury/shaders/rt_odfs/tournier/eval_sh_12.frag rename to fury/shaders/ray_tracing/odf/tournier/eval_sh_12.frag index bad475582..3994374e9 100644 --- a/fury/shaders/rt_odfs/tournier/eval_sh_12.frag +++ b/fury/shaders/ray_tracing/odf/tournier/eval_sh_12.frag @@ -1,4 +1,4 @@ -void eval_sh_12(out float outSH[91], vec3 point) +void evalSH12(out float outSH[91], vec3 point) { float x, y, z, z2, c0, s0, c1, s1, d, a, b; x = point[0]; diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_2.frag b/fury/shaders/ray_tracing/odf/tournier/eval_sh_2.frag similarity index 90% rename from fury/shaders/rt_odfs/tournier/eval_sh_2.frag rename to fury/shaders/ray_tracing/odf/tournier/eval_sh_2.frag index 98dfa2d0a..174ac5d62 100644 --- a/fury/shaders/rt_odfs/tournier/eval_sh_2.frag +++ b/fury/shaders/ray_tracing/odf/tournier/eval_sh_2.frag @@ -1,4 +1,4 @@ -void eval_sh_2(out float outSH[6], vec3 point) +void evalSH2(out float outSH[6], vec3 point) { float x, y, z, z2, c0, s0, c1, s1, d, a; x = point[0]; diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_4.frag b/fury/shaders/ray_tracing/odf/tournier/eval_sh_4.frag similarity index 95% rename from fury/shaders/rt_odfs/tournier/eval_sh_4.frag rename to fury/shaders/ray_tracing/odf/tournier/eval_sh_4.frag index 0ea37caa4..77152bb6a 100644 --- a/fury/shaders/rt_odfs/tournier/eval_sh_4.frag +++ b/fury/shaders/ray_tracing/odf/tournier/eval_sh_4.frag @@ -1,4 +1,4 @@ -void eval_sh_4(out float outSH[15], vec3 point) +void evalSH4(out float outSH[15], vec3 point) { float x, y, z, z2, c0, s0, c1, s1, d, a, b; x = point[0]; diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_6.frag b/fury/shaders/ray_tracing/odf/tournier/eval_sh_6.frag similarity index 97% rename from fury/shaders/rt_odfs/tournier/eval_sh_6.frag rename to fury/shaders/ray_tracing/odf/tournier/eval_sh_6.frag index 1d17b9b8b..6e3d53307 100644 --- a/fury/shaders/rt_odfs/tournier/eval_sh_6.frag +++ b/fury/shaders/ray_tracing/odf/tournier/eval_sh_6.frag @@ -1,4 +1,4 @@ -void eval_sh_6(out float outSH[28], vec3 point) +void evalSH6(out float outSH[28], vec3 point) { float x, y, z, z2, c0, s0, c1, s1, d, a, b; x = point[0]; diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_8.frag b/fury/shaders/ray_tracing/odf/tournier/eval_sh_8.frag similarity index 98% rename from fury/shaders/rt_odfs/tournier/eval_sh_8.frag rename to fury/shaders/ray_tracing/odf/tournier/eval_sh_8.frag index 6550fc525..e68a3efba 100644 --- a/fury/shaders/rt_odfs/tournier/eval_sh_8.frag +++ b/fury/shaders/ray_tracing/odf/tournier/eval_sh_8.frag @@ -1,4 +1,4 @@ -void eval_sh_8(out float outSH[45], vec3 point) +void evalSH8(out float outSH[45], vec3 point) { float x, y, z, z2, c0, s0, c1, s1, d, a, b; x = point[0]; diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_10.frag b/fury/shaders/ray_tracing/odf/tournier/eval_sh_grad_10.frag similarity index 100% rename from fury/shaders/rt_odfs/tournier/eval_sh_grad_10.frag rename to fury/shaders/ray_tracing/odf/tournier/eval_sh_grad_10.frag diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_12.frag b/fury/shaders/ray_tracing/odf/tournier/eval_sh_grad_12.frag similarity index 100% rename from fury/shaders/rt_odfs/tournier/eval_sh_grad_12.frag rename to fury/shaders/ray_tracing/odf/tournier/eval_sh_grad_12.frag diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_2.frag b/fury/shaders/ray_tracing/odf/tournier/eval_sh_grad_2.frag similarity index 100% rename from fury/shaders/rt_odfs/tournier/eval_sh_grad_2.frag rename to fury/shaders/ray_tracing/odf/tournier/eval_sh_grad_2.frag diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_4.frag b/fury/shaders/ray_tracing/odf/tournier/eval_sh_grad_4.frag similarity index 100% rename from fury/shaders/rt_odfs/tournier/eval_sh_grad_4.frag rename to fury/shaders/ray_tracing/odf/tournier/eval_sh_grad_4.frag diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_6.frag b/fury/shaders/ray_tracing/odf/tournier/eval_sh_grad_6.frag similarity index 100% rename from fury/shaders/rt_odfs/tournier/eval_sh_grad_6.frag rename to fury/shaders/ray_tracing/odf/tournier/eval_sh_grad_6.frag diff --git a/fury/shaders/rt_odfs/tournier/eval_sh_grad_8.frag b/fury/shaders/ray_tracing/odf/tournier/eval_sh_grad_8.frag similarity index 100% rename from fury/shaders/rt_odfs/tournier/eval_sh_grad_8.frag rename to fury/shaders/ray_tracing/odf/tournier/eval_sh_grad_8.frag diff --git a/fury/shaders/rt_odfs/eval_sh.frag b/fury/shaders/rt_odfs/eval_sh.frag deleted file mode 100644 index fac4b17d8..000000000 --- a/fury/shaders/rt_odfs/eval_sh.frag +++ /dev/null @@ -1,58 +0,0 @@ -void evalSH(out float outSH[SH_COUNT], vec3 point, int shDegree, - int numCoeffs) - { - if (shDegree == 2) - { - float tmpOutSH[6]; - #if SH_DEGREE == 2 - evalSH2(tmpOutSH, point); - #endif - for (int i = 0; i != numCoeffs; ++i) - outSH[i] = tmpOutSH[i]; - } - else if (shDegree == 4) - { - float tmpOutSH[15]; - #if SH_DEGREE == 4 - evalSH4(tmpOutSH, point); - #endif - for (int i = 0; i != numCoeffs; ++i) - outSH[i] = tmpOutSH[i]; - } - else if (shDegree == 6) - { - float tmpOutSH[28]; - #if SH_DEGREE == 6 - evalSH6(tmpOutSH, point); - #endif - for (int i = 0; i != numCoeffs; ++i) - outSH[i] = tmpOutSH[i]; - } - else if (shDegree == 8) - { - float tmpOutSH[45]; - #if SH_DEGREE == 8 - evalSH8(tmpOutSH, point); - #endif - for (int i = 0; i != numCoeffs; ++i) - outSH[i] = tmpOutSH[i]; - } - else if (shDegree == 10) - { - float tmpOutSH[66]; - #if SH_DEGREE == 10 - evalSH10(tmpOutSH, point); - #endif - for (int i = 0; i != numCoeffs; ++i) - outSH[i] = tmpOutSH[i]; - } - else if (shDegree == 12) - { - float tmpOutSH[91]; - #if SH_DEGREE == 12 - evalSH12(tmpOutSH, point); - #endif - for (int i = 0; i != numCoeffs; ++i) - outSH[i] = tmpOutSH[i]; - } - } \ No newline at end of file diff --git a/fury/shaders/rt_odfs/tonemap.frag b/fury/shaders/rt_odfs/tonemap.frag deleted file mode 100644 index dd6cdcacb..000000000 --- a/fury/shaders/rt_odfs/tonemap.frag +++ /dev/null @@ -1,5 +0,0 @@ -vec3 tonemap(vec3 linear) -{ - float max_channel = max(max(1.0, linear.r), max(linear.g, linear.b)); - return linear * ((1.0 - 0.02 * log2(max_channel)) / max_channel); -} diff --git a/fury/shaders/utils/find_roots.frag b/fury/shaders/utils/find_roots.frag index 9c69a4801..8b5377942 100644 --- a/fury/shaders/utils/find_roots.frag +++ b/fury/shaders/utils/find_roots.frag @@ -15,12 +15,12 @@ void findRoots(out float outRoots[MAX_DEGREE + 1], float poly[MAX_DEGREE + 1], f // Compute its two roots using the quadratic formula float discriminant = derivative[1] * derivative[1] - 4.0 * derivative[0] * derivative[2]; if (discriminant >= 0.0) { - float sqrt_discriminant = sqrt(discriminant); - float scaled_root = derivative[1] + ((derivative[1] > 0.0) ? sqrt_discriminant : (-sqrt_discriminant)); - float root_0 = clamp(-2.0 * derivative[0] / scaled_root, begin, end); - float root_1 = clamp(-0.5 * scaled_root / derivative[2], begin, end); - outRoots[maxPolyDegree - 2] = min(root_0, root_1); - outRoots[maxPolyDegree - 1] = max(root_0, root_1); + float sqrtDiscriminant = sqrt(discriminant); + float scaledRoot = derivative[1] + ((derivative[1] > 0.0) ? sqrtDiscriminant : (-sqrtDiscriminant)); + float root0 = clamp(-2.0 * derivative[0] / scaledRoot, begin, end); + float root1 = clamp(-0.5 * scaledRoot / derivative[2], begin, end); + outRoots[maxPolyDegree - 2] = min(root0, root1); + outRoots[maxPolyDegree - 1] = max(root0, root1); } else { // Indicate that the cubic derivative has a single root @@ -45,30 +45,30 @@ void findRoots(out float outRoots[MAX_DEGREE + 1], float poly[MAX_DEGREE + 1], f for (int degree = 3; degree != maxPolyDegree + 1; ++degree) { // Take the integral of the previous derivative (scaled such that the // constant coefficient can still be copied directly from poly) - float prev_derivative_order = float(maxPolyDegree + 1 - degree); + float prevDerivativeOrder = float(maxPolyDegree + 1 - degree); _unroll_ for (int i = maxPolyDegree; i != 0; --i) - derivative[i] = derivative[i - 1] * (prev_derivative_order * (1.0 / float(i))); + derivative[i] = derivative[i - 1] * (prevDerivativeOrder * (1.0 / float(i))); // Copy the constant coefficient without causing spilling. This part // would be harder if the derivative were not scaled the way it is. _unroll_ for (int i = 0; i != maxPolyDegree - 2; ++i) derivative[0] = (degree == maxPolyDegree - i) ? poly[i] : derivative[0]; // Determine the value of this derivative at begin - float begin_value = derivative[maxPolyDegree]; + float beginValue = derivative[maxPolyDegree]; _unroll_ for (int i = maxPolyDegree - 1; i != -1; --i) - begin_value = begin_value * begin + derivative[i]; + beginValue = beginValue * begin + derivative[i]; // Iterate over the intervals where roots may be found _unroll_ for (int i = 0; i != maxPolyDegree; ++i) { if (i < maxPolyDegree - degree) continue; - float current_begin = outRoots[i]; - float current_end = outRoots[i + 1]; + float currentBegin = outRoots[i]; + float currentEnd = outRoots[i + 1]; // Try to find a root float root; - if (newtonBisection(root, begin_value, derivative, current_begin, current_end, begin_value, tolerance, maxPolyDegree)) + if (newtonBisection(root, beginValue, derivative, currentBegin, currentEnd, beginValue, tolerance, maxPolyDegree)) outRoots[i] = root; else if (degree < maxPolyDegree) // Create an empty interval for the next iteration diff --git a/fury/utils.py b/fury/utils.py index 2b170a2a2..6ee13a489 100644 --- a/fury/utils.py +++ b/fury/utils.py @@ -1645,13 +1645,13 @@ def minmax_norm(data, axis=1): if data.ndim == 1: data = np.array([data]) elif data.ndim > 2: - raise ValueError('the dimension of the array must be 2.') + raise ValueError("the dimension of the array dimension must be 2.") minimum = data.min(axis=axis) maximum = data.max(axis=axis) if np.array_equal(minimum, maximum): return data - if (axis == 0): - return (data - minimum)/(maximum - minimum) - if (axis == 1): - return (data - minimum[:, None])/(maximum - minimum)[:, None] + if axis == 0: + return (data - minimum) / (maximum - minimum) + if axis == 1: + return (data - minimum[:, None]) / (maximum - minimum)[:, None] From 98d01af393960495eeba048700d4baa872416615 Mon Sep 17 00:00:00 2001 From: tvcastillod Date: Mon, 30 Sep 2024 12:24:39 -0500 Subject: [PATCH 117/118] made adjustments to the format --- fury/actor.py | 30 ++++------ fury/actors/odf.py | 73 ++++++++++-------------- fury/tests/test_actors.py | 117 +++++++++++++++++++++++++++++++------- fury/tests/test_utils.py | 12 ++-- fury/utils.py | 2 +- 5 files changed, 143 insertions(+), 91 deletions(-) diff --git a/fury/actor.py b/fury/actor.py index cf9c1fe74..26b948c2e 100644 --- a/fury/actor.py +++ b/fury/actor.py @@ -7,6 +7,7 @@ import numpy as np from fury import layout as lyt +from fury.actors.odf import sh_odf from fury.actors.odf_slicer import OdfSlicerActor from fury.actors.peak import PeakActor from fury.actors.tensor import ( @@ -14,7 +15,6 @@ main_dir_uncertainty, tensor_ellipsoid, ) -from fury.actors.odf import sh_odf from fury.colormap import colormap_lookup_table from fury.decorators import warn_on_args_to_kwargs from fury.io import load_image @@ -4022,15 +4022,7 @@ def uncertainty_cone( return double_cone(centers, evecs, angles, colors, scales, opacity) -@warn_on_args_to_kwargs() -def odf( - centers, - coeffs, - *, - sh_basis='descoteaux', - scales=1.0, - opacity=1.0 -): +def odf(centers, coeffs, sh_basis="descoteaux", scales=1.0, opacity=1.0): """ FURY actor for visualizing Orientation Distribution Functions (ODFs) given an array of Spherical Harmonics (SH) coefficients. @@ -4046,9 +4038,9 @@ def odf( Type of basis (descoteaux, tournier) 'descoteaux' for the default ``descoteaux07`` DYPY basis. 'tournier' for the default ``tournier07` DYPY basis. - scales : float or ndarray (N, ) + scales : float or ndarray (N, ), optional ODFs size. - opacity : float + opacity : float, optional Takes values from 0 (fully transparent) to 1 (opaque). Returns @@ -4068,23 +4060,25 @@ def odf( if coeffs.ndim == 1: coeffs = np.array([coeffs]) else: - raise ValueError('coeffs should be a 2D array.') + raise ValueError("coeffs should be a 2D array.") if coeffs.shape[0] != centers.shape[0]: - raise ValueError('number of odf glyphs defined does not match with ' - 'number of centers') + raise ValueError( + "number of odf glyphs defined does not match with number of centers" + ) coeffs_given = coeffs.shape[-1] degree = int((np.sqrt(8 * coeffs_given + 1) - 3) / 2) - if (degree%2 != 0): + if degree % 2 != 0: degree -= 1 - coeffs = coeffs[:, :int(((degree + 1) * (degree + 2)) / 2)] + coeffs = coeffs[:, : int(((degree + 1) * (degree + 2)) / 2)] if not isinstance(scales, np.ndarray): scales = np.array(scales) if scales.size == 1: scales = np.repeat(scales, centers.shape[0]) elif scales.size != centers.shape[0]: scales = np.concatenate( - (scales, np.ones(centers.shape[0] - scales.shape[0])), axis=None) + (scales, np.ones(centers.shape[0] - scales.shape[0])), axis=None + ) total = np.sum(abs(coeffs), axis=1) coeffs = np.dot(np.diag(1 / total * scales), coeffs) * 1.7 diff --git a/fury/actors/odf.py b/fury/actors/odf.py index 470bcb64b..fd317b8d5 100644 --- a/fury/actors/odf.py +++ b/fury/actors/odf.py @@ -10,12 +10,8 @@ import_fury_shader, shader_to_actor, ) -from fury.utils import ( - numpy_to_vtk_image_data, - set_polydata_tcoords, - minmax_norm -) from fury.texture.utils import uv_calculations +from fury.utils import minmax_norm, numpy_to_vtk_image_data, set_polydata_tcoords def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): @@ -100,8 +96,7 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): # Start of shader implementation - vs_dec = \ - """ + vs_dec = """ uniform float shDegree; in vec3 center; @@ -117,8 +112,7 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): out vec3 camUpMCVSOutput; """ - vs_impl = \ - """ + vs_impl = """ numCoeffsVSOutput = (shDegree + 1) * (shDegree + 2) / 2; maxPolyDegreeVSOutput = 2 * shDegree + 2; vertexMCVSOutput = vertexMC; @@ -147,8 +141,7 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): # defined as [[unroll]] and [[loop]] to give reasonable hints to the # compiler. That avoids register spilling, which makes execution # considerably faster. - def_gl_ext_control_flow_attributes = \ - """ + def_gl_ext_control_flow_attributes = """ #ifndef _unroll_ #define _unroll_ #endif @@ -162,14 +155,12 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): def_no_intersection = "#define NO_INTERSECTION 3.4e38" # pi and its reciprocal - def_pis = \ - """ + def_pis = """ #define M_PI 3.141592653589793238462643 #define M_INV_PI 0.318309886183790671537767526745 """ - fs_vs_vars = \ - """ + fs_vs_vars = """ flat in float numCoeffsVSOutput; flat in float maxPolyDegreeVSOutput; in vec4 vertexMCVSOutput; @@ -185,18 +176,14 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): eval_sh_composed = "" for i in range(2, max_sh_degree + 1, 2): eval_sh = import_fury_shader( - os.path.join("ray_tracing", "odf", sh_basis, "eval_sh_" + str(i) + - ".frag") + os.path.join("ray_tracing", "odf", sh_basis, "eval_sh_" + str(i) + ".frag") ) eval_sh_grad = import_fury_shader( os.path.join( - "ray_tracing", "odf", sh_basis, "eval_sh_grad_" + str(i) + - ".frag" + "ray_tracing", "odf", sh_basis, "eval_sh_grad_" + str(i) + ".frag" ) ) - eval_sh_composed = compose_shader( - [eval_sh_composed, eval_sh, eval_sh_grad] - ) + eval_sh_composed = compose_shader([eval_sh_composed, eval_sh, eval_sh_grad]) # Searches a single root of a polynomial within a given interval. # param out_root The location of the found root. @@ -272,14 +259,10 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): ) # Applies the non-linearity that maps linear RGB to sRGB - linear_to_srgb = import_fury_shader( - os.path.join("lighting", "linear_to_srgb.frag") - ) + linear_to_srgb = import_fury_shader(os.path.join("lighting", "linear_to_srgb.frag")) # Inverse of linear_to_srgb() - srgb_to_linear = import_fury_shader( - os.path.join("lighting", "srgb_to_linear.frag") - ) + srgb_to_linear = import_fury_shader(os.path.join("lighting", "srgb_to_linear.frag")) # Turns a linear RGB color (i.e. rec. 709) into sRGB linear_rgb_to_srgb = import_fury_shader( @@ -326,8 +309,7 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): light_direction = "vec3 ld = normalize(ro - pnt);" # Define SH coefficients (measured up to band 8, noise beyond that) - sh_coeffs = \ - """ + sh_coeffs = """ float i = 1 / (numCoeffsVSOutput * 2); float shCoeffs[SH_COUNT]; for(int j=0; j < numCoeffsVSOutput; j++){ @@ -341,8 +323,7 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): """ # Perform the intersection test - intersection_test = \ - """ + intersection_test = """ float rayParams[MAX_DEGREE]; rayGlyphIntersections( rayParams, shCoeffs, ro - centerMCVSOutput, rd, int(shDegree), @@ -352,8 +333,7 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): """ # Identify the first intersection - first_intersection = \ - """ + first_intersection = """ float firstRayParam = NO_INTERSECTION; _unroll_ for (int i = 0; i != maxPolyDegreeVSOutput; ++i) { @@ -365,12 +345,11 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): """ # Evaluate shading for a directional light - directional_light = \ - """ + directional_light = """ vec3 color = vec3(1.); if (firstRayParam != NO_INTERSECTION) { vec3 intersection = ro - centerMCVSOutput + firstRayParam * rd; - vec3 normal = getShGlyphNormal(shCoeffs, intersection, + vec3 normal = getShGlyphNormal(shCoeffs, intersection, int(shDegree), int(numCoeffsVSOutput)); vec3 colorDir = srgbToLinearRgb(abs(normalize(intersection))); float attenuation = dot(ld, normal); @@ -382,16 +361,24 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity): } """ - frag_output = \ - """ + frag_output = """ vec3 outColor = linearRgbToSrgb(tonemap(color)); fragOutput0 = vec4(outColor, opacity); """ - fs_impl = compose_shader([ - point_from_vs, ray_origin, ray_direction, light_direction, sh_coeffs, - intersection_test, first_intersection, directional_light, frag_output - ]) + fs_impl = compose_shader( + [ + point_from_vs, + ray_origin, + ray_direction, + light_direction, + sh_coeffs, + intersection_test, + first_intersection, + directional_light, + frag_output, + ] + ) shader_to_actor(odf_actor, "fragment", impl_code=fs_impl, block="picking") diff --git a/fury/tests/test_actors.py b/fury/tests/test_actors.py index dffd2b4fd..b41c65d6b 100644 --- a/fury/tests/test_actors.py +++ b/fury/tests/test_actors.py @@ -1955,23 +1955,71 @@ def test_actors_primitives_count(): def test_odf_actor(interactive=False): # number of odf glyphs does not match with number of centers centers = np.array([[0, -1, 0]]) - coeffs = np.array([[0.282, 0.152, -0.040, -0.112, -0.045, 0.149], - [0.285, 0.097, -0.115, 0.125, -0.001, 0.003]]) + coeffs = np.array( + [ + [0.282, 0.152, -0.040, -0.112, -0.045, 0.149], + [0.285, 0.097, -0.115, 0.125, -0.001, 0.003], + ] + ) npt.assert_raises(ValueError, actor.odf, centers, coeffs) scene = window.Scene() centers = np.array([[0, -1, 0], [1, -1, 0], [2, -1, 0]]) - coeffs = np.array([ - [0.2820735, 0.15236554, -0.04038717, -0.11270988, -0.04532376, - 0.14921817, 0.00257928, 0.0040734, -0.05313807, 0.03486542, - 0.04083064, 0.02105767, -0.04389586, -0.04302812, 0.1048641], - [0.28549338, 0.0978267, -0.11544838, 0.12525354, -0.00126003, - 0.00320594, 0.04744155, -0.07141446, 0.03211689, 0.04711322, - 0.08064896, 0.00154299, 0.00086506, 0.00162543, -0.00444893], - [0.28208936, -0.13133252, -0.04701012, -0.06303016, -0.0468775, - 0.02348355, 0.03991898, 0.02587433, 0.02645416, 0.00668765, - 0.00890633, 0.02189304, 0.00387415, 0.01665629, -0.01427194] - ]) + coeffs = np.array( + [ + [ + 0.2820735, + 0.15236554, + -0.04038717, + -0.11270988, + -0.04532376, + 0.14921817, + 0.00257928, + 0.0040734, + -0.05313807, + 0.03486542, + 0.04083064, + 0.02105767, + -0.04389586, + -0.04302812, + 0.1048641, + ], + [ + 0.28549338, + 0.0978267, + -0.11544838, + 0.12525354, + -0.00126003, + 0.00320594, + 0.04744155, + -0.07141446, + 0.03211689, + 0.04711322, + 0.08064896, + 0.00154299, + 0.00086506, + 0.00162543, + -0.00444893, + ], + [ + 0.28208936, + -0.13133252, + -0.04701012, + -0.06303016, + -0.0468775, + 0.02348355, + 0.03991898, + 0.02587433, + 0.02645416, + 0.00668765, + 0.00890633, + 0.02189304, + 0.00387415, + 0.01665629, + -0.01427194, + ], + ] + ) odf_actor = actor.odf(centers=centers, coeffs=coeffs) scene.add(odf_actor) @@ -1983,15 +2031,40 @@ def test_odf_actor(interactive=False): scene.clear() centers = np.array([0, 0, 0]) - coeffs = np.array([ - [-0.2739740312099, 0.2526670396328, 1.8922271728516, 0.2878578901291, - -0.5339795947075, -0.2620058953762, 0.1580424904823, 0.0329004973173, - -0.1322413831949, -0.1332057565451, 1.0894461870193, -0.6319401264191, - -0.0416776277125, -1.0772529840469, 0.1423762738705, 0.7941166162491, - 0.7490307092667, -0.3428381681442, 0.1024847552180, -0.0219132602215, - 0.0499043911695, 0.2162453681231, 0.0921059995890, -0.2611238956451, - 0.2549301385880, -0.4534865319729, 0.1922748684883, -0.6200597286224] - ]) + coeffs = np.array( + [ + [ + -0.2739740312099, + 0.2526670396328, + 1.8922271728516, + 0.2878578901291, + -0.5339795947075, + -0.2620058953762, + 0.1580424904823, + 0.0329004973173, + -0.1322413831949, + -0.1332057565451, + 1.0894461870193, + -0.6319401264191, + -0.0416776277125, + -1.0772529840469, + 0.1423762738705, + 0.7941166162491, + 0.7490307092667, + -0.3428381681442, + 0.1024847552180, + -0.0219132602215, + 0.0499043911695, + 0.2162453681231, + 0.0921059995890, + -0.2611238956451, + 0.2549301385880, + -0.4534865319729, + 0.1922748684883, + -0.6200597286224, + ] + ] + ) # odf glyph of degree 6 odf_actor = actor.odf(centers=centers, coeffs=coeffs) scene.add(odf_actor) diff --git a/fury/tests/test_utils.py b/fury/tests/test_utils.py index f1758fa95..c4904be5f 100644 --- a/fury/tests/test_utils.py +++ b/fury/tests/test_utils.py @@ -37,6 +37,7 @@ get_polydata_tangents, is_ui, map_coordinates_3d_4d, + minmax_norm, normals_from_actor, normals_to_actor, numpy_to_vtk_matrix, @@ -54,7 +55,6 @@ update_surface_actor_colors, vertices_from_actor, vtk_matrix_to_numpy, - minmax_norm, ) dipy, have_dipy, _ = optional_package("dipy") @@ -976,20 +976,18 @@ def test_set_actor_origin(): def test_minmax_normalization(): data1d = np.array([2, -2, 5, -1, 8]) actual_data1d = minmax_norm(data1d) - expected_data1d = np.array([[0.4, 0. , 0.7, 0.1, 1. ]]) + expected_data1d = np.array([[0.4, 0.0, 0.7, 0.1, 1.0]]) npt.assert_array_almost_equal(actual_data1d, expected_data1d, decimal=1) - data3d = np.array([[[2, 7, 7, 9], [2, -1, -3, 5]], - [[-4, 5, 6, 0], [1, 1, -9, 3]]]) + data3d = np.array([[[2, 7, 7, 9], [2, -1, -3, 5]], [[-4, 5, 6, 0], [1, 1, -9, 3]]]) npt.assert_raises(ValueError, utils.minmax_norm, data3d) - + data = np.array([[1, 2, -1, 3], [4, -1, 3, 5], [-1, 9, 8, 0]]) actual = minmax_norm(data, axis=0) expected = np.array([[0.4, 0.3, 0, 0.6], [1, 0, 0.444, 1], [0, 1, 1, 0]]) npt.assert_array_almost_equal(actual, expected, decimal=3) actual = minmax_norm(data, axis=1) - expected = np.array([[0.5, 0.75, 0, 1], [0.833, 0, 0.666, 1], - [0, 1, 0.9, 0.1]]) + expected = np.array([[0.5, 0.75, 0, 1], [0.833, 0, 0.666, 1], [0, 1, 0.9, 0.1]]) npt.assert_array_almost_equal(actual, expected, decimal=3) data2 = np.array([1, 3, 9, 6]) diff --git a/fury/utils.py b/fury/utils.py index 6ee13a489..e524f7299 100644 --- a/fury/utils.py +++ b/fury/utils.py @@ -1631,7 +1631,7 @@ def minmax_norm(data, axis=1): ---------- data: ndarray 2D array - axis: int + axis: int, optional axis for the function to be applied on Returns From 9824013afab0b492c68a6997e5f623cb537d8c8a Mon Sep 17 00:00:00 2001 From: tvcastillod Date: Mon, 30 Sep 2024 12:29:23 -0500 Subject: [PATCH 118/118] fixed format --- fury/texture/tests/test_utils.py | 142 +++++++++++++++++++++++-------- 1 file changed, 108 insertions(+), 34 deletions(-) diff --git a/fury/texture/tests/test_utils.py b/fury/texture/tests/test_utils.py index 71f108596..de85ec3ab 100644 --- a/fury/texture/tests/test_utils.py +++ b/fury/texture/tests/test_utils.py @@ -1,41 +1,115 @@ import numpy as np import numpy.testing as npt + from fury.texture.utils import uv_calculations + def test_uv_calculations(): - uv_coords = uv_calculations(1) - expected_uv1 = np.array([ - [0.001, 0.001], [0.001, 0.999], [0.999, 0.999], [0.999, 0.001], - [0.001, 0.001], [0.001, 0.999], [0.999, 0.999], [0.999, 0.001] - ]) - npt.assert_array_almost_equal(uv_coords, expected_uv1, decimal=3) + uv_coords = uv_calculations(1) + expected_uv1 = np.array( + [ + [0.001, 0.001], + [0.001, 0.999], + [0.999, 0.999], + [0.999, 0.001], + [0.001, 0.001], + [0.001, 0.999], + [0.999, 0.999], + [0.999, 0.001], + ] + ) + npt.assert_array_almost_equal(uv_coords, expected_uv1, decimal=3) - uv_coords = uv_calculations(3) - expected_uv3 = np.array([ - [0.001, 0.667], [0.001, 0.999], [0.999, 0.999], [0.999, 0.667], - [0.001, 0.667], [0.001, 0.999], [0.999, 0.999], [0.999, 0.667], - [0.001, 0.334], [0.001, 0.665], [0.999, 0.665], [0.999, 0.334], - [0.001, 0.334], [0.001, 0.665], [0.999, 0.665], [0.999, 0.334], - [0.001, 0.001], [0.001, 0.332], [0.999, 0.332], [0.999, 0.001], - [0.001, 0.001], [0.001, 0.332], [0.999, 0.332], [0.999, 0.001] - ]) - npt.assert_array_almost_equal(uv_coords, expected_uv3, decimal=3) + uv_coords = uv_calculations(3) + expected_uv3 = np.array( + [ + [0.001, 0.667], + [0.001, 0.999], + [0.999, 0.999], + [0.999, 0.667], + [0.001, 0.667], + [0.001, 0.999], + [0.999, 0.999], + [0.999, 0.667], + [0.001, 0.334], + [0.001, 0.665], + [0.999, 0.665], + [0.999, 0.334], + [0.001, 0.334], + [0.001, 0.665], + [0.999, 0.665], + [0.999, 0.334], + [0.001, 0.001], + [0.001, 0.332], + [0.999, 0.332], + [0.999, 0.001], + [0.001, 0.001], + [0.001, 0.332], + [0.999, 0.332], + [0.999, 0.001], + ] + ) + npt.assert_array_almost_equal(uv_coords, expected_uv3, decimal=3) - uv_coords = uv_calculations(7) - expected_uv7 = np.array([ - [0.001, 0.858], [0.001, 0.999], [0.999, 0.999], [0.999, 0.858], - [0.001, 0.858], [0.001, 0.999], [0.999, 0.999], [0.999, 0.858], - [0.001, 0.715], [0.001, 0.856], [0.999, 0.856], [0.999, 0.715], - [0.001, 0.715], [0.001, 0.856], [0.999, 0.856], [0.999, 0.715], - [0.001, 0.572], [0.001, 0.713], [0.999, 0.713], [0.999, 0.572], - [0.001, 0.572], [0.001, 0.713], [0.999, 0.713], [0.999, 0.572], - [0.001, 0.429], [0.001, 0.570], [0.999, 0.570], [0.999, 0.429], - [0.001, 0.429], [0.001, 0.570], [0.999, 0.570], [0.999, 0.429], - [0.001, 0.286], [0.001, 0.427], [0.999, 0.427], [0.999, 0.286], - [0.001, 0.286], [0.001, 0.427], [0.999, 0.427], [0.999, 0.286], - [0.001, 0.143], [0.001, 0.284], [0.999, 0.284], [0.999, 0.143], - [0.001, 0.143], [0.001, 0.284], [0.999, 0.284], [0.999, 0.143], - [0.001, 0.001], [0.001, 0.141], [0.999, 0.141], [0.999, 0.001], - [0.001, 0.001], [0.001, 0.141], [0.999, 0.141], [0.999, 0.001] - ]) - npt.assert_array_almost_equal(uv_coords, expected_uv7, decimal=3) + uv_coords = uv_calculations(7) + expected_uv7 = np.array( + [ + [0.001, 0.858], + [0.001, 0.999], + [0.999, 0.999], + [0.999, 0.858], + [0.001, 0.858], + [0.001, 0.999], + [0.999, 0.999], + [0.999, 0.858], + [0.001, 0.715], + [0.001, 0.856], + [0.999, 0.856], + [0.999, 0.715], + [0.001, 0.715], + [0.001, 0.856], + [0.999, 0.856], + [0.999, 0.715], + [0.001, 0.572], + [0.001, 0.713], + [0.999, 0.713], + [0.999, 0.572], + [0.001, 0.572], + [0.001, 0.713], + [0.999, 0.713], + [0.999, 0.572], + [0.001, 0.429], + [0.001, 0.570], + [0.999, 0.570], + [0.999, 0.429], + [0.001, 0.429], + [0.001, 0.570], + [0.999, 0.570], + [0.999, 0.429], + [0.001, 0.286], + [0.001, 0.427], + [0.999, 0.427], + [0.999, 0.286], + [0.001, 0.286], + [0.001, 0.427], + [0.999, 0.427], + [0.999, 0.286], + [0.001, 0.143], + [0.001, 0.284], + [0.999, 0.284], + [0.999, 0.143], + [0.001, 0.143], + [0.001, 0.284], + [0.999, 0.284], + [0.999, 0.143], + [0.001, 0.001], + [0.001, 0.141], + [0.999, 0.141], + [0.999, 0.001], + [0.001, 0.001], + [0.001, 0.141], + [0.999, 0.141], + [0.999, 0.001], + ] + ) + npt.assert_array_almost_equal(uv_coords, expected_uv7, decimal=3)