Particle rendering method and apparatus
View Patent ↗The embodiments of the present disclosure provide a particle rendering method and apparatus, which relate to the technical field of image rendering. The method includes: obtaining state information of a target particle; obtaining a fall duration of the target particle if the state information is first state information indicating that no collision with the target particle occurred; obtaining a first position based on the fall duration and a fall speed of the target particle; and rendering the target particle to be at the first position.
1 . A particle rendering method, comprising:
obtaining state information of a target particle, wherein the state information of the target particle comprises values carried by a preset number of bits;
determining whether the state information is first state information indicating that no collision with the target particle occurred or second state information indicating that a collision with the target particle occurred;
in response to determining the state information being the first state information:
obtaining a fall duration of the target particle, wherein the fall duration of the target particle is obtained based on a time when the particle starts to fall and a current time;
obtaining a first position based on the fall duration and a fall speed of the target particle; and
rendering the target particle to be at the first position;
in response to determining the state information being the second state information:
obtaining a collision time of the target particle, the collision time indicating a fall duration of the target particle before the collision occurred;
obtaining a second position based on the collision time and the fall speed of the target particle; and
rendering the target particle to be at the second position.
2 . The particle rendering method according to claim 1 , further comprising:
obtaining a first depth value and a second depth value after obtaining the first position, the first depth value being a depth value of the first position in a screen space, and the second depth value being a scene depth value corresponding to the first position in the screen space;
determining whether the first depth value is greater than the second depth value;
in response to determining the first depth value being greater than the second depth value, changing the state information of the target particle to second state information indicating that a collision with the target particle occurred, and storing the fall duration as a collision time of the target particle, the collision time indicating a fall duration of the target particle before the collision occurred.
3 . The particle rendering method according to claim 2 , wherein the obtaining the first depth value comprises:
obtaining coordinate values of the first position in a world space based on coordinate values of the first position in a local space and a model matrix;
obtaining coordinate values of the first position in a view space based on coordinate values of the first position in the world space and a view matrix;
obtaining coordinate values of the first position in a clip space based on the coordinate values of the first position in the view space and a projection matrix;
normalizing the coordinate values of the first position in the clip space to obtain coordinate values of the first position in the screen space; and
obtaining the first depth value based on the coordinate values of the first position in the screen space.
4 . The particle rendering method according to claim 1 , further comprising:
in response to determining the state information being the second state information:
obtaining a collision position of the target particle, the collision position indicating a position where the target particle located when the collision occurred; and
rendering the target particle at the collision position.
5 . The particle rendering method according to claim 1 , further comprising:
obtaining a first depth value and a second depth value after obtaining the first position, the first depth value being a depth value of the first position in a screen space, and the second depth value being a scene depth value corresponding to the first position in the screen space;
determining whether the first depth value is greater than the second depth value;
in response to determining the first depth value being greater than the second depth value, changing the state information of the target particle to second state information indicating that a collision with the target particle occurred, and storing the first position as a collision position of the target particle, the collision position indicating a position where the target particle located when the collision occurred.
6 . The method according to claim 5 , wherein obtaining the first depth value comprises:
obtaining coordinate values of the first position in a world space based on coordinate values of the first position in a local space and a model matrix;
obtaining coordinate values of the first position in a view space based on coordinate values of the first position in the world space and a view matrix;
obtaining coordinate values of the first position in a clip space based on the coordinate values of the first position in the view space and a projection matrix;
normalizing the coordinate values of the first position in the clip space to obtain coordinate values of the first position in the screen space; and
obtaining the first depth value based on the coordinate values of the first position in the screen space.
7 . The particle rendering method according to claim 1 , further comprising:
controlling the particle to return to an initial position thereof and resetting the fall duration of the particle to zero when the fall duration of the particle reaches a duration threshold, and updating the state information of the target particle with the first state information.
8 . An electronic device, comprising:
a memory for storing a computer program; and
a processor that, when executing the computer program, causes the electronic device to implement a particle rendering method comprising:
obtaining state information of a target particle, wherein the state information of the target particle comprises values carried by a preset number of bits;
determining whether the state information is first state information indicating that no collision with the target particle occurred or second state information indicating that a collision with the target particle occurred;
in response to determining the state information being the first state information:
obtaining a fall duration of the target particle, wherein the fall duration of the target particle is obtained based on a time when the particle starts to fall and a current time;
obtaining a first position based on the fall duration and a fall speed of the target particle; and
rendering the target particle to be at the first position;
in response to determining the state information being the second state information:
obtaining a collision time of the target particle, the collision time indicating a fall duration of the target particle before the collision occurred;
obtaining a second position based on the collision time and the fall speed of the target particle; and
rendering the target particle to be at the second position.
9 . The electronic device according to claim 8 , wherein the processor is configured to:
obtain a first depth value and a second depth value after obtaining the first position, the first depth value being a depth value of the first position in a screen space, and the second depth value being a scene depth value corresponding to the first position in the screen space;
determine whether the first depth value is greater than the second depth value;
in response to the first depth value being greater than the second depth value, change the state information of the target particle to second state information indicating that a collision with the target particle occurred, and store the fall duration as a collision time of the target particle, the collision time indicating a fall duration of the target particle before the collision occurred.
10 . The electronic device according to claim 9 , wherein the processor is configured to:
obtain coordinate values of the first position in a world space based on coordinate values of the first position in a local space and a model matrix;
obtain coordinate values of the first position in a view space based on coordinate values of the first position in the world space and a view matrix;
obtain coordinate values of the first position in a clip space based on the coordinate values of the first position in the view space and a projection matrix;
normalize the coordinate values of the first position in the clip space to obtain coordinate values of the first position in the screen space; and
obtain the first depth value based on the coordinate values of the first position in the screen space.
11 . The electronic device according to claim 8 , wherein the processor is configured to:
in response to the state information being second state information indicating that a collision with the target particle:
obtain a collision position of the target particle, the collision position indicating a position where the target particle located when the collision occurred; and
render the target particle at the collision position.
12 . The electronic device according to claim 8 , wherein the processor is configured to:
obtain a first depth value and a second depth value after obtaining the first position, the first depth value being a depth value of the first position in a screen space, and the second depth value being a scene depth value corresponding to the first position in the screen space;
determine whether the first depth value is greater than the second depth value;
in response to the first depth value being greater than the second depth value, change the state information of the target particle to second state information indicating that a collision with the target particle occurred, and store the first position as a collision position of the target particle, the collision position indicating a position where the target particle located when the collision occurred.
13 . The electronic device according to claim 12 , wherein the processor is configured to:
obtain coordinate values of the first position in a world space based on coordinate values of the first position in a local space and a model matrix;
obtain coordinate values of the first position in a view space based on coordinate values of the first position in the world space and a view matrix;
obtain coordinate values of the first position in a clip space based on the coordinate values of the first position in the view space and a projection matrix;
normalize the coordinate values of the first position in the clip space to obtain coordinate values of the first position in the screen space; and
obtain the first depth value based on the coordinate values of the first position in the screen space.
14 . The electronic device according to claim 8 , wherein the processor is configured to:
control the particle to return to an initial position thereof and resetting the fall duration of the particle to zero when the fall duration of the particle reaches a duration threshold, and updating the state information of the target particle with the first state information.
15 . A non-transitory computer-readable storage medium stored thereon a computer program that, when executed by a computing device, causes the computing device to implement a particle rendering method comprising:
obtaining state information of a target particle, wherein the state information of the target particle comprises values carried by a preset number of bits;
determining whether the state information is first state information indicating that no collision with the target particle occurred or second state information indicating that a collision with the target particle occurred;
in response to determining the state information being the first state information:
obtaining a fall duration of the target particle, wherein the fall duration of the target particle is obtained based on a time when the particle starts to fall and a current time;
obtaining a first position based on the fall duration and a fall speed of the target particle; and
rendering the target particle to be at the first position;
in response to determining the state information being the second state information:
obtaining a collision time of the target particle, the collision time indicating a fall duration of the target particle before the collision occurred;
obtaining a second position based on the collision time and the fall speed of the target particle; and
rendering the target particle to be at the second position.
16 . The non-transitory computer-readable storage medium according to claim 15 , wherein the particle rendering method further comprises:
obtaining a first depth value and a second depth value after obtaining the first position, the first depth value being a depth value of the first position in a screen space, and the second depth value being a scene depth value corresponding to the first position in the screen space;
determining whether the first depth value is greater than the second depth value;
in response to the first depth value being greater than the second depth value, changing the state information of the target particle to second state information indicating that a collision with the target particle occurred, and storing the fall duration as a collision time of the target particle, the collision time indicating a fall duration of the target particle before the collision occurred.
17 . The non-transitory computer-readable storage medium according to claim 15 , wherein the particle rendering method further comprises:
in response to the state information being second state information indicating that a collision with the target particle:
obtaining a collision position of the target particle, the collision position indicating a position where the target particle located when the collision occurred; and
rendering the target particle at the collision position.