Skip to content

A lightweight Clip Studio Paint alternative with real-time multiplayer collaborative drawing. Built with Tauri and React.

gpu layer styles (non destruct)

sora3ec8dd075af7
diff --git a/src/App.tsx b/src/App.tsx
index 940998a..fdf2d8e 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -84,6 +84,7 @@ import { WebLandingModal } from './components/WebLandingModal';
import { WelcomeScreen } from './components/WelcomeScreen';
import { FirstTimeNameModal } from './components/FirstTimeNameModal';
import { AdjustmentModal } from './components/AdjustmentModal';
+import { LayerStylesModal } from './components/LayerStylesModal';
import { applyFilter } from './utils/filterEngine';
import { saveRecentDocument, RecentDocument } from './utils/recentDocumentsManager';
import {
@@ -575,6 +576,7 @@ export function App() {
updateMaskThumbnail,
addAdjustmentLayer,
updateAdjustmentData,
+ updateLayerStyles,
} = useLayerManager({ dimensions });
// Active edit target for painting/erasing ('layer' content vs 'mask')
@@ -673,6 +675,38 @@ export function App() {
[adjustmentModalState.layerId, updateAdjustmentData, addAdjustmentLayer, showToast]
);
+ // Non-Destructive GPU Layer Styles Modal State (Stroke, Drop Shadow, Outer Glow)
+ const [layerStylesModalState, setLayerStylesModalState] = useState<{
+ isOpen: boolean;
+ layerId?: string | null;
+ }>({
+ isOpen: false,
+ });
+
+ const handleOpenLayerStylesModal = useCallback(
+ (layerId?: string) => {
+ const targetId = layerId || activeLayerId;
+ if (targetId) {
+ setLayerStylesModalState({
+ isOpen: true,
+ layerId: targetId,
+ });
+ }
+ },
+ [activeLayerId]
+ );
+
+ const handleApplyLayerStyles = useCallback(
+ (styles: any) => {
+ if (layerStylesModalState.layerId) {
+ updateLayerStyles(layerStylesModalState.layerId, styles);
+ showToast('Updated Layer Styles');
+ }
+ setLayerStylesModalState({ isOpen: false });
+ },
+ [layerStylesModalState.layerId, updateLayerStyles, showToast]
+ );
+
const handleApplyFilter = useCallback(
(type: FilterType, params?: any) => {
if (!hasOpenDocument || !activeLayer || activeLayer.type !== 'raster' || activeLayer.locked) {
@@ -4892,6 +4926,12 @@ export function App() {
label: '',
divider: true,
},
+ {
+ id: 'layer-styles',
+ label: 'Layer Style (Stroke, Shadow, Glow)...',
+ disabled: !hasOpenDocument || !activeLayer || activeLayer.type === 'folder' || activeLayer.type === 'adjustment',
+ onClick: () => handleOpenLayerStylesModal(activeLayerId),
+ },
{
id: 'layer-toggle-tint',
label: activeLayer?.layerColorEnabled ? 'Disable Layer Color (Tint)' : 'Enable Layer Color (Tint)',
@@ -5783,6 +5823,7 @@ export function App() {
onToggleLayerMask={toggleLayerMask}
onToggleMaskLinked={toggleMaskLinked}
onOpenAdjustmentModal={handleOpenAdjustmentModal}
+ onOpenLayerStylesModal={handleOpenLayerStylesModal}
width={rightSidebarWidth}
onWidthChange={handleRightSidebarWidthChange}
/>
@@ -5861,6 +5902,17 @@ export function App() {
/>
)}
+ {/* Non-destructive GPU Layer Styles Modal (Stroke, Drop Shadow, Outer Glow) */}
+ {layerStylesModalState.isOpen && (
+ <LayerStylesModal
+ isOpen={layerStylesModalState.isOpen}
+ layerName={layers.find((l) => l.id === layerStylesModalState.layerId)?.name || 'Layer'}
+ initialStyles={layers.find((l) => l.id === layerStylesModalState.layerId)?.styles}
+ onClose={() => setLayerStylesModalState({ isOpen: false })}
+ onApply={handleApplyLayerStyles}
+ />
+ )}
+
{/* Clip Studio Paint Simple Tone Settings Modal */}
<SimpleToneModal
isOpen={isToneModalOpen}
diff --git a/src/components/LayerStylesModal.tsx b/src/components/LayerStylesModal.tsx
new file mode 100644
index 0000000..ae583ff
--- /dev/null
+++ b/src/components/LayerStylesModal.tsx
@@ -0,0 +1,710 @@
+import React, { useState, useEffect, useRef } from 'react';
+import { X, Check, RotateCcw, Sparkles } from 'lucide-react';
+import {
+ LayerStyles,
+ LayerStyleStroke,
+ LayerStyleDropShadow,
+ LayerStyleOuterGlow,
+} from '../types/editor';
+
+export interface LayerStylesModalProps {
+ isOpen: boolean;
+ initialStyles?: LayerStyles;
+ layerName?: string;
+ onClose: () => void;
+ onApply: (styles: LayerStyles) => void;
+}
+
+export const DEFAULT_STROKE: LayerStyleStroke = {
+ enabled: false,
+ size: 4,
+ color: '#000000',
+ position: 'outside',
+ opacity: 1,
+};
+
+export const DEFAULT_DROP_SHADOW: LayerStyleDropShadow = {
+ enabled: false,
+ color: '#000000',
+ opacity: 0.75,
+ angle: 120,
+ distance: 8,
+ blur: 10,
+ spread: 0,
+};
+
+export const DEFAULT_OUTER_GLOW: LayerStyleOuterGlow = {
+ enabled: false,
+ color: '#ffe600',
+ opacity: 0.75,
+ blur: 15,
+ spread: 10,
+};
+
+type StyleTab = 'stroke' | 'dropShadow' | 'outerGlow';
+
+export const LayerStylesModal: React.FC<LayerStylesModalProps> = ({
+ isOpen,
+ initialStyles,
+ layerName = 'Layer',
+ onClose,
+ onApply,
+}) => {
+ const [activeTab, setActiveTab] = useState<StyleTab>('stroke');
+
+ const [stroke, setStroke] = useState<LayerStyleStroke>(() => ({
+ ...DEFAULT_STROKE,
+ ...(initialStyles?.stroke || {}),
+ }));
+
+ const [dropShadow, setDropShadow] = useState<LayerStyleDropShadow>(() => ({
+ ...DEFAULT_DROP_SHADOW,
+ ...(initialStyles?.dropShadow || {}),
+ }));
+
+ const [outerGlow, setOuterGlow] = useState<LayerStyleOuterGlow>(() => ({
+ ...DEFAULT_OUTER_GLOW,
+ ...(initialStyles?.outerGlow || {}),
+ }));
+
+ // Modal dragging support
+ const [pos, setPos] = useState<{ x: number; y: number }>({ x: 0, y: 0 });
+ const isDraggingRef = useRef(false);
+ const dragStartRef = useRef<{ startX: number; startY: number; initX: number; initY: number }>({
+ startX: 0,
+ startY: 0,
+ initX: 0,
+ initY: 0,
+ });
+
+ const previewCanvasRef = useRef<HTMLCanvasElement | null>(null);
+
+ // Sync state when opening modal
+ useEffect(() => {
+ if (isOpen) {
+ setStroke({
+ ...DEFAULT_STROKE,
+ ...(initialStyles?.stroke || {}),
+ });
+ setDropShadow({
+ ...DEFAULT_DROP_SHADOW,
+ ...(initialStyles?.dropShadow || {}),
+ });
+ setOuterGlow({
+ ...DEFAULT_OUTER_GLOW,
+ ...(initialStyles?.outerGlow || {}),
+ });
+ // Center modal dialog
+ setPos({ x: 0, y: 0 });
+ }
+ }, [isOpen, initialStyles]);
+
+ // Live Swatch Preview Renderer
+ useEffect(() => {
+ if (!isOpen) return;
+ const canvas = previewCanvasRef.current;
+ if (!canvas) return;
+
+ const ctx = canvas.getContext('2d');
+ if (!ctx) return;
+
+ const w = canvas.width;
+ const h = canvas.height;
+ ctx.clearRect(0, 0, w, h);
+
+ // Checkerboard background
+ const tileSize = 8;
+ for (let y = 0; y < h; y += tileSize) {
+ for (let x = 0; x < w; x += tileSize) {
+ ctx.fillStyle = ((x / tileSize + y / tileSize) % 2 === 0) ? '#28282b' : '#1f1f22';
+ ctx.fillRect(x, y, tileSize, tileSize);
+ }
+ }
+
+ ctx.save();
+ const cx = w / 2;
+ const cy = h / 2;
+
+ // Draw Drop Shadow
+ if (dropShadow.enabled && dropShadow.opacity > 0) {
+ ctx.save();
+ const rad = ((dropShadow.angle || 0) * Math.PI) / 180;
+ ctx.shadowColor = dropShadow.color || '#000000';
+ ctx.shadowBlur = dropShadow.blur || 0;
+ ctx.shadowOffsetX = Math.cos(rad) * (dropShadow.distance || 0);
+ ctx.shadowOffsetY = Math.sin(rad) * (dropShadow.distance || 0);
+ ctx.globalAlpha = dropShadow.opacity;
+ drawPreviewShape(ctx, cx, cy);
+ ctx.restore();
+ }
+
+ // Draw Outer Glow
+ if (outerGlow.enabled && outerGlow.opacity > 0) {
+ ctx.save();
+ ctx.shadowColor = outerGlow.color || '#ffe600';
+ ctx.shadowBlur = outerGlow.blur || 0;
+ ctx.shadowOffsetX = 0;
+ ctx.shadowOffsetY = 0;
+ ctx.globalAlpha = outerGlow.opacity;
+ drawPreviewShape(ctx, cx, cy);
+ ctx.restore();
+ }
+
+ // Draw Outside Stroke
+ if (stroke.enabled && stroke.size > 0 && stroke.opacity > 0 && stroke.position === 'outside') {
+ ctx.save();
+ ctx.strokeStyle = stroke.color || '#000000';
+ ctx.lineWidth = stroke.size * 2;
+ ctx.lineJoin = 'round';
+ ctx.globalAlpha = stroke.opacity;
+ strokePreviewShape(ctx, cx, cy);
+ ctx.restore();
+ }
+
+ // Draw Center Stroke under shape
+ if (stroke.enabled && stroke.size > 0 && stroke.opacity > 0 && stroke.position === 'center') {
+ ctx.save();
+ ctx.strokeStyle = stroke.color || '#000000';
+ ctx.lineWidth = stroke.size;
+ ctx.lineJoin = 'round';
+ ctx.globalAlpha = stroke.opacity;
+ strokePreviewShape(ctx, cx, cy);
+ ctx.restore();
+ }
+
+ // Draw Shape Body
+ ctx.save();
+ ctx.fillStyle = '#3b82f6';
+ drawPreviewShape(ctx, cx, cy);
+ ctx.restore();
+
+ // Draw Inside Stroke
+ if (stroke.enabled && stroke.size > 0 && stroke.opacity > 0 && stroke.position === 'inside') {
+ ctx.save();
+ ctx.clip();
+ ctx.strokeStyle = stroke.color || '#000000';
+ ctx.lineWidth = stroke.size * 2;
+ ctx.lineJoin = 'round';
+ ctx.globalAlpha = stroke.opacity;
+ strokePreviewShape(ctx, cx, cy);
+ ctx.restore();
+ }
+
+ ctx.restore();
+ }, [isOpen, stroke, dropShadow, outerGlow]);
+
+ function drawPreviewShape(ctx: CanvasRenderingContext2D, cx: number, cy: number) {
+ ctx.beginPath();
+ ctx.arc(cx, cy, 28, 0, Math.PI * 2);
+ ctx.fill();
+ }
+
+ function strokePreviewShape(ctx: CanvasRenderingContext2D, cx: number, cy: number) {
+ ctx.beginPath();
+ ctx.arc(cx, cy, 28, 0, Math.PI * 2);
+ ctx.stroke();
+ }
+
+ // Keyboard shortcut handlers (Escape = Close, Enter = OK)
+ useEffect(() => {
+ if (!isOpen) return;
+ const handleKeyDown = (e: KeyboardEvent) => {
+ if (e.key === 'Escape') {
+ onClose();
+ } else if (e.key === 'Enter' && !e.shiftKey && !e.ctrlKey && !e.metaKey) {
+ handleConfirm();
+ }
+ };
+ window.addEventListener('keydown', handleKeyDown);
+ return () => window.removeEventListener('keydown', handleKeyDown);
+ }, [isOpen, stroke, dropShadow, outerGlow]);
+
+ const handlePointerDown = (e: React.PointerEvent) => {
+ isDraggingRef.current = true;
+ dragStartRef.current = {
+ startX: e.clientX,
+ startY: e.clientY,
+ initX: pos.x,
+ initY: pos.y,
+ };
+ (e.target as HTMLElement).setPointerCapture(e.pointerId);
+ };
+
+ const handlePointerMove = (e: React.PointerEvent) => {
+ if (!isDraggingRef.current) return;
+ const dx = e.clientX - dragStartRef.current.startX;
+ const dy = e.clientY - dragStartRef.current.startY;
+ setPos({
+ x: dragStartRef.current.initX + dx,
+ y: dragStartRef.current.initY + dy,
+ });
+ };
+
+ const handlePointerUp = (e: React.PointerEvent) => {
+ isDraggingRef.current = false;
+ try {
+ (e.target as HTMLElement).releasePointerCapture(e.pointerId);
+ } catch {
+ // Ignore pointer release failure
+ }
+ };
+
+ const handleResetDefaults = () => {
+ if (activeTab === 'stroke') setStroke(DEFAULT_STROKE);
+ else if (activeTab === 'dropShadow') setDropShadow(DEFAULT_DROP_SHADOW);
+ else if (activeTab === 'outerGlow') setOuterGlow(DEFAULT_OUTER_GLOW);
+ };
+
+ const handleConfirm = () => {
+ onApply({
+ stroke,
+ dropShadow,
+ outerGlow,
+ });
+ onClose();
+ };
+
+ if (!isOpen) return null;
+
+ return (
+ <div className="fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-xs select-none">
+ <div
+ className="w-[640px] max-w-[95vw] bg-[#242426] border border-[#3e3e42] rounded-lg shadow-2xl flex flex-col text-[#cccccc] overflow-hidden"
+ style={{
+ transform: `translate(${pos.x}px, ${pos.y}px)`,
+ }}
+ >
+ {/* Header / Title Bar */}
+ <div
+ onPointerDown={handlePointerDown}
+ onPointerMove={handlePointerMove}
+ onPointerUp={handlePointerUp}
+ className="flex items-center justify-between px-4 py-2.5 bg-[#1e1e20] border-b border-[#333336] cursor-move text-xs font-semibold"
+ >
+ <div className="flex items-center space-x-2">
+ <Sparkles className="w-4 h-4 text-amber-400" />
+ <span className="text-white">Layer Style (Blending Options) - {layerName}</span>
+ </div>
+ <button
+ onClick={onClose}
+ className="p-1 text-[#888888] hover:text-white hover:bg-[#333336] rounded transition-colors"
+ >
+ <X className="w-4 h-4" />
+ </button>
+ </div>
+
+ {/* Modal Body: Left category sidebar + Right parameter panel */}
+ <div className="flex flex-1 min-h-[380px] text-xs">
+ {/* Left Column: Styles Checklist */}
+ <div className="w-48 bg-[#1a1a1c] border-r border-[#333336] p-2 flex flex-col justify-between">
+ <div className="space-y-1">
+ <div className="px-2 py-1 text-[10px] font-bold uppercase tracking-wider text-[#777777]">
+ Styles
+ </div>
+
+ {/* Stroke Item */}
+ <div
+ onClick={() => setActiveTab('stroke')}
+ className={`flex items-center space-x-2 px-2.5 py-2 rounded cursor-pointer transition-colors ${
+ activeTab === 'stroke'
+ ? 'bg-[#353538] text-white font-medium shadow-xs'
+ : 'hover:bg-[#252528] text-[#aaaaaa]'
+ }`}
+ >
+ <input
+ type="checkbox"
+ checked={stroke.enabled}
+ onChange={(e) => {
+ e.stopPropagation();
+ setStroke((s) => ({ ...s, enabled: e.target.checked }));
+ }}
+ className="rounded border-[#444448] bg-[#1a1a1c] text-blue-500 focus:ring-0 cursor-pointer"
+ />
+ <span className="flex-1 truncate">Stroke</span>
+ </div>
+
+ {/* Drop Shadow Item */}
+ <div
+ onClick={() => setActiveTab('dropShadow')}
+ className={`flex items-center space-x-2 px-2.5 py-2 rounded cursor-pointer transition-colors ${
+ activeTab === 'dropShadow'
+ ? 'bg-[#353538] text-white font-medium shadow-xs'
+ : 'hover:bg-[#252528] text-[#aaaaaa]'
+ }`}
+ >
+ <input
+ type="checkbox"
+ checked={dropShadow.enabled}
+ onChange={(e) => {
+ e.stopPropagation();
+ setDropShadow((s) => ({ ...s, enabled: e.target.checked }));
+ }}
+ className="rounded border-[#444448] bg-[#1a1a1c] text-blue-500 focus:ring-0 cursor-pointer"
+ />
+ <span className="flex-1 truncate">Drop Shadow</span>
+ </div>
+
+ {/* Outer Glow Item */}
+ <div
+ onClick={() => setActiveTab('outerGlow')}
+ className={`flex items-center space-x-2 px-2.5 py-2 rounded cursor-pointer transition-colors ${
+ activeTab === 'outerGlow'
+ ? 'bg-[#353538] text-white font-medium shadow-xs'
+ : 'hover:bg-[#252528] text-[#aaaaaa]'
+ }`}
+ >
+ <input
+ type="checkbox"
+ checked={outerGlow.enabled}
+ onChange={(e) => {
+ e.stopPropagation();
+ setOuterGlow((s) => ({ ...s, enabled: e.target.checked }));
+ }}
+ className="rounded border-[#444448] bg-[#1a1a1c] text-blue-500 focus:ring-0 cursor-pointer"
+ />
+ <span className="flex-1 truncate">Outer Glow</span>
+ </div>
+ </div>
+
+ {/* Interactive Swatch Preview Canvas */}
+ <div className="pt-2 border-t border-[#2d2d30] flex flex-col items-center">
+ <span className="text-[10px] text-[#777777] mb-1 font-mono">Preview</span>
+ <canvas
+ ref={previewCanvasRef}
+ width={100}
+ height={100}
+ className="w-24 h-24 rounded border border-[#3e3e42] shadow-inner bg-[#1e1e20]"
+ />
+ </div>
+ </div>
+
+ {/* Right Column: Parameters for the selected category */}
+ <div className="flex-1 p-5 overflow-y-auto space-y-4">
+ {/* --- STROKE OPTIONS --- */}
+ {activeTab === 'stroke' && (
+ <div className="space-y-4">
+ <div className="flex items-center justify-between pb-2 border-b border-[#333336]">
+ <span className="font-semibold text-white">Stroke Options</span>
+ <label className="flex items-center space-x-1.5 cursor-pointer">
+ <input
+ type="checkbox"
+ checked={stroke.enabled}
+ onChange={(e) => setStroke((s) => ({ ...s, enabled: e.target.checked }))}
+ className="rounded border-[#444448] bg-[#1a1a1c] text-blue-500 focus:ring-0"
+ />
+ <span className="text-xs">Enable Stroke</span>
+ </label>
+ </div>
+
+ {/* Structure / Size */}
+ <div className="space-y-1">
+ <div className="flex justify-between">
+ <span className="text-[#999999]">Size</span>
+ <span className="font-mono">{stroke.size} px</span>
+ </div>
+ <input
+ type="range"
+ min="1"
+ max="100"
+ value={stroke.size}
+ onChange={(e) => setStroke((s) => ({ ...s, size: Number(e.target.value) }))}
+ className="w-full accent-blue-500 cursor-pointer"
+ />
+ </div>
+
+ {/* Position */}
+ <div className="space-y-1">
+ <span className="text-[#999999] block">Position</span>
+ <div className="grid grid-cols-3 gap-1 bg-[#1a1a1c] p-1 rounded border border-[#333336]">
+ {(['outside', 'inside', 'center'] as const).map((pos) => (
+ <button
+ key={pos}
+ onClick={() => setStroke((s) => ({ ...s, position: pos }))}
+ className={`py-1 text-center capitalize rounded transition-colors ${
+ stroke.position === pos
+ ? 'bg-[#3b82f6] text-white font-medium shadow-xs'
+ : 'hover:bg-[#28282b] text-[#aaaaaa]'
+ }`}
+ >
+ {pos}
+ </button>
+ ))}
+ </div>
+ </div>
+
+ {/* Opacity */}
+ <div className="space-y-1">
+ <div className="flex justify-between">
+ <span className="text-[#999999]">Opacity</span>
+ <span className="font-mono">{Math.round(stroke.opacity * 100)}%</span>
+ </div>
+ <input
+ type="range"
+ min="0"
+ max="1"
+ step="0.01"
+ value={stroke.opacity}
+ onChange={(e) => setStroke((s) => ({ ...s, opacity: Number(e.target.value) }))}
+ className="w-full accent-blue-500 cursor-pointer"
+ />
+ </div>
+
+ {/* Color */}
+ <div className="space-y-1">
+ <span className="text-[#999999] block">Color</span>
+ <div className="flex items-center space-x-2">
+ <input
+ type="color"
+ value={stroke.color}
+ onChange={(e) => setStroke((s) => ({ ...s, color: e.target.value }))}
+ className="w-8 h-8 rounded border border-[#444448] bg-transparent cursor-pointer"
+ />
+ <input
+ type="text"
+ value={stroke.color}
+ onChange={(e) => setStroke((s) => ({ ...s, color: e.target.value }))}
+ className="w-24 px-2 py-1 bg-[#1a1a1c] border border-[#3e3e42] rounded font-mono text-xs focus:outline-none focus:border-blue-500"
+ />
+ </div>
+ </div>
+ </div>
+ )}
+
+ {/* --- DROP SHADOW OPTIONS --- */}
+ {activeTab === 'dropShadow' && (
+ <div className="space-y-4">
+ <div className="flex items-center justify-between pb-2 border-b border-[#333336]">
+ <span className="font-semibold text-white">Drop Shadow Options</span>
+ <label className="flex items-center space-x-1.5 cursor-pointer">
+ <input
+ type="checkbox"
+ checked={dropShadow.enabled}
+ onChange={(e) => setDropShadow((s) => ({ ...s, enabled: e.target.checked }))}
+ className="rounded border-[#444448] bg-[#1a1a1c] text-blue-500 focus:ring-0"
+ />
+ <span className="text-xs">Enable Shadow</span>
+ </label>
+ </div>
+
+ {/* Color & Opacity */}
+ <div className="grid grid-cols-2 gap-3">
+ <div className="space-y-1">
+ <span className="text-[#999999] block">Color</span>
+ <div className="flex items-center space-x-2">
+ <input
+ type="color"
+ value={dropShadow.color}
+ onChange={(e) => setDropShadow((s) => ({ ...s, color: e.target.value }))}
+ className="w-8 h-8 rounded border border-[#444448] bg-transparent cursor-pointer"
+ />
+ <input
+ type="text"
+ value={dropShadow.color}
+ onChange={(e) => setDropShadow((s) => ({ ...s, color: e.target.value }))}
+ className="w-20 px-2 py-1 bg-[#1a1a1c] border border-[#3e3e42] rounded font-mono text-xs focus:outline-none focus:border-blue-500"
+ />
+ </div>
+ </div>
+
+ <div className="space-y-1">
+ <div className="flex justify-between">
+ <span className="text-[#999999]">Opacity</span>
+ <span className="font-mono">{Math.round(dropShadow.opacity * 100)}%</span>
+ </div>
+ <input
+ type="range"
+ min="0"
+ max="1"
+ step="0.01"
+ value={dropShadow.opacity}
+ onChange={(e) => setDropShadow((s) => ({ ...s, opacity: Number(e.target.value) }))}
+ className="w-full accent-blue-500 cursor-pointer"
+ />
+ </div>
+ </div>
+
+ {/* Angle */}
+ <div className="space-y-1">
+ <div className="flex justify-between">
+ <span className="text-[#999999]">Angle</span>
+ <span className="font-mono">{dropShadow.angle}°</span>
+ </div>
+ <input
+ type="range"
+ min="0"
+ max="360"
+ value={dropShadow.angle}
+ onChange={(e) => setDropShadow((s) => ({ ...s, angle: Number(e.target.value) }))}
+ className="w-full accent-blue-500 cursor-pointer"
+ />
+ </div>
+
+ {/* Distance */}
+ <div className="space-y-1">
+ <div className="flex justify-between">
+ <span className="text-[#999999]">Distance</span>
+ <span className="font-mono">{dropShadow.distance} px</span>
+ </div>
+ <input
+ type="range"
+ min="0"
+ max="100"
+ value={dropShadow.distance}
+ onChange={(e) => setDropShadow((s) => ({ ...s, distance: Number(e.target.value) }))}
+ className="w-full accent-blue-500 cursor-pointer"
+ />
+ </div>
+
+ {/* Spread */}
+ <div className="space-y-1">
+ <div className="flex justify-between">
+ <span className="text-[#999999]">Spread</span>
+ <span className="font-mono">{dropShadow.spread}%</span>
+ </div>
+ <input
+ type="range"
+ min="0"
+ max="100"
+ value={dropShadow.spread}
+ onChange={(e) => setDropShadow((s) => ({ ...s, spread: Number(e.target.value) }))}
+ className="w-full accent-blue-500 cursor-pointer"
+ />
+ </div>
+
+ {/* Size / Blur */}
+ <div className="space-y-1">
+ <div className="flex justify-between">
+ <span className="text-[#999999]">Size (Blur)</span>
+ <span className="font-mono">{dropShadow.blur} px</span>
+ </div>
+ <input
+ type="range"
+ min="0"
+ max="100"
+ value={dropShadow.blur}
+ onChange={(e) => setDropShadow((s) => ({ ...s, blur: Number(e.target.value) }))}
+ className="w-full accent-blue-500 cursor-pointer"
+ />
+ </div>
+ </div>
+ )}
+
+ {/* --- OUTER GLOW OPTIONS --- */}
+ {activeTab === 'outerGlow' && (
+ <div className="space-y-4">
+ <div className="flex items-center justify-between pb-2 border-b border-[#333336]">
+ <span className="font-semibold text-white">Outer Glow Options</span>
+ <label className="flex items-center space-x-1.5 cursor-pointer">
+ <input
+ type="checkbox"
+ checked={outerGlow.enabled}
+ onChange={(e) => setOuterGlow((s) => ({ ...s, enabled: e.target.checked }))}
+ className="rounded border-[#444448] bg-[#1a1a1c] text-blue-500 focus:ring-0"
+ />
+ <span className="text-xs">Enable Glow</span>
+ </label>
+ </div>
+
+ {/* Color & Opacity */}
+ <div className="grid grid-cols-2 gap-3">
+ <div className="space-y-1">
+ <span className="text-[#999999] block">Color</span>
+ <div className="flex items-center space-x-2">
+ <input
+ type="color"
+ value={outerGlow.color}
+ onChange={(e) => setOuterGlow((s) => ({ ...s, color: e.target.value }))}
+ className="w-8 h-8 rounded border border-[#444448] bg-transparent cursor-pointer"
+ />
+ <input
+ type="text"
+ value={outerGlow.color}
+ onChange={(e) => setOuterGlow((s) => ({ ...s, color: e.target.value }))}
+ className="w-20 px-2 py-1 bg-[#1a1a1c] border border-[#3e3e42] rounded font-mono text-xs focus:outline-none focus:border-blue-500"
+ />
+ </div>
+ </div>
+
+ <div className="space-y-1">
+ <div className="flex justify-between">
+ <span className="text-[#999999]">Opacity</span>
+ <span className="font-mono">{Math.round(outerGlow.opacity * 100)}%</span>
+ </div>
+ <input
+ type="range"
+ min="0"
+ max="1"
+ step="0.01"
+ value={outerGlow.opacity}
+ onChange={(e) => setOuterGlow((s) => ({ ...s, opacity: Number(e.target.value) }))}
+ className="w-full accent-blue-500 cursor-pointer"
+ />
+ </div>
+ </div>
+
+ {/* Spread */}
+ <div className="space-y-1">
+ <div className="flex justify-between">
+ <span className="text-[#999999]">Spread</span>
+ <span className="font-mono">{outerGlow.spread}%</span>
+ </div>
+ <input
+ type="range"
+ min="0"
+ max="100"
+ value={outerGlow.spread}
+ onChange={(e) => setOuterGlow((s) => ({ ...s, spread: Number(e.target.value) }))}
+ className="w-full accent-blue-500 cursor-pointer"
+ />
+ </div>
+
+ {/* Size / Blur */}
+ <div className="space-y-1">
+ <div className="flex justify-between">
+ <span className="text-[#999999]">Size (Blur)</span>
+ <span className="font-mono">{outerGlow.blur} px</span>
+ </div>
+ <input
+ type="range"
+ min="0"
+ max="100"
+ value={outerGlow.blur}
+ onChange={(e) => setOuterGlow((s) => ({ ...s, blur: Number(e.target.value) }))}
+ className="w-full accent-blue-500 cursor-pointer"
+ />
+ </div>
+ </div>
+ )}
+ </div>
+ </div>
+
+ {/* Footer Actions */}
+ <div className="flex items-center justify-between px-4 py-3 bg-[#1e1e20] border-t border-[#333336]">
+ <button
+ onClick={handleResetDefaults}
+ className="flex items-center space-x-1.5 px-3 py-1.5 text-xs text-[#888888] hover:text-white bg-[#28282b] hover:bg-[#333336] rounded border border-[#3e3e42] transition-colors"
+ >
+ <RotateCcw className="w-3.5 h-3.5" />
+ <span>Reset Category</span>
+ </button>
+
+ <div className="flex items-center space-x-2">
+ <button
+ onClick={onClose}
+ className="px-4 py-1.5 text-xs text-[#aaaaaa] hover:text-white hover:bg-[#333336] rounded transition-colors"
+ >
+ Cancel
+ </button>
+ <button
+ onClick={handleConfirm}
+ className="flex items-center space-x-1.5 px-4 py-1.5 text-xs font-medium text-white bg-blue-600 hover:bg-blue-500 rounded shadow transition-colors"
+ >
+ <Check className="w-3.5 h-3.5" />
+ <span>OK</span>
+ </button>
+ </div>
+ </div>
+ </div>
+ </div>
+ );
+};
diff --git a/src/components/RightSidebar.tsx b/src/components/RightSidebar.tsx
index cc96476..dd03393 100644
--- a/src/components/RightSidebar.tsx
+++ b/src/components/RightSidebar.tsx
@@ -28,6 +28,7 @@ import {
SquareDot,
Link2,
SlidersHorizontal,
+ Sparkles,
} from 'lucide-react';
import { HistoryItemMeta, LayerItem, BlendMode, ToolType, CanvasColorMode, ExpressionColor } from '../types/editor';
import { BLEND_MODES } from '../utils/canvasUtils';
@@ -73,6 +74,7 @@ interface RightSidebarProps {
onToggleLayerMask?: (layerId: string) => void;
onToggleMaskLinked?: (layerId: string) => void;
onOpenAdjustmentModal?: (layerId?: string, initialType?: 'curves' | 'gradient-map' | 'levels' | 'color-balance') => void;
+ onOpenLayerStylesModal?: (layerId: string) => void;
onReorderLayers?: (draggedId: string, targetId: string, position: 'above' | 'below' | 'inside') => void;
onToggleReferenceLayer?: (id: string) => void;
// Tone (Screentone) Effect Props
@@ -215,6 +217,7 @@ export const RightSidebar: React.FC<RightSidebarProps> = React.memo(({
onToggleLayerMask,
onToggleMaskLinked,
onOpenAdjustmentModal,
+ onOpenLayerStylesModal,
onToggleReferenceLayer,
onToggleTone,
onSetToneFrequency,
@@ -1254,6 +1257,19 @@ export const RightSidebar: React.FC<RightSidebarProps> = React.memo(({
<span className="text-[10px]">3D</span>
</button>
)}
+
+ {/* Layer Styles (Blending Options) Button */}
+ {onOpenLayerStylesModal && (
+ <button
+ onClick={() => activeLayerId && onOpenLayerStylesModal(activeLayerId)}
+ title="Layer Styles (Stroke, Drop Shadow, Outer Glow)"
+ disabled={!activeLayerId || activeLayer?.type === 'folder' || activeLayer?.type === 'adjustment'}
+ className="flex items-center space-x-1 px-1.5 py-0.5 hover:text-white hover:bg-[#333333] disabled:opacity-40 rounded-[2px] transition-colors text-amber-400"
+ >
+ <Sparkles className="w-3.5 h-3.5" />
+ <span className="text-[10px] font-bold">fx</span>
+ </button>
+ )}
</div>
<div className="flex items-center space-x-0.5">
@@ -1386,6 +1402,8 @@ export const RightSidebar: React.FC<RightSidebarProps> = React.memo(({
onDoubleClick={() => {
if (layer.type === 'adjustment') {
onOpenAdjustmentModal?.(layer.id, layer.adjustmentData?.type);
+ } else if (layer.type !== 'folder') {
+ onOpenLayerStylesModal?.(layer.id);
}
}}
onContextMenu={(e) => {
@@ -1734,6 +1752,26 @@ export const RightSidebar: React.FC<RightSidebarProps> = React.memo(({
<span className="capitalize">{layer.adjustmentData?.type?.replace('-', ' ') || 'Adjustment'}</span>
</button>
)}
+
+ {/* Non-Destructive Layer Styles fx Indicator Tag */}
+ {Boolean(
+ (layer.styles?.stroke?.enabled && layer.styles.stroke.size > 0 && layer.styles.stroke.opacity > 0) ||
+ (layer.styles?.dropShadow?.enabled && layer.styles.dropShadow.opacity > 0) ||
+ (layer.styles?.outerGlow?.enabled && layer.styles.outerGlow.opacity > 0)
+ ) && (
+ <button
+ type="button"
+ onClick={(e) => {
+ e.stopPropagation();
+ onOpenLayerStylesModal?.(layer.id);
+ }}
+ className="text-[9px] px-1 py-0.5 rounded bg-amber-500/20 border border-amber-500/40 text-amber-300 font-mono font-bold flex items-center gap-0.5 shrink-0 hover:border-amber-400 hover:text-amber-200 hover:bg-amber-500/30 transition-colors cursor-pointer"
+ title="Layer Styles (Stroke, Drop Shadow, Outer Glow) active. Click to edit."
+ >
+ <Sparkles className="w-2.5 h-2.5 text-amber-400" />
+ <span>fx</span>
+ </button>
+ )}
</div>
{/* Alpha Lock Indicator Tag */}
@@ -2112,6 +2150,23 @@ export const RightSidebar: React.FC<RightSidebarProps> = React.memo(({
</>
)}
+ {/* --- LAYER STYLES / BLENDING OPTIONS --- */}
+ {targetLayer.type !== 'folder' && targetLayer.type !== 'adjustment' && onOpenLayerStylesModal && (
+ <>
+ <button
+ onClick={() => {
+ onOpenLayerStylesModal(targetLayer.id);
+ setContextMenu(null);
+ }}
+ className="w-full text-left px-3 py-1.5 flex items-center space-x-2 hover:bg-[#333333] text-amber-400 hover:text-amber-300 transition-colors"
+ >
+ <Sparkles className="w-3.5 h-3.5" />
+ <span className="font-medium">Blending Options / Layer Styles...</span>
+ </button>
+ <div className="my-1 border-t border-[#2d2d30]" />
+ </>
+ )}
+
{/* --- GENERAL ACTIONS --- */}
<button
onClick={() => {
diff --git a/src/hooks/useLayerManager.ts b/src/hooks/useLayerManager.ts
index fc99104..4df7ee3 100644
--- a/src/hooks/useLayerManager.ts
+++ b/src/hooks/useLayerManager.ts
@@ -1,5 +1,5 @@
import { useState, useRef, useCallback, useEffect } from 'react';
-import { LayerItem, BlendMode, CanvasDimensions, CanvasColorMode, LoadedDocument, ExpressionColor, CanvasSelection, DirtyRect, AdjustmentLayerData } from '../types/editor';
+import { LayerItem, BlendMode, CanvasDimensions, CanvasColorMode, LoadedDocument, ExpressionColor, CanvasSelection, DirtyRect, AdjustmentLayerData, LayerStyles } from '../types/editor';
import { ResizeCanvasOptions } from '../types/settings';
import { createCanvasThumbnail, get2DContext } from '../utils/canvasUtils';
import { applyLayerEffects, applyExpressionColorToImageData } from '../utils/layerEffectsEngine';
@@ -1877,6 +1877,15 @@ export function useLayerManager({ dimensions: _dimensions }: UseLayerManagerProp
// Get active layer object
const activeLayer = layers.find((l) => l.id === activeLayerId) || layers[0];
+ // Update Layer Styles (Stroke, Drop Shadow, Outer Glow)
+ const updateLayerStyles = useCallback((id: string, styles: LayerStyles) => {
+ setLayers((prev) => {
+ const target = prev.find((l) => l.id === id);
+ if (!target || target.type === 'folder') return prev;
+ return prev.map((l) => (l.id === id ? { ...l, styles } : l));
+ });
+ }, []);
+
return {
layers,
setLayers,
@@ -1942,6 +1951,7 @@ export function useLayerManager({ dimensions: _dimensions }: UseLayerManagerProp
updateMaskThumbnail,
addAdjustmentLayer,
updateAdjustmentData,
+ updateLayerStyles,
};
}
diff --git a/src/types/editor.ts b/src/types/editor.ts
index cc37dca..66a336b 100644
--- a/src/types/editor.ts
+++ b/src/types/editor.ts
@@ -561,6 +561,38 @@ export type AdjustmentLayerData =
| LevelsAdjustmentData
| ColorBalanceAdjustmentData;
+export interface LayerStyleStroke {
+ enabled: boolean;
+ size: number;
+ color: string;
+ position: 'outside' | 'inside' | 'center';
+ opacity: number;
+}
+
+export interface LayerStyleDropShadow {
+ enabled: boolean;
+ color: string;
+ opacity: number;
+ angle: number; // degrees
+ distance: number;
+ blur: number;
+ spread: number;
+}
+
+export interface LayerStyleOuterGlow {
+ enabled: boolean;
+ color: string;
+ opacity: number;
+ blur: number;
+ spread: number;
+}
+
+export interface LayerStyles {
+ stroke?: LayerStyleStroke;
+ dropShadow?: LayerStyleDropShadow;
+ outerGlow?: LayerStyleOuterGlow;
+}
+
export interface LayerItem {
id: string;
name: string;
@@ -598,6 +630,8 @@ export interface LayerItem {
maskThumbnailUrl?: string;
// Non-destructive Adjustment Layer
adjustmentData?: AdjustmentLayerData;
+ // Non-destructive Layer Styles (Stroke, Drop Shadow, Outer Glow)
+ styles?: LayerStyles;
// Vector Layer Data
vectorStrokes?: VectorStroke[];
// Comic Frame Data
diff --git a/src/utils/__tests__/compositor.test.ts b/src/utils/__tests__/compositor.test.ts
index 3eb8be3..e4dcd7a 100644
--- a/src/utils/__tests__/compositor.test.ts
+++ b/src/utils/__tests__/compositor.test.ts
@@ -110,4 +110,68 @@ describe('Unified GPU Viewport Compositor', () => {
expect(groups[2].baseLayer.id).toBe('base-3');
expect(groups[2].clippedLayers).toHaveLength(0);
});
+
+ describe('Non-Destructive GPU Layer Styles Engine', () => {
+ it('accurately identifies active layer styles', async () => {
+ const { hasActiveLayerStyles } = await import('../compositor');
+
+ expect(hasActiveLayerStyles(undefined)).toBe(false);
+ expect(hasActiveLayerStyles({})).toBe(false);
+
+ // Disabled stroke
+ expect(
+ hasActiveLayerStyles({
+ stroke: { enabled: false, size: 5, color: '#000', position: 'outside', opacity: 1 },
+ })
+ ).toBe(false);
+
+ // Active stroke
+ expect(
+ hasActiveLayerStyles({
+ stroke: { enabled: true, size: 3, color: '#ff0000', position: 'outside', opacity: 1 },
+ })
+ ).toBe(true);
+
+ // Active drop shadow
+ expect(
+ hasActiveLayerStyles({
+ dropShadow: { enabled: true, color: '#000000', opacity: 0.8, angle: 90, distance: 5, blur: 10, spread: 0 },
+ })
+ ).toBe(true);
+
+ // Active outer glow
+ expect(
+ hasActiveLayerStyles({
+ outerGlow: { enabled: true, color: '#ffff00', opacity: 0.9, blur: 15, spread: 20 },
+ })
+ ).toBe(true);
+ });
+
+ it('contains valid Layer Styles shader uniforms and structures', async () => {
+ const { LAYER_STYLES_VERTEX_SHADER, LAYER_STYLES_FRAGMENT_SHADER } = await import('../compositor');
+
+ // Vertex shader quad mapping
+ expect(LAYER_STYLES_VERTEX_SHADER).toContain('a_quadPos');
+ expect(LAYER_STYLES_VERTEX_SHADER).toContain('v_uv');
+ expect(LAYER_STYLES_VERTEX_SHADER).toContain('a_quadPos.x * 2.0 - 1.0');
+
+ // Fragment shader uniforms
+ expect(LAYER_STYLES_FRAGMENT_SHADER).toContain('u_layerTexture');
+ expect(LAYER_STYLES_FRAGMENT_SHADER).toContain('u_strokeEnabled');
+ expect(LAYER_STYLES_FRAGMENT_SHADER).toContain('u_strokeSize');
+ expect(LAYER_STYLES_FRAGMENT_SHADER).toContain('u_strokePosition');
+ expect(LAYER_STYLES_FRAGMENT_SHADER).toContain('u_glowEnabled');
+ expect(LAYER_STYLES_FRAGMENT_SHADER).toContain('u_glowBlur');
+ expect(LAYER_STYLES_FRAGMENT_SHADER).toContain('u_shadowEnabled');
+ expect(LAYER_STYLES_FRAGMENT_SHADER).toContain('u_shadowOffset');
+ expect(LAYER_STYLES_FRAGMENT_SHADER).toContain('u_shadowBlur');
+
+ // Photoshop compositing order
+ expect(LAYER_STYLES_FRAGMENT_SHADER).toContain('// 1. Drop Shadow Pass');
+ expect(LAYER_STYLES_FRAGMENT_SHADER).toContain('// 2. Outer Glow Pass');
+ expect(LAYER_STYLES_FRAGMENT_SHADER).toContain('// 3. Stroke Pass');
+ expect(LAYER_STYLES_FRAGMENT_SHADER).toContain('POISSON_KERNEL');
+ });
+ });
});
+
diff --git a/src/utils/compositor.ts b/src/utils/compositor.ts
index b915c78..8438495 100644
--- a/src/utils/compositor.ts
+++ b/src/utils/compositor.ts
@@ -8,7 +8,7 @@
* anti-moiré screentones, vector layers, and comic frame clipping.
*/
-import { LayerItem, CanvasDimensions, BlendMode, CanvasColorMode } from '../types/editor';
+import { LayerItem, CanvasDimensions, BlendMode, CanvasColorMode, LayerStyles } from '../types/editor';
import { SparseTileGrid, TILE_SIZE, TileBuffer, globalTileGrid } from './tileEngine';
import {
buildCurvesCombinedLut,
@@ -322,6 +322,259 @@ void main() {
}
`;
+export function hasActiveLayerStyles(styles?: LayerStyles): boolean {
+ if (!styles) return false;
+ const hasStroke = Boolean(styles.stroke?.enabled && styles.stroke.size > 0 && styles.stroke.opacity > 0);
+ const hasShadow = Boolean(styles.dropShadow?.enabled && styles.dropShadow.opacity > 0);
+ const hasGlow = Boolean(styles.outerGlow?.enabled && styles.outerGlow.opacity > 0);
+ return hasStroke || hasShadow || hasGlow;
+}
+
+// Vertex Shader: Fullscreen quad for Layer Styles post-processing
+export const LAYER_STYLES_VERTEX_SHADER = `#version 300 es
+precision highp float;
+
+in vec2 a_quadPos; // [0, 1] x [0, 1]
+out vec2 v_uv;
+
+void main() {
+ v_uv = a_quadPos;
+ gl_Position = vec4(a_quadPos.x * 2.0 - 1.0, a_quadPos.y * 2.0 - 1.0, 0.0, 1.0);
+}
+`;
+
+// Fragment Shader: Real-Time Non-Destructive Stroke, Outer Glow, and Drop Shadow
+export const LAYER_STYLES_FRAGMENT_SHADER = `#version 300 es
+precision highp float;
+
+in vec2 v_uv;
+
+uniform sampler2D u_layerTexture;
+uniform vec2 u_viewportSize;
+uniform float u_layerOpacity;
+
+// Stroke Uniforms
+uniform int u_strokeEnabled;
+uniform float u_strokeSize; // in physical screen pixels
+uniform vec4 u_strokeColor; // rgba (includes stroke opacity)
+uniform int u_strokePosition; // 0: outside, 1: inside, 2: center
+
+// Outer Glow Uniforms
+uniform int u_glowEnabled;
+uniform vec4 u_glowColor; // rgba (includes glow opacity)
+uniform float u_glowBlur; // in physical screen pixels
+uniform float u_glowSpread; // 0.0 to 1.0
+
+// Drop Shadow Uniforms
+uniform int u_shadowEnabled;
+uniform vec4 u_shadowColor; // rgba (includes shadow opacity)
+uniform vec2 u_shadowOffset; // in physical screen pixels (dx, dy)
+uniform float u_shadowBlur; // in physical screen pixels
+uniform float u_shadowSpread; // 0.0 to 1.0
+
+out vec4 fragColor;
+
+// 16 Poisson disk sample offsets
+const vec2 POISSON_KERNEL[16] = vec2[](
+ vec2(-0.326212, -0.405805),
+ vec2(-0.840144, -0.073580),
+ vec2(-0.695914, 0.457137),
+ vec2(-0.203345, 0.620716),
+ vec2( 0.962340, -0.194983),
+ vec2( 0.473434, -0.480026),
+ vec2( 0.519456, 0.767022),
+ vec2( 0.185461, -0.893124),
+ vec2( 0.507431, 0.064425),
+ vec2( 0.896420, 0.412458),
+ vec2(-0.321940, -0.932615),
+ vec2(-0.791559, -0.597705),
+ vec2(-0.504245, -0.007671),
+ vec2( 0.052445, 0.375489),
+ vec2( 0.284245, -0.052445),
+ vec2(-0.052445, -0.284245)
+);
+
+float computeStrokeCoverage(vec2 uv, float centerAlpha, float R, int position, vec2 texel) {
+ if (R <= 0.0) return 0.0;
+
+ // Outside stroke
+ if (position == 0) {
+ if (centerAlpha >= 0.99) return 0.0;
+ float minInsideDist = R + 1.0;
+ for (int i = 0; i < 16; i++) {
+ float ang = float(i) * 0.39269908;
+ vec2 dir = vec2(cos(ang), sin(ang));
+ for (int j = 1; j <= 4; j++) {
+ float dist = R * (float(j) / 4.0);
+ vec2 sUv = uv + dir * (dist * texel);
+ if (texture(u_layerTexture, sUv).a > 0.5) {
+ if (dist < minInsideDist) minInsideDist = dist;
+ break;
+ }
+ }
+ }
+ if (minInsideDist <= R) {
+ return clamp(R - minInsideDist + 1.0, 0.0, 1.0) * (1.0 - centerAlpha);
+ }
+ return 0.0;
+ }
+
+ // Inside stroke
+ if (position == 1) {
+ if (centerAlpha < 0.01) return 0.0;
+ float minOutsideDist = R + 1.0;
+ for (int i = 0; i < 16; i++) {
+ float ang = float(i) * 0.39269908;
+ vec2 dir = vec2(cos(ang), sin(ang));
+ for (int j = 1; j <= 4; j++) {
+ float dist = R * (float(j) / 4.0);
+ vec2 sUv = uv + dir * (dist * texel);
+ if (texture(u_layerTexture, sUv).a < 0.5) {
+ if (dist < minOutsideDist) minOutsideDist = dist;
+ break;
+ }
+ }
+ }
+ if (minOutsideDist <= R) {
+ return clamp(R - minOutsideDist + 1.0, 0.0, 1.0) * centerAlpha;
+ }
+ return 0.0;
+ }
+
+ // Center stroke (half outside, half inside)
+ float halfR = max(0.5, R * 0.5);
+ if (centerAlpha < 0.5) {
+ float minInsideDist = halfR + 1.0;
+ for (int i = 0; i < 16; i++) {
+ float ang = float(i) * 0.39269908;
+ vec2 dir = vec2(cos(ang), sin(ang));
+ for (int j = 1; j <= 4; j++) {
+ float dist = halfR * (float(j) / 4.0);
+ vec2 sUv = uv + dir * (dist * texel);
+ if (texture(u_layerTexture, sUv).a >= 0.5) {
+ if (dist < minInsideDist) minInsideDist = dist;
+ break;
+ }
+ }
+ }
+ if (minInsideDist <= halfR) {
+ return clamp(halfR - minInsideDist + 1.0, 0.0, 1.0);
+ }
+ return 0.0;
+ } else {
+ float minOutsideDist = halfR + 1.0;
+ for (int i = 0; i < 16; i++) {
+ float ang = float(i) * 0.39269908;
+ vec2 dir = vec2(cos(ang), sin(ang));
+ for (int j = 1; j <= 4; j++) {
+ float dist = halfR * (float(j) / 4.0);
+ vec2 sUv = uv + dir * (dist * texel);
+ if (texture(u_layerTexture, sUv).a < 0.5) {
+ if (dist < minOutsideDist) minOutsideDist = dist;
+ break;
+ }
+ }
+ }
+ if (minOutsideDist <= halfR) {
+ return clamp(halfR - minOutsideDist + 1.0, 0.0, 1.0);
+ }
+ return 0.0;
+ }
+}
+
+void main() {
+ vec2 texel = 1.0 / u_viewportSize;
+ vec4 centerSample = texture(u_layerTexture, v_uv);
+ float centerAlpha = centerSample.a;
+
+ // 1. Drop Shadow Pass
+ float shadowAlpha = 0.0;
+ if (u_shadowEnabled == 1) {
+ vec2 shadowUV = v_uv - u_shadowOffset * texel;
+ if (u_shadowBlur <= 0.5) {
+ shadowAlpha = texture(u_layerTexture, shadowUV).a;
+ } else {
+ float rad = max(1.0, u_shadowBlur);
+ float accum = 0.0;
+ for (int k = 0; k < 16; k++) {
+ vec2 sUv = shadowUV + POISSON_KERNEL[k] * (rad * texel);
+ accum += texture(u_layerTexture, sUv).a;
+ }
+ accum /= 16.0;
+ float spreadFactor = max(0.01, 1.0 - u_shadowSpread * 0.95);
+ shadowAlpha = clamp(accum / spreadFactor, 0.0, 1.0);
+ }
+ shadowAlpha *= u_shadowColor.a;
+ }
+
+ // 2. Outer Glow Pass
+ float glowAlpha = 0.0;
+ if (u_glowEnabled == 1 && centerAlpha < 0.99) {
+ float rad = max(1.0, u_glowBlur);
+ float accum = 0.0;
+ for (int k = 0; k < 16; k++) {
+ vec2 sUv = v_uv + POISSON_KERNEL[k] * (rad * texel);
+ accum += texture(u_layerTexture, sUv).a;
+ }
+ accum /= 16.0;
+ float spreadFactor = max(0.01, 1.0 - u_glowSpread * 0.95);
+ float glowVal = clamp(accum / spreadFactor, 0.0, 1.0);
+ glowAlpha = glowVal * (1.0 - centerAlpha) * u_glowColor.a;
+ }
+
+ // 3. Stroke Pass
+ float strokeCov = 0.0;
+ if (u_strokeEnabled == 1) {
+ strokeCov = computeStrokeCoverage(v_uv, centerAlpha, u_strokeSize, u_strokePosition, texel);
+ }
+
+ // Composite layers in standard Photoshop order: Drop Shadow -> Outer Glow -> Outside Stroke -> Layer Body -> Inside Stroke
+ vec4 composite = vec4(0.0);
+
+ // Drop Shadow
+ if (u_shadowEnabled == 1 && shadowAlpha > 0.001) {
+ composite = vec4(u_shadowColor.rgb * shadowAlpha, shadowAlpha);
+ }
+
+ // Outer Glow
+ if (u_glowEnabled == 1 && glowAlpha > 0.001) {
+ vec4 glow = vec4(u_glowColor.rgb * glowAlpha, glowAlpha);
+ composite = glow + composite * (1.0 - glow.a);
+ }
+
+ // Outside / Outer Center Stroke
+ bool isOutsideOrCenter = (u_strokePosition == 0 || (u_strokePosition == 2 && centerAlpha < 0.5));
+ if (u_strokeEnabled == 1 && isOutsideOrCenter && strokeCov > 0.001) {
+ float sA = strokeCov * u_strokeColor.a;
+ vec4 strk = vec4(u_strokeColor.rgb * sA, sA);
+ composite = strk + composite * (1.0 - strk.a);
+ }
+
+ // Layer Content
+ if (centerSample.a > 0.001) {
+ composite = centerSample + composite * (1.0 - centerSample.a);
+ }
+
+ // Inside / Inner Center Stroke
+ bool isInsideOrCenter = (u_strokePosition == 1 || (u_strokePosition == 2 && centerAlpha >= 0.5));
+ if (u_strokeEnabled == 1 && isInsideOrCenter && strokeCov > 0.001) {
+ float sA = strokeCov * u_strokeColor.a;
+ vec4 strk = vec4(u_strokeColor.rgb * sA, sA);
+ composite = strk + composite * (1.0 - strk.a);
+ }
+
+ // Overall Layer Opacity
+ composite *= u_layerOpacity;
+
+ if (composite.a < 0.002) {
+ discard;
+ }
+
+ fragColor = composite;
+}
+`;
+
+
export interface OnionSkinCompositorFrame {
layerId: string;
tint: string;
@@ -461,6 +714,31 @@ export class ViewportCompositor {
private snapshotHeight: number = 0;
private lutTexture: WebGLTexture | null = null;
+ // Layer Styles program, FBO & uniforms
+ private stylesProgram: WebGLProgram | null = null;
+ private stylesQuadBuffer: WebGLBuffer | null = null;
+ private layerFbo: WebGLFramebuffer | null = null;
+ private layerTexture: WebGLTexture | null = null;
+ private layerFboWidth: number = 0;
+ private layerFboHeight: number = 0;
+
+ private uStylesLayerTextureLoc: WebGLUniformLocation | null = null;
+ private uStylesViewportSizeLoc: WebGLUniformLocation | null = null;
+ private uStylesLayerOpacityLoc: WebGLUniformLocation | null = null;
+ private uStylesStrokeEnabledLoc: WebGLUniformLocation | null = null;
+ private uStylesStrokeSizeLoc: WebGLUniformLocation | null = null;
+ private uStylesStrokeColorLoc: WebGLUniformLocation | null = null;
+ private uStylesStrokePositionLoc: WebGLUniformLocation | null = null;
+ private uStylesGlowEnabledLoc: WebGLUniformLocation | null = null;
+ private uStylesGlowColorLoc: WebGLUniformLocation | null = null;
+ private uStylesGlowBlurLoc: WebGLUniformLocation | null = null;
+ private uStylesGlowSpreadLoc: WebGLUniformLocation | null = null;
+ private uStylesShadowEnabledLoc: WebGLUniformLocation | null = null;
+ private uStylesShadowColorLoc: WebGLUniformLocation | null = null;
+ private uStylesShadowOffsetLoc: WebGLUniformLocation | null = null;
+ private uStylesShadowBlurLoc: WebGLUniformLocation | null = null;
+ private uStylesShadowSpreadLoc: WebGLUniformLocation | null = null;
+
// Tile texture cache: tileKey -> { texture, version }
private textureCache: Map<string, { texture: WebGLTexture; version: number; lastUsed: number }> = new Map();
private fallbackTileCanvas: HTMLCanvasElement | null = null;
@@ -585,6 +863,64 @@ export class ViewportCompositor {
}
}
+ // Compile Layer Styles Shader Program
+ const stylesVs = gl.createShader(gl.VERTEX_SHADER);
+ const stylesFs = gl.createShader(gl.FRAGMENT_SHADER);
+ if (stylesVs && stylesFs) {
+ gl.shaderSource(stylesVs, LAYER_STYLES_VERTEX_SHADER);
+ gl.compileShader(stylesVs);
+ gl.shaderSource(stylesFs, LAYER_STYLES_FRAGMENT_SHADER);
+ gl.compileShader(stylesFs);
+ if (gl.getShaderParameter(stylesVs, gl.COMPILE_STATUS) && gl.getShaderParameter(stylesFs, gl.COMPILE_STATUS)) {
+ const sProg = gl.createProgram();
+ if (sProg) {
+ gl.attachShader(sProg, stylesVs);
+ gl.attachShader(sProg, stylesFs);
+ gl.linkProgram(sProg);
+ if (gl.getProgramParameter(sProg, gl.LINK_STATUS)) {
+ this.stylesProgram = sProg;
+ this.uStylesLayerTextureLoc = gl.getUniformLocation(sProg, 'u_layerTexture');
+ this.uStylesViewportSizeLoc = gl.getUniformLocation(sProg, 'u_viewportSize');
+ this.uStylesLayerOpacityLoc = gl.getUniformLocation(sProg, 'u_layerOpacity');
+ this.uStylesStrokeEnabledLoc = gl.getUniformLocation(sProg, 'u_strokeEnabled');
+ this.uStylesStrokeSizeLoc = gl.getUniformLocation(sProg, 'u_strokeSize');
+ this.uStylesStrokeColorLoc = gl.getUniformLocation(sProg, 'u_strokeColor');
+ this.uStylesStrokePositionLoc = gl.getUniformLocation(sProg, 'u_strokePosition');
+ this.uStylesGlowEnabledLoc = gl.getUniformLocation(sProg, 'u_glowEnabled');
+ this.uStylesGlowColorLoc = gl.getUniformLocation(sProg, 'u_glowColor');
+ this.uStylesGlowBlurLoc = gl.getUniformLocation(sProg, 'u_glowBlur');
+ this.uStylesGlowSpreadLoc = gl.getUniformLocation(sProg, 'u_glowSpread');
+ this.uStylesShadowEnabledLoc = gl.getUniformLocation(sProg, 'u_shadowEnabled');
+ this.uStylesShadowColorLoc = gl.getUniformLocation(sProg, 'u_shadowColor');
+ this.uStylesShadowOffsetLoc = gl.getUniformLocation(sProg, 'u_shadowOffset');
+ this.uStylesShadowBlurLoc = gl.getUniformLocation(sProg, 'u_shadowBlur');
+ this.uStylesShadowSpreadLoc = gl.getUniformLocation(sProg, 'u_shadowSpread');
+ }
+ }
+ } else {
+ console.error('Layer Styles shader compile error:', gl.getShaderInfoLog(stylesFs));
+ }
+ }
+
+ // Create Layer Styles Quad Buffer [0, 1]
+ const stylesQuad = gl.createBuffer();
+ if (stylesQuad) {
+ gl.bindBuffer(gl.ARRAY_BUFFER, stylesQuad);
+ gl.bufferData(
+ gl.ARRAY_BUFFER,
+ new Float32Array([
+ 0.0, 0.0,
+ 1.0, 0.0,
+ 0.0, 1.0,
+ 0.0, 1.0,
+ 1.0, 0.0,
+ 1.0, 1.0,
+ ]),
+ gl.STATIC_DRAW
+ );
+ this.stylesQuadBuffer = stylesQuad;
+ }
+
// Create Unit Quad Buffer [0, 1]
const quad = gl.createBuffer();
if (!quad) return false;
@@ -843,6 +1179,8 @@ export class ViewportCompositor {
(cl) => cl.visible && cl.opacity > 0.001 && cl.type !== 'folder'
);
+ const baseHasStyles = hasActiveLayerStyles(baseLayer.styles);
+
if (activeClippedLayers.length > 0) {
// Group successive clipped layers: record base silhouette in stencil buffer
gl.enable(gl.STENCIL_TEST);
@@ -850,24 +1188,72 @@ export class ViewportCompositor {
gl.stencilMask(0xFF);
gl.stencilFunc(gl.ALWAYS, 1, 0xFF);
gl.stencilOp(gl.KEEP, gl.KEEP, gl.REPLACE);
- } else {
- gl.disable(gl.STENCIL_TEST);
- }
- // Draw base layer
- this.renderSingleLayer(gl, baseLayer, dimensions, grid, frustum);
+ if (baseHasStyles) {
+ // Record base layer silhouette in stencil without writing colors to canvas
+ gl.colorMask(false, false, false, false);
+ this.renderSingleLayer(gl, baseLayer, dimensions, grid, frustum);
+ gl.colorMask(true, true, true, true);
+
+ // Now draw base layer with styles (don't overwrite stencil with shadow/glow)
+ gl.stencilMask(0x00);
+ this.renderLayerWithStyles(
+ gl,
+ baseLayer,
+ dimensions,
+ grid,
+ frustum,
+ viewportW,
+ viewportH,
+ transform,
+ dpr
+ );
+ gl.stencilMask(0xFF);
+ } else {
+ this.renderSingleLayer(gl, baseLayer, dimensions, grid, frustum);
+ }
- if (activeClippedLayers.length > 0) {
// Render clipped layers: only draw over the opaque pixels of the base layer
gl.stencilMask(0x00);
gl.stencilFunc(gl.EQUAL, 1, 0xFF);
gl.stencilOp(gl.KEEP, gl.KEEP, gl.KEEP);
for (const clippedLayer of activeClippedLayers) {
- this.renderSingleLayer(gl, clippedLayer, dimensions, grid, frustum);
+ if (hasActiveLayerStyles(clippedLayer.styles)) {
+ this.renderLayerWithStyles(
+ gl,
+ clippedLayer,
+ dimensions,
+ grid,
+ frustum,
+ viewportW,
+ viewportH,
+ transform,
+ dpr
+ );
+ } else {
+ this.renderSingleLayer(gl, clippedLayer, dimensions, grid, frustum);
+ }
}
gl.disable(gl.STENCIL_TEST);
+ } else {
+ gl.disable(gl.STENCIL_TEST);
+ if (baseHasStyles) {
+ this.renderLayerWithStyles(
+ gl,
+ baseLayer,
+ dimensions,
+ grid,
+ frustum,
+ viewportW,
+ viewportH,
+ transform,
+ dpr
+ );
+ } else {
+ this.renderSingleLayer(gl, baseLayer, dimensions, grid, frustum);
+ }
}
}
@@ -1126,6 +1512,179 @@ export class ViewportCompositor {
}
}
+ /**
+ * Ensures an offscreen framebuffer and texture exist for isolated layer style rendering.
+ */
+ private ensureLayerFbo(width: number, height: number): boolean {
+ if (!this.gl) return false;
+ const gl = this.gl;
+
+ if (this.layerFbo && this.layerTexture && this.layerFboWidth === width && this.layerFboHeight === height) {
+ return true;
+ }
+
+ if (!this.layerFbo) {
+ this.layerFbo = gl.createFramebuffer();
+ }
+ if (!this.layerTexture) {
+ this.layerTexture = gl.createTexture();
+ }
+
+ this.layerFboWidth = width;
+ this.layerFboHeight = height;
+
+ gl.bindTexture(gl.TEXTURE_2D, this.layerTexture);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
+
+ gl.bindFramebuffer(gl.FRAMEBUFFER, this.layerFbo);
+ gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this.layerTexture, 0);
+
+ const status = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
+
+ if (status !== gl.FRAMEBUFFER_COMPLETE) {
+ console.error('Layer FBO incomplete:', status);
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Evaluates non-destructive GPU layer styles (Stroke, Drop Shadow, Outer Glow)
+ * by rendering the layer into an isolated FBO and processing through LAYER_STYLES_FRAGMENT_SHADER.
+ */
+ private renderLayerWithStyles(
+ gl: WebGL2RenderingContext,
+ layer: LayerItem,
+ dimensions: CanvasDimensions,
+ grid: SparseTileGrid,
+ frustum: { minX: number; minY: number; maxX: number; maxY: number },
+ viewportW: number,
+ viewportH: number,
+ transform: ViewportTransform,
+ dpr: number
+ ): void {
+ if (!this.ensureLayerFbo(viewportW, viewportH) || !this.stylesProgram) {
+ this.renderSingleLayer(gl, layer, dimensions, grid, frustum);
+ return;
+ }
+
+ const styles = layer.styles;
+ if (!styles) {
+ this.renderSingleLayer(gl, layer, dimensions, grid, frustum);
+ return;
+ }
+
+ let maxStyleMargin = 0;
+ if (styles.stroke?.enabled) {
+ maxStyleMargin = Math.max(maxStyleMargin, styles.stroke.size || 0);
+ }
+ if (styles.dropShadow?.enabled) {
+ maxStyleMargin = Math.max(maxStyleMargin, (styles.dropShadow.distance || 0) + (styles.dropShadow.blur || 0));
+ }
+ if (styles.outerGlow?.enabled) {
+ maxStyleMargin = Math.max(maxStyleMargin, styles.outerGlow.blur || 0);
+ }
+
+ const expandedFrustum = {
+ minX: Math.max(0, frustum.minX - maxStyleMargin),
+ minY: Math.max(0, frustum.minY - maxStyleMargin),
+ maxX: Math.min(dimensions.width, frustum.maxX + maxStyleMargin),
+ maxY: Math.min(dimensions.height, frustum.maxY + maxStyleMargin),
+ };
+
+ // 1. Render layer into isolated FBO with opacity 1.0 (opacity is modulated by stylesProgram)
+ gl.bindFramebuffer(gl.FRAMEBUFFER, this.layerFbo);
+ gl.viewport(0, 0, viewportW, viewportH);
+ gl.clearColor(0.0, 0.0, 0.0, 0.0);
+ gl.clear(gl.COLOR_BUFFER_BIT);
+
+ const virtualLayer: LayerItem = { ...layer, opacity: 1.0, blendMode: 'normal' };
+ this.renderSingleLayer(gl, virtualLayer, dimensions, grid, expandedFrustum);
+
+ // 2. Restore default framebuffer (canvas)
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
+ gl.viewport(0, 0, viewportW, viewportH);
+
+ // 3. Set layer blend mode
+ this.setGLBlendMode(layer.blendMode);
+
+ // 4. Activate styles program and bind uniforms
+ gl.useProgram(this.stylesProgram);
+
+ gl.bindBuffer(gl.ARRAY_BUFFER, this.stylesQuadBuffer);
+ const posAttr = gl.getAttribLocation(this.stylesProgram, 'a_quadPos');
+ gl.enableVertexAttribArray(posAttr);
+ gl.vertexAttribPointer(posAttr, 2, gl.FLOAT, false, 0, 0);
+
+ gl.activeTexture(gl.TEXTURE0);
+ gl.bindTexture(gl.TEXTURE_2D, this.layerTexture);
+ gl.uniform1i(this.uStylesLayerTextureLoc, 0);
+
+ gl.uniform2f(this.uStylesViewportSizeLoc, viewportW, viewportH);
+ gl.uniform1f(this.uStylesLayerOpacityLoc, layer.opacity);
+
+ // Stroke uniforms
+ const stroke = styles.stroke;
+ const strokeActive = Boolean(stroke?.enabled && stroke.size > 0 && stroke.opacity > 0);
+ gl.uniform1i(this.uStylesStrokeEnabledLoc, strokeActive ? 1 : 0);
+ if (strokeActive && stroke) {
+ const strokePx = stroke.size * transform.zoom * dpr;
+ gl.uniform1f(this.uStylesStrokeSizeLoc, strokePx);
+ const [sr, sg, sb] = this.parseHexColor(stroke.color || '#000000');
+ gl.uniform4f(this.uStylesStrokeColorLoc, sr, sg, sb, stroke.opacity);
+ const posCode = stroke.position === 'inside' ? 1 : stroke.position === 'center' ? 2 : 0;
+ gl.uniform1i(this.uStylesStrokePositionLoc, posCode);
+ }
+
+ // Outer Glow uniforms
+ const glow = styles.outerGlow;
+ const glowActive = Boolean(glow?.enabled && glow.opacity > 0 && glow.blur > 0);
+ gl.uniform1i(this.uStylesGlowEnabledLoc, glowActive ? 1 : 0);
+ if (glowActive && glow) {
+ const glowBlurPx = glow.blur * transform.zoom * dpr;
+ gl.uniform1f(this.uStylesGlowBlurLoc, glowBlurPx);
+ const [gr, gg, gb] = this.parseHexColor(glow.color || '#ffff00');
+ gl.uniform4f(this.uStylesGlowColorLoc, gr, gg, gb, glow.opacity);
+ gl.uniform1f(this.uStylesGlowSpreadLoc, (glow.spread || 0) / 100);
+ }
+
+ // Drop Shadow uniforms
+ const shadow = styles.dropShadow;
+ const shadowActive = Boolean(shadow?.enabled && shadow.opacity > 0);
+ gl.uniform1i(this.uStylesShadowEnabledLoc, shadowActive ? 1 : 0);
+ if (shadowActive && shadow) {
+ const rad = ((shadow.angle || 0) * Math.PI) / 180;
+ const distPx = (shadow.distance || 0) * transform.zoom * dpr;
+ const dx = Math.cos(rad) * distPx;
+ const dy = Math.sin(rad) * distPx;
+ gl.uniform2f(this.uStylesShadowOffsetLoc, dx, -dy);
+ const shadowBlurPx = (shadow.blur || 0) * transform.zoom * dpr;
+ gl.uniform1f(this.uStylesShadowBlurLoc, shadowBlurPx);
+ const [dr, dg, db] = this.parseHexColor(shadow.color || '#000000');
+ gl.uniform4f(this.uStylesShadowColorLoc, dr, dg, db, shadow.opacity);
+ gl.uniform1f(this.uStylesShadowSpreadLoc, (shadow.spread || 0) / 100);
+ }
+
+ // 5. Draw fullscreen quad
+ gl.drawArrays(gl.TRIANGLES, 0, 6);
+
+ // 6. Restore standard program and quad buffer
+ if (this.program) {
+ gl.useProgram(this.program);
+ gl.bindBuffer(gl.ARRAY_BUFFER, this.quadBuffer);
+ const mainPosAttrib = gl.getAttribLocation(this.program, 'a_quadPos');
+ gl.enableVertexAttribArray(mainPosAttrib);
+ gl.vertexAttribPointer(mainPosAttrib, 2, gl.FLOAT, false, 0, 0);
+ }
+ }
+
+
/**
* Evict least recently used tile textures when texture cache exceeds threshold.
*/
@@ -1162,26 +1721,61 @@ export class ViewportCompositor {
const hasMask = Boolean(layer.maskCanvas && layer.maskEnabled !== false);
const maskCtx = hasMask && layer.maskCanvas ? layer.maskCanvas.getContext('2d', { willReadFrequently: true }) : null;
- for (const tile of tiles) {
- if (!tileCtx || !this.fallbackTileCanvas) continue;
- const rgba = grid.getTileAsRGBA(tile);
- const imgData = tileCtx.createImageData(TILE_SIZE, TILE_SIZE);
- imgData.data.set(rgba);
-
- if (hasMask && maskCtx) {
- const maskImgData = maskCtx.getImageData(tile.tileX * TILE_SIZE, tile.tileY * TILE_SIZE, TILE_SIZE, TILE_SIZE);
- const md = maskImgData.data;
- const d = imgData.data;
- for (let i = 0; i < d.length; i += 4) {
- if (d[i + 3] === 0) continue;
- const maskLum = (0.299 * md[i] + 0.587 * md[i + 1] + 0.114 * md[i + 2]) / 255 * (md[i + 3] / 255);
- d[i + 3] = Math.round(d[i + 3] * maskLum);
+ // Helper to render tiles into target context
+ const drawTiles = (ctx: CanvasRenderingContext2D) => {
+ for (const tile of tiles) {
+ if (!tileCtx || !this.fallbackTileCanvas) continue;
+ const rgba = grid.getTileAsRGBA(tile);
+ const imgData = tileCtx.createImageData(TILE_SIZE, TILE_SIZE);
+ imgData.data.set(rgba);
+
+ if (hasMask && maskCtx) {
+ const maskImgData = maskCtx.getImageData(tile.tileX * TILE_SIZE, tile.tileY * TILE_SIZE, TILE_SIZE, TILE_SIZE);
+ const md = maskImgData.data;
+ const d = imgData.data;
+ for (let i = 0; i < d.length; i += 4) {
+ if (d[i + 3] === 0) continue;
+ const maskLum = (0.299 * md[i] + 0.587 * md[i + 1] + 0.114 * md[i + 2]) / 255 * (md[i + 3] / 255);
+ d[i + 3] = Math.round(d[i + 3] * maskLum);
+ }
}
+
+ tileCtx.putImageData(imgData, 0, 0);
+ ctx.drawImage(this.fallbackTileCanvas, tile.tileX * TILE_SIZE, tile.tileY * TILE_SIZE);
}
+ };
+
+ const styles = layer.styles;
+ const hasStyles = hasActiveLayerStyles(styles);
+
+ // 2D Layer Styles: Draw Drop Shadow
+ if (hasStyles && styles?.dropShadow?.enabled && styles.dropShadow.opacity > 0) {
+ targetCtx.save();
+ const rad = ((styles.dropShadow.angle || 0) * Math.PI) / 180;
+ const dist = styles.dropShadow.distance || 0;
+ targetCtx.shadowColor = styles.dropShadow.color || '#000000';
+ targetCtx.shadowBlur = styles.dropShadow.blur || 0;
+ targetCtx.shadowOffsetX = Math.cos(rad) * dist;
+ targetCtx.shadowOffsetY = Math.sin(rad) * dist;
+ targetCtx.globalAlpha = layer.opacity * styles.dropShadow.opacity;
+ drawTiles(targetCtx);
+ targetCtx.restore();
+ }
- tileCtx.putImageData(imgData, 0, 0);
- targetCtx.drawImage(this.fallbackTileCanvas, tile.tileX * TILE_SIZE, tile.tileY * TILE_SIZE);
+ // 2D Layer Styles: Draw Outer Glow
+ if (hasStyles && styles?.outerGlow?.enabled && styles.outerGlow.opacity > 0) {
+ targetCtx.save();
+ targetCtx.shadowColor = styles.outerGlow.color || '#ffff00';
+ targetCtx.shadowBlur = styles.outerGlow.blur || 0;
+ targetCtx.shadowOffsetX = 0;
+ targetCtx.shadowOffsetY = 0;
+ targetCtx.globalAlpha = layer.opacity * styles.outerGlow.opacity;
+ drawTiles(targetCtx);
+ targetCtx.restore();
}
+
+ // Draw main layer content
+ drawTiles(targetCtx);
targetCtx.restore();
}
@@ -1328,6 +1922,22 @@ export class ViewportCompositor {
this.gl.deleteProgram(this.adjProgram);
this.adjProgram = null;
}
+ if (this.stylesProgram) {
+ this.gl.deleteProgram(this.stylesProgram);
+ this.stylesProgram = null;
+ }
+ if (this.layerFbo) {
+ this.gl.deleteFramebuffer(this.layerFbo);
+ this.layerFbo = null;
+ }
+ if (this.layerTexture) {
+ this.gl.deleteTexture(this.layerTexture);
+ this.layerTexture = null;
+ }
+ if (this.stylesQuadBuffer) {
+ this.gl.deleteBuffer(this.stylesQuadBuffer);
+ this.stylesQuadBuffer = null;
+ }
}
if (this.fallbackTileCanvas) {
this.fallbackTileCanvas = null;