diff --git a/.codespellrc b/.codespellrc index c48cd788c..31076209a 100644 --- a/.codespellrc +++ b/.codespellrc @@ -2,4 +2,4 @@ skip = .git,*.pdf,*.svg,*.bib,*.html # ue,lod,ans,lastr,numer,lamda,PrIs -- variable names # Hart,Flagg -- name -ignore-words-list = IST,nd,te,ue,lod,hart,ans,lastr,numer,lamda,flagg,pris,lod,IST,tese +ignore-words-list = IST,nd,te,ue,lod,hart,ans,lastr,numer,lamda,flagg,pris,lod,IST,tese,shs diff --git a/docs/experimental/sh-odf-impl/sh_odf_base.py b/docs/experimental/sh-odf-impl/sh_odf_base.py index e32c7c814..37d46d839 100644 --- a/docs/experimental/sh-odf-impl/sh_odf_base.py +++ b/docs/experimental/sh-odf-impl/sh_odf_base.py @@ -1,6 +1,7 @@ """ This script includes TEXTURE experimentation for passing SH coefficients """ + import os import numpy as np @@ -17,6 +18,7 @@ ) from fury.utils import numpy_to_vtk_image_data, set_polydata_tcoords + def uv_calculations(n): """Return UV coordinates based on the number of elements. @@ -49,6 +51,7 @@ def uv_calculations(n): ) return uvs + def minmax_norm(data, axis=1): """Returns the min-max normalization of data along an axis. @@ -81,6 +84,7 @@ def minmax_norm(data, axis=1): if axis == 1: return (data - minimum[:, None]) / (maximum - minimum)[:, None] + if __name__ == "__main__": show_man = window.ShowManager(size=(1920, 1080)) show_man.scene.background((1, 1, 1)) @@ -113,7 +117,7 @@ def minmax_norm(data, axis=1): # fmt: on centers = np.array([[0, -1, 0], [1, -1, 0], [2, -1, 0], [3, -1, 0]]) - scales = np.array([1.2, 2, 2, .3]) + scales = np.array([1.2, 2, 2, 0.3]) odf_actor = actor.box(centers=centers, scales=1.0) @@ -344,23 +348,6 @@ def minmax_norm(data, axis=1): } """ - 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) { @@ -388,6 +375,46 @@ def minmax_norm(data, axis=1): } """ + 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") + ) + """ + + # Applies the non-linearity that maps linear RGB to sRGB + 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") + ) + + # 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") + ) + + # Inverse of linear_rgb_to_srgb() + srgb_to_linear_rgb = import_fury_shader( + os.path.join("lighting", "srgb_to_linear_rgb.frag") + ) + + # Logarithmic tonemapping operator. Input and output are linear RGB. + tonemap = import_fury_shader(os.path.join("lighting", "tonemap.frag")) + blinn_phong_model = import_fury_shader( os.path.join("lighting", "blinn_phong_model.frag") ) @@ -395,8 +422,9 @@ def minmax_norm(data, axis=1): # fmt: off fs_dec = compose_shader([ 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 + norm_const, spherical_harmonics, sdf_map, cast_ray, + central_diffs_normals, linear_to_srgb, srgb_to_linear, + linear_rgb_to_srgb, srgb_to_linear_rgb, tonemap, blinn_phong_model ]) # fmt: on @@ -415,12 +443,15 @@ def minmax_norm(data, axis=1): vec3 t = castRay(ro, rd); + vec3 color = vec3(1.); + if(t.y > -.5) { - vec3 pos = ro + t.y * rd; + vec3 pos = ro- centerMCVSOutput + 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); @@ -431,11 +462,22 @@ def minmax_norm(data, axis=1): vec3 mater = .5 * mix(vec3(1, 1, 0), vec3(1), t.y); fragOutput0 = vec4(vec3(1, 0, 0) * lin, opacity); + */ + vec3 colorDir = srgbToLinearRgb(abs(normalize(pos))); + float attenuation = dot(ld, normal); + color = blinnPhongIllumModel( + //attenuation, lightColor0, diffuseColor, specularPower, + attenuation, lightColor0, colorDir, specularPower, + specularColor, ambientColor); } else { discard; } + + //fragOutput0 = vec4(linearToSrgb(color * colorDir), opacity); + vec3 outColor = linearRgbToSrgb(tonemap(color)); + fragOutput0 = vec4(outColor, opacity); """ shader_to_actor( @@ -447,7 +489,7 @@ def minmax_norm(data, axis=1): sphere = get_sphere("repulsion724") sh_basis = "descoteaux07" - #sh_basis = "tournier07" + # sh_basis = "tournier07" sh_order = 4 sh = np.zeros((4, 1, 1, 15)) @@ -457,7 +499,11 @@ def minmax_norm(data, axis=1): sh[3, 0, 0, :] = coeffs[3, :] tensor_sf = sh_to_sf( - sh, sh_order_max=sh_order, basis_type=sh_basis, sphere=sphere, legacy=True + sh, + sh_order_max=sh_order, + basis_type=sh_basis, + sphere=sphere, + legacy=True, ) odf_slicer_actor = actor.odf_slicer( diff --git a/fury/actor.py b/fury/actor.py index 3d552ae3a..5ad8b9207 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 ( @@ -4019,3 +4020,67 @@ 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, 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. + sh_basis: str, optional + Type of basis (descoteaux, tournier) + 'descoteaux' for the default ``descoteaux07`` DIPY basis. + 'tournier' for the default ``tournier07`` DIPY basis. + scales : float or ndarray (N, ), optional + ODFs size. + opacity : float, optional + 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] + 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: + 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, sh_basis, scales, opacity) diff --git a/fury/actors/odf.py b/fury/actors/odf.py new file mode 100644 index 000000000..0699d0165 --- /dev/null +++ b/fury/actors/odf.py @@ -0,0 +1,385 @@ +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.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): + """ + Visualize one or many ODFs with different features. + + Parameters + ---------- + centers : ndarray(N, 3) + ODFs positions. + coeffs : ndarray + 2D ODFs array in SH coefficients. + sh_basis: str, optional + Type of basis (descoteaux, tournier) + 'descoteaux' for the default ``descoteaux07`` DIPY basis. + 'tournier' for the default ``tournier07`` DIPY 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 + 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") + + 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 + # 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) + + 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( + "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; + out vec3 camPosMCVSOutput; + out vec3 camRightMCVSOutput; + out vec3 camUpMCVSOutput; + """ + + vs_impl = """ + numCoeffsVSOutput = (shDegree + 1) * (shDegree + 2) / 2; + maxPolyDegreeVSOutput = 2 * shDegree + 2; + 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 = f"#define SH_DEGREE {max_sh_degree}" + + # The number of spherical harmonics basis functions + def_sh_count = f"#define SH_COUNT {max_num_coeffs}" + + # Degree of polynomials for which we have to find roots + 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 + # 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 = """ + flat in float numCoeffsVSOutput; + flat in float maxPolyDegreeVSOutput; + 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_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") + ) + eval_sh_grad = import_fury_shader( + os.path.join( + "ray_tracing", "odf", 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. + # 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("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("utils", "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 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. + 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("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("ray_tracing", "odf", "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("ray_tracing", "odf", "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("ray_tracing", "odf", "get_sh_glyph_normal.frag") + ) + + # Applies the non-linearity that maps linear RGB to sRGB + 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")) + + # 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") + ) + + # Inverse of linear_rgb_to_srgb() + srgb_to_linear_rgb = import_fury_shader( + os.path.join("lighting", "srgb_to_linear_rgb.frag") + ) + + # Logarithmic tonemapping operator. Input and output are linear RGB. + tonemap = import_fury_shader(os.path.join("lighting", "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_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 + ]) + # 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;" + + # 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 / (numCoeffsVSOutput * 2); + float shCoeffs[SH_COUNT]; + for(int j=0; j < numCoeffsVSOutput; j++){ + shCoeffs[j] = rescale( + texture( + texture0, + vec2(i + j / numCoeffsVSOutput, tcoordVCVSOutput.y)).x, + 0, 1, minmaxVSOutput.x, minmaxVSOutput.y + ); + } + """ + + # Perform the intersection test + intersection_test = """ + float rayParams[MAX_DEGREE]; + rayGlyphIntersections( + rayParams, shCoeffs, ro - centerMCVSOutput, rd, int(shDegree), + int(numCoeffsVSOutput), int(maxPolyDegreeVSOutput), M_PI, + NO_INTERSECTION + ); + """ + + # Identify the first intersection + first_intersection = """ + float firstRayParam = NO_INTERSECTION; + _unroll_ + for (int i = 0; i != maxPolyDegreeVSOutput; ++i) { + if (rayParams[i] != NO_INTERSECTION && rayParams[i] > 0.0) { + firstRayParam = rayParams[i]; + break; + } + } + """ + + # Evaluate shading for a directional light + directional_light = """ + vec3 color = vec3(1.); + 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 = dot(ld, normal); + color = blinnPhongIllumModel( + attenuation, lightColor0, colorDir, specularPower, + specularColor, ambientColor); + } else { + discard; + } + """ + + 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, + ] + ) + + shader_to_actor(odf_actor, "fragment", impl_code=fs_impl, block="picking") + + return odf_actor diff --git a/fury/shaders/lighting/linear_rgb_to_srgb.frag b/fury/shaders/lighting/linear_rgb_to_srgb.frag new file mode 100644 index 000000000..901aad0d2 --- /dev/null +++ b/fury/shaders/lighting/linear_rgb_to_srgb.frag @@ -0,0 +1,4 @@ +vec3 linearRgbToSrgb(vec3 linear) +{ + 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 new file mode 100644 index 000000000..7a3773c01 --- /dev/null +++ b/fury/shaders/lighting/linear_to_srgb.frag @@ -0,0 +1,4 @@ +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 new file mode 100644 index 000000000..5240d4b9d --- /dev/null +++ b/fury/shaders/lighting/srgb_to_linear.frag @@ -0,0 +1,4 @@ +float srgbToLinear(float nonLinear) +{ + 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 new file mode 100644 index 000000000..0c47f780b --- /dev/null +++ b/fury/shaders/lighting/srgb_to_linear_rgb.frag @@ -0,0 +1,4 @@ +vec3 srgbToLinearRgb(vec3 srgb) +{ + return vec3(srgbToLinear(srgb.r), srgbToLinear(srgb.g), srgbToLinear(srgb.b)); +} 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/ray_tracing/odf/descoteaux/eval_sh_10.frag b/fury/shaders/ray_tracing/odf/descoteaux/eval_sh_10.frag new file mode 100644 index 000000000..f12ad5881 --- /dev/null +++ b/fury/shaders/ray_tracing/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_tracing/odf/descoteaux/eval_sh_12.frag b/fury/shaders/ray_tracing/odf/descoteaux/eval_sh_12.frag new file mode 100644 index 000000000..93a0da982 --- /dev/null +++ b/fury/shaders/ray_tracing/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_tracing/odf/descoteaux/eval_sh_2.frag b/fury/shaders/ray_tracing/odf/descoteaux/eval_sh_2.frag new file mode 100644 index 000000000..77c9b62bb --- /dev/null +++ b/fury/shaders/ray_tracing/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_tracing/odf/descoteaux/eval_sh_4.frag b/fury/shaders/ray_tracing/odf/descoteaux/eval_sh_4.frag new file mode 100644 index 000000000..2c1b927c3 --- /dev/null +++ b/fury/shaders/ray_tracing/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_tracing/odf/descoteaux/eval_sh_6.frag b/fury/shaders/ray_tracing/odf/descoteaux/eval_sh_6.frag new file mode 100644 index 000000000..e080626a2 --- /dev/null +++ b/fury/shaders/ray_tracing/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_tracing/odf/descoteaux/eval_sh_8.frag b/fury/shaders/ray_tracing/odf/descoteaux/eval_sh_8.frag new file mode 100644 index 000000000..a88190d35 --- /dev/null +++ b/fury/shaders/ray_tracing/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_tracing/odf/descoteaux/eval_sh_grad_10.frag b/fury/shaders/ray_tracing/odf/descoteaux/eval_sh_grad_10.frag new file mode 100644 index 000000000..bed7ce26f --- /dev/null +++ b/fury/shaders/ray_tracing/odf/descoteaux/eval_sh_grad_10.frag @@ -0,0 +1,430 @@ +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]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + 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; + outGrads[2][0] = -c0 * d; + outGrads[4][0] = s0 * d; + outGrads[2][1] = s0 * d; + outGrads[4][1] = c0 * d; + d = 1.892349392 * z; + outGrads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + 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; + outGrads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + 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; + outGrads[21][2] = d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + 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; + outGrads[36][2] = d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + 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; + outGrads[55][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + outSH[1] = c0 * d; + outSH[5] = s0 * d; + d = 1.092548431; + outGrads[1][0] = c1 * d; + outGrads[5][0] = s1 * d; + outGrads[1][1] = -s1 * d; + outGrads[5][1] = c1 * d; + d = -1.092548431; + outGrads[2][2] = -c1 * d; + outGrads[4][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + outSH[8] = c0 * d; + outSH[12] = s0 * d; + d = 6.62322287 * a; + outGrads[8][0] = c1 * d; + outGrads[12][0] = s1 * d; + outGrads[8][1] = -s1 * d; + outGrads[12][1] = c1 * d; + d = -14.049977415 * a; + outGrads[9][2] = -c1 * d; + outGrads[11][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + outSH[19] = c0 * d; + outSH[23] = s0 * d; + d = 30.399773564 * a; + outGrads[19][0] = c1 * d; + outGrads[23][0] = s1 * d; + outGrads[19][1] = -s1 * d; + outGrads[23][1] = c1 * d; + d = -96.132524816 * a; + 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; + outSH[34] = c0 * d; + outSH[38] = s0 * d; + d = 130.459545912 * a; + outGrads[34][0] = c1 * d; + outGrads[38][0] = s1 * d; + outGrads[34][1] = -s1 * d; + outGrads[38][1] = c1 * d; + d = -545.751435723 * a; + 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; + outSH[53] = c0 * d; + outSH[57] = s0 * d; + d = 544.731628762 * a; + outGrads[53][0] = c1 * d; + outGrads[57][0] = s1 * d; + outGrads[53][1] = -s1 * d; + outGrads[57][1] = c1 * d; + d = -2830.508572514 * a; + outGrads[54][2] = -c1 * d; + outGrads[56][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + outSH[7] = -c1 * d; + outSH[13] = s1 * d; + d = -5.310392309 * z; + outGrads[7][0] = -c0 * d; + outGrads[13][0] = s0 * d; + outGrads[7][1] = s0 * d; + outGrads[13][1] = c0 * d; + d = 6.62322287 * z; + outGrads[8][2] = c0 * d; + outGrads[12][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + outSH[18] = -c1 * d; + outSH[24] = s1 * d; + d = -30.399773564 * b; + outGrads[18][0] = -c0 * d; + outGrads[24][0] = s0 * d; + outGrads[18][1] = s0 * d; + outGrads[24][1] = c0 * d; + d = 60.799547128 * b; + 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; + outSH[33] = -c1 * d; + outSH[39] = s1 * d; + d = -144.52614017 * b; + outGrads[33][0] = -c0 * d; + outGrads[39][0] = s0 * d; + outGrads[33][1] = s0 * d; + outGrads[39][1] = c0 * d; + d = 391.378637737 * b; + 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; + outSH[52] = -c1 * d; + outSH[58] = s1 * d; + d = -640.983970322 * b; + outGrads[52][0] = -c0 * d; + outGrads[58][0] = s0 * d; + outGrads[52][1] = s0 * d; + outGrads[58][1] = c0 * d; + d = 2178.926515046 * b; + outGrads[53][2] = c0 * d; + outGrads[57][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + outSH[6] = c0 * d; + outSH[14] = s0 * d; + d = 2.503342942; + outGrads[6][0] = c1 * d; + outGrads[14][0] = s1 * d; + outGrads[6][1] = -s1 * d; + outGrads[14][1] = c1 * d; + d = -1.77013077; + outGrads[7][2] = -c1 * d; + outGrads[13][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + outSH[17] = c0 * d; + outSH[25] = s0 * d; + d = 22.200855632 * a; + outGrads[17][0] = c1 * d; + outGrads[25][0] = s1 * d; + outGrads[17][1] = -s1 * d; + outGrads[25][1] = c1 * d; + d = -30.399773564 * a; + outGrads[18][2] = -c1 * d; + outGrads[24][2] = s1 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + outSH[32] = c0 * d; + outSH[40] = s0 * d; + d = 124.388296437 * a; + outGrads[32][0] = c1 * d; + outGrads[40][0] = s1 * d; + outGrads[32][1] = -s1 * d; + outGrads[40][1] = c1 * d; + d = -240.876900283 * a; + 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; + outSH[51] = c0 * d; + outSH[59] = s0 * d; + d = 604.325482728 * a; + outGrads[51][0] = c1 * d; + outGrads[59][0] = s1 * d; + outGrads[51][1] = -s1 * d; + outGrads[59][1] = c1 * d; + d = -1495.629264084 * a; + outGrads[52][2] = -c1 * d; + outGrads[58][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + outSH[16] = -c1 * d; + outSH[26] = s1 * d; + d = -11.833095811 * z; + outGrads[16][0] = -c0 * d; + outGrads[26][0] = s0 * d; + outGrads[16][1] = s0 * d; + outGrads[26][1] = c0 * d; + d = 11.100427816 * z; + 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; + outSH[31] = -c1 * d; + outSH[41] = s1 * d; + d = -86.247765552 * b; + outGrads[31][0] = -c0 * d; + outGrads[41][0] = s0 * d; + outGrads[31][1] = s0 * d; + outGrads[41][1] = c0 * d; + d = 124.388296437 * b; + 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; + outSH[50] = -c1 * d; + outSH[60] = s1 * d; + d = -477.761243376 * b; + outGrads[50][0] = -c0 * d; + outGrads[60][0] = s0 * d; + outGrads[50][1] = s0 * d; + outGrads[60][1] = c0 * d; + d = 906.488224092 * b; + outGrads[51][2] = c0 * d; + outGrads[59][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + outSH[15] = c0 * d; + outSH[27] = s0 * d; + d = 4.099104631; + outGrads[15][0] = c1 * d; + outGrads[27][0] = s1 * d; + outGrads[15][1] = -s1 * d; + outGrads[27][1] = c1 * d; + d = -2.366619162; + outGrads[16][2] = -c1 * d; + outGrads[26][2] = s1 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + outSH[30] = c0 * d; + outSH[42] = s0 * d; + d = 47.909948945 * a; + outGrads[30][0] = c1 * d; + outGrads[42][0] = s1 * d; + outGrads[30][1] = -s1 * d; + outGrads[42][1] = c1 * d; + d = -51.748659331 * a; + outGrads[31][2] = -c1 * d; + outGrads[41][2] = s1 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + outSH[49] = c0 * d; + outSH[61] = s0 * d; + d = 320.491985161 * a; + outGrads[49][0] = c1 * d; + outGrads[61][0] = s1 * d; + outGrads[49][1] = -s1 * d; + outGrads[61][1] = c1 * d; + d = -477.761243376 * a; + outGrads[50][2] = -c1 * d; + outGrads[60][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + outSH[29] = -c1 * d; + outSH[43] = s1 * d; + d = -20.409946485 * z; + outGrads[29][0] = -c0 * d; + outGrads[43][0] = s0 * d; + outGrads[29][1] = s0 * d; + outGrads[43][1] = c0 * d; + d = 15.969982982 * z; + 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; + outSH[48] = -c1 * d; + outSH[62] = s1 * d; + d = -181.371689194 * b; + outGrads[48][0] = -c0 * d; + outGrads[62][0] = s0 * d; + outGrads[48][1] = s0 * d; + outGrads[62][1] = c0 * d; + d = 213.661323441 * b; + outGrads[49][2] = c0 * d; + outGrads[61][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + outSH[28] = c0 * d; + outSH[44] = s0 * d; + d = 5.831413281; + outGrads[28][0] = c1 * d; + outGrads[44][0] = s1 * d; + outGrads[28][1] = -s1 * d; + outGrads[44][1] = c1 * d; + d = -2.915706641; + outGrads[29][2] = -c1 * d; + outGrads[43][2] = s1 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + outSH[47] = c0 * d; + outSH[63] = s0 * d; + d = 84.622493774 * a; + outGrads[47][0] = c1 * d; + outGrads[63][0] = s1 * d; + outGrads[47][1] = -s1 * d; + outGrads[63][1] = c1 * d; + d = -77.73072394 * a; + outGrads[48][2] = -c1 * d; + outGrads[62][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + outSH[46] = -c1 * d; + outSH[64] = s1 * d; + d = -30.887057699 * z; + outGrads[46][0] = -c0 * d; + outGrads[64][0] = s0 * d; + outGrads[46][1] = s0 * d; + outGrads[64][1] = c0 * d; + d = 21.155623443 * z; + outGrads[47][2] = c0 * d; + outGrads[63][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + outSH[45] = c0 * d; + outSH[65] = s0 * d; + d = 7.673951182; + outGrads[45][0] = c1 * d; + outGrads[65][0] = s1 * d; + outGrads[45][1] = -s1 * d; + outGrads[65][1] = c1 * d; + d = -3.4318953; + 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/ray_tracing/odf/descoteaux/eval_sh_grad_12.frag b/fury/shaders/ray_tracing/odf/descoteaux/eval_sh_grad_12.frag new file mode 100644 index 000000000..7b391a77c --- /dev/null +++ b/fury/shaders/ray_tracing/odf/descoteaux/eval_sh_grad_12.frag @@ -0,0 +1,591 @@ +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]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + 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; + outGrads[2][0] = -c0 * d; + outGrads[4][0] = s0 * d; + outGrads[2][1] = s0 * d; + outGrads[4][1] = c0 * d; + d = 1.892349392 * z; + outGrads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + 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; + outGrads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + 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; + outGrads[21][2] = d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + 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; + outGrads[36][2] = d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + 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; + outGrads[55][2] = d; + a = z2 * b - 0.248120301 * a; + b = a - 0.248447205 * b; + d = -1265.233874957 * b; + 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; + outGrads[78][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + outSH[1] = c0 * d; + outSH[5] = s0 * d; + d = 1.092548431; + outGrads[1][0] = c1 * d; + outGrads[5][0] = s1 * d; + outGrads[1][1] = -s1 * d; + outGrads[5][1] = c1 * d; + d = -1.092548431; + outGrads[2][2] = -c1 * d; + outGrads[4][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + outSH[8] = c0 * d; + outSH[12] = s0 * d; + d = 6.62322287 * a; + outGrads[8][0] = c1 * d; + outGrads[12][0] = s1 * d; + outGrads[8][1] = -s1 * d; + outGrads[12][1] = c1 * d; + d = -14.049977415 * a; + outGrads[9][2] = -c1 * d; + outGrads[11][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + outSH[19] = c0 * d; + outSH[23] = s0 * d; + d = 30.399773564 * a; + outGrads[19][0] = c1 * d; + outGrads[23][0] = s1 * d; + outGrads[19][1] = -s1 * d; + outGrads[23][1] = c1 * d; + d = -96.132524816 * a; + 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; + outSH[34] = c0 * d; + outSH[38] = s0 * d; + d = 130.459545912 * a; + outGrads[34][0] = c1 * d; + outGrads[38][0] = s1 * d; + outGrads[34][1] = -s1 * d; + outGrads[38][1] = c1 * d; + d = -545.751435723 * a; + 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; + outSH[53] = c0 * d; + outSH[57] = s0 * d; + d = 544.731628762 * a; + outGrads[53][0] = c1 * d; + outGrads[57][0] = s1 * d; + outGrads[53][1] = -s1 * d; + outGrads[57][1] = c1 * d; + d = -2830.508572514 * a; + 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; + outSH[76] = c0 * d; + outSH[80] = s0 * d; + d = 2243.019924866 * a; + outGrads[76][0] = c1 * d; + outGrads[80][0] = s1 * d; + outGrads[76][1] = -s1 * d; + outGrads[80][1] = c1 * d; + d = -13917.572624524 * a; + outGrads[77][2] = -c1 * d; + outGrads[79][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + outSH[7] = -c1 * d; + outSH[13] = s1 * d; + d = -5.310392309 * z; + outGrads[7][0] = -c0 * d; + outGrads[13][0] = s0 * d; + outGrads[7][1] = s0 * d; + outGrads[13][1] = c0 * d; + d = 6.62322287 * z; + outGrads[8][2] = c0 * d; + outGrads[12][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + outSH[18] = -c1 * d; + outSH[24] = s1 * d; + d = -30.399773564 * b; + outGrads[18][0] = -c0 * d; + outGrads[24][0] = s0 * d; + outGrads[18][1] = s0 * d; + outGrads[24][1] = c0 * d; + d = 60.799547128 * b; + 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; + outSH[33] = -c1 * d; + outSH[39] = s1 * d; + d = -144.52614017 * b; + outGrads[33][0] = -c0 * d; + outGrads[39][0] = s0 * d; + outGrads[33][1] = s0 * d; + outGrads[39][1] = c0 * d; + d = 391.378637737 * b; + 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; + outSH[52] = -c1 * d; + outSH[58] = s1 * d; + d = -640.983970322 * b; + outGrads[52][0] = -c0 * d; + outGrads[58][0] = s0 * d; + outGrads[52][1] = s0 * d; + outGrads[58][1] = c0 * d; + d = 2178.926515046 * b; + 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; + outSH[75] = -c1 * d; + outSH[81] = s1 * d; + d = -2747.127149409 * b; + outGrads[75][0] = -c0 * d; + outGrads[81][0] = s0 * d; + outGrads[75][1] = s0 * d; + outGrads[81][1] = c0 * d; + d = 11215.099624332 * b; + outGrads[76][2] = c0 * d; + outGrads[80][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + outSH[6] = c0 * d; + outSH[14] = s0 * d; + d = 2.503342942; + outGrads[6][0] = c1 * d; + outGrads[14][0] = s1 * d; + outGrads[6][1] = -s1 * d; + outGrads[14][1] = c1 * d; + d = -1.77013077; + outGrads[7][2] = -c1 * d; + outGrads[13][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + outSH[17] = c0 * d; + outSH[25] = s0 * d; + d = 22.200855632 * a; + outGrads[17][0] = c1 * d; + outGrads[25][0] = s1 * d; + outGrads[17][1] = -s1 * d; + outGrads[25][1] = c1 * d; + d = -30.399773564 * a; + outGrads[18][2] = -c1 * d; + outGrads[24][2] = s1 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + outSH[32] = c0 * d; + outSH[40] = s0 * d; + d = 124.388296437 * a; + outGrads[32][0] = c1 * d; + outGrads[40][0] = s1 * d; + outGrads[32][1] = -s1 * d; + outGrads[40][1] = c1 * d; + d = -240.876900283 * a; + 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; + outSH[51] = c0 * d; + outSH[59] = s0 * d; + d = 604.325482728 * a; + outGrads[51][0] = c1 * d; + outGrads[59][0] = s1 * d; + outGrads[51][1] = -s1 * d; + outGrads[59][1] = c1 * d; + d = -1495.629264084 * a; + 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; + outSH[74] = c0 * d; + outSH[82] = s0 * d; + d = 2747.127149409 * a; + outGrads[74][0] = c1 * d; + outGrads[82][0] = s1 * d; + outGrads[74][1] = -s1 * d; + outGrads[82][1] = c1 * d; + d = -8241.381448228 * a; + outGrads[75][2] = -c1 * d; + outGrads[81][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + outSH[16] = -c1 * d; + outSH[26] = s1 * d; + d = -11.833095811 * z; + outGrads[16][0] = -c0 * d; + outGrads[26][0] = s0 * d; + outGrads[16][1] = s0 * d; + outGrads[26][1] = c0 * d; + d = 11.100427816 * z; + 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; + outSH[31] = -c1 * d; + outSH[41] = s1 * d; + d = -86.247765552 * b; + outGrads[31][0] = -c0 * d; + outGrads[41][0] = s0 * d; + outGrads[31][1] = s0 * d; + outGrads[41][1] = c0 * d; + d = 124.388296437 * b; + 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; + outSH[50] = -c1 * d; + outSH[60] = s1 * d; + d = -477.761243376 * b; + outGrads[50][0] = -c0 * d; + outGrads[60][0] = s0 * d; + outGrads[50][1] = s0 * d; + outGrads[60][1] = c0 * d; + d = 906.488224092 * b; + 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; + outSH[73] = -c1 * d; + outSH[83] = s1 * d; + d = -2355.642096651 * b; + outGrads[73][0] = -c0 * d; + outGrads[83][0] = s0 * d; + outGrads[73][1] = s0 * d; + outGrads[83][1] = c0 * d; + d = 5494.254298819 * b; + outGrads[74][2] = c0 * d; + outGrads[82][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + outSH[15] = c0 * d; + outSH[27] = s0 * d; + d = 4.099104631; + outGrads[15][0] = c1 * d; + outGrads[27][0] = s1 * d; + outGrads[15][1] = -s1 * d; + outGrads[27][1] = c1 * d; + d = -2.366619162; + outGrads[16][2] = -c1 * d; + outGrads[26][2] = s1 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + outSH[30] = c0 * d; + outSH[42] = s0 * d; + d = 47.909948945 * a; + outGrads[30][0] = c1 * d; + outGrads[42][0] = s1 * d; + outGrads[30][1] = -s1 * d; + outGrads[42][1] = c1 * d; + d = -51.748659331 * a; + outGrads[31][2] = -c1 * d; + outGrads[41][2] = s1 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + outSH[49] = c0 * d; + outSH[61] = s0 * d; + d = 320.491985161 * a; + outGrads[49][0] = c1 * d; + outGrads[61][0] = s1 * d; + outGrads[49][1] = -s1 * d; + outGrads[61][1] = c1 * d; + d = -477.761243376 * a; + 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; + outSH[72] = c0 * d; + outSH[84] = s0 * d; + d = 1762.801130306 * a; + outGrads[72][0] = c1 * d; + outGrads[84][0] = s1 * d; + outGrads[72][1] = -s1 * d; + outGrads[84][1] = c1 * d; + d = -3297.898935312 * a; + outGrads[73][2] = -c1 * d; + outGrads[83][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + outSH[29] = -c1 * d; + outSH[43] = s1 * d; + d = -20.409946485 * z; + outGrads[29][0] = -c0 * d; + outGrads[43][0] = s0 * d; + outGrads[29][1] = s0 * d; + outGrads[43][1] = c0 * d; + d = 15.969982982 * z; + 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; + outSH[48] = -c1 * d; + outSH[62] = s1 * d; + d = -181.371689194 * b; + outGrads[48][0] = -c0 * d; + outGrads[62][0] = s0 * d; + outGrads[48][1] = s0 * d; + outGrads[62][1] = c0 * d; + d = 213.661323441 * b; + 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; + outSH[71] = -c1 * d; + outSH[85] = s1 * d; + d = -1155.7101691 * b; + outGrads[71][0] = -c0 * d; + outGrads[85][0] = s0 * d; + outGrads[71][1] = s0 * d; + outGrads[85][1] = c0 * d; + d = 1762.801130306 * b; + outGrads[72][2] = c0 * d; + outGrads[84][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + outSH[28] = c0 * d; + outSH[44] = s0 * d; + d = 5.831413281; + outGrads[28][0] = c1 * d; + outGrads[44][0] = s1 * d; + outGrads[28][1] = -s1 * d; + outGrads[44][1] = c1 * d; + d = -2.915706641; + outGrads[29][2] = -c1 * d; + outGrads[43][2] = s1 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + outSH[47] = c0 * d; + outSH[63] = s0 * d; + d = 84.622493774 * a; + outGrads[47][0] = c1 * d; + outGrads[63][0] = s1 * d; + outGrads[47][1] = -s1 * d; + outGrads[63][1] = c1 * d; + d = -77.73072394 * a; + 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; + outSH[70] = c0 * d; + outSH[86] = s0 * d; + d = 660.405810914 * a; + outGrads[70][0] = c1 * d; + outGrads[86][0] = s1 * d; + outGrads[70][1] = -s1 * d; + outGrads[86][1] = c1 * d; + d = -825.507263643 * a; + outGrads[71][2] = -c1 * d; + outGrads[85][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + outSH[46] = -c1 * d; + outSH[64] = s1 * d; + d = -30.887057699 * z; + outGrads[46][0] = -c0 * d; + outGrads[64][0] = s0 * d; + outGrads[46][1] = s0 * d; + outGrads[64][1] = c0 * d; + d = 21.155623443 * z; + 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; + outSH[69] = -c1 * d; + outSH[87] = s1 * d; + d = -324.252816204 * b; + outGrads[69][0] = -c0 * d; + outGrads[87][0] = s0 * d; + outGrads[69][1] = s0 * d; + outGrads[87][1] = c0 * d; + d = 330.202905457 * b; + outGrads[70][2] = c0 * d; + outGrads[86][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + outSH[45] = c0 * d; + outSH[65] = s0 * d; + d = 7.673951182; + outGrads[45][0] = c1 * d; + outGrads[65][0] = s1 * d; + outGrads[45][1] = -s1 * d; + outGrads[65][1] = c1 * d; + d = -3.4318953; + outGrads[46][2] = -c1 * d; + outGrads[64][2] = s1 * d; + a = z2 - 4.34782609e-02; + d = 13.3042542 * a; + outSH[68] = c0 * d; + outSH[88] = s0 * d; + d = 133.042542003 * a; + outGrads[68][0] = c1 * d; + outGrads[88][0] = s1 * d; + outGrads[68][1] = -s1 * d; + outGrads[88][1] = c1 * d; + d = -108.084272068 * a; + outGrads[69][2] = -c1 * d; + outGrads[87][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.923210529 * z; + outSH[67] = -c1 * d; + outSH[89] = s1 * d; + d = -43.155315818 * z; + outGrads[67][0] = -c0 * d; + outGrads[89][0] = s0 * d; + outGrads[67][1] = s0 * d; + outGrads[89][1] = c0 * d; + d = 26.608508401 * z; + outGrads[68][2] = c0 * d; + outGrads[88][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.800821996; + outSH[66] = c0 * d; + outSH[90] = s0 * d; + d = 9.609863949; + outGrads[66][0] = c1 * d; + outGrads[90][0] = s1 * d; + outGrads[66][1] = -s1 * d; + outGrads[90][1] = c1 * d; + d = -3.923210529; + 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/ray_tracing/odf/descoteaux/eval_sh_grad_2.frag b/fury/shaders/ray_tracing/odf/descoteaux/eval_sh_grad_2.frag new file mode 100644 index 000000000..315b5ae0f --- /dev/null +++ b/fury/shaders/ray_tracing/odf/descoteaux/eval_sh_grad_2.frag @@ -0,0 +1,46 @@ +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]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + 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; + outGrads[2][0] = -c0 * d; + outGrads[4][0] = s0 * d; + outGrads[2][1] = s0 * d; + outGrads[4][1] = c0 * d; + d = 1.892349392 * z; + outGrads[3][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + outSH[1] = c0 * d; + outSH[5] = s0 * d; + d = 1.092548431; + outGrads[1][0] = c1 * d; + outGrads[5][0] = s1 * d; + outGrads[1][1] = -s1 * d; + outGrads[5][1] = c1 * d; + d = -1.092548431; + 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/ray_tracing/odf/descoteaux/eval_sh_grad_4.frag b/fury/shaders/ray_tracing/odf/descoteaux/eval_sh_grad_4.frag new file mode 100644 index 000000000..30b16e7a4 --- /dev/null +++ b/fury/shaders/ray_tracing/odf/descoteaux/eval_sh_grad_4.frag @@ -0,0 +1,103 @@ +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]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + 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; + outGrads[2][0] = -c0 * d; + outGrads[4][0] = s0 * d; + outGrads[2][1] = s0 * d; + outGrads[4][1] = c0 * d; + d = 1.892349392 * z; + outGrads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + 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; + outGrads[10][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + outSH[1] = c0 * d; + outSH[5] = s0 * d; + d = 1.092548431; + outGrads[1][0] = c1 * d; + outGrads[5][0] = s1 * d; + outGrads[1][1] = -s1 * d; + outGrads[5][1] = c1 * d; + d = -1.092548431; + outGrads[2][2] = -c1 * d; + outGrads[4][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + outSH[8] = c0 * d; + outSH[12] = s0 * d; + d = 6.62322287 * a; + outGrads[8][0] = c1 * d; + outGrads[12][0] = s1 * d; + outGrads[8][1] = -s1 * d; + outGrads[12][1] = c1 * d; + d = -14.049977415 * a; + outGrads[9][2] = -c1 * d; + outGrads[11][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + outSH[7] = -c1 * d; + outSH[13] = s1 * d; + d = -5.310392309 * z; + outGrads[7][0] = -c0 * d; + outGrads[13][0] = s0 * d; + outGrads[7][1] = s0 * d; + outGrads[13][1] = c0 * d; + d = 6.62322287 * z; + outGrads[8][2] = c0 * d; + outGrads[12][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + outSH[6] = c0 * d; + outSH[14] = s0 * d; + d = 2.503342942; + outGrads[6][0] = c1 * d; + outGrads[14][0] = s1 * d; + outGrads[6][1] = -s1 * d; + outGrads[14][1] = c1 * d; + d = -1.77013077; + 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/ray_tracing/odf/descoteaux/eval_sh_grad_6.frag b/fury/shaders/ray_tracing/odf/descoteaux/eval_sh_grad_6.frag new file mode 100644 index 000000000..95970b168 --- /dev/null +++ b/fury/shaders/ray_tracing/odf/descoteaux/eval_sh_grad_6.frag @@ -0,0 +1,186 @@ +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]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + 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; + outGrads[2][0] = -c0 * d; + outGrads[4][0] = s0 * d; + outGrads[2][1] = s0 * d; + outGrads[4][1] = c0 * d; + d = 1.892349392 * z; + outGrads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + 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; + outGrads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + 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; + outGrads[21][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + outSH[1] = c0 * d; + outSH[5] = s0 * d; + d = 1.092548431; + outGrads[1][0] = c1 * d; + outGrads[5][0] = s1 * d; + outGrads[1][1] = -s1 * d; + outGrads[5][1] = c1 * d; + d = -1.092548431; + outGrads[2][2] = -c1 * d; + outGrads[4][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + outSH[8] = c0 * d; + outSH[12] = s0 * d; + d = 6.62322287 * a; + outGrads[8][0] = c1 * d; + outGrads[12][0] = s1 * d; + outGrads[8][1] = -s1 * d; + outGrads[12][1] = c1 * d; + d = -14.049977415 * a; + outGrads[9][2] = -c1 * d; + outGrads[11][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + outSH[19] = c0 * d; + outSH[23] = s0 * d; + d = 30.399773564 * a; + outGrads[19][0] = c1 * d; + outGrads[23][0] = s1 * d; + outGrads[19][1] = -s1 * d; + outGrads[23][1] = c1 * d; + d = -96.132524816 * a; + outGrads[20][2] = -c1 * d; + outGrads[22][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + outSH[7] = -c1 * d; + outSH[13] = s1 * d; + d = -5.310392309 * z; + outGrads[7][0] = -c0 * d; + outGrads[13][0] = s0 * d; + outGrads[7][1] = s0 * d; + outGrads[13][1] = c0 * d; + d = 6.62322287 * z; + outGrads[8][2] = c0 * d; + outGrads[12][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + outSH[18] = -c1 * d; + outSH[24] = s1 * d; + d = -30.399773564 * b; + outGrads[18][0] = -c0 * d; + outGrads[24][0] = s0 * d; + outGrads[18][1] = s0 * d; + outGrads[24][1] = c0 * d; + d = 60.799547128 * b; + outGrads[19][2] = c0 * d; + outGrads[23][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + outSH[6] = c0 * d; + outSH[14] = s0 * d; + d = 2.503342942; + outGrads[6][0] = c1 * d; + outGrads[14][0] = s1 * d; + outGrads[6][1] = -s1 * d; + outGrads[14][1] = c1 * d; + d = -1.77013077; + outGrads[7][2] = -c1 * d; + outGrads[13][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + outSH[17] = c0 * d; + outSH[25] = s0 * d; + d = 22.200855632 * a; + outGrads[17][0] = c1 * d; + outGrads[25][0] = s1 * d; + outGrads[17][1] = -s1 * d; + outGrads[25][1] = c1 * d; + d = -30.399773564 * a; + outGrads[18][2] = -c1 * d; + outGrads[24][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + outSH[16] = -c1 * d; + outSH[26] = s1 * d; + d = -11.833095811 * z; + outGrads[16][0] = -c0 * d; + outGrads[26][0] = s0 * d; + outGrads[16][1] = s0 * d; + outGrads[26][1] = c0 * d; + d = 11.100427816 * z; + outGrads[17][2] = c0 * d; + outGrads[25][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + outSH[15] = c0 * d; + outSH[27] = s0 * d; + d = 4.099104631; + outGrads[15][0] = c1 * d; + outGrads[27][0] = s1 * d; + outGrads[15][1] = -s1 * d; + outGrads[27][1] = c1 * d; + d = -2.366619162; + 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/ray_tracing/odf/descoteaux/eval_sh_grad_8.frag b/fury/shaders/ray_tracing/odf/descoteaux/eval_sh_grad_8.frag new file mode 100644 index 000000000..9e788bd24 --- /dev/null +++ b/fury/shaders/ray_tracing/odf/descoteaux/eval_sh_grad_8.frag @@ -0,0 +1,295 @@ +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]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + 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; + outGrads[2][0] = -c0 * d; + outGrads[4][0] = s0 * d; + outGrads[2][1] = s0 * d; + outGrads[4][1] = c0 * d; + d = 1.892349392 * z; + outGrads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + 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; + outGrads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + 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; + outGrads[21][2] = d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + 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; + outGrads[36][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + outSH[1] = c0 * d; + outSH[5] = s0 * d; + d = 1.092548431; + outGrads[1][0] = c1 * d; + outGrads[5][0] = s1 * d; + outGrads[1][1] = -s1 * d; + outGrads[5][1] = c1 * d; + d = -1.092548431; + outGrads[2][2] = -c1 * d; + outGrads[4][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + outSH[8] = c0 * d; + outSH[12] = s0 * d; + d = 6.62322287 * a; + outGrads[8][0] = c1 * d; + outGrads[12][0] = s1 * d; + outGrads[8][1] = -s1 * d; + outGrads[12][1] = c1 * d; + d = -14.049977415 * a; + outGrads[9][2] = -c1 * d; + outGrads[11][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + outSH[19] = c0 * d; + outSH[23] = s0 * d; + d = 30.399773564 * a; + outGrads[19][0] = c1 * d; + outGrads[23][0] = s1 * d; + outGrads[19][1] = -s1 * d; + outGrads[23][1] = c1 * d; + d = -96.132524816 * a; + 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; + outSH[34] = c0 * d; + outSH[38] = s0 * d; + d = 130.459545912 * a; + outGrads[34][0] = c1 * d; + outGrads[38][0] = s1 * d; + outGrads[34][1] = -s1 * d; + outGrads[38][1] = c1 * d; + d = -545.751435723 * a; + outGrads[35][2] = -c1 * d; + outGrads[37][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + outSH[7] = -c1 * d; + outSH[13] = s1 * d; + d = -5.310392309 * z; + outGrads[7][0] = -c0 * d; + outGrads[13][0] = s0 * d; + outGrads[7][1] = s0 * d; + outGrads[13][1] = c0 * d; + d = 6.62322287 * z; + outGrads[8][2] = c0 * d; + outGrads[12][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + outSH[18] = -c1 * d; + outSH[24] = s1 * d; + d = -30.399773564 * b; + outGrads[18][0] = -c0 * d; + outGrads[24][0] = s0 * d; + outGrads[18][1] = s0 * d; + outGrads[24][1] = c0 * d; + d = 60.799547128 * b; + 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; + outSH[33] = -c1 * d; + outSH[39] = s1 * d; + d = -144.52614017 * b; + outGrads[33][0] = -c0 * d; + outGrads[39][0] = s0 * d; + outGrads[33][1] = s0 * d; + outGrads[39][1] = c0 * d; + d = 391.378637737 * b; + outGrads[34][2] = c0 * d; + outGrads[38][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + outSH[6] = c0 * d; + outSH[14] = s0 * d; + d = 2.503342942; + outGrads[6][0] = c1 * d; + outGrads[14][0] = s1 * d; + outGrads[6][1] = -s1 * d; + outGrads[14][1] = c1 * d; + d = -1.77013077; + outGrads[7][2] = -c1 * d; + outGrads[13][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + outSH[17] = c0 * d; + outSH[25] = s0 * d; + d = 22.200855632 * a; + outGrads[17][0] = c1 * d; + outGrads[25][0] = s1 * d; + outGrads[17][1] = -s1 * d; + outGrads[25][1] = c1 * d; + d = -30.399773564 * a; + outGrads[18][2] = -c1 * d; + outGrads[24][2] = s1 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + outSH[32] = c0 * d; + outSH[40] = s0 * d; + d = 124.388296437 * a; + outGrads[32][0] = c1 * d; + outGrads[40][0] = s1 * d; + outGrads[32][1] = -s1 * d; + outGrads[40][1] = c1 * d; + d = -240.876900283 * a; + outGrads[33][2] = -c1 * d; + outGrads[39][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + outSH[16] = -c1 * d; + outSH[26] = s1 * d; + d = -11.833095811 * z; + outGrads[16][0] = -c0 * d; + outGrads[26][0] = s0 * d; + outGrads[16][1] = s0 * d; + outGrads[26][1] = c0 * d; + d = 11.100427816 * z; + 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; + outSH[31] = -c1 * d; + outSH[41] = s1 * d; + d = -86.247765552 * b; + outGrads[31][0] = -c0 * d; + outGrads[41][0] = s0 * d; + outGrads[31][1] = s0 * d; + outGrads[41][1] = c0 * d; + d = 124.388296437 * b; + outGrads[32][2] = c0 * d; + outGrads[40][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + outSH[15] = c0 * d; + outSH[27] = s0 * d; + d = 4.099104631; + outGrads[15][0] = c1 * d; + outGrads[27][0] = s1 * d; + outGrads[15][1] = -s1 * d; + outGrads[27][1] = c1 * d; + d = -2.366619162; + outGrads[16][2] = -c1 * d; + outGrads[26][2] = s1 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + outSH[30] = c0 * d; + outSH[42] = s0 * d; + d = 47.909948945 * a; + outGrads[30][0] = c1 * d; + outGrads[42][0] = s1 * d; + outGrads[30][1] = -s1 * d; + outGrads[42][1] = c1 * d; + d = -51.748659331 * a; + outGrads[31][2] = -c1 * d; + outGrads[41][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + outSH[29] = -c1 * d; + outSH[43] = s1 * d; + d = -20.409946485 * z; + outGrads[29][0] = -c0 * d; + outGrads[43][0] = s0 * d; + outGrads[29][1] = s0 * d; + outGrads[43][1] = c0 * d; + d = 15.969982982 * z; + outGrads[30][2] = c0 * d; + outGrads[42][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + outSH[28] = c0 * d; + outSH[44] = s0 * d; + d = 5.831413281; + outGrads[28][0] = c1 * d; + outGrads[44][0] = s1 * d; + outGrads[28][1] = -s1 * d; + outGrads[44][1] = c1 * d; + d = -2.915706641; + 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/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/ray_tracing/odf/eval_sh_grad.frag b/fury/shaders/ray_tracing/odf/eval_sh_grad.frag new file mode 100644 index 000000000..30a2584e3 --- /dev/null +++ b/fury/shaders/ray_tracing/odf/eval_sh_grad.frag @@ -0,0 +1,60 @@ +void evalShGrad(out float outSH[SH_COUNT], out vec3 outGrads[SH_COUNT], vec3 point, int shDegree, + int numCoeffs) +{ + 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/ray_tracing/odf/get_inv_vandermonde.frag b/fury/shaders/ray_tracing/odf/get_inv_vandermonde.frag new file mode 100644 index 000000000..988cd5783 --- /dev/null +++ b/fury/shaders/ray_tracing/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_tracing/odf/get_sh_glyph_normal.frag b/fury/shaders/ray_tracing/odf/get_sh_glyph_normal.frag new file mode 100644 index 000000000..e9717d815 --- /dev/null +++ b/fury/shaders/ray_tracing/odf/get_sh_glyph_normal.frag @@ -0,0 +1,16 @@ +vec3 getShGlyphNormal(float shCoeffs[SH_COUNT], vec3 point, int shDegree, int numCoeffs) +{ + float shs[SH_COUNT]; + vec3 grads[SH_COUNT]; + 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 != numCoeffs; ++i) { + value += shCoeffs[i] * shs[i]; + grad += shCoeffs[i] * grads[i]; + } + return normalize(point - (value * lengthInv) * (grad - dot(grad, normalized) * normalized)); +} diff --git a/fury/shaders/ray_tracing/odf/ray_sh_glyph_intersections.frag b/fury/shaders/ray_tracing/odf/ray_sh_glyph_intersections.frag new file mode 100644 index 000000000..fa72a1c2f --- /dev/null +++ b/fury/shaders/ray_tracing/odf/ray_sh_glyph_intersections.frag @@ -0,0 +1,86 @@ +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 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 shValues[SH_DEGREE + 1]; + _unroll_ + 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]; + evalSH(shs, point, shDegree, numCoeffs); + shValues[i] = 0.0; + _unroll_ + 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 closestDir + float radiusPoly[SH_DEGREE + 1]; + float invVander[(SH_DEGREE + 1) * (SH_DEGREE + 1)]; + getInvVandermonde(invVander, shDegree); + _unroll_ + for (int i = 0; i != shDegree + 1; ++i) { + radiusPoly[i] = 0.0; + _unroll_ + 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 radiusMax = 0.0; + _unroll_ + 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 == shDegree) ? 1.0 : bound; + radiusMax += bound * abs(radiusPoly[i]); + } + // Figure out the interval, where (if at all) the ray intersects the circle + float dotCloOri = dot(closestDir, rayOri); + if (radiusMax < abs(dotCloOri)) { + _unroll_ + for (int i = 0; i != maxPolyDegree; ++i) + outRayParams[i] = noIntersection; + return; + } + 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) + poly[i] = 0.0; + _unroll_ + for (int i = 0; i != shDegree + 1; ++i) + _unroll_ + 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 dotSq = dotCloOri * dotCloOri; + float binomial = 1.0; + _unroll_ + for (int i = 0; i != shDegree + 2; ++i) { + 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]; + 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 != maxPolyDegree; ++i) + outRayParams[i] = (roots[i] != noIntersection) + ? (roots[i] * dotCloOri - dotDirOri) + : noIntersection; +} diff --git a/fury/shaders/ray_tracing/odf/tournier/eval_sh_10.frag b/fury/shaders/ray_tracing/odf/tournier/eval_sh_10.frag new file mode 100644 index 000000000..d5b33c189 --- /dev/null +++ b/fury/shaders/ray_tracing/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_tracing/odf/tournier/eval_sh_12.frag b/fury/shaders/ray_tracing/odf/tournier/eval_sh_12.frag new file mode 100644 index 000000000..3994374e9 --- /dev/null +++ b/fury/shaders/ray_tracing/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_tracing/odf/tournier/eval_sh_2.frag b/fury/shaders/ray_tracing/odf/tournier/eval_sh_2.frag new file mode 100644 index 000000000..174ac5d62 --- /dev/null +++ b/fury/shaders/ray_tracing/odf/tournier/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[4] = c1 * d; + outSH[2] = s1 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + outSH[5] = c0 * d; + outSH[1] = s0 * d; +} diff --git a/fury/shaders/ray_tracing/odf/tournier/eval_sh_4.frag b/fury/shaders/ray_tracing/odf/tournier/eval_sh_4.frag new file mode 100644 index 000000000..77152bb6a --- /dev/null +++ b/fury/shaders/ray_tracing/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_tracing/odf/tournier/eval_sh_6.frag b/fury/shaders/ray_tracing/odf/tournier/eval_sh_6.frag new file mode 100644 index 000000000..6e3d53307 --- /dev/null +++ b/fury/shaders/ray_tracing/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_tracing/odf/tournier/eval_sh_8.frag b/fury/shaders/ray_tracing/odf/tournier/eval_sh_8.frag new file mode 100644 index 000000000..e68a3efba --- /dev/null +++ b/fury/shaders/ray_tracing/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_tracing/odf/tournier/eval_sh_grad_10.frag b/fury/shaders/ray_tracing/odf/tournier/eval_sh_grad_10.frag new file mode 100644 index 000000000..ace867b13 --- /dev/null +++ b/fury/shaders/ray_tracing/odf/tournier/eval_sh_grad_10.frag @@ -0,0 +1,430 @@ +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]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + 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; + outGrads[4][0] = c0 * d; + outGrads[2][0] = s0 * d; + outGrads[4][1] = s0 * d; + outGrads[2][1] = c0 * d; + d = 1.892349392 * z; + outGrads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + 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; + outGrads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + 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; + outGrads[21][2] = d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + 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; + outGrads[36][2] = d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + 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; + outGrads[55][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + outSH[5] = c0 * d; + outSH[1] = s0 * d; + d = 1.092548431; + outGrads[5][0] = c1 * d; + outGrads[1][0] = s1 * d; + outGrads[5][1] = -s1 * d; + outGrads[1][1] = c1 * d; + d = -1.092548431; + outGrads[4][2] = c1 * d; + outGrads[2][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + outSH[12] = c0 * d; + outSH[8] = s0 * d; + d = 6.62322287 * a; + outGrads[12][0] = c1 * d; + outGrads[8][0] = s1 * d; + outGrads[12][1] = -s1 * d; + outGrads[8][1] = c1 * d; + d = -14.049977415 * a; + outGrads[11][2] = c1 * d; + outGrads[9][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + outSH[23] = c0 * d; + outSH[19] = s0 * d; + d = 30.399773564 * a; + outGrads[23][0] = c1 * d; + outGrads[19][0] = s1 * d; + outGrads[23][1] = -s1 * d; + outGrads[19][1] = c1 * d; + d = -96.132524816 * a; + 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; + outSH[38] = c0 * d; + outSH[34] = s0 * d; + d = 130.459545912 * a; + outGrads[38][0] = c1 * d; + outGrads[34][0] = s1 * d; + outGrads[38][1] = -s1 * d; + outGrads[34][1] = c1 * d; + d = -545.751435723 * a; + 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; + outSH[57] = c0 * d; + outSH[53] = s0 * d; + d = 544.731628762 * a; + outGrads[57][0] = c1 * d; + outGrads[53][0] = s1 * d; + outGrads[57][1] = -s1 * d; + outGrads[53][1] = c1 * d; + d = -2830.508572514 * a; + outGrads[56][2] = c1 * d; + outGrads[54][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + outSH[13] = c1 * d; + outSH[7] = s1 * d; + d = -5.310392309 * z; + outGrads[13][0] = c0 * d; + outGrads[7][0] = s0 * d; + outGrads[13][1] = s0 * d; + outGrads[7][1] = c0 * d; + d = 6.62322287 * z; + outGrads[12][2] = c0 * d; + outGrads[8][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + outSH[24] = c1 * d; + outSH[18] = s1 * d; + d = -30.399773564 * b; + outGrads[24][0] = c0 * d; + outGrads[18][0] = s0 * d; + outGrads[24][1] = s0 * d; + outGrads[18][1] = c0 * d; + d = 60.799547128 * b; + 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; + outSH[39] = c1 * d; + outSH[33] = s1 * d; + d = -144.52614017 * b; + outGrads[39][0] = c0 * d; + outGrads[33][0] = s0 * d; + outGrads[39][1] = s0 * d; + outGrads[33][1] = c0 * d; + d = 391.378637737 * b; + 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; + outSH[58] = c1 * d; + outSH[52] = s1 * d; + d = -640.983970322 * b; + outGrads[58][0] = c0 * d; + outGrads[52][0] = s0 * d; + outGrads[58][1] = s0 * d; + outGrads[52][1] = c0 * d; + d = 2178.926515046 * b; + outGrads[57][2] = c0 * d; + outGrads[53][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + outSH[14] = c0 * d; + outSH[6] = s0 * d; + d = 2.503342942; + outGrads[14][0] = c1 * d; + outGrads[6][0] = s1 * d; + outGrads[14][1] = -s1 * d; + outGrads[6][1] = c1 * d; + d = -1.77013077; + outGrads[13][2] = c1 * d; + outGrads[7][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + outSH[25] = c0 * d; + outSH[17] = s0 * d; + d = 22.200855632 * a; + outGrads[25][0] = c1 * d; + outGrads[17][0] = s1 * d; + outGrads[25][1] = -s1 * d; + outGrads[17][1] = c1 * d; + d = -30.399773564 * a; + outGrads[24][2] = c1 * d; + outGrads[18][2] = s1 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + outSH[40] = c0 * d; + outSH[32] = s0 * d; + d = 124.388296437 * a; + outGrads[40][0] = c1 * d; + outGrads[32][0] = s1 * d; + outGrads[40][1] = -s1 * d; + outGrads[32][1] = c1 * d; + d = -240.876900283 * a; + 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; + outSH[59] = c0 * d; + outSH[51] = s0 * d; + d = 604.325482728 * a; + outGrads[59][0] = c1 * d; + outGrads[51][0] = s1 * d; + outGrads[59][1] = -s1 * d; + outGrads[51][1] = c1 * d; + d = -1495.629264084 * a; + outGrads[58][2] = c1 * d; + outGrads[52][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + outSH[26] = c1 * d; + outSH[16] = s1 * d; + d = -11.833095811 * z; + outGrads[26][0] = c0 * d; + outGrads[16][0] = s0 * d; + outGrads[26][1] = s0 * d; + outGrads[16][1] = c0 * d; + d = 11.100427816 * z; + 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; + outSH[41] = c1 * d; + outSH[31] = s1 * d; + d = -86.247765552 * b; + outGrads[41][0] = c0 * d; + outGrads[31][0] = s0 * d; + outGrads[41][1] = s0 * d; + outGrads[31][1] = c0 * d; + d = 124.388296437 * b; + 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; + outSH[60] = c1 * d; + outSH[50] = s1 * d; + d = -477.761243376 * b; + outGrads[60][0] = c0 * d; + outGrads[50][0] = s0 * d; + outGrads[60][1] = s0 * d; + outGrads[50][1] = c0 * d; + d = 906.488224092 * b; + outGrads[59][2] = c0 * d; + outGrads[51][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + outSH[27] = c0 * d; + outSH[15] = s0 * d; + d = 4.099104631; + outGrads[27][0] = c1 * d; + outGrads[15][0] = s1 * d; + outGrads[27][1] = -s1 * d; + outGrads[15][1] = c1 * d; + d = -2.366619162; + outGrads[26][2] = c1 * d; + outGrads[16][2] = s1 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + outSH[42] = c0 * d; + outSH[30] = s0 * d; + d = 47.909948945 * a; + outGrads[42][0] = c1 * d; + outGrads[30][0] = s1 * d; + outGrads[42][1] = -s1 * d; + outGrads[30][1] = c1 * d; + d = -51.748659331 * a; + outGrads[41][2] = c1 * d; + outGrads[31][2] = s1 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + outSH[61] = c0 * d; + outSH[49] = s0 * d; + d = 320.491985161 * a; + outGrads[61][0] = c1 * d; + outGrads[49][0] = s1 * d; + outGrads[61][1] = -s1 * d; + outGrads[49][1] = c1 * d; + d = -477.761243376 * a; + outGrads[60][2] = c1 * d; + outGrads[50][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + outSH[43] = c1 * d; + outSH[29] = s1 * d; + d = -20.409946485 * z; + outGrads[43][0] = c0 * d; + outGrads[29][0] = s0 * d; + outGrads[43][1] = s0 * d; + outGrads[29][1] = c0 * d; + d = 15.969982982 * z; + 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; + outSH[62] = c1 * d; + outSH[48] = s1 * d; + d = -181.371689194 * b; + outGrads[62][0] = c0 * d; + outGrads[48][0] = s0 * d; + outGrads[62][1] = s0 * d; + outGrads[48][1] = c0 * d; + d = 213.661323441 * b; + outGrads[61][2] = c0 * d; + outGrads[49][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + outSH[44] = c0 * d; + outSH[28] = s0 * d; + d = 5.831413281; + outGrads[44][0] = c1 * d; + outGrads[28][0] = s1 * d; + outGrads[44][1] = -s1 * d; + outGrads[28][1] = c1 * d; + d = -2.915706641; + outGrads[43][2] = c1 * d; + outGrads[29][2] = s1 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + outSH[63] = c0 * d; + outSH[47] = s0 * d; + d = 84.622493774 * a; + outGrads[63][0] = c1 * d; + outGrads[47][0] = s1 * d; + outGrads[63][1] = -s1 * d; + outGrads[47][1] = c1 * d; + d = -77.73072394 * a; + outGrads[62][2] = c1 * d; + outGrads[48][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + outSH[64] = c1 * d; + outSH[46] = s1 * d; + d = -30.887057699 * z; + outGrads[64][0] = c0 * d; + outGrads[46][0] = s0 * d; + outGrads[64][1] = s0 * d; + outGrads[46][1] = c0 * d; + d = 21.155623443 * z; + outGrads[63][2] = c0 * d; + outGrads[47][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + outSH[65] = c0 * d; + outSH[45] = s0 * d; + d = 7.673951182; + outGrads[65][0] = c1 * d; + outGrads[45][0] = s1 * d; + outGrads[65][1] = -s1 * d; + outGrads[45][1] = c1 * d; + d = -3.4318953; + 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/ray_tracing/odf/tournier/eval_sh_grad_12.frag b/fury/shaders/ray_tracing/odf/tournier/eval_sh_grad_12.frag new file mode 100644 index 000000000..9639e0789 --- /dev/null +++ b/fury/shaders/ray_tracing/odf/tournier/eval_sh_grad_12.frag @@ -0,0 +1,591 @@ +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]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + 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; + outGrads[4][0] = c0 * d; + outGrads[2][0] = s0 * d; + outGrads[4][1] = s0 * d; + outGrads[2][1] = c0 * d; + d = 1.892349392 * z; + outGrads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + 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; + outGrads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + 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; + outGrads[21][2] = d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + 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; + outGrads[36][2] = d; + a = z2 * b - 0.247058824 * a; + b = a - 0.247678019 * b; + d = -314.500952502 * b; + 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; + outGrads[55][2] = d; + a = z2 * b - 0.248120301 * a; + b = a - 0.248447205 * b; + d = -1265.233874957 * b; + 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; + outGrads[78][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + outSH[5] = c0 * d; + outSH[1] = s0 * d; + d = 1.092548431; + outGrads[5][0] = c1 * d; + outGrads[1][0] = s1 * d; + outGrads[5][1] = -s1 * d; + outGrads[1][1] = c1 * d; + d = -1.092548431; + outGrads[4][2] = c1 * d; + outGrads[2][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + outSH[12] = c0 * d; + outSH[8] = s0 * d; + d = 6.62322287 * a; + outGrads[12][0] = c1 * d; + outGrads[8][0] = s1 * d; + outGrads[12][1] = -s1 * d; + outGrads[8][1] = c1 * d; + d = -14.049977415 * a; + outGrads[11][2] = c1 * d; + outGrads[9][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + outSH[23] = c0 * d; + outSH[19] = s0 * d; + d = 30.399773564 * a; + outGrads[23][0] = c1 * d; + outGrads[19][0] = s1 * d; + outGrads[23][1] = -s1 * d; + outGrads[19][1] = c1 * d; + d = -96.132524816 * a; + 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; + outSH[38] = c0 * d; + outSH[34] = s0 * d; + d = 130.459545912 * a; + outGrads[38][0] = c1 * d; + outGrads[34][0] = s1 * d; + outGrads[38][1] = -s1 * d; + outGrads[34][1] = c1 * d; + d = -545.751435723 * a; + 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; + outSH[57] = c0 * d; + outSH[53] = s0 * d; + d = 544.731628762 * a; + outGrads[57][0] = c1 * d; + outGrads[53][0] = s1 * d; + outGrads[57][1] = -s1 * d; + outGrads[53][1] = c1 * d; + d = -2830.508572514 * a; + 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; + outSH[80] = c0 * d; + outSH[76] = s0 * d; + d = 2243.019924866 * a; + outGrads[80][0] = c1 * d; + outGrads[76][0] = s1 * d; + outGrads[80][1] = -s1 * d; + outGrads[76][1] = c1 * d; + d = -13917.572624524 * a; + outGrads[79][2] = c1 * d; + outGrads[77][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + outSH[13] = c1 * d; + outSH[7] = s1 * d; + d = -5.310392309 * z; + outGrads[13][0] = c0 * d; + outGrads[7][0] = s0 * d; + outGrads[13][1] = s0 * d; + outGrads[7][1] = c0 * d; + d = 6.62322287 * z; + outGrads[12][2] = c0 * d; + outGrads[8][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + outSH[24] = c1 * d; + outSH[18] = s1 * d; + d = -30.399773564 * b; + outGrads[24][0] = c0 * d; + outGrads[18][0] = s0 * d; + outGrads[24][1] = s0 * d; + outGrads[18][1] = c0 * d; + d = 60.799547128 * b; + 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; + outSH[39] = c1 * d; + outSH[33] = s1 * d; + d = -144.52614017 * b; + outGrads[39][0] = c0 * d; + outGrads[33][0] = s0 * d; + outGrads[39][1] = s0 * d; + outGrads[33][1] = c0 * d; + d = 391.378637737 * b; + 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; + outSH[58] = c1 * d; + outSH[52] = s1 * d; + d = -640.983970322 * b; + outGrads[58][0] = c0 * d; + outGrads[52][0] = s0 * d; + outGrads[58][1] = s0 * d; + outGrads[52][1] = c0 * d; + d = 2178.926515046 * b; + 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; + outSH[81] = c1 * d; + outSH[75] = s1 * d; + d = -2747.127149409 * b; + outGrads[81][0] = c0 * d; + outGrads[75][0] = s0 * d; + outGrads[81][1] = s0 * d; + outGrads[75][1] = c0 * d; + d = 11215.099624332 * b; + outGrads[80][2] = c0 * d; + outGrads[76][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + outSH[14] = c0 * d; + outSH[6] = s0 * d; + d = 2.503342942; + outGrads[14][0] = c1 * d; + outGrads[6][0] = s1 * d; + outGrads[14][1] = -s1 * d; + outGrads[6][1] = c1 * d; + d = -1.77013077; + outGrads[13][2] = c1 * d; + outGrads[7][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + outSH[25] = c0 * d; + outSH[17] = s0 * d; + d = 22.200855632 * a; + outGrads[25][0] = c1 * d; + outGrads[17][0] = s1 * d; + outGrads[25][1] = -s1 * d; + outGrads[17][1] = c1 * d; + d = -30.399773564 * a; + outGrads[24][2] = c1 * d; + outGrads[18][2] = s1 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + outSH[40] = c0 * d; + outSH[32] = s0 * d; + d = 124.388296437 * a; + outGrads[40][0] = c1 * d; + outGrads[32][0] = s1 * d; + outGrads[40][1] = -s1 * d; + outGrads[32][1] = c1 * d; + d = -240.876900283 * a; + 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; + outSH[59] = c0 * d; + outSH[51] = s0 * d; + d = 604.325482728 * a; + outGrads[59][0] = c1 * d; + outGrads[51][0] = s1 * d; + outGrads[59][1] = -s1 * d; + outGrads[51][1] = c1 * d; + d = -1495.629264084 * a; + 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; + outSH[82] = c0 * d; + outSH[74] = s0 * d; + d = 2747.127149409 * a; + outGrads[82][0] = c1 * d; + outGrads[74][0] = s1 * d; + outGrads[82][1] = -s1 * d; + outGrads[74][1] = c1 * d; + d = -8241.381448228 * a; + outGrads[81][2] = -c1 * d; + outGrads[75][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + outSH[26] = c1 * d; + outSH[16] = s1 * d; + d = -11.833095811 * z; + outGrads[26][0] = c0 * d; + outGrads[16][0] = s0 * d; + outGrads[26][1] = s0 * d; + outGrads[16][1] = c0 * d; + d = 11.100427816 * z; + 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; + outSH[41] = c1 * d; + outSH[31] = s1 * d; + d = -86.247765552 * b; + outGrads[41][0] = c0 * d; + outGrads[31][0] = s0 * d; + outGrads[41][1] = s0 * d; + outGrads[31][1] = c0 * d; + d = 124.388296437 * b; + 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; + outSH[60] = c1 * d; + outSH[50] = s1 * d; + d = -477.761243376 * b; + outGrads[60][0] = c0 * d; + outGrads[50][0] = s0 * d; + outGrads[60][1] = s0 * d; + outGrads[50][1] = c0 * d; + d = 906.488224092 * b; + 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; + outSH[83] = c1 * d; + outSH[73] = s1 * d; + d = -2355.642096651 * b; + outGrads[83][0] = c0 * d; + outGrads[73][0] = s0 * d; + outGrads[83][1] = s0 * d; + outGrads[73][1] = c0 * d; + d = 5494.254298819 * b; + outGrads[82][2] = c0 * d; + outGrads[74][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + outSH[27] = c0 * d; + outSH[15] = s0 * d; + d = 4.099104631; + outGrads[27][0] = c1 * d; + outGrads[15][0] = s1 * d; + outGrads[27][1] = -s1 * d; + outGrads[15][1] = c1 * d; + d = -2.366619162; + outGrads[26][2] = c1 * d; + outGrads[16][2] = s1 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + outSH[42] = c0 * d; + outSH[30] = s0 * d; + d = 47.909948945 * a; + outGrads[42][0] = c1 * d; + outGrads[30][0] = s1 * d; + outGrads[42][1] = -s1 * d; + outGrads[30][1] = c1 * d; + d = -51.748659331 * a; + outGrads[41][2] = c1 * d; + outGrads[31][2] = s1 * d; + b = z2 * (a - 0.109803922); + a = b - 0.139318885 * a; + d = 53.41533086 * a; + outSH[61] = c0 * d; + outSH[49] = s0 * d; + d = 320.491985161 * a; + outGrads[61][0] = c1 * d; + outGrads[49][0] = s1 * d; + outGrads[61][1] = -s1 * d; + outGrads[49][1] = c1 * d; + d = -477.761243376 * a; + 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; + outSH[84] = c0 * d; + outSH[72] = s0 * d; + d = 1762.801130306 * a; + outGrads[84][0] = c1 * d; + outGrads[72][0] = s1 * d; + outGrads[84][1] = -s1 * d; + outGrads[72][1] = c1 * d; + d = -3297.898935312 * a; + outGrads[83][2] = c1 * d; + outGrads[73][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + outSH[43] = c1 * d; + outSH[29] = s1 * d; + d = -20.409946485 * z; + outGrads[43][0] = c0 * d; + outGrads[29][0] = s0 * d; + outGrads[43][1] = s0 * d; + outGrads[29][1] = c0 * d; + d = 15.969982982 * z; + 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; + outSH[62] = c1 * d; + outSH[48] = s1 * d; + d = -181.371689194 * b; + outGrads[62][0] = c0 * d; + outGrads[48][0] = s0 * d; + outGrads[62][1] = s0 * d; + outGrads[48][1] = c0 * d; + d = 213.661323441 * b; + 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; + outSH[85] = c1 * d; + outSH[71] = s1 * d; + d = -1155.7101691 * b; + outGrads[85][0] = c0 * d; + outGrads[71][0] = s0 * d; + outGrads[85][1] = s0 * d; + outGrads[71][1] = c0 * d; + d = 1762.801130306 * b; + outGrads[84][2] = c0 * d; + outGrads[72][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + outSH[44] = c0 * d; + outSH[28] = s0 * d; + d = 5.831413281; + outGrads[44][0] = c1 * d; + outGrads[28][0] = s1 * d; + outGrads[44][1] = -s1 * d; + outGrads[28][1] = c1 * d; + d = -2.915706641; + outGrads[43][2] = c1 * d; + outGrads[29][2] = s1 * d; + a = z2 - 5.26315789e-02; + d = 10.577811722 * a; + outSH[63] = c0 * d; + outSH[47] = s0 * d; + d = 84.622493774 * a; + outGrads[63][0] = c1 * d; + outGrads[47][0] = s1 * d; + outGrads[63][1] = -s1 * d; + outGrads[47][1] = c1 * d; + d = -77.73072394 * a; + 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; + outSH[86] = c0 * d; + outSH[70] = s0 * d; + d = 660.405810914 * a; + outGrads[86][0] = c1 * d; + outGrads[70][0] = s1 * d; + outGrads[86][1] = -s1 * d; + outGrads[70][1] = c1 * d; + d = -825.507263643 * a; + outGrads[85][2] = c1 * d; + outGrads[71][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.4318953 * z; + outSH[64] = c1 * d; + outSH[46] = s1 * d; + d = -30.887057699 * z; + outGrads[64][0] = c0 * d; + outGrads[46][0] = s0 * d; + outGrads[64][1] = s0 * d; + outGrads[46][1] = c0 * d; + d = 21.155623443 * z; + 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; + outSH[87] = c1 * d; + outSH[69] = s1 * d; + d = -324.252816204 * b; + outGrads[87][0] = c0 * d; + outGrads[69][0] = s0 * d; + outGrads[87][1] = s0 * d; + outGrads[69][1] = c0 * d; + d = 330.202905457 * b; + outGrads[86][2] = c0 * d; + outGrads[70][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.767395118; + outSH[65] = c0 * d; + outSH[45] = s0 * d; + d = 7.673951182; + outGrads[65][0] = c1 * d; + outGrads[45][0] = s1 * d; + outGrads[65][1] = -s1 * d; + outGrads[45][1] = c1 * d; + d = -3.4318953; + outGrads[64][2] = c1 * d; + outGrads[46][2] = s1 * d; + a = z2 - 4.34782609e-02; + d = 13.3042542 * a; + outSH[88] = c0 * d; + outSH[68] = s0 * d; + d = 133.042542003 * a; + outGrads[88][0] = c1 * d; + outGrads[68][0] = s1 * d; + outGrads[88][1] = -s1 * d; + outGrads[68][1] = c1 * d; + d = -108.084272068 * a; + outGrads[87][2] = c1 * d; + outGrads[69][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -3.923210529 * z; + outSH[89] = c1 * d; + outSH[67] = s1 * d; + d = -43.155315818 * z; + outGrads[89][0] = c0 * d; + outGrads[67][0] = s0 * d; + outGrads[89][1] = s0 * d; + outGrads[67][1] = c0 * d; + d = 26.608508401 * z; + outGrads[88][2] = c0 * d; + outGrads[68][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.800821996; + outSH[90] = c0 * d; + outSH[66] = s0 * d; + d = 9.609863949; + outGrads[90][0] = c1 * d; + outGrads[66][0] = s1 * d; + outGrads[90][1] = -s1 * d; + outGrads[66][1] = c1 * d; + d = -3.923210529; + 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/ray_tracing/odf/tournier/eval_sh_grad_2.frag b/fury/shaders/ray_tracing/odf/tournier/eval_sh_grad_2.frag new file mode 100644 index 000000000..cfd071515 --- /dev/null +++ b/fury/shaders/ray_tracing/odf/tournier/eval_sh_grad_2.frag @@ -0,0 +1,46 @@ +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]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + 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[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; + outGrads[3][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + outSH[5] = c0 * d; + outSH[1] = s0 * d; + d = 1.092548431; + outGrads[1][0] = c1 * d; + outGrads[5][0] = s1 * d; + outGrads[5][1] = -s1 * d; + outGrads[1][1] = c1 * d; + d = -1.092548431; + 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/ray_tracing/odf/tournier/eval_sh_grad_4.frag b/fury/shaders/ray_tracing/odf/tournier/eval_sh_grad_4.frag new file mode 100644 index 000000000..acdb37afa --- /dev/null +++ b/fury/shaders/ray_tracing/odf/tournier/eval_sh_grad_4.frag @@ -0,0 +1,103 @@ +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]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + 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; + outGrads[4][0] = c0 * d; + outGrads[2][0] = s0 * d; + outGrads[4][1] = s0 * d; + outGrads[2][1] = c0 * d; + d = 1.892349392 * z; + outGrads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + 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; + outGrads[10][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + outSH[5] = c0 * d; + outSH[1] = s0 * d; + d = 1.092548431; + outGrads[5][0] = c1 * d; + outGrads[1][0] = s1 * d; + outGrads[5][1] = -s1 * d; + outGrads[1][1] = c1 * d; + d = -1.092548431; + outGrads[4][2] = c1 * d; + outGrads[2][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + outSH[12] = c0 * d; + outSH[8] = s0 * d; + d = 6.62322287 * a; + outGrads[12][0] = c1 * d; + outGrads[8][0] = s1 * d; + outGrads[12][1] = -s1 * d; + outGrads[8][1] = c1 * d; + d = -14.049977415 * a; + outGrads[11][2] = c1 * d; + outGrads[9][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + outSH[13] = c1 * d; + outSH[7] = s1 * d; + d = -5.310392309 * z; + outGrads[13][0] = c0 * d; + outGrads[7][0] = s0 * d; + outGrads[13][1] = s0 * d; + outGrads[7][1] = c0 * d; + d = 6.62322287 * z; + outGrads[12][2] = c0 * d; + outGrads[8][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + outSH[14] = c0 * d; + outSH[6] = s0 * d; + d = 2.503342942; + outGrads[14][0] = c1 * d; + outGrads[6][0] = s1 * d; + outGrads[14][1] = -s1 * d; + outGrads[6][1] = c1 * d; + d = -1.77013077; + 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/ray_tracing/odf/tournier/eval_sh_grad_6.frag b/fury/shaders/ray_tracing/odf/tournier/eval_sh_grad_6.frag new file mode 100644 index 000000000..1a9cdb53f --- /dev/null +++ b/fury/shaders/ray_tracing/odf/tournier/eval_sh_grad_6.frag @@ -0,0 +1,186 @@ +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]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + 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; + outGrads[4][0] = c0 * d; + outGrads[2][0] = s0 * d; + outGrads[4][1] = s0 * d; + outGrads[2][1] = c0 * d; + d = 1.892349392 * z; + outGrads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + 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; + outGrads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + 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; + outGrads[21][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + outSH[5] = c0 * d; + outSH[1] = s0 * d; + d = 1.092548431; + outGrads[5][0] = c1 * d; + outGrads[1][0] = s1 * d; + outGrads[5][1] = -s1 * d; + outGrads[1][1] = c1 * d; + d = -1.092548431; + outGrads[4][2] = c1 * d; + outGrads[2][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + outSH[12] = c0 * d; + outSH[8] = s0 * d; + d = 6.62322287 * a; + outGrads[12][0] = c1 * d; + outGrads[8][0] = s1 * d; + outGrads[12][1] = -s1 * d; + outGrads[8][1] = c1 * d; + d = -14.049977415 * a; + outGrads[11][2] = c1 * d; + outGrads[9][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + outSH[23] = c0 * d; + outSH[19] = s0 * d; + d = 30.399773564 * a; + outGrads[23][0] = c1 * d; + outGrads[19][0] = s1 * d; + outGrads[23][1] = -s1 * d; + outGrads[19][1] = c1 * d; + d = -96.132524816 * a; + outGrads[22][2] = c1 * d; + outGrads[20][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + outSH[13] = c1 * d; + outSH[7] = s1 * d; + d = -5.310392309 * z; + outGrads[13][0] = c0 * d; + outGrads[7][0] = s0 * d; + outGrads[13][1] = s0 * d; + outGrads[7][1] = c0 * d; + d = 6.62322287 * z; + outGrads[12][2] = c0 * d; + outGrads[8][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + outSH[24] = c1 * d; + outSH[18] = s1 * d; + d = -30.399773564 * b; + outGrads[24][0] = c0 * d; + outGrads[18][0] = s0 * d; + outGrads[24][1] = s0 * d; + outGrads[18][1] = c0 * d; + d = 60.799547128 * b; + outGrads[23][2] = c0 * d; + outGrads[19][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + outSH[14] = c0 * d; + outSH[6] = s0 * d; + d = 2.503342942; + outGrads[14][0] = c1 * d; + outGrads[6][0] = s1 * d; + outGrads[14][1] = -s1 * d; + outGrads[6][1] = c1 * d; + d = -1.77013077; + outGrads[13][2] = c1 * d; + outGrads[7][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + outSH[25] = c0 * d; + outSH[17] = s0 * d; + d = 22.200855632 * a; + outGrads[25][0] = c1 * d; + outGrads[17][0] = s1 * d; + outGrads[25][1] = -s1 * d; + outGrads[17][1] = c1 * d; + d = -30.399773564 * a; + outGrads[24][2] = c1 * d; + outGrads[18][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + outSH[26] = c1 * d; + outSH[16] = s1 * d; + d = -11.833095811 * z; + outGrads[26][0] = c0 * d; + outGrads[16][0] = s0 * d; + outGrads[26][1] = s0 * d; + outGrads[16][1] = c0 * d; + d = 11.100427816 * z; + outGrads[25][2] = c0 * d; + outGrads[17][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + outSH[27] = c0 * d; + outSH[15] = s0 * d; + d = 4.099104631; + outGrads[27][0] = c1 * d; + outGrads[15][0] = s1 * d; + outGrads[27][1] = -s1 * d; + outGrads[15][1] = c1 * d; + d = -2.366619162; + 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/ray_tracing/odf/tournier/eval_sh_grad_8.frag b/fury/shaders/ray_tracing/odf/tournier/eval_sh_grad_8.frag new file mode 100644 index 000000000..fbe0545db --- /dev/null +++ b/fury/shaders/ray_tracing/odf/tournier/eval_sh_grad_8.frag @@ -0,0 +1,295 @@ +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]; + y = point[1]; + z = point[2]; + z2 = z * z; + c0 = 1.0; + s0 = 0.0; + 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; + outGrads[4][0] = c0 * d; + outGrads[2][0] = s0 * d; + outGrads[4][1] = s0 * d; + outGrads[2][1] = c0 * d; + d = 1.892349392 * z; + outGrads[3][2] = d; + a = (z2 - 0.2) * z; + b = a - 0.228571429 * z; + d = -4.683325805 * b; + 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; + outGrads[10][2] = d; + a = z2 * b - 0.238095238 * a; + b = a - 0.242424242 * b; + d = -19.226504963 * b; + 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; + outGrads[21][2] = d; + a = z2 * b - 0.244755245 * a; + b = a - 0.246153846 * b; + d = -77.964490818 * b; + 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; + outGrads[36][2] = d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.546274215; + outSH[5] = c0 * d; + outSH[1] = s0 * d; + d = 1.092548431; + outGrads[5][0] = c1 * d; + outGrads[1][0] = s1 * d; + outGrads[5][1] = -s1 * d; + outGrads[1][1] = c1 * d; + d = -1.092548431; + outGrads[4][2] = c1 * d; + outGrads[2][2] = s1 * d; + a = z2 - 0.142857143; + d = 3.311611435 * a; + outSH[12] = c0 * d; + outSH[8] = s0 * d; + d = 6.62322287 * a; + outGrads[12][0] = c1 * d; + outGrads[8][0] = s1 * d; + outGrads[12][1] = -s1 * d; + outGrads[8][1] = c1 * d; + d = -14.049977415 * a; + outGrads[11][2] = c1 * d; + outGrads[9][2] = s1 * d; + b = z2 * (a - 0.19047619); + a = b - 0.212121212 * a; + d = 15.199886782 * a; + outSH[23] = c0 * d; + outSH[19] = s0 * d; + d = 30.399773564 * a; + outGrads[23][0] = c1 * d; + outGrads[19][0] = s1 * d; + outGrads[23][1] = -s1 * d; + outGrads[19][1] = c1 * d; + d = -96.132524816 * a; + 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; + outSH[38] = c0 * d; + outSH[34] = s0 * d; + d = 130.459545912 * a; + outGrads[38][0] = c1 * d; + outGrads[34][0] = s1 * d; + outGrads[38][1] = -s1 * d; + outGrads[34][1] = c1 * d; + d = -545.751435723 * a; + outGrads[37][2] = c1 * d; + outGrads[35][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -1.77013077 * z; + outSH[13] = c1 * d; + outSH[7] = s1 * d; + d = -5.310392309 * z; + outGrads[13][0] = c0 * d; + outGrads[7][0] = s0 * d; + outGrads[13][1] = s0 * d; + outGrads[7][1] = c0 * d; + d = 6.62322287 * z; + outGrads[12][2] = c0 * d; + outGrads[8][2] = s0 * d; + a = (z2 - 0.111111111) * z; + b = a - 0.161616162 * z; + d = -10.133257855 * b; + outSH[24] = c1 * d; + outSH[18] = s1 * d; + d = -30.399773564 * b; + outGrads[24][0] = c0 * d; + outGrads[18][0] = s0 * d; + outGrads[24][1] = s0 * d; + outGrads[18][1] = c0 * d; + d = 60.799547128 * b; + 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; + outSH[39] = c1 * d; + outSH[33] = s1 * d; + d = -144.52614017 * b; + outGrads[39][0] = c0 * d; + outGrads[33][0] = s0 * d; + outGrads[39][1] = s0 * d; + outGrads[33][1] = c0 * d; + d = 391.378637737 * b; + outGrads[38][2] = c0 * d; + outGrads[34][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.625835735; + outSH[14] = c0 * d; + outSH[6] = s0 * d; + d = 2.503342942; + outGrads[14][0] = c1 * d; + outGrads[6][0] = s1 * d; + outGrads[14][1] = -s1 * d; + outGrads[6][1] = c1 * d; + d = -1.77013077; + outGrads[13][2] = c1 * d; + outGrads[7][2] = s1 * d; + a = z2 - 9.09090909e-02; + d = 5.550213908 * a; + outSH[25] = c0 * d; + outSH[17] = s0 * d; + d = 22.200855632 * a; + outGrads[25][0] = c1 * d; + outGrads[17][0] = s1 * d; + outGrads[25][1] = -s1 * d; + outGrads[17][1] = c1 * d; + d = -30.399773564 * a; + outGrads[24][2] = c1 * d; + outGrads[18][2] = s1 * d; + b = z2 * (a - 0.13986014); + a = b - 0.169230769 * a; + d = 31.097074109 * a; + outSH[40] = c0 * d; + outSH[32] = s0 * d; + d = 124.388296437 * a; + outGrads[40][0] = c1 * d; + outGrads[32][0] = s1 * d; + outGrads[40][1] = -s1 * d; + outGrads[32][1] = c1 * d; + d = -240.876900283 * a; + outGrads[39][2] = c1 * d; + outGrads[33][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.366619162 * z; + outSH[26] = c1 * d; + outSH[16] = s1 * d; + d = -11.833095811 * z; + outGrads[26][0] = c0 * d; + outGrads[16][0] = s0 * d; + outGrads[26][1] = s0 * d; + outGrads[16][1] = c0 * d; + d = 11.100427816 * z; + 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; + outSH[41] = c1 * d; + outSH[31] = s1 * d; + d = -86.247765552 * b; + outGrads[41][0] = c0 * d; + outGrads[31][0] = s0 * d; + outGrads[41][1] = s0 * d; + outGrads[31][1] = c0 * d; + d = 124.388296437 * b; + outGrads[40][2] = c0 * d; + outGrads[32][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.683184105; + outSH[27] = c0 * d; + outSH[15] = s0 * d; + d = 4.099104631; + outGrads[27][0] = c1 * d; + outGrads[15][0] = s1 * d; + outGrads[27][1] = -s1 * d; + outGrads[15][1] = c1 * d; + d = -2.366619162; + outGrads[26][2] = c1 * d; + outGrads[16][2] = s1 * d; + a = z2 - 6.66666667e-02; + d = 7.984991491 * a; + outSH[42] = c0 * d; + outSH[30] = s0 * d; + d = 47.909948945 * a; + outGrads[42][0] = c1 * d; + outGrads[30][0] = s1 * d; + outGrads[42][1] = -s1 * d; + outGrads[30][1] = c1 * d; + d = -51.748659331 * a; + outGrads[41][2] = c1 * d; + outGrads[31][2] = s1 * d; + c1 = x * c0 - y * s0; + s1 = y * c0 + x * s0; + d = -2.915706641 * z; + outSH[43] = c1 * d; + outSH[29] = s1 * d; + d = -20.409946485 * z; + outGrads[43][0] = c0 * d; + outGrads[29][0] = s0 * d; + outGrads[43][1] = s0 * d; + outGrads[29][1] = c0 * d; + d = 15.969982982 * z; + outGrads[42][2] = c0 * d; + outGrads[30][2] = s0 * d; + c0 = x * c1 - y * s1; + s0 = y * c1 + x * s1; + d = 0.72892666; + outSH[44] = c0 * d; + outSH[28] = s0 * d; + d = 5.831413281; + outGrads[44][0] = c1 * d; + outGrads[28][0] = s1 * d; + outGrads[44][1] = -s1 * d; + outGrads[28][1] = c1 * d; + d = -2.915706641; + 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 new file mode 100644 index 000000000..8b5377942 --- /dev/null +++ b/fury/shaders/utils/find_roots.frag @@ -0,0 +1,82 @@ +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 + // 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[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 != 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]; + if (discriminant >= 0.0) { + 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 + 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 + outRoots[maxPolyDegree] = end; + _unroll_ + 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 + // 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 != maxPolyDegree + 1; ++degree) { + // Take the integral of the previous derivative (scaled such that the + // constant coefficient can still be copied directly from poly) + float prevDerivativeOrder = float(maxPolyDegree + 1 - degree); + _unroll_ + for (int i = maxPolyDegree; i != 0; --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 beginValue = derivative[maxPolyDegree]; + _unroll_ + for (int i = maxPolyDegree - 1; i != -1; --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 currentBegin = outRoots[i]; + float currentEnd = outRoots[i + 1]; + // Try to find a root + float root; + 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 + outRoots[i] = outRoots[i - 1]; + else + outRoots[i] = noIntersection; + } + } + // We no longer need this array entry + outRoots[maxPolyDegree] = noIntersection; +} diff --git a/fury/shaders/utils/minmax_norm.glsl b/fury/shaders/utils/minmax_norm.glsl new file mode 100644 index 000000000..fea8817ae --- /dev/null +++ b/fury/shaders/utils/minmax_norm.glsl @@ -0,0 +1,4 @@ +float rescale(float x, float oldMin, float oldMax, float newMin, float newMax) +{ + return (x - oldMin) * (newMax - newMin) / (oldMax - oldMin) + newMin; +} diff --git a/fury/shaders/utils/newton_bisection.frag b/fury/shaders/utils/newton_bisection.frag new file mode 100644 index 000000000..2202b7c1b --- /dev/null +++ b/fury/shaders/utils/newton_bisection.frag @@ -0,0 +1,47 @@ +bool newtonBisection(out float outRoot, out float outEndValue, + float poly[MAX_DEGREE + 1], float begin, float end, + float beginValue, float errorTolerance, int maxPolyDegree) +{ + if (begin == end) { + outEndValue = beginValue; + return false; + } + // Evaluate the polynomial at the end of the interval + outEndValue = poly[maxPolyDegree]; + _unroll_ + 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 (beginValue * outEndValue > 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[maxPolyDegree] * current + poly[maxPolyDegree - 1]; + float derivative = poly[maxPolyDegree]; + _unroll_ + for (int j = maxPolyDegree - 2; j != -1; --j) { + derivative = derivative * current + value; + value = value * current + poly[j]; + } + // Shorten the interval + bool right = beginValue * 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) < errorTolerance; + current = next; + if (done) + break; + } + outRoot = current; + return true; +} diff --git a/fury/tests/test_actors.py b/fury/tests/test_actors.py index 4f6b2b5df..b41c65d6b 100644 --- a/fury/tests/test_actors.py +++ b/fury/tests/test_actors.py @@ -1950,3 +1950,139 @@ 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() + + 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 glyph of degree 6 + 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() + + # odf glyph of degree 4 + odf_actor = actor.odf(centers=centers, coeffs=coeffs[:15]) + scene.add(odf_actor) + + if interactive: + window.show(scene) + + report = window.analyze_scene(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..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, @@ -970,3 +971,29 @@ 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(): + data1d = np.array([2, -2, 5, -1, 8]) + actual_data1d = minmax_norm(data1d) + 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]]]) + 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]]) + 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/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..de85ec3ab --- /dev/null +++ b/fury/texture/tests/test_utils.py @@ -0,0 +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(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 new file mode 100644 index 000000000..25da3a714 --- /dev/null +++ b/fury/texture/utils.py @@ -0,0 +1,31 @@ +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 + 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 diff --git a/fury/utils.py b/fury/utils.py index cb5d0671f..e524f7299 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 along an axis. + + Parameters + ---------- + data: ndarray + 2D array + axis: int, optional + 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 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]