Comparing version 0.14.3 to 0.14.4
@@ -0,1 +1,7 @@ | ||
### 0.14.4 (2024-12-17) | ||
_New:_ | ||
- Added `direction` property to `slitScan` effect for choosing `x` or `y`. | ||
### 0.14.3 (2024-12-16) | ||
@@ -2,0 +8,0 @@ |
{ | ||
"name": "kampos", | ||
"version": "0.14.3", | ||
"version": "0.14.4", | ||
"description": "Tiny and fast effects compositor on WebGL", | ||
@@ -5,0 +5,0 @@ "registry": "https://registry.npmjs.org/", |
@@ -332,4 +332,7 @@ const LUMA_COEFFICIENT = 'const vec3 lumcoeff = vec3(0.2125, 0.7154, 0.0721);'; | ||
if (error) { | ||
function addLineNumbers(str) { | ||
return str.split('\n').map((line, i) => `${i + 1}: ${line}`).join('\n'); | ||
} | ||
throw new Error( | ||
`${type} error:: ${error}\n${type === SHADER_ERROR_TYPES.fragment ? fragmentSrc : vertexSrc}`, | ||
`${type} error:: ${error}\n${addLineNumbers(type === SHADER_ERROR_TYPES.fragment ? fragmentSrc : vertexSrc)}`, | ||
); | ||
@@ -336,0 +339,0 @@ } |
@@ -9,2 +9,3 @@ /** | ||
* @param {number} [params.frequency] initial frequency to use . | ||
* @param {string} [params.direction='x'] direction to apply the slit scan effect. | ||
* @returns {slitScanEffect} | ||
@@ -18,3 +19,4 @@ * | ||
intensity = 0.1, | ||
frequency = 2.0 | ||
frequency = 2.0, | ||
direction = 'x', | ||
}) { | ||
@@ -32,2 +34,6 @@ /** | ||
*/ | ||
const isHorizontal = direction === 'x'; | ||
const noiseFragPart = `gl_FragCoord.${direction} / u_resolution.${direction} * u_frequency`; | ||
const noiseTimePart = 'u_time * 0.0001'; | ||
return { | ||
@@ -40,9 +46,12 @@ fragment: { | ||
u_time: 'float', | ||
u_horizontal: 'bool' | ||
}, | ||
constant: noise, | ||
source: ` | ||
float noiseValue = noise(vec2(gl_FragCoord.x / u_resolution.x * u_frequency, u_time * 0.0001)); | ||
float sourceX = sourceCoord.x + noiseValue * u_intensity; | ||
float mirroredX = mod(-sourceX, 1.0) * (mod(sourceX - 1.0, 2.0) - mod(sourceX, 1.0)) + mod(sourceX, 1.0) * (mod(sourceX, 2.0) - mod(sourceX, 1.0)); | ||
sourceCoord = vec2(mirroredX, sourceCoord.y);`, | ||
if (u_slitScanEnabled) { | ||
float noiseValue = noise(vec2(${isHorizontal ? noiseFragPart : noiseTimePart}, ${isHorizontal ? noiseTimePart : noiseFragPart})); | ||
float source_ = sourceCoord.${direction} + noiseValue * u_intensity; | ||
float mirrored_ = mod(-source_, 1.0) * (mod(source_ - 1.0, 2.0) - mod(source_, 1.0)) + mod(source_, 1.0) * (mod(source_, 2.0) - mod(source_, 1.0)); | ||
sourceCoord = ${isHorizontal ? 'vec2(mirrored_, sourceCoord.y)' : 'vec2(sourceCoord.x, mirrored_)'}; | ||
}`, | ||
}, | ||
@@ -49,0 +58,0 @@ get disabled() { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
10546584
29959