-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from Absulit/dev
Dev
- Loading branch information
Showing
21 changed files
with
338 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
examples/dithering3/compute.js → examples/dithering3_1/compute.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { brightness } from '../../src/core/color.js'; | ||
|
||
const compute = /*wgsl*/` | ||
struct Variable{ | ||
init: i32 | ||
} | ||
${brightness} | ||
const workgroupSize = 1; | ||
@compute @workgroup_size(workgroupSize,workgroupSize,1) | ||
fn main( | ||
@builtin(global_invocation_id) GlobalId: vec3<u32>, | ||
@builtin(workgroup_id) WorkGroupID: vec3<u32>, | ||
@builtin(local_invocation_id) LocalInvocationID: vec3<u32> | ||
) { | ||
//-------------------------------------------------- | ||
let dims = textureDimensions(image); | ||
var layerIndex = 0; | ||
if(variables.init == 0){ | ||
let pointIndex = i32(GlobalId.y + (GlobalId.x * dims.x)); | ||
var point = textureLoad(image, GlobalId.yx, 0); // image | ||
// var point = textureLoad(image, GlobalId.yx); // video | ||
layers[0][pointIndex] = point; | ||
layers[1][pointIndex] = point; | ||
// variables.init = 1; | ||
}else{ | ||
layerIndex = 1; | ||
} | ||
//-------------------------------------------------- | ||
let pointIndex = i32(GlobalId.x + (GlobalId.y * dims.y)); | ||
var point = layers[layerIndex][pointIndex]; | ||
let b = brightness(point); | ||
var newBrightness = 0.; | ||
if(b > .5){ | ||
newBrightness = 1.; | ||
} | ||
let quant_error = b - newBrightness; | ||
let distance = 1; | ||
let distanceU = u32(distance); | ||
let distanceF = f32(distance); | ||
point = vec4(newBrightness); | ||
let pointP = &layers[layerIndex][pointIndex]; | ||
(*pointP) = point; | ||
let pointIndexC = i32(GlobalId.x + ((GlobalId.y+distanceU) * dims.y)); | ||
var rightPoint = layers[layerIndex][pointIndexC]; | ||
rightPoint = vec4(brightness(rightPoint) + (.5 * quant_error * params.sliderB)); | ||
let pointPC = &layers[layerIndex][pointIndexC]; | ||
(*pointPC) = rightPoint; | ||
let pointIndexR = i32((GlobalId.y+distanceU) + (GlobalId.x * dims.x)); | ||
var bottomPoint = layers[layerIndex][pointIndexR]; | ||
bottomPoint = vec4(brightness(bottomPoint) + (.5 * quant_error)); | ||
let pointPR = &layers[layerIndex][pointIndexR]; | ||
(*pointPR) = bottomPoint; | ||
point = layers[layerIndex][pointIndex]; | ||
let positionU = GlobalId.xy; | ||
textureStore(outputTex, positionU, point); | ||
storageBarrier(); | ||
// workgroupBarrier(); | ||
} | ||
`; | ||
|
||
export default compute; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { snoise } from '../../src/core/noise2d.js'; | ||
import { getClosestColorInPalette, orderedDithering, orderedDithering_threshold_map } from '../../src/core/effects.js'; | ||
import { texturePosition } from '../../src/core/image.js'; | ||
import { fnusin } from '../../src/core/animation.js'; | ||
|
||
const frag = /*wgsl*/` | ||
struct Variable{ | ||
init: i32 | ||
} | ||
${fnusin} | ||
${snoise} | ||
${getClosestColorInPalette} | ||
${orderedDithering} | ||
${texturePosition} | ||
${orderedDithering_threshold_map} | ||
const numPaletteItems = 21; | ||
const getClosestColorInPalette_palette = array< vec4<f32>, numPaletteItems>( | ||
vec4(255./255, 69./255, 0, 1.), | ||
vec4(255./255, 168./255, 0, 1.), | ||
vec4(255./255, 214./255, 53./255, 1.), | ||
vec4(0, 204./255, 120./255, 1.), | ||
vec4(126./255, 237./255, 86./255, 1.), | ||
vec4(0./255, 117./255, 111./255, 1.), | ||
vec4(0./255, 158./255, 170./255, 1.), | ||
vec4(36./255, 80./255, 164./255, 1.), | ||
vec4(54./255, 144./255, 234./255, 1.), | ||
vec4(81./255, 233./255, 244./255, 1.), | ||
vec4(73./255, 58./255, 193./255, 1.), | ||
vec4(106./255, 92./255, 255./255, 1.), | ||
vec4(129./255, 30./255, 159./255, 1.), | ||
vec4(180./255, 74./255, 192./255, 1.), | ||
vec4(255./255, 56./255, 129./255, 1.), | ||
vec4(255./255, 153./255, 170./255, 1.), | ||
vec4(109./255, 72./255, 48./255, 1.), | ||
vec4(156./255, 105./255, 38./255, 1.), | ||
vec4(0, 0, 0, 1.), | ||
vec4(137./255, 141./255, 144./255, 1.), | ||
vec4(212./255, 215./255, 217./255, 1.), | ||
); | ||
@fragment | ||
fn main( | ||
@location(0) color: vec4<f32>, | ||
@location(1) uv: vec2<f32>, | ||
@location(2) ratio: vec2<f32>, | ||
@location(3) uvRatio: vec2<f32>, | ||
@location(4) mouse: vec2<f32>, | ||
@builtin(position) position: vec4<f32> | ||
) -> @location(0) vec4<f32> { | ||
//let imageUV = (uv / f + vec2(0, .549 ) ) * vec2(1,-1 * dimsRatio) * ratio.y / params.sliderA; | ||
//var point = textureSample(computeTexture, imageSampler, imageUV); //* .998046; | ||
var point = texturePosition(computeTexture, imageSampler, vec2(0.), uv / params.sliderA, false); //* .998046; | ||
return point; | ||
} | ||
`; | ||
|
||
export default frag; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import vert from './vert.js'; | ||
import compute from './compute.js'; | ||
import frag from './frag.js'; | ||
import { RenderPass, ShaderType } from '../../src/absulit.points.module.js'; | ||
const dithering3 = { | ||
renderPasses: [ | ||
new RenderPass(vert, frag, compute, 800, 800) | ||
], | ||
init: async points => { | ||
points.addSampler('imageSampler', null); | ||
// await points.addTextureImage('image', './../img/carmen_lyra_423x643.jpg'); | ||
// await points.addTextureImage('image', './../img/old_king_800x00.jpg'); | ||
// await points.addTextureWebcam('image'); | ||
// await points.addTextureImage('image', './../img/angel_600x600.jpg'); | ||
// await points.addTextureImage('image', './../img/gratia_800x800.jpg'); | ||
await points.addTextureImage('image', './../img/absulit_800x800.jpg'); | ||
points.addBindingTexture('outputTex', 'computeTexture'); | ||
points.addLayers(2); | ||
points.addStorage('variables', 1, 'Variable', 1, false, ShaderType.COMPUTE); | ||
}, | ||
update: points => { | ||
|
||
} | ||
} | ||
|
||
export default dithering3; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const vert = /*wgsl*/` | ||
struct Variable{ | ||
init: i32 | ||
} | ||
@vertex | ||
fn main( | ||
@location(0) position: vec4<f32>, | ||
@location(1) color: vec4<f32>, | ||
@location(2) uv: vec2<f32>, | ||
@builtin(vertex_index) vertexIndex: u32 | ||
) -> Fragment { | ||
return defaultVertexBody(position, color, uv); | ||
} | ||
`; | ||
|
||
export default vert; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.