<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=0" />
<title>WebGL Volume Viewer</title>
<script type="text/javascript" src="sharevol.js"></script>
<script type="text/javascript" src="/src/comp/Slicer.js"></script>
<script type="text/javascript" src="/src/comp/SliceView.js"></script>
<script type="text/javascript" src="/src/comp/Volume.js"></script>
<script type="text/javascript" src="/src/comp/GradientEditor.js"></script>
<script type="text/javascript" src="/src/comp/MoveWindow.js"></script>
<script type="text/javascript" src="/src/comp/Colour.js"></script>
<script type="text/javascript" src="/src/comp/ColourPicker.js"></script>
<script type="text/javascript" src="/src/comp/Popup.js"></script>
<script type="text/javascript" src="/src/comp/Palette.js"></script>
<script type="text/javascript" src="/src/comp/ViewMatrix.js"></script>
<script type="text/javascript" src="/src/comp/WebGL.js"></script>
<script type="text/javascript" src="/src/comp/WebGLProgram.js"></script>
<script id="volume-vs" type="x-shader/x-vertex">
precision highp float;
//Volume vertex shader
precision highp float;
attribute vec3 aVertexPosition;
void main(void)
{
gl_Position = vec4(aVertexPosition, 1.0);
}
</script>
<script id="volume-fs" type="x-shader/x-fragment">
precision highp float;
//Volume fragment shader
/*
* Copyright (c) 2014, Monash University. All rights reserved.
* Author: Owen Kaluza - owen.kaluza ( at ) monash.edu
*
* Licensed under the GNU Lesser General Public License
* https://www.gnu.org/licenses/lgpl.html
*/
precision highp float;
//Defined dynamically before compile...
//const vec2 slices = vec2(16.0,16.0);
//const int maxSamples = 256;
uniform sampler2D uVolume;
uniform sampler2D uTransferFunction;
uniform vec3 uBBMin;
uniform vec3 uBBMax;
uniform vec3 uResolution;
uniform bool uEnableColour;
uniform float uBrightness;
uniform float uContrast;
uniform float uSaturation;
uniform float uPower;
uniform mat4 uPMatrix;
uniform mat4 uInvPMatrix;
uniform mat4 uMVMatrix;
uniform mat4 uNMatrix;
uniform vec4 uViewport;
uniform int uSamples;
uniform float uDensityFactor;
uniform float uIsoValue;
uniform vec4 uIsoColour;
uniform float uIsoSmooth;
uniform int uIsoWalls;
uniform int uFilter;
uniform vec2 uRange;
uniform vec2 uDenMinMax;
//#define tex3D(pos) interpolate_tricubic_fast(pos)
//#define tex3D(pos) texture3Dfrom2D(pos).x
vec2 islices = vec2(1.0 / slices.x, 1.0 / slices.y);
vec4 texture3Dfrom2D(vec3 pos)
{
//Get z slice index and position between two slices
float Z = pos.z * slices.x * slices.y;
int slice = int(Z); //Index of first slice
//X & Y coords of sample scaled to slice size
vec2 sampleOffset = pos.xy * islices;
//Offsets in 2D texture of given slice indices
//(add offsets to scaled position within slice to get sample positions)
float A = float(slice) * islices.x;
float B = float(slice+1) * islices.x;
vec2 z1offset = vec2(fract(A), floor(A) / slices.y) + sampleOffset;
vec2 z2offset = vec2(fract(B), floor(B) / slices.y) + sampleOffset;
//Interpolate the final value by position between slices [0,1]
return mix(texture2D(uVolume, z1offset), texture2D(uVolume, z2offset), fract(Z));
}
float interpolate_tricubic_fast(vec3 coord);
float tex3D(vec3 pos)
{
if (uFilter > 0)
return interpolate_tricubic_fast(pos);
return texture3Dfrom2D(pos).x;
}
// It seems WebGL has no transpose
mat4 transpose(in mat4 m)
{
return mat4(
vec4(m[0].x, m[1].x, m[2].x, m[3].x),
vec4(m[0].y, m[1].y, m[2].y, m[3].y),
vec4(m[0].z, m[1].z, m[2].z, m[3].z),
vec4(m[0].w, m[1].w, m[2].w, m[3].w)
);
}
//Light moves with camera
const vec3 lightPos = vec3(0.5, 0.5, 5.0);
const float ambient = 0.2;
const float diffuse = 0.8;
const vec3 diffColour = vec3(1.0, 1.0, 1.0); //Colour of diffuse light
const vec3 ambColour = vec3(0.2, 0.2, 0.2); //Colour of ambient light
void lighting(in vec3 pos, in vec3 normal, inout vec3 colour)
{
vec4 vertPos = uMVMatrix * vec4(pos, 1.0);
vec3 lightDir = normalize(lightPos - vertPos.xyz);
vec3 lightWeighting = ambColour + diffColour * diffuse * clamp(abs(dot(normal, lightDir)), 0.1, 1.0);
colour *= lightWeighting;
}
vec3 isoNormal(in vec3 pos, in vec3 shift, in float density)
{
vec3 shiftpos = vec3(pos.x + shift.x, pos.y + shift.y, pos.z + shift.z);
vec3 shiftx = vec3(shiftpos.x, pos.y, pos.z);
vec3 shifty = vec3(pos.x, shiftpos.y, pos.z);
vec3 shiftz = vec3(pos.x, pos.y, shiftpos.z);
//Detect bounding box hit (walls)
if (uIsoWalls > 0)
{
if (pos.x <= uBBMin.x) return vec3(-1.0, 0.0, 0.0);
if (pos.x >= uBBMax.x) return vec3(1.0, 0.0, 0.0);
if (pos.y <= uBBMin.y) return vec3(0.0, -1.0, 0.0);
if (pos.y >= uBBMax.y) return vec3(0.0, 1.0, 0.0);
if (pos.z <= uBBMin.z) return vec3(0.0, 0.0, -1.0);
if (pos.z >= uBBMax.z) return vec3(0.0, 0.0, 1.0);
}
//Calculate normal
return vec3(density) - vec3(tex3D(shiftx), tex3D(shifty), tex3D(shiftz));
}
vec2 rayIntersectBox(vec3 rayDirection, vec3 rayOrigin)
{
//Intersect ray with bounding box
vec3 rayInvDirection = 1.0 / rayDirection;
vec3 bbMinDiff = (uBBMin - rayOrigin) * rayInvDirection;
vec3 bbMaxDiff = (uBBMax - rayOrigin) * rayInvDirection;
vec3 imax = max(bbMaxDiff, bbMinDiff);
vec3 imin = min(bbMaxDiff, bbMinDiff);
float back = min(imax.x, min(imax.y, imax.z));
float front = max(max(imin.x, 0.0), max(imin.y, imin.z));
return vec2(back, front);
}
void main()
{
//Compute eye space coord from window space to get the ray direction
mat4 invMVMatrix = transpose(uMVMatrix);
//ObjectSpace *[MV] = EyeSpace *[P] = Clip /w = Normalised device coords ->VP-> Window
//Window ->[VP^]-> NDC ->[/w]-> Clip ->[P^]-> EyeSpace ->[MV^]-> ObjectSpace
vec4 ndcPos;
ndcPos.xy = ((2.0 * gl_FragCoord.xy) - (2.0 * uViewport.xy)) / (uViewport.zw) - 1.0;
ndcPos.z = (2.0 * gl_FragCoord.z - gl_DepthRange.near - gl_DepthRange.far) /
(gl_DepthRange.far - gl_DepthRange.near);
ndcPos.w = 1.0;
vec4 clipPos = ndcPos / gl_FragCoord.w;
//vec4 eyeSpacePos = uInvPMatrix * clipPos;
vec3 rayDirection = normalize((invMVMatrix * uInvPMatrix * clipPos).xyz);
//Ray origin from the camera position
vec4 camPos = -vec4(uMVMatrix[3]); //4th column of modelview
vec3 rayOrigin = (invMVMatrix * camPos).xyz;
//Calc step
float stepSize = 1.732 / float(uSamples); //diagonal of [0,1] normalised coord cube = sqrt(3)
//Intersect ray with bounding box
vec2 intersection = rayIntersectBox(rayDirection, rayOrigin);
//Subtract small increment to avoid errors on front boundary
intersection.y -= 0.000001;
//Discard points outside the box (no intersection)
if (intersection.x <= intersection.y) discard;
vec3 rayStart = rayOrigin + rayDirection * intersection.y;
vec3 rayStop = rayOrigin + rayDirection * intersection.x;
vec3 step = normalize(rayStop-rayStart) * stepSize;
vec3 pos = rayStart;
float T = 1.0;
vec3 colour = vec3(0.0);
bool inside = false;
vec3 shift = uIsoSmooth / uResolution;
//Number of samples to take along this ray before we pass out back of volume...
float travel = distance(rayStop, rayStart) / stepSize;
int samples = int(ceil(travel));
float range = uRange.y - uRange.x;
if (range <= 0.0) range = 1.0;
//Scale isoValue
float isoValue = uRange.x + uIsoValue * range;
//Raymarch, front to back
for (int i=0; i < maxSamples; ++i)
{
//Render samples until we pass out back of cube or fully opaque
#ifndef IE11
if (i == samples || T < 0.01) break;
#else
//This is slower but allows IE 11 to render, break on non-uniform condition causes it to fail
if (i == uSamples) break;
if (all(greaterThanEqual(pos, uBBMin)) && all(lessThanEqual(pos, uBBMax)))
#endi
没有合适的资源?快使用搜索试试~ 我知道了~
H5版的MR模型展示sharevol-master
共43个文件
js:19个
xml:3个
vs:3个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 136 浏览量
2023-08-14
20:35:10
上传
评论
收藏 2.09MB RAR 举报
温馨提示
H5版的MR模型展示sharevol-master
资源推荐
资源详情
资源评论
收起资源包目录
H5版的MR模型展示sharevol-master.rar (43个子文件)
sharevol-master
lib
OK.js 62KB
dat.gui.js 98KB
gl-matrix.js 103KB
default.json 3KB
Makefile 1KB
src
comp
ViewMatrix.js 1KB
Popup.js 726B
WebGL.js 5KB
WebGLProgram.js 3KB
SliceView.js 2KB
ColourPicker.js 11KB
Volume.js 27KB
MoveWindow.js 2KB
Slicer.js 11KB
GradientEditor.js 7KB
Palette.js 9KB
Colour.js 8KB
utils
arguments.js 101KB
shaders
volumeShaderWEBGL.vert 120B
textureShaderWEBGL.vert 429B
lineShaderWEBGL.frag 93B
volumeShaderWEBGL.frag 13KB
lineShaderWEBGL.vert 502B
textureShaderWEBGL.frag 2KB
LICENSE 7KB
shader
texture.vs 513B
texture.fs 2KB
line.vs 617B
volume.fs 15KB
volume.vs 186B
line.fs 163B
.idea
workspace.xml 6KB
misc.xml 174B
inspectionProfiles
modules.xml 282B
sharevol-master.iml 458B
package-lock.json 27B
index.html 21KB
.gitignore 10B
data.jpg 1.89MB
sharevol.js 232KB
index.css 1KB
sharevol11.js 321KB
Helper.js 239B
共 43 条
- 1
资源评论
Bricke
- 粉丝: 441
- 资源: 371
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功