Sub-surface scattering generation method, apparatus, storage medium, and electronic device
Patent Information
- Application Number
- CN202310152358.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-14
- Publication Date
- 2026-10-27
- Estimated Expiration
- 2043-02-14
AI Technical Summary
[0006]本申请至少部分实施例提供了一种次表面散射生成方法、装置、存储介质及电子装置,以至少解决相关技术中依赖额外增加的厚度贴图制作次表面散射效果导致制作成本高、性能消耗大的技术问题
[0011]在本申请至少部分实施例中,通过获取第一方向、第二方向和第三方向,其中,第一方向是由游戏场景内虚拟植物模型在世界空间下的模型顶点与模型原点确定的方向,第二方向为游戏场景内虚拟光源的照射方向,第三方向为游戏场景内虚拟摄像机的视线方向,采用利用第一方向与第二方向确定虚拟植物模型的目标厚度,以及利用第二方向与第三方向确定虚拟植物模型的目标背光强度的方式,进一步对虚拟植物模型的叶片色彩感知要素进行调整,得到目标叶片色彩,基于目标厚度、目标背光强度和目标叶片色彩,生成虚拟植物模型的次表面散射结果,达到了基于虚拟植物模型、虚拟光源和虚拟摄像机确定虚拟植物模型的次表面散射结果的目的,从而实现了在无需增加制作成本的情况下提升虚拟植物模型的次表面散射效果的技术效果,进而解决了相关技术中依赖额外增加的厚度贴图制作次表面散射效果导致制作成本高、性能消耗大的技术问题。
Smart Images

Figure CN116310014B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and more specifically, to a method, apparatus, storage medium, and electronic device for generating subsurface scattering. Background Technology
[0002] In the design of virtual game scenes, it is often necessary to display the realistic effect of virtual plant models. The interaction between plants and light in real-world scenes is quite complex. When light penetrates the leaf area of a plant, it propagates within the gaps between the leaves, thus producing a subsurface scattering effect within the leaf area.
[0003] In related technologies, to mimic the subsurface scattering effect of real-world plant leaf areas, console PC games use screen-space subsurface scattering or ray tracing. These methods are performance-intensive and difficult to apply to mobile games. Mobile games typically achieve the subsurface scattering effect by adding a thickness map to the virtual plant model to control the light scattering intensity. This method increases production costs due to the added thickness map, and sampling this thickness map in the shader also increases rendering performance.
[0004] There is currently no effective solution to the above problems.
[0005] It should be noted that the information disclosed in the background section above is only used to enhance the understanding of the background of this application, and therefore may include information that does not constitute prior art known to those skilled in the art. Summary of the Invention
[0006] This application provides at least some embodiments a method, apparatus, storage medium, and electronic device for generating subsurface scattering, in order to at least solve the technical problems in the related art that rely on additional thickness maps to create subsurface scattering effects, resulting in high production costs and high performance consumption.
[0007] According to one embodiment of this application, a subsurface scattering generation method is provided, comprising: obtaining a first direction, a second direction, and a third direction, wherein the first direction is the direction determined by the model vertex and the model origin of the virtual plant model in world space within the game scene, the second direction is the illumination direction of the virtual light source within the game scene, and the third direction is the line-of-sight direction of the virtual camera within the game scene; determining the target thickness of the virtual plant model using the first direction and the second direction, and determining the target backlight intensity of the virtual plant model using the second direction and the third direction; adjusting the leaf color perception elements of the virtual plant model to obtain the target leaf color; and generating the subsurface scattering result of the virtual plant model based on the target thickness, the target backlight intensity, and the target leaf color.
[0008] According to one embodiment of this application, a subsurface scattering generation device is also provided, comprising: an acquisition module for acquiring a first direction, a second direction, and a third direction, wherein the first direction is the direction determined by the model vertex and the model origin of the virtual plant model in world space within the game scene, the second direction is the illumination direction of the virtual light source within the game scene, and the third direction is the line-of-sight direction of the virtual camera within the game scene; a determination module for determining the target thickness of the virtual plant model using the first direction and the second direction, and determining the target backlight intensity of the virtual plant model using the second direction and the third direction; an adjustment module for adjusting the leaf color perception elements of the virtual plant model to obtain the target leaf color; and a generation module for generating the subsurface scattering result of the virtual plant model based on the target thickness, the target backlight intensity, and the target leaf color.
[0009] According to one embodiment of this application, a computer-readable storage medium is also provided, wherein a computer program is stored in the computer-readable storage medium, and the computer program is configured to execute the subsurface scattering generation method of any of the above claims when running.
[0010] According to one embodiment of this application, an electronic device is also provided, comprising: a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to perform the subsurface scattering generation method of any of the above claims.
[0011] In at least some embodiments of this application, by obtaining a first direction, a second direction, and a third direction, wherein the first direction is the direction determined by the model vertex and the model origin of the virtual plant model in the world space within the game scene, the second direction is the illumination direction of the virtual light source within the game scene, and the third direction is the viewing direction of the virtual camera within the game scene, the target thickness of the virtual plant model is determined using the first and second directions, and the target backlight intensity of the virtual plant model is determined using the second and third directions, the leaf color perception elements of the virtual plant model are further adjusted to obtain the target leaf color. Based on the target thickness, target backlight intensity, and target leaf color, the subsurface scattering result of the virtual plant model is generated, achieving the purpose of determining the subsurface scattering result of the virtual plant model based on the virtual plant model, virtual light source, and virtual camera. This achieves the technical effect of improving the subsurface scattering effect of the virtual plant model without increasing production costs, thereby solving the technical problem in related technologies where relying on additional thickness textures to create subsurface scattering effects leads to high production costs and high performance consumption. Attached Figure Description
[0012] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings:
[0013] Figure 1 This is a hardware structure block diagram of a mobile terminal according to a subsurface scattering generation method according to one embodiment of this application;
[0014] Figure 2 This is a flowchart of a subsurface scattering generation method according to one embodiment of this application;
[0015] Figure 3 This is a schematic diagram of a virtual plant model according to one embodiment of this application;
[0016] Figure 4 This is a schematic diagram illustrating the thickness information of a virtual plant model according to one embodiment of this application;
[0017] Figure 5 This is a schematic diagram of a subsurface scattering result according to one embodiment of this application;
[0018] Figure 6 This is a structural block diagram of a subsurface scattering generation device according to one embodiment of this application;
[0019] Figure 7 This is a schematic diagram of an electronic device according to one embodiment of the present application. Detailed Implementation
[0020] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort should fall within the scope of protection of the present application.
[0021] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0022] It should be noted that, in the specification of this application, the word "for example" is used to mean "used as an example, illustration, or description." Any embodiment described as "for example" in this application is not necessarily to be construed as being more preferred or advantageous than other embodiments. The following description is provided to enable any person skilled in the art to make and use this application. In the following description, details are set forth for purposes of explanation. It should be understood that those skilled in the art will recognize that this application can be made without using these specific details. In other instances, well-known structures and processes will not be described in detail to avoid unnecessarily obscuring the description of this application. Therefore, this application is not intended to be limited to the embodiments shown, but is consistent with the broadest scope of the principles and features disclosed in this application.
[0023] In one possible implementation of this application, the method of increasing model thickness mapping to control light scattering intensity, which is commonly used in the field of computer technology and video games to involve subsurface scattering of virtual plant models, still suffers from high production costs and high performance consumption after the inventors have conducted practice and careful research. Based on this, the application scenario of this application embodiment can be a scenario involving subsurface scattering of virtual plant models in the field of computer technology and video games. In the field of video games, the game type targeted by this application embodiment can be action, adventure, simulation, role-playing, and casual games, etc.
[0024] This application proposes a method for generating subsurface scattering results for virtual plant models in game scenes. It adopts a technical concept of determining the subsurface scattering results of virtual plant models based on virtual plant models, virtual light sources, and virtual cameras. This achieves the technical effect of improving the subsurface scattering effect of virtual plant models without increasing production costs. It solves the technical problems of high production costs and high performance consumption caused by relying on additional thickness maps to create subsurface scattering effects in related technologies.
[0025] The methods described in this application can be executed in a terminal device (e.g., a mobile terminal, a computer terminal, or a similar computing device). Taking a mobile terminal as an example, the mobile terminal can be a smartphone, tablet computer, PDA, mobile internet device, PAD, game console, or other terminal device.
[0026] Figure 1 This is a hardware structure block diagram of a mobile terminal according to a subsurface scattering generation method based on one embodiment of this application. Figure 1 As shown, a mobile terminal may include one or more ( Figure 1 (Only one is shown) Processor 102, memory 104, transmission device 106, input / output device 108, and display device 110. Taking the application of the subsurface scattering generation method to a video game scene through this mobile terminal as an example, processor 102 calls and runs the computer program stored in memory 104 to execute the subsurface scattering generation method. The subsurface scattering result of the virtual plant model in the generated video game scene is transmitted to input / output device 108 and / or display device 110 through transmission device 106, thereby providing the subsurface scattering result of the virtual plant model to the player.
[0027] Still as Figure 1 As shown, the processor 102 may include, but is not limited to, processing devices such as: Central Processing Unit (CPU), Graphics Processing Unit (GPU), Digital Signal Processing (DSP) chip, Microcontroller Unit (MCU), Field Programmable Gate Array (FPGA), Neural-Network Processing Unit (NPU), Tensor Processing Unit (TPU), Artificial Intelligence (AI) type processor, etc.
[0028] Those skilled in the art will understand that Figure 1 The structure shown is for illustrative purposes only and does not limit the structure of the mobile terminal described above. For example, the mobile terminal may also include components that are more... Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown.
[0029] In some optional embodiments primarily focused on gaming scenarios, the aforementioned terminal device may also provide a human-computer interaction interface with a touch-sensitive surface. This interface can sense finger contact and / or gestures to interact with a graphical user interface (GUI). The human-computer interaction functions may include the following: creating web pages, drawing, word processing, creating electronic documents, playing games, video conferencing, instant messaging, sending and receiving emails, call interfaces, playing digital videos, playing digital music, and / or web browsing, etc. Executable instructions for performing the aforementioned human-computer interaction functions are configured / stored in one or more processor-executable computer program products or readable storage media.
[0030] The methods described in this application can also be executed on a server. The server can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms. Taking the subsurface scattering generation method applied to a video game scene via a video game server as an example, the video game server can generate the subsurface scattering results of a virtual plant model in the video game scene based on this method, and provide the subsurface scattering results of the virtual plant model to the player (e.g., by rendering and displaying them on the player's terminal screen, or by providing them to the player through holographic projection, etc.).
[0031] According to one embodiment of this application, an embodiment of a subsurface scattering generation method is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than that shown here.
[0032] This embodiment provides a subsurface scattering generation method that operates on the aforementioned mobile terminal. Figure 2 This is a flowchart of a subsurface scattering generation method according to one embodiment of this application, such as... Figure 2 As shown, the method includes the following steps:
[0033] Step S21: Obtain the first direction, the second direction, and the third direction. The first direction is the direction determined by the model vertex and the model origin of the virtual plant model in the world space within the game scene. The second direction is the illumination direction of the virtual light source within the game scene. The third direction is the line of sight of the virtual camera within the game scene.
[0034] The aforementioned game scene can be a virtual game scene displaying a subsurface scattering effect with virtual plant models. The corresponding game type can be: action (e.g., first-person or third-person shooter games, 2D or 3D fighting games, war action games, and sports action games), adventure (e.g., exploration games, collection games, puzzle games), simulation (e.g., sandbox simulation games, simulation games, strategy simulation games, city-building simulation games, business simulation games), role-playing games, and casual (e.g., board games, casual competitive games, music rhythm games, dress-up games, etc.).
[0035] The aforementioned first direction refers to the direction determined by the model vertex and model origin of the virtual plant model in the world space within the aforementioned virtual game scene. The virtual plant model includes multiple virtual leaves. For example, the virtual plant model can be a virtual tree model, a virtual grass model, or a virtual flower bush model, etc. The model vertex and model origin of the virtual plant model are model points defined by the technicians when creating the virtual plant model. The model file of the virtual plant model records the position information (such as coordinates in world space) of the model vertex and model origin. The specific implementation method for obtaining the aforementioned first direction can be as follows: a first vector is calculated using the position information of the model vertex and model origin, and this first vector is used to represent the aforementioned first direction.
[0036] The second direction mentioned above refers to the illumination direction of a virtual light source within the game scene. This virtual light source is a light source added to the game scene to illuminate scene objects (at least including the aforementioned virtual plant model). One specific implementation method for obtaining the second direction is to obtain the illumination direction of the virtual light source through the game scene file.
[0037] The aforementioned third-party orientation refers to the viewing direction of the virtual camera within the game scene. This virtual camera is a virtual observation camera used to observe scene objects (at least the aforementioned virtual plant model). The viewing direction of the virtual camera is its current orientation within the game scene. One specific implementation of obtaining this third-party orientation is to obtain the viewing direction of the virtual camera through the game scene's scene file.
[0038] Step S22: Determine the target thickness of the virtual plant model using the first direction and the second direction, and determine the target backlight intensity of the virtual plant model using the second direction and the third direction.
[0039] In real-world scenarios, when plants are illuminated by a light source (such as lamplight or sunlight), multiple reflections occur in the gaps between leaves. These reflections, excluding the first reflection that occurs when the light source directly hits the plant surface, are called subsurface scattering. The intensity of subsurface scattering decreases as the number of reflections increases. Along the direction of the light source, the further away the leaf surface is from the light source, the weaker the subsurface scattering intensity. To simulate this real-world phenomenon, the target thickness of the virtual plant model is defined as the thickness of the virtual plant model along the direction of the virtual light source. This target thickness characterizes the subsurface scattering intensity of the virtual plant model when illuminated by the virtual light source; the thicker the target thickness of the virtual plant model (and its leaves), the weaker the subsurface scattering intensity.
[0040] In real-world scenarios, the visual appearance of light on plants depends not only on the plant itself and the light source, but also on the viewing angle. For example, the subsurface scattering observed when standing on the sun-facing side of a tree (i.e., the viewing direction is the same as the direction of the light source) differs from that observed when standing on the shaded side (i.e., the viewing direction is opposite to the direction of the light source). To simulate these real-world phenomena, the target backlight intensity of the virtual plant model is determined using the illumination direction of the virtual light source (i.e., the second direction) and the viewing direction of the virtual camera (i.e., the third direction). This target backlight intensity characterizes the influence of the relationship between the illumination direction of the virtual light source and the viewing direction of the virtual camera on subsurface scattering.
[0041] Step S23: Adjust the leaf color perception elements of the virtual plant model to obtain the target leaf color;
[0042] In real-world scenarios, because the underside of plant leaves experiences less intense light reflection (such as specular reflection), the color saturation of the shaded leaves is usually higher (e.g., leaves facing the light appear as a light green with lower saturation, while leaves in the shade appear as a dark green with higher saturation).
[0043] To simulate the aforementioned color patterns in real-world scenes, subsurface scattering between multiple virtual leaves in the virtual plant model will affect the visual color representation of the virtual plant model. The color perception elements of the virtual plant model's leaves are adjusted to obtain the target leaf color. These leaf color perception elements include at least hue, saturation, and brightness. The target leaf color is the color information of multiple leaves in the virtual plant model considering subsurface scattering.
[0044] Step S24: Based on the target thickness, target backlight intensity, and target leaf color, generate the subsurface scattering results of the virtual plant model.
[0045] According to step S24 above, it is easy to understand that, based on the target thickness, target backlight intensity and target leaf color, the subsurface scattering result of the virtual plant model is generated. Compared with related technologies, the above steps generate a more realistic subsurface scattering result of the virtual plant model without the need to add an additional thickness texture map to the virtual plant model, thereby reducing the production cost and performance consumption in the process of realizing the subsurface scattering effect of the virtual plant model.
[0046] Specifically, the above-mentioned subsurface scattering results of generating the virtual plant model based on the target thickness, target backlight intensity, and target leaf color may also include other methods and steps, which can be referred to in the further description of the embodiments of this application below, and will not be repeated here.
[0047] In at least some embodiments of this application, by obtaining a first direction, a second direction, and a third direction, wherein the first direction is the direction determined by the model vertex and the model origin of the virtual plant model in the world space within the game scene, the second direction is the illumination direction of the virtual light source within the game scene, and the third direction is the viewing direction of the virtual camera within the game scene, the target thickness of the virtual plant model is determined using the first and second directions, and the target backlight intensity of the virtual plant model is determined using the second and third directions, the leaf color perception elements of the virtual plant model are further adjusted to obtain the target leaf color. Based on the target thickness, target backlight intensity, and target leaf color, the subsurface scattering result of the virtual plant model is generated, achieving the purpose of determining the subsurface scattering result of the virtual plant model based on the virtual plant model, virtual light source, and virtual camera. This achieves the technical effect of improving the subsurface scattering effect of the virtual plant model without increasing production costs, thereby solving the technical problem in related technologies where relying on additional thickness textures to create subsurface scattering effects leads to high production costs and high performance consumption.
[0048] The method provided in this application embodiment can be applied to scenarios involving subsurface scattering of virtual plant models in the fields of computer technology and video games, especially in the scenario of generating subsurface scattering results of virtual tree models in game scenarios where the accuracy of lighting effect representation is high. The following uses this scenario as an example to further introduce the above method in this application embodiment.
[0049] Optionally, obtaining the first direction in step S21 may include the following steps:
[0050] Step S211: In the vertex shader, the coordinates of the first vertex of the virtual plant model in model space are converted to the coordinates of the second vertex of the virtual plant model in world space, and the coordinates of the first origin of the virtual plant model in model space are converted to the coordinates of the second origin of the virtual plant model in world space.
[0051] Step S212: Determine the first direction based on the coordinates of the second vertex and the second origin.
[0052] The vertex shader described above is used to manipulate the vertices of the virtual plant model in a programmable manner. Taking the scenario of generating subsurface scattering results for a virtual tree model as an example, Figure 3 This is a schematic diagram of a virtual plant model according to one embodiment of this application, such as... Figure 3 As shown, the virtual plant model is a virtual tree model. The coordinates of vertex a of the virtual tree model in the model space coordinate system are denoted as positionOS (i.e., the first vertex coordinates), and the coordinates of vertex a of the virtual tree model in the world space coordinate system are denoted as positionWS (i.e., the second vertex coordinates). The coordinates of the origin of the virtual tree model in the model space coordinate system are (0,0,0) (i.e., the first origin coordinates), and the coordinates of the origin O of the virtual tree model in the world space coordinate system are denoted as originPositionWS (i.e., the second origin coordinates).
[0053] The first orientation of the virtual tree model is determined in the vertex shader using the following steps:
[0054] Step E31: Using the TransformObjectToWorld function, the model vertex coordinates positionOS are transformed to the world space coordinate system to obtain positionWS, which is...
[0055] float3 positionWS=TransformObjectToWorld(positionOS);
[0056] Step E32: Using the TransformObjectToWorld function, the model's origin coordinates (0,0,0) are transformed to the world space coordinate system, resulting in originPositionWS, which is...
[0057] float3 originPositionWS=float3(TransformObjectToWorld(float3(0,0,0)));
[0058] Step E33: In the world space coordinate system, calculate the direction of the vector Oa between the model vertex a of the virtual tree model and the origin O, i.e.,
[0059] half3 diraction=positionWS–originPositionWS.
[0060] It should be noted that the aforementioned positionOS (i.e., the coordinates of the first vertex), positionWS (i.e., the coordinates of the second vertex), and originPositionWS (i.e., the coordinates of the second origin) can be obtained from the model file of the virtual tree model. Furthermore, the illumination direction of the virtual light source (lightDiraction, i.e., the second direction) and the viewing direction of the virtual camera (viewDirectionWS, i.e., the third direction) can also be obtained from the scene file of the game scene.
[0061] Optionally, in step S22, determining the target thickness of the virtual plant model using the first and second directions may include the following steps:
[0062] Step S221: Normalize the direction vector corresponding to the first direction to obtain the first processing result;
[0063] Step S222: Normalize the direction vector corresponding to the second direction to obtain the second processing result;
[0064] Step S223: Perform a dot product calculation on the first processing result and the second processing result to obtain the target thickness.
[0065] Taking the scenario of generating subsurface scattering results for a virtual tree model as an example, the direction diraction of the vector Oa between the origin O and the origin O is normalized to obtain the first processing result, denoted as normalize(diraction); the illumination direction lightDiraction of the virtual light source in the game scene is normalized to obtain the second processing result, denoted as normalize(lightDiraction). Then, in the vertex shader, the first and second processing results are multiplied to obtain the thickness information (i.e., target thickness) of the virtual tree model. Specifically, halfthickness = saturate(dot(normalize(lightDiraction), normalize(diraction))).
[0066] It's easy to understand that, for different regions of the virtual tree model, the larger the value of the dot product between the vector Oa and the virtual light source direction lightDiraction, the thicker the region, and the darker the color of the corresponding virtual tree model (the virtual tree model corresponding to the maximum thickness threshold is black, and the virtual tree model corresponding to the minimum thickness threshold is white). Based on the thickness information, the thinner the region on the virtual tree model, the easier it is for light to penetrate.
[0067] Figure 4This is a schematic diagram showing the thickness information of a virtual plant model according to one embodiment of this application, such as... Figure 4 As shown, the virtual plant model is a virtual tree model. In the virtual tree model, the color diffusion effect of the leaves behind the virtual light source is affected by the projection of other leaves. For example... Figure 4 In the virtual tree model, the lower half is obscured by other leaves and therefore appears black, while the canopy (such as...) appears black. Figure 4 The top areas of the trees and the leaves around the trees are not or only slightly obscured, thus appearing grayish-white, which basically matches the visual effect of light on plant models in real-world scenes.
[0068] Optionally, in step S22, determining the target backlight intensity of the virtual plant model using the second direction and the third direction may include the following steps:
[0069] Step S224: Determine the fourth direction based on the second direction, wherein the fourth direction is the opposite direction of the irradiation direction;
[0070] Step S225: Perform a dot product calculation on the direction vector corresponding to the third direction and the direction vector corresponding to the fourth direction to obtain the target backlight intensity.
[0071] The second direction mentioned above is the illumination direction of the virtual light source. Since it is necessary to calculate the target backlight intensity of the virtual plant model, the calculation is performed based on the opposite direction of the illumination direction of the virtual light source and the line of sight of the virtual camera to characterize the backlight intensity of the virtual plant model.
[0072] Taking the scenario of generating subsurface scattering results for a virtual tree model as an example, in the vertex shader, a dot product is calculated between the virtual camera's viewDirectionWS and the opposite direction of the virtual light source's illumination direction (i.e., -lightDiraction), resulting in a dot product denoted as VdotL0. Specifically, half VdotL0 = saturate(dot(-lightDiraction,viewDirectionWS)). The dot product result VdotL0 is then used as the target backlight intensity of the virtual tree model.
[0073] Optionally, in step S22, determining the target backlight intensity of the virtual plant model using the second direction and the third direction may include the following steps:
[0074] Step S226: Determine the fourth direction based on the second direction, wherein the fourth direction is the opposite direction of the irradiation direction;
[0075] Step S227: Perform a dot product calculation on the direction vector corresponding to the third direction and the direction vector corresponding to the fourth direction to obtain the initial backlight intensity;
[0076] Step S228: Perform a power operation on the initial backlight intensity and the preset attenuation coefficient to obtain the target backlight intensity, wherein the preset attenuation coefficient is used to control the subsurface scattering attenuation of the virtual plant model.
[0077] To simulate the subsurface scattering effect of plants in real-world scenarios, the target backlight intensity of the virtual plant model is adjusted by setting a preset attenuation coefficient to obtain a more realistic subsurface scattering result.
[0078] Taking the scenario of generating subsurface scattering results for a virtual tree model as an example, in the vertex shader, a dot product is calculated between the virtual camera's viewDirectionWS and the opposite direction of the virtual light source's illumination direction (i.e., -lightDiraction), resulting in a dot product denoted as VdotL0. Specifically, half VdotL0 = saturate(dot(-lightDiraction,viewDirectionWS)). The dot product result VdotL0 is used as the initial backlight intensity of the virtual tree model.
[0079] Furthermore, a preset attenuation coefficient, FallOff, is used to control the attenuation level of subsurface scattering in the virtual tree model. Specifically, the initial backlight intensity VdotL0 is exponentially raised to the preset attenuation coefficient FallOff, resulting in VdotL1. Specifically, VdotL1 = pow(VdotL0, FallOff). The exponentiation result VdotL1 is then used as the target backlight intensity of the virtual tree model.
[0080] Optionally, in step S23, the leaf color perception elements include hue, saturation, and brightness. Adjusting the leaf color perception elements of the virtual plant model to obtain the target leaf color may include the following steps:
[0081] Step S231: Convert the color of the first leaf of the virtual plant model in the first color space to the color of the second leaf of the virtual plant model in the second color space. The first color space is a color space determined by the three primary colors, and the second color space is a color space determined by hue, saturation and brightness.
[0082] Step S232: Adjust the saturation of the second leaf color to obtain the color of the third leaf of the virtual plant model in the second color space;
[0083] Step S233: Convert the color of the third leaf back to the target leaf color of the virtual plant model in the first color space.
[0084] In real-world scenarios, because the underside of plant leaves experiences less intense light reflection (such as specular reflection), the color saturation of the shaded leaves is usually higher (e.g., leaves facing the light appear as a light green with lower saturation, while leaves in the shade appear as a dark green with higher saturation).
[0085] Taking the scenario of generating subsurface scattering results for a virtual tree model as an example, to simulate the saturation rules of plant leaves in a real-world scene, the vertex shader first converts the color space corresponding to the virtual tree model from RGB space (i.e., the first color space) to HSV space (i.e., the second color space) to obtain the color information of the leaves in the virtual tree model. The color information in HSV space includes: hue value (Hue, H), saturation value (S), and value (V). Then, according to the preset saturation adjustment rules, the saturation value (S value) of the backlit leaves in the virtual tree model is adjusted (usually increased) to obtain the adjusted color information of the virtual tree model.
[0086] Specifically, the above-mentioned method for converting the original color space corresponding to the virtual tree model from RGB space to HSV space can be as follows: obtain the color information leavesColor0 (i.e., the color of the first leaf) of the virtual tree model in RGB space, and convert the color information leavesColor0 in RGB space to HSV space through the general color space conversion function RGBtoHSV to obtain the color information leavesColorHSV0 (i.e., the color of the second leaf) in RGB space. That is, half3leavesColorHSV0 = RGBtoHSV(leavesColor0).
[0087] Specifically, the aforementioned preset saturation adjustment rules can be pre-set by artists or game designers. For example, leavesColorHSV0.x represents the hue value (H value) in the color information before saturation adjustment, leavesColorHSV0.y represents the saturation value (S value) in the color information before saturation adjustment, leavesColorHSV0.z represents the brightness value (V value) in the color information before saturation adjustment, and the color information after saturation adjustment is represented as leavesColorHSV1 (i.e., the third leaf color). The aforementioned preset saturation adjustment rule is "increase the saturation value by 0.25", and the aforementioned saturation adjustment process can be expressed as:
[0088] leavesColorHSV1=
[0089] half3(leavesColorHSV0.x,leavesColorHSV0.y+0.25,leavesColorHSV0.z).
[0090] Furthermore, the color information leavesColorHSV1 after adjusting the saturation is converted back to the RGB space to obtain the color information leavesColor1 in the RGB space after adjusting the saturation (i.e., the target leaf color). Specifically, the following conversion is performed using the general color space conversion function HSVtoRGB: half3 leavesColor1=HSVtoRGB(leavesColorHSV1).
[0091] By using the above methods and steps, the saturation rules of plant leaves in real-world scenes can be simulated to adjust the leaf color of the virtual tree model, so as to obtain a more realistic subsurface scattering result.
[0092] Optionally, in step S24, generating the subsurface scattering result of the virtual plant model based on the target thickness, target backlight intensity, and target leaf color may include the following steps:
[0093] Step S241: Perform convolution calculations on the target thickness, target backlight intensity, and target blade color to obtain the subsurface scattering results.
[0094] Taking the scenario of generating subsurface scattering results for a virtual tree model as an example, based on the above dot product result VdotL0 (i.e., target backlight intensity), the thickness information of the virtual tree model (i.e., target thickness), and the color information leavesColor1 in the RGB space after adjusting the saturation (i.e., target leaf color), the subsurface scattering result finalColor of the virtual tree model is calculated, that is, half3 finalColor=VdotL0×thickness×leavesColor1.
[0095] Preferably, a preset attenuation coefficient FallOff is used to control the attenuation of subsurface scattering of the virtual tree model. Based on the above power operation result VdotL1 (i.e., target backlight intensity), the thickness information of the virtual tree model (i.e., target thickness), and the color information leavesColor1 in the RGB space after saturation adjustment (i.e., target leaf color), the subsurface scattering result finalColor of the virtual tree model is calculated, that is, half3finalColor=VdotL1×thickness×leavesColor1.
[0096] Figure 5This is a schematic diagram of a subsurface scattering result according to one embodiment of this application, as shown below. Figure 5 As shown, the method provided in this application embodiment, based on the direction determined by the model vertex and model origin of the virtual plant model in the world space, the illumination direction of the virtual light source, and the line of sight of the virtual camera, simulates the thickness factor, backlight intensity factor, color perception factor (such as saturation rule), and subsurface scattering attenuation factor of plants in real scenes when they are illuminated. The resulting virtual plant model has a strong sense of physical realism in its subsurface scattering results, which can enhance the player's immersion and gaming experience in the game scene.
[0097] It is easy to understand that the subsurface scattering generation method provided in the embodiments of this application can create the subsurface scattering effect of the virtual plant model without adding an extra thickness texture to the virtual plant model. In other words, it improves the subsurface scattering performance of the virtual plant model without increasing the production cost and performance consumption.
[0098] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods according to the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as a magnetic disk or optical disk) and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of this application.
[0099] This embodiment also provides a subsurface scattering generation device for implementing the above embodiments and preferred embodiments; details already described will not be repeated. As used below, the term "module" can refer to a combination of software and / or hardware that performs a predetermined function. Although the device described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.
[0100] Figure 6 This is a structural block diagram of a subsurface scattering generation device according to one embodiment of this application, such as... Figure 6As shown, the device includes: an acquisition module 61, used to acquire a first direction, a second direction, and a third direction, wherein the first direction is the direction determined by the model vertex and the model origin of the virtual plant model in world space within the game scene, the second direction is the illumination direction of the virtual light source within the game scene, and the third direction is the line-of-sight direction of the virtual camera within the game scene; a determination module 62, used to determine the target thickness of the virtual plant model using the first direction and the second direction, and to determine the target backlight intensity of the virtual plant model using the second direction and the third direction; an adjustment module 63, used to adjust the leaf color perception elements of the virtual plant model to obtain the target leaf color; and a generation module 64, used to generate the subsurface scattering result of the virtual plant model based on the target thickness, the target backlight intensity, and the target leaf color.
[0101] Optionally, the acquisition module 61 described above is further configured to: in the vertex shader, convert the first vertex coordinates of the virtual plant model in model space to the second vertex coordinates of the virtual plant model in world space, and convert the first origin coordinates of the virtual plant model in model space to the second origin coordinates of the virtual plant model in world space; and determine the first direction based on the second vertex coordinates and the second origin coordinates.
[0102] Optionally, the determining module 62 is further configured to: normalize the direction vector corresponding to the first direction to obtain a first processing result; normalize the direction vector corresponding to the second direction to obtain a second processing result; and perform a dot product calculation on the first processing result and the second processing result to obtain the target thickness.
[0103] Optionally, the determining module 62 is further configured to: determine a fourth direction based on the second direction, wherein the fourth direction is the opposite direction of the illumination direction; and perform a dot product calculation on the direction vector corresponding to the third direction and the direction vector corresponding to the fourth direction to obtain the target backlight intensity.
[0104] Optionally, the aforementioned determining module 62 is further configured to: determine a fourth direction based on the second direction, wherein the fourth direction is the opposite direction of the illumination direction; perform a dot product calculation on the direction vector corresponding to the third direction and the direction vector corresponding to the fourth direction to obtain the initial backlight intensity; and perform a power operation on the initial backlight intensity and a preset attenuation coefficient to obtain the target backlight intensity, wherein the preset attenuation coefficient is used to control the subsurface scattering attenuation of the virtual plant model.
[0105] Optionally, the adjustment module 63 is further configured to: convert the color of the first leaf of the virtual plant model in the first color space to the color of the second leaf of the virtual plant model in the second color space, wherein the first color space is a color space determined by the three primary colors, and the second color space is a color space determined by hue, saturation, and brightness; adjust the saturation of the second leaf color to obtain the color of the third leaf of the virtual plant model in the second color space; and convert the third leaf color back to the target leaf color of the virtual plant model in the first color space.
[0106] Optionally, the above-mentioned generation module 64 is also used to: perform convolution calculations on the target thickness, target backlight intensity and target blade color to obtain subsurface scattering results.
[0107] It should be noted that the above modules can be implemented by software or hardware. For the latter, they can be implemented in the following ways, but are not limited to: all the above modules are located in the same processor; or, the above modules are located in different processors in any combination.
[0108] Embodiments of this application also provide a computer-readable storage medium storing a computer program, wherein the computer program is configured to execute the steps in any of the above method embodiments when run.
[0109] Optionally, in this embodiment, the computer-readable storage medium may include, but is not limited to, various media capable of storing computer programs, such as USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.
[0110] Optionally, in this embodiment, the computer-readable storage medium may be located in any computer terminal in a group of computer terminals in a computer network, or in any mobile terminal in a group of mobile terminals.
[0111] Optionally, in this embodiment, the computer-readable storage medium may be configured to store a computer program for performing the following steps:
[0112] S1, obtain the first direction, the second direction and the third direction, wherein the first direction is the direction determined by the model vertex and the model origin of the virtual plant model in the world space in the game scene, the second direction is the illumination direction of the virtual light source in the game scene, and the third direction is the line of sight of the virtual camera in the game scene.
[0113] S2, using the first and second directions to determine the target thickness of the virtual plant model, and using the second and third directions to determine the target backlight intensity of the virtual plant model;
[0114] S3, adjust the leaf color perception elements of the virtual plant model to obtain the target leaf color;
[0115] S4 generates the subsurface scattering results of the virtual plant model based on the target thickness, target backlight intensity, and target leaf color.
[0116] Optionally, the aforementioned computer-readable storage medium is further configured to store program code for performing the following steps: in a vertex shader, converting the first vertex coordinates of the virtual plant model in model space to the second vertex coordinates of the virtual plant model in world space, and converting the first origin coordinates of the virtual plant model in model space to the second origin coordinates of the virtual plant model in world space; determining a first direction based on the second vertex coordinates and the second origin coordinates.
[0117] Optionally, the aforementioned computer-readable storage medium is further configured to store program code for performing the following steps: normalizing the direction vector corresponding to the first direction to obtain a first processing result; normalizing the direction vector corresponding to the second direction to obtain a second processing result; and performing a dot product calculation on the first processing result and the second processing result to obtain the target thickness.
[0118] Optionally, the aforementioned computer-readable storage medium is further configured to store program code for performing the following steps: determining a fourth direction based on a second direction, wherein the fourth direction is the opposite direction to the illumination direction; performing a dot product calculation on the direction vector corresponding to the third direction and the direction vector corresponding to the fourth direction to obtain the target backlight intensity.
[0119] Optionally, the aforementioned computer-readable storage medium is further configured to store program code for performing the following steps: determining a fourth direction based on a second direction, wherein the fourth direction is the opposite direction of the illumination direction; performing a dot product calculation on the direction vector corresponding to the third direction and the direction vector corresponding to the fourth direction to obtain an initial backlight intensity; and performing a power operation on the initial backlight intensity and a preset attenuation coefficient to obtain a target backlight intensity, wherein the preset attenuation coefficient is used to control the subsurface scattering attenuation of the virtual plant model.
[0120] Optionally, the aforementioned computer-readable storage medium is further configured to store program code for performing the following steps: converting the color of a first leaf of a virtual plant model in a first color space to the color of a second leaf of the virtual plant model in a second color space, wherein the first color space is a color space determined by the three primary colors, and the second color space is a color space determined by hue, saturation, and brightness; adjusting the saturation of the second leaf color to obtain the color of a third leaf of the virtual plant model in the second color space; and converting the third leaf color back to the target leaf color of the virtual plant model in the first color space.
[0121] Optionally, the aforementioned computer-readable storage medium is further configured to store program code for performing the following steps: performing convolution calculations on the target thickness, target backlight intensity, and target blade color to obtain subsurface scattering results.
[0122] In the computer-readable storage medium of the above embodiments, a technical solution for implementing a subsurface scattering generation method is provided. By acquiring a first direction, a second direction, and a third direction, wherein the first direction is determined by the model vertex and model origin of the virtual plant model in world space within the game scene, the second direction is the illumination direction of the virtual light source within the game scene, and the third direction is the viewing direction of the virtual camera within the game scene, the target thickness of the virtual plant model is determined using the first and second directions, and the target backlight intensity of the virtual plant model is determined using the second and third directions. This further adjusts the leaf color perception elements of the virtual plant model to obtain the target leaf color. Based on the target thickness, target backlight intensity, and target leaf color, the subsurface scattering result of the virtual plant model is generated. This achieves the goal of determining the subsurface scattering result of the virtual plant model based on the virtual plant model, virtual light source, and virtual camera, thereby improving the subsurface scattering effect of the virtual plant model without increasing production costs. This solves the technical problem in related technologies where relying on additional thickness textures to create subsurface scattering effects leads to high production costs and high performance consumption.
[0123] Through the above description of the embodiments, those skilled in the art will readily understand that the exemplary embodiments described herein can be implemented by software or by combining software with necessary hardware. Therefore, the technical solutions according to the embodiments of this application can be embodied in the form of a software product, which can be stored in a computer-readable storage medium (such as a CD-ROM, USB flash drive, external hard drive, etc.) or on a network, including several instructions to cause a computing device (such as a personal computer, server, terminal device, or network device, etc.) to execute the methods according to the embodiments of this application.
[0124] In exemplary embodiments of this application, a computer-readable storage medium stores a program product capable of implementing the methods described above in this embodiment. In some possible implementations, various aspects of the embodiments of this application may also be implemented as a program product including program code, which, when the program product is run on a terminal device, causes the terminal device to perform the steps described in the "Exemplary Methods" section of this embodiment according to various exemplary embodiments of this application.
[0125] The program product for implementing the above-described method according to embodiments of this application may employ a portable compact disc read-only memory (CD-ROM) and include program code, and may run on a terminal device, such as a personal computer. However, the program product of the embodiments of this application is not limited thereto. In the embodiments of this application, the computer-readable storage medium may be any tangible medium containing or storing a program that may be used by or in conjunction with an instruction execution system, apparatus, or device.
[0126] The aforementioned program product may take the form of any combination of one or more computer-readable media. Such computer-readable storage media may be, for example, but not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatuses, or devices, or any combination thereof. More specific examples (not exhaustive) of computer-readable storage media include: electrical connections having one or more wires, portable disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.
[0127] It should be noted that the program code contained on the computer-readable storage medium can be transmitted using any suitable medium, including but not limited to wireless, wired, optical fiber, RF, etc., or any suitable combination thereof.
[0128] Embodiments of this application also provide an electronic device including a memory and a processor, wherein the memory stores a computer program and the processor is configured to run the computer program to perform the steps in any of the above method embodiments.
[0129] Optionally, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor and the input / output device is connected to the processor.
[0130] Optionally, in this embodiment, the processor can be configured to perform the following steps via a computer program:
[0131] S1, obtain the first direction, the second direction and the third direction, wherein the first direction is the direction determined by the model vertex and the model origin of the virtual plant model in the world space in the game scene, the second direction is the illumination direction of the virtual light source in the game scene, and the third direction is the line of sight of the virtual camera in the game scene.
[0132] S2, using the first and second directions to determine the target thickness of the virtual plant model, and using the second and third directions to determine the target backlight intensity of the virtual plant model;
[0133] S3, adjust the leaf color perception elements of the virtual plant model to obtain the target leaf color;
[0134] S4 generates the subsurface scattering results of the virtual plant model based on the target thickness, target backlight intensity, and target leaf color.
[0135] Optionally, the processor described above may also be configured to perform the following steps via a computer program: in the vertex shader, converting the first vertex coordinates of the virtual plant model in model space to the second vertex coordinates of the virtual plant model in world space, and converting the first origin coordinates of the virtual plant model in model space to the second origin coordinates of the virtual plant model in world space; and determining the first direction based on the second vertex coordinates and the second origin coordinates.
[0136] Optionally, the processor may also be configured to perform the following steps via a computer program: normalize the direction vector corresponding to the first direction to obtain a first processing result; normalize the direction vector corresponding to the second direction to obtain a second processing result; and perform a dot product calculation on the first processing result and the second processing result to obtain the target thickness.
[0137] Optionally, the processor may also be configured to perform the following steps via a computer program: determining a fourth direction based on the second direction, wherein the fourth direction is the opposite direction of the illumination direction; performing a dot product calculation on the direction vector corresponding to the third direction and the direction vector corresponding to the fourth direction to obtain the target backlight intensity.
[0138] Optionally, the processor may also be configured to perform the following steps via a computer program: determining a fourth direction based on a second direction, wherein the fourth direction is the opposite direction to the illumination direction; performing a dot product calculation on the direction vector corresponding to the third direction and the direction vector corresponding to the fourth direction to obtain an initial backlight intensity; and performing a power operation on the initial backlight intensity and a preset attenuation coefficient to obtain a target backlight intensity, wherein the preset attenuation coefficient is used to control the subsurface scattering attenuation of the virtual plant model.
[0139] Optionally, the processor may also be configured to perform the following steps via a computer program: converting the color of the first leaf of the virtual plant model in a first color space to the color of the second leaf of the virtual plant model in a second color space, wherein the first color space is a color space determined by the three primary colors, and the second color space is a color space determined by hue, saturation, and brightness; adjusting the saturation of the second leaf color to obtain the color of the third leaf of the virtual plant model in the second color space; and converting the third leaf color back to the target leaf color of the virtual plant model in the first color space.
[0140] Optionally, the processor can also be configured to perform the following steps via a computer program: perform convolution calculations on the target thickness, target backlight intensity, and target blade color to obtain subsurface scattering results.
[0141] In the electronic device described in the above embodiments, a technical solution for generating subsurface scattering is provided. By acquiring a first direction, a second direction, and a third direction, where the first direction is determined by the model vertex and model origin of the virtual plant model in world space within the game scene, the second direction is the illumination direction of the virtual light source within the game scene, and the third direction is the viewing direction of the virtual camera within the game scene, the target thickness of the virtual plant model is determined using the first and second directions, and the target backlight intensity of the virtual plant model is determined using the second and third directions. This further adjusts the leaf color perception elements of the virtual plant model to obtain the target leaf color. Based on the target thickness, target backlight intensity, and target leaf color, the subsurface scattering result of the virtual plant model is generated. This achieves the goal of determining the subsurface scattering result of the virtual plant model based on the virtual plant model, virtual light source, and virtual camera, thereby improving the subsurface scattering effect of the virtual plant model without increasing production costs. This solves the technical problem in related technologies where relying on additional thickness textures to create subsurface scattering effects leads to high production costs and high performance consumption.
[0142] Figure 7 This is a schematic diagram of an electronic device according to one embodiment of this application. Figure 7 As shown, the electronic device 700 is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of this application.
[0143] like Figure 7 As shown, the electronic device 700 is presented in the form of a general-purpose computing device. The components of the electronic device 700 may include, but are not limited to: at least one processor 710, at least one memory 720, a bus 730 connecting different system components (including memory 720 and processor 710), and a display 740.
[0144] The memory 720 stores program code that can be executed by the processor 710, causing the processor 710 to perform the steps described in the method section of the embodiments of this application according to various exemplary implementations of this application.
[0145] The memory 720 may include a readable medium in the form of volatile memory cells, such as random access memory (RAM) 7201 and / or cache memory 7202, and may further include read-only memory (ROM) 7203, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory.
[0146] In some instances, memory 720 may also include a program / utility 7204 having a set (at least one) of program modules 7205, including but not limited to: an operating system, one or more application programs, other program modules, and program data. Each or some combination of these examples may include an implementation of a network environment. Memory 720 may further include memory remotely located relative to processor 710, which can be connected to electronic device 700 via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.
[0147] Bus 730 can represent one or more of several types of bus structures, including a memory cell bus or memory cell controller, peripheral bus, graphics acceleration port, processor 710, or a local bus using any of the various bus structures.
[0148] The display 740 may be, for example, a touch-screen liquid crystal display (LCD) that allows a user to interact with the user interface of the electronic device 700.
[0149] Optionally, the electronic device 700 can also communicate with one or more external devices 800 (e.g., keyboard, pointing device, Bluetooth device, etc.), one or more devices that enable a user to interact with the electronic device 700, and / or any device that enables the electronic device 700 to communicate with one or more other computing devices (e.g., router, modem, etc.). This communication can be performed via the input / output (I / O) interface 750. Furthermore, the electronic device 700 can also communicate with one or more networks (e.g., local area network (LAN), wide area network (WAN), and / or public networks, such as the Internet) via a network adapter 760. Figure 7 As shown, network adapter 760 communicates with other modules of electronic device 700 via bus 730. It should be understood that, although... Figure 7 As not shown, other hardware and / or software modules may be used in conjunction with electronic device 700, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, Redundant Arrays of Independent Disks (RAID) systems, tape drives, and data backup storage systems.
[0150] The aforementioned electronic device 700 may also include: a keyboard, a cursor control device (such as a mouse), an input / output interface (I / O interface), a network interface, a power supply, and / or a camera.
[0151] Those skilled in the art will understand that Figure 7 The structure shown is for illustrative purposes only and does not limit the structure of the electronic device described above. For example, the electronic device 700 may also include components that are more... Figure 7 The more or fewer components shown, or having the same Figure 7 Different configurations are shown. The memory 720 can be used to store computer programs and corresponding data, such as the computer program and corresponding data corresponding to the subsurface scattering generation method in this embodiment. The processor 710 executes various functional applications and data processing by running the computer program stored in the memory 720, thereby implementing the aforementioned subsurface scattering generation method.
[0152] The sequence numbers of the embodiments in this application are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0153] In the above embodiments of this application, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0154] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. The device embodiments described above are merely illustrative; for example, the division of units can be a logical functional division, and in actual implementation, there may be other division methods. For instance, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the displayed or discussed mutual coupling, direct coupling, or communication connection may be through some interfaces; the indirect coupling or communication connection between units or modules may be electrical or other forms.
[0155] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0156] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0157] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard drive, magnetic disk, or optical disk.
[0158] The above description is only a preferred embodiment of this application. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of this application, and these improvements and modifications should also be considered within the scope of protection of this application.
Claims
1. A method for generating subsurface scattering, characterized in that, The method includes: Obtain a first direction, a second direction, and a third direction, wherein the first direction is the direction determined by the model vertex and the model origin of the virtual plant model in the game scene in world space, the second direction is the illumination direction of the virtual light source in the game scene, and the third direction is the line of sight direction of the virtual camera in the game scene; The target thickness of the virtual plant model is determined using the first direction and the second direction, and the target backlight intensity of the virtual plant model is determined using the second direction and the third direction. The leaf color perception elements of the virtual plant model are adjusted to obtain the target leaf color, wherein the leaf color perception elements include: hue, saturation and brightness; Based on the target thickness, the target backlight intensity, and the target leaf color, the subsurface scattering result of the virtual plant model is generated; The method of determining the target thickness of the virtual plant model using the first direction and the second direction includes: normalizing the direction vector corresponding to the first direction to obtain a first processing result; normalizing the direction vector corresponding to the second direction to obtain a second processing result; and performing a dot product calculation on the first processing result and the second processing result to obtain the target thickness.
2. The subsurface scattering generation method according to claim 1, characterized in that, Obtaining the first direction includes: In the vertex shader, the first vertex coordinates of the virtual plant model in model space are converted to the second vertex coordinates of the virtual plant model in world space, and the first origin coordinates of the virtual plant model in model space are converted to the second origin coordinates of the virtual plant model in world space. The first direction is determined based on the coordinates of the second vertex and the coordinates of the second origin.
3. The subsurface scattering generation method according to claim 1, characterized in that, Determining the target backlight intensity of the virtual plant model using the second direction and the third direction includes: A fourth direction is determined based on the second direction, wherein the fourth direction is the opposite direction of the irradiation direction; The target backlight intensity is obtained by multiplying the direction vector corresponding to the third direction and the direction vector corresponding to the fourth direction.
4. The subsurface scattering generation method according to claim 1, characterized in that, Determining the target backlight intensity of the virtual plant model using the second direction and the third direction includes: A fourth direction is determined based on the second direction, wherein the fourth direction is the opposite direction of the irradiation direction; The initial backlight intensity is obtained by multiplying the direction vector corresponding to the third direction and the direction vector corresponding to the fourth direction. The target backlight intensity is obtained by exponentiation of the initial backlight intensity and the preset attenuation coefficient, wherein the preset attenuation coefficient is used to control the subsurface scattering attenuation of the virtual plant model.
5. The subsurface scattering generation method according to claim 1, characterized in that, Adjusting the leaf color perception elements of the virtual plant model to obtain the target leaf color includes: The color of the first leaf of the virtual plant model in the first color space is converted to the color of the second leaf of the virtual plant model in the second color space, wherein the first color space is a color space determined by the three primary colors, and the second color space is a color space determined by the hue, the saturation, and the brightness; The saturation of the second leaf color is adjusted to obtain the third leaf color of the virtual plant model in the second color space; The color of the third leaf is converted back to the target leaf color of the virtual plant model in the first color space.
6. The subsurface scattering generation method according to claim 1, characterized in that, Based on the target thickness, the target backlight intensity, and the target leaf color, the subsurface scattering result for generating the virtual plant model includes: The subsurface scattering result is obtained by performing convolution calculations on the target thickness, the target backlight intensity, and the target blade color.
7. A subsurface scattering generation device, characterized in that, The subsurface scattering generation device includes: The acquisition module is used to acquire a first direction, a second direction, and a third direction, wherein the first direction is the direction determined by the model vertex and the model origin of the virtual plant model in the game scene in world space, the second direction is the illumination direction of the virtual light source in the game scene, and the third direction is the line of sight direction of the virtual camera in the game scene. A determining module is configured to determine the target thickness of the virtual plant model using the first direction and the second direction, and to determine the target backlight intensity of the virtual plant model using the second direction and the third direction. The determination of the target thickness of the virtual plant model using the first direction and the second direction includes: normalizing the direction vector corresponding to the first direction to obtain a first processing result; normalizing the direction vector corresponding to the second direction to obtain a second processing result; and performing a dot product calculation on the first processing result and the second processing result to obtain the target thickness. The adjustment module is used to adjust the leaf color perception elements of the virtual plant model to obtain the target leaf color, wherein the leaf color perception elements include: hue, saturation and brightness; The generation module is used to generate the subsurface scattering results of the virtual plant model based on the target thickness, the target backlight intensity, and the target leaf color.
8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, wherein the computer program is configured to execute the subsurface scattering generation method according to any one of claims 1 to 6 when run by a processor.
9. An electronic device comprising a memory and a processor, characterized in that, The memory stores a computer program, and the processor is configured to run the computer program to perform the subsurface scattering generation method according to any one of claims 1 to 6.