Grassland rendering method, device and system and electronic equipment

By obtaining the texture map of the grass model and sampling the status information, the rendering efficiency problem caused by the large number of grasses in the virtual scene is solved, and efficient grass rendering effect is achieved.

CN119516012APending Publication Date: 2025-02-25NETEASE (HANGZHOU) NETWORK CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411229655.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-02
Publication Date
2025-02-25

AI Technical Summary

Technical Problem

In virtual scenes, when there are too many grasses, the existing rendering method leads to low rendering efficiency and screen stuttering.

Method used

By obtaining the texture map corresponding to the grass model, sampling the texture coordinates of each pixel point on the plane model, obtaining its corresponding state information, and calling the shader to render the plane model to generate a grass rendering effect.

Benefits of technology

This method converts the rendering of multiple grasses into rendering of a flat model, improving the rendering efficiency and solving the problem of inefficient rendering efficiency when there are too many grasses.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119516012A_ABST
    Figure CN119516012A_ABST
Patent Text Reader

Abstract

The invention discloses a grassland rendering method, device and system, electronic equipment and a computer readable storage medium. The method comprises the following steps: obtaining a texture map, wherein the texture map records state information corresponding to at least part of point locations on a preset grass model; according to the texture coordinate corresponding to each pixel point on a plane model, sampling is carried out in the texture map, state information corresponding to each pixel point is obtained, and the plane model is a preset model covering the virtual scene terrain; and calling a shader, rendering the planar model according to the state information corresponding to each pixel point, and generating a planar model with a grassland rendering effect. According to the method, rendering of a plurality of grassland plants is converted into rendering of a plane model, so that the rendering efficiency of the grassland is separated from the number of grassland plants, and the technical problem that the rendering efficiency of an existing rendering method is low under the condition that the number of grassland plants is large is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a grass rendering method, device, system, electronic device, and computer-readable storage medium. Background Art

[0002] Vegetation plays a vital role in increasing the realism of virtual scenes. Therefore, a large amount of vegetation is often implanted in virtual scenes. Grass, as a dense vegetation, is usually implanted in larger quantities than other vegetation. During scene rendering, rendering a large amount of grass will undoubtedly increase the rendering burden of the graphics card, resulting in low rendering efficiency and even screen freezes.

[0003] At present, in order to solve the above problems, an instanced rendering method is provided. This method can form multiple instances with unique properties through a grass model. In the rendering process, the calculation amount of the shader is reduced, and the rendering efficiency is improved to a certain extent. However, in the instanced rendering method, in order to ensure that each instance has unique properties, instanced rendering data will be set for each instance. When the amount of grass is large, a large amount of instanced rendering data will still cause the problem of low rendering efficiency.

[0004] Therefore, how to ensure rendering efficiency and achieve smooth images when there are a large number of grasses has become a technical problem that needs to be solved urgently in virtual scene rendering. Summary of the invention

[0005] The present application provides a grass rendering method, device, system, electronic device, and computer-readable storage medium to solve the technical problem of low rendering efficiency when there is a large amount of grass in the prior art.

[0006] In a first aspect, an embodiment of the present application provides a grass rendering method, the method comprising: obtaining a texture map, the texture map recording status information corresponding to at least some points on a preset grass model; sampling in the texture map according to the texture coordinates corresponding to each pixel point on the plane model to obtain the status information corresponding to each pixel point, the plane model being a preset model covered on the terrain of a virtual scene; calling a shader to render the plane model according to the status information corresponding to each pixel point to generate the plane model with a grass rendering effect.

[0007] In the second aspect, an embodiment of the present application provides a grass rendering device, which includes: an acquisition unit, a sampling unit, and a rendering unit; the acquisition unit is used to acquire a texture map, and the texture map records the status information corresponding to at least some points on a preset grass model; the sampling unit is used to sample in the texture map according to the texture coordinates corresponding to each pixel point on the plane model, and obtain the status information corresponding to each pixel point, and the plane model is a preset model covered on the terrain of the virtual scene; the rendering unit is used to call a shader to render the plane model according to the status information corresponding to each pixel point, so as to generate the plane model with a grass rendering effect.

[0008] In a third aspect, an embodiment of the present application provides a grass rendering system, the system comprising: a baking module and a rendering module; the baking module is used to bake a preset grass model offline to generate a texture map corresponding to the grass model, the texture map records status information corresponding to at least some points on the grass model; the rendering module is used to obtain the texture map; according to the texture coordinates corresponding to each pixel point on the plane model, sampling is performed in the texture map to obtain the status information corresponding to each pixel point, the plane model is a preset model covered on the terrain of the virtual scene; calling the shader to render the plane model according to the status information corresponding to each pixel point, to generate the plane model with grass rendering effect.

[0009] In a fourth aspect, an embodiment of the present application provides an electronic device, comprising: a memory and a processor; the memory is used to store one or more computer instructions; the processor is used to execute the one or more computer instructions to implement the above method.

[0010] In a fifth aspect, an embodiment of the present application provides a computer-readable storage medium having one or more computer instructions stored thereon, which, when executed by a processor, executes the above method.

[0011] Compared with the prior art, the grass rendering method provided by the present application includes: obtaining a texture map (the texture map records the state information corresponding to at least some points on the grass model); sampling in the texture map according to the texture coordinates corresponding to each pixel on the plane model (the preset model covered on the virtual scene terrain), and obtaining the state information corresponding to each pixel; calling the shader to render the plane model according to the state information corresponding to each pixel, and generating a plane model with a grass rendering effect. This method enables the rendering of a grass effect on the plane model by sampling the state information corresponding to each pixel on the plane model in the texture map corresponding to the grass model. That is, the grass rendering method provided by the present application converts the rendering of multiple grasses into the rendering of a plane model, so that the rendering efficiency of the grass is separated from the amount of grass, which solves the technical problem of low rendering efficiency of the existing rendering method when the amount of grass is large. BRIEF DESCRIPTION OF THE DRAWINGS

[0012] Figure 1 is an application system diagram of the grass rendering method provided in an embodiment of the present application;

[0013] Figure 2 is a flow chart of a grass rendering method provided in the first embodiment of the present application;

[0014] Figure 3 is a schematic diagram of pre-baking a grass model provided in the first embodiment of the present application;

[0015] Figure 4 is a schematic diagram of the ray tracing direction provided in the first embodiment of the present application;

[0016] Figure 5 is a schematic diagram of calculating the third texture coordinate of a texture element provided by the first embodiment of the present application;

[0017] Figure 6 This is a schematic diagram of the rendering effect of a portion of a two-dimensional texture map in a three-dimensional texture map provided in the first embodiment of the present application;

[0018] Figure 7 is a schematic diagram of calculating the third texture coordinates of a pixel point provided by the first embodiment of the present application;

[0019] Figure 8 is a schematic diagram of recording depth information in a texture map provided by the first embodiment of the present application;

[0020] Fig. 9 is a schematic diagram of depth migration of a plane model provided by the first embodiment of the present application;

[0021] Fig.10 This is a schematic diagram of the grass rendering effect provided by the first embodiment of the present application:

[0022] Fig.11 This is a schematic diagram of the structure of a grass rendering device provided in the second embodiment of the present application:

[0023] Fig.12 is a schematic diagram of a grass rendering system provided in a third embodiment of the present application;

[0024] Fig.13 It is a schematic diagram of the structure of an electronic device provided in the fourth embodiment of the present application. DETAILED DESCRIPTION

[0025] Many specific details are described in the following description to facilitate a full understanding of the present application. However, the present application can be implemented in many other ways than those described herein, and those skilled in the art can make similar generalizations without violating the connotation of the present application, so the present application is not limited by the specific implementation disclosed below.

[0026] With the rapid advancement of computer technology and game development technology, the game industry has entered an unprecedented stage of development. The focus of game developers has gradually shifted from improving game functions to improving the realism and immersion of games. The realism and immersion of games are crucial to increasing user participation in games and extending the life cycle of games.

[0027] Virtual vegetation plays a vital role in increasing the realism of virtual scenes. Therefore, a large amount of vegetation is often implanted in virtual scenes during the game development stage. Grass, as a dense vegetation, is often deployed in virtual scenes in the form of grassland, and the amount of grass implanted is larger than other vegetation. During the scene rendering process, the rendering of a large amount of grass will undoubtedly increase the rendering burden of the graphics card, resulting in low rendering efficiency, resulting in screen freezes and lags.

[0028] At present, in response to the above problems, an instance rendering method is provided, which has obvious advantages in rendering a large number of repeated geometric bodies such as grass. It can form multiple instances with unique attributes based on a grass model. During the rendering process, all instances are rendered based on the same vertex data, thereby reducing the amount of shader calculation and improving the rendering efficiency to a certain extent. However, in the instance rendering method, in order to ensure that each instance has unique attributes, a set of transformation matrices will be provided for each instance, including instance rendering data such as position information, rotation information, and scaling information. When the number of grasses is large (e.g., more than 100,000 grasses), a large amount of instance rendering data will still have a negative impact on the rendering efficiency. In addition, the instance rendering method also has the defect of repeated drawing (Overdraw), so that a pixel point is often repeatedly drawn many times. In the case of dense grass, this will undoubtedly have a negative impact on the rendering efficiency.

[0029] In view of this, the present application provides a grass rendering method, which can render a grass effect on a plane model by sampling the state information corresponding to each pixel point on a plane model in the texture map corresponding to the grass model. The grass rendering method provided by the present application converts the rendering of multiple grasses into the rendering of a plane model, so that the rendering efficiency of the grass is separated from the amount of grass, and the rendering efficiency is not affected when the grass is dense.

[0030] The grass rendering method, device, system, electronic device, and computer-readable storage medium described in the present application are further described in detail below in conjunction with specific embodiments and drawings.

[0031] Figure 1 is an application system diagram of the grass rendering method provided in the embodiment of the present application. Figure 1 As shown, the system includes a user terminal 101 and a server terminal 102, and the user terminal 101 can be any device such as a smart phone, a tablet computer, a laptop computer, a desktop computer, a personal digital assistant (PDA), etc. The server terminal 102 can be a processing module inside the user terminal 101, or a processing device electrically connected to the user terminal 101, or a server connected to multiple user terminals 101 in communication. A grass rendering method is deployed on the server terminal 102. When a user enters a virtual scene through the user terminal 101, the server terminal 102 can render grass based on the method.

[0032] The first embodiment of the present application provides a grass rendering method, which is deployed in Figure 1 The server 102 shown is used to perform real-time grass rendering in a virtual scene.

[0033] Figure 2 : is a flow chart of the grass rendering method provided by this embodiment. Figure 2 The grass rendering method provided by this embodiment is described in detail. The embodiments described below are used to explain the technical solution of this application and are not intended to be used as limitations for actual use.

[0034] like Figure 2 As shown, the grass rendering method provided in this embodiment includes the following steps S210 to S230:

[0035] Step S210: obtaining a texture map, wherein the texture map records state information corresponding to at least some points on a preset grass model.

[0036] The texture map can be understood as a texture image, which is mapped onto the surface of the model to increase the details and realism of the model. Typically, texture maps use a UV coordinate system, where U represents the horizontal position and V represents the vertical position. When the model is rendered, these UV coordinates are used to find the corresponding pixels in the texture image and apply their colors to the model surface.

[0037] In an optional implementation, the texture map is the result of offline pre-baking of a preset grass model. That is, before rendering the virtual scene, a texture map corresponding to the preset grass model is generated through model baking technology. The texture map is the data source for rendering the grass effect in the virtual scene and can remain unchanged.

[0038] The model baking technology can be understood as pre-calculating and recording the detail information, lighting information, shadow information, normal information, etc. of the high polygon model into the texture map of the low polygon model. In this way, during the rendering process, the low polygon model can use these texture maps to simulate the appearance of the high polygon model without complex real-time calculations.

[0039] In this embodiment, the grass model can be a model of a single grass or a model of a clump of grass, without specific limitation. After the grass model is pre-baked, the texture map will record the status information corresponding to some points on the grass model or all points, which is related to the specific baking method and the type of texture map. Exemplarily, the grass model is baked using ray tracing technology. When the texture map is a two-dimensional texture map, the texture map only records the status information corresponding to the interaction points between the light and the grass model in one ray tracing direction, that is, the status information corresponding to some points. When the texture map is a three-dimensional texture map, the texture map records the status information corresponding to the interaction points between the light and the grass model in multiple ray tracing directions. When multiple ray tracing directions are relatively dense, the texture map will record the status information corresponding to all points on the grass model.

[0040] The state information can be understood as data that characterizes the performance of the grass model at a certain point, for example, color data that characterizes the basic color of the grass model at a certain point, a normal vector that characterizes the normal of the grass model at a certain point, and displacement data that characterizes the displacement of the grass model at a certain point. Which state information or which state information is recorded in the texture map needs to be determined according to the specific requirements of grass rendering. Generally, the higher the requirements for the grass rendering effect, the more state information needs to be recorded in the texture map, so as to ensure that the rendered grass is more realistic or conforms to a specific artistic style. When the terminal device has performance limitations, it is necessary to weigh the balance between details and performance to reduce the amount of state information baked into the texture map.

[0041] Step S220, sampling in the texture map according to the texture coordinates corresponding to each pixel point on the plane model to obtain the state information corresponding to each pixel point, the plane model is a preset model covered on the virtual scene terrain.

[0042] The plane model can be understood as a two-dimensional patch. In the business development stage, the plane model is covered on the virtual scene terrain. In the business application stage, for each pixel on the plane model, the texture map is sampled to obtain the state information corresponding to each pixel. The sampling process can be understood as the process of obtaining state information from the texture map and recording the state information in the pixel of the plane model. Before sampling, it is necessary to establish the projection relationship between the pixel in the plane model and the texture element in the texture map, so as to obtain the texture coordinates corresponding to the pixel, and then sample from the texture map based on the texture coordinates.

[0043] In an optional implementation, the texture coordinates corresponding to each pixel point on the plane model can be calculated based on the texture coordinates corresponding to multiple vertices on the plane model. Then, the texture coordinates corresponding to each pixel point on the plane model are sampled in the texture map. For example, if the texture coordinates corresponding to point N on the plane model are (0.3, 0.7), then the state information recorded by the texture element with the texture coordinates (0.3, 0.7) in the texture map will be sampled.

[0044] In another optional implementation, the texture map can be amplified, such as by proportionally copying the texture map so that the size of the copied texture map is the same as the size of the plane model, and each pixel on the plane model corresponds to each texture element on the copied texture map, and the texture coordinates of the texture element are used as the texture coordinates of the corresponding pixel, and then the state information recorded by the texture element is sampled.

[0045] Step S230 , calling a shader to render the plane model according to the state information corresponding to each pixel point, thereby generating a plane model with a grass rendering effect.

[0046] The shader is a program specially designed for graphics processing, which can run efficiently on a graphics processing unit (GPU) and is used to process different aspects of graphics data, such as vertex positions, colors, lighting effects, etc. Shaders allow developers to define the appearance of graphics in a programmatic way and achieve complex visual effects.

[0047] In this embodiment, when sampling is completed, the shader is called, and specifically, the shader program is run to render graphics according to the state information corresponding to each pixel. Since the state information comes from the texture map corresponding to the grass model, after the plane model is rendered based on the state information, the grass effect can be rendered on the plane model.

[0048] The following describes in detail various optional implementations provided in this embodiment:

[0049] In an optional implementation, the texture map is a three-dimensional texture map, which includes multiple two-dimensional texture maps, and each two-dimensional texture map corresponds to a different ray tracing direction when baking the grass model.

[0050] In this implementation, the grass model is baked using ray tracing technology. Specifically, the grass model is pre-baked offline using ray tracing technology. The ray tracing technology is mainly used to achieve highly realistic lighting effects in real-time rendering and offline rendering. Baking using ray tracing technology can be understood as generating high-quality model data using ray tracing, and then baking these model data to the texture map corresponding to the model. In this embodiment, the generated model data is called state information.

[0051] Light has directionality. Different ray tracing directions will result in different points where the light interacts with the grass model, and the baked texture maps will also be different. Therefore, in this implementation, multiple ray tracing directions are preset, and the two-dimensional texture maps obtained by baking the grass model from each ray tracing direction are combined to form a three-dimensional texture map. Usually, the two-dimensional texture map records the local state of the grass model, while the three-dimensional texture map records the global state of the grass model.

[0052] The use of ray tracing technology to bake the grass model mainly relies on tracing rays to obtain the state information corresponding to the interaction points of the grass model, and then baking the obtained state information corresponding to the interaction points onto a two-dimensional texture map, specifically into the texture elements corresponding to the interaction points.

[0053] The number of ray tracing directions and specific angles are adjustable values, which can be set according to the requirements for the final rendered grass effect. Generally, the higher the requirements for the grass rendering effect (such as more realistic, more flexible), the more ray tracing directions there are, and the more two-dimensional texture maps are included in the three-dimensional texture map.

[0054] In a specific implementation, the ray tracing direction is set to maintain a fixed angle with the X-axis of the spatial coordinate system, and multiple evenly distributed directions around the Y-axis of the spatial coordinate system (in this embodiment, the spatial coordinate system is a left-handed coordinate system, and the Y-axis is upward) for one circle (360°). Exemplarily, the angle with the X-axis of the spatial coordinate system is maintained at 45°, and the angle between adjacent directions of the 16 directions rotated around the Y-axis of the spatial coordinate system is 22.5°. That is, a ray tracing with an angle of 45° with the X-axis of the spatial coordinate system is performed every 22.5° rotation around the Y-axis of the spatial coordinate system.

[0055] In another specific implementation, the direction and number of ray tracing can be determined according to the preset parameters of the three-dimensional texture map. Exemplarily, the preset parameters of the three-dimensional texture map are 256ⅹ256ⅹ32, where 256ⅹ256 represents the size of each two-dimensional texture map (a two-dimensional texture map includes 256ⅹ256 texture elements), and 32 represents the number of two-dimensional texture maps included in the three-dimensional texture map. If the ray tracing direction is preset to maintain an angle of 45° with the X-axis of the spatial coordinate system and rotate around the Y-axis of the spatial coordinate system, then the number of ray tracing directions is 32, and the angle between adjacent directions is 11.25° (360° / 32=11.25°). That is, a ray tracing with an angle of 45° with the X-axis of the spatial coordinate system is performed every 11.25° rotation around the Y-axis of the spatial coordinate system.

[0056] In an optional implementation, before the step of obtaining the texture map, the method provided in this embodiment may further include the following steps S11 to S14:

[0057] Step S11, creating a two-dimensional texture map.

[0058] Step S12, emitting a tracing ray to the grass model in a first ray tracing direction to obtain status information corresponding to points on the grass model that interact with the tracing ray, wherein the first ray tracing direction is any one of a plurality of preset ray tracing directions.

[0059] Step S13, recording the state information corresponding to the points on the grass model that interact with the tracing light on the corresponding texture coordinates of the two-dimensional texture map, where the corresponding texture coordinates are the texture coordinates corresponding to the texture elements on the two-dimensional texture map that interact with the tracing light.

[0060] Step S14, combining the two-dimensional texture maps recording the state information obtained in each ray tracing direction into a three-dimensional texture map.

[0061] Taking the first ray tracing direction (any one of the multiple ray tracing directions) as an example, how to generate a two-dimensional texture map recording state information in the first ray tracing direction is described.

[0062] Figure 3 It is a schematic diagram of pre-baking a grass model provided in this embodiment.

[0063] like Figure 3As shown, a tracing ray 320 is emitted toward the grass model 310 in a first ray tracing direction, the tracing ray 320 interacts with the grass model 310, the interaction point is point 330, the tracing ray 320 obtains status information corresponding to point 330, and records the status information corresponding to point 330 on the corresponding texture coordinates of the two-dimensional texture map 340, the corresponding texture coordinates are the texture coordinates (U, V) corresponding to the texture element 350 on the tracing ray 320 that interacts with the two-dimensional texture map 340.

[0064] By combining the two-dimensional texture maps that record the state information in each ray tracing direction generated based on the above method, a three-dimensional texture map can be formed. For example, by rotating around the Y axis of the spatial coordinate system at intervals of 11.25° and tracing a ray with an angle of 45° with the X axis of the spatial coordinate system, 32 two-dimensional texture maps that record the state information can be generated. By combining the 32 two-dimensional texture maps that record the state information together, a three-dimensional texture map that meets the preset parameters MxNx32 can be formed, where MxN represents the size of the two-dimensional texture map.

[0065] In an optional implementation, the preset multiple ray tracing directions have preset angles with the X-axis of the spatial coordinate system and are evenly distributed in multiple directions within 360 degrees around the Y-axis of the spatial coordinate system.

[0066] The preset angle can be any angle between 0° and 90°. In a specific implementation, in order to obtain a good grass rendering effect for any viewpoint direction during the rendering stage, 45° (the average value of 0° to 90°) is used as the preset angle. Then, the multiple ray tracing directions are evenly distributed in multiple directions around the Y axis of the spatial coordinate system (360°) while maintaining an angle of 45° with the X axis of the spatial coordinate system.

[0067] Figure 4 It is a schematic diagram of the ray tracing direction provided in this embodiment.

[0068] like Figure 4 As shown in (a), the two-dimensional texture map 430 is created on the XZ plane of the spatial coordinate system. When observed along the Z axis of the spatial coordinate system, the angle between the tracing ray 420 directed toward the grass model 410 and the X axis of the spatial coordinate system is 45 degrees, and this angle remains unchanged for each tracing ray.

[0069] like Figure 4As shown in (b), assuming that the number of two-dimensional texture maps included in the three-dimensional texture map is 32, then, when observed along the Y-axis of the spatial coordinate system, the tracing rays are evenly distributed in 32 directions around the Y-axis of the spatial coordinate system, such as tracing ray 441, tracing ray 442, tracing ray 443, tracing ray 444, etc. The rotation angle between tracing ray 441 and tracing ray 442 is 11.25°, the rotation angle between tracing ray 442 and tracing ray 443 is 11.25°, and the rotation angle between tracing ray 443 and tracing ray 444 is 11.25°.

[0070] In an optional implementation, combining the two-dimensional texture maps recording the state information obtained in each ray tracing direction into a three-dimensional texture map has a certain arrangement order, and the specific combination method may include the following steps S14-1 to S14-4:

[0071] Step S14-1, projecting the first ray tracing direction onto the XZ plane of the spatial coordinate system to obtain a projection direction corresponding to the first ray tracing direction;

[0072] Step S14-2, calculating a first angle between the projection direction corresponding to the first ray tracing direction and the Z axis of the space coordinate system;

[0073] Step S14-3: taking the quotient of the first angle divided by 360 as the third texture coordinate in the three-dimensional texture map of each texture element in the two-dimensional texture map recording the state information obtained in the first ray tracing direction.

[0074] Step S14-4, arranging and combining the two-dimensional texture maps recording the state information obtained in each ray tracing direction into a three-dimensional texture map according to the calculated third texture coordinates of each texture element in the two-dimensional texture map in the three-dimensional texture map.

[0075] Each texture element in the two-dimensional texture map has a first texture coordinate U and a second texture coordinate V, but does not have a third texture coordinate W. After combining multiple two-dimensional texture maps into a three-dimensional texture map, each texture element in the three-dimensional texture map has not only the first texture coordinate U and the second texture coordinate V, but also the third texture coordinate W. In this embodiment, based on the ray tracing direction for generating the two-dimensional texture map, the third texture coordinate W corresponding to the texture element in the two-dimensional texture map is calculated, and the third texture coordinate W corresponding to the texture element in each two-dimensional texture map is used as the basis for combining multiple two-dimensional texture maps to form a three-dimensional texture map arranged in a certain manner. Based on this method, the third texture coordinate W corresponding to each texture element in the three-dimensional texture map is associated with the ray tracing direction when baking the grass model.

[0076] For example, Figure 5 It is a schematic diagram of calculating the third texture coordinate of the texture element provided by this embodiment.

[0077] like Figure 5 As shown, when viewed from the angle of the Y axis of the spatial coordinate system, the ray tracing direction a is projected onto the XZ plane of the spatial coordinate system to form a projection direction OA, and the ray tracing direction b is projected onto the XZ plane of the spatial coordinate system to form a projection direction OB. The angle between the projection direction OA and the Z axis of the spatial coordinate system is 90°, so the third texture coordinate of each texture element in the two-dimensional texture map with state information obtained in the ray tracing direction a in the three-dimensional texture map is 0.25 (90 / 360=0.25), and the angle between the projection direction OB and the Z axis of the spatial coordinate system is 315°, so the third texture coordinate of each texture element in the two-dimensional texture map with state information obtained in the ray tracing direction b in the three-dimensional texture map is 0.875 (315 / 360=0.875).

[0078] Figure 6 It is a schematic diagram of the rendering effect of a part of the two-dimensional texture map in the three-dimensional texture map provided in this embodiment.

[0079] like Figure 6 As shown, part of the two-dimensional texture map in the three-dimensional texture map is rendered to obtain the rendering effect map corresponding to the grass model. Figure 6 (a) is a rendering effect diagram corresponding to the two-dimensional texture map obtained in the ray tracing direction with the first angle (the angle between the projection direction of the ray tracing direction on the XZ plane of the spatial coordinate system and the Z axis of the spatial coordinate system) being 0°. Figure 6 (b) is a rendering effect diagram corresponding to the two-dimensional texture map obtained in the ray tracing direction with a first angle of 270°. Figure 6 (c) is a rendering effect diagram corresponding to the two-dimensional texture map obtained in the ray tracing direction with a first angle of 180°. Figure 6 (d) is a rendering effect diagram corresponding to the two-dimensional texture map obtained in the ray tracing direction with a first angle of 90°.

[0080] In an optional implementation provided by this embodiment, sampling in the texture map according to the texture coordinates corresponding to each pixel point on the plane model to obtain the state information corresponding to each pixel point may include the following steps S21 to S22:

[0081] Step S21, based on a plurality of vertices on the plane model, calculating a first texture coordinate and a second texture coordinate corresponding to each pixel point on the plane model.

[0082] In a plane model, each vertex has a UV coordinate (including the first texture coordinate U and the second texture coordinate V), which is used to indicate the position of the vertex on the texture map. Therefore, based on the UV coordinates of these vertices, the texture coordinates corresponding to other pixel points on the plane model can be calculated.

[0083] In a specific implementation, based on multiple vertices on the plane model, the first texture coordinates and the second texture coordinates corresponding to each pixel point on the plane model are calculated. This can be done by: according to the first texture coordinates and the second texture coordinates corresponding to the first vertex on the plane model, the first texture coordinates and the second texture coordinates corresponding to the second vertex, and the first texture coordinates and the second texture coordinates corresponding to the third vertex, based on interpolation operations, obtaining the first texture coordinates and the second texture coordinates corresponding to the first pixel point; wherein the first vertex, the second vertex, and the third vertex are any three of the multiple vertices, and the first pixel point is any pixel point located inside the triangle formed by the first vertex, the second vertex, and the third vertex.

[0084] For example, the plane model is a rectangular patch consisting of four vertices, each vertex has a corresponding texture coordinate, where the texture coordinate corresponding to vertex A is (0,0), the texture coordinate corresponding to vertex B is (1,0), the texture coordinate corresponding to vertex C is (1,1), and the texture coordinate corresponding to vertex D is (0,1). Each pixel on the rectangular patch can obtain a unique texture coordinate by interpolating the texture coordinates corresponding to the three vertices. Assuming that point P is located inside the triangle composed of vertex A, vertex B, and vertex D, then the texture coordinate corresponding to point P can be expressed as:

[0085] UV(P)=α×UV(A)+β×UV(B)+γ×UV(D), and

[0086] α+β+γ=1

[0087] Among them, α, β, and γ are the centroid coordinates of point P relative to triangle ABD, indicating the relative position of point P in the triangle.

[0088] Step S22: sampling in the texture map according to the first texture coordinates and the second texture coordinates corresponding to each pixel point.

[0089] After calculating the first texture coordinates and the second texture coordinates corresponding to each pixel point, sampling can be performed in the texture map. For example, the texture coordinates corresponding to point P on the plane model are (0.25, 0.25), then the state information recorded by the texture element with texture coordinates (0.25, 0.25) in the texture map will be sampled.

[0090] In an optional implementation, after the step of calculating the first texture coordinates and the second texture coordinates corresponding to each pixel point on the plane model based on multiple vertices on the plane model, the method provided in this embodiment may also include the following steps: calculating the third texture coordinates corresponding to each pixel point on the plane model according to the position information of the virtual camera. Based on this, sampling in the texture map according to the first texture coordinates and the second texture coordinates corresponding to each pixel point may specifically include: sampling in the texture map according to the first texture coordinates, the second texture coordinates, and the third texture coordinates corresponding to each pixel point. Exemplarily, the texture coordinates corresponding to point P on the plane model are (0.25, 0.25, 0.5), then the state information recorded by the texture element with the texture coordinates (0.25, 0.25.0.5) in the texture map will be sampled.

[0091] As shown above, the third texture coordinate W corresponding to each texture element in the three-dimensional texture map is related to the ray tracing direction when baking the grass model. In this step, the third texture coordinate corresponding to each pixel point on the plane model is calculated according to the position information of the virtual camera, so as to sample the texture map based on the first texture coordinate, the second texture coordinate, and the third texture coordinate. This ensures that the state information baked in the ray tracing direction consistent with the virtual camera position information is obtained, so that the grass effect rendered based on the state information conforms to the observer's viewpoint direction, thereby increasing the realistic visual experience of the grass.

[0092] In a specific implementation, calculating the third texture coordinates corresponding to each pixel point on the plane model according to the position information of the virtual camera may specifically include the following steps S31 to S35:

[0093] Step S31, determining the viewpoint direction of the virtual camera according to the position information.

[0094] Step S32, projecting the viewpoint direction onto the XZ plane of the spatial coordinate system to obtain a first vector corresponding to the viewpoint direction, where the first vector is used to represent the projection direction of the viewpoint direction onto the XZ plane of the spatial coordinate system;

[0095] Step S33, normalizing the first vector to form a first unit vector corresponding to the first vector;

[0096] Step S34, calculating a second angle between the first unit vector and the second unit vector, where the second unit vector is used to represent the direction of the Z axis of the spatial coordinate system;

[0097] Step S35: taking the quotient of the second angle divided by 360 as the third texture coordinate corresponding to each pixel point on the plane model.

[0098] The above steps are similar to calculating the third texture coordinates corresponding to each texture element in a two-dimensional texture map. In this step, it is necessary to determine the third texture coordinates corresponding to each pixel point on the plane model based on the position information of the virtual camera before sampling in the three-dimensional texture map based on the first texture coordinates, the second texture coordinates, and the third texture coordinates.

[0099] For example, Figure 7 It is a schematic diagram of calculating the third texture coordinates of a pixel point provided by this embodiment.

[0100] like Figure 7 As shown, when observing along the Y-axis of the spatial coordinate system, the viewpoint direction b of the virtual camera is projected onto the XZ plane of the spatial coordinate system to form a projection direction OC. The first vector corresponding to OC is normalized to obtain the first unit vector Normalize(X,0,Z). The second angle α between the first unit vector Normalize(X,0,Z) and the second unit vector (0,0,1) is calculated. Assuming α=45°, the third texture coordinate W corresponding to each pixel point on the plane model is 0.125 (45 / 360=0.125).

[0101] It can be understood that, since the position of the virtual camera is unique at a rendering moment, the third texture coordinate W corresponding to each pixel point on the plane model is the same. Therefore, at a rendering moment, for each pixel point on the plane model, sampling is actually performed on a two-dimensional texture map in a three-dimensional texture map.

[0102] In an optional implementation provided by this embodiment, the state information includes at least diffuse reflection information and depth information.

[0103] Diffuse reflection information is a key component in calculating lighting effects, mainly including the diffuse reflection color (Diffuse Color) of the material, the diffuse reflection coefficient (Diffuse Coefficient) of the material, the surface normal (SurfaceNormal), the light direction (Light Direction), and the light color (Light Color). Using this information to calculate the diffuse reflection color of the lighting model can achieve a more realistic rendering effect. Among them, the diffuse reflection color of the material represents the basic color of the material under diffuse reflection conditions, usually an ARGB value (A is the transparency channel, indicating the opacity of the color; R is the red channel, indicating the red component in the color; G is the green channel, indicating the green component in the color; B is the blue channel, indicating the blue component in the color), reflecting the ability of the material to absorb and reflect light of different wavelengths. The diffuse reflection coefficient of the material is used to quantify the reflective ability of the material and to adjust the reflection intensity. The surface normal is a unit vector that points to the outside of the surface and indicates the direction of the surface. In diffuse reflection calculations, the normal is used to determine the relative angle between the surface orientation and the light direction. The light direction refers to the direction of the light emitted from the light source. In diffuse reflection calculations, the angle between the light direction and the surface normal determines the intensity of diffuse reflection. The lighting color represents the color of the light emitted by the light source. In the diffuse reflection calculation, the color of the light source is multiplied by the diffuse reflection color of the material to get the final diffuse reflection color.

[0104] The depth information refers to the distance information of the points on the model in three-dimensional space, usually expressed as the depth value of each point. Depth information is used to determine the distance of the model point relative to the observer (usually a virtual camera), and plays a vital role in the rendering process, especially in processing depth testing, shadow effects, depth offset, etc. In the rendering process, based on the depth information of each pixel on the plane model, the depth effect of grass can be rendered on the plane model.

[0105] Figure 8 It is a schematic diagram of recording depth information in a texture map provided by this embodiment.

[0106] like Figure 8 As shown, the two-dimensional texture map 830 is created on the XZ plane of the spatial coordinate system. When observed along the Z axis of the spatial coordinate system, the tracing light 820 directed toward the grass model 810 interacts with the two-dimensional texture map 830 at the texture element 840, and interacts with the grass model 810 at the point 850. The distance L between the texture element 840 and the point 850 is the depth information recorded in the texture element 840.

[0107] In an optional implementation, calling a shader to render the plane model according to the state information corresponding to each pixel point to generate a plane model with a grass rendering effect may include the following steps S41 to S43:

[0108] Step S41, calculating the color information corresponding to each pixel point according to the diffuse reflection information corresponding to each pixel point.

[0109] In a specific implementation, the color information corresponding to the pixel can be calculated by the following formula:

[0110] Color information = material diffuse color information × dot (N, L) × directional light color

[0111] Among them, L represents the direction of the directional light, N represents the normal of the plane model, and dot(N,L) represents the dot product between the direction of the directional light and the normal of the plane model.

[0112] Step S42: Calculate the depth offset corresponding to each pixel point according to the depth information corresponding to each pixel point.

[0113] In a specific implementation, the depth offset corresponding to each pixel can be obtained by multiplying the depth information corresponding to each pixel by the ViewProj matrix (camera View matrix x projection Projection matrix). The ViewProj matrix combines the functions of the view matrix (camera View matrix) and the projection matrix (projection Projection matrix) to convert points in three-dimensional space into the clipping coordinate system, and the view matrix is ​​used to convert three-dimensional points in the world coordinate system into the view coordinate system. The view matrix usually contains the position and direction information of the virtual camera, as well as the orientation of the virtual camera, and converts the geometric body in the virtual scene from the world coordinate system to the camera coordinate system so that the entire virtual scene looks like it is observed from the perspective of the virtual camera. The projection matrix is ​​used to project the points in the view coordinate system into the clipping coordinate system. There are two main types of projection matrices: perspective projection matrix and orthogonal projection matrix. The perspective projection matrix simulates the visual effect of the human eye, and objects in the distance will appear smaller. The orthogonal projection matrix does not consider the influence of distance, and all objects are the same size regardless of distance. The specific method for calculating the depth offset can be selected according to the preset requirements for the grass in the virtual scene, and there is no restriction here.

[0114] Step S43, performing color rendering on each pixel based on the color information corresponding to each pixel, and performing depth offset on each pixel based on the depth offset corresponding to each pixel, to generate a plane model with grass rendering effect.

[0115] During the rendering process, the grass effect can be rendered based on the color information corresponding to each pixel, and the depth value of the pixel can be adjusted based on the depth offset corresponding to each pixel, which can enhance the details of the grass and create a sense of depth of the grass.

[0116] Fig. 9 It is a schematic diagram of depth migration of a plane model provided in this embodiment.

[0117] like Fig. 9 As shown, when observed along the Z-axis of the spatial coordinate system, the plane model 910 is a two-dimensional patch covering the terrain of the virtual scene. During the rendering process, each pixel is depth-shifted based on the depth information corresponding to each pixel on the plane model 910. For example, pixel 921 is depth-shifted to move pixel 921 from position A0 to position A1, pixel 922 is depth-shifted to move pixel 922 from position B0 to position B1, pixel 923 is depth-shifted to move pixel 923 from position C0 to position C1, and pixel 924 is depth-shifted to move pixel 924 from position D0 to position D1, thereby creating a sense of depth of the grass.

[0118] By using the above method, the rendering of multiple grasses is converted into the rendering of a plane model, so that the rendering efficiency of the grass is separated from the number of grasses, and the rendering efficiency is not affected when the grass is dense. For example, if there are 100,000 grasses in the grass, then when the grass is rendered based on the instantiation rendering method, there will be 100,000 instantiation rendering data. Generally, the instantiation rendering data is represented by a float4x4 matrix, so 100,000 grasses will have 4x4x4x100,000=6.4 million bytes of bandwidth occupation, which has a serious impact on the rendering efficiency of the graphics card. Based on the method provided in this embodiment, the rendering of 100,000 grasses is converted into the rendering of a plane model, and there is no instantiation data occupying the bandwidth, which greatly improves the rendering effect. In addition, there is also the defect of repeated drawing (Overdraw) in the instantiation rendering, that is, there are a large number of invalid drawing covers on the same pixel point, but the method provided in this embodiment will not have this problem, and each pixel point will only be drawn once. Combining the above two aspects, the method provided in this embodiment solves the technical problems existing in the instanced rendering method in large-scale rendering, and improves the rendering efficiency in the case of dense grass.

[0119] In addition to the improvement in rendering efficiency, the method provided in this embodiment also ensures the rendering effect of the grass, and renders each pixel based on the diffuse reflection information and the depth information, so that the rendered grass has a sense of reality and depth.

[0120] Fig.10Schematic diagram of the grass rendering effect provided by this embodiment.

[0121] like Fig.10 As shown, the method provided in this embodiment is used to render the grass, and the rendered grass has a sense of depth, and there is an interlacing effect between the grass and the model 1001.

[0122] The above-mentioned first embodiment provides a grass rendering method. It should be noted that the example in the first embodiment is only for explaining the method described in this application and is not intended to be a limitation for actual use. The grass rendering method provided in this application includes but is not limited to the method described in the first embodiment.

[0123] A second embodiment of the present application provides a grass rendering device. Fig.11 Schematic diagram of the structure of the grass rendering device provided in this embodiment.

[0124] like Fig.11 As shown, the grass rendering device provided by this embodiment includes: an acquisition unit 1101 , a sampling unit 1102 , and a rendering unit 1103 .

[0125] The acquisition unit 1101 is used to acquire a texture map, where the texture map records state information corresponding to at least some points on a preset grass model.

[0126] Optionally, the texture map is a three-dimensional texture map, which includes a plurality of two-dimensional texture maps, and each of the two-dimensional texture maps corresponds to a different ray tracing direction when baking the grass model.

[0127] Optionally, the device further comprises a baking unit;

[0128] Before the step of obtaining the texture map, the baking unit is used to:

[0129] Create 2D texture maps;

[0130] In a first ray tracing direction, emitting a tracing ray to the grass model to obtain the state information corresponding to a point on the grass model that interacts with the tracing ray, wherein the first ray tracing direction is any one of a plurality of preset ray tracing directions;

[0131] Recording the state information corresponding to the point on the grass model that interacts with the tracing ray on the corresponding texture coordinates of the two-dimensional texture map, wherein the corresponding texture coordinates are the texture coordinates corresponding to the texture element on the two-dimensional texture map that interacts with the tracing ray;

[0132] The two-dimensional texture map recording the state information obtained in each of the ray tracing directions is combined into the three-dimensional texture map.

[0133] Optionally, the preset multiple ray tracing directions have a preset angle with the X-axis of the spatial coordinate system and are evenly distributed in multiple directions within 360 degrees around the Y-axis of the spatial coordinate system;

[0134] The step of combining the two-dimensional texture maps recorded with the state information obtained in each of the ray tracing directions into the three-dimensional texture map comprises:

[0135] Projecting the first ray tracing direction onto the XZ plane of the spatial coordinate system to obtain a projection direction corresponding to the first ray tracing direction;

[0136] Calculate a first angle between the projection direction corresponding to the first ray tracing direction and the Z axis of the space coordinate system;

[0137] Taking the quotient of the first angle divided by 360 as the third texture coordinate of each texture element in the two-dimensional texture map recording the state information obtained in the first ray tracing direction in the three-dimensional texture map;

[0138] The two-dimensional texture map recording the state information obtained in each of the ray tracing directions is arranged and combined into the three-dimensional texture map according to the calculated third texture coordinates of each texture element in the two-dimensional texture map in the three-dimensional texture map.

[0139] The sampling unit 1102 is used to sample in the texture map according to the texture coordinates corresponding to each pixel point on the plane model to obtain the state information corresponding to each pixel point. The plane model is a preset model covered on the virtual scene terrain.

[0140] Optionally, sampling in the texture map according to the texture coordinates corresponding to each pixel point on the plane model to obtain the state information corresponding to each pixel point includes:

[0141] Calculating first texture coordinates and second texture coordinates corresponding to each pixel point on the plane model based on a plurality of vertices on the plane model;

[0142] The texture map is sampled according to the first texture coordinates and the second texture coordinates corresponding to each pixel point.

[0143] Optionally, the calculating, based on a plurality of vertices on the plane model, a first texture coordinate and a second texture coordinate corresponding to each pixel point on the plane model includes:

[0144] According to the first texture coordinates and the second texture coordinates corresponding to the first vertex on the plane model, the first texture coordinates and the second texture coordinates corresponding to the second vertex, and the first texture coordinates and the second texture coordinates corresponding to the third vertex, based on the interpolation operation, the first texture coordinates and the second texture coordinates corresponding to the first pixel point are obtained; wherein,

[0145] The first vertex, the second vertex, and the third vertex are any three of the plurality of vertices, and the first pixel point is any pixel point located inside a triangle formed by the first vertex, the second vertex, and the third vertex.

[0146] Optionally, after the step of calculating the first texture coordinates and the second texture coordinates corresponding to each pixel point on the plane model based on the multiple vertices on the plane model, the method is further used to:

[0147] Calculating the third texture coordinates corresponding to each pixel point on the plane model according to the position information of the virtual camera;

[0148] The sampling in the texture map according to the first texture coordinate and the second texture coordinate corresponding to each pixel point includes:

[0149] The texture map is sampled according to the first texture coordinate, the second texture coordinate, and the third texture coordinate corresponding to each pixel point.

[0150] Optionally, calculating the third texture coordinates corresponding to each pixel point on the plane model according to the position information of the virtual camera includes:

[0151] Determining the viewpoint direction of the virtual camera according to the position information;

[0152] Projecting the viewpoint direction onto the XZ plane of the spatial coordinate system to obtain a first vector corresponding to the viewpoint direction, where the first vector is used to represent the projection direction of the viewpoint direction onto the XZ plane of the spatial coordinate system;

[0153] Normalizing the first vector to form a first unit vector corresponding to the first vector;

[0154] Calculating a second angle between the first unit vector and a second unit vector, where the second unit vector is used to represent the direction of the Z axis of the spatial coordinate system;

[0155] The quotient of the second angle divided by 360 is used as the third texture coordinate corresponding to each pixel point on the plane model.

[0156] The rendering unit 1103 is used to call a shader to render the plane model according to the state information corresponding to each pixel point, so as to generate the plane model with a grass rendering effect.

[0157] Optionally, the state information includes at least diffuse reflection information and depth information;

[0158] The calling of the shader to render the plane model according to the state information corresponding to each pixel point to generate the plane model with grass rendering effect includes:

[0159] Calculate the color information corresponding to each pixel point according to the diffuse reflection information corresponding to each pixel point;

[0160] Calculate the depth offset corresponding to each pixel point according to the depth information corresponding to each pixel point;

[0161] Color rendering is performed on each pixel based on the color information corresponding to each pixel, and depth offset is performed on each pixel based on the depth offset corresponding to each pixel, so as to generate the plane model with grass rendering effect.

[0162] The third embodiment of the present application provides a grass rendering system. Fig.12 Schematic diagram of a grass rendering system provided in this embodiment.

[0163] like Fig.12 As shown, the grass rendering system provided in this embodiment includes: a baking module 1201 and a rendering module 1202;

[0164] The baking module 1201 is used for offline baking of a preset grass model to generate a texture map corresponding to the grass model. The texture map records the state information corresponding to at least some points on the grass model.

[0165] The baking module 1201 can be understood as the offline end of the grass rendering system. In an optional implementation, the texture map generated by the baking module 1201 is a three-dimensional texture map, which includes multiple two-dimensional texture maps, and each two-dimensional texture map corresponds to a different ray tracing direction when baking the grass model.

[0166] Optionally, the baked grass model may include:

[0167] First, create a 2D texture map.

[0168] Second, in a first ray tracing direction, a tracing ray is emitted to the grass model to obtain status information corresponding to points on the grass model that interact with the tracing ray, and the first ray tracing direction is any one of a plurality of preset ray tracing directions.

[0169] Third, the state information corresponding to the points on the grass model that interact with the tracing rays is recorded on the corresponding texture coordinates of the two-dimensional texture map, where the corresponding texture coordinates are the texture coordinates corresponding to the texture elements on the two-dimensional texture map that interact with the tracing rays.

[0170] Fourth, the two-dimensional texture map recording the state information obtained in each ray tracing direction is combined into a three-dimensional texture map.

[0171] Optionally, the preset multiple ray tracing directions have preset angles with the X-axis of the spatial coordinate system and are evenly distributed in multiple directions within 360 degrees around the Y-axis of the spatial coordinate system.

[0172] Combining multiple two-dimensional texture maps into a three-dimensional texture map may include: projecting a first ray tracing direction onto an XZ plane of a spatial coordinate system to obtain a projection direction corresponding to the first ray tracing direction; calculating a first angle between the projection direction corresponding to the first ray tracing direction and the Z axis of the spatial coordinate system; taking the quotient of the first angle divided by 360 as the third texture coordinate in the three-dimensional texture map of each texture element in the two-dimensional texture map recording status information obtained in the first ray tracing direction; arranging and combining the two-dimensional texture maps recording status information obtained in each ray tracing direction into a three-dimensional texture map according to the calculated third texture coordinate in the three-dimensional texture map of each texture element in the two-dimensional texture map.

[0173] In a specific implementation, the baking module 1201 can place the grass model at the origin (0,0,0) of the spatial coordinate system, start ray tracing from the direction represented by the Normalize (1,1,0) unit vector, rotate the Normalize (1,1,0) unit vector 360° around the Y axis of the spatial coordinate system, and store the obtained state information in the texture map.

[0174] The rendering module 1202 is used to obtain a texture map; sample the texture map according to the texture coordinates corresponding to each pixel point on the plane model to obtain the state information corresponding to each pixel point, where the plane model is a preset model covered on the terrain of the virtual scene; call the shader to render the plane model according to the state information corresponding to each pixel point to generate a plane model with a grass rendering effect.

[0175] The rendering module 1202 may be understood as a rendering end of a grass rendering system. In an optional implementation, sampling in a texture map may include:

[0176] First, based on a plurality of vertices on the plane model, a first texture coordinate and a second texture coordinate corresponding to each pixel point on the plane model are calculated.

[0177] Optionally, based on the interpolation operation, the first texture coordinates and the second texture coordinates corresponding to the first vertex on the plane model, the first texture coordinates and the second texture coordinates corresponding to the second vertex, and the first texture coordinates and the second texture coordinates corresponding to the third vertex, the first texture coordinates and the second texture coordinates corresponding to the first pixel point are obtained; wherein the first vertex, the second vertex, and the third vertex are any three of the multiple vertices, and the first pixel point is any pixel point located inside the triangle formed by the first vertex, the second vertex, and the third vertex.

[0178] Optionally, the third texture coordinates corresponding to each pixel point on the plane model are calculated according to the position information of the virtual camera.

[0179] Optionally, determine the viewpoint direction of the virtual camera based on the position information; project the viewpoint direction onto the XZ plane of the spatial coordinate system to obtain a first vector corresponding to the viewpoint direction, the first vector being used to represent the projection direction of the viewpoint direction onto the XZ plane of the spatial coordinate system; normalize the first vector to form a first unit vector corresponding to the first vector; calculate the second angle between the first unit vector and the second unit vector, the second unit vector being used to represent the direction of the Z axis of the spatial coordinate system; and use the quotient of the second angle divided by 360 as the third texture coordinate corresponding to each pixel point on the plane model.

[0180] Second, sampling is performed in the texture map according to the first texture coordinates and the second texture coordinates corresponding to each pixel.

[0181] Optionally, sampling is performed in the texture map according to the first texture coordinate, the second texture coordinate, and the third texture coordinate corresponding to each pixel point.

[0182] In an optional implementation, the state information includes at least diffuse reflection information and depth information.

[0183] Optionally, rendering the plane model may include:

[0184] First, the color information corresponding to each pixel is calculated based on the diffuse reflection information corresponding to each pixel.

[0185] Second, based on the depth information corresponding to each pixel, the depth offset corresponding to each pixel is calculated.

[0186] Third, color rendering is performed on each pixel based on the color information corresponding to each pixel, and depth offset is performed on each pixel based on the depth offset corresponding to each pixel, so as to generate a plane model with grass rendering effect.

[0187] In a specific implementation, the rendering module 1202 can create a new plane model covering the scene terrain in the virtual scene, load the baked texture map, sample diffuse reflection information and depth information from the texture map, calculate the color and depth, and render a plane model with a grass effect.

[0188] A fourth embodiment of the present application provides an electronic device, Fig.13 It is a schematic diagram of the structure of the electronic device provided in this embodiment.

[0189] like Fig.13 As shown, the electronic device provided in this embodiment includes: a memory 1301 and a processor 1302;

[0190] The memory 1301 is used to store computer instructions for executing the grass rendering method;

[0191] The processor 1302 is configured to execute computer instructions stored in the memory 1301 to perform the following operations:

[0192] Acquire a texture map, wherein the texture map records state information corresponding to at least some points on a preset grass model;

[0193] According to the texture coordinates corresponding to each pixel point on the plane model, sampling is performed in the texture map to obtain the state information corresponding to each pixel point, and the plane model is a preset model covered on the terrain of the virtual scene;

[0194] The shader is called to render the plane model according to the state information corresponding to each pixel point, so as to generate the plane model with grass rendering effect.

[0195] Optionally, the texture map is a three-dimensional texture map, which includes a plurality of two-dimensional texture maps, and each of the two-dimensional texture maps corresponds to a different ray tracing direction when baking the grass model.

[0196] Optionally, before the step of obtaining the texture map, the following steps are further performed:

[0197] Create 2D texture maps;

[0198] In a first ray tracing direction, emitting a tracing ray to the grass model to obtain the state information corresponding to a point on the grass model that interacts with the tracing ray, wherein the first ray tracing direction is any one of a plurality of preset ray tracing directions;

[0199] Recording the state information corresponding to the point on the grass model that interacts with the tracing ray on the corresponding texture coordinates of the two-dimensional texture map, wherein the corresponding texture coordinates are the texture coordinates corresponding to the texture element on the two-dimensional texture map that interacts with the tracing ray;

[0200] The two-dimensional texture map recording the state information obtained in each of the ray tracing directions is combined into the three-dimensional texture map.

[0201] Optionally, the preset multiple ray tracing directions have a preset angle with the X-axis of the spatial coordinate system and are evenly distributed in multiple directions within 360 degrees around the Y-axis of the spatial coordinate system;

[0202] The step of combining the two-dimensional texture maps recorded with the state information obtained in each of the ray tracing directions into the three-dimensional texture map comprises:

[0203] Projecting the first ray tracing direction onto the XZ plane of the spatial coordinate system to obtain a projection direction corresponding to the first ray tracing direction;

[0204] Calculate a first angle between the projection direction corresponding to the first ray tracing direction and the Z axis of the space coordinate system;

[0205] Taking the quotient of the first angle divided by 360 as the third texture coordinate of each texture element in the two-dimensional texture map recording the state information obtained in the first ray tracing direction in the three-dimensional texture map;

[0206] The two-dimensional texture map recording the state information obtained in each of the ray tracing directions is arranged and combined into the three-dimensional texture map according to the calculated third texture coordinates of each texture element in the two-dimensional texture map in the three-dimensional texture map.

[0207] Optionally, sampling in the texture map according to the texture coordinates corresponding to each pixel point on the plane model to obtain the state information corresponding to each pixel point includes:

[0208] Calculating first texture coordinates and second texture coordinates corresponding to each pixel point on the plane model based on a plurality of vertices on the plane model;

[0209] The texture map is sampled according to the first texture coordinates and the second texture coordinates corresponding to each pixel point.

[0210] Optionally, the calculating, based on a plurality of vertices on the plane model, a first texture coordinate and a second texture coordinate corresponding to each pixel point on the plane model includes:

[0211] According to the first texture coordinates and the second texture coordinates corresponding to the first vertex on the plane model, the first texture coordinates and the second texture coordinates corresponding to the second vertex, and the first texture coordinates and the second texture coordinates corresponding to the third vertex, based on the interpolation operation, the first texture coordinates and the second texture coordinates corresponding to the first pixel point are obtained; wherein,

[0212] The first vertex, the second vertex, and the third vertex are any three of the plurality of vertices, and the first pixel point is any pixel point located inside a triangle formed by the first vertex, the second vertex, and the third vertex.

[0213] Optionally, after the step of calculating the first texture coordinates and the second texture coordinates corresponding to each pixel point on the plane model based on the multiple vertices on the plane model, further performing:

[0214] Calculating the third texture coordinates corresponding to each pixel point on the plane model according to the position information of the virtual camera;

[0215] The sampling in the texture map according to the first texture coordinate and the second texture coordinate corresponding to each pixel point includes:

[0216] The texture map is sampled according to the first texture coordinate, the second texture coordinate, and the third texture coordinate corresponding to each pixel point.

[0217] Optionally, calculating the third texture coordinates corresponding to each pixel point on the plane model according to the position information of the virtual camera includes:

[0218] Determining the viewpoint direction of the virtual camera according to the position information;

[0219] Projecting the viewpoint direction onto the XZ plane of the spatial coordinate system to obtain a first vector corresponding to the viewpoint direction, where the first vector is used to represent the projection direction of the viewpoint direction onto the XZ plane of the spatial coordinate system;

[0220] Normalizing the first vector to form a first unit vector corresponding to the first vector;

[0221] Calculating a second angle between the first unit vector and a second unit vector, where the second unit vector is used to represent the direction of the Z axis of the spatial coordinate system;

[0222] The quotient of the second angle divided by 360 is used as the third texture coordinate corresponding to each pixel point on the plane model.

[0223] Optionally, the state information includes at least diffuse reflection information and depth information;

[0224] The calling of the shader to render the plane model according to the state information corresponding to each pixel point to generate the plane model with grass rendering effect includes:

[0225] Calculate the color information corresponding to each pixel point according to the diffuse reflection information corresponding to each pixel point;

[0226] Calculate the depth offset corresponding to each pixel point according to the depth information corresponding to each pixel point;

[0227] Color rendering is performed on each pixel based on the color information corresponding to each pixel, and depth offset is performed on each pixel based on the depth offset corresponding to each pixel, so as to generate the plane model with grass rendering effect.

[0228] The fifth embodiment of the present application provides a computer-readable storage medium, which includes computer instructions. When the computer instructions are executed by a processor, they are used to implement the methods described in the embodiments of the present application.

[0229] It should be noted that the relational terms such as "first" and "second" in this article are only used to distinguish one entity or operation from another entity or operation, and do not require or imply any actual relationship or order between these entities or operations. In addition, the words "include", "have", "include" and "includes" and other similar forms are the same in meaning, and the end of any one or more items after any of the above words is open-ended, and any of the above nouns does not mean that the one or more items have been exhaustively listed or are limited to the one or more items listed.

[0230] As used herein, unless expressly stated otherwise, the term "or" includes all possible combinations, except those that are not feasible. For example, if it is expressed that a database may include A or B, then unless otherwise specifically stated or not feasible, it may include database A, or B, or A and B. As a second example, if it is expressed that a database may include A, B, or C, then unless otherwise specifically stated or not feasible, the database may include database A, or B, or C, or A and B, or A and C, or B and C, or A, B, and C.

[0231] It is worth noting that the above embodiments can be implemented by hardware or software (program code), or a combination of hardware and software. If implemented by software, it can be stored in the above-mentioned computer-readable medium. When the software is executed by a processor, it can execute the above-mentioned disclosed method. The computing unit and other functional units described in the present disclosure can be implemented by hardware or software, or a combination of hardware and software. Those of ordinary skill in the art will also understand that the above-mentioned multiple modules / units can be combined into one module / unit, and each of the above-mentioned modules / units can be further divided into multiple sub-modules / sub-units.

[0232] In the above detailed description, the embodiments have been described with reference to many specific details, which may vary from implementation to implementation. Certain adaptations and modifications may be made to the embodiments. For those skilled in the art, other embodiments may be readily apparent from the specific embodiments disclosed in the present application. This specification and examples are for exemplary purposes only, and the true scope and essence of the present application are described by the claims. The sequence of steps shown in the diagrams is also for the purpose of explanation only and is not intended to be limited to any particular steps or sequence. Therefore, those skilled in the art will appreciate that these steps may be performed in different orders when implementing the same method.

[0233] In the drawings and detailed description of the present application, exemplary embodiments are disclosed. However, many variations and modifications may be made to these embodiments. Accordingly, although specific terms are used, these terms are only general and descriptive and not for the purpose of limitation.

Claims

1. A grass rendering method, characterized in that: The method comprises: Acquire a texture map, wherein the texture map records state information corresponding to at least some points on a preset grass model; According to the texture coordinates corresponding to each pixel point on the plane model, sampling is performed in the texture map to obtain the state information corresponding to each pixel point, and the plane model is a preset model covered on the terrain of the virtual scene; The shader is called to render the plane model according to the state information corresponding to each pixel point, so as to generate the plane model with grass rendering effect.

2. The method according to claim 1, characterized in that The texture map is a three-dimensional texture map, which includes a plurality of two-dimensional texture maps, and each of the two-dimensional texture maps corresponds to a different ray tracing direction when baking the grass model.

3. The method according to claim 2, characterized in that Before the step of obtaining the texture map, the method further includes: Create 2D texture maps; In a first ray tracing direction, emitting a tracing ray to the grass model to obtain the state information corresponding to a point on the grass model that interacts with the tracing ray, wherein the first ray tracing direction is any one of a plurality of preset ray tracing directions; Recording the state information corresponding to the point on the grass model that interacts with the tracing ray on the corresponding texture coordinates of the two-dimensional texture map, wherein the corresponding texture coordinates are the texture coordinates corresponding to the texture element on the two-dimensional texture map that interacts with the tracing ray; The two-dimensional texture map recording the state information obtained in each of the ray tracing directions is combined into the three-dimensional texture map.

4. The method according to claim 3, characterized in that The preset multiple ray tracing directions have a preset angle with the X-axis of the spatial coordinate system and are evenly distributed in multiple directions within 360 degrees around the Y-axis of the spatial coordinate system; The step of combining the two-dimensional texture maps recorded with the state information obtained in each of the ray tracing directions into the three-dimensional texture map comprises: Projecting the first ray tracing direction onto the XZ plane of the spatial coordinate system to obtain a projection direction corresponding to the first ray tracing direction; Calculate a first angle between the projection direction corresponding to the first ray tracing direction and the Z axis of the space coordinate system; Taking the quotient of the first angle divided by 360 as the third texture coordinate of each texture element in the two-dimensional texture map recording the state information obtained in the first ray tracing direction in the three-dimensional texture map; The two-dimensional texture map recording the state information obtained in each of the ray tracing directions is arranged and combined into the three-dimensional texture map according to the calculated third texture coordinates of each texture element in the two-dimensional texture map in the three-dimensional texture map.

5. The method according to claim 1, characterized in that: The sampling in the texture map according to the texture coordinates corresponding to each pixel point on the plane model to obtain the state information corresponding to each pixel point includes: Calculating first texture coordinates and second texture coordinates corresponding to each pixel point on the plane model based on a plurality of vertices on the plane model; The texture map is sampled according to the first texture coordinates and the second texture coordinates corresponding to each pixel point.

6. The method according to claim 5, characterized in that The step of calculating the first texture coordinate and the second texture coordinate corresponding to each pixel point on the plane model based on the plurality of vertices on the plane model comprises: According to the first texture coordinates and the second texture coordinates corresponding to the first vertex on the plane model, the first texture coordinates and the second texture coordinates corresponding to the second vertex, and the first texture coordinates and the second texture coordinates corresponding to the third vertex, based on the interpolation operation, the first texture coordinates and the second texture coordinates corresponding to the first pixel point are obtained; wherein, The first vertex, the second vertex, and the third vertex are any three of the plurality of vertices, and the first pixel point is any pixel point located inside a triangle formed by the first vertex, the second vertex, and the third vertex.

7. The method according to claim 5, characterized in that After the step of calculating the first texture coordinate and the second texture coordinate corresponding to each pixel point on the plane model based on the multiple vertices on the plane model, the method further includes: Calculating the third texture coordinates corresponding to each pixel point on the plane model according to the position information of the virtual camera; The sampling in the texture map according to the first texture coordinate and the second texture coordinate corresponding to each pixel point includes: The texture map is sampled according to the first texture coordinate, the second texture coordinate, and the third texture coordinate corresponding to each pixel point.

8. The method according to claim 7, characterized in that The step of calculating the third texture coordinates corresponding to each pixel point on the plane model according to the position information of the virtual camera includes: Determining the viewpoint direction of the virtual camera according to the position information; Projecting the viewpoint direction onto the XZ plane of the spatial coordinate system to obtain a first vector corresponding to the viewpoint direction, where the first vector is used to represent the projection direction of the viewpoint direction onto the XZ plane of the spatial coordinate system; Normalizing the first vector to form a first unit vector corresponding to the first vector; Calculating a second angle between the first unit vector and a second unit vector, where the second unit vector is used to represent the direction of the Z axis of the spatial coordinate system; The quotient of the second angle divided by 360 is used as the third texture coordinate corresponding to each pixel point on the plane model.

9. The method according to claim 1, characterized in that: The state information includes at least diffuse reflection information and depth information; The calling of the shader to render the plane model according to the state information corresponding to each pixel point to generate the plane model with grass rendering effect includes: Calculate the color information corresponding to each pixel point according to the diffuse reflection information corresponding to each pixel point; Calculate the depth offset corresponding to each pixel point according to the depth information corresponding to each pixel point; Color rendering is performed on each pixel based on the color information corresponding to each pixel, and depth offset is performed on each pixel based on the depth offset corresponding to each pixel, so as to generate the plane model with grass rendering effect.

10. A grass rendering device, characterized in that: The device comprises: an acquisition unit, a sampling unit, and a rendering unit; The acquisition unit is used to acquire a texture map, wherein the texture map records state information corresponding to at least some points on a preset grass model; The sampling unit is used to sample in the texture map according to the texture coordinates corresponding to each pixel point on the plane model to obtain the state information corresponding to each pixel point, and the plane model is a preset model covered on the terrain of the virtual scene; The rendering unit is used to call the shader to render the plane model according to the state information corresponding to each pixel point, so as to generate the plane model with grass rendering effect.

11. A grass rendering system, characterized in that: The system comprises: a baking module and a rendering module; The baking module is used to bake a preset grass model offline to generate a texture map corresponding to the grass model, wherein the texture map records state information corresponding to at least some points on the grass model; The rendering module is used to obtain the texture map; sample the texture map according to the texture coordinates corresponding to each pixel point on the plane model to obtain the state information corresponding to each pixel point, and the plane model is a preset model covered on the virtual scene terrain; call the shader to render the plane model according to the state information corresponding to each pixel point to generate the plane model with grass rendering effect.

12. An electronic device, characterized in that: include: Memory, processor; The memory is used to store one or more computer instructions; The processor is used to execute the one or more computer instructions to implement the method according to any one of claims 1-9.

13. A computer-readable storage medium having one or more computer instructions stored thereon, characterized in that: When the instruction is executed by a processor, the method according to any one of claims 1 to 9 is performed.

Citation Information

Cited By

  • Spi detection system

    CN122875496A