Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Try to modify the velocity
#2
Hi!

There's quite a few problems with this code:

- Your compute shader does not declare any kernels. As a result, it won't do anything. You must add this line at the top:
Code:
#pragma kernel CSMain

- You're not checking whether the current thread can do any work. As a result your compute shader will access memory outside of the structured buffer and yield undefined behavior, including the chance of your game crashing. You must pass the total amount of particles to your shader and add this code at the beginning of your kernel:

Code:
if(id.x >= particleCount)
        return;

- You're using Time.deltaTime to set the velocity, which is expressed in m/s. As a result, the velocity will randomly change every frame. As usual when dealing with physics, you should only multiply by the time delta if adding an acceleration and in that case you should use the time delta passed to you as an argument to the solver's callback, not the frame's delta time.

- Math.CeilToInt does nothing, as you're already passing an int as argument.

Also note this code only does something if using the Compute backend, it won't work when using the Burst backend for obvious reasons (compute shaders run on the GPU, not the CPU).

kind regards,
Reply


Messages In This Thread
Try to modify the velocity - by a172862967 - 11-08-2024, 10:39 AM
RE: Try to modify the velocity - by josemendez - 12-08-2024, 07:44 AM
RE: Try to modify the velocity - by a172862967 - 12-08-2024, 09:55 AM
RE: Try to modify the velocity - by josemendez - 12-08-2024, 10:52 AM