Skip to content

Commit 0d4843c

Browse files
authored
Merge pull request #7663 from lukeplowden/shadergen
Remove debug logs from the Shader Generator file
2 parents bd2b227 + 55a09ab commit 0d4843c

File tree

2 files changed

+60
-29
lines changed

2 files changed

+60
-29
lines changed

preview/global/sketch.js

+56-12
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ let myModel;
77
let starShader;
88
let starStrokeShader;
99
let stars;
10+
let ditheringShader;
11+
let originalFrameBuffer;
12+
let blurredFrameBuffer;
1013

1114
function starShaderCallback() {
1215
const time = uniformFloat(() => millis());
1316
getWorldInputs((inputs) => {
1417
inputs.position.y += instanceID() * 20 - 1000;
15-
inputs.position.x += 40*sin(time * 0.001 + instanceID());
18+
inputs.position.x += 40 * sin(time * 0.001 + instanceID());
1619
return inputs;
1720
});
1821
getObjectInputs((inputs) => {
@@ -21,30 +24,71 @@ function starShaderCallback() {
2124
})
2225
}
2326

27+
function ditheringCallback() {
28+
const time = uniformFloat(() => millis())
29+
30+
function rand(co) {
31+
return fract(sin(dot(co, [12.9898, 78.233])) * 43758.5453);
32+
}
33+
34+
function grayscale(col) {
35+
return dot([col.x, col.y, col.z], [0.21, 0.72, 0.07])
36+
}
37+
38+
getColor((input, canvasContent) => {
39+
let col = texture(canvasContent, input.texCoord);
40+
col.z = 0.55;
41+
col += rand(input.texCoord + time/10000000000) * 0.15 - 0.05;
42+
let greyscaleValue = grayscale(col);
43+
col.x = greyscaleValue
44+
col.y = greyscaleValue
45+
return col;
46+
});
47+
}
48+
49+
function bloom() {
50+
const blurred = uniformTexture(() => blurredFrameBuffer);
51+
const original = uniformTexture(() => originalFrameBuffer);
52+
53+
getColor((input, canvasContent) => {
54+
const blurredCol = texture(blurred, input.texCoord);
55+
const originalCol = texture(original, input.texCoord);
56+
const brightPass = max(originalCol - 0.0, 0.0) * 3.0;
57+
// const bloom = original + blurred * brightPass;
58+
// return bloom;
59+
return texture(blurred, input.texCoord) + texture(original, input.texCoord);
60+
});
61+
}
62+
2463
async function setup(){
2564
createCanvas(windowWidth, windowHeight, WEBGL);
26-
stars = buildGeometry(() => sphere(20, 7, 4))
65+
stars = buildGeometry(() => sphere(20, 3, 3))
2766
starShader = baseMaterialShader().modify(starShaderCallback);
2867
starStrokeShader = baseStrokeShader().modify(starShaderCallback)
68+
ditheringShader = baseFilterShader().modify(ditheringCallback);
69+
originalFrameBuffer = createFramebuffer();
70+
blurredFrameBuffer = createFramebuffer();
71+
bloomShader = baseFilterShader().modify(bloom);
2972
}
3073

3174
function draw(){
32-
background(0,200,240);
75+
originalFrameBuffer.begin();
3376
orbitControl();
34-
// noStroke();
35-
77+
background(0,0,0);
3678
push();
3779
stroke(255,0,255)
3880
fill(255,200,255)
3981
strokeShader(starStrokeShader)
4082
shader(starShader);
4183
model(stars, 100);
4284
pop();
43-
push();
44-
shader(baseMaterialShader());
45-
noStroke();
46-
rotateX(HALF_PI);
47-
translate(0, 0, -250);
48-
plane(10000)
49-
pop();
85+
originalFrameBuffer.end();
86+
87+
blurredFrameBuffer.begin();
88+
image(originalFrameBuffer, -windowWidth/2, -windowHeight/2)
89+
filter(BLUR)
90+
blurredFrameBuffer.end();
91+
92+
// image(originalFrameBuffer, -windowWidth/2, -windowHeight/2)
93+
filter(bloomShader);
5094
}

src/webgl/ShaderGenerator.js

+4-17
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ function shadergenerator(p5, fn) {
3636
}
3737
const generator = new ShaderGenerator(generatorFunction, this, options.srcLocations)
3838
const generatedModifyArgument = generator.generate();
39-
console.log("SRC STRING: ", generatorFunction);
40-
console.log("NEW OPTIONS:", generatedModifyArgument)
4139
return oldModify.call(this, generatedModifyArgument);
4240
}
4341
else {
@@ -479,7 +477,6 @@ function shadergenerator(p5, fn) {
479477
}
480478
}
481479

482-
// TODO: Correct the implementation for floats/ genType etc
483480
class ModulusNode extends BinaryOperatorNode {
484481
constructor(a, b) {
485482
super(a, b);
@@ -616,7 +613,6 @@ function shadergenerator(p5, fn) {
616613

617614
Object.keys(availableHooks).forEach((hookName) => {
618615
const hookTypes = originalShader.hookTypes(hookName);
619-
console.log(hookTypes);
620616
this[hookTypes.name] = function(userCallback) {
621617
// Create the initial nodes which are passed to the user callback
622618
// Also generate a string of the arguments for the code generation
@@ -779,14 +775,6 @@ function shadergenerator(p5, fn) {
779775
// GLSL Built in functions
780776
// Add a whole lot of these functions.
781777
// https://docs.gl/el3/abs
782-
// In reality many of these have multiple overrides which will need to address later.
783-
// Also, their return types depend on the genType which will need to address urgently
784-
// genType clamp(genType x,
785-
// genType minVal,
786-
// genType maxVal);
787-
// genType clamp(genType x,
788-
// float minVal,
789-
// float maxVal);
790778
const builtInGLSLFunctions = {
791779
//////////// Trigonometry //////////
792780
'acos': { args: ['genType'], returnType: 'genType', isp5Function: true},
@@ -821,12 +809,12 @@ function shadergenerator(p5, fn) {
821809
// 'isnan': {},
822810
'log': { args: ['genType'], returnType: 'genType', isp5Function: true},
823811
'log2': { args: ['genType'], returnType: 'genType', isp5Function: false},
824-
'max': { args: ['genType'], returnType: 'genType', isp5Function: true},
825-
'min': { args: ['genType'], returnType: 'genType', isp5Function: true},
826-
'mix': { args: ['genType'], returnType: 'genType', isp5Function: false},
812+
'max': { args: ['genType', 'genType'], returnType: 'genType', isp5Function: true},
813+
'min': { args: ['genType', 'genType'], returnType: 'genType', isp5Function: true},
814+
'mix': { args: ['genType', 'genType', 'genType'], returnType: 'genType', isp5Function: false},
827815
// 'mod': {},
828816
// 'modf': {},
829-
'pow': { args: ['genType'], returnType: 'genType', isp5Function: true},
817+
'pow': { args: ['genType', 'genType'], returnType: 'genType', isp5Function: true},
830818
'round': { args: ['genType'], returnType: 'genType', isp5Function: true},
831819
'roundEven': { args: ['genType'], returnType: 'genType', isp5Function: false},
832820
// 'sign': {},
@@ -853,7 +841,6 @@ function shadergenerator(p5, fn) {
853841
Object.entries(builtInGLSLFunctions).forEach(([functionName, properties]) => {
854842
if (properties.isp5Function) {
855843
const originalFn = fn[functionName];
856-
857844
fn[functionName] = function (...args) {
858845
if (GLOBAL_SHADER?.isGenerating) {
859846
return new FunctionCallNode(functionName, args, properties)

0 commit comments

Comments
 (0)