Special effect generation method and device, computer readable storage medium and electronic equipment
By setting up a reflection probe for the associated second model, capturing ambient lighting information and generating a square map, the existing translucent material rendering methods are solved, and the efficient translucent material rendering effect is achieved.
Patent Information
- Application Number
- CN202510060828.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-14
- Publication Date
- 2025-05-13
AI Technical Summary
The existing translucent material rendering method has high computational complexity, high performance consumption, and requires the problem of depth sorting of multiple layers, which increases the computation and memory burden.
By setting a reflection probe for the associated second model, capturing ambient lighting information in real time, creating a square map, and forward sampling of the cubic map, obtaining the sampling results. Based on this result, the first model is rendered to generate a target special effect containing the second model image.
It significantly reduces performance consumption, avoids the need for depth sorting, improves rendering accuracy, and realizes the simulation of translucent effects through opaque materials.
Smart Images

Figure CN119991922A_ABST
Abstract
Description
Background Art
[0002] In the field of modern computer graphics, translucent materials are widely used in games, virtual reality, movie special effects and other fields. Their realistic visual effects can greatly enhance the user experience. Traditional methods of rendering translucent materials rely on ray tracing algorithms or volume rendering. Although these methods can achieve highly realistic visual effects, they are extremely computationally complex.
[0003] In addition, translucent materials need to deal with the depth sorting problem of multiple layers to correctly depict the overlapping relationship between objects. Commonly used sorting algorithms such as depth and transfer or double depth buffering, but these algorithms also increase the computational and memory burden.
[0004] Therefore, it is necessary to provide a new special effect generation method.
[0005] It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of the present invention, and therefore may include information that does not constitute prior art known to ordinary technicians in the field. Summary of the invention
[0006] The present disclosure provides a special effect generation method, a special effect generation device, a computer-readable storage medium and an electronic device, thereby overcoming the problems of high performance consumption and high computational complexity caused by the limitations and defects of related technologies at least to a certain extent.
[0007] According to one aspect of the present disclosure, a special effect generation method is provided, comprising:
[0008] Determine a first model and a second model associated with the first model, set a reflection probe for the second model, and obtain a cube map of the second model based on the reflection probe;
[0009] Acquire the cubemap, and perform forward sampling on the cubemap to obtain a sampling result;
[0010] The first model is rendered according to the sampling result to generate a target special effect of the first model, where the target special effect is an effect including the second model image.
[0011] In an exemplary embodiment of the present disclosure, setting a reflection probe for the second model includes:
[0012] Create a reflection probe and obtain a cube space corresponding to the reflection probe;
[0013] The position of the cubic space is adjusted so that the second model is located in the cubic space.
[0014] In an exemplary embodiment of the present disclosure, obtaining the cubemap includes:
[0015] Acquire an incident light direction vector of the second model and a surface normal vector of the second model, and obtain a reflected light direction vector of the second model according to the incident light direction vector and the surface normal vector;
[0016] Obtain a first direction vector based on the reflected light direction vector, the first world space position of the second model, and the second world space position of the reflection probe;
[0017] The cube map is sampled based on the first direction vector to obtain a first sampling result, and the first sampling result is decoded to obtain a decoded color value.
[0018] In an exemplary embodiment of the present disclosure, the acquiring the incident light direction vector of the second model and the surface normal vector of the second model includes:
[0019] Obtaining a third world space position of the camera, and subtracting the first world space position from the third world space position to obtain the incident light direction vector;
[0020] A local normal vector of the second model is obtained, and the local normal vector of the second model is converted into a world space to obtain the surface normal vector.
[0021] In an exemplary embodiment of the present disclosure, obtaining the reflected light direction vector of the second model according to the incident light direction vector and the surface normal vector includes:
[0022] Determine a second direction vector opposite to the direction of the incident light according to the incident light direction vector;
[0023] The reflected light direction vector of the second model is obtained according to the second direction vector and the surface normal vector.
[0024] In an exemplary embodiment of the present disclosure, obtaining a first direction vector based on the reflected light direction vector, the first world space position of the second model, and the second world space position of the reflection probe includes:
[0025] Subtracting the second world space position from the first world space position to obtain an offset of the reflected light direction vector;
[0026] A preset scalar value is obtained, and the reflected light direction vector is adjusted based on the scalar value, and the first direction vector is obtained through the adjusted reflected light direction vector and the offset of the reflected light direction vector.
[0027] In an exemplary embodiment of the present disclosure, forward sampling the cubemap to obtain a sampling result includes:
[0028] A sampling direction vector is determined according to the incident light direction vector, and the decoded color value is sampled according to the sampling direction vector to obtain a second sampling result.
[0029] In an exemplary embodiment of the present disclosure, determining a sampling direction vector according to the incident light direction vector includes:
[0030] The incident light direction is determined according to the incident light direction vector, and a direction vector opposite to the incident light direction is determined as the sampling direction vector.
[0031] In an exemplary embodiment of the present disclosure, after obtaining the sampling result, the method further includes:
[0032] A preset adjustment parameter and a preset depth parameter are obtained, and the sampling result is adjusted based on the preset adjustment parameter and the preset depth parameter.
[0033] According to one aspect of the present disclosure, there is provided a special effect generating device, comprising:
[0034] A reflection probe setting module, used for determining a first model and a second model associated with the first model, setting a reflection probe for the second model, and obtaining a cube map of the second model based on the reflection probe;
[0035] A sampling module, used for reading the cube map, performing forward sampling on the cube map, and obtaining a sampling result;
[0036] A special effects rendering module is used to render the first model according to the sampling result to generate a target special effect of the first model.
[0037] According to one aspect of the present disclosure, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the method described in any one of the above exemplary embodiments is implemented.
[0038] According to one aspect of the present disclosure, there is provided an electronic device, including:
[0039] A processor; and a memory for storing executable instructions of the processor;
[0040] The processor is configured to perform the method described in any of the above exemplary embodiments by executing the executable instructions.
[0041] According to one aspect of the present disclosure, a computer program product is provided, including a computer program, wherein when the computer program is executed by a processor, the special effect generating method described in any one of the above exemplary embodiments is implemented.
[0042] The embodiment of the present disclosure provides a special effect generation method, which determines a first model and a second model associated with the first model, sets a reflection probe for the second model, obtains a cube map of the second model based on the reflection probe, obtains the cube map, performs forward sampling on the cube map, and obtains a sampling result; renders the first model according to the sampling result, and generates a target special effect of the first model, wherein the target special effect is an effect containing an image of the second model. On the one hand, after determining the first model and the second model, sets a reflection probe for the second model, and uses the reflection probe to capture the ambient lighting information of the second model in real time, obtains the cube map of the second model, obtains the cube map, performs forward sampling on the cube map, obtains the sampling result, and renders the first model according to the sampling result, thereby realizing the simulation of the semi-transparent effect by the opaque material, and significantly reducing the performance consumption. On the other hand, only by forward sampling of the cube map, the simulation of the semi-transparent effect by the opaque material is realized, which solves the problem of depth sorting required for semi-transparent rendering in the related art, eliminates the need for depth sorting, and improves the rendering correctness.
[0043] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] The accompanying drawings herein are incorporated into and constitute a part of the specification, illustrate embodiments consistent with the present invention, and together with the specification are used to explain the principles of the present invention. Obviously, the accompanying drawings described below are only some embodiments of the present invention, and for those of ordinary skill in the art, other accompanying drawings can be obtained based on these accompanying drawings without creative work.
[0045] Figure 1 The following schematically shows a flow chart of a special effect generation method according to an exemplary embodiment of the present disclosure.
[0046] Figure 2 A flow chart of a method for setting a reflection probe for the second model according to an exemplary embodiment of the present disclosure is schematically shown.
[0047] Figure 3 A flow chart of a method for obtaining the cubemap according to an exemplary embodiment of the present disclosure is schematically shown.
[0048] Figure 4A flowchart of a method for obtaining an incident light direction vector of the second model and a surface normal vector of the second model according to an exemplary embodiment of the present disclosure is schematically shown.
[0049] Figure 5 A flowchart of a method for obtaining the reflected light direction vector of the second model according to the incident light direction vector and the surface normal vector according to an example embodiment of the present disclosure is schematically shown.
[0050] Figure 6 A flowchart of a method for obtaining a first direction vector based on the reflected light direction vector, the first world space position of the second model, and the second world space position of the reflection probe according to an exemplary embodiment of the present disclosure is schematically shown.
[0051] Figure 7 The following is a block diagram schematically showing a special effect generating device according to an exemplary embodiment of the present disclosure.
[0052] Figure 8 An electronic device for implementing a special effect generating method according to an exemplary embodiment of the present invention is schematically shown. DETAILED DESCRIPTION
[0053] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in a variety of forms and should not be construed as being limited to the examples set forth herein; on the contrary, these embodiments are provided so that the present invention will be more comprehensive and complete, and the concept of the example embodiments will be fully conveyed to those skilled in the art. The described features, structures, or characteristics may be combined in one or more embodiments in any suitable manner. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present invention. However, those skilled in the art will appreciate that the technical solutions of the present invention may be practiced while omitting one or more of the specific details, or other methods, components, devices, steps, etc. may be adopted. In other cases, known technical solutions are not shown or described in detail to avoid obscuring various aspects of the present invention.
[0054] In addition, the accompanying drawings are only schematic illustrations of the present invention and are not necessarily drawn to scale. The same reference numerals in the figures represent the same or similar parts, and their repeated description will be omitted. Some of the block diagrams shown in the accompanying drawings are functional entities and do not necessarily correspond to physically or logically independent entities. These functional entities can be implemented in software form, or implemented in one or more hardware modules or integrated circuits, or implemented in different networks and / or processor devices and / or microcontroller devices.
[0055] In the field of modern computer graphics, the rendering of translucent materials has always been a challenging topic. Translucent materials are widely used in many fields such as games, virtual reality, and movie special effects. Their realistic visual effects can greatly enhance the user experience. However, the rendering performance of translucent materials is huge, mainly because it needs to deal with complex optical phenomena when light passes through objects, such as refraction, reflection, and scattering.
[0056] Traditional semi-transparent material rendering methods rely on complex ray tracing algorithms or volume rendering technologies. Ray tracing algorithms simulate the interaction between light and objects in the scene to handle complex optical phenomena such as refraction, reflection, and scattering. Ray tracing can achieve highly realistic visual effects, but its computational complexity is extremely high and requires the simulation of a large number of light paths, resulting in very low rendering performance and difficulty in achieving a smooth frame rate in real-time rendering; volume rendering uses voxels to represent data in three-dimensional space and simulates the propagation and scattering of light inside semi-transparent materials by calculating a large number of voxels one by one. Although this method can realistically reproduce complex optical phenomena, it has a huge amount of calculations and is also difficult to meet performance requirements in real-time rendering. In short, ray tracing requires the simulation of a large number of interactions between light and objects, while volume rendering requires the calculation of a large number of voxels one by one. These methods cannot achieve a smooth frame rate in real-time rendering, which seriously affects the user experience.
[0057] In addition, translucent materials need to deal with the depth sorting problem of multiple layers to correctly depict the overlapping relationship between objects. Usually, this is achieved through sorting algorithms such as Depth Pre-pass or Dual DepthBuffer, but these algorithms also increase the computational and memory burden.
[0058] To optimize performance, another commonly used method is pre-computation. However, the limitation of this method is that it cannot dynamically update the lighting information in the scene, resulting in insufficient flexibility and realism in the rendering effect.
[0059] Based on one or more of the above problems, this example implementation first provides a special effect generation method, referring to Figure 1 As shown, the special effect generation method may include the following steps:
[0060] Step S110: determining a first model and a second model associated with the first model, setting a reflection probe for the second model, and obtaining a cubemap of the second model based on the reflection probe;
[0061] Step S120: Obtain the cubemap, perform forward sampling on the cubemap, and obtain a sampling result;
[0062] Step S130: Render the first model according to the sampling result to generate a target special effect of the first model, where the target special effect is an effect including the second model image.
[0063] The above-mentioned special effect generation method determines a first model and a second model associated with the first model, sets a reflection probe for the second model, obtains a cube map of the second model based on the reflection probe; obtains the cube map, performs forward sampling on the cube map, and obtains a sampling result; renders the first model according to the sampling result, and generates a target special effect of the first model, wherein the target special effect is an effect containing an image of the second model. On the one hand, after determining the first model and the second model, sets a reflection probe for the second model, and uses the reflection probe to capture the ambient lighting information of the second model in real time, obtains a cube map of the second model, obtains the cube map, performs forward sampling on the cube map, obtains a sampling result, and renders the first model according to the sampling result, thereby realizing the simulation of the semi-transparent effect by an opaque material, and significantly reducing performance consumption. On the other hand, only by forward sampling of the cube map, the simulation of the semi-transparent effect by the opaque material is realized, which solves the problem of depth sorting required for semi-transparent rendering in the related art, eliminates the need for depth sorting, and improves rendering correctness.
[0064] Hereinafter, each step involved in the special effect generation method according to the exemplary embodiment of the present disclosure is explained and illustrated in detail.
[0065] In step S110, a first model and a second model associated with the first model are determined, a reflection probe is set for the second model, and a cube map of the second model is obtained based on the reflection probe.
[0066] In this example embodiment, the first model is a model that needs to present the target special effects, and can be any model in the game scene. In this example embodiment, the first model is not specifically limited. The second model is a model associated with the first model, and the association can be a position association in the game scene. In this example embodiment, the association is not specifically limited. For example, when the first model is a bridge model, the second model can be a model located under the bridge model in the game scene. After determining the second model, a reflection probe can be set for the second model, wherein the reflection probe is a technology for pre-calculating and storing scene lighting information, and is typically used for environmental reflection and global illumination calculations. The reflection probe can generate a high-resolution cube map that records the reflected light information of the second model in six directions.
[0067] In one embodiment, reference Figure 2As shown, setting a reflection probe for the second model includes:
[0068] Step S210. Create a reflection probe to obtain a cubic space corresponding to the reflection probe;
[0069] Step S220: Adjust the position of the cubic space so that the second model is located in the cubic space.
[0070] In the following, step S210 and step S220 will be further explained and illustrated. Specifically, a reflection probe is created in the game scene to obtain a cube space corresponding to the reflection probe. Only the model in the cube space will be reflected. The position and size of the cube space can be adjusted. Therefore, after obtaining the cube space, the size and position of the cube space can be adjusted so that the second model is located in the cube space to generate a cube map of the second model.
[0071] In step S120, the cube map is obtained, and forward sampling is performed on the cube map to obtain a sampling result.
[0072] After the reflection probe generates a cube map, the shader of the first model must first read the cube map, and after reading the cube map, forward sample the cube map. Among them, the shader is used to generate images in computer graphics and color objects on the screen. When sampling a cube map, sampling coordinates are required. The sampling coordinates are a coordinate system used to sample texture images. The sampling coordinates are usually an extension of texture coordinates, which can be two-dimensional, three-dimensional or higher-dimensional coordinates. When sampling, the shader will look up the corresponding color value in the texture image according to the sampling coordinates corresponding to each pixel, and apply it to the model surface, thereby achieving the effect of texture mapping.
[0073] In one embodiment, reference Figure 3 As shown, obtaining the cube map includes:
[0074] Step S310. Obtain the incident light direction vector of the second model and the surface normal vector of the second model, and obtain the reflected light direction vector of the second model according to the incident light direction vector and the surface normal vector;
[0075] Step S320: Obtain a first direction vector based on the reflected light direction vector, the first world space position of the second model, and the second world space position of the reflection probe;
[0076] Step S330: Sample the cube map based on the first direction vector to obtain a first sampling result, and decode the first sampling result to obtain a decoded color value.
[0077] In the following, step S310-step S330 will be further explained and illustrated. Specifically, the incident light direction vector viewDirWS of the second model and the surface normal vector normalWS of the second model are obtained, wherein the incident light direction vector and the surface normal vector are both normalized vectors, the incident light direction vector is the direction vector from the surface of the virtual object to the camera, and the surface normal vector of the second model is calculated in the vertex shader and passed to the fragment shader, which is the representation of the local normal vector of the second model in the world space. After obtaining the incident light direction vector and the surface normal vector of the second model, the reflected light direction vector reflDir of the second model can be obtained according to the incident light direction vector and the surface normal vector, and the first direction vector uvw can be obtained according to the reflected light direction vector, the first world space position of the second model and the second world space position of the reflection probe. The first direction vector is the sampling direction of the first model shader to sample the cube map, and the first model shader samples the cube map based on the first direction vector to obtain the first sampling result sampleRefl. After obtaining the first sampling result, the first sampling result may be decoded to obtain a decoded color value specCol.
[0078] In one embodiment, reference Figure 4 As shown, obtaining the incident light direction vector of the second model and the surface normal vector of the second model includes:
[0079] Step S410. Obtain the third world space position of the camera, and subtract the first world space position from the third world space position to obtain the incident light direction vector;
[0080] Step S420: Obtain the local normal vector of the second model, convert the local normal vector of the second model into the world space, and obtain the surface normal vector.
[0081] In the following, step S410 and step S420 will be further explained and illustrated. Specifically, obtain the position of the camera in the world space CameraPositionWS, that is, the third world space position, and use the third world space position of the camera to subtract the first world position PositionWS of the second model, and standardize the vector obtained by subtraction. The obtained standardized vector is the incident light direction vector ViewDirWS. Among them, standardization is to set the length of the vector to 1. For the surface normal vector of the second model, you can first obtain the local normal vector of the second model, convert the local normal vector of the second model to the world space, and after converting the local normal vector to the world space, you can standardize the converted vector to obtain the surface normal vector of the second model.
[0082] In one embodiment, reference Figure 5 As shown, according to the incident light direction vector and the surface normal vector, the reflected light direction vector of the second model is obtained, including:
[0083] Step S510. Determine a second direction vector opposite to the incident light direction according to the incident light direction vector;
[0084] Step S520: Obtain the reflected light direction vector of the second model according to the second direction vector and the surface normal vector.
[0085] In the following, step S510 and step S520 will be further explained and illustrated. Specifically, according to the incident light direction vector, a second direction vector opposite to the incident light direction is determined. When the incident light direction vector is viewDirWS, the second direction vector can be expressed as -viewDirWS. After obtaining the second direction vector, the second direction vector and the surface normal vector can be used as parameters of the reflection vector function reflect(). The reflected light direction vector of the second model is obtained through the reflection vector function, and the reflected light direction vector is a standardized vector.
[0086] In one embodiment, reference Figure 6 As shown, based on the reflected light direction vector, the first world space position of the second model, and the second world space position of the reflection probe, a first direction vector is obtained, including:
[0087] Step S610: Subtract the second world space position from the first world space position to obtain an offset of the reflected light direction vector;
[0088] Step S620: Obtain a preset scalar value, adjust the reflected light direction vector based on the scalar value, and obtain the first direction vector through the adjusted reflected light direction vector and the offset of the reflected light direction vector.
[0089] In the following, step S610 and step S620 will be further explained and illustrated. Specifically, the first world space position PositionWS of the second model and the second world space position unity_SpecCube0_ProbePosition.xyz of the reflection probe are obtained, and the second world space position is subtracted from the first world space position to obtain a vector which is the offset of the reflection vector relative to the reflection probe, that is, the offset of the reflected light direction vector. After obtaining the offset of the reflected light direction vector, a preset scalar value scalar is obtained, and the preset scalar value is used to adjust the size of the reflected light direction vector. The preset scalar value is used to adjust the reflected light direction vector, and the first direction vector uvw is obtained based on the adjusted reflected light direction vector and the offset of the reflected light direction vector, that is, uvw=reflDir*scalar+(PositionWS-unity_SpecCube0_ProbePosition.xyz.
[0090] In one embodiment, after the first direction vector is obtained, the cube map can be sampled based on the first direction vector to obtain a first sampling result sampleRefl, which is the color value included in the cube map. The first sampling result sampleRefl = SAMPLE_TEXTURECUBE_LOD (unity_SpecCube0, samplerunity_SpecCube0, uvw, LOD), where SAMPLE_TEXTURECUBE_LOD() is used to sample the color value from the cube map; unity_SpecCube0 represents the cube texture (environment reflection map) to be sampled; samplerunity_SpecCube0 is a sampler associated with the cube texture, which is used to control texture filtering and other sampling parameters; uvw is the first direction vector, which is used to determine the direction from which to sample. LoD (Level of Detail) represents the texture detail level to be used, which is usually used to control the resolution of the texture.
[0091] In one embodiment, after obtaining the first sampling result, the first sampling result can be decoded to obtain a decoded color value specCol, which is the cube map obtained by the shader of the first model. The decoded color value specCol = DecodeHDREnvironment (sampleRefl, unity_SpecCube0_HDR), where the DecodeHDREnvironment() function is used to decode the sampled high dynamic range color value into the final ambient lighting color; sampleRefl is the color value from the cube map sample, that is, the first sampling result; unity_SpecCube0_HDR is used to mark whether the environment map is a high dynamic range.
[0092] In one embodiment, after the shader of the first model obtains the cube map, in order to simulate a semi-transparent scene in the first model, the cube map is forward sampled. The forward sampling of the cube map to obtain the sampling result includes:
[0093] A sampling direction vector is determined according to the incident light direction vector, and the decoded color value is sampled according to the sampling direction vector to obtain a second sampling result.
[0094] Specifically, a sampling direction vector is determined according to the incident light direction vector, and the decoded color value is sampled according to the sampling direction vector to obtain a second sampling result.
[0095] In one implementation, determining a sampling direction vector according to the incident light direction vector includes:
[0096] The incident light direction is determined according to the incident light direction vector, and a direction vector opposite to the incident light direction is determined as the sampling direction vector.
[0097] Specifically, the incident light direction vector is obtained, the incident light direction is determined according to the incident light direction vector, and the direction vector opposite to the incident light direction is determined as the sampling direction vector. When the incident light direction vector is viewDirWS, the sampling direction vector can be expressed as -viewDirWS. Then, the sampling of the decoded color value by the shader of the first model can be expressed as cubemap = DecodeHDREnvironment(SAMPLE_TEXTURECUBE_LOD(CubeMap,sampler_CubeMap,-input.viewDirWS.xyz,0),1.0).rgb, where the SAMPLE_TEXTURECUBE_LOD() function samples from the cube map; CubeMap is the cube texture to be sampled; sampler_CubeMap is the sampler associated with the CubeMap texture; -input.viewDirWS.xyz is the sampling direction vector. If it is not negated, the reflection (reflected texture) will be sampled; 0 is the LOD (Level of Detail) parameter, indicating the level of detail to be used. Here, 0 means using the highest resolution texture (i.e. the most detailed version); SAMPLE_TEXTURECUBE_LOD is the decoded color value; 1.0 is an additional parameter used to control the intensity or exposure of the decoding; rgb is the final extracted color component, retaining only the RGB part.
[0098] In step S130, the first model is rendered according to the sampling result to generate a target special effect of the first model, where the target special effect is an effect including the second model image.
[0099] In one embodiment, after obtaining the sampling result, the shader of the first model may render the first model according to the sampling result to generate a target special effect in the first model, wherein the target special effect is to display an image containing the second model in the first model.
[0100] In one embodiment, after the shader of the first model performs forward sampling on the cubemap to obtain a sampling result, the intensity and depth of the sampling result may be adjusted to present a better translucent effect. After obtaining the sampling result, the method further includes:
[0101] A preset adjustment parameter and a preset depth parameter are obtained, and the sampling result is adjusted based on the preset adjustment parameter and the preset depth parameter.
[0102] Specifically, get the preset adjustment parameter EnvStr and the preset depth parameter DepthFadeRange; the preset adjustment parameter can be used for artists to adjust the intensity, and the preset depth parameter is used to adjust the depth. The adjustment can refer to CubeMap*EnvStr*saturate(input.texcoord.z*DepthFadeRange); among them, CubeMap is the sampling result, saturate() is used to limit the input value to [0,1], and input.texcoord.z is the depth value of the texture coordinate.
[0103] After the sampling result is adjusted, the first model may be rendered according to the adjusted sampling result to generate a target special effect in the first model.
[0104] The special effects generation method provided by the exemplary embodiment of the present disclosure has at least the following advantages: on the one hand, after determining the first model and the second model, a reflection probe is set for the second model, and the ambient lighting information of the second model is captured in real time through the reflection probe to obtain a cube map of the second model, obtain the cube map, forward sample the cube map, obtain the sampling result, and render the first model according to the sampling result, thereby realizing the simulation of the semi-transparent effect through the opaque material, and significantly reducing the performance consumption. On the other hand, the simulation of the semi-transparent effect by the opaque material is realized only through the forward sampling of the cube map, which solves the problem of depth sorting required for semi-transparent rendering in the related technology, eliminates the need for depth sorting, and improves the rendering correctness.
[0105] The exemplary embodiment of the present disclosure also provides a special effect generating device, referring to Figure 7 As shown, it may include: a reflection probe setting module 710 , a sampling module 720 and a special effect rendering module 730 .
[0106] in:
[0107] A reflection probe setting module 710, configured to determine a first model and a second model associated with the first model, set a reflection probe for the second model, and obtain a cubemap of the second model based on the reflection probe;
[0108] A sampling module 720 is used to obtain the cube map, perform forward sampling on the cube map, and obtain a sampling result;
[0109] The special effect rendering module 730 is used to render the first model according to the sampling result to generate the target special effect of the first model.
[0110] The specific details of each module in the above-mentioned special effect generation device have been described in detail in the corresponding special effect generation method, so they will not be repeated here.
[0111] In an exemplary embodiment of the present disclosure, the reflection probe setting module includes:
[0112] A reflection probe creation module, used to create a reflection probe and obtain a cubic space corresponding to the reflection probe;
[0113] The position adjustment module is used to adjust the position of the cubic space so that the second model is located in the cubic space.
[0114] In an exemplary embodiment of the present disclosure, the sampling module includes:
[0115] a reflected light direction vector determination module, used to obtain the incident light direction vector of the second model and the surface normal vector of the second model, and obtain the reflected light direction vector of the second model according to the incident light direction vector and the surface normal vector;
[0116] a first direction vector determining module, configured to obtain a first direction vector based on the reflected light direction vector, a first world space position of the second model, and a second world space position of the reflection probe;
[0117] The texture sampling module is used to sample the cubic texture based on the first direction vector to obtain a first sampling result, and decode the first sampling result to obtain a decoded color value.
[0118] In an exemplary embodiment of the present disclosure, the reflected light direction vector determination module includes:
[0119] An incident light direction vector acquisition module, used to acquire a third world space position of the camera, and obtain the incident light direction vector by subtracting the first world space position from the third world space position;
[0120] The surface normal vector acquisition module is used to acquire the local normal vector of the second model, convert the local normal vector of the second model into the world space, and obtain the surface normal vector.
[0121] In an exemplary embodiment of the present disclosure, the reflected light direction vector determination module includes:
[0122] A second direction vector determining module, used to determine a second direction vector opposite to the incident light direction according to the incident light direction vector;
[0123] A reflected light direction vector acquisition module is used to obtain the reflected light direction vector of the second model according to the second direction vector and the surface normal vector.
[0124] In an exemplary embodiment of the present disclosure, the first direction vector determining module includes:
[0125] an offset calculation module, configured to obtain an offset of the reflected light direction vector by subtracting the second world space position from the first world space position;
[0126] The first direction vector acquisition module is used to acquire a preset scalar value, adjust the reflected light direction vector based on the scalar value, and obtain the first direction vector through the adjusted reflected light direction vector and the offset of the reflected light direction vector.
[0127] In an exemplary embodiment of the present disclosure, the sampling module includes:
[0128] The second sampling result acquisition module is used to determine a sampling direction vector according to the incident light direction vector, and sample the decoded color value according to the sampling direction vector to obtain a second sampling result.
[0129] In an exemplary embodiment of the present disclosure, the second sampling result acquisition module includes:
[0130] The sampling direction vector determination module is used to determine the incident light direction according to the incident light direction vector, and determine the direction vector opposite to the incident light direction as the sampling direction vector.
[0131] In an exemplary embodiment of the present disclosure, the sampling module further includes:
[0132] The sampling result adjustment module is used to obtain a preset adjustment parameter and a preset depth parameter, and adjust the sampling result based on the preset adjustment parameter and the preset depth parameter.
[0133] It should be noted that, although several modules or units of the equipment for action execution are mentioned in the above detailed description, this division is not mandatory. In fact, according to an embodiment of the present invention, the features and functions of two or more modules or units described above can be embodied in one module or unit. On the contrary, the features and functions of one module or unit described above can be further divided into being embodied by multiple modules or units.
[0134] In addition, although the steps of the method of the present invention are described in a specific order in the drawings, this does not require or imply that the steps must be performed in this specific order, or that all the steps shown must be performed to achieve the desired results. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step, and / or one step may be decomposed into multiple steps, etc.
[0135] In an exemplary embodiment of the present invention, an electronic device capable of implementing the above method is also provided.
[0136] It will be appreciated by those skilled in the art that various aspects of the present invention may be implemented as a system, method or program product. Therefore, various aspects of the present invention may be specifically implemented in the following forms, namely: a complete hardware implementation, a complete software implementation (including firmware, microcode, etc.), or a combination of hardware and software, which may be collectively referred to herein as a "circuit", "module" or "system".
[0137] Refer to the following Figure 8 An electronic device 800 according to this embodiment of the present invention will be described. Figure 8 The electronic device 800 shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0138] like Figure 8 As shown, the electronic device 800 is in the form of a general computing device. The components of the electronic device 800 may include, but are not limited to: the at least one processing unit 810, the at least one storage unit 820, a bus 830 connecting different system components (including the storage unit 820 and the processing unit 810), and a display unit 840.
[0139] The storage unit stores program codes, which can be executed by the processing unit 810, so that the processing unit 810 performs the steps according to various exemplary embodiments of the present invention described in the above “Exemplary Method” section of this specification. For example, the processing unit 810 can perform the following steps: Figure 1 The steps S110 shown in the figure are: determining a first model and a second model associated with the first model, setting a reflection probe for the second model, and obtaining a cube map of the second model based on the reflection probe; S120: obtaining the cube map, forward sampling the cube map, and obtaining a sampling result; S130: rendering the first model according to the sampling result, and generating a target special effect for the first model, wherein the target special effect is an effect including an image of the second model.
[0140] The storage unit 820 may include a readable medium in the form of a volatile storage unit, such as a random access memory unit (RAM) 8201 and / or a cache memory unit 8202 , and may further include a read-only memory unit (ROM) 8203 .
[0141] The storage unit 820 may also include a program / utility 8204 having a set (at least one) of program modules 8205, such program modules 8205 including but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment.
[0142] Bus 830 may represent one or more of several types of bus structures, including a memory unit bus or memory unit controller, a peripheral bus, an accelerated graphics port, a processing unit, or a local bus using any of a variety of bus architectures.
[0143] The electronic device 800 may also communicate with one or more external devices 900 (e.g., keyboards, pointing devices, Bluetooth devices, etc.), may also communicate with one or more devices that enable a user to interact with the electronic device 800, and / or communicate with any device that enables the electronic device 800 to communicate with one or more other computing devices (e.g., routers, modems, etc.). Such communication may be performed via an input / output (I / O) interface 850. Furthermore, the electronic device 800 may also communicate with one or more networks (e.g., local area networks (LANs), wide area networks (WANs), and / or public networks, such as the Internet) via a network adapter 860. As shown, the network adapter 860 communicates with other modules of the electronic device 800 via a bus 830. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 800, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID (Redundant Arrays of Independent Disks, independent redundant disk arrays) systems, tape drives, and data backup storage systems, etc.
[0144] Through the description of the above implementation, it is easy for those skilled in the art to understand that the example implementation described here can be implemented by software, or by software combined with necessary hardware. Therefore, the technical solution according to the implementation of the present invention can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, and includes several instructions to enable a computing device (which can be a personal computer, a server, a terminal device, or a network device, etc.) to execute the method according to the implementation of the present invention.
[0145] In an exemplary embodiment of the present invention, a computer-readable storage medium is also provided, on which a program product capable of implementing the above method of this specification is stored. In some possible implementations, various aspects of the present invention can also be implemented in the form of a program product, which includes a program code, and when the program product is run on a terminal device, the program code is used to enable the terminal device to perform the steps according to various exemplary embodiments of the present invention described in the above "Exemplary Method" section of this specification.
[0146] The program product for implementing the above method according to an embodiment of the present invention may adopt a portable compact disk read-only memory (CD-ROM) and include program code, and may be run on a terminal device, such as a personal computer. However, the program product of the present invention is not limited thereto, and in this document, a readable storage medium may be any tangible medium containing or storing a program, which may be used by or in combination with an instruction execution system, apparatus, or device.
[0147] The program product may use any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.
[0148] Computer readable signal media may include data signals propagated in baseband or as part of a carrier wave, in which readable program code is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Readable signal media may also be any readable medium other than a readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0149] The program code contained on the readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wired, optical cable, RF (Radio Frequency), etc., or any suitable combination of the above.
[0150] Program code for performing the operations of the present invention may be written in any combination of one or more programming languages, including object-oriented programming languages such as Java, C++, etc., and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server. In cases involving a remote computing device, the remote computing device may be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computing device (e.g., through the Internet using an Internet service provider).
[0151] In addition, the above-mentioned figures are only schematic illustrations of the processes included in the method according to an exemplary embodiment of the present invention, and are not intended to be limiting. It is easy to understand that the processes shown in the above-mentioned figures do not indicate or limit the time sequence of these processes. In addition, it is also easy to understand that these processes can be performed synchronously or asynchronously, for example, in multiple modules.
[0152] Other embodiments of the invention will readily occur to those skilled in the art after considering the specification and practicing the invention invented herein. This application is intended to cover any variations, uses or adaptations of the invention that follow the general principles of the invention and include common knowledge or customary techniques in the art that are not invented by the present invention. The specification and examples are to be considered exemplary only, and the true scope and spirit of the invention are indicated by the claims.
Claims
1. A special effect generation method, characterized in that: include: Determine a first model and a second model associated with the first model, set a reflection probe for the second model, and obtain a cube map of the second model based on the reflection probe; Acquire the cubemap, and perform forward sampling on the cubemap to obtain a sampling result; The first model is rendered according to the sampling result to generate a target special effect of the first model, where the target special effect is an effect including the second model image.
2. The method according to claim 1, characterized in that The step of setting a reflection probe for the second model includes: Create a reflection probe and obtain a cube space corresponding to the reflection probe; The position of the cubic space is adjusted so that the second model is located in the cubic space.
3. The method according to claim 1, characterized in that The obtaining of the cube map comprises: Acquire an incident light direction vector of the second model and a surface normal vector of the second model, and obtain a reflected light direction vector of the second model according to the incident light direction vector and the surface normal vector; Obtain a first direction vector based on the reflected light direction vector, the first world space position of the second model, and the second world space position of the reflection probe; The cube map is sampled based on the first direction vector to obtain a first sampling result, and the first sampling result is decoded to obtain a decoded color value.
4. The method according to claim 3, characterized in that The obtaining of the incident light direction vector of the second model and the surface normal vector of the second model includes: Obtaining a third world space position of the camera, and subtracting the first world space position from the third world space position to obtain the incident light direction vector; A local normal vector of the second model is obtained, and the local normal vector of the second model is converted into a world space to obtain the surface normal vector.
5. The method according to claim 3, characterized in that: The step of obtaining the reflected light direction vector of the second model according to the incident light direction vector and the surface normal vector comprises: Determine a second direction vector opposite to the direction of the incident light according to the incident light direction vector; The reflected light direction vector of the second model is obtained according to the second direction vector and the surface normal vector.
6. The method according to claim 3, characterized in that The obtaining a first direction vector based on the reflected light direction vector, the first world space position of the second model, and the second world space position of the reflection probe comprises: Subtracting the second world space position from the first world space position to obtain an offset of the reflected light direction vector; A preset scalar value is obtained, and the reflected light direction vector is adjusted based on the scalar value, and the first direction vector is obtained through the adjusted reflected light direction vector and the offset of the reflected light direction vector.
7. The method according to claim 3, characterized in that The forward sampling of the cube map to obtain a sampling result includes: A sampling direction vector is determined according to the incident light direction vector, and the decoded color value is sampled according to the sampling direction vector to obtain a second sampling result.
8. The method according to claim 7, characterized in that The step of determining a sampling direction vector according to the incident light direction vector comprises: The incident light direction is determined according to the incident light direction vector, and a direction vector opposite to the incident light direction is determined as the sampling direction vector.
9. The method according to claim 1, characterized in that: After obtaining the sampling result, the method further includes: A preset adjustment parameter and a preset depth parameter are obtained, and the sampling result is adjusted based on the preset adjustment parameter and the preset depth parameter.
10. A special effect generating device, characterized in that: include: A reflection probe setting module, used for determining a first model and a second model associated with the first model, setting a reflection probe for the second model, and obtaining a cube map of the second model based on the reflection probe; A sampling module, used for acquiring the cube map, performing forward sampling on the cube map, and obtaining a sampling result; A special effects rendering module is used to render the first model according to the sampling result to generate a target special effect of the first model.
11. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the method according to any one of claims 1 to 9 is implemented.
12. An electronic device, characterized in that: include: processor; A memory, configured to store executable instructions of the processor; The processor is configured to perform the method of any one of claims 1 to 9 by executing the executable instructions.