Repository navigation
Add colorField and buildColorFieldShader for fragment shaders - #9341
LalitNarayanYadav wants to merge 7 commits into
Conversation
|
Thanks @LalitNarayanYadav! I tested this and the main paths look good, including framebuffers, blending, resize and the depth behavior. One thing I noticed: Also, the current depth test still passes if the second |
|
Looking good! I think we need to add a base WebGPU shader too (and ideally a visual test to confirm) before merging. |
|
@perminder-17 @bhabishnu @LalitNarayanYadav how do you all feel about the
Overall I'm less concerned about consistency with the way things are right now and more with trying to find a good compromise of what's natural to teach/write + fits in with the rest of p5 without issues + is close enough to what we've done already that we could update other APIs to be more similar in the future. Maybe Open to other ideas too if you have any! |
|
@davepagurek I think I’m leaning towards I tried both styles with a few common mistakes, and
|
|
I also lean towards |
|
ok maybe let's go ahead with that idea then, and then we can test some more examples with it and see how it feels in action with the sorts of things one might yeah with it. in the reference maybe we can move a lot of the filter shader docs over to here, and make the filter shader docs reference this and then continue with more filter specific examples? |
|
Sorry for the late response,
I agree with all of this! One small thought on the last point: I think
So with but happy to go with whatever the group feels is more natural. |
|
Right, I don't think we could move to a world where everything uses There are a few lesser-used hooks that also use I suppose if we did want to migrate in the future to a property assignment only world, we'd be looking into having a property alias for filterColor anyway, for backwards compatibility. Although filterColor.color is a tad verbose. Did you have thoughts on what the naming would be if we did? |
Maybe |
|
Pushed the current state: the On naming, after reading the last few comments I've changed my mind and lean towards property assignment with fieldPixel.begin();
fieldPixel.color = [fieldPixel.texCoord, 0, 1];
fieldPixel.end();
Switching is a small change on my side (hook alias, the WGSL shader, tests and docs), so I'm happy to do it once you all agree, or to stay with |
Resolves #9326
Changes:
Adds a stripped-down alternative to filter shaders for coordinate-based fragment shaders (gradients, noise, warping), where nothing is read from the canvas:
buildColorFieldShader(callback)creates the shader with p5.strandscolorField(shader)draws it over the whole canvas or active framebufferHow it works:
getFieldhook (field.texCoordin,field.colorout). It reuses the filter vertex shader.colorField()follows the approach discussed in the issue: reset the matrix, use the default filter camera, draw a full-sizeplane. This avoids special handling of depth, projection or Y orientation.clearDepth()runs before and after the plane, so the field doesn't affect geometry drawn later (thanks @bhabishnu).blendMode(), so translucent fields can be layered.framebuffer.begin()andend(), and onp5.Graphicsthrough the existingmaterialregistration.field:millis(),frameCount,widthandheightare already available in strands.Not included / open:
baseColorFieldShaderexists only on the WebGL renderer, so this is WebGL-only for now.pixelDensity()isn't available in strands yet. I think it's better as a separate change.field.color = ...(property assignment) is used here, following the discussion. If the project settles on.set()instead, it's a small change.Tests:
Screenshots of the change:
PR Checklist
npm run lintpasses