diff --git a/package-lock.json b/package-lock.json index 7c4eb794..6f022f24 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "react-volume-viewer", - "version": "1.1.0", + "version": "1.1.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "react-volume-viewer", - "version": "1.1.0", + "version": "1.1.3", "license": "MIT", "dependencies": { "@reach/listbox": "^0.16.2", @@ -10229,6 +10229,14 @@ "url": "https://opencollective.com/immer" } }, + "node_modules/immutable": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/immutable/-/immutable-4.1.0.tgz", + "integrity": "sha512-oNkuqVTA8jqG1Q6c+UglTOD1xhC1BtjKI7XkCXRkZHrN5m18/XsnUp8Q89GkQO/z+0WjonSvl0FLhDYftp46nQ==", + "dev": true, + "optional": true, + "peer": true + }, "node_modules/import-cwd": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/import-cwd/-/import-cwd-3.0.0.tgz", @@ -17371,6 +17379,25 @@ "integrity": "sha512-ZRwKbh/eQ6w9vmTjkuG0Ioi3HBwPFce0O+v//ve+aOq1oeCy7jMV2qzzAlpsNuqpqCBjjriM1lbtZbF/Q8jVyA==", "dev": true }, + "node_modules/sass": { + "version": "1.53.0", + "resolved": "https://registry.npmjs.org/sass/-/sass-1.53.0.tgz", + "integrity": "sha512-zb/oMirbKhUgRQ0/GFz8TSAwRq2IlR29vOUJZOx0l8sV+CkHUfHa4u5nqrG+1VceZp7Jfj59SVW9ogdhTvJDcQ==", + "dev": true, + "optional": true, + "peer": true, + "dependencies": { + "chokidar": ">=3.0.0 <4.0.0", + "immutable": "^4.0.0", + "source-map-js": ">=0.6.2 <2.0.0" + }, + "bin": { + "sass": "sass.js" + }, + "engines": { + "node": ">=12.0.0" + } + }, "node_modules/sass-loader": { "version": "12.6.0", "resolved": "https://registry.npmjs.org/sass-loader/-/sass-loader-12.6.0.tgz", @@ -27794,6 +27821,14 @@ "integrity": "sha512-2eB/sswms9AEUSkOm4SbV5Y7Vmt/bKRwByd52jfLkW4OLYeaTP3EEiJ9agqU0O/tq6Dk62Zfj+TJSqfm1rLVGQ==", "dev": true }, + "immutable": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/immutable/-/immutable-4.1.0.tgz", + "integrity": "sha512-oNkuqVTA8jqG1Q6c+UglTOD1xhC1BtjKI7XkCXRkZHrN5m18/XsnUp8Q89GkQO/z+0WjonSvl0FLhDYftp46nQ==", + "dev": true, + "optional": true, + "peer": true + }, "import-cwd": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/import-cwd/-/import-cwd-3.0.0.tgz", @@ -32983,6 +33018,19 @@ "integrity": "sha512-ZRwKbh/eQ6w9vmTjkuG0Ioi3HBwPFce0O+v//ve+aOq1oeCy7jMV2qzzAlpsNuqpqCBjjriM1lbtZbF/Q8jVyA==", "dev": true }, + "sass": { + "version": "1.53.0", + "resolved": "https://registry.npmjs.org/sass/-/sass-1.53.0.tgz", + "integrity": "sha512-zb/oMirbKhUgRQ0/GFz8TSAwRq2IlR29vOUJZOx0l8sV+CkHUfHa4u5nqrG+1VceZp7Jfj59SVW9ogdhTvJDcQ==", + "dev": true, + "optional": true, + "peer": true, + "requires": { + "chokidar": ">=3.0.0 <4.0.0", + "immutable": "^4.0.0", + "source-map-js": ">=0.6.2 <2.0.0" + } + }, "sass-loader": { "version": "12.6.0", "resolved": "https://registry.npmjs.org/sass-loader/-/sass-loader-12.6.0.tgz", diff --git a/package.json b/package.json index e2459cb4..85da40f0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-volume-viewer", - "version": "1.1.2", + "version": "1.1.3", "description": "Aframe container with custom controls for use in react applications", "author": "brown-ccv", "license": "MIT", @@ -78,4 +78,4 @@ "/node_modules/(?!d3|d3-array|@reach/listbox|@reach/tabs/styles.css|rc-slider|internmap|delaunator|robust-predicates)" ] } -} +} \ No newline at end of file diff --git a/src/aframe/fragment-shader.frag b/src/aframe/fragment-shader.frag index 55ab4362..5f2468b3 100644 --- a/src/aframe/fragment-shader.frag +++ b/src/aframe/fragment-shader.frag @@ -1,18 +1,18 @@ -# version 300 es +#version 300 es precision mediump float; precision highp sampler2D; #define MAX_MODELS 4 -struct ModelStruct { +struct ModelStruct{ bool use; float intensity; sampler2D model_texture; sampler2D transfer_texture; }; -in vec3 vUV; // Coordinates of the texture -in vec3 camPos; // Coordinates of the camera -out vec4 fragColor; // Final output color +in vec3 vUV;// Coordinates of the texture +in vec3 camPos;// Coordinates of the camera +out vec4 fragColor;// Final output color uniform bool apply_vr_clip; uniform int blending; @@ -25,11 +25,11 @@ uniform float step_size; uniform mat4 vr_clip_matrix; /** - Shader code for the VR Volume Viewer - t_: Translation vector - p_: Position vector - m_: Data for an individual model - v_: Data for the entire volume +Shader code for the VR Volume Viewer +t_: Translation vector +p_: Position vector +m_: Data for an individual model +v_: Data for the entire volume */ // Clip the volume between clip_min and clip_max @@ -53,10 +53,10 @@ vec4 sample_model(ModelStruct model, vec2 start_position, vec2 end_position, flo ); model_sample.a = max(model_sample.r, max(model_sample.g, model_sample.b)); if(model_sample.a < 0.25) model_sample.a *= 0.1; - + // Sample transfer texture return texture( - model.transfer_texture, + model.transfer_texture, vec2(clamp(model_sample.a, 0.0, 1.0), 0.5) ); } @@ -64,31 +64,31 @@ vec4 sample_model(ModelStruct model, vec2 start_position, vec2 end_position, flo void main() { // Get the 3D texture coordinates for lookup into the volume dataset vec3 data_position = vUV; - + // Direction the ray is marching in vec3 ray_direction = normalize(data_position - camPos); - + // Get the t values for the intersection with the clipping values vec2 t_hit = intersectBox(camPos, ray_direction, clip_min, clip_max); float t_start = t_hit.x; float t_end = t_hit.y; - + /* - We dont want to sample voxels behind the eye if its inside the volume, - so keep the starting point at or in front of the eye + We dont want to sample voxels behind the eye if its inside the volume, + so keep the starting point at or in front of the eye */ t_start = max(t_start, 0.0); - + /* - We don't know if the ray was cast from the back or the front face. To ensure we - update data_position and t_hit to reflect a ray from entry point to exit - We're shifting the clipping box to [0.0, end - start] - (Note: We only render the back face) + We don't know if the ray was cast from the back or the front face. To ensure we + update data_position and t_hit to reflect a ray from entry point to exit + We're shifting the clipping box to [0.0, end - start] + (Note: We only render the back face) */ data_position = camPos + t_start * ray_direction; t_end = t_end - t_start; t_start = 0.0; - + // Get t for the clipping plane and overwrite the entry point // This only occurs when grabbing volume in a VR headset if(apply_vr_clip) { @@ -99,81 +99,74 @@ void main() { vec4 c_pos = vr_clip_matrix * vec4(data_position, 1); vec4 c_dir = vr_clip_matrix * vec4(ray_direction, 0); float t_clip = -c_pos.y / c_dir.y; - + // Update either entry or exit based on which is on the clipped side - if (p_in.y > 0.0) t_start = t_clip; - else t_end = t_clip; + if (p_in.y > 0.0) t_start = t_clip; + else t_end = t_clip; } else { /* - Both points lie on the same side of the plane, if one of them is - on the wrong side they can be clipped + Both points lie on the same side of the plane, if one of them is + on the wrong side they can be clipped */ - if(p_in.y > 0.0) discard; + if(p_in.y>0.)discard; } } - data_position = data_position + t_start * ray_direction; - + data_position=data_position+t_start*ray_direction; + // Starting from the entry point, march the ray through the volume and sample it - vec4 vFragColor = vec4(0); - vec4 v_sample; - float intensity = 0.0; - for(float t = t_start; t < t_end; t += step_size) { + vec4 vFragColor=vec4(0); + vec4 v_sample=vec4(0); + float intensity=0.; + float mix_factor=.5; + for(float t=t_start;t= 0.95) break; - + if(vFragColor.a>=.95)break; + // Advance point - data_position += ray_direction * step_size; + data_position+=ray_direction*step_size; } - fragColor = vFragColor; -} \ No newline at end of file + fragColor=vFragColor; +}