Skip to content
Snippets Groups Projects
Unverified Commit d9b2b99c authored by David Sehnal's avatar David Sehnal Committed by GitHub
Browse files

Merge pull request #531 from molstar/safari-wboit

add missing depth renderbuffer to wboit pass
parents e474e9b0 bdf23a7c
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,8 @@ Note that since we don't clearly distinguish between a public and private interf ...@@ -6,6 +6,8 @@ Note that since we don't clearly distinguish between a public and private interf
## [Unreleased] ## [Unreleased]
- Fix wboit in Safari >=15 (add missing depth renderbuffer to wboit pass)
## [v3.14.0] - 2022-08-20 ## [v3.14.0] - 2022-08-20
- Expose inter-bonds compute params in structure - Expose inter-bonds compute params in structure
......
...@@ -18,6 +18,8 @@ import { evaluateWboit_frag } from '../../mol-gl/shader/evaluate-wboit.frag'; ...@@ -18,6 +18,8 @@ import { evaluateWboit_frag } from '../../mol-gl/shader/evaluate-wboit.frag';
import { Framebuffer } from '../../mol-gl/webgl/framebuffer'; import { Framebuffer } from '../../mol-gl/webgl/framebuffer';
import { Vec2 } from '../../mol-math/linear-algebra'; import { Vec2 } from '../../mol-math/linear-algebra';
import { isDebugMode, isTimingMode } from '../../mol-util/debug'; import { isDebugMode, isTimingMode } from '../../mol-util/debug';
import { isWebGL2 } from '../../mol-gl/webgl/compat';
import { Renderbuffer } from '../../mol-gl/webgl/renderbuffer';
const EvaluateWboitSchema = { const EvaluateWboitSchema = {
...QuadSchema, ...QuadSchema,
...@@ -50,6 +52,7 @@ export class WboitPass { ...@@ -50,6 +52,7 @@ export class WboitPass {
private readonly framebuffer: Framebuffer; private readonly framebuffer: Framebuffer;
private readonly textureA: Texture; private readonly textureA: Texture;
private readonly textureB: Texture; private readonly textureB: Texture;
private readonly depthRenderbuffer: Renderbuffer;
private _supported = false; private _supported = false;
get supported() { get supported() {
...@@ -87,6 +90,7 @@ export class WboitPass { ...@@ -87,6 +90,7 @@ export class WboitPass {
if (width !== w || height !== h) { if (width !== w || height !== h) {
this.textureA.define(width, height); this.textureA.define(width, height);
this.textureB.define(width, height); this.textureB.define(width, height);
this.depthRenderbuffer.setSize(width, height);
ValueCell.update(this.renderable.values.uTexSize, Vec2.set(this.renderable.values.uTexSize.ref.value, width, height)); ValueCell.update(this.renderable.values.uTexSize, Vec2.set(this.renderable.values.uTexSize.ref.value, width, height));
} }
} }
...@@ -106,6 +110,8 @@ export class WboitPass { ...@@ -106,6 +110,8 @@ export class WboitPass {
this.textureA.attachFramebuffer(this.framebuffer, 'color0'); this.textureA.attachFramebuffer(this.framebuffer, 'color0');
this.textureB.attachFramebuffer(this.framebuffer, 'color1'); this.textureB.attachFramebuffer(this.framebuffer, 'color1');
this.depthRenderbuffer.attachFramebuffer(this.framebuffer);
} }
static isSupported(webgl: WebGLContext) { static isSupported(webgl: WebGLContext) {
...@@ -128,7 +134,7 @@ export class WboitPass { ...@@ -128,7 +134,7 @@ export class WboitPass {
constructor(private webgl: WebGLContext, width: number, height: number) { constructor(private webgl: WebGLContext, width: number, height: number) {
if (!WboitPass.isSupported(webgl)) return; if (!WboitPass.isSupported(webgl)) return;
const { resources } = webgl; const { resources, gl } = webgl;
this.textureA = resources.texture('image-float32', 'rgba', 'float', 'nearest'); this.textureA = resources.texture('image-float32', 'rgba', 'float', 'nearest');
this.textureA.define(width, height); this.textureA.define(width, height);
...@@ -136,6 +142,10 @@ export class WboitPass { ...@@ -136,6 +142,10 @@ export class WboitPass {
this.textureB = resources.texture('image-float32', 'rgba', 'float', 'nearest'); this.textureB = resources.texture('image-float32', 'rgba', 'float', 'nearest');
this.textureB.define(width, height); this.textureB.define(width, height);
this.depthRenderbuffer = isWebGL2(gl)
? resources.renderbuffer('depth32f', 'depth', width, height)
: resources.renderbuffer('depth16', 'depth', width, height);
this.renderable = getEvaluateWboitRenderable(webgl, this.textureA, this.textureB); this.renderable = getEvaluateWboitRenderable(webgl, this.textureA, this.textureB);
this.framebuffer = resources.framebuffer(); this.framebuffer = resources.framebuffer();
......
...@@ -109,14 +109,14 @@ void main() { ...@@ -109,14 +109,14 @@ void main() {
vec3 vViewPosition = vModelPosition + intersection.x * rayDir; vec3 vViewPosition = vModelPosition + intersection.x * rayDir;
vViewPosition = (uView * vec4(vViewPosition, 1.0)).xyz; vViewPosition = (uView * vec4(vViewPosition, 1.0)).xyz;
gl_FragDepthEXT = calcDepth(vViewPosition); float fragmentDepth = calcDepth(vViewPosition);
vec3 vModelPosition = (uInvView * vec4(vViewPosition, 1.0)).xyz; if (fragmentDepth < 0.0) discard;
if (fragmentDepth > 1.0) discard;
if (gl_FragDepthEXT < 0.0) discard; gl_FragDepthEXT = fragmentDepth;
if (gl_FragDepthEXT > 1.0) discard;
float fragmentDepth = gl_FragDepthEXT; vec3 vModelPosition = (uInvView * vec4(vViewPosition, 1.0)).xyz;
#include assign_material_color #include assign_material_color
#if defined(dRenderVariant_pick) #if defined(dRenderVariant_pick)
......
...@@ -70,17 +70,17 @@ void main(void){ ...@@ -70,17 +70,17 @@ void main(void){
} }
vec3 vViewPosition = cameraPos; vec3 vViewPosition = cameraPos;
gl_FragDepthEXT = calcDepth(vViewPosition); float fragmentDepth = calcDepth(vViewPosition);
if (!flag && gl_FragDepthEXT >= 0.0) { if (!flag && fragmentDepth >= 0.0) {
gl_FragDepthEXT = 0.0 + (0.0000001 / vRadius); fragmentDepth = 0.0 + (0.0000001 / vRadius);
} }
vec3 vModelPosition = (uInvView * vec4(vViewPosition, 1.0)).xyz; if (fragmentDepth < 0.0) discard;
if (fragmentDepth > 1.0) discard;
if (gl_FragDepthEXT < 0.0) discard; gl_FragDepthEXT = fragmentDepth;
if (gl_FragDepthEXT > 1.0) discard;
float fragmentDepth = gl_FragDepthEXT; vec3 vModelPosition = (uInvView * vec4(vViewPosition, 1.0)).xyz;
#include assign_material_color #include assign_material_color
#if defined(dRenderVariant_pick) #if defined(dRenderVariant_pick)
......
...@@ -31,7 +31,7 @@ export const PluginConfig = { ...@@ -31,7 +31,7 @@ export const PluginConfig = {
PixelScale: item('plugin-config.pixel-scale', 1), PixelScale: item('plugin-config.pixel-scale', 1),
PickScale: item('plugin-config.pick-scale', 0.25), PickScale: item('plugin-config.pick-scale', 0.25),
PickPadding: item('plugin-config.pick-padding', 3), PickPadding: item('plugin-config.pick-padding', 3),
EnableWboit: item('plugin-config.enable-wboit', PluginFeatureDetection.wboit), EnableWboit: item('plugin-config.enable-wboit', true),
// as of Oct 1 2021, WebGL 2 doesn't work on iOS 15. // as of Oct 1 2021, WebGL 2 doesn't work on iOS 15.
// TODO: check back in a few weeks to see if it was fixed // TODO: check back in a few weeks to see if it was fixed
PreferWebGl1: item('plugin-config.prefer-webgl1', PluginFeatureDetection.preferWebGl1), PreferWebGl1: item('plugin-config.prefer-webgl1', PluginFeatureDetection.preferWebGl1),
......
...@@ -29,10 +29,4 @@ export const PluginFeatureDetection = { ...@@ -29,10 +29,4 @@ export const PluginFeatureDetection = {
const isTouchScreen = navigator.maxTouchPoints >= 4; // true for iOS 13 (and hopefully beyond) const isTouchScreen = navigator.maxTouchPoints >= 4; // true for iOS 13 (and hopefully beyond)
return !(window as any).MSStream && (isIOS || (isAppleDevice && isTouchScreen)); return !(window as any).MSStream && (isIOS || (isAppleDevice && isTouchScreen));
}, },
get wboit() {
if (typeof navigator === 'undefined' || typeof window === 'undefined') return true;
// disable Wboit in Safari 15
return !/Version\/15.\d Safari/.test(navigator.userAgent);
}
}; };
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment