Disclosure of Invention
The application provides a reflection texture complement method, a device, equipment and a storage medium, which are used for solving the inherent defect that reflection textures are incomplete and poor in visual effect caused by the fact that reflection content outside a screen cannot be acquired by using a screen space plane reflection technology, and the technical problem that the effect is poor when a sky box sampling result is adopted for repairing the reflection textures.
In view of this, a first aspect of the present application provides a reflective texture complement method, including:
 generating a reflective texture from an image acquired by a primary camera based on a screen space planar reflection technique;
 Rotating the orientation of the primary camera to a reflective orientation, the primary orientation and the reflective orientation of the primary camera being mirrored based on a reflection plane;
 vertically turning over the picture of the main camera, enabling the main camera to render a space box once, and rendering the acquired image to a texture to obtain a sky texture in a reflecting direction;
 and mixing the reflection texture and the sky texture to obtain a complement back reflection texture.
Optionally, the vertically flipping the frame of the main camera includes:
 multiplying the projection matrix of the main camera by a preset parameter matrix to realize vertical overturning of the picture of the main camera, wherein the preset parameter matrix is that
Optionally, the method further comprises:
 and restoring the orientation and projection matrix of the main camera.
Optionally, the mixing the reflection texture and the sky texture to obtain a complementary reflection texture includes:
 Mixing the reflection texture and the sky texture through the A channel to obtain a complement back reflection texture, wherein the mixing process is as follows:
refl.rgb=lerp(reflSkybox.rgb,refl.rgb,refl.a);
 Where refl.rgb is the color of the reflection texture, refl.a is the value of the reflection texture a channel, reflskybox.rgb is the color of the sky texture, and lerp () is a linear interpolation function.
A second aspect of the present application provides a reflective texture complement apparatus comprising:
 a reflection texture generation unit for generating a reflection texture from an image acquired by the main camera based on a screen space plane reflection technique;
 A rotation unit for rotating the orientation of the main camera to a reflection orientation, the primary orientation and the reflection orientation of the main camera being mirrored based on a reflection plane;
 The sky texture generation unit is used for vertically overturning the picture of the main camera, enabling the main camera to render a space box once, and rendering the acquired image to textures to obtain sky textures in the reflecting direction;
 and the texture mixing unit is used for mixing the reflection texture and the sky texture to obtain a complement back reflection texture.
Optionally, the sky texture generating unit is specifically configured to:
 multiplying the projection matrix of the main camera by a preset parameter matrix to realize vertical overturning of the picture of the main camera, wherein the preset parameter matrix is that
And rendering the primary space box by the main camera, and rendering the acquired image to the texture to obtain the sky texture in the reflecting direction.
Optionally, the apparatus further includes:
 and the restoring unit is used for restoring the orientation and the projection matrix of the main camera.
Optionally, the texture mixing unit is specifically configured to:
 Mixing the reflection texture and the sky texture through the A channel to obtain a complement back reflection texture, wherein the mixing process is as follows:
refl.rgb=lerp(reflSkybox.rgb,refl.rgb,refl.a);
 Where refl.rgb is the color of the reflection texture, refl.a is the value of the reflection texture a channel, reflskybox.rgb is the color of the sky texture, and lerp () is a linear interpolation function.
A third aspect of the application provides a reflective texture complement apparatus, the apparatus comprising a processor and a memory;
 the memory is used for storing program codes and transmitting the program codes to the processor;
 the processor is configured to execute the reflective texture complement method of any one of the first aspect according to instructions in the program code.
A fourth aspect of the application provides a computer readable storage medium storing program code which when executed by a processor implements the reflective texture complement method of any one of the first aspects.
From the above technical scheme, the application has the following advantages:
 The application provides a reflection texture complement method which comprises the steps of generating a reflection texture from an image acquired by a main camera based on a screen space plane reflection technology, rotating the direction of the main camera to the reflection direction, enabling the original direction and the reflection direction of the main camera to be mirror images based on the reflection plane, vertically overturning the picture of the main camera, enabling the main camera to render a space box once, enabling the acquired image to be rendered to the texture to obtain the sky texture in the reflection direction, and mixing the reflection texture and the sky texture to obtain the complement back reflection texture.
According to the application, after the reflection texture is generated based on the screen space plane reflection technology, the main camera is rotated to the reflection orientation, and the picture of the main camera is vertically turned over, so that the main camera renders a space box once, the acquired image is rendered to the texture to obtain the sky texture in the reflection direction, the sky texture in the reflection direction is rendered by using the reflection camera, the real reflection result is obtained, the mixed visual effect is good, the inherent defect that the reflection texture is incomplete and the visual effect is poor due to the fact that the reflection content outside the screen cannot be acquired by using the screen space plane reflection technology is improved, and the technical problem that the effect is poor due to the fact that the sky box sampling result is adopted to repair the reflection texture is solved.
Detailed Description
The application provides a reflection texture complement method, a device, equipment and a storage medium, which are used for solving the inherent defect that reflection textures are incomplete and poor in visual effect caused by the fact that reflection content outside a screen cannot be acquired by using a screen space plane reflection technology, and the technical problem that the effect is poor when a sky box sampling result is adopted for repairing the reflection textures.
In order to make the present application better understood by those skilled in the art, the following description will clearly and completely describe the technical solutions in the embodiments of the present application with reference to the accompanying drawings, and it is apparent that the described embodiments are only some embodiments of the present application, not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the application without making any inventive effort, are intended to be within the scope of the application.
Because of the limited machine performance of mobile platforms, it is very suitable to select a screen space planar reflection technique to achieve the reflective visual effect of mobile-end games, which is adopted by many games. The screen space plane reflection technology is essentially that a reflection texture is generated according to a screen image, and then the texture is acquired by a shader and reflection content is drawn, so that the performance is balanced and stable. However, screen space planar reflection techniques have their own limitations. Since the offscreen content is not known, imperfections in the reflective texture are unavoidable, which results in poor reflection at certain viewing angles. In practice, the incomplete part of the reflective texture is often part of the sky in the scene. In order to improve the problem, the application provides a reflection texture complement method, which aims to complement the sky part content missing in the reflection texture generated by a screen space plane reflection technology, so as to optimize the visual effect.
For easy understanding, referring to fig. 1, an embodiment of the present application provides a reflection texture complement method, which is implemented based on a Unity engine, and includes:
 step 101, generating a reflection texture from an image acquired by a main camera based on a screen space plane reflection technique.
The method comprises the steps of obtaining a screen image under the current direction of a current main camera through a game, and then rendering the screen image obtained by the current main camera to textures based on a screen space plane reflection technology to generate reflection textures. The screen space plane reflection technology belongs to the prior art, and a specific generation process of the reflection texture is not repeated here.
Step 102, the main camera is rotated to a reflection orientation, and the original orientation and the reflection orientation of the main camera are mirrored based on a reflection plane.
The current orientation of the main camera of the game is rotated to a reflective orientation, wherein the primary orientation and the reflective orientation of the main camera are mirrored based on a reflective plane, see fig. 2. This approach is similar to that of a reflex camera, but does not require adjustment of the position of the main camera, since here only the content of the space box needs to be rendered, while the camera is always in the center of the space box.
And 103, vertically turning over the picture of the main camera, enabling the main camera to render the space box once, and rendering the acquired image to the texture to obtain the sky texture in the reflecting direction.
The picture of the main camera is flipped vertically after the main camera is rotated in the direction of the main camera by multiplying the projection matrix of the main camera by a preset parameter matrixThe vertical overturning of the picture of the main camera is realized.
After the picture of the main camera is vertically turned over, the main camera renders a space box once, an image currently acquired by the main camera is acquired, the image is rendered to a texture, and the sky texture in the reflecting direction is obtained. The sky texture obtained at this time is a true reflection result.
Further, after the sky texture is acquired, the main camera orientation and projection matrix are restored.
And 104, mixing the reflection texture and the sky texture to obtain the complement back reflection texture.
After the sky texture is acquired, it is necessary to determine how the sky texture and the reflection texture generated by the screen space plane reflection technique are mixed. Embodiments of the present application find that the a-channel of the reflection texture identifies where the texture has actual reflection content, and thus the reflection texture and sky texture can be mixed by the a-channel. The closer to 1 (i.e., the whiter) the a channel tends to draw the content of the reflection texture, and the closer to 0 (i.e., the darker) the sky texture tends to draw the content of the sky texture. The embodiment of the application adopts an interpolation mode to mix the reflection texture and the sky texture, and specifically comprises the following steps:
refl.rgb=lerp(reflSkybox.rgb,refl.rgb,refl.a);
 Where refl.rgb is the color of the reflection texture, refl.a is the value of the reflection texture a channel, reflskybox.rgb is the color of the sky texture, and lerp () is a linear interpolation function.
After the sky texture and the reflection texture are mixed, the reflection content is drawn through a coloring device of a relevant scene object, and the effect after the sky texture is complemented is more attractive than the original effect through comparison.
The performance consumption and visual performance of the screen space plane reflection technology are balanced, the performance consumption of the reflection camera is high, and the visual performance is good. The embodiment of the application optimizes and complements the distortion part in the reflection texture generated by the screen space plane reflection technology by applying the thought of a reflection camera within the acceptable range of performance consumption, optimizes the visual effect, has higher controllability for developers, can adjust the rendering efficiency, allows the developers to balance the image quality expression precision and the performance consumption, and regulates the resolution and the sky box special effect when the sky texture is rendered, so that the visual effect and the rendering efficiency are balanced compared with a space box which is sampled more once in a shader. Because the sky box tone of most game scenes is simple, the reflection texture is not required to be very fine, and the resolution of rendering the sky texture can be completely reduced, so that the rendering time is reduced. Through tests, when the resolution of the sky texture is reduced to 0.04 times of the original resolution, the visual effect of plane reflection is still quite good, the GPU time consumption for rendering the sky texture is 18% -30% of that for rendering the rhodiola rosea empty box, and the time consumption in a reasonable range is increased to replace the great improvement of the plane reflection effect.
In the embodiment of the application, after the reflective texture is generated based on the screen space plane reflection technology, the main camera is rotated to the reflective orientation, and the picture of the main camera is vertically turned over, so that the main camera renders a space box once, the acquired image is rendered to the texture to obtain the sky texture in the reflective direction, the sky texture in the reflective direction is rendered by using the reflective camera, the real reflective result is obtained, the mixed visual effect is good, the inherent defect that the visual effect is poor due to incomplete reflective texture can be improved, and the technical problem that the effect is poor due to the adoption of the sky box sampling result to repair the reflective texture is solved.
The foregoing is an embodiment of a reflective texture filling method provided by the present application, and the following is an embodiment of a reflective texture filling device provided by the present application.
Referring to fig. 3, a reflective texture complement apparatus provided in an embodiment of the present application includes:
 a reflection texture generation unit for generating a reflection texture from an image acquired by the main camera based on a screen space plane reflection technique;
 A rotation unit for rotating an orientation of the main camera to a reflection orientation, the original orientation and the reflection orientation of the main camera being mirrored based on a reflection plane;
 The sky texture generation unit is used for vertically overturning the picture of the main camera, enabling the main camera to render a space box once, and rendering the acquired image to textures to obtain sky textures in the reflecting direction;
 and the texture mixing unit is used for mixing the reflection texture and the sky texture to obtain the complement back reflection texture.
In the embodiment of the application, the reflection texture generation unit acquires the screen image under the current orientation of the current main camera through the game, and then renders the screen image acquired by the current main camera to the texture based on the screen space plane reflection technology to generate the reflection texture. The screen space plane reflection technology belongs to the prior art, and a specific generation process of the reflection texture is not repeated here.
The rotation unit rotates the orientation of the main camera to a reflective orientation, wherein the primary orientation and the reflective orientation of the main camera are mirrored based on a reflection plane. The sky texture generating unit multiplies the projection matrix of the main camera by a preset parameter matrix to realize the vertical overturn of the picture of the main camera, wherein the preset parameter matrix is thatAnd rendering the space box once by the main camera, and rendering the acquired image to the texture to obtain the sky texture in the reflecting direction. The sky texture obtained at this time is a true reflection result.
As a further improvement, the device further comprises:
 and the restoring unit is used for restoring the orientation and the projection matrix of the main camera. After the sky texture generation unit acquires the sky texture, the restoration unit restores the orientation and the projection matrix of the main camera.
After the sky texture is acquired, it is necessary to determine how the sky texture and the reflection texture generated by the screen space plane reflection technique are mixed. Embodiments of the present application find that the a-channel of the reflection texture identifies where the texture has actual reflection content, and thus the reflection texture and sky texture can be mixed by the a-channel. The closer to 1 (i.e., the whiter) the a channel tends to draw the content of the reflection texture, and the closer to 0 (i.e., the darker) the sky texture tends to draw the content of the sky texture. Therefore, the texture mixing unit mixes the reflection texture and the sky texture through the A channel to obtain the complementary back reflection texture, and the mixing process is as follows:
refl.rgb=lerp(reflSkybox.rgb,refl.rgb,refl.a);
 Where refl.rgb is the color of the reflection texture, refl.a is the value of the reflection texture a channel, reflskybox.rgb is the color of the sky texture, and lerp () is a linear interpolation function.
In the embodiment of the application, after the reflective texture is generated based on the screen space plane reflection technology, the main camera is rotated to the reflective orientation, and the picture of the main camera is vertically turned over, so that the main camera renders a space box once, the acquired image is rendered to the texture to obtain the sky texture in the reflective direction, the sky texture in the reflective direction is rendered by using the reflective camera, the real reflective result is obtained, the mixed visual effect is good, the inherent defect that the visual effect is poor due to incomplete reflective texture can be improved, and the technical problem that the effect is poor due to the adoption of the sky box sampling result to repair the reflective texture is solved.
The embodiment of the application also provides a reflective texture complement device, which comprises a processor and a memory;
 the memory is used for storing the program codes and transmitting the program codes to the processor;
 The processor is configured to perform the reflective texture completion method of the foregoing method embodiments according to instructions in the program code.
The embodiment of the application also provides a computer readable storage medium, and the computer readable storage medium is used for storing program codes which are executed by a processor to realize the reflection texture complement method in the embodiment of the method.
It will be clear to those skilled in the art that, for convenience and brevity of description, specific working procedures of the apparatus and units described above may refer to corresponding procedures in the foregoing method embodiments, which are not described herein again.
The terms "first," "second," "third," "fourth," and the like in the description of the application and in the above figures, if any, are used for distinguishing between similar objects and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used may be interchanged where appropriate such that the embodiments of the application described herein may be implemented, for example, in sequences other than those illustrated or otherwise described herein. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
It should be understood that in the present application, "at least one (item)" means one or more, and "a plurality" means two or more. "and/or" is used to describe an association relationship of an associated object, and indicates that three relationships may exist, for example, "a and/or B" may indicate that only a exists, only B exists, and three cases of a and B exist simultaneously, where a and B may be singular or plural. The character "/" generally indicates that the context-dependent object is an "or" relationship. "at least one of" or the like means any combination of these items, including any combination of single item(s) or plural items(s). For example, at least one of a, b or c may represent a, b, c, "a and b", "a and c", "b and c", or "a and b and c", wherein a, b, c may be single or plural.
In the several embodiments provided by the present application, it should be understood that the disclosed apparatus and method may be implemented in other manners. For example, the apparatus embodiments described above are merely illustrative, e.g., the division of the units is merely a logical function division, and there may be additional divisions when actually implemented, e.g., multiple units or components may be combined or integrated into another system, or some features may be omitted or not performed. Alternatively, the coupling or direct coupling or communication connection shown or discussed with each other may be an indirect coupling or communication connection via some interfaces, devices or units, which may be in electrical, mechanical or other form.
The units described as separate units may or may not be physically separate, and units shown as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
In addition, each functional unit in the embodiments of the present application may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit. The integrated units may be implemented in hardware or in software functional units.
The integrated units, if implemented in the form of software functional units and sold or used as stand-alone products, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present application may be embodied in essence or a part contributing to the prior art or all or part of the technical solution in the form of a software product stored in a storage medium, comprising several instructions for executing all or part of the steps of the method according to the embodiments of the present application by means of a computer device (which may be a personal computer, a server, or a network device, etc.). The storage medium includes various media capable of storing program codes, such as a U disk, a removable hard disk, a Read-Only Memory (ROM), a random access Memory (Random Access Memory, RAM), a magnetic disk, or an optical disk.
While the application has been described in detail with reference to the foregoing embodiments, it will be understood by those skilled in the art that the foregoing embodiments may be modified or equivalents may be substituted for some of the features thereof, and that the modifications or substitutions do not depart from the spirit and scope of the embodiments of the application.