Method and device for rendering semitransparent effect at mobile terminal
By rendering and texture processing of opaque objects, the complexity of translucent effect rendering on mobile terminals is solved, realizing realistic visual effects and performance balance, and is suitable for mobile terminal applications.
Patent Information
- Application Number
- CN202411168105.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-23
- Publication Date
- 2024-12-03
AI Technical Summary
The prior art is difficult to calculate the translucent effects in three-dimensional games in real time on mobile devices, resulting in large amounts of transmission calculations and unreal refraction effects of light internally, and poor user experience.
By rendering opaque objects, creating a dedicated camera and adjusting parameters, making the non-rendered area black, using texture coordinate sampling to obtain the rendered texture, and creating a translucent effect through black and white texture interpolation, avoiding complex real-time ray tracing calculations.
It realizes high-quality translucent rendering on the mobile side, creates realistic non-transparent objects and easily adjusts the visibility of internal objects, maintains a good performance balance and is suitable for mobile applications.
Smart Images

Figure CN119068104A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of computer graphics rendering, and in particular to a method and apparatus for rendering semi-transparent effects on a mobile terminal, a computing device, and a computer-readable storage medium. Background Art
[0002] In existing 3D games, there is a need to render 3D models of various game props, bonus items, etc. with semi-transparent effects. For example, game props can be placed inside objects such as ice cubes. However, the amount of transmission calculation required to simulate the semi-transparent effect is too large to be calculated in real time on mobile terminals. The conventional solution is to render transparent objects and directly place other objects inside the transparent objects. However, this method cannot achieve the internal refraction effect of light, resulting in unrealistic fusion between objects and poor user experience. Summary of the invention
[0003] In view of this, the embodiments of the present application provide a method and apparatus, a computing device, and a computer-readable storage medium for rendering a semi-transparent effect on a mobile terminal to solve the technical defects existing in the prior art.
[0004] According to a first aspect of an embodiment of the present application, a method for rendering a semi-transparent effect on a mobile terminal is provided, comprising:
[0005] Rendering an opaque object and saving the texture coordinates of the opaque object;
[0006] A first rendering object is placed inside the opaque object, a special camera is created to shoot the inside of the opaque object, and parameters of the special camera are adjusted so that a non-rendering area outside the first rendering object is black, thereby obtaining a first rendering texture;
[0007] Sampling the first rendering texture using the texture coordinates to obtain a second rendering texture;
[0008] The black-and-white texture of the second rendering texture is obtained, and the opaque object and the second rendering texture are interpolated by using the black-and-white texture to obtain a final rendering effect.
[0009] According to a second aspect of an embodiment of the present application, a device for rendering a semi-transparent effect on a mobile terminal is provided, comprising:
[0010] A first computing unit, configured to render an opaque object and save texture coordinates of the opaque object;
[0011] A creating unit, which places a first rendering object inside the opaque object, creates a dedicated camera for photographing the inside of the opaque object, and adjusts parameters of the dedicated camera so that a non-rendering area outside the first rendering object is black, thereby obtaining a first rendering texture;
[0012] a sampling unit, configured to sample the first rendering texture using the texture coordinates to obtain a second rendering texture;
[0013] The second calculation unit is used to obtain the black and white texture of the second rendering texture, and interpolate the opaque object and the second rendering texture through the black and white texture to obtain a final rendering effect.
[0014] According to a third aspect of an embodiment of the present application, a computing device is provided, comprising a memory, a processor, and computer instructions stored in the memory and executable on the processor, wherein when the processor executes the instructions, the steps of the method for rendering a semi-transparent effect on a mobile terminal are implemented.
[0015] According to a fourth aspect of an embodiment of the present application, a computer-readable storage medium is provided, which stores computer instructions, and when the instructions are executed by a processor, the steps of the method for rendering a semi-transparent effect on a mobile terminal are implemented.
[0016] Through the method provided by the embodiment of the present application, a realistic non-transparent object is first created by combining parallax offset and real refraction effects, and then an object that needs to be displayed semi-transparently is added inside the non-transparent object, and a camera that only shoots the rendered target is created; further, the texture coordinates of the non-transparent object are used to sample the rendering result of the object that needs to be displayed semi-transparently, and the black and white texture of the sampling result is used to interpolate and superimpose between the original color of the non-transparent object and the rendering texture of the sampling result to create the final semi-transparent visual effect, and the visibility of the internal objects can be easily adjusted. This solution avoids complex real-time ray tracing calculations by using rendering textures, and maintains a good performance balance while creating complex visual effects, which is suitable for high-quality semi-transparent effects in mobile applications. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 is a structural block diagram of a computing device provided in an embodiment of the present application;
[0018] Figure 2 It is a flowchart of a method for rendering a semi-transparent effect on a mobile terminal provided by an embodiment of the present application;
[0019] Figure 3 This is a schematic diagram of a rendering effect for creating an opaque object provided by an embodiment of the present application;
[0020] Figure 4a This is a schematic diagram of a model in which other rendering objects are placed in an opaque object, provided by an embodiment of the present application;
[0021] Figure 4b is a rendering schematic diagram provided by an embodiment of the present application after an opaque object is placed in a first rendering object;
[0022] Figure 5 is a schematic diagram of an effect of using a dedicated camera to render a first rendering object provided by an embodiment of the present application;
[0023] Figure 6 is a schematic diagram of an effect of using texture coordinates to sample the texture of a first rendering object provided by an embodiment of the present application;
[0024] Figure 7a is a schematic diagram of a semi-transparent rendering effect achieved by a method provided in an embodiment of the present application;
[0025] Figure 7b is another schematic diagram of a semi-transparent rendering effect achieved by a method provided in an embodiment of the present application;
[0026] Figure 8 It is a structural schematic diagram of a device for rendering a semi-transparent effect on a mobile terminal provided in an embodiment of the present application. DETAILED DESCRIPTION
[0027] Many specific details are described in the following description to facilitate a full understanding of the present application. However, the present application can be implemented in many other ways than those described herein, and those skilled in the art can make similar generalizations without violating the connotation of the present application, so the present application is not limited by the specific implementation disclosed below.
[0028] The terms used in one or more embodiments of the present application are only for the purpose of describing specific embodiments, and are not intended to limit one or more embodiments of the present application. The singular forms of "a", "said" and "the" used in one or more embodiments of the present application and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used in one or more embodiments of the present application refers to and includes any or all possible combinations of one or more associated listed items.
[0029] It should be understood that, although the terms first, second, etc. may be used to describe various information in one or more embodiments of the present application, these information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of one or more embodiments of the present application, the first may also be referred to as the second, and similarly, the second may also be referred to as the first. Depending on the context, the word "if" as used herein may be interpreted as "in response to determination".
[0030] In the present application, a method and apparatus for rendering a semi-transparent effect on a mobile terminal, a computing device, and a computer-readable storage medium are provided, which will be described in detail one by one in the following embodiments.
[0031] Figure 1 The structure block diagram of a computing device 100 according to an embodiment of the present application is shown. The components of the computing device 100 include but are not limited to a memory 110 and a processor 120. The processor 120 is connected to the memory 110 via a bus 130, and the database 150 is used to store data.
[0032] The computing device 100 also includes an access device 140 that enables the computing device 100 to communicate via one or more networks 160. Examples of these networks include a public switched telephone network (PSTN), a local area network (LAN), a wide area network (WAN), a personal area network (PAN), or a combination of communication networks such as the Internet. The access device 140 may include one or more of any type of network interface (e.g., a network interface card (NIC)) whether wired or wireless, such as an IEEE 802.11 wireless local area network (WLAN) wireless interface, a World Wide Interoperability for Microwave Access (Wi-MAX) interface, an Ethernet interface, a universal serial bus (USB) interface, a cellular network interface, a Bluetooth interface, a near field communication (NFC) interface, and the like.
[0033] In one embodiment of the present application, the above components of the computing device 100 and Figure 1 Other components not shown in the figure may also be connected to each other, for example, via a bus. It should be understood that Figure 1 The computing device structure block diagram shown is only for the purpose of illustration, and is not intended to limit the scope of the present application. Those skilled in the art may add or replace other components as needed.
[0034] The computing device 100 may be any type of stationary or mobile computing device, including a mobile computer or mobile computing device (e.g., a tablet computer, a personal digital assistant, a laptop computer, a notebook computer, a netbook, etc.), a mobile phone (e.g., a smart phone), a wearable computing device (e.g., a smart watch, smart glasses, etc.), or other types of mobile devices, or a stationary computing device such as a desktop computer or PC. The computing device 100 may also be a mobile or stationary server.
[0035] In the embodiments of the present application, Figure 2 A flowchart of a method for rendering a semi-transparent effect on a mobile terminal provided by the present application is shown, including steps 202 to 208.
[0036] Step 202: Render the opaque object and save its texture coordinates.
[0037] In this step, first create a shader to render an opaque object, such as creating an opaque ice cube. Figure 3 As shown, the texture coordinates of the opaque object, that is, the UV coordinates, are saved.
[0038] Preferably, the parallax offset method is used to render the opaque object to enhance the surface details and depth in the 3D rendering. The method simulates the depth of the surface details of the object by changing the offset of the texture coordinates, and can simulate the concavity and depth of the surface without increasing the geometric complexity. In the embodiment of the present application, the parallax offset method is used to create the required rendering effect on the surface of the opaque object, such as tiny concavities, cracks or bubbles to simulate the translucent effect.
[0039] Furthermore, the parallax offset sampling coordinates of the opaque object are saved. The parallax offset sampling coordinates generally refer to texture coordinates processed by the parallax mapping technology, which are obtained by offsetting the original texture coordinates according to the viewing angle and height map information.
[0040] The original texture coordinates are usually the UV coordinates of the model, and the parallax offset is an offset of the texture coordinates based on the surface's bump information and viewing angle. The result after the offset is still the UV coordinate but after the offset, the offset amount depends on the viewing angle and surface height.
[0041] Step 204: Place a first rendering object inside the opaque object, create a dedicated camera for photographing the inside of the opaque object, and obtain a first rendering texture.
[0042] In this step, the first rendering object to be rendered is placed into the opaque object, such as Figure 4a As shown in the figure, an apple is placed in an ice cube. At this time, since the ice cube is rendered in an opaque way, the apple cannot be seen through the ice cube. Figure 4b shown.
[0043] Furthermore, a special camera is created, which only captures the interior of the opaque object;
[0044] Adjusting the parameters of the dedicated camera so that the non-rendering area except the first rendering object is black;
[0045] Specifically, the culling mask of the dedicated camera is set to the layer of the first rendering object, so that only the first rendering object is rendered; and the background color of the dedicated camera is set to black, so that the area except the first rendering object is black.
[0046] Preferably, various parameters of the camera can be adjusted to be consistent with those of the main camera in real time.
[0047] Further, the dedicated camera renders the first rendering object and passes the rendering texture to the shader, such as Figure 5 shown.
[0048] Step 206: Sample the first rendering texture using the texture coordinates of the opaque object to obtain a second rendering texture.
[0049] In this step, the first rendering texture is sampled using the texture coordinates of the opaque object obtained in step 202 to obtain a rendering result consistent with the light effect of the opaque object.
[0050] In step 202, the parallax offset sampling coordinates of the opaque object are calculated using the parallax offset method. The parallax offset sampling coordinates simulate the refraction path of light in the opaque object and store the offset information based on the viewing angle and the surface of the opaque object.
[0051] Therefore, preferably, the parallax offset coordinates are used in the shader to sample the texture of the first rendering object inside the opaque object, simulating the refraction effect of light passing through the opaque object to obtain a second rendering texture, such as Figure 6 shown.
[0052] Step 208: Obtain the black and white texture of the second rendering texture, and interpolate the opaque object and the second rendering texture through the black and white texture to obtain the final rendering effect.
[0053] The second rendering texture is further processed by RGB channels to generate a black and white texture of the second rendering texture, which is used to control the distribution and intensity of the rendering effect. By adjusting this texture, an effect in which some parts are more transparent and some parts are more opaque can be created.
[0054] For example, the opaque object is an ice cube, and the above black and white texture is used to control the freezing effect of the first rendered object:
[0055] White areas represent highly frozen areas
[0056] Black areas represent less frozen or unfrozen areas
[0057] Grayscale values represent intermediate levels of freezing
[0058] Furthermore, the second rendering texture and the texture of the opaque object are interpolated in combination with the black and white texture to obtain a final rendering result. Schematically, the process includes the following steps:
[0059] (1) Sampling:
[0060] float2 parallaxUVOffset = ViewDir.xy*height; / / Save parallax offset texture coordinates
[0061] fixed4 iceTex = tex2D(_IceTex, IN.uv_IceTex+parallaxUVOffset); / / sample ice surface texture
[0062] fixed4 internalTex=tex2D(_InternalTex,IN.uv_InternalTex+parallaxUVOffset); / / sample internal object rendering texture, using offset UV coordinates
[0063] fixed freezeMask = max(max(internalTex.r, internalTex.g), internalTex.b); / / Process internalTex to get black and white texture (frozen mask)
[0064] (2) Adjust the intensity of the freezing effect:
[0065] freezeMask = smoothstep(0, _FrozenIntensity, freezeMask); This line of code allows you to further adjust the effect of the black and white texture. By changing the value of _FrozenIntensity, you can adjust the overall strength of the freezing effect and the steepness of the transition.
[0066] (3) Use black and white texture for color interpolation:
[0067] fixed3 finalColor=lerp(iceTex.rgb,internalTex.rgb+iceTex.rgb,freezeMask);
[0068] The value of freezeMask comes from the black and white texture, which determines the mixing ratio between the internal rendering and the ice appearance at each pixel. By changing the calculation method of freezeMask, the distribution and intensity of the freezing effect can be easily adjusted, such as Figure 7a-7b shown.
[0069] In the above-mentioned embodiment of the present application, in order to efficiently realize the rendering of translucent objects on the mobile terminal and ensure that the rendering results are as realistic as possible without consuming too many hardware resources, firstly, realistic non-transparent objects are created by combining parallax offset and real refraction effects, and then objects that need to be displayed semi-transparently are added inside the non-transparent objects, and a camera that only shoots the rendered target is created; further, the texture coordinates of the non-transparent objects are used to sample the objects that need to be displayed semi-transparently, and the black and white texture of the sampling results is used to interpolate and superimpose between the original color of the non-transparent objects and the rendering texture of the sampling results to create the final translucent visual effect, and the visibility of the internal objects can be easily adjusted. This solution avoids complex real-time ray tracing calculations by using rendering textures, creating complex visual effects while maintaining a good performance balance, and is suitable for high-quality translucent effects in mobile applications.
[0070] Corresponding to the above method embodiment, the present application also provides an embodiment of a device for rendering a semi-transparent effect on a mobile terminal, such as Figure 8 As shown, the device comprises:
[0071] A first computing unit, configured to render an opaque object and save texture coordinates of the opaque object;
[0072] A creating unit, which places a first rendering object inside the opaque object, creates a dedicated camera for photographing the inside of the opaque object, and adjusts parameters of the dedicated camera so that a non-rendering area outside the first rendering object is black, thereby obtaining a first rendering texture;
[0073] a sampling unit, configured to sample the first rendering texture using the texture coordinates to obtain a second rendering texture;
[0074] The second calculation unit is used to obtain the black and white texture of the second rendering texture, and interpolate the opaque object and the second rendering texture through the black and white texture to obtain a final rendering effect.
[0075] The above is a schematic scheme of a device for rendering semi-transparent effects on a mobile terminal of this embodiment. It should be noted that the technical scheme of the device for rendering semi-transparent effects on a mobile terminal and the technical scheme of the method for rendering semi-transparent effects on a mobile terminal belong to the same concept, and the details not described in detail in the technical scheme of the device for rendering semi-transparent effects on a mobile terminal can be found in the description of the technical scheme of the method for rendering semi-transparent effects on a mobile terminal.
[0076] In one embodiment of the present application, a computing device is also provided, including a memory, a processor, and computer instructions stored in the memory and executable on the processor. When the processor executes the instructions, the steps of the method for rendering a semi-transparent effect on a mobile terminal are implemented.
[0077] The above is a schematic scheme of a computing device of this embodiment. It should be noted that the technical scheme of the computing device and the technical scheme of the method for rendering semi-transparent effects on a mobile terminal are of the same concept, and the details not described in detail in the technical scheme of the computing device can be found in the description of the technical scheme of the method for rendering semi-transparent effects on a mobile terminal.
[0078] An embodiment of the present application further provides a computer-readable storage medium storing computer instructions, which, when executed by a processor, implement the steps of the method for rendering a semi-transparent effect on a mobile terminal as described above.
[0079] The above is a schematic scheme of a computer-readable storage medium of this embodiment. It should be noted that the technical scheme of the storage medium and the technical scheme of the method for rendering semi-transparent effects on a mobile terminal are of the same concept, and the details not described in detail in the technical scheme of the storage medium can be found in the description of the technical scheme of the method for rendering semi-transparent effects on a mobile terminal.
[0080] The above describes specific embodiments of the present application. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the accompanying drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0081] The computer instructions include computer program codes, which may be in source code form, object code form, executable files or some intermediate forms, etc. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium, etc. It should be noted that the content contained in the computer-readable medium may be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.
[0082] It should be noted that, for the above-mentioned method embodiments, for the sake of simplicity of description, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described action sequence, because according to the present application, certain steps can be performed in other sequences or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present application.
[0083] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0084] The preferred embodiments of the present application disclosed above are only used to help explain the present application. The optional embodiments do not describe all the details in detail, nor do they limit the invention to the specific implementation methods described. Obviously, many modifications and changes can be made according to the content of the present application. The present application selects and specifically describes these embodiments in order to better explain the principles and practical applications of the present application, so that those skilled in the art can understand and use the present application well. The present application is only limited by the claims and their full scope and equivalents.
Claims
1. A method for rendering a semi-transparent effect on a mobile terminal, characterized in that: include: Rendering an opaque object and saving the texture coordinates of the opaque object; Put a first rendering object inside the opaque object, create a dedicated camera for photographing the inside of the opaque object, and adjust parameters of the dedicated camera so that a non-rendering area outside the first rendering object is black, thereby obtaining a first rendering texture; Sampling the first rendering texture using the texture coordinates to obtain a second rendering texture; The black-and-white texture of the second rendering texture is obtained, and the opaque object and the second rendering texture are interpolated by using the black-and-white texture to obtain a final rendering effect.
2. The method according to claim 1, wherein: The rendering of the opaque object and saving the texture coordinates of the opaque object includes: The opaque object is rendered using a parallax offset method, and the parallax offset sampling coordinates of the opaque object are saved.
3. The method according to claim 1, wherein: The step of creating a dedicated camera for photographing the interior of the opaque object and adjusting parameters of the dedicated camera includes: The culling mask of the dedicated camera is set as the layer of the first rendering object, and the background color of the dedicated camera is set to black; and other parameters of the dedicated camera are adjusted to be consistent with those of the main camera in real time.
4. The method according to claim 2, wherein: Sampling the first rendering texture using the texture coordinates to obtain a second rendering texture includes: The first rendering texture is sampled in a shader using the parallax offset coordinates to obtain a second rendering texture.
5. The method according to claim 1, wherein: The interpolating the opaque object and the second rendering texture by using the black and white texture to obtain a final rendering effect comprises: By adjusting the value of the black and white texture, the mixing ratio between the second rendering texture and the opaque object appearance texture is adjusted, thereby controlling the distribution and intensity of the semi-transparent effect.
6. A device for rendering a semi-transparent effect on a mobile terminal, characterized in that: include: A first computing unit, configured to render an opaque object and save texture coordinates of the opaque object; A creating unit, which places a first rendering object inside the opaque object, creates a dedicated camera for photographing the inside of the opaque object, and adjusts parameters of the dedicated camera so that a non-rendering area outside the first rendering object is black, thereby obtaining a first rendering texture; a sampling unit, configured to sample the first rendering texture using the texture coordinates to obtain a second rendering texture; The second calculation unit is used to obtain the black and white texture of the second rendering texture, and interpolate the opaque object and the second rendering texture through the black and white texture to obtain a final rendering effect.
7. The device according to claim 6, wherein: The first computing unit further includes: The opaque object is rendered using a parallax offset method, and the parallax offset sampling coordinates of the opaque object are saved.
8. The device according to claim 6, wherein: The creation unit also includes: The culling mask of the dedicated camera is set as the layer of the first rendering object, and the background color of the dedicated camera is set to black; and other parameters of the dedicated camera are adjusted to be consistent with those of the main camera in real time.
9. A computing device comprising a memory, a processor, and computer instructions stored in the memory and executable on the processor, characterized in that: When the processor executes the instructions, the steps of the method according to any one of claims 1 to 5 are implemented.
10. A computer-readable storage medium storing computer instructions, characterized in that: When the instruction is executed by a processor, the steps of the method described in any one of claims 1 to 5 are implemented.
