Add Delta V and Adjust Geometry in Geometry Shader
Shader “Argos_Compute/Octahedron_Lerp_Banned_Emitter”
D:\0._ArgosVU_Christmas_Work\Assets\Argos_Compute_Shader\ARGOS_DynamicDUALS.compute #pragma kernel CSMain // Thread group size #define thread_group_size_x 32 #define thread_group_size_y 1 #define thread_group_size_z 1 struct Particle { float3 position; float3 velocity; float speed; }; int app_mode; float time; float pi; float deltaTime; float damping; float3 base; // HANDLE. float3 orbit; // BOB float targetStrength; // POWER MAG float orbit_weighting; // POWER RATIO BETWEEN HANDLE AND BOB float radius_of_action; // RADIUS OF TROUGH / MOTE :) around ATTRACTOR float zero_mirror_radius; int attractor_Count; float3 att_0; float3 att_1; float3 att_2; float3 att_3; float3 att_4; float3 att_5; float3 att_6; float3 att_7; float3 att_8; float3 att_9; float3 att_10; float3 att_11; float3 att_12; float3 att_13; float3 att_14; float3 att_15; float3 att_16; float3 att_17; float3 att_18; float3 att_19; float constVel; RWStructuredBuffer <Particle> particles; [numthreads(thread_group_size_x, thread_group_size_y, thread_group_size_z )] void CSMain ( uint3 Gid : SV_GroupID, uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID, uint GI : SV_GroupIndex ) { int index = DTid.x; float3 velDeref; float3 vUp; vUp.y = 1; vUp.x = 0; vUp.z = 0; float3 att_Dir; float3 att_Perp; float3 att_A; float3 att_B; float3 att_A_Dir; float3 att_B_Dir; float att_Dist; float3 constVelz; constVelz.z = constVel; constVelz.x = 0; constVelz.y = 0; if(app_mode == 0) //Platonics Mode MONAD { velDeref = particles[index].velocity; att_Dir = normalize((att_0 - particles[index].position)); att_Perp = normalize(cross(att_Dir, vUp)); att_A = att_0 + 1.5*att_Perp;//add adjuster att_B = att_0 - 1.5*att_Perp; att_A_Dir = normalize(att_A - particles[index].position); att_B_Dir = normalize(att_B - particles[index].position); att_Dist = distance(att_A, particles[index].position); velDeref += 0.5*targetStrength * att_A_Dir * deltaTime / att_Dist; velDeref += 0.5*targetStrength * att_B_Dir * deltaTime / att_Dist; if(attractor_Count != 1) //DIAD { att_Dir = normalize((att_1 - particles[index].position)); att_Perp = normalize(cross(att_Dir, vUp)); att_A = att_1 + 1.5*att_Perp; att_B = att_1 - 1.5*att_Perp; att_A_Dir = normalize(att_A - particles[index].position); att_B_Dir = normalize(att_B - particles[index].position); att_Dist = distance(att_A, particles[index].position); velDeref += 0.5*targetStrength * att_A_Dir * deltaTime / att_Dist; velDeref += 0.5*targetStrength * att_B_Dir * deltaTime / att_Dist; if(attractor_Count != 2) //TRIAD { att_Dir = normalize((att_2 - particles[index].position)); att_Perp = normalize(cross(att_Dir, vUp)); att_A = att_2 + 1.5*att_Perp; att_B = att_2 - 1.5*att_Perp; att_A_Dir = normalize(att_A - particles[index].position); att_B_Dir = normalize(att_B - particles[index].position); att_Dist = distance(att_A, particles[index].position); velDeref += 0.5*targetStrength * att_A_Dir * deltaTime / att_Dist; velDeref += 0.5*targetStrength * att_B_Dir * deltaTime / att_Dist; if(attractor_Count != 3) //TETRA { att_Dir = normalize((att_3 - particles[index].position)); att_Perp = normalize(cross(att_Dir, vUp)); att_A = att_3 + 1.5*att_Perp; att_B = att_3 - 1.5*att_Perp; att_A_Dir = normalize(att_A - particles[index].position); att_B_Dir = normalize(att_B - particles[index].position); att_Dist = distance(att_A, particles[index].position); velDeref += 0.5*targetStrength * att_A_Dir * deltaTime / att_Dist; velDeref += 0.5*targetStrength * att_B_Dir * deltaTime / att_Dist; if(attractor_Count != 4) //OCTAHEDRON { //////////////////////////////////////////////// D:\0._ArgosVU_Christmas_Work\Assets\Argos_Compute_Shader\Argos_Particle_Spawner.cs using UnityEngine; using System.Collections; using System.Collections.Generic; using System.Runtime.InteropServices; using System.Runtime.Serialization.Formatters.Binary; using UnityEngine.UI; using System.IO; using System; public class Argos_Particle_Spawner : MonoBehaviour { public enum SPAWNER_Mode { HOLD, DYNAMIC, STYLUS, VACUUM, STEP,//FUTURE } public SPAWNER_Mode mode; public const int maxNumParticles = 120000; public Text Stylus_DBG_Text; private float[] stylii_radii_1; private float[] stylii_radii_2; private float[] stylii_radii_1_floats = new float[12]; private float[] stylii_radii_2_floats = new float[12]; private Vector3[] stylii_posi_1; private Vector3[] stylii_posi_2; class dVec { public float[] vec = new float[3]; } private dVec[] stylii_posi_1_floats = new dVec[12];//Vector holder to compute shader private dVec[] stylii_posi_2_floats = new dVec[12]; private int nStylus_1_On; private int nStylus_2_On; public struct Particle { public Vector3 position; public Vector3 velocity; public float speed; } Particle[] pInitBuffer; Particle[] pOutputBuffer; public MD_Scale_Cube md_Scale_Cube; Vector3 vMax_Last; Vector3 vMin_Last; float activeScale_Last; Vector3 vSpawn_Last_Pos; Quaternion qSpawn_Last_Rota; Vector3 vScaleOffset_Last; public float redraw_timer = 0f; public float redraw_wait_time = 0.3f; float scaleX; float scaleY; float scaleZ; Vector3 vScaleOffset; public bool bCompute_Running = false; public GameObject centerSphere;//HANDLE MOVER-ROTATOR public UI_Ladder ui_Ladder; public int Attractor_Mode; //0 - Pendulum : 1 - Frisbee private int attractor_Count; private GameObject[] go_Atts = new GameObject[20]; private float[] att_0 = new float[3]; private float[] att_1 = new float[3]; private float[] att_2 = new float[3]; private float[] att_3 = new float[3]; private float[] att_4 = new float[3]; private float[] att_5 = new float[3]; private float[] att_6 = new float[3]; private float[] att_7 = new float[3]; private float[] att_8 = new float[3]; private float[] att_9 = new float[3]; private float[] att_10 = new float[3]; private float[] att_11 = new float[3]; private float[] att_12 = new float[3]; private float[] att_13 = new float[3]; private float[] att_14 = new float[3]; private float[] att_15 = new float[3]; private float[] att_16 = new float[3]; private float[] att_17 = new float[3]; private float[] att_18 = new float[3]; private float[] att_19 = new float[3]; public Velocity_Color_Slider velocity_color_slider; public bool bPrimary; public UI_Control ui_control; public HMD_Ctrl_Tracking hmd_Ctrl; public Text BlendMode_Txt; public Slider speedSwitch_Slider; float speedSwitch_Value; public Text speedSwitch_Text; public Slider constVel_Slider; float constVel_Value; public Text constVel_Text; public ComputeShader dynamicCompute; public ComputeShader stylusCompute; public ComputeShader vacuumCompute; private ComputeShader activeCompute; private int hardDamp = 0; //braking for particlles on Shader Switch for snap public Material material; public int maxParticles = 32; private int editor_Max_Particles; private bool bDraw_Reduced = false; public GameObject pendulum_Handle; //Handle public GameObject orbitingSphere; public GameObject Frisbee; public GameObject Frisbee_Attractor_Right; public GameObject Frisbee_Attractor_Left; public Color_Swatches color_Swatches; public float targetStrength = 1000;//POWER MAG public float particle_size = 1f; public float timeMod = 1f; public float damping = 0f; public float orbit_weighting = 0.5f; public float zero_mirror_radius = 1f; public float radius_of_action = 1.0f; public float roa_amplitude = 0; public float roa_frequency = 0; public float constVel = 0; public float cubeSize = 100; public float maxAge = 3.0f; public float particleSize = 0.5f; private ComputeBuffer particles; private int particleSizeOf; int kernel; public bool bAsync_Done = false; //switch to load Compute buffer public static List<Argos_Particle_Spawner> aps_list;// Static list, just to call Render() from the camera. StreamWriter sBufferOut; int nLoaded_Capture = 0; void Start() { if (aps_list == null) aps_list = new List<Argos_Particle_Spawner>(); aps_list.Add(this); sBufferOut = new StreamWriter("BUFFER_Point_Cloud.txt"); for (int i = 0; i < 12; i++) { stylii_posi_1_floats[i] = new dVec(); stylii_posi_2_floats[i] = new dVec(); } mode = SPAWNER_Mode.DYNAMIC; activeCompute = dynamicCompute; pInitBuffer = new Particle[maxParticles]; pOutputBuffer = new Particle[maxParticles]; editor_Max_Particles = maxParticles; StartCoroutine(Defer_LoadAttractors()); attractor_Count = 0; scaleX = 1f; scaleY = 1f; scaleZ = 1f; vScaleOffset = Vector3.zero; hmd_Ctrl.Use_Mode_Change += new HMD_Ctrl_Tracking.USE_MODE_Event_Handler(onUse_Mode_Change); } private IEnumerator Switch_Compute_Shader_To(SPAWNER_Mode spawnMode) { yield return new WaitForEndOfFrame(); if (particles != null) { particles.GetData(pOutputBuffer); particles.Dispose(); if (spawnMode == SPAWNER_Mode.DYNAMIC) { activeCompute = dynamicCompute; kernel = activeCompute.FindKernel("CSMain"); mode = SPAWNER_Mode.DYNAMIC; } else if (spawnMode == SPAWNER_Mode.STYLUS) { activeCompute = stylusCompute; kernel = activeCompute.FindKernel("CSMain"); mode = SPAWNER_Mode.STYLUS; hardDamp = 12; } else if (spawnMode == SPAWNER_Mode.VACUUM) { activeCompute = vacuumCompute; kernel = activeCompute.FindKernel("CSMain"); mode = SPAWNER_Mode.VACUUM; hardDamp = 12; } particles = new ComputeBuffer(maxParticles, particleSizeOf, ComputeBufferType.Default); particles.SetData(pOutputBuffer); vSpawn_Last_Pos = centerSphere.transform.position; qSpawn_Last_Rota = centerSphere.transform.rotation; vMax_Last = md_Scale_Cube.vIn_Max; vMin_Last = md_Scale_Cube.vIn_Min; vScaleOffset_Last = (vMax_Last + vMin_Last) / 2f; activeCompute.SetBuffer(kernel, "particles", particles); } } public void onUse_Mode_Change(HMD_Ctrl_Tracking.USE_MODE useMode) { if (useMode == HMD_Ctrl_Tracking.USE_MODE.DYNAMIC) { StartCoroutine(Switch_Compute_Shader_To(SPAWNER_Mode.DYNAMIC)); } else if (useMode == HMD_Ctrl_Tracking.USE_MODE.STYLUS) { centerSphere.GetComponent<CenterSphere_Interactions>().Reset_Position_and_Rotation_Tracking(); StartCoroutine(Switch_Compute_Shader_To(SPAWNER_Mode.STYLUS)); } else if (useMode == HMD_Ctrl_Tracking.USE_MODE.VACUUM) { centerSphere.GetComponent<CenterSphere_Interactions>().Reset_Position_and_Rotation_Tracking(); StartCoroutine(Switch_Compute_Shader_To(SPAWNER_Mode.VACUUM)); } } D:\0._ArgosVU_Christmas_Work\Assets\Argos_Compute_Shader\Octahedron_Lerp_Banned_Emitter.shader Shader "Argos_Compute/Octahedron_Lerp_Banned_Emitter" { Properties { _ParticleTexture("Diffuse Tex", 2D) = "white" {} _LowColor("Low Color", Color) = (0, 1, 1,0.3) _MidColor("Mid Color", Color) = (1, 0, 0, 0.3) _HighColor("High Color", Color) = (0,0,1,0.3) _LowMidThresh("LowMidThresh", Range(0,1)) = 0.3 _MidHighThresh("MidHighThresh", Range(0,1)) = 0.6 _colorSwitch("Switch", Range(0, 700)) = 60 _nPerc("nPerc", Range(0, 1)) = 0.05 _ARG_SrcMode("SrcMode", Float) = 0 _ARG_DstMode("DstMode", Float) = 0 } SubShader { Pass { //Blend SrcAlpha OneMinusSrcAlpha // Traditional transparency //Blend One OneMinusSrcAlpha // Premultiplied transparency //Blend One One // Additive //Blend OneMinusDstColor One // Soft Additive //Blend DstColor Zero // Multiplicative //Blend DstColor SrcColor // 2x Multiplicative Tags{ "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" } //Blend SrcAlpha One Blend[_ARG_SrcMode][_ARG_DstMode] Cull Off Lighting Off ZWrite Off Fog{ Color(0,0,0,0) } CGPROGRAM #pragma target 5.0 #pragma vertex VSMAIN #pragma fragment PSMAIN #pragma geometry GSMAIN #include "UnityCG.cginc" struct Particle { //int index; float3 position; float3 velocity; float speed; //float age; //float normAge; //int type; }; StructuredBuffer<Particle> particles; // Variables from the properties. float4 _LowColor; float4 _MidColor; float4 _HighColor; float _colorSwitch; float _LowMidThresh; float _MidHighThresh; float _nPerc; //nPercent of _colorSwitch velocity Texture2D _ParticleTexture; SamplerState sampler_ParticleTexture; Texture2D _Ramp1Texture; SamplerState sampler_Ramp1Texture; float3 _worldPos; float _particleSize; float maxAge; float maxRad; struct VS_INPUT { uint vertexid : SV_VertexID; }; //-------------------------------------------------------------------------------- struct GS_INPUT { float4 position : SV_POSITION; float4 color : COLOR; //float size : TEXCOORD0; //float age : TEXCOORD1; //float type : TEXCOORD2; }; //-------------------------------------------------------------------------------- struct PS_INPUT { float4 position : SV_POSITION; float2 texcoords : TEXCOORD0; float4 color : COLOR; //float size : TEXCOORD1; //float age : TEXCOORD2; //float type : TEXCOORD3; }; //-------------------------------------------------------------------------------- GS_INPUT VSMAIN(in VS_INPUT input) { GS_INPUT output; float4 color_mid; output.position.xyz = particles[input.vertexid].position; output.position.w = 1.0; float speed = particles[input.vertexid].speed; float lerpValue1 = clamp((speed - _colorSwitch*(_LowMidThresh - _nPerc / 2)) / (_colorSwitch*_nPerc), 0, 1); color_mid = lerp(_LowColor, _MidColor, lerpValue1); float lerpValue2 = clamp((speed - _colorSwitch*(_MidHighThresh - _nPerc / 2)) / (_colorSwitch*_nPerc), 0, 1); output.color = lerp(color_mid, _HighColor, lerpValue2); return output; } // Dimensions // Length of tetrahedron edge : a. // The height of an regular tetrahedron : // h = sqrt(2 / 3) * a; // The radius of circumsphere : // R = sqrt(3 / 8) * a; // The height of the incenter O or // the radius of the insphere : // r = 1 / 3 * R or r = 1 / sqrt(24) * a; // The radius of midsphere(tangent to edges) : // rm = 1 / sqrt(8) * a; // The angle between two faces : ~70, 53 (yellow) // Angle(C, MAB, D) = degrees(atan(2 * sqrt(2))); // The angle between an edge and a face : ~54, 74 (green) // Angle(0, A, D) = degrees(atan(sqrt(2))); // The angle vertex - center - vertex: ~109.471 (violet) // Angle(A, 0, D) = degrees(acos(-1 / 3)); //void make_face(float3 a, float3 b, float3 c) //{ // float3 face_normal = normalize(cross(c - a, c - b)); // EmitVertex(); // gl_Position = mvpMatrix * vec4(b, 1.0); // color = face_color; // EmitVertex(); // gl_Position = mvpMatrix * vec4(c, 1.0); // color = face_color; // EmitVertex(); // EndPrimitive(); //} //-------------------------------------------------------------------------------- [maxvertexcount(24)] void GSMAIN(point GS_INPUT p[1], inout TriangleStream<PS_INPUT> triStream) { PS_INPUT pIn; float4 pos = p[0].position*2;//TODO FIND OUT WHY *2 pos.w = 1; float4 col = p[0].color; //float4 pos = mul(UNITY_MATRIX_MVP, p[0].position); float scl = 20; float4 v[6]; float3 A, B, C, D, E, F; float4 a, b, c, d, e, f; A = _particleSize*float3( 0.0, 0.5, 0.0); B = _particleSize*float3( 0.5, 0.0, 0.0); C = _particleSize*float3( 0.0, 0.0, 0.5); D = _particleSize*float3(-0.5, 0.0, 0.0); E = _particleSize*float3( 0.0, 0.0, -0.5); F = _particleSize*float3( 0.0, -0.5, 0.0); v[0] = pos + float4(A.x, A.y, A.z, 1); v[1] = pos + float4(B.x, B.y, B.z, 1); v[2] = pos + float4(C.x, C.y, C.z, 1); v[3] = pos + float4(D.x, D.y, D.z, 1); v[4] = pos + float4(E.x, E.y, E.z, 1); v[5] = pos + float4(F.x, F.y, F.z, 1); a = mul(UNITY_MATRIX_MVP, v[0]); b = mul(UNITY_MATRIX_MVP, v[1]); c = mul(UNITY_MATRIX_MVP, v[2]); d = mul(UNITY_MATRIX_MVP, v[3]); e = mul(UNITY_MATRIX_MVP, v[4]); f = mul(UNITY_MATRIX_MVP, v[5]); pIn.position = a; pIn.texcoords = float2(0.0f, 1.0f); pIn.color = col; triStream.Append(pIn); pIn.position = c; pIn.texcoords = float2(1.0f, 1.0f); pIn.color = col; triStream.Append(pIn); pIn.position = b; pIn.texcoords = float2(0.0f, 0.0f); pIn.color = col; triStream.Append(pIn); triStream.RestartStrip(); pIn.position = a; pIn.texcoords = float2(0.0f, 1.0f); pIn.color = col; triStream.Append(pIn); pIn.position = d; pIn.texcoords = float2(1.0f, 1.0f); pIn.color = col; triStream.Append(pIn); pIn.position = c; pIn.texcoords = float2(0.0f, 0.0f); pIn.color = col; triStream.Append(pIn); triStream.RestartStrip(); pIn.position = a; pIn.texcoords = float2(0.0f, 1.0f); pIn.color = col; triStream.Append(pIn); pIn.position = e; pIn.texcoords = float2(1.0f, 1.0f); pIn.color = col; triStream.Append(pIn); pIn.position = d; pIn.texcoords = float2(0.0f, 0.0f); pIn.color = col; triStream.Append(pIn); triStream.RestartStrip(); pIn.position = a; pIn.texcoords = float2(0.0f, 1.0f); pIn.color = col; triStream.Append(pIn); pIn.position = b; pIn.texcoords = float2(1.0f, 1.0f); pIn.color = col; triStream.Append(pIn); pIn.position = e; pIn.texcoords = float2(0.0f, 0.0f); pIn.color = col; triStream.Append(pIn); triStream.RestartStrip(); ///////// pIn.position = f; pIn.texcoords = float2(0.0f, 1.0f); pIn.color = col; triStream.Append(pIn); pIn.position = c; pIn.texcoords = float2(1.0f, 1.0f); pIn.color = col; triStream.Append(pIn); pIn.position = b; pIn.texcoords = float2(0.0f, 0.0f); pIn.color = col; triStream.Append(pIn); triStream.RestartStrip(); pIn.position = f; pIn.texcoords = float2(0.0f, 1.0f); pIn.color = col; triStream.Append(pIn); pIn.position = c; pIn.texcoords = float2(1.0f, 1.0f); pIn.color = col; triStream.Append(pIn); pIn.position = d; pIn.texcoords = float2(0.0f, 0.0f); pIn.color = col; triStream.Append(pIn); triStream.RestartStrip(); pIn.position = f; pIn.texcoords = float2(0.0f, 1.0f); pIn.color = col; triStream.Append(pIn); pIn.position = d; pIn.texcoords = float2(1.0f, 1.0f); pIn.color = col; triStream.Append(pIn); pIn.position = e; pIn.texcoords = float2(0.0f, 0.0f); pIn.color = col; triStream.Append(pIn); triStream.RestartStrip(); pIn.position = f; pIn.texcoords = float2(0.0f, 1.0f); pIn.color = col; triStream.Append(pIn); pIn.position = e; pIn.texcoords = float2(1.0f, 1.0f); pIn.color = col; triStream.Append(pIn); pIn.position = b; pIn.texcoords = float2(0.0f, 0.0f); pIn.color = col; triStream.Append(pIn); triStream.RestartStrip(); //ref //pIn.size = p[0].size; //pIn.age = p[0].age; //pIn.type = p[0].type; } //-------------------------------------------------------------------------------- float4 PSMAIN(in PS_INPUT input) : COLOR { float4 col = input.color; float4 color = _ParticleTexture.Sample(sampler_ParticleTexture, input.texcoords); color *= col; return color; } //-------------------------------------------------------------------------------- ENDCG } } } D:\0._ArgosVU_Christmas_Work\Assets\ArgosVu_Scripts\Serialize.cs public void Populate_float_buffer() { Argos_Particle_Spawner.Particle[] particle_buff = argos_Particle_Spawner.getCompute_Particle_Buffer(); num_active_Particles = particle_buff.Length; bool done = false; int part_buff_idx = 0; int ride_idx = 0; while(!done) { pb_floats[ride_idx++] = particle_buff[part_buff_idx].position.x; pb_floats[ride_idx++] = particle_buff[part_buff_idx].position.y; pb_floats[ride_idx++] = particle_buff[part_buff_idx].position.z; pb_floats[ride_idx++] = particle_buff[part_buff_idx].velocity.x; pb_floats[ride_idx++] = particle_buff[part_buff_idx].velocity.y; pb_floats[ride_idx++] = particle_buff[part_buff_idx].velocity.z; pb_floats[ride_idx++] = particle_buff[part_buff_idx].speed; if (++part_buff_idx > num_active_Particles - 1) done = true; } } public void Populate_Compute_Buffer(ref Argos_Particle_Spawner.Particle[] read_particles, ref int numParticles) { int pbIDX = 0; numParticles = num_active_Particles;//FROM read_UNO_File for (int i = 0; i < numParticles; i++) { read_particles[i].position.x = pb_floats[pbIDX++]; read_particles[i].position.y = pb_floats[pbIDX++]; read_particles[i].position.z = pb_floats[pbIDX++]; read_particles[i].velocity.x = pb_floats[pbIDX++]; read_particles[i].velocity.y = pb_floats[pbIDX++]; read_particles[i].velocity.z = pb_floats[pbIDX++]; read_particles[i].speed = pb_floats[pbIDX++]; } DBG_Text.text += " Populate Done"; } #pragma kernel CSMain //FOR STYLUS // Thread group size #define thread_group_size_x 32 #define thread_group_size_y 1 #define thread_group_size_z 1 struct Particle { float3 position; float3 velocity; float speed; }; int nStylus_1_On; int nStylus_2_On; int num_ATT_Stylus; float targetStrength; float deltaTime; float damping; float outer_rad_mult; float zero_mirror_radius; float3 styl_1_0; float3 styl_1_1; float3 styl_1_2; float3 styl_1_3; float3 styl_1_4; float3 styl_1_5; float3 styl_1_6; float3 styl_1_7; float3 styl_1_8; float3 styl_1_9; float3 styl_1_10; float3 styl_1_11; //-------------------------------- float3 styl_2_0; float3 styl_2_1; float3 styl_2_2; float3 styl_2_3; float3 styl_2_4; float3 styl_2_5; float3 styl_2_6; float3 styl_2_7; float3 styl_2_8; float3 styl_2_9; float3 styl_2_10; float3 styl_2_11; //----------------------------------- float rad_1_0; float rad_1_1; float rad_1_2; float rad_1_3; float rad_1_4; float rad_1_5; float rad_1_6; float rad_1_7; float rad_1_8; float rad_1_9; float rad_1_10; float rad_1_11; //----------------------------------- float rad_2_0; float rad_2_1; float rad_2_2; float rad_2_3; float rad_2_4; float rad_2_5; float rad_2_6; float rad_2_7; float rad_2_8; float rad_2_9; float rad_2_10; float rad_2_11; //----------------------------------- D:\0._ArgosVU_Christmas_Work\Assets\Argos_Compute_Shader\ARGOS_StylusCompute.compute RWStructuredBuffer <Particle> particles; [numthreads(thread_group_size_x, thread_group_size_y, thread_group_size_z )] void CSMain ( uint3 Gid : SV_GroupID, uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID, uint GI : SV_GroupIndex ) { int index = DTid.x; //int index = DTid.x + DTid.y * thread_group_size_x * 32; bool bEdited = false; if(nStylus_1_On == 1) //FOR STYLUS 1 { float3 nDir; float fDist; float Or; float linEase; nDir = normalize(styl_1_0 - particles[index].position); fDist = distance(styl_1_0, particles[index].position); Or = (1+outer_rad_mult)*rad_1_0; if(fDist < Or) { linEase = (fDist - Or)/(rad_1_0 - Or); particles[index].velocity += targetStrength * nDir * deltaTime * linEase; } nDir = normalize(styl_1_1 - particles[index].position); fDist = distance(styl_1_1, particles[index].position); Or = (1+outer_rad_mult)*rad_1_1; if(fDist < Or) { linEase = (fDist - Or)/(rad_1_1 - Or); particles[index].velocity += targetStrength * nDir * deltaTime * linEase; bEdited = true; } nDir = normalize(styl_1_2 - particles[index].position); fDist = distance(styl_1_2, particles[index].position); Or = (1+outer_rad_mult)*rad_1_2; if(fDist < Or) { linEase = (fDist - Or)/(rad_1_2 - Or); particles[index].velocity += targetStrength * nDir * deltaTime * linEase; bEdited = true; } D:\0._ArgosVU_Christmas_Work\Assets\Argos_Compute_Shader\ARGOS_VacuumCompute.compute #pragma kernel CSMain //FOR Vacuum // Thread group size #define thread_group_size_x 32 #define thread_group_size_y 1 #define thread_group_size_z 1 struct Particle { float3 position; float3 velocity; float speed; }; int nStylus_1_On; int nStylus_2_On; int num_ATT_Stylus; float targetStrength; float deltaTime; float damping; float outer_rad_mult; float zero_mirror_radius; float3 styl_1_0; float3 styl_1_1; float3 styl_1_2; float3 styl_1_3; float3 styl_1_4; float3 styl_1_5; float3 styl_1_6; float3 styl_1_7; float3 styl_1_8; float3 styl_1_9; float3 styl_1_10; float3 styl_1_11; //-------------------------------- float3 styl_2_0; float3 styl_2_1; float3 styl_2_2; float3 styl_2_3; float3 styl_2_4; float3 styl_2_5; float3 styl_2_6; float3 styl_2_7; float3 styl_2_8; float3 styl_2_9; float3 styl_2_10; float3 styl_2_11; //----------------------------------- float rad_1_0; float rad_1_1; float rad_1_2; float rad_1_3; float rad_1_4; float rad_1_5; float rad_1_6; float rad_1_7; float rad_1_8; float rad_1_9; float rad_1_10; float rad_1_11; //----------------------------------- float rad_2_0; float rad_2_1; float rad_2_2; float rad_2_3; float rad_2_4; float rad_2_5; float rad_2_6; float rad_2_7; float rad_2_8; float rad_2_9; float rad_2_10; float rad_2_11; //----------------------------------- RWStructuredBuffer <Particle> particles; [numthreads(thread_group_size_x, thread_group_size_y, thread_group_size_z )] void CSMain ( uint3 Gid : SV_GroupID, uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID, uint GI : SV_GroupIndex ) { int index = DTid.x; //int index = DTid.x + DTid.y * thread_group_size_x * 32; float3 vZero; vZero.x = 0; vZero.y = 0; vZero.z = 0; if(nStylus_1_On == 1) //FOR STYLUS 1 { float3 nDir; float fDist; nDir = normalize(styl_1_0 - particles[index].position); fDist = distance(styl_1_0, particles[index].position); if(fDist < (1+outer_rad_mult)*rad_1_0) { particles[index].velocity += targetStrength * nDir * deltaTime; particles[index].position = vZero; } nDir = normalize(styl_1_1 - particles[index].position); fDist = distance(styl_1_1, particles[index].position); if(fDist < (1+outer_rad_mult)*rad_1_1) { particles[index].velocity += targetStrength * nDir * deltaTime; particles[index].position = vZero; } nDir = normalize(styl_1_2 - particles[index].position); fDist = distance(styl_1_2, particles[index].position); if(fDist < (1+outer_rad_mult)*rad_1_2) { particles[index].velocity += targetStrength * nDir * deltaTime; particles[index].position = vZero; } nDir = normalize(styl_1_3 - particles[index].position); fDist = distance(styl_1_3, particles[index].position);