[x3d-public] VariationPhysicsModel for ParticleSystem using programmable shaders
John Carlson
yottzumm at gmail.com
Tue Apr 23 01:12:11 PDT 2024
Here are my ideas for VariationPhysicsModel implementation:
Particle Physics Model XML:
<VariationPhysicsModel values="2 2 5 5 0 0" varations="2 1 3 3 0.1 0.1"
lastFrame='0' updateRate='0.1'>
=====================
X3D Script version. Does not do instance animation
=====
<Script DEF='Animate'>
<field name="set_fraction" accessType="inputOnly"
type="SFFloat"></field>
<field name='values' type='MFFloat'
accessType='inputOutput' value='2 2 5 5 0 0'></field>
<field name='variations' type='MFFloat'
accessType='inputOutput' value='2 1 3 3 0.1 0.1'></field>
<field name='lastframe' type='SFFloat'
accessType='inputOutput' value='0'></field>
<field name='updaterate' type='SFFloat'
accessType='inputOutput' value='0.1'></field>
<![CDATA[
ecmascript:
function set_fraction(f, tm) {
if (lastframe + updaterate < tm) {
lastframe = tm;
for (let v in values) {
values[v] = values[v] +
(Math.random() - 0.5) * 2 * variations[v] * 0.1;
}
}
}
]]>
</Script>
======
Shader implementation:
======
uniform float [6] values; // change to x3d_ParticleValues
vec3 rose(vec3 p, float[6] values) {
float a = values[0];
float b = values[1];
float c = values[2];
float d = values[3];
float tdelta = values[4];
float pdelta = values[5];
[snip]
=======
ComposedShader I realize I could pass all floats in one field, but the
first 3 SFFloats don't change.
=======
<ComposedShader DEF="x_ite" language='GLSL'>
<field name='chromaticDispertion'
accessType='initializeOnly' type='SFVec3f' value='0.98 1 1.033'></field>
<field name='cube' type='SFNode'
accessType="initializeOnly">
<ComposedCubeMapTexture
USE="texture"></ComposedCubeMapTexture>
</field>
<field name='bias' accessType='initializeOnly'
type='SFFloat' value='0.5'></field>
<field name='scale' accessType='initializeOnly'
type='SFFloat' value='0.5'></field>
<field name='power' accessType='initializeOnly'
type='SFFloat' value='2'></field>
<field name='values' type='MFFloat'
accessType='inputOutput' value='2 1 4 4 0 0'></field>
<ShaderPart url='"../shaders/x_ite_variations.vs" "
https://coderextreme.net/X3DJSONLD/src/main/shaders/x_ite_variations.vs"'
type="VERTEX" containerField='parts'></ShaderPart>
<ShaderPart url='"../shaders/commonnew.fs" "
https://coderextreme.net/X3DJSONLD/src/main/shaders/commonnew.fs"'
containerField='parts' type='FRAGMENT'></ShaderPart>
</ComposedShader>
===============================
Normally I would use separate variables, but I want this to be widely
applicable. There should probably be a max array size for performance
reasons.
==================================
You can see most of my current changes on my
https://github/coderextreme/x_ite repo.
Here's my current demo:
https://coderextreme.net/X3DJSONLD/src/main/html/particles.html
On Mon, Apr 22, 2024 at 8:21 PM John Carlson <yottzumm at gmail.com> wrote:
> My thought is to add a new input variable in to shader,
>
> in float[] myVariable;
>
> Then provide
>
> <field name=“myVariable” type=“MFFloat” accessType=“inputOnly” value=“…”/>
>
> In the ComposedShader.
>
> But I don’t know currently how to tie a particle physics model to a
> composed shader, nor how to address instances of geometry. The work I’ve
> done so far addresses all instances, and uses scripts, not wind.
>
> So I need to look into source code a bit.
>
> It would seem that naming individual floats might provide better
> documentation. I guess an MFFloat is less wordy, and a single float
> MFFloat can serve as an SFFloat.
>
> John
>
> On Mon, Apr 22, 2024 at 7:53 PM John Carlson <yottzumm at gmail.com> wrote:
>
>> Also, one could provide Variational Physics Models that apply to all
>> particles or one particle.
>>
>> WindPhysicsModel already does this, but the 6 variational physics models
>> I’m imagining affects each particle.
>>
>> I’ll probably start coding this up tonight, if no one else volunteers.
>>
>> I don’t know if I need a Script per particle or not. I’m thinking I need
>> to provide toNode and toField (ROUTEs), but on a particle level, so perhaps
>> I need a specialized ROUTE.
>>
>> How might we combine this with InstancedShape? Can we add
>> ParticleSystems’ PhysicsModels to InstancedShape?
>>
>> I’m looking for more collaboration on reducing the number of Scripts I
>> use.
>>
>> I’m now seeing that float arrays are a thing in custom shaders, so
>> perhaps for my 6 shader parameters, a single variational physics model is
>> all that is required, with 2 MFFloats, one for values, and one for
>> variation of values.
>>
>> Thanks!
>>
>> John
>>
>> On Mon, Apr 22, 2024 at 7:24 PM John Carlson <yottzumm at gmail.com> wrote:
>>
>>> Holger, I would like to provide 2 sets of (SFVec3f of values as well as
>>> an SFVec3f of variation corresponding to the values). My thought is to use
>>> PhysicsModels in the ParticleSystems. These are not emitters, but
>>> something more like a WindPhysicsModel, they parametrically alter the shape
>>> of geometry over time in a ComposedShader. There are actually 6 individual
>>> SFFloats of values, so technically, I might use 6 WindPhysicsModels,
>>> sending speed into the programmable shader, and providing gustiness for
>>> variation. But this is not wind, and AFAIK, X_ITE and Sunrize does wind
>>> with the WindPhysicsModel. Is there another PhysicsModel available, or
>>> should I write my own?
>>>
>>> Would it be better to use 2 MFFloats, and how do I send an MFFloat to
>>> the ComposedShader?
>>>
>>> Thanks!
>>>
>>> John
>>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20240423/f7ab3065/attachment-0001.html>
More information about the x3d-public
mailing list