diff --git a/cortex/tests/test_webgl_shaders.py b/cortex/tests/test_webgl_shaders.py index 6a676d1ae..c54f38adc 100644 --- a/cortex/tests/test_webgl_shaders.py +++ b/cortex/tests/test_webgl_shaders.py @@ -126,7 +126,7 @@ # says the subject has a white matter surface; the rest come from the dataview # and from the surface menu. SURFACE_OPTS = dict(morphs=3, volume=1, layers=1, rois=True, extratex=False, - halo=False, dither=False, voxline=False, sampler="nearest") + dither=False, voxline=False, sampler="nearest") def _surface_variants() -> Iterator[Any]: diff --git a/cortex/webgl/resources/js/axes3d.js b/cortex/webgl/resources/js/axes3d.js index e78684723..5115f1182 100644 --- a/cortex/webgl/resources/js/axes3d.js +++ b/cortex/webgl/resources/js/axes3d.js @@ -308,8 +308,6 @@ var jsplot = (function (module) { scene = new THREE.Scene(); scene.add(this.camera); scene.add(this.root); - // scene.fsquad = new THREE.Mesh(new THREE.PlaneGeometry(100, 100), null); - // scene.fsquad.position.z = -1.0001; this.views.push({left:left, bottom:bottom, width:width, height:height, scene:scene}); } } diff --git a/cortex/webgl/resources/js/mriview_surface.js b/cortex/webgl/resources/js/mriview_surface.js index ffb86e85d..4414f5a0a 100644 --- a/cortex/webgl/resources/js/mriview_surface.js +++ b/cortex/webgl/resources/js/mriview_surface.js @@ -99,9 +99,6 @@ var mriview = (function(module) { smoothness: { type:'f', value:parseFloat(viewopts.smoothness)}, contrast: { type:'f', value:parseFloat(viewopts.contrast)}, extratex: { type:'t', value:null}, - - // screen: { type:'t', value:this.volumebuf}, - // screen_size:{ type:'v2', value:new THREE.Vector2(100, 100)}, } ]); @@ -346,14 +343,6 @@ var mriview = (function(module) { }; THREE.EventDispatcher.prototype.apply(module.Surface.prototype); module.Surface.prototype.resize = function(evt) { - // this.volumebuf = new THREE.WebGLRenderTarget(width, height, { - // minFilter: THREE.LinearFilter, - // magFilter: THREE.LinearFilter, - // format:THREE.RGBAFormat, - // stencilBuffer:false, - // }); - // this.uniforms.screen.value = this.volumebuf; - // this.uniforms.screen_size.value.set(width, height); this.width = evt.width; this.height = evt.height; this.loaded.done(function() { @@ -366,37 +355,6 @@ var mriview = (function(module) { this._active = dataview; this.loaded.done(function() { - var shaders = []; - // Halo rendering code, ignore for now - // if (this.sheets.length > 1) { //setup meshes for halo rendering - // for (var i = 0; i < this.sheets.length; i++) { - // var shaders = dataview.getShader(Shaders.surface, this.uniforms, { - // morphs:this.names.length, volume:1, rois: false, halo: true }); - // for (var j = 0; j < shaders.length; j++) { - // shaders[j].transparent = i != 0; - // shaders[j].depthTest = true; - // shaders[j].depthWrite = i == 0; - // shaders[j].uniforms.thickmix = {type:'f', value: 1 - i / (this.sheets.length-1)}; - // shaders[j].blending = THREE.CustomBlending; - // shaders[j].blendSrc = THREE.OneFactor; - // shaders[j].blendDst = THREE.OneFactor; - // } - // this.preshaders.push(shaders); - // } - // var shaders = dataview.getShader(Shaders.surface, this.uniforms, { - // morphs:this.names.length, volume:1, rois:false, halo:false }); - // for (var j = 0; j < shaders.length; j++) { - // shaders[j].uniforms.thickmix = {type:'f', value:1}; - // shaders[j].uniforms.dataAlpha = {type:'f', value:0}; - // } - - // this.quadshade = dataview.getShader(Shaders.cmap_quad, this.uniforms); - // this.quadshade.transparent = true; - // this.quadshade.blending = THREE.CustomBlending - // this.quadshade.blendSrc = THREE.OneFactor - // this.quadshade.blendDst = THREE.OneMinusSrcAlphaFactor - // this.quadshade.depthWrite = false; - // } else { if (dataview.vertex) { var shade_cls = Shaders.surface_vertex; } else { @@ -409,7 +367,6 @@ var mriview = (function(module) { layers: this._layers, rois: this.svg instanceof svgoverlay.SVGOverlay, extratex: this.uniforms.extratex.value !== null, - halo: false, dither: this._dither, nanmean: this._nanmean, equivolume: this._equivolume, @@ -442,30 +399,6 @@ var mriview = (function(module) { } } - // var oldcolor, black = new THREE.Color(0,0,0); - // module.Surface.prototype._prerender_halosurf = function(evt) { - // var idx = evt.idx, renderer = evt.renderer, scene = evt.scene, camera = evt.camera; - // camera.add(scene.fsquad); - // scene.fsquad.material = this.quadshade[idx]; - // scene.fsquad.visible = false; - // for (var i = 0; i < this.sheets.length; i++) { - // this.sheets[i].left.material = this.preshaders[i][idx]; - // this.sheets[i].right.material = this.preshaders[i][idx]; - // this.sheets[i].left.visible = true; - // this.sheets[i].right.visible = true; - // } - // oldcolor = renderer.getClearColor() - // renderer.setClearColor(black, 0); - // //renderer.render(scene, camera); - // renderer.render(scene, camera, this.volumebuf); - // renderer.setClearColor(oldcolor, 1); - // for (var i = 1; i < this.sheets.length; i++) { - // this.sheets[i].left.visible = false; - // this.sheets[i].right.visible = false; - // } - // scene.fsquad.visible = true; - // }; - module.Surface.prototype.apply = function(dataview) { this.loaded.done(function() { for (var i = 0; i < this.sheets.length; i++) { @@ -960,93 +893,5 @@ var mriview = (function(module) { this.surf.prerender(renderer, scene, camera); } - - module.VolumeSheets = function(dataview) { - if (dataview.vertex) - throw "Cannot show volume integration for vertex dataview" - - this.shaders = {}; - this.uniforms = THREE.UniformsUtils.merge( [ - THREE.UniformsLib[ "lights" ], - { - diffuse: { type:'v3', value:new THREE.Vector3( 0,0,0 )}, - specular: { type:'v3', value:new THREE.Vector3( 0,0,0 )}, - emissive: { type:'v3', value:new THREE.Vector3( 1,1,1 )}, - shininess: { type:'f', value:0}, - specularStrength:{ type:'f', value:0}, - dataAlpha: { type:'f', value:.1}, - }]); - - this.object = new THREE.Group(); - this.object.name = 'VolumeSheets' - this.setSheets(30); - this.update(dataview); - } - THREE.EventDispatcher.prototype.apply(module.VolumeSheets.prototype); - module.VolumeSheets.prototype.update = function(dataview) { - var shaders = dataview.getShader(Shaders.main, this.uniforms, { - viewspace:true, - depthTest:true, - depthWrite:false, - blending:THREE.AdditiveBlending, - transparent:true, - lights:false, - }); - this.shaders[dataview.uuid] = shaders[0]; - - //compute dataview extents to scale the sheets - var xfm = new THREE.Matrix4(); - xfm.set.apply(xfm, dataview.xfm); - var ixfm = (new THREE.Matrix4()).getInverse(xfm); - var zsize = dataview.data[0].mosaic; - var shape = dataview.data[0].shape; - var near = (new THREE.Vector3(0,0,0)).applyMatrix4(ixfm); - var far = (new THREE.Vector3(shape[0], shape[1], zsize[0]*zsize[1])).applyMatrix4(ixfm); - var mid = near.clone().multiplyScalar(0.5).add(far.clone().multiplyScalar(.5)); - - var scale = near.distanceTo(far); - this.object.scale.set(scale/2, scale/2, scale/2); - this.object.position.set(mid.x, mid.y, mid.z); - } - module.VolumeSheets.prototype.apply = function(dataview) { - this.mesh.material = this.shaders[dataview.uuid]; - //this.sheets.material = this.debug_shade; - } - module.VolumeSheets.prototype.setSheets = function(n) { - this.n_sheets = n; - this.uniforms.dataAlpha.value = 1 / n; - var position = new THREE.BufferAttribute(new Float32Array(4*3*n), 3); - var index = new THREE.BufferAttribute(new Uint16Array(2*3*n), 3); - var normal = new THREE.BufferAttribute(new Float32Array(4*3*n), 3); - for (var i = 0; i < n; i++) { - var z = ((2*i+1) / (2*n))*2 - 1; - position.setXYZ(i*4 , -1, -1, z); - position.setXYZ(i*4+1, 1, -1, z); - position.setXYZ(i*4+2, 1, 1, z); - position.setXYZ(i*4+3, -1, 1, z); - normal.setXYZ(i*4 , 0, 0, 1); - normal.setXYZ(i*4+1, 0, 0, 1); - normal.setXYZ(i*4+2, 0, 0, 1); - normal.setXYZ(i*4+3, 0, 0, 1); - index.setXYZ(i*2 , i*4, i*4+1, i*4+2); - index.setXYZ(i*2+1, i*4, i*4+2, i*4+3); - } - this.sheets = new THREE.BufferGeometry(); - this.sheets.addAttribute("position", position); - this.sheets.addAttribute("index", index); - this.sheets.addAttribute("normal", normal); - - this.debug_shade = new THREE.MeshBasicMaterial({color:0xffcccc, - side:THREE.DoubleSide, - transparent:true, - opacity:.1, - blending:THREE.AdditiveBlending, - depthTest:true, - depthWrite:false, - }); - this.mesh = new THREE.Mesh(this.sheets, null); - this.object.add(this.mesh); - } - return module; }(mriview || {})); diff --git a/cortex/webgl/resources/js/shaderlib.js b/cortex/webgl/resources/js/shaderlib.js index 2cf3af0ae..ce7b72b1d 100644 --- a/cortex/webgl/resources/js/shaderlib.js +++ b/cortex/webgl/resources/js/shaderlib.js @@ -82,10 +82,6 @@ var Shaderlib = (function() { "const vec4 shift = vec4(1.0, 1. / 255., 1. / 65025., 1./160581375.0);", "return dot(rgba, shift);", "}", - "float decode_float_vec2(vec2 rg) {", - "const vec2 shift = vec2(1.0, 1. / 255.);", - "return dot(rg, shift);", - "}", "vec4 pack_float( const in float depth ) {", "const vec4 bit_shift = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );", @@ -392,11 +388,6 @@ var Shaderlib = (function() { header += "#define ROI_RENDER\n"; if (opts.extratex) header += "#define EXTRATEX\n" - if (opts.halo) { - if (opts.twod) - throw "Cannot use 2D colormaps with volume integration" - header += "#define HALO_RENDER\n"; - } if (opts.hasflat) header += "#define HASFLAT\n" if (opts.equivolume) @@ -566,7 +557,6 @@ var Shaderlib = (function() { utils.rand, utils.edge, utils.colormap, - utils.pack, utils.samplers, "void main() {", @@ -717,19 +707,6 @@ var Shaderlib = (function() { "#endif", "#endif", "}", - "#ifdef HALO_RENDER", - "if (vMedial < .999) {", - "float dweight = gl_FragCoord.w;", - "float value = dweight * vnorm(values).x;", - - "gl_FragColor.rg = encode_float_vec2(value);", - "gl_FragColor.ba = encode_float_vec2(dweight);", - //"gl_FragColor = vec4(res / 256., 1. / 256.);", - //"gl_FragColor = vec4(vec3(gl_FragCoord.w), 1.);", - "} else if (surfmix > "+((morphs-2)/(morphs-1))+") {", - "gl_FragColor = vec4(0.);", - "}", - "#else", "#ifdef RGBCOLORS", "vec4 vColor = mix(color[0], color[1], framemix);", "#else", @@ -773,7 +750,6 @@ var Shaderlib = (function() { "gl_FragColor = tColor + (1.-tColor.a)*gl_FragColor;", "#endif", THREE.ShaderChunk[ "lights_phong_fragment" ], - "#endif", "}" ].join("\n"); @@ -1036,34 +1012,6 @@ var Shaderlib = (function() { return {vertex:header+vertShade, fragment:header+fragShade, attrs:attributes}; }, - cmap_quad: function() { - //Colormaps the full-screen quad, used for stage 2 of volume integration - var vertShade = [ - "void main() {", - "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );", - "}", - ].join("\n"); - var fragShade = [ - utils.pack, - "uniform vec2 screen_size;", - "uniform sampler2D screen;", - "uniform sampler2D colormap;", - "void main() {", - "vec4 data = texture2D(screen, gl_FragCoord.xy / screen_size);", - "float value = decode_float_vec2(data.rg);", - "float raw = value / decode_float_vec2(data.ba);", - //"if (value.a > 0.) {", - "gl_FragColor = texture2D(colormap, vec2(raw, 0.));", - //"} else {", - // "discard;", - //"}", - //"gl_FragColor = vec4(vec3(raw), 1.);", - //"gl_FragColor = vec4(value.rgb, 1.);", - "}", - ].join("\n"); - return {vertex:vertShade, fragment:fragShade, attrs:{}}; - }, - pick: function(opts) { var header = ""; var morphs = opts.morphs; diff --git a/cortex/webgl/resources/js/shadowtex.js b/cortex/webgl/resources/js/shadowtex.js deleted file mode 100644 index 3e06b2a55..000000000 --- a/cortex/webgl/resources/js/shadowtex.js +++ /dev/null @@ -1,170 +0,0 @@ -var vshade = [ -//"uniform vec4 color;", -"varying vec2 vUv;", -"void main(void) {", - "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );", - "vUv = uv;", -"}", -].join("\n"); - -var fshadeh = [ -"uniform sampler2D tex;", // the texture with the scene you want to blur -//"uniform vec4 color;", -"varying vec2 vUv;", - -"uniform float blur;", - -"void main(void) {", - -" vec4 sum = vec4(0.0);", - // blur in y (vertical) - // take nine samples, with the distance blur between them -" sum += texture2D(tex, vec2(vUv.x - 4.0*blur, vUv.y)) * 0.05;", -" sum += texture2D(tex, vec2(vUv.x - 3.0*blur, vUv.y)) * 0.09;", -" sum += texture2D(tex, vec2(vUv.x - 2.0*blur, vUv.y)) * 0.12;", -" sum += texture2D(tex, vec2(vUv.x - blur, vUv.y)) * 0.15;", -" sum += texture2D(tex, vec2(vUv.x, vUv.y)) * 0.16;", -" sum += texture2D(tex, vec2(vUv.x + blur, vUv.y)) * 0.15;", -" sum += texture2D(tex, vec2(vUv.x + 2.0*blur, vUv.y)) * 0.12;", -" sum += texture2D(tex, vec2(vUv.x + 3.0*blur, vUv.y)) * 0.09;", -" sum += texture2D(tex, vec2(vUv.x + 4.0*blur, vUv.y)) * 0.05;", - -" gl_FragColor = sum;", -//" gl_FragColor = vec4(vUv.x, vUv.y, 0., 1.);", -"}", -].join("\n"); - -var fshadev = [ -"uniform sampler2D tex;", // this should hold the texture rendered by the horizontal blur pass -//"uniform vec4 color;", -"varying vec2 vUv;", - -"uniform float blur;", - -"void main(void) {", - "vec4 sum = vec4(0.0);", - - // blur in y (vertical) - // take nine samples, with the distance blur between them - "sum += texture2D(tex, vec2(vUv.x, vUv.y - 4.0*blur)) * 0.05;", - "sum += texture2D(tex, vec2(vUv.x, vUv.y - 3.0*blur)) * 0.09;", - "sum += texture2D(tex, vec2(vUv.x, vUv.y - 2.0*blur)) * 0.12;", - "sum += texture2D(tex, vec2(vUv.x, vUv.y - blur)) * 0.15;", - "sum += texture2D(tex, vec2(vUv.x, vUv.y)) * 0.16;", - "sum += texture2D(tex, vec2(vUv.x, vUv.y + blur)) * 0.15;", - "sum += texture2D(tex, vec2(vUv.x, vUv.y + 2.0*blur)) * 0.12;", - "sum += texture2D(tex, vec2(vUv.x, vUv.y + 3.0*blur)) * 0.09;", - "sum += texture2D(tex, vec2(vUv.x, vUv.y + 4.0*blur)) * 0.05;", - - "gl_FragColor = sum;", -"}", -].join("\n"); - -var composite = [ -"uniform sampler2D over;", -"uniform sampler2D under;", -"varying vec2 vUv;", - -"void main(void) {", - "vec4 o = texture2D(over, vUv);", - "vec4 u = texture2D(under, vUv);", - "gl_FragColor.rgb = o.rgb + u.rgb*(1.-o.a);", - "gl_FragColor.a = o.a + u.a*(1.-o.a);", -"}", -].join("\n"); - -function ShadowTex(width, height, radius) { - this.width = width; - this.height = height; - - this.htex = new THREE.WebGLRenderTarget(width, height, { - minFilter: THREE.LinearFilter, - magFilter: THREE.LinearFilter, - format:THREE.RGBAFormat, - stencilBuffer:false, - }); - this.vtex = new THREE.WebGLRenderTarget(width, height, { - minFilter: THREE.LinearFilter, - magFilter: THREE.LinearFilter, - format:THREE.RGBAFormat, - stencilBuffer:false, - }); - this.hpass = new THREE.ShaderMaterial({ - vertexShader:vshade, - fragmentShader:fshadeh, - transparent:true, - blending: THREE.CustomBlending, - uniforms: { - tex:{type:'t', value:0, texture:null}, - blur:{type:'f', value:radius / width} - } - }) - this.hpass.blendSrc = THREE.OneFactor; - this.vpass = new THREE.ShaderMaterial({ - vertexShader:vshade, - fragmentShader:fshadev, - transparent:true, - blending: THREE.CustomBlending, - uniforms: { - tex: {type:'t', value:0, texture:this.htex}, - blur:{type:'f', value:radius / height} - } - }) - this.vpass.blendSrc = THREE.OneFactor; - - this.opass = new THREE.ShaderMaterial({ - vertexShader:vshade, - fragmentShader:composite, - transparent:true, - blending: THREE.CustomBlending, - uniforms: { - over: {type:'t', value:0, texture:null}, - under: {type:'t', value:1, texture:null} - } - }); - this.opass.blendSrc = THREE.OneFactor; - - this.fsquad = new THREE.Mesh(new THREE.PlaneGeometry(width, height), this.hpass); - this.fsquad.rotation.x = Math.PI / 2; - this.camera = new THREE.OrthographicCamera( width / - 2, width / 2, height / 2, height / - 2, -10000, 10000 ); - this.scene = new THREE.Scene(); - this.scene.add(this.camera); - this.scene.add(this.fsquad); -} -ShadowTex.prototype = { - setRadius: function(radius) { - this.vpass.uniforms.blur.value = radius / this.height; - this.hpass.uniforms.blur.value = radius / this.width; - }, - blur: function(renderer, shadow) { - var clearAlpha = renderer.getClearAlpha(); - var clearColor = renderer.getClearColor(); - renderer.setClearColorHex(0x0, 0); - this.hpass.uniforms.tex.texture = this._setTex(shadow); - this.fsquad.material = this.hpass; - renderer.render(this.scene, this.camera, this.htex); - this.vpass.uniforms.tex.texture = this.htex; - this.fsquad.material = this.vpass; - renderer.render(this.scene, this.camera, this.vtex); - renderer.setClearColor(clearColor, clearAlpha); - return this.vtex; - }, - overlay: function(renderer, over) { - var clearAlpha = renderer.getClearAlpha(); - var clearColor = renderer.getClearColor(); - renderer.setClearColorHex(0x0, 0); - this.opass.uniforms.over.texture = this._setTex(over); - this.opass.uniforms.under.texture = this.vtex; - this.fsquad.material = this.opass; - renderer.render(this.scene, this.camera, this.htex); - renderer.setClearColor(clearColor, clearAlpha); - return this.htex; - }, - _setTex: function(tex) { - tex.needsUpdate = true; - tex.premultiplyAlpha = true; - tex.minFilter = THREE.LinearFilter; - tex.magFilter = THREE.LinearFilter; - return tex; - } -}; \ No newline at end of file diff --git a/cortex/webgl/simple.html b/cortex/webgl/simple.html index 41d811d7e..7fbc11e31 100644 --- a/cortex/webgl/simple.html +++ b/cortex/webgl/simple.html @@ -33,7 +33,6 @@ -