Starry sky simulation method, starry sky simulation device, computer equipment and medium
By randomly generating star points on the spherical model and rendering star circles, the repetition problem of existing starry sky models is solved, and a more realistic starry sky simulation effect is achieved.
Patent Information
- Application Number
- CN202111666592.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-31
- Publication Date
- 2025-09-02
- Estimated Expiration
- 2041-12-31
AI Technical Summary
The existing starry sky modeling method simulates the starry sky is repetitive and unreal.
On the preset spherical model, the star points corresponding to the preset number of spherical points are randomly generated based on the preset rules, the first map is generated using the star point parameter information, and the target star circle is rendered through the shader to realize the star sky simulation and avoid the repetition of star point.
It increases the realism of the starry sky, avoids the repetition of star dots, makes the parameter information of the star circle random, and improves the authenticity and visual effect of the simulation.
Smart Images

Figure CN114470756B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of scene simulation technology, and in particular to a starry sky simulation method, a starry sky simulation device, a computer device and a medium. Background Art
[0002] In current games, different scenes are usually generated by combining different weather conditions and times. For example, a night scene may have a starry sky.
[0003] Existing starry sky scenes are created by tiling preset textures onto a starry sky model using a shader. This allows users to see a certain degree of repetitiveness in the star points across different regions. However, in the real sky, the layout of stars varies from region to region. Therefore, the starry sky simulated by existing starry sky modeling methods is repetitive and unrealistic. Summary of the Invention
[0004] In view of this, the purpose of the embodiments of the present application is to provide a starry sky simulation method, a starry sky simulation device, a computer device and a medium, which can solve the problem that the starry sky simulated by the existing starry sky model method is unrealistic.
[0005] In order to solve the above technical problems, this application is implemented as follows:
[0006] In a first aspect, an embodiment of the present application provides a starry sky simulation method, comprising:
[0007] On a preset spherical model, randomly generating a preset number of star points corresponding to spherical points based on preset rules, wherein each star point is represented by star point parameter information, and the star point parameter information includes a first position parameter and a noise value;
[0008] Calculating the nearest star point for each preset spherical point on the preset spherical model, using parameter information of the nearest star point as pixel information of the corresponding pixel point, and generating a first map based on the second position parameter of each spherical point and the pixel information, wherein the preset spherical points on the preset spherical model correspond one-to-one to the pixel points on the first map;
[0009] Using a shader to read the first map, obtaining star point parameter information of a first target star point;
[0010] According to the star point parameter information of the first target star point, the star circle parameter information of the target star circle is generated, and the target star circle is rendered according to the position information of the first target star point and the star circle parameter information of the target star circle to realize starry sky simulation, wherein the star circle parameter information of the target star circle includes the star circle radius and the color information of each target spherical point in the target star circle.
[0011] According to a specific embodiment disclosed in the present application, randomly generating a preset number of star points corresponding to spherical points on a preset spherical model based on preset rules includes:
[0012] On the preset spherical model, a preset number of star points are randomly generated according to a preset star point density value and a preset size of the first map.
[0013] According to a specific embodiment disclosed in this application, the method further includes:
[0014] Each time a new star point is generated, determining whether the distance between the new star point and the generated star point is less than or equal to a preset distance threshold;
[0015] If so, the new star point is deleted.
[0016] According to a specific embodiment disclosed in the present application, randomly generating a preset number of star points corresponding to spherical points on a preset spherical model based on preset rules includes:
[0017] Sampling the preset star data to obtain a preset number of star data;
[0018] On a preset spherical model, a preset number of star points are randomly generated according to the star data.
[0019] According to a specific embodiment disclosed in the present application, the step of reading the first map using a shader to obtain the star point parameter information of the first target star point includes:
[0020] Determining a target area on the preset spherical model, wherein the target area includes a first target star point;
[0021] A portion corresponding to the target area in the first map is read using a shader to obtain star point parameter information of a first target star point.
[0022] According to a specific embodiment disclosed in the present application, generating star circle parameter information of a target star circle based on the star point parameter information of the first target star point, and rendering the target star circle based on the position information of the first target star point and the star circle parameter information of the target star circle to achieve starry sky simulation includes:
[0023] Determine, based on the position information of each target spherical point, a target pixel point corresponding to the target spherical point in the first map;
[0024] Calculating the distance between each target spherical point and the corresponding nearest star point based on the pixel information of each target pixel point;
[0025] If the distance is greater than a preset star circle radius threshold, setting the color information of the target spherical point to first preset color information;
[0026] If the distance is less than or equal to a preset star circle radius threshold, calculating the star circle radius of the target star circle corresponding to the first target star point;
[0027] If the distance is greater than the star circle radius, setting the color information of the target spherical point to the first preset color information;
[0028] If the distance is less than or equal to the star circle radius, setting the color information of the target spherical point to an initial color, wherein the initial color is the second preset color information multiplied by the noise value;
[0029] A change value is obtained according to the noise value and a preset formula, and is multiplied by the initial color to obtain color information of the target spherical point. The target spherical point is rendered according to the color information to obtain a target star circle and realize starry sky simulation.
[0030] According to a specific embodiment disclosed in this application, the method further includes:
[0031] For each target spherical point whose distance is less than or equal to the radius of the star circle, if the color information of the target spherical point is less than a preset color information threshold, the color information of the target spherical point is changed to the preset color information threshold.
[0032] According to a specific embodiment disclosed in this application, the method further includes:
[0033] The color information of each target spherical point in the target star circle is processed according to the smoothstep function and the distance.
[0034] According to a specific embodiment disclosed in this application, the method further includes:
[0035] In the preset constellation image, the coordinates of each star point in the preset constellation are extracted to generate a second map;
[0036] Using a shader to read the second map, obtaining position information of a second target star point;
[0037] The first target star point whose distance to the second target star point is less than a preset distance threshold is replaced by the second target star point.
[0038] In a second aspect, an embodiment of the present application provides a starry sky simulation device, comprising:
[0039] a star point generation module, configured to randomly generate a preset number of star points corresponding to spherical points on a preset spherical model based on preset rules, wherein each star point is represented by star point parameter information, and the star point parameter information includes a first position parameter and a noise value;
[0040] a map generation module, configured to calculate the nearest star point for each preset spherical point on the preset spherical model, use parameter information of the nearest star point as pixel information of the corresponding pixel point, and generate a first map based on the second position parameter of each spherical point and the pixel information, wherein the preset spherical points on the preset spherical model correspond one-to-one to the pixels on the first map;
[0041] A reading module, configured to read the first map using a shader to obtain star point parameter information of a first target star point;
[0042] A rendering module is used to generate star circle parameter information of a target star circle based on the star point parameter information of the first target star point, and to render the target star circle based on the position information of the first target star point and the star circle parameter information of the target star circle to realize starry sky simulation, wherein the star circle parameter information of the target star circle includes the star circle radius and the color information of each target spherical point in the target star circle.
[0043] In a third aspect, an embodiment of the present application provides a computer device comprising a processor and a memory, wherein the memory stores a program or instruction, and when the program or instruction is executed by the processor, the steps of the method described in the first aspect are implemented.
[0044] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, the steps of the method described in the first aspect are implemented.
[0045] In the starry sky simulation method, starry sky simulation device, computer equipment, and medium provided by the above-mentioned embodiments of the present application, the star point parameter information of each star point is randomly generated, so that the star circle parameter information of the star circle is also random. This avoids the repetitiveness of the star points and increases the sense of reality. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] In order to more clearly illustrate the technical solution of the present invention, the following is a brief introduction to the drawings required for use in the embodiments. It should be understood that the following drawings only illustrate certain embodiments of the present invention and should not be regarded as limiting the scope of protection of the present invention. In each of the drawings, similar components are numbered similarly.
[0047] Figure 1 A flow chart of a starry sky simulation method provided in an embodiment of the present application is shown;
[0048] Figure 2a A schematic diagram of a first map provided in an embodiment of the present application is shown;
[0049] Figure 2b A schematic diagram of another first map provided in an embodiment of the present application is shown;
[0050] Figure 3 A schematic diagram of a starry sky provided in an embodiment of the present application is shown;
[0051] Figure 4 A schematic diagram of the Big Dipper provided in an embodiment of the present application is shown;
[0052] Figure 5 A schematic structural diagram of a starry sky simulation device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION
[0053] The technical solutions in the embodiments of the present invention will be described clearly and completely below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments.
[0054] The components of the embodiments of the present invention generally described and illustrated in the figures herein may be arranged and designed in a variety of different configurations. Therefore, the following detailed description of the embodiments of the present invention provided in the figures is not intended to limit the scope of the claimed invention, but rather merely represents selected embodiments of the present invention. All other embodiments derived by those skilled in the art based on the embodiments of the present invention without inventive effort are intended to be within the scope of protection of the present invention.
[0055] Hereinafter, the terms "including", "having" and their cognates, which may be used in various embodiments of the present invention, are intended only to indicate specific features, numbers, steps, operations, elements, components or combinations of the foregoing items, and should not be understood as first excluding the existence of one or more other features, numbers, steps, operations, elements, components or combinations of the foregoing items or the possibility of adding one or more features, numbers, steps, operations, elements, components or combinations of the foregoing items.
[0056] Furthermore, the terms “first,” “second,” “third,” etc., are merely used for distinguishing descriptions and are not to be understood as indicating or implying relative importance.
[0057] Unless otherwise defined, all terms used herein (including technical and scientific terms) have the same meaning as commonly understood by those skilled in the art to which the various embodiments of the present invention pertain. The terms (such as those defined in generally used dictionaries) will be interpreted as having the same meaning as in the context of the relevant technical field and will not be interpreted as having an idealized meaning or an overly formal meaning unless clearly defined in the various embodiments of the present invention.
[0058] In game scene design, object images are typically displayed using textures, models, and shaders. Textures are pre-set images, and in this application, they are used to store star point data. Models are typically created using multiple connected triangular planes. Shaders are computer programs used to render images.
[0059] In this application, a spherical model is used to simulate the starry sky. Stars can be abstracted into a dot, so they can be presented by a star circle set on the spherical model. The dot represented by the star circle is a plane figure with a certain radius. The star circle at the spherical point P on the spherical model is actually a figure composed of all points within a certain radius with P as the center. It is a plane. If this plane is perpendicular to the line connecting point P and the center of the spherical model, then except for point P, any other points on the star circle do not belong to the sphere. However, the star circle that is actually rendered is the projection area of the star circle at the spherical point P on the sphere, which is a curved surface. In summary, for the convenience of calculation and description, the star circle is considered to be a plane, and the star circle actually rendered is a curved surface that is approximately a plane.
[0060] Furthermore, a star circle can be abstracted into the point at the center of the star circle, also known as a star point. It should be noted that in a broad sense, a star point refers to the point in the spherical model corresponding to the center of the star circle plus a noise value parameter. This means that it contains both position information and noise value. Position information is represented by three parameters, while a star point is represented by four parameters. A star point can be understood as a special type of point that inherits the characteristics of points in the spherical model, possessing all of the characteristics of points in the spherical model as well as its own unique features.
[0061] In a narrow sense, star points do not contain noise value parameters, that is, points in the spherical model, and only contain position information.
[0062] In this application, the discussion of star points should be understood in a broad sense. The narrow sense of the concept is only used in some cases and the meaning is automatically converted.
[0063] See also Figure 1 , Figure 1 The flowchart of the starry sky simulation method provided in the embodiment of the present application is as follows: Figure 1 As shown, the method includes the following steps:
[0064] Step 101: On a preset spherical model, randomly generate a preset number of star points corresponding to spherical points based on preset rules, wherein each star point is represented by star point parameter information, and the star point parameter information includes a first position parameter and a noise value.
[0065] Specifically, the position information of each spherical point on the preset spherical model can be represented in two ways, and the two ways can be converted to each other. The first way is to use the center of the preset spherical model as the origin, the bottom surface of the preset spherical model as the xy plane, and the extension direction of the preset spherical model as the z axis to construct a rectangular coordinate system. Then, each spherical point on the preset spherical model can be represented by (x, y, z) to represent its position information. In this application, (x, y, z) is called a three-dimensional rectangular coordinate; the second way is to use the spherical coordinate system on this basis and each spherical point on the preset spherical model can also be represented by (r, θ, ) to represent the position information of the spherical point, where r represents the distance from the origin to the spherical point, and θ represents the angle between the line connecting the origin to the spherical point and the positive z axis. It represents the azimuth angle between the projection line of the line connecting the origin to the spherical point in the xy plane and the positive x-axis. In this application, the preset spherical model is the unit sphere model. For each spherical point, the value of r is fixed and consistent, so (θ, ) is used to represent the position information of the spherical point. In this application, (θ, ) are called two-dimensional spherical coordinates.
[0066] The pre-set spherical model encloses other objects in the game scene. Assuming the radius of the pre-set spherical model is large enough, when the game character stands near the center of the sphere and looks at a point on the sphere, it is like a person standing on the ground looking at the stars in the sky.
[0067] In this embodiment, the first position information is a three-dimensional rectangular coordinate, and the second position information described below is a two-dimensional spherical coordinate.
[0068] The noise value is a random value. In this embodiment, the noise value ranges from [0, 1]. Preferably, the noise value ranges from [0.5, 1] to avoid large differences between random values and to prevent the resulting values from being too small when the noise value is subsequently used to generate the radius of the star circle and the color information of each spherical point in the star circle.
[0069] Since the star point parameter information of each star point, ie, the first position parameter and the noise value, are randomly generated, the repetitiveness of the star points is avoided and the sense of reality is increased.
[0070] In an optional implementation, step 101 includes:
[0071] On the preset spherical model, a preset number of star points are randomly generated according to a preset star point density value and a preset size of the first map.
[0072] Specifically, if the preset size of the first texture is 256*256 pixels and the preset star point density is 0.05, the number of star points to be generated, that is, the expected number of star points, is 65536*0.05, which is rounded down to 3276. It is understood that the preset size and preset star point density of the first texture can be set according to actual needs. The preset star point density is generally set to a smaller value to make the stars sparser and reduce the star point density.
[0073] Star points are generated according to a preset star point density value and a preset size of the first map. Since these two parameters can be set according to actual needs, the number of star points can be adjusted according to actual needs, thereby improving the adjustability of the number of star points.
[0074] On this basis, the method further comprises:
[0075] Each time a new star point is generated, determining whether the distance between the new star point and the generated star point is less than or equal to a preset distance threshold;
[0076] If so, the new star point is deleted.
[0077] Specifically, during the generation process, each newly generated star point is determined to see if it overlaps with an already generated star point. Specifically, if the distance between the two is less than or equal to a preset distance threshold, the newly generated star point is considered to overlap and discarded. In this embodiment, the preset distance threshold is twice the radius of the preset star circle. While it's understandable that the actual number of generated star points may be less than the expected number, this avoids overlap and enhances realism.
[0078] In an optional implementation, step 101 includes:
[0079] Sampling the preset star data to obtain a preset number of star data;
[0080] On a preset spherical model, a preset number of star points are randomly generated according to the star data.
[0081] Specifically, the preset star data is publicly available data, such as the Hipparcos catalog. Because the star point position information is derived from publicly available data, it represents data about stars existing in the real sky, further enhancing the sense of realism. It will be appreciated that in this embodiment, the star point position information is derived from real data, but the noise value is still randomly generated. Furthermore, after sampling, the distances between star points can be compared, and any two star points whose distance is less than or equal to a preset distance threshold can be eliminated.
[0082] Step 102: Calculate the nearest star point for each preset spherical point on the preset spherical model, use the parameter information of the nearest star point as the pixel information of the corresponding pixel point, and generate a first map based on the second position parameter of each spherical point and the pixel information, wherein the preset spherical points on the preset spherical model correspond one-to-one to the pixel points on the first map.
[0083] Specifically, the preset spherical model includes countless spherical points. These are part of the spherical points and correspond one-to-one with each pixel on the map. That is, the preset spherical model has as many preset spherical points as there are pixels on the map. In this embodiment, the first map is a square with equal length and width. For example, taking a 256*256 map as an example, the preset spherical model includes 256*256, or 65,536 preset spherical points.
[0084] In this embodiment, pixel information is represented by RGBA.
[0085] RGBA is a color space that represents Red, Green, Blue, and an Alpha channel. The Alpha channel is generally used as an opacity parameter. If the Alpha channel value of a pixel is 0%, it is completely transparent, that is, invisible; and a value of 100% means a completely opaque pixel. Values between 0% and 100% allow the background to show through the pixel, just like through glass. The Alpha channel value can be expressed as a percentage, an integer, or a real number from 0 to 1 like the RGB parameter. In this embodiment, the Alpha channel value ranges from [0, 1].
[0086] For any preset spherical point on the preset spherical model, the nearest star point N can be found by calculation. The star point N can be represented by four parameters, namely (x, y, z, a), where x, y, z are the first position information of the star point N, a is the noise value, and the value ranges of x, y, z, and a are all [0, 1].
[0087] Assuming each pixel can be abstracted into a square, the vertex at the lower left corner of the square can be used to represent the pixel, called a pixel point. Although a pixel point is just a point, it represents the square that the pixels are abstracted into. Therefore, if the points on the square correspond one-to-one with the points on another shape, then the pixel point can correspond to all the points in that shape.
[0088] For a pixel point P on the map corresponding to the preset spherical point, the pixel information of the pixel point can also be represented by four parameters, namely (R, G, B, A), where R, G, and B are the color information of the pixel point, and A is the alpha channel value. A two-dimensional rectangular coordinate system is constructed with the lower left corner of the map as the origin and the two sides as the xy axes. The position information of the pixel point P can be represented by (x, y), and the value range of x and y is [0, 1]. For example, taking a 256*256 map as an example, the coordinates of the first pixel point P1 in the lower left corner of the map are (0, 0), and the coordinates of the pixel point P2 adjacent to the upper right corner of P1 are (1 / 256, 1 / 256).
[0089] In this embodiment, since the pixels can be abstracted into a square, the texture with the same length and width can also be abstracted into a square, which is composed of the squares corresponding to each pixel in the texture. According to the above, it can be understood that since only θ and Two parameters can represent a point on the preset spherical model. Since two parameters can also be used to represent any point on a square, and the parameter values are all [0, 1], the points on the preset spherical model can correspond one-to-one with the points on the square, and thus each pixel point of the map corresponds one-to-one with a preset spherical point on the preset spherical model. Therefore, the second position information of the preset spherical point and the position information of the pixel point can be converted into each other.
[0090] Therefore, a star point can be represented by four elements. Just as a pixel point also has four RGBA sub-elements, and their value ranges are all [0, 1], the star point parameter information of the nearest star point N can be used as the pixel information of the corresponding pixel point P. Then, the storage location of the pixel information is determined based on the correspondence between the second position parameter of each preset spherical point and the map pixel point, and the pixel information is stored in the first map. This operation is performed for each preset spherical point to generate the first map. Please refer to Figure 2a and Figure 2b , Figure 2a and Figure 2b A first map provided by this embodiment is shown respectively, Figure 2a The first map shown corresponds to a starry sky with denser stars. Figure 2b The first texture shown corresponds to a starry sky with relatively sparse stars. The pixels in the first texture can display corresponding colors according to their own pixel information, that is, RGBA.
[0091] It can be understood that the pixel information of each pixel in the first map is the star point parameter information of the star point closest to the preset spherical point in the corresponding preset spherical model. Therefore, the first map stores the star point parameter information of all star points.
[0092] Step 103: Use a shader to read the first map to obtain star point parameter information of the first target star point.
[0093] Specifically, since the first map stores the star point parameter information of all star points, the star point parameter information of all star points on the preset spherical model can be obtained by reading the first map using a shader, thereby obtaining the star point parameter information of the first target star point. The first target star point is a portion of all star points. It is understood that not all spherical points on the preset spherical model need to be rendered; only all spherical points within a portion of the preset spherical model need to be rendered. Therefore, in an optional embodiment, step 103 includes:
[0094] Determining a target area on the preset spherical model, wherein the target area includes a first target star point;
[0095] A portion corresponding to the target area in the first map is read using a shader to obtain star point parameter information of a first target star point.
[0096] Specifically, in a game scene, the target area is related to the game character's perspective. Star points outside the perspective do not need to be displayed. The target area on a preset spherical model can be determined based on the game character's perspective. Therefore, the portion of the first map corresponding to the target area is read using a shader, thereby reducing data processing and improving rendering efficiency.
[0097] Step 104: Generate star circle parameter information of a target star circle based on the star point parameter information of the first target star point, and render the target star circle based on the position information of the first target star point and the star circle parameter information of the target star circle to achieve starry sky simulation, wherein the star circle parameter information of the target star circle includes the star circle radius and the color information of each target spherical point in the target star circle.
[0098] Specifically, the star point parameter information of the first target star point is used to generate the star circle parameter information of the target star circle. Then, based on the position information of the first target star point and the star circle parameter information of the target star circle, namely, the position of the center of each star circle, the radius of the star circle, and the color information of each spherical point in the star circle, rendering is performed to obtain the star circle. The combination of a preset number of target star circles achieves the simulation of the starry sky.
[0099] In an optional implementation, step 104 includes:
[0100] Determine, based on the position information of each target spherical point, a target pixel point corresponding to the target spherical point in the first map;
[0101] Calculating the distance between each target spherical point and the corresponding nearest star point based on the pixel information of each target pixel point;
[0102] If the distance is greater than a preset star circle radius threshold, setting the color information of the target spherical point to first preset color information;
[0103] If the distance is less than or equal to a preset star circle radius threshold, calculating the star circle radius of the target star circle corresponding to the first target star point;
[0104] If the distance is greater than the star circle radius, setting the color information of the target spherical point to the first preset color information;
[0105] If the distance is less than or equal to the star circle radius, setting the color information of the target spherical point to an initial color, wherein the initial color is the second preset color information multiplied by the noise value;
[0106] A change value is obtained according to the noise value and a preset formula, and is multiplied by the initial color to obtain color information of the target spherical point. The target spherical point is rendered according to the color information to obtain a target star circle and realize starry sky simulation.
[0107] Specifically, a target spherical point refers to each spherical point that needs to be rendered on the screen. It is the spherical point corresponding to the pixel point on the screen, including all spherical points within the star circle. For a target spherical point P on the preset spherical model, the first position parameter of point P is obtained, first converted to the second position parameter, and then the corresponding target pixel point P' is found in the first map based on the second position parameter.
[0108] It is understandable that three-dimensional rectangular coordinates are more general than two-dimensional spherical coordinates, and shaders usually obtain three-dimensional rectangular coordinates.
[0109] From the generation process of the first map, it can be seen that the target pixel point P' stores the star point parameter information of the star point N closest to the target spherical point P corresponding to the target pixel point P'. In this way, the distance between the target spherical point P and the star point N can be calculated.
[0110] First, determine whether the distance is greater than the preset star circle radius threshold. If so, the color information of the target spherical point P is set to the first preset color information. In this embodiment, the first preset color information is (0, 0, 0, 0), which is colorless and not displayed, and the rendering process of the target spherical point P is terminated. Through the above steps, the initial screening of spherical points is completed, that is, some spherical points that do not need further rendering are initially excluded to ensure rendering efficiency. It can be understood that the vast majority of spherical points on the preset spherical model that need to be rendered on the screen are excluded in this step.
[0111] If not, the radius of each star circle is calculated based on the preset radius and noise value. As you can see, since the noise value of each star point is different, the radius of each star circle is also different, thus achieving random star circle radius and making the generated star circles of different sizes, further increasing the sense of realism.
[0112] Furthermore, it is determined whether the distance is greater than the radius of the star circle. If so, the color information of the target spherical point P is also set to the first preset color information, that is, colorless and not displayed, and the rendering process of the target spherical point P is terminated; if not, the color information of the target spherical point P is set to the initial color. In this embodiment, the initial color is the second preset color information multiplied by the noise value a. The second preset color information is (1, 1, 1, 1), that is, white, and the initial color is (a, a, a, a). Through the above steps, the re-screening of the spherical points is completed, that is, on the basis of the initial screening, some points that do not need to be further rendered are excluded to ensure rendering efficiency.
[0113] It can be understood that spherical points with the same RGB values are displayed as grayscale colors. Grayscale colors refer to black, white, and a series of transition colors from black to white. Each grayscale color corresponds to a brightness value. Different RBGA values will result in different brightness of different spherical points. At the same time, since the noise value of each star point is different, the color information of the spherical points in each star circle is also different, thereby achieving randomness in the maximum brightness of the star circle, making the maximum brightness of the generated star circles different, further increasing the sense of reality.
[0114] Finally, a change value is obtained based on the noise value and the preset formula. The change value is multiplied by the initial color. For each spherical point, at a certain time point t, a change value W that changes dynamically with time can be obtained, thereby obtaining color information that changes dynamically with time. In this embodiment, the preset formula is the cosine curve formula cos(ωt). It is understandable that the preset formula can also be sin(ωt), where the value of ω is the noise value a of the star point closest to the spherical point, and t is the standard time of the game engine. It is understandable that the value range of the change value W is [0, 1]. Multiplying this value by the initial color of the spherical point P, the color information of the spherical point P becomes (aW, aW, aW, aW).
[0115] Figure 3 shows a schematic diagram of a starry sky provided in an embodiment of the present application, Figure 3This is obtained using the starry sky simulation method provided by this application. It is understood that through the above steps, the color information of the stars changes dynamically, achieving a twinkling effect. It is also understood that because the noise value of each star point is different, the twinkling time points of different star circles are also different, thereby achieving random twinkling time of the star circles. At a given time point, different star circles have different twinkling effects, further enhancing the sense of realism.
[0116] In an optional implementation manner, on this basis, the method further includes:
[0117] For each target spherical point whose distance is less than or equal to the radius of the star circle, if the color information of the target spherical point is less than a preset color information threshold, the color information of the target spherical point is changed to the preset color information threshold.
[0118] It is understood that the preset color information threshold can be set according to actual needs, and the specific value can be 0.3, 0.5, etc. Note that it is necessary to limit the color information, for example, to between 0.3 and 1. Otherwise, if the values of the color information corresponding to each parameter are too low, the minimum brightness of the star circle will be too low, the effect will be poor, and the user's perception will be affected.
[0119] In an optional implementation manner, on this basis, the method further includes:
[0120] The color information of each target spherical point in the target star circle is processed according to the smoothstep function and the distance.
[0121] Specifically, a gradient parameter F is calculated based on the smoothstep function and the distance, and the value range of the gradient parameter F is [0, 1]. The gradient parameter is multiplied by the color information to obtain the final color of the spherical point (aWF, aWF, aWF, aWF).
[0122] Through the above processing, the star circle can produce a gradient effect, with darker colors in the middle and lighter colors around it, avoiding the entire star circle being of the same color, further increasing the sense of reality.
[0123] In an optional implementation, the method further includes:
[0124] In the preset constellation image, the coordinates of each star point in the preset constellation are extracted to generate a second map;
[0125] Using a shader to read the second map, obtaining position information of a second target star point;
[0126] The first target star point whose distance to the second target star point is less than a preset distance threshold is replaced by the second target star point.
[0127] Specifically, in order to further increase the realism of the starry sky, stars in existing constellations can be added on the basis of the above solution to achieve the simulation of a specific constellation.
[0128] For example, take the Big Dipper in Ursa Major, see Figure 4 , Figure 4 A schematic diagram of the Big Dipper, provided in an embodiment of the present application, is shown. A two-dimensional rectangular coordinate system is constructed with the lower left corner of the diagram as the origin, obtaining the coordinates of the seven star points of the Big Dipper. Based on the mapping relationship between the two-dimensional rectangular coordinates and the two-dimensional spherical coordinates, the corresponding seven star points are generated in a preset spherical model. It will be appreciated that the subsequent process of obtaining a second map from the star points in the preset spherical model is similar to that of the first map, and to avoid repetition, it will not be described here.
[0129] Then, the shader is used to read the second map to obtain the position information of the seven star points. At the same time, since there may be first target star points in the first map that overlap with the positions of second target star points, these first target star points need to be removed to avoid star point overlap.
[0130] It should be noted that, in this embodiment, the position change of the Big Dipper is not considered, that is, the position of the stars in a specific constellation is not changed, because the fixed position is sufficient to meet the needs of conventional game scenes.
[0131] In the starry sky simulation method provided in the embodiment of the present application, the star point parameter information of each star point is randomly generated, so that the star circle parameter information of the star circle is also random. In this way, the repetitiveness of the star points is avoided and the sense of reality is enhanced.
[0132] Corresponding to the above method embodiment, see Figure 5 , Figure 5 A schematic diagram of the structure of the starry sky simulation device provided in the embodiment of the present application is shown in FIG. Figure 5 As shown, the starry sky simulation device 500 includes:
[0133] A star point generating module 501 is configured to randomly generate a preset number of star points corresponding to spherical points on a preset spherical model based on a preset rule, wherein each star point is represented by star point parameter information, and the star point parameter information includes a first position parameter and a noise value;
[0134] The map generation module 502 is used to calculate the nearest star point for each preset spherical point on the preset spherical model, use the parameter information of the nearest star point as the pixel information of the corresponding pixel point, and generate a first map based on the second position parameter of each spherical point and the pixel information, wherein the preset spherical points on the preset spherical model correspond one-to-one to the pixel points on the first map.
[0135] A reading module 503 is configured to read the first map using a shader to obtain star point parameter information of a first target star point;
[0136] The rendering module 504 is used to generate star circle parameter information of a target star circle based on the star point parameter information of the first target star point, and render the target star circle based on the position information of the first target star point and the star circle parameter information of the target star circle to realize starry sky simulation, wherein the star circle parameter information of the target star circle includes the star circle radius and the color information of each target spherical point in the target star circle.
[0137] The starry sky simulation device provided in the embodiment of the present application can achieve Figure 1 The various processes of the starry sky simulation method in the method embodiment can achieve the same technical effect. To avoid repetition, they will not be described here.
[0138] Optionally, an embodiment of the present application also provides a computer device, including a processor and a memory, wherein the memory stores a program or instruction, which, when executed by the processor, implements the various processes of the above-mentioned starry sky simulation method embodiment and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0139] Optionally, an embodiment of the present application also provides a computer-readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, the various processes of the above-mentioned starry sky simulation method embodiment are implemented and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0140] The processor is the processor in the computer device described in the above embodiment. The readable storage medium includes a computer-readable storage medium, such as a computer read-only memory (ROM), random access memory (RAM), a magnetic disk, or an optical disk.
[0141] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are merely schematic. For example, the flowcharts and structure diagrams in the accompanying drawings show the possible architectures, functions and operations of the devices, methods and computer program products according to multiple embodiments of the present invention. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of the code, and the module, program segment or a part of the code contains one or more executable instructions for implementing the specified logical functions. It should also be noted that in an alternative implementation, the functions marked in the box can also occur in an order different from that marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the structure diagram and / or flowchart, and the combination of boxes in the structure diagram and / or flowchart, can be implemented using a dedicated hardware-based system that performs the specified function or action, or can be implemented using a combination of dedicated hardware and computer instructions.
[0142] In addition, the functional modules or units in the various embodiments of the present invention may be integrated together to form an independent part, or each module may exist independently, or two or more modules may be integrated to form an independent part.
[0143] If the functions are implemented in the form of software function modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for enabling a computer device (which can be a smart phone, a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.
[0144] The above description is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with this technical field can easily think of changes or replacements within the technical scope disclosed by the present invention, which should be covered by the protection scope of the present invention.
Claims
1. A starry sky simulation method, characterized in that: include: On a preset spherical model, randomly generating a preset number of star points corresponding to spherical points based on preset rules, wherein each star point is represented by star point parameter information, and the star point parameter information includes a first position parameter and a noise value; Calculating the nearest star point for each preset spherical point on the preset spherical model, using parameter information of the nearest star point as pixel information of the corresponding pixel point, and generating a first map based on the second position parameter of each spherical point and the pixel information, wherein the preset spherical points on the preset spherical model correspond one-to-one to the pixel points on the first map; Using a shader to read the first map, obtaining star point parameter information of a first target star point; Generate star circle parameter information of a target star circle based on the star point parameter information of the first target star point, and render the target star circle based on the position information of the first target star point and the star circle parameter information of the target star circle to achieve starry sky simulation, wherein the star circle parameter information of the target star circle includes the star circle radius and color information of each target spherical point in the target star circle; In the preset constellation image, the coordinates of each star point in the preset constellation are extracted to generate a second map; Using a shader to read the second map, obtaining position information of a second target star point; The first target star point whose distance to the second target star point is less than a preset distance threshold is replaced by the second target star point.
2. The starry sky simulation method according to claim 1, characterized in that: The method of randomly generating a preset number of star points corresponding to spherical points on a preset spherical model based on a preset rule includes: On the preset spherical model, a preset number of star points are randomly generated according to a preset star point density value and a preset size of the first map.
3. The starry sky simulation method according to claim 2, characterized in that: The method further comprises: Each time a new star point is generated, determining whether the distance between the new star point and the generated star point is less than or equal to a preset distance threshold; If so, the new star point is deleted.
4. The starry sky simulation method according to claim 1, characterized in that: The method of randomly generating a preset number of star points corresponding to spherical points on a preset spherical model based on a preset rule includes: Sampling the preset star data to obtain a preset number of star data; On a preset spherical model, a preset number of star points are randomly generated according to the star data.
5. The starry sky simulation method according to claim 1, characterized in that: The step of using a shader to read the first map and obtain star point parameter information of a first target star point includes: Determining a target area on the preset spherical model, wherein the target area includes a first target star point; A portion corresponding to the target area in the first map is read using a shader to obtain star point parameter information of a first target star point.
6. The starry sky simulation method according to claim 1, characterized in that: Generating star circle parameter information of a target star circle according to the star point parameter information of the first target star point, and rendering to obtain a target star circle according to the position information of the first target star point and the star circle parameter information of the target star circle to realize starry sky simulation, including: Determine, based on the position information of each target spherical point, a target pixel point corresponding to the target spherical point in the first map; Calculating the distance between each target spherical point and the corresponding nearest star point based on the pixel information of each target pixel point; If the distance is greater than a preset star circle radius threshold, setting the color information of the target spherical point to first preset color information; If the distance is less than or equal to a preset star circle radius threshold, calculating the star circle radius of the target star circle corresponding to the first target star point; If the distance is greater than the star circle radius, setting the color information of the target spherical point to the first preset color information; If the distance is less than or equal to the star circle radius, setting the color information of the target spherical point to an initial color, wherein the initial color is the second preset color information multiplied by the noise value; A change value is obtained according to the noise value and a preset formula, and is multiplied by the initial color to obtain color information of the target spherical point. The target spherical point is rendered according to the color information to obtain a target star circle and realize starry sky simulation.
7. The starry sky simulation method according to claim 6, characterized in that: The method further comprises: For each target spherical point whose distance is less than or equal to the radius of the star circle, if the color information of the target spherical point is less than a preset color information threshold, the color information of the target spherical point is changed to the preset color information threshold.
8. The starry sky simulation method according to claim 6, characterized in that: The method further comprises: The color information of each target spherical point in the target star circle is processed according to the smoothstep function and the distance.
9. A starry sky simulation device, characterized in that: include: a star point generation module, configured to randomly generate a preset number of star points corresponding to spherical points on a preset spherical model based on preset rules, wherein each star point is represented by star point parameter information, and the star point parameter information includes a first position parameter and a noise value; A map generation module is configured to calculate the nearest star point for each preset spherical point on the preset spherical model, use parameter information of the nearest star point as pixel information of the corresponding pixel point, and generate a first map based on the second position parameter of each spherical point and the pixel information, wherein the preset spherical points on the preset spherical model correspond one-to-one to the pixel points on the first map; extract the coordinates of each star point in the preset constellation from the preset constellation image to generate a second map; use a shader to read the second map to obtain position information of a second target star point; and replace the first target star point whose distance to the second target star point is less than a preset distance threshold with the second target star point; A reading module, configured to read the first map using a shader to obtain star point parameter information of a first target star point; A rendering module is used to generate star circle parameter information of a target star circle based on the star point parameter information of the first target star point, and to render the target star circle based on the position information of the first target star point and the star circle parameter information of the target star circle to realize starry sky simulation, wherein the star circle parameter information of the target star circle includes the star circle radius and the color information of each target spherical point in the target star circle.
10. A computer device, characterized in that: The method comprises a processor and a memory, wherein the memory stores a program or instruction, and when the program or instruction is executed by the processor, the steps of the starry sky simulation method as described in any one of claims 1 to 8 are implemented.
11. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a program or instruction, and when the program or instruction is executed by a processor, the steps of the starry sky simulation method according to any one of claims 1 to 8 are implemented.
Citation Information
Patent Citations
Star field simulation method and star field simulation device
CN108182723A
Virtual sky picture rendering method and related equipment
CN113077541A