mirror of
https://github.com/Ttanasart-pt/Pixel-Composer.git
synced 2024-12-24 14:06:23 +01:00
3d particle
This commit is contained in:
parent
fdb2858378
commit
a4035b52bf
9 changed files with 135 additions and 26 deletions
|
@ -220,6 +220,7 @@
|
|||
{"name":"biterator","order":2,"path":"folders/VCT/biterator.yy",},
|
||||
{"name":"widget","order":3,"path":"folders/VCT/widget.yy",},
|
||||
{"name":"widgets","order":5,"path":"folders/widgets.yy",},
|
||||
{"name":"d3d particle","order":19,"path":"folders/nodes/data/3D/d3d particle.yy",},
|
||||
],
|
||||
"ResourceOrderSettings": [
|
||||
{"name":"s_node_corner","order":16,"path":"sprites/s_node_corner/s_node_corner.yy",},
|
||||
|
@ -648,7 +649,6 @@
|
|||
{"name":"sh_3d_extrude_filler","order":8,"path":"shaders/sh_3d_extrude_filler/sh_3d_extrude_filler.yy",},
|
||||
{"name":"quarternionBox","order":32,"path":"scripts/quarternionBox/quarternionBox.yy",},
|
||||
{"name":"s_window_exit","order":2,"path":"sprites/s_window_exit/s_window_exit.yy",},
|
||||
{"name":"node_3d_particle","order":4,"path":"scripts/node_3d_particle/node_3d_particle.yy",},
|
||||
{"name":"s_node_color_remove","order":7,"path":"sprites/s_node_color_remove/s_node_color_remove.yy",},
|
||||
{"name":"sh_average","order":7,"path":"shaders/sh_average/sh_average.yy",},
|
||||
{"name":"sh_warp_4points_pers","order":10,"path":"shaders/sh_warp_4points_pers/sh_warp_4points_pers.yy",},
|
||||
|
@ -1536,6 +1536,7 @@
|
|||
{"name":"__matrix3","order":5,"path":"scripts/__matrix3/__matrix3.yy",},
|
||||
{"name":"draw_fit","order":12,"path":"scripts/draw_fit/draw_fit.yy",},
|
||||
{"name":"node_armature_sample","order":5,"path":"scripts/node_armature_sample/node_armature_sample.yy",},
|
||||
{"name":"__3d_particle","order":1,"path":"scripts/__3d_particle/__3d_particle.yy",},
|
||||
{"name":"sh_pb_shade","order":3,"path":"shaders/sh_pb_shade/sh_pb_shade.yy",},
|
||||
{"name":"s_node_morph_surface","order":56,"path":"sprites/s_node_morph_surface/s_node_morph_surface.yy",},
|
||||
{"name":"fd_rectangle_get_velocity_dissipation_type","order":20,"path":"scripts/fd_rectangle_get_velocity_dissipation_type/fd_rectangle_get_velocity_dissipation_type.yy",},
|
||||
|
|
|
@ -253,6 +253,7 @@
|
|||
{"resourceType":"GMFolder","resourceVersion":"1.0","name":"biterator","folderPath":"folders/VCT/biterator.yy",},
|
||||
{"resourceType":"GMFolder","resourceVersion":"1.0","name":"widget","folderPath":"folders/VCT/widget.yy",},
|
||||
{"resourceType":"GMFolder","resourceVersion":"1.0","name":"widgets","folderPath":"folders/widgets.yy",},
|
||||
{"resourceType":"GMFolder","resourceVersion":"1.0","name":"d3d particle","folderPath":"folders/nodes/data/3D/d3d particle.yy",},
|
||||
],
|
||||
"IncludedFiles": [
|
||||
{"resourceType":"GMIncludedFile","resourceVersion":"1.0","name":"ApolloHelp.html","ConfigValues":{"Itch":{"CopyToMask":"0",},},"CopyToMask":-1,"filePath":"datafiles",},
|
||||
|
@ -2280,6 +2281,7 @@
|
|||
{"id":{"name":"__matrix3","path":"scripts/__matrix3/__matrix3.yy",},},
|
||||
{"id":{"name":"draw_fit","path":"scripts/draw_fit/draw_fit.yy",},},
|
||||
{"id":{"name":"node_armature_sample","path":"scripts/node_armature_sample/node_armature_sample.yy",},},
|
||||
{"id":{"name":"__3d_particle","path":"scripts/__3d_particle/__3d_particle.yy",},},
|
||||
{"id":{"name":"sh_pb_shade","path":"shaders/sh_pb_shade/sh_pb_shade.yy",},},
|
||||
{"id":{"name":"ds_map","path":"scripts/ds_map/ds_map.yy",},},
|
||||
{"id":{"name":"s_node_morph_surface","path":"sprites/s_node_morph_surface/s_node_morph_surface.yy",},},
|
||||
|
|
|
@ -1,23 +1,20 @@
|
|||
#include "CommonPS.hlsl"
|
||||
|
||||
struct VS_out
|
||||
{
|
||||
struct VS_out {
|
||||
float4 Position : SV_POSITION;
|
||||
float3 Normal : NORMAL0;
|
||||
float4 Color : COLOR0;
|
||||
float2 TexCoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct PS_out
|
||||
{
|
||||
struct PS_out {
|
||||
float4 Color : SV_Target0;
|
||||
};
|
||||
|
||||
void main(in VS_out IN, out PS_out OUT)
|
||||
{
|
||||
void main(in VS_out IN, out PS_out OUT) {
|
||||
OUT.Color = gm_BaseTextureObject.Sample(gm_BaseTexture, IN.TexCoord);
|
||||
float3 N = normalize(IN.Normal);
|
||||
float3 L = normalize(float3(1.0, 1.0, 1.0));
|
||||
float3 L = normalize(float3(1.0, 1.0, 2.0));
|
||||
float NdotL = saturate(dot(N, L));
|
||||
OUT.Color.rgb *= lerp(0.2, 1.0, NdotL);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#include "CommonVS.hlsl"
|
||||
|
||||
struct VS_in
|
||||
{
|
||||
struct VS_in {
|
||||
float3 Position : POSITION;
|
||||
float3 Normal : NORMAL0;
|
||||
float4 Color : COLOR0;
|
||||
|
@ -9,22 +8,47 @@ struct VS_in
|
|||
uint InstanceID : SV_InstanceID;
|
||||
};
|
||||
|
||||
struct VS_out
|
||||
{
|
||||
struct VS_out {
|
||||
float4 Position : SV_POSITION;
|
||||
float3 Normal : NORMAL0;
|
||||
float4 Color : COLOR0;
|
||||
float2 TexCoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
cbuffer Data : register(b10)
|
||||
{
|
||||
float4 InstancePosition[4096];
|
||||
struct Transform {
|
||||
float4 position;
|
||||
float4 rotation;
|
||||
float4 scale;
|
||||
float4 reserved;
|
||||
};
|
||||
|
||||
void main(in VS_in IN, out VS_out OUT)
|
||||
{
|
||||
float3 position = IN.Position.xyz + InstancePosition[IN.InstanceID].xyz;
|
||||
cbuffer Data : register(b10) {
|
||||
Transform InstanceTransforms[128];
|
||||
};
|
||||
|
||||
// float4x4 EulerToMatrix(float3 eulerAngles) {
|
||||
// float3 c = cos(eulerAngles);
|
||||
// float3 s = sin(eulerAngles);
|
||||
|
||||
// float4x4 rotationMatrix;
|
||||
|
||||
// rotationMatrix[0] = float4(c.y * c.z, -c.x * s.z + s.x * s.y * c.z, s.x * s.z + c.x * s.y * c.z, 0.0);
|
||||
// rotationMatrix[1] = float4(c.y * s.z, c.x * c.z + s.x * s.y * s.z, -s.x * c.z + c.x * s.y * s.z, 0.0);
|
||||
// rotationMatrix[2] = float4(-s.y, s.x * c.y, c.x * c.y, 0.0);
|
||||
// rotationMatrix[3] = float4(0.0, 0.0, 0.0, 1.0);
|
||||
|
||||
// return rotationMatrix;
|
||||
// }
|
||||
|
||||
void main(in VS_in IN, out VS_out OUT) {
|
||||
float3 position = IN.Position.xyz;
|
||||
//float4x4 rotation = EulerToMatrix(InstanceTransforms[IN.InstanceID].rotation.xyz);
|
||||
float3 scale = InstanceTransforms[IN.InstanceID].scale.xyz;
|
||||
|
||||
//position = mul(rotation, float4(position, 1.)).xyz;
|
||||
position = position * scale;
|
||||
position = position + InstanceTransforms[IN.InstanceID].position.xyz;
|
||||
|
||||
OUT.Position = mul(gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION], float4(position.xyz, 1.0));
|
||||
OUT.Normal = mul(gm_Matrices[MATRIX_WORLD], float4(IN.Normal.xyz, 0.0));
|
||||
OUT.Color = IN.Color;
|
||||
|
|
23
scripts/__3d_particle/__3d_particle.gml
Normal file
23
scripts/__3d_particle/__3d_particle.gml
Normal file
|
@ -0,0 +1,23 @@
|
|||
function __3DVFX() constructor {
|
||||
active = true;
|
||||
position = [ 0, 0, 0 ];
|
||||
rotation = [ 0, 0, 0 ];
|
||||
scale = [ 0, 0, 0 ];
|
||||
|
||||
seed = 0;
|
||||
velocity = [ 0, 0, 0 ];
|
||||
|
||||
static reset = function(seed) {
|
||||
self.seed = seed;
|
||||
|
||||
random_set_seed(seed);
|
||||
position[0] = random_range(-4, 4);
|
||||
position[1] = random_range(-4, 4);
|
||||
position[2] = random_range(-4, 4);
|
||||
}
|
||||
|
||||
static step = function() {
|
||||
for( var i = 0; i < 3; i++ )
|
||||
position[i] += velocity[i];
|
||||
}
|
||||
}
|
11
scripts/__3d_particle/__3d_particle.yy
Normal file
11
scripts/__3d_particle/__3d_particle.yy
Normal file
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"resourceType": "GMScript",
|
||||
"resourceVersion": "1.0",
|
||||
"name": "__3d_particle",
|
||||
"isCompatibility": false,
|
||||
"isDnD": false,
|
||||
"parent": {
|
||||
"name": "d3d particle",
|
||||
"path": "folders/nodes/data/3D/d3d particle.yy",
|
||||
},
|
||||
}
|
|
@ -21,21 +21,40 @@ function __3dObjectInstancer() : __3dObject() constructor {
|
|||
size = new __vec3(1);
|
||||
|
||||
positions = [];
|
||||
rotations = [];
|
||||
scales = [];
|
||||
|
||||
static setData = function() { #region
|
||||
d3d11_cbuffer_begin();
|
||||
d3d11_cbuffer_add_float(4 * object_counts);
|
||||
d3d11_cbuffer_add_float(16 * object_counts);
|
||||
object_data = d3d11_cbuffer_end();
|
||||
|
||||
var _buffer = buffer_create(d3d11_cbuffer_get_size(object_data), buffer_fixed, 1);
|
||||
|
||||
for(var i = 0; i < object_counts; i++) {
|
||||
var pos = array_safe_get(positions, i, 0);
|
||||
var rot = array_safe_get(rotations, i, 0);
|
||||
var sca = array_safe_get(scales, i, 0);
|
||||
|
||||
buffer_write(_buffer, buffer_f32, array_safe_get(pos, 0, 0));
|
||||
buffer_write(_buffer, buffer_f32, array_safe_get(pos, 1, 0));
|
||||
buffer_write(_buffer, buffer_f32, array_safe_get(pos, 2, 0));
|
||||
buffer_write(_buffer, buffer_f32, 0);
|
||||
|
||||
buffer_write(_buffer, buffer_f32, array_safe_get(rot, 0, 0));
|
||||
buffer_write(_buffer, buffer_f32, array_safe_get(rot, 1, 0));
|
||||
buffer_write(_buffer, buffer_f32, array_safe_get(rot, 2, 0));
|
||||
buffer_write(_buffer, buffer_f32, 0);
|
||||
|
||||
buffer_write(_buffer, buffer_f32, array_safe_get(sca, 0, 0));
|
||||
buffer_write(_buffer, buffer_f32, array_safe_get(sca, 1, 0));
|
||||
buffer_write(_buffer, buffer_f32, array_safe_get(sca, 2, 0));
|
||||
buffer_write(_buffer, buffer_f32, 0);
|
||||
|
||||
buffer_write(_buffer, buffer_f32, 0);
|
||||
buffer_write(_buffer, buffer_f32, 0);
|
||||
buffer_write(_buffer, buffer_f32, 0);
|
||||
buffer_write(_buffer, buffer_f32, 0);
|
||||
}
|
||||
|
||||
d3d11_cbuffer_update(object_data, _buffer);
|
||||
|
|
|
@ -1,11 +1,31 @@
|
|||
function Node_3D_Particle(_x, _y, _group = noone) : Node_3D_Modifier(_x, _y, _group) constructor {
|
||||
name = "3D Particle";
|
||||
update_on_frame = true;
|
||||
|
||||
inputs[| in_mesh + 0] = nodeValue("Amounts", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 1);
|
||||
|
||||
inputs[| in_mesh + 1] = nodeValue("Positions", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0, 0, 0 ])
|
||||
.setDisplay(VALUE_DISPLAY.vector)
|
||||
.setArrayDepth(1);
|
||||
part_pool_size = 128;
|
||||
parts = array_create(part_pool_size);
|
||||
for( var i = 0; i < part_pool_size; i++ )
|
||||
parts[i] = new __3DVFX();
|
||||
|
||||
part_pos = array_create(part_pool_size);
|
||||
part_rot = array_create(part_pool_size);
|
||||
part_sca = array_create(part_pool_size);
|
||||
|
||||
seed = irandom_range(100000, 999999);
|
||||
|
||||
static processData_prebatch = function() {
|
||||
if(CURRENT_FRAME == 0) {
|
||||
var _sed = seed;
|
||||
|
||||
for( var i = 0; i < part_pool_size; i++ )
|
||||
parts[i].reset(_sed++);
|
||||
} else {
|
||||
for( var i = 0; i < part_pool_size; i++ )
|
||||
parts[i].step();
|
||||
}
|
||||
}
|
||||
|
||||
static processData = function(_output, _data, _output_index, _array_index = 0) {
|
||||
var _obj = _data[0];
|
||||
|
@ -13,13 +33,25 @@ function Node_3D_Particle(_x, _y, _group = noone) : Node_3D_Modifier(_x, _y, _gr
|
|||
if(_obj.VF != global.VF_POS_NORM_TEX_COL) return noone;
|
||||
|
||||
var _amo = _data[in_mesh + 0];
|
||||
var _pos = _data[in_mesh + 1];
|
||||
|
||||
if(_amo <= 0) return noone;
|
||||
var _res = new __3dObjectInstancer();
|
||||
var _scaleZero = [ 0, 0, 0 ];
|
||||
|
||||
_res.object_counts = max(1, _amo);
|
||||
_res.positions = _pos;
|
||||
|
||||
for( var i = 0; i < part_pool_size; i++ ) {
|
||||
var _part = parts[i];
|
||||
|
||||
part_pos[i] = _part.position;
|
||||
part_rot[i] = _part.rotation;
|
||||
part_sca[i] = _part.active? _part.scale : _scaleZero;
|
||||
}
|
||||
|
||||
_res.positions = part_pos;
|
||||
_res.rotations = part_rot;
|
||||
_res.scales = part_sca;
|
||||
_res.object_counts = part_pool_size;
|
||||
|
||||
_res.vertex = _obj.vertex;
|
||||
_res.VB = _obj.VB;
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
"isCompatibility": false,
|
||||
"isDnD": false,
|
||||
"parent": {
|
||||
"name": "d3d modifier",
|
||||
"path": "folders/nodes/data/3D/d3d modifier.yy",
|
||||
"name": "d3d particle",
|
||||
"path": "folders/nodes/data/3D/d3d particle.yy",
|
||||
},
|
||||
}
|
Loading…
Reference in a new issue