Fluid rendering method, device, electronic device and storage medium
By adopting at least two unidirectional smoothing processing methods in the fluid rendering algorithm, the problem of long-term depth texture bilateral filtering smoothing processing in the prior art is solved, and efficient fluid rendering on the mobile terminal is achieved.
Patent Information
- Application Number
- CN202110183971.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-02-10
- Publication Date
- 2025-03-18
- Estimated Expiration
- 2041-02-10
AI Technical Summary
In the existing fluid rendering algorithm, the bilateral filtering smoothing processing of depth textures takes a long time, making it impossible to achieve efficient fluid rendering on the mobile side.
At least two unidirectional smoothing processes are used to perform depth smoothing. The directions of the adjacent two unidirectional smoothing processes are different. The adjacent pixel points are other pixel points in the same preset range as the target pixel points in the same direction as the unidirectional smoothing process.
It greatly reduces the time-consuming of smoothing processing, such as 80% reduction, and enables the fluid rendering algorithm to be applied to devices such as mobile terminals.
Smart Images

Figure CN114943793B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the technical field of computer graphics, and in particular to a fluid rendering method, device, electronic device, and computer-readable storage medium. Background Art
[0002] Fluid simulation is a very important technology in computer graphics and animation. Realistic fluid will bring users a more realistic experience.
[0003] The commonly used fluid simulation algorithm at present is the SSF (Screen Space Fluid Rendering) algorithm. However, in the SSF algorithm, the most time-consuming and computationally intensive process is the use of bilateral filtering to smooth the depth texture. Currently, only high-end graphics cards (for example, core frequencies higher than 1410 / 1710MHz, and video memory frequencies higher than 14000MHz) can complete this process smoothly. This makes the SSF algorithm currently unavailable for application on mobile devices. Summary of the invention
[0004] Embodiments of the present disclosure provide a fluid rendering method, device, electronic device, and computer-readable storage medium that overcome the above problems or at least partially solve the above problems.
[0005] In a first aspect, a fluid rendering method is provided, the method comprising:
[0006] Get the fluid to be rendered, render the fluid to the screen space, and store the initial depth value of the fluid in the screen space in the texture image;
[0007] Taking any pixel in the texture image as the target pixel, performing an even number of unidirectional smoothing operations on the depth value of the target pixel according to the depth values of the neighboring pixels of the target pixel and the distance between the neighboring pixels and the target pixel, and obtaining the updated depth value of the target pixel according to the result of the smoothing operation;
[0008] Perform lighting shading based on the updated depth values of all pixels to generate fluid rendering effects, and output the rendering effects to the screen for display;
[0009] The direction of the unidirectional smoothing process is horizontal or vertical, and the directions of two adjacent unidirectional smoothing processes are different. The neighboring pixel points are other pixel points within a preset range that are on the same straight line as the target pixel point in the direction of the unidirectional smoothing process.
[0010] In a second aspect, an embodiment of the present invention provides a fluid rendering device, comprising:
[0011] An initial depth value storage module, used for acquiring the fluid to be rendered, rendering the fluid to the screen space, and storing the initial depth value of the fluid in the screen space in the texture image;
[0012] A depth value updating module is used to take any pixel in the texture image as a target pixel, perform an even number of unidirectional smoothing processes on the depth value of the target pixel according to the depth values of the neighboring pixels of the target pixel and the distances between the neighboring pixels and the target pixel, and obtain an updated depth value of the target pixel according to the result of the smoothing process;
[0013] The shading module is used to perform lighting shading according to the updated depth values of all pixels, generate fluid rendering effects, and output the rendering effects to the screen for display;
[0014] The direction of the unidirectional smoothing process is horizontal or vertical, and the directions of two adjacent unidirectional smoothing processes are different. The neighboring pixel points are other pixel points within a preset range that are on the same straight line as the target pixel point in the direction of the unidirectional smoothing process.
[0015] In a third aspect, an embodiment of the present invention provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of the method provided in the first aspect are implemented.
[0016] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the method provided in the first aspect.
[0017] In a fifth aspect, an embodiment of the present invention provides a computer program product, which includes computer instructions, and when the computer instructions are executed by a processor, the method provided in the first aspect is implemented.
[0018] The fluid rendering method, device, electronic device and computer-readable storage medium provided by the embodiments of the present invention use at least two unidirectional smoothing processes to perform depth smoothing, and the directions of the two adjacent unidirectional smoothing processes are different. Since the neighboring pixel points are other pixel points within a preset range that are on the same straight line as the target pixel point in the direction of the unidirectional smoothing process, the time consumption is greatly reduced (for example, the time consumption can be reduced by 80%) on the basis of achieving a smoothing effect with similar appearance, and can be applied to devices such as mobile terminals. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to more clearly illustrate the technical solutions in the embodiments of the present disclosure, the drawings required for describing the embodiments of the present disclosure are briefly introduced below.
[0020] Figure 1A schematic diagram of a flow chart of a fluid rendering method provided by an embodiment of the present disclosure;
[0021] Figure 2 A schematic diagram of a flow chart of another fluid rendering method provided by an embodiment of the present disclosure;
[0022] Figure 3 A schematic diagram of the structure of a fluid rendering device provided by an embodiment of the present disclosure;
[0023] Figure 4 A schematic diagram of the structure of an electronic device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0024] Embodiments of the present disclosure are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present disclosure, and cannot be interpreted as limiting the present invention.
[0025] It will be understood by those skilled in the art that, unless expressly stated, the singular forms "one", "an" and "the" used herein may also include plural forms. It should be further understood that the term "comprising" used in the specification of the present disclosure refers to the presence of features, integers, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or groups thereof. It should be understood that when we refer to an element as being "connected" or "coupled" to another element, it may be directly connected or coupled to the other element, or there may be an intermediate element. In addition, the "connection" or "coupling" used herein may include wireless connection or wireless coupling. The term "and / or" used herein includes all or any unit and all combinations of one or more associated listed items.
[0026] When rendering the fluid on the screen for display, the depth texture needs to be smoothed. In the prior art, there are two main methods for smoothing the depth texture, namely, a method using Gaussian filtering and a method using bilateral filtering:
[0027] The Gaussian filter smoothing method is to treat the depth texture as a picture and use Gaussian weights to perform a filtering operation. However, there is a problem with the Gaussian filter smoothing method. The Gaussian filter does not consider the depth value, it only considers the distance from the current pixel to the center pixel. This causes the Gaussian filter to obviously blur the boundary, making the boundary and the background or the fluid in the distance look merged together.
[0028] The bilateral filtering smoothing method can well preserve the boundaries, but there are performance issues with bilateral filtering. For a bilateral filter with a kernel diameter of 20, each pixel has to process 20×20=400 neighboring pixels. It is currently only suitable for application on high-end independent graphics cards. For mid- and low-end independent graphics cards, it will seriously slow down the rendering speed. Therefore, it is even less likely to be suitable for mobile terminals, such as mobile phones, tablets, and computer devices with integrated graphics cards.
[0029] The fluid rendering method, device, electronic device and computer-readable storage medium provided in the present disclosure are intended to solve the above technical problems existing in the prior art when smoothing depth textures.
[0030] The technical solution of the present invention and how the technical solution of the present invention solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present invention will be described below in conjunction with the accompanying drawings.
[0031] The present disclosure provides a fluid rendering method, such as Figure 1 As shown, according to the embodiments of the present disclosure, the step of smoothing the depth value in the prior art can be improved, so that the fluid rendering method according to the embodiments of the present disclosure can be applied to the mobile terminal. When the depth value is smoothed, the present disclosure adopts multiple horizontal and vertical unidirectional smoothing of the depth value. Compared with the bilateral filtering used in the prior art, the number of adjacent pixel points required in the smoothing process is greatly reduced, so that the fluid rendering method according to the embodiments of the present disclosure can be applied to the mobile terminal.
[0032] Figure 2 A flow chart of another fluid rendering method provided by an embodiment of the present disclosure is shown as follows: Figure 2 As shown, the method includes:
[0033] S101. Obtain a fluid to be rendered, render the fluid to a screen space, and store an initial depth value of the fluid in the screen space in a texture image.
[0034] The fluid rendering method disclosed in the present invention directly restores the fluid surface in the screen space based on the fluid rendering algorithm in the screen space, and the operation dimension is reduced from three dimensions to two dimensions. After obtaining the fluid to be rendered, the fluid is first rendered to the screen space according to the current projection matrix and view matrix, the initial depth value and thickness information of the fluid are obtained, and then the initial depth value is stored in a texture image, and the thickness information is stored in another texture image.
[0035] S102, taking any pixel in the texture image as a target pixel, performing an even number of unidirectional smoothing operations on the depth value of the target pixel according to the depth values of the neighboring pixels of the target pixel and the distances between the neighboring pixels and the target pixel, and obtaining an updated depth value of the target pixel according to the result of the smoothing operation.
[0036] When the present disclosure performs smoothing on the depth value, no matter which direction the smoothing is performed, the neighboring pixel points are other pixel points within a preset range that are on the same straight line as the pixel point in the direction of the unidirectional smoothing.
[0037] For example, in horizontal unidirectional smoothing, if the coordinates of the target pixel are (0,0) and the neighborhood is set to 2n, then the neighboring pixels are (-n,0), (-n+1,0), (-n+2,0), … (1,0), (2,0), …, (n-1,0), (n,0). There are 2n neighboring pixels in total; in vertical unidirectional smoothing, the neighboring pixels of the target pixel are (0,-n), (0,-n+1), (0,-n+2), … (0,1), (0,2), …, (0,n-1), (0,n).
[0038] Compared with the number of neighboring pixels in the existing bilateral filtering (for example, the neighboring pixels in the existing bilateral filtering can be n*n pixels around the pixel, that is, if the pixel is the center of a square with a side length of 2n+1, all pixels in this square with a side length of 2n+1 are the neighboring pixels of the pixel, that is, the bilateral filtering needs to consider (2n+1) 2 -1 depth value of a neighboring pixel point), the neighboring pixel points referenced by the smoothing process disclosed in the present invention are much smaller than the neighboring pixel points of the existing bilateral filtering, thereby being able to increase the speed of the smoothing process.
[0039] It has been verified in practice that the present invention can achieve a smoothing effect similar to that of the existing bilateral filtering method while greatly reducing the time consumption, so that the fluid rendering algorithm of the present invention can be applied to mobile terminals.
[0040] The directions of the even-numbered unidirectional smoothing processes according to the embodiments of the present disclosure are different. Specifically, each pixel point will be treated as an object to be smoothed at least twice (once horizontally and once vertically), although the neighboring pixels of each pixel point during the smoothing process are much smaller than the neighboring pixels of the bilateral filtering, but because the number of smoothing processes is greater and the directions of the two adjacent unidirectional smoothing processes are different, compared with the bilateral filtering in the prior art, when smoothing the pixels, only one horizontal smoothing is used, that is, each pixel point will only be treated as an object to be smoothed once, which can reduce the processing time.
[0041] It should be noted that the number of smoothing processes disclosed herein is an even number and the directions of two adjacent unidirectional smoothing processes are different. That is to say, if the number of smoothing processes is two, the directions of the two unidirectional smoothing processes are horizontal-vertical, or vertical-horizontal; if the number of smoothing processes is four, the directions of the four unidirectional processes are horizontal-vertical-horizontal-vertical, or vertical-horizontal-vertical-horizontal. It can be seen that the number of horizontal smoothing processes and vertical smoothing processes disclosed herein are the same.
[0042] Specifically, let the target pixel position be p0, and the smoothing kernel size be 9. Then, for each unidirectional smoothing, the influence of the surrounding 8 pixels on the target pixel needs to be considered. Let the position offset be D = (a, b). If the current smoothing is horizontal, then b=0; otherwise, a=0, Where W and H represent the width and height of the texture image respectively. The coordinates of the 8 neighboring pixels are P0-4D, P0-3D, P0-2D, P0-D, P0+D, P0+2D, P0+3D, and P0+4D respectively. In each unidirectional smoothing process, the depth weighted sum of the target pixel in this unidirectional smoothing process is obtained according to the distance between the 8 neighboring pixels and the target pixel and the depth weighted sum of the 8 neighboring pixels obtained in the previous unidirectional smoothing process. When the number of unidirectional smoothing processes reaches the preset value, the depth value of each pixel after smoothing can be obtained.
[0043] S103, performing lighting shading according to the updated depth values of all pixels to generate a rendering effect of the fluid, and outputting the rendering effect to the screen for display.
[0044] In one embodiment, the smoothed depth texture can be used to further restore the surface normal of the fluid, and the smoothed depth texture and the normal can be used for lighting shading to obtain the final fluid rendering effect.
[0045] The fluid rendering method disclosed in the present invention improves the depth smoothing performed by the bilateral filtering method in the prior art into at least two unidirectional smoothing processes, and the directions of the two adjacent unidirectional smoothing processes are different. Since the neighboring pixel points are other pixel points within a preset range that are on the same straight line as the target pixel point in the direction of the unidirectional smoothing process, the time consumption is greatly reduced while achieving a smoothing effect with a similar look and feel, and the method can be applied to devices such as mobile terminals.
[0046] Based on the above embodiments, as an optional embodiment, the depth value of the target pixel is subjected to an even number of unidirectional smoothing processes, including:
[0047] S201. In each unidirectional smoothing process, a weighted sum of the depths of the target pixel in this unidirectional smoothing process is obtained according to the distances between the neighboring pixels and the target pixel and the weighted sum of the depths of the neighboring pixels obtained in the previous unidirectional smoothing process.
[0048] The present invention obtains the depth weighted sum and weighted sum of the target pixel in this unidirectional smoothing process each time the unidirectional smoothing process is performed. The present invention obtains the depth weighted sum of the target pixel in this unidirectional smoothing process according to the distance between the neighboring pixel and the target pixel and the depth weighted sum of the neighboring pixel.
[0049] Specifically, for each neighboring pixel point, the depth weight of the neighboring pixel point relative to the target pixel point can be obtained according to the distance between the neighboring pixel point and the target pixel point and the weighted sum of the depths of the neighboring pixel point obtained in the last unidirectional smoothing process. Then, the weighted sum of the depths of all neighboring pixels with respect to the target pixel point is calculated, and the sum result is used as the weighted sum of the depths obtained by the target pixel point in this unidirectional smoothing process.
[0050] It should be noted that, in the first unidirectional smoothing process among the even-numbered unidirectional smoothing processes, the present invention uses, for each neighboring pixel of the target pixel, the initial depth value of the neighboring pixel as the weighted sum of the depths obtained by the neighboring pixel in the previous unidirectional smoothing process.
[0051] As an optional embodiment, the present disclosure obtains the depth weighted sum S of the target pixel point p0 in this unidirectional smoothing process according to the following formula:
[0052]
[0053] Among them, e represents a natural constant, R represents a set of pixels consisting of neighboring pixels p, and S p ′ represents the weighted sum of the depths of the neighboring pixel p obtained in the last unidirectional smoothing process; |p-p0| 2 represents the square of the distance between the neighboring pixel point p and the target pixel point p0, and r represents a preset coefficient, which can be set according to actual applications and requirements.
[0054] In the process of obtaining the weighted sum of the depth of the target pixel in this unidirectional smoothing processing disclosed in the present invention, by calculating the square of the distance between the target pixel and the adjacent pixels, the updated depth value of the target pixel can both partially maintain the original characteristics and have an obvious smoothing effect.
[0055] S202, obtaining the weight sum of the target pixel in this unidirectional smoothing process according to the distance between the neighboring pixel and the target pixel and the weight sum of the neighboring pixel in the previous unidirectional smoothing process.
[0056] Specifically, for each neighboring pixel point, the weight of the neighboring pixel point to the target pixel point is obtained according to the distance between the neighboring pixel point and the target pixel point and the sum of the weights of the neighboring pixel point obtained in the last unidirectional smoothing process;
[0057] If the sum of the weights of the target pixel obtained in the previous unidirectional smoothing process is greater than the third preset threshold, the sum of the weights of all neighboring pixels to the target pixel is used as the sum of the weights of the target pixel obtained in this unidirectional smoothing process;
[0058] If the sum of the weights of the target pixel obtained in the last unidirectional smoothing process is not greater than the third preset threshold, the negative value of the sum of the weights of all neighboring pixels to the target pixel is used as the sum of the weights of the target pixel obtained in this unidirectional smoothing process.
[0059] When calculating the weight sum of the target pixel point, the present invention ensures that the weight sum can be less than or equal to 0 when the original depth of the pixel point is 0 by considering the size relationship between the weight sum of the target pixel point obtained in the last unidirectional smoothing process and the third preset threshold. In other words, if the weight sum is less than the third preset threshold, it is considered that the initial depth value of the pixel point is 0, and the initial depth value of the pixel point is indicated by explicitly adding a negative sign.
[0060] As those skilled in the art understand, if the initial depth value of a pixel is 0, it means that the pixel has no fluid. Through the above operation, after smoothing, the pixel that originally had no fluid still has no fluid, ensuring the degree of simulation of the rendering. The third preset threshold value of the present disclosure is a number slightly greater than 0.
[0061] As an optional embodiment, the present disclosure obtains the weight sum of the target pixel point obtained in this unidirectional smoothing process according to the following formula:
[0062] When W′ is greater than the third preset threshold y,
[0063] When W′ is not greater than the third preset threshold y,
[0064] Where e represents a natural constant, R represents a pixel set consisting of neighboring pixel points p, and W′ represents the weight sum of pixel point p0 obtained in the last unidirectional smoothing process; W p ′ represents the weight sum of neighboring pixels obtained in the last unidirectional smoothing process; |p-p0| 2 represents the square of the distance between the neighboring pixel point p and the target pixel point p0, and r represents a preset coefficient, which can be set according to actual applications and requirements.
[0065] On the basis of the above embodiments, the present disclosure performs at least two unidirectional smoothing processes on the depth value of the target pixel to obtain the updated depth value of the target pixel, and further includes:
[0066] The updated depth value of the target pixel is obtained according to the weighted sum of the depths and the weight sum obtained by the target pixel in the last unidirectional smoothing process.
[0067] After the number of unidirectional smoothing processes reaches a preset condition, the present disclosure needs to perform a normalization operation to obtain a smoothed result. The normalization operation of the present disclosure may be to divide the weighted sum of the last smoothing depth by the weighted sum.
[0068] Based on the above embodiments, as an optional embodiment, obtaining an updated depth value of a target pixel point according to a depth weighted sum and a weight sum obtained by a unidirectional smoothing process of the target pixel point includes:
[0069] If the weight sum obtained by the last unidirectional smoothing process of the target pixel in the even number of unidirectional smoothing processes is greater than the fourth preset threshold, the absolute value of the quotient of the weighted sum of the depth obtained by the target pixel in the last unidirectional smoothing process and the weight sum is used as the updated depth value of the target pixel;
[0070] If the sum of the weights of the target pixel obtained in the last unidirectional smoothing process is not greater than the fourth preset threshold, the updated depth value of the target pixel is 0.
[0071] It should be noted that the purpose of smoothing is to make the shape of the fluid smooth, rather than to expand the fluid. The most typical expansion is that a position where there was no fluid originally becomes filled with fluid. Therefore, the present disclosure sets a fourth preset threshold and updates the depth of pixels whose weights and depths are not greater than the fourth preset threshold to 0, thereby ensuring that there is still no fluid in the position where there was no fluid originally. The fourth preset threshold of the present disclosure is slightly greater than 0, and the magnitude relationship between the fourth preset threshold and the third preset threshold is not specifically limited. For example, the third preset threshold can be equal to the fourth preset threshold.
[0072] Based on the above embodiments, as an optional embodiment, the texture image of the present invention is a dual-channel texture image, wherein the first channel and the second channel of each pixel are respectively used to record the depth weighted sum and the weight sum obtained by each unidirectional smoothing process of the corresponding pixel.
[0073] The depth value of the target pixel is smoothed in one direction an even number of times, and also includes:
[0074] After obtaining the depth weighted sum and the weight sum of the target pixel point obtained in each unidirectional smoothing process, the depth weighted sum and the weight sum obtained in each unidirectional smoothing process are recorded in the first channel and the second channel of the target pixel point respectively.
[0075] That is, the present disclosure records the weight sum and the depth weighted sum in two channels of the texture image, so that when performing unidirectional smoothing processing, the depth weighted sum and the weight sum can be obtained from the two channels, which is faster in data acquisition.
[0076] Furthermore, in order to further improve the operation speed, the present disclosure also involves the following steps before performing the first unidirectional smoothing process on the target pixel point:
[0077] Determine whether the initial depth value of the target pixel is 0;
[0078] If the initial depth value of the target pixel is 0, the weighted sum of the depths and the weight sum recorded in the first channel and the second channel of the target pixel are set to 0, and the subsequent unidirectional smoothing process for the target pixel is skipped;
[0079] If the initial depth value of the target pixel is not 0, the target pixel is subjected to a first unidirectional smoothing process.
[0080] If the initial depth value of the target pixel is 0, it means that there is no fluid at the pixel, and there is no need to smooth the pixel, so the unidirectional smoothing of the pixel can be skipped, that is, no unidirectional smoothing is performed on the pixel. Further, the weighted sum of the depth and the weight sum of the pixel recorded by the first channel and the second channel is set to 0, which is equivalent to reducing the use of channels, reducing the occupation of memory and buffer, and improving time efficiency.
[0081] When performing the nth (n is an even number) unidirectional smoothing process on the target pixel point, if the obtained weight sum is less than the second preset threshold, the depth weighted sum and the weight sum of the target pixel point recorded by the first channel and the second channel will be directly set to 0, so that the depth weighted sum and the weight sum obtained in all subsequent unidirectional smoothing processes are also 0, and can also be directly determined to be 0 in the final normalization operation.
[0082] The second preset threshold of the present disclosure is slightly greater than 0. The present disclosure does not specifically limit the size relationship between the first preset threshold, the second preset threshold, the third preset threshold and the fourth preset threshold, and the first preset threshold, the second preset threshold, the third preset threshold and the fourth preset threshold can be set according to actual needs and application conditions.
[0083] The present disclosure provides a fluid rendering device, such as Figure 3 As shown, the fluid rendering device may include: an initial depth value storage module 101, a depth value update module 102 and a coloring module 103, wherein:
[0084] The initial depth value storage module 101 is used to obtain the fluid to be rendered, render the fluid to the screen space, and store the initial depth value of the fluid in the screen space in the texture image;
[0085] The depth value updating module 102 is used to take any pixel in the texture image as a target pixel, perform an even number of unidirectional smoothing processes on the depth value of the target pixel according to the depth values of the neighboring pixels of the target pixel and the distances between the neighboring pixels and the target pixel, and obtain an updated depth value of the target pixel according to the result of the smoothing process;
[0086] The shading module 103 is used to perform lighting shading according to the updated depth values of all pixels, generate a rendering effect of the fluid, and output the rendering effect to the screen for display;
[0087] The directions of two adjacent one-way smoothing processes are different, and the neighboring pixel points are other pixel points within a preset range that are on the same straight line as the target pixel point in the direction of the one-way smoothing process.
[0088] The fluid rendering device provided by the embodiment of the present invention specifically executes the above method embodiment process. For details, please refer to the content of the above fluid rendering method embodiment, which will not be repeated here. The fluid rendering device provided by the embodiment of the present invention improves the deep smoothing of the bilateral filtering method used in the prior art into at least two unidirectional smoothing processes, and the directions of the two adjacent unidirectional smoothing processes are different. Since the neighboring pixel points are other pixel points within a preset range that are on the same straight line as the target pixel point in the direction of the unidirectional smoothing process, the time consumption is greatly reduced on the basis of achieving a smoothing effect with a similar look and feel, and it can be applied to devices such as mobile terminals.
[0089] Based on the above embodiments, as an optional embodiment, the depth value updating module includes a smoothing processing submodule that performs an even number of unidirectional smoothing processes on the depth value of the target pixel point, and the smoothing processing submodule includes:
[0090] A depth weighted sum acquisition unit is used to obtain the depth weighted sum of the target pixel in the current unidirectional smoothing process according to the distance between the neighboring pixels and the target pixel and the depth weighted sum of the neighboring pixels obtained in the previous unidirectional smoothing process during each unidirectional smoothing process;
[0091] The weight sum acquisition unit is used to obtain the weight sum of the target pixel in this unidirectional smoothing process according to the distance between the neighboring pixel and the target pixel and the weight sum of the neighboring pixel obtained in the previous unidirectional smoothing process.
[0092] Based on the above embodiments, as an optional embodiment, the smoothing processing submodule further includes:
[0093] The initial value setting unit is used to use the initial depth value of the neighboring pixel points as the weighted sum of the depths obtained by the neighboring pixel points in the previous unidirectional smoothing process during the first unidirectional smoothing process in an even number of unidirectional smoothing processes, and use the preset value as the weight sum obtained by the neighboring pixel points in the previous unidirectional smoothing process.
[0094] Based on the above embodiments, as an optional embodiment, the texture image includes a dual-channel texture image, wherein the first channel and the second channel of each pixel are respectively used to record the depth weighted sum and the weight sum obtained by each unidirectional smoothing process of the corresponding pixel.
[0095] The smoothing submodule also includes:
[0096] After obtaining the depth weighted sum and weight sum obtained by each unidirectional smoothing process for the target pixel point, the depth weighted sum and weight sum obtained by each unidirectional smoothing process are recorded in the first channel and the second channel of the target pixel point respectively.
[0097] Based on the above embodiments, as an optional embodiment, the smoothing processing submodule is further used for:
[0098] Before performing the first unidirectional smoothing process on the target pixel, determine whether the initial depth value of the target pixel is 0;
[0099] If the initial depth value of the target pixel is 0, the depth weighted sum and the weight sum of the target pixel are set to 0, and an even number of unidirectional smoothing processes are excluded for the target pixel, and the updated depth value of the target pixel is set to 0;
[0100] If the initial depth value of the target pixel is not 0, the target pixel is subjected to unidirectional smoothing.
[0101] Based on the above embodiments, as an optional embodiment, the smoothing processing submodule further includes:
[0102] A negative number adjustment unit is used to determine the difference between the initial depth value of the target pixel and the first preset threshold value during the first unidirectional smoothing process, and if the initial depth value of the target pixel is less than the first preset threshold value, update the weight sum of the target pixel obtained during the current unidirectional smoothing process to a negative number;
[0103] Among them, the first preset threshold is greater than 0.
[0104] Based on the above embodiments, as an optional embodiment, the smoothing processing submodule further includes:
[0105] an updating unit, configured to record the depth weighted sum and the weight sum obtained by each unidirectional smoothing process in the first channel and the second channel of the target pixel point respectively, and if the current unidirectional smoothing process is the nth unidirectional smoothing process and the weight sum obtained by the current unidirectional smoothing process of the target pixel point is less than a second preset threshold, then update the depth weighted sum and the weight sum recorded in the first channel and the second channel of the target pixel point respectively to 0;
[0106] Wherein, n is an even number, and the second preset threshold is greater than 0.
[0107] Based on the above embodiments, as an optional embodiment, the depth weighting and acquisition unit includes:
[0108] A neighboring depth weighted acquisition subunit is used to obtain, for each neighboring pixel, a depth weight of the neighboring pixel with respect to the target pixel according to the distance between the neighboring pixel and the target pixel and the weighted sum of the depths of the neighboring pixel obtained in the last unidirectional smoothing process;
[0109] The target depth weighted acquisition subunit is used to take the weighted sum of the depths of all neighboring pixels with respect to the target pixel as the weighted sum of the depths of the target pixel obtained in this unidirectional smoothing process.
[0110] Based on the above embodiments, as an optional embodiment, the weighting and obtaining unit includes:
[0111] A neighbor weight acquisition subunit is used to obtain, for each neighbor pixel, the weight of the neighbor pixel with respect to the target pixel according to the distance between the neighbor pixel and the target pixel and the sum of the weights of the neighbor pixel obtained in the last unidirectional smoothing process;
[0112] a target weight sum acquisition subunit, configured to take the sum of the weights of all neighboring pixels to the target pixel as the sum of the weights of the target pixel obtained in the current unidirectional smoothing process if the sum of the weights obtained in the previous unidirectional smoothing process for the target pixel is greater than a third preset threshold;
[0113] If the sum of the weights of the target pixel obtained in the previous unidirectional smoothing process is not greater than the third preset threshold, the negative value of the sum of the weights of all neighboring pixels to the target pixel is used as the sum of the weights of the target pixel obtained in this unidirectional smoothing process;
[0114] Among them, the third preset threshold is greater than 0.
[0115] Based on the above embodiments, as an optional embodiment, the depth value updating module includes a depth value updating submodule for obtaining an updated depth value of a target pixel according to a result of smoothing processing, and the depth value updating submodule is specifically used for:
[0116] If the weight sum obtained by the last unidirectional smoothing process of the target pixel in the even number of unidirectional smoothing processes is greater than the fourth preset threshold, the absolute value of the quotient of the weighted sum of the depth obtained by the target pixel in the last unidirectional smoothing process and the weight sum is used as the updated depth value of the target pixel;
[0117] If the sum of the weights of the target pixel obtained in the last unidirectional smoothing process is not greater than the fourth preset threshold, the updated depth value of the target pixel is 0;
[0118] Among them, the fourth preset threshold is greater than 0.
[0119] An electronic device is provided in an embodiment of the present disclosure, and the electronic device includes: a memory and a processor; at least one program, which is stored in the memory and is used to, when executed by the processor, obtain a fluid to be rendered, render the fluid to a screen space, and store an initial depth value of the fluid in the screen space in a texture image; take any pixel point in the texture image as a target pixel point, perform a unidirectional smoothing process on the depth value of the target pixel point an even number of times according to the depth values of the neighboring pixels of the target pixel point and the distance between the neighboring pixels and the target pixel point, and obtain an updated depth value of the target pixel point according to the result of the smoothing process; perform illumination shading according to the updated depth values of all pixels to generate a rendering effect of the fluid, and output the rendering effect to a screen for display; wherein the direction of the unidirectional smoothing process is horizontal or vertical, and the directions of two adjacent unidirectional smoothing processes are different, and the neighboring pixels are other pixels within a preset range that are on the same straight line as the target pixel point in the direction of the unidirectional smoothing process. Compared with the prior art, the present invention can achieve: improving the depth smoothing using the bilateral filtering method in the prior art to at least two unidirectional smoothing processes, and the directions of the two adjacent unidirectional smoothing processes are different. Since the neighboring pixel points are other pixel points within a preset range that are on the same straight line as the target pixel point in the direction of the unidirectional smoothing process, the time consumption is greatly reduced on the basis of achieving a smoothing effect with a similar look and feel, and the invention can be applied to devices such as mobile terminals.
[0120] In an alternative embodiment, an electronic device is provided, such as Figure 4 As shown, Figure 4The electronic device 600 shown includes: a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 601, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 602 or a program loaded from a storage device 606 or a storage device 608 into a random access memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the electronic device 600 are also stored. The processing device 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.
[0121] Typically, the following devices may be connected to the I / O interface 605: an input device 606 including, for example, a touch screen, a touchpad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 607 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 606 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 609. The communication device 609 may allow the electronic device 600 to communicate with other devices wirelessly or by wire to exchange data. Although Figure 4 The electronic device 600 is shown with various devices, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.
[0122] The disclosed embodiment provides a computer-readable storage medium, which stores a computer program, and when the computer-readable storage medium is run on a computer, the computer can execute the corresponding content in the aforementioned method embodiment. Compared with the prior art, the bilateral filtering method used in the prior art for deep smoothing is improved to at least two unidirectional smoothing processes, and the directions of the two adjacent unidirectional smoothing processes are different. Since the neighboring pixel points are other pixel points within a preset range that are on the same straight line as the target pixel point in the direction of the unidirectional smoothing process, the time consumption is greatly reduced on the basis of obtaining a smoothing effect with a similar look and feel, and it can be applied to devices such as mobile terminals.
[0123] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.
[0124] The disclosed embodiment provides a computer-readable storage medium, which stores a computer program, and when the computer-readable storage medium is run on a computer, the computer can execute the corresponding content in the aforementioned method embodiment. Compared with the prior art, the bilateral filtering method used in the prior art for deep smoothing is improved to at least two unidirectional smoothing processes, and the directions of the two adjacent unidirectional smoothing processes are different. Since the neighboring pixel points are other pixel points within a preset range that are on the same straight line as the target pixel point in the direction of the unidirectional smoothing process, the time consumption is greatly reduced on the basis of obtaining a smoothing effect with a similar look and feel, and it can be applied to devices such as mobile terminals.
[0125] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer program product. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a non-transitory computer-readable medium, and the computer program contains a program code for executing the method shown in the flowchart. In such an embodiment, the computer program product can be downloaded and installed from a network through a communication device 609, or installed from a storage device 606, or installed from a ROM 602. When the computer program product is executed by the processing device 601, the above-mentioned functions defined in the fluid rendering method of the embodiment of the present disclosure are executed.
[0126] The above are only some embodiments of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.
Claims
1. A fluid rendering method, characterized in that: include: Obtaining a fluid to be rendered, rendering the fluid to a screen space, and storing an initial depth value of the fluid in the screen space in a texture image; Taking any pixel in the texture image as a target pixel, performing an even number of unidirectional smoothing operations on the depth value of the target pixel according to the depth values of the neighboring pixels of the target pixel and the distance between the neighboring pixels and the target pixel, and obtaining an updated depth value of the target pixel according to the result of the smoothing operation; Performing lighting shading according to the updated depth values of all pixels to generate a rendering effect of the fluid, and outputting the rendering effect to a screen for display; Among them, the direction of the unidirectional smoothing processing is horizontal or vertical, and the directions of two adjacent unidirectional smoothing processing are different, and the neighboring pixel points are other pixel points within a preset range that are on the same straight line as the target pixel point in the direction of the unidirectional smoothing processing.
2. The fluid rendering method according to claim 1, characterized in that: The performing an even number of unidirectional smoothing processes on the depth value of the target pixel point comprises: In each unidirectional smoothing process, the weighted sum of the depth of the target pixel in this unidirectional smoothing process is obtained according to the distance between the neighboring pixel and the target pixel and the weighted sum of the depth of the neighboring pixel obtained in the previous unidirectional smoothing process; The weight sum of the target pixel in this unidirectional smoothing process is obtained according to the distance between the neighboring pixel and the target pixel and the weight sum of the neighboring pixel obtained in the previous unidirectional smoothing process.
3. The fluid rendering method according to claim 2, characterized in that: The performing an even number of unidirectional smoothing processes on the depth value of the target pixel point comprises: During the first unidirectional smoothing process in the even-numbered unidirectional smoothing processes, the initial depth values of the neighboring pixels are used as the weighted sum of the depths obtained by the neighboring pixels in the previous unidirectional smoothing process, and the preset value is used as the weight sum obtained by the neighboring pixels in the previous unidirectional smoothing process.
4. The fluid rendering method according to claim 2, characterized in that: The texture image comprises a dual-channel texture image, wherein the first channel and the second channel of each pixel point are respectively used to record the depth weighted sum and the weight sum obtained by each unidirectional smoothing process of the corresponding pixel point; The performing an even number of unidirectional smoothing processes on the depth value of the target pixel point also includes: After obtaining the depth weighted sum and the weighted sum obtained by each unidirectional smoothing process for the target pixel, the obtained depth weighted sum and the weighted sum are recorded in the first channel and the second channel of the target pixel respectively.
5. The fluid rendering method according to claim 2, characterized in that: The performing an even number of unidirectional smoothing processes on the depth value of the target pixel point also includes: Before performing the first unidirectional smoothing process on the target pixel, determining whether an initial depth value of the target pixel is 0; If the initial depth value of the target pixel is 0, the weighted sum of the depths and the weight sum of the target pixel are set to 0, and the even number of unidirectional smoothing operations on the target pixel is excluded, and the updated depth value of the target pixel is set to 0; If the initial depth value of the target pixel is not 0, a unidirectional smoothing process is performed on the target pixel.
6. The fluid rendering method according to claim 2, characterized in that: The performing an even number of unidirectional smoothing processes on the depth value of the target pixel point also includes: During the first unidirectional smoothing process, the difference between the initial depth value of the target pixel and the first preset threshold is determined. If the initial depth value of the target pixel is less than the first preset threshold, the weight sum of the target pixel obtained in the current unidirectional smoothing process is updated to a negative number. Wherein, the first preset threshold is greater than 0.
7. The fluid rendering method according to claim 4, characterized in that: The depth weighted sum and the weighted sum obtained by each unidirectional smoothing process are recorded in the first channel and the second channel of the target pixel point respectively, and then further comprising: If the current unidirectional smoothing process is the nth unidirectional smoothing process, and the weight sum obtained by the current unidirectional smoothing process of the target pixel point is less than the second preset threshold, the depth weighted sum and the weight sum respectively recorded by the first channel and the second channel of the target pixel point obtained by the current unidirectional smoothing process are updated to 0; Wherein, n is an even number, and the second preset threshold is greater than 0.
8. The fluid rendering method according to claim 2, characterized in that: The step of obtaining the weighted sum of the depths of the target pixel obtained in the current unidirectional smoothing process according to the distance between the neighboring pixel and the target pixel and the weighted sum of the depths of the neighboring pixel obtained in the previous unidirectional smoothing process comprises: For each neighboring pixel, obtain a depth weight of the neighboring pixel with respect to the target pixel according to the distance between the neighboring pixel and the target pixel and the weighted sum of the depths of the neighboring pixel obtained in the last unidirectional smoothing process; The weighted sum of the depths of all neighboring pixels with respect to the target pixel is taken as the weighted sum of the depths of the target pixel obtained in this unidirectional smoothing process.
9. The fluid rendering method according to claim 2 or 7, characterized in that: Obtaining the weight sum of the target pixel point obtained in the current unidirectional smoothing process according to the distance between the neighboring pixel point and the target pixel point and the weight sum of the neighboring pixel point obtained in the previous unidirectional smoothing process, including: For each neighboring pixel point, the weight of the neighboring pixel point with respect to the target pixel point is obtained according to the distance between the neighboring pixel point and the target pixel point and the sum of the weights of the neighboring pixel point obtained in the last unidirectional smoothing process; If the sum of the weights of the target pixel obtained in the previous unidirectional smoothing process is greater than the third preset threshold, the sum of the weights of all neighboring pixels to the target pixel is used as the sum of the weights of the target pixel obtained in this unidirectional smoothing process; If the sum of the weights of the target pixel obtained in the previous unidirectional smoothing process is not greater than the third preset threshold, the negative value of the sum of the weights of all neighboring pixels to the target pixel is used as the sum of the weights of the target pixel obtained in this unidirectional smoothing process; Wherein, the third preset threshold is greater than 0.
10. The fluid rendering method according to claim 2, characterized in that: The step of obtaining the updated depth value of the target pixel according to the result of the smoothing process includes: If the weight sum obtained by the last unidirectional smoothing process of the target pixel in the even-numbered unidirectional smoothing processes is greater than a fourth preset threshold, the absolute value of the quotient of the weighted sum of the depth obtained by the last unidirectional smoothing process of the target pixel and the weight sum is used as the updated depth value of the target pixel; If the sum of the weights of the target pixel point obtained in the last unidirectional smoothing process is not greater than the third preset threshold, the updated depth value of the target pixel point is 0; Among them, the fourth preset threshold is greater than 0.
11. A fluid rendering device, characterized in that: include: An initial depth value storage module, used for acquiring a fluid to be rendered, rendering the fluid to a screen space, and storing an initial depth value of the fluid in the screen space in a texture image; A depth value updating module is used to take any pixel in the texture image as a target pixel, perform an even number of unidirectional smoothing processes on the depth value of the target pixel according to the depth values of the neighboring pixels of the target pixel and the distances between the neighboring pixels and the target pixel, and obtain an updated depth value of the target pixel according to the result of the smoothing process; A shading module, used for performing lighting shading according to the updated depth values of all pixels, generating a rendering effect of the fluid, and outputting the rendering effect to a screen for display; Among them, the direction of the unidirectional smoothing processing is horizontal or vertical, and the directions of two adjacent unidirectional smoothing processing are different, and the neighboring pixel points are other pixel points within a preset range that are on the same straight line as the target pixel point in the direction of the unidirectional smoothing processing.
12. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the steps of the fluid rendering method according to any one of claims 1 to 10 are implemented.
13. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions enable the computer to execute the steps of the fluid rendering method according to any one of claims 1 to 10.
14. A computer program product, characterized in that The method comprises computer instructions, which, when executed by a processor, implement the fluid rendering method as claimed in any one of claims 1 to 10.
Citation Information
Patent Citations
Method and device for extracting and optimizing depth map of image
CN103493482A
Automatic image repair method for video 2D-3D conversion
CN106097273A