From b32546bea7ca7e54b6d0911e643bcc186fe2acdb Mon Sep 17 00:00:00 2001 From: Alexander Rose <alexander.rose@weirdbyte.de> Date: Sat, 11 Dec 2021 11:30:00 -0800 Subject: [PATCH] add outline color option to renderer --- CHANGELOG.md | 1 + src/apps/docking-viewer/viewport.tsx | 3 ++- src/examples/lighting/index.ts | 3 ++- src/mol-canvas3d/passes/postprocessing.ts | 5 +++++ src/mol-gl/shader/postprocessing.frag.ts | 3 ++- 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 00c383280..13eced13a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ Note that since we don't clearly distinguish between a public and private interf - Add ``bumpiness`` (per-object and per-group), ``bumpFrequency`` & ``bumpAmplitude`` (per-object) render parameters (#299) - Change ``label`` representation defaults: Use text border instead of rectangle background. +- Add outline color option to renderer ## [v3.0.0-dev.3] - 2021-12-4 diff --git a/src/apps/docking-viewer/viewport.tsx b/src/apps/docking-viewer/viewport.tsx index 082c59dd6..6be977980 100644 --- a/src/apps/docking-viewer/viewport.tsx +++ b/src/apps/docking-viewer/viewport.tsx @@ -51,7 +51,8 @@ function occlusionStyle(plugin: PluginContext) { } }, outline: { name: 'on', params: { scale: 1.0, - threshold: 0.33 + threshold: 0.33, + color: Color(0x0000), } } } } }); diff --git a/src/examples/lighting/index.ts b/src/examples/lighting/index.ts index 6bc693ccc..9537ba667 100644 --- a/src/examples/lighting/index.ts +++ b/src/examples/lighting/index.ts @@ -11,6 +11,7 @@ import { PluginUIContext } from '../../mol-plugin-ui/context'; import { DefaultPluginUISpec } from '../../mol-plugin-ui/spec'; import { PluginCommands } from '../../mol-plugin/commands'; import { Asset } from '../../mol-util/assets'; +import { Color } from '../../mol-util/color'; import './index.html'; require('mol-plugin-ui/skin/light.scss'); @@ -26,7 +27,7 @@ const Canvas3DPresets = { }, postprocessing: { occlusion: { name: 'on', params: { samples: 32, radius: 6, bias: 1.4, blurKernelSize: 15 } }, - outline: { name: 'on', params: { scale: 1, threshold: 0.1 } } + outline: { name: 'on', params: { scale: 1, threshold: 0.1, color: Color(0x000000) } } }, renderer: { style: { name: 'flat', params: {} } diff --git a/src/mol-canvas3d/passes/postprocessing.ts b/src/mol-canvas3d/passes/postprocessing.ts index 836975241..5f013e248 100644 --- a/src/mol-canvas3d/passes/postprocessing.ts +++ b/src/mol-canvas3d/passes/postprocessing.ts @@ -193,6 +193,7 @@ const PostprocessingSchema = { uFogNear: UniformSpec('f'), uFogFar: UniformSpec('f'), uFogColor: UniformSpec('v3'), + uOutlineColor: UniformSpec('v3'), uTransparentBackground: UniformSpec('b'), uMaxPossibleViewZDiff: UniformSpec('f'), @@ -220,6 +221,7 @@ function getPostprocessingRenderable(ctx: WebGLContext, colorTexture: Texture, d uFogNear: ValueCell.create(10000), uFogFar: ValueCell.create(10000), uFogColor: ValueCell.create(Vec3.create(1, 1, 1)), + uOutlineColor: ValueCell.create(Vec3.create(0, 0, 0)), uTransparentBackground: ValueCell.create(false), uMaxPossibleViewZDiff: ValueCell.create(0.5), @@ -252,6 +254,7 @@ export const PostprocessingParams = { on: PD.Group({ scale: PD.Numeric(1, { min: 1, max: 5, step: 1 }), threshold: PD.Numeric(0.33, { min: 0.01, max: 1, step: 0.01 }), + color: PD.Color(Color(0x000000)), }), off: PD.Group({}) }, { cycle: true, description: 'Draw outline around 3D objects' }), @@ -446,6 +449,8 @@ export class PostprocessingPass { ValueCell.updateIfChanged(this.outlinesRenderable.values.uFar, camera.far); ValueCell.updateIfChanged(this.outlinesRenderable.values.uMaxPossibleViewZDiff, maxPossibleViewZDiff); + ValueCell.update(this.renderable.values.uOutlineColor, Color.toVec3Normalized(this.renderable.values.uOutlineColor.ref.value, props.outline.params.color)); + ValueCell.updateIfChanged(this.renderable.values.uMaxPossibleViewZDiff, maxPossibleViewZDiff); if (this.renderable.values.dOutlineScale.ref.value !== outlineScale) { needsUpdateMain = true; } ValueCell.updateIfChanged(this.renderable.values.dOutlineScale, outlineScale); diff --git a/src/mol-gl/shader/postprocessing.frag.ts b/src/mol-gl/shader/postprocessing.frag.ts index 8bb6b78c1..9a50f4143 100644 --- a/src/mol-gl/shader/postprocessing.frag.ts +++ b/src/mol-gl/shader/postprocessing.frag.ts @@ -21,6 +21,7 @@ uniform float uFar; uniform float uFogNear; uniform float uFogFar; uniform vec3 uFogColor; +uniform vec3 uOutlineColor; uniform bool uTransparentBackground; uniform float uOcclusionBias; @@ -116,7 +117,7 @@ void main(void) { float outline = getOutline(coords, closestTexel); if (outline == 0.0) { - color.rgb *= outline; + color.rgb = mix(uOutlineColor, color.rgb, outline); viewDist = abs(getViewZ(closestTexel)); fogFactor = smoothstep(uFogNear, uFogFar, viewDist); if (!uTransparentBackground) { -- GitLab