Rendering Method and Device for Material Effects
By generating and detecting the platform's shader code through the material attribute node, a targeted material rendering process is implemented, solving the problem of low rendering efficiency of cross-platform multiplexing of material, improving rendering efficiency and reducing device performance overhead.
Patent Information
- Application Number
- CN202210604950.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-30
- Publication Date
- 2025-07-04
- Estimated Expiration
- 2042-05-30
AI Technical Summary
In the virtual engine of multi-operation platforms, when the material rendering process is multiplexed across platforms, the differences in equipment performance and operation conditions of each operating platform make it difficult to achieve certain material effects, affecting the rendering efficiency.
The material attribute node generates the shader codes corresponding to each operating platform, detects the rendering settings of each operating platform, realizes a targeted material effect rendering process, and optimizes the rendering process of the target material on each operating platform.
Improves material rendering efficiency, reduces equipment performance overhead, and ensures smoothness and visual effects on different operating platforms.
Smart Images

Figure CN115018964B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image technology, and in particular, to a rendering method and device for material effects. Background Art
[0002] In a virtual engine, a material editor is usually used to construct the materials of various objects in a virtual scene.
[0003] In related technologies, in a virtual engine that supports multiple operating platforms (such as a PC side, a mobile terminal, etc.), to improve the efficiency of scene construction, the virtual engine also supports cross-platform reuse of materials. During the cross-platform reuse process, corresponding shader codes need to be generated for each operating platform to implement the material rendering process in each operating platform. However, there are differences in device performance, operating conditions, etc. among different operating platforms, resulting in difficulty in implementing certain material effects on some operating platforms, which affects the cross-platform reuse of materials. For example, material effects with high computational performance consumption often cause lags on mobile terminals.
[0004] Therefore, how to implement the rendering process of cross-platform reusable materials in each operating platform has become an urgent technical problem to be solved. Summary of the Invention
[0005] Embodiments of the present invention provide a rendering method and device for material effects, which are used to identify the material effects required for a material reused by multiple operating platforms in each operating platform, so as to execute a targeted rendering process in each operating platform, improve the material rendering efficiency, and reduce the device performance overhead.
[0006] In a first aspect, an embodiment of the present invention provides a rendering method for material effects, and the method includes:
[0007] In response to an operation on a material property node in a material editor, generating shader codes corresponding to each operating platform based on the material property node, where the material property node is associated with a target material reused by multiple operating platforms, and the material property node is used to set the material effects presented by the target material in each operating platform respectively;
[0008] Detecting the shader codes corresponding to each operating platform to obtain the rendering settings corresponding to the target material in each operating platform;
[0009] Rendering the material effects corresponding to the target material in each operating platform according to the rendering settings.
[0010] In a second aspect, an embodiment of the present invention provides a rendering device for material effects, and the rendering device for material effects includes:
[0011] A generation module, configured to generate shader codes corresponding to each operating platform based on a material property node in response to an operation on the material property node in a material editor. The material property node is associated with a target material reused by multiple operating platforms, and the material property node is used to set the material effects presented by the target material in each operating platform respectively.
[0012] A detection module, configured to detect the shader codes corresponding to each operating platform to obtain the rendering settings corresponding to the target material in each operating platform.
[0013] A rendering module, configured to render the material effects corresponding to the target material in each operating platform according to the rendering settings.
[0014] In a third aspect, an embodiment of the present invention provides an electronic device, which includes a processor and a memory. The memory stores executable code, and when the executable code is executed by the processor, the processor can at least implement the method for rendering the material effects in the first aspect.
[0015] An embodiment of the present invention provides a non-transitory machine-readable storage medium, on which executable code is stored. When the executable code is executed by a processor of an electronic device, the processor can at least implement the method for rendering the material effects in the first aspect.
[0016] In the embodiments of the present invention, the virtual engine supports multiple operating platforms (such as PC terminals, mobile terminals, etc.) to reuse the same set of materials (i.e., target materials) and the material property nodes associated with the target materials. For the case where multiple operating platforms reuse the target materials, since the material property nodes can be used to set the material effects presented by the reused target materials in each operating platform respectively, therefore, in response to the operation on the material property nodes in the material editor, shader codes corresponding to each operating platform are generated based on the material property nodes, and the shader codes corresponding to each operating platform can be applied to the rendering process of the target material in each operating platform. And the device conditions and operating situations of different operating platforms are different. Therefore, the rendering process of the target material will be optimized for each operating platform. For this purpose, by detecting the shader codes corresponding to each operating platform, the rendering settings corresponding to the target material in each operating platform can be obtained, so as to clearly indicate the rendering process that needs to be started for the target material in each operating platform through the rendering settings, and avoid misjudgment of the startup state of the material effect. Finally, according to the rendering settings, the material effects corresponding to the target material are rendered in each operating platform, so that the targeted rendering settings can be applied to the rendering process of the target material in each operating platform, and the targeted optimization of the rendering process of the target material is realized in each operating platform. In the embodiments of the present invention, by detecting the shader codes corresponding to each operating platform, the rendering settings corresponding to the target material in each operating platform can be obtained, and the targeted rendering settings are applied to the rendering process of the target material in each operating platform, accurately identifying the optimization of the target material in each operating platform, realizing a targeted rendering process for the materials reused by multiple operating platforms, greatly improving the material rendering efficiency, and reducing the device performance overhead. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following will briefly introduce the drawings required for the description of the embodiments. Obviously, the following drawings are some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0018] Figure 1 It is a flowchart of a method for rendering a material effect provided by an embodiment of the present invention;
[0019] Figure 2 It is a schematic structural diagram of a device for rendering a material effect provided by an embodiment of the present invention;
[0020] Figure 3 For Figure 2 It is a schematic structural diagram of an electronic device corresponding to the device for rendering a material effect shown in the embodiment. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0021] To make the objectives, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. Apparently, the described embodiments are some, but not all, of the embodiments of the present invention. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.
[0022] The terms used in the embodiments of the present invention are only for the purpose of describing specific embodiments, and are not intended to limit the present invention. The singular forms "a", "said" and "the" used in the embodiments of the present invention and the appended claims are also intended to include the plural forms, unless the context clearly indicates otherwise. "Plural" generally includes at least two.
[0023] Depending on the context, the words "if" and "when" as used herein may be interpreted as "when" or "while" or "in response to determining" or "in response to detecting". Similarly, depending on the context, the phrase "if determined" or "if detected (stated condition or event)" may be interpreted as "when determined" or "in response to determining" or "when detecting (stated condition or event)" or "in response to detecting (stated condition or event)".
[0024] In addition, the step timings in the following method embodiments are only examples and not strictly limited.
[0025] The rendering solution for the material effect provided by the embodiments of the present invention can be executed by an electronic device, which can be a server. The server can be a physical server including an independent host, or can also be a virtual server hosted by a host cluster, or can also be a cloud server. The electronic device can also be a terminal device such as a PC, a laptop, a smartphone, a tablet computer, etc.
[0026] In practical applications, an application for editing the material effect is installed in the electronic device. The application can be connected to a client for editing a virtual scene, so as to edit and optimize the materials in the virtual scene managed by the client based on the shader code output by the application. In a possible embodiment, the client is, for example, a client of a virtual engine, a game editor, or a three-dimensional scene editor, and the application is, for example, a material editor mounted to the client.
[0027] In the real world, due to the nature of objects themselves and the influence of environmental factors, colors, textures, and glosses that match can be observed by the human eye. For example, glass is transparent, tree rings can be seen on the surface of wood, and metals have luster. In a virtual scene, the material effects on the material surface can be controlled by editing and adjusting the material of the object to obtain display characteristics that match the object. In practical applications, a material editor is usually used in a virtual engine to construct the materials of various objects in the virtual scene.
[0028] The rendering solution for material effects provided by the embodiments of the present invention is applicable to the application scenarios of material effects, such as the editing process of material effects, the optimization process of material effects, and the rendering process of material effects.
[0029] Currently, in a virtual engine that supports multiple operating platforms, the virtual engine supports cross-platform reuse of materials. During the cross-platform reuse process, corresponding shader codes need to be generated for each operating platform to implement the material rendering process in each operating platform. However, there are differences in device performance, operating conditions, etc. among each operating platform, resulting in difficulty in implementing certain material effects on some operating platforms, which affects the cross-platform reuse of materials.
[0030] Therefore, how to implement the rendering process of cross-platform reusable materials in each operating platform has become a technical problem to be solved urgently.
[0031] In response to the above-mentioned technical problem, the embodiments of the present invention provide a method and device for rendering material effects. Generally speaking, the solution idea of the rendering solution for material effects provided by the embodiments of the present invention is as follows:
[0032] For the case where multiple operating platforms share a target material, first, since the material property node is associated with the target material, therefore, in response to an operation on the material property node in the material editor, shader codes corresponding to each operating platform can be generated based on the material property node. Since the material property node is used to set the material effects presented by the shared target material in each operating platform respectively, therefore, by detecting the shader codes corresponding to each operating platform, the rendering settings corresponding to the target material in each operating platform can be obtained, and the different settings of the material shared by multiple operating platforms in each operating platform can be accurately identified. Finally, according to the rendering settings, the material effects corresponding to the target material are rendered in each operating platform, so that the targeted rendering settings are applied to the rendering process of the target material in the corresponding operating platform, and a more targeted rendering process is realized in each operating platform, greatly improving the material rendering efficiency and reducing the device performance overhead.
[0033] After introducing the basic idea of the rendering solution for material effects, the various non-limiting embodiments of the present invention will be specifically introduced below.
[0034] The execution process of the rendering method for the material effect will be described below in conjunction with the following embodiments.
[0035] Figure 1 The flowchart of a rendering method for a material effect provided by an embodiment of the present invention is as Figure 1 shown, and the method includes the following steps:
[0036] 101. In response to an operation on a material property node in a material editor, generate shader codes corresponding to each operating platform based on the material property node.
[0037] 102. Detect the shader codes corresponding to each operating platform to obtain the rendering settings of the target material on each operating platform.
[0038] 103. Render the material effect corresponding to the target material on each operating platform according to the rendering settings.
[0039] In the embodiment of the present invention, the material editor is mainly used to edit, adjust, and optimize the surface properties such as the color and texture of various objects in a virtual scene. In the material editor, various material nodes can be called through material balls to implement corresponding functions. The material property node is a type of material node, that is, the material node is a visual scripting node that converts a blueprint state machine into a material expression.
[0040] Taking the virtual scene in a game as an example, since a game often runs on multiple devices, therefore, the virtual scene in the game also needs to be adapted to the operating platforms of different devices, so that the materials of various objects in the virtual scene have the need for cross-platform reuse. For example, a game can run on devices such as mobile phones, PCs, game consoles, wearable devices, cloud servers, etc., or be run in cooperation with multiple devices, such as realized in cooperation with a mobile phone and a cloud server. Therefore, the materials of various NPCs, scene props, and scenery in the virtual scene of the game need to be cross-platform reused. Due to factors such as the display device type, hardware computing power, and running conditions of these devices, it is often difficult to render the same material effect. Therefore, in order to ensure the smoothness and visual effect of the game, it is necessary to perform targeted optimization on the reused materials according to the operating platform. For example, turn off the material effects that require high computing power support on some platforms and turn on such material effects on some platforms.
[0041] In the embodiments of the present invention, a material property node can be associated with the same set of materials (referred to as target materials in the embodiments of the present invention) that can be reused by multiple operating platforms. Therefore, in response to the above optimization requirements, targeted optimization can be performed on the same set of materials (referred to as target materials in the embodiments of the present invention) reused by multiple operating platforms in the material property node. Specifically, in a material editor, by adjusting the connection relationships of the material property nodes and setting parameters, the target materials reused by multiple operating platforms can be edited. For example, assuming that the target material is material a reused by the PC and mobile phone platforms, the material property parameters can be edited in the material property node connected to material a, so as to set the corresponding material properties for material a. The editing method of the material property parameters can be to enter the material property parameter values (such as entering constants) in the input interfaces (such as input fields, sliders, etc.) of the material property nodes, or to adjust the connection relationships between the material property nodes, or other methods, which are not limited in the present invention.
[0042] In the embodiments of the present invention, the material property node is used to set the material effects presented by the target material on each operating platform. Continuing with the above example, assume that the target material is material a reused by the PC and mobile phone platforms. Based on this, assume that to enhance the visual effect, a translucent refraction effect is enabled for material a on the PC, while to save computing power, the refraction effect needs to be disabled for material a on the mobile phone. In this case, targeted editing operations need to be performed on material a on the PC and mobile phone platforms to complete the optimization, that is, input valid data (such as 1) into the PC input terminal of the Feature Level Switch node connected to material a, connect the output terminal of the Feature Level Switch node to the Refraction property node. At the same time, input the default invalid data (such as 0) into the mobile phone input terminal of the Feature Level Switch node connected to material a. Or, by setting the connection relationships of the nodes, the enabling states of material a on different operating platforms can be controlled. For example, disconnect the connection of the mobile phone input terminal of the Feature Level Switch node connected to material a. Among them, the Refraction property is a kind of material property. The Feature Level Switch node is a function related to macro functions, mainly used to switch different material properties for the same type of materials used by different types of devices (such as devices using different operating platforms), so that the same type of materials can present different material effects on different types of devices, ensuring smooth switching of materials between devices with different computing rates.
[0043] Based on the above assumption, in response to the editing operation on material a in the above example, in 101, the corresponding shader codes for the PC and mobile phone platforms are generated based on the material property node.
[0044] Among them, the shader code mainly performs rendering operations on various objects in the virtual scene. The shader code can be executed by a processor (such as a CPU or GPU), so as to render the image effect corresponding to the shader code through the processor. Specifically, in the process of implementing the image effect rendering, usually the code supported by the shader (i.e., the shader code) is adopted, and the shader code needs to be written in a string, and these shader codes will be loaded into the processor for execution.
[0045] Specifically, in one implementation of 101, for the material property nodes associated with the target material, the material property parameters in the material property nodes configured for each operating platform are obtained. In addition, the connection relationships between the respective material property nodes can also be obtained, where the connection relationships between the respective material property nodes are used to indicate the material effects applied by the target material in multiple operating platforms. For example, assuming that the material property node is connected to the node of Attribute 1, then, according to the connection relationship between the material property node and the node of Attribute 1, it can be determined that Attribute 1 needs to be enabled during the rendering of the target material. It should be noted that in practical applications, the material property parameters and connection relationships of each material property node can be obtained synchronously or separately, and this embodiment does not limit it. Furthermore, shader codes corresponding to each operating platform are generated according to the connection relationships between the material property nodes and / or the material property parameters in the material property nodes.
[0046] Continuing with the above example, assume that the target material is Material a reused on the PC side and the mobile phone side. Assume that the semi-transparent refraction effect is enabled for Material a on the PC side, while the refraction effect needs to be disabled for Material a on the mobile phone side. Based on the above assumption, for the PC-side node associated with Material a, the refraction effect parameters in the refraction effect node configured for the PC side and the connection relationship of the refraction effect node are obtained. Furthermore, according to the refraction effect parameters in the refraction effect node and / or the connection relationship of the refraction effect node, a shader code for indicating the semi-transparent refraction effect for Material a to be enabled on the PC side is generated. For example, the refraction effect parameter can be the transparency required to be set when rendering this Material a on the PC side. Of course, in practical applications, the refraction effect node is connected to the PC-side node, which can also be considered to indicate that the semi-transparent refraction effect for Material a needs to be enabled on the PC side.
[0047] For the mobile - end node associated with Material A, obtain the refraction effect parameters and / or the connection relationship of the refraction effect node configured for the mobile end. Furthermore, based on the refraction effect parameters in the refraction effect node and the connection relationship of the refraction effect node, generate shader code for indicating the closing of the translucent refraction effect for Material A on the mobile end. Optionally, the refraction effect parameters in the refraction effect node configured for the mobile end can be set to a preset constant, such as 1, to indicate the closing of the translucent refraction effect. Of course, in practical applications, the disconnection of the refraction effect node from the mobile - end node can also be considered as indicating that the translucent refraction effect for Material A needs to be enabled on the PC side.
[0048] Furthermore, after generating the shader code corresponding to each operating platform, due to the differences in device conditions and operating situations of different operating platforms, it is necessary to introduce optimizations for each operating platform in the rendering process of the target material. For this requirement, it is necessary to accurately identify the optimizations of the target material in each operating platform, that is, the material effects that need to be launched for the target material in each operating platform.
[0049] In practical applications, in an alternative implementation, the connection relationship of the material property node can be used to determine whether to launch the corresponding material effect in the rendering process of the model, so as to identify the optimizations of the target material in each operating platform. However, the material property node is also connected to functions related to macros such as Feature Level Switch and Static Switch. In the process of generating shader code, no matter which operating platform is used, using the above - mentioned method will start the rendering process corresponding to the material property node due to the connection relationship between the material property node and the above - mentioned functions, greatly increasing the performance overhead of the device and affecting the smooth operation of the device. For example, on the PC side, the translucent refraction effect can be enabled to improve the visual effect, while on the mobile end, the refraction effect needs to be closed to save computing power. In this case, when parsing the connection status of the material property (such as the Refraction property), whether the default invalid data is input to the mobile - end input of the Feature Level Switch node or the connection with the mobile - end input of the Feature Level Switch node is disconnected, because the Refraction property is connected to the output of the Feature Level Switch node, the mobile end will misjudge that there is a node connection for the Refraction property, resulting in the mobile end still rendering the refraction effect even though the Feature Level Switch node has been optimized (i.e., the translucent refraction effect has been switched to the off state).
[0050] To avoid the misjudgment phenomenon in the above implementation method, in 102, the shader code corresponding to each operating platform can be detected to obtain the rendering settings corresponding to the target material on each operating platform, so as to more accurately identify the optimization of the target material on each operating platform. Specifically, it is detected whether the shader code corresponding to each operating platform contains a pre-set data type. Furthermore, if the shader code corresponding to the current operating platform contains a pre-set data type, the shader code is parsed to obtain the setting parameters and / or rendering process corresponding to the target material on the current operating platform. Optionally, if it is detected that the current shader code does not belong to the pre-set data type, a prompt of detection error is fed back to the corresponding operating platform.
[0051] It can be understood that assuming that the material effect of the target material on any operating platform is optimized by setting a constant return value, in this case, what the above steps actually need to identify is whether the return value of the shader code corresponding to the current operating platform is a constant; if the return value of the shader code is a constant, then the shader code must not include variables and operators, but only include numbers, floating-point numbers, non-operator symbols, and keywords related to rendering operations. Based on the above assumption, in this case, the pre-set data type is actually: the data type included in the constant return value.
[0052] Based on the above assumption, the shader code corresponding to the constant return value should at least meet the following three conditions:
[0053] First, the shader code corresponding to the constant return value does not contain numerical operations. The constant return value is usually pre-set for the rendering of specific material effects and is not the result of numerical calculations. Therefore, the shader code should not contain numerical operations. Specifically, the shader code corresponding to the constant return value should not contain functions and operation symbols related to numerical operations, such as addition, subtraction, multiplication, division, and other built-in functions of the shader code. Optionally, the shader code corresponding to the constant return value should not have function names and operation symbols such as "+", "-", "*", " / ", "?", ":", etc.
[0054] Second, all numerical values in the shader code corresponding to the constant return value are constants. There will be no parameters in the shader code corresponding to the constant return value, and all numerical values exist in the form of floating-point numbers.
[0055] Third, the type conversion in the shader code corresponding to the constant return value. For example, when a floating-point number is converted from the float1 type to the float3 type, the corresponding shader code can be in the form of float3(1, 1, 1), rather than (float3)1. For example, when a multi-channel vector is converted from the current number of channels to another multi-channel vector with a larger number of channels, zeros are filled. Exemplarily, when converting from float2(1, 0.2) to the float3 type, the converted data is float3(1, 0.2, 0). Conversely, when a multi-channel vector is converted from the current number of channels to another multi-channel vector with a smaller number of channels, channels are discarded. Exemplarily, when converting from float3(1, 2, 3) to the float2 type, the converted data is float2(1, 2).
[0056] Based on the above hypothetical analysis, in the case of optimizing the material effect by setting the constant return value, in the embodiments of the present invention, the pre-set data types include one or more of numbers, floating-point numbers, symbols, and keywords associated with rendering operations. In practical applications, the floating-point numbers to be detected include, but are not limited to, float, float2, float3, float4. The symbols to be detected include, but are not limited to, the dot (i.e., "."), comma, left parenthesis, right parenthesis, and space symbol. The keywords associated with rendering operations include, but are not limited to, keywords related to channel selection. For example, keywords for implementing channel selection and keywords for setting the number of channels.
[0057] Optionally, after parsing the shader code in 102, the start position of the parsing result of the shader code can also be increased to facilitate indicating the processing status of each character in the shader code and avoid performance consumption caused by repeated calculations. For example, set the start position of the currently parsed character to -1.
[0058] In practical applications, if the shader code corresponding to the constant return value contains type conversion and channel selection, then the shader code often contains a multi-layer nested structure. Exemplarily, for example, the shader code with a multi-layer nested structure is as follows:
[0059] EngineFloat3(EngineFloat4(1, rr, ngineFloat3(EngineFloat2(0.33.rrrr.rg),.6.rr.r).zy).
[0060] wx, 0.3)
[0061] In the above shader code, EngineFloat is a floating-point number macro, the VertexShader stage is a floating-point number, and the PixelShader stage is a half-precision floating-point number.
[0062] For the shader code with the above multi-layer nested structure, the steps of parsing the shader code in 102 can be implemented as follows: Parse the shader code in the way of function self-call to obtain the call result in the form of a multi-channel vector; Set the parsing result of the multi-layer nested structure according to the number of channels and data type in the call result. Optionally, the ExpressionState structure can be used to record various states of the parsing process. For example, the ComponentIndex parameter in the ExpressionState structure is related to the number of channels.
[0063] For example, for a given code segment in the shader code corresponding to the current operating platform, parse the given code segment in the way of function self-call to obtain the call result in the form of a four-channel vector, and the call result can be stored in a four-channel vector structure. Furthermore, set the ResultValue (i.e., the parsing result) of the multi-layer nested structure according to the number of channels and data type in the call result. ResultValue is, for example, a four-channel floating point number of the FLinearColor type.
[0064] Furthermore, after obtaining the rendering settings corresponding to each operating platform, in 103, render the material effect corresponding to the target material in each operating platform according to the rendering settings. Specifically, first, it is necessary to determine the rendering steps and / or setting parameters to be enabled in the rendering process of the target material in each operating platform based on the rendering settings. Then, add the rendering steps and / or setting parameters to the shader files corresponding to each operating platform, and transmit the corresponding shader files to each operating platform so that each operating platform executes the rendering process of the target material according to the corresponding shader file. Optionally, the rendering steps in the rendering process of each operating platform are preset. In this case, the states of each rendering step, that is, on or off, can be controlled based on the shader file.
[0065] Specifically, in the above steps, adding the rendering steps and / or setting parameters to the shader files corresponding to each operating platform can be implemented as follows: Generate the indication information corresponding to each operating platform based on the rendering steps and / or setting parameters matched in the rendering process of the target material in each operating platform; Add the indication information to the shader file of the corresponding operating platform.
[0066] Continuing with the above example, assume that the target material is material a that can be reused on both the PC side and the mobile side. Assume that in the mobile side, the refraction effect needs to be turned off for material a, while in the PC side, a translucent refraction effect is enabled for material a. Based on the above assumptions, in the shader file received on the mobile side, there is an indication message a1, and this indication message a1 is used to indicate turning off the refraction effect for material a on the mobile side. In this case, it means that in the rendering process on the mobile side, there is no need to trigger the step of generating the refraction map for material a, nor to set the refraction parameters for material a.
[0067] In the shader file received on the PC side, there is an indication message a2, and this indication message a2 is used to indicate turning on the refraction effect for material a on the PC side. In this case, it means that in the rendering process on the PC side, it is necessary to trigger the step of generating the refraction map for material a and set the refraction parameters for material a according to the refraction parameters in the shader file.
[0068] It should be noted that for the convenience of description, the specific execution process of the refraction effect is mainly introduced in the embodiments of the present invention. In practical applications, the technical solution provided by the present invention is not limited to the refraction effect, and can also be other effects implemented for factors such as the picture style, color, and ambient light. Details are not elaborated here.
[0069] Figure 1 In the shown rendering method of the material effect, the virtual engine supports reusing the target material and the material property nodes associated with the target material on multiple operating platforms. For the case of reusing the target material on multiple operating platforms, since the material property nodes can be used to set the material effects presented by the reused target material on each operating platform respectively, therefore, in response to the operation on the material property nodes in the material editor, the shader codes corresponding to each operating platform are generated based on the material property nodes, and the shader codes corresponding to each operating platform can be applied to the rendering process of the target material on each operating platform. However, the device conditions and running situations of different operating platforms are different, which will cause the rendering process of the target material to need to be optimized for each operating platform. For this reason, by detecting the shader codes corresponding to each operating platform, the rendering settings corresponding to the target material on each operating platform can be obtained, so as to clearly indicate the rendering process that needs to be started for the target material on each operating platform through this rendering setting, avoiding misjudgment of the startup state of the material effect. Finally, according to the rendering settings, the material effects corresponding to the target material are rendered on each operating platform, so that the targeted rendering settings can be applied to the rendering process of the target material on each operating platform, and the targeted optimization of the rendering process of the target material can be realized on each operating platform.
[0070] In this method, by detecting the shader code corresponding to each operating platform, the rendering settings of the target material corresponding to each operating platform can be obtained, and the targeted rendering settings are applied to the rendering process of the target material on each operating platform, accurately identifying the material effects that need to be activated for the target material on each operating platform, implementing a targeted rendering process for materials reused across multiple operating platforms, greatly improving the material rendering efficiency, and reducing the device performance overhead.
[0071] To facilitate an intuitive understanding of the execution process of the material effect rendering method in the embodiments of the present invention, the following embodiments are used to exemplarily illustrate how to obtain the rendering settings of the target material corresponding to the current operating platform for different pre-set data types.
[0072] In the first implementation manner, it is assumed that the pre-set data type is a numeric field or a keyword. Based on this, such a practical application scenario is assumed: detecting the numeric field or keyword in the shader code corresponding to the current operating platform.
[0073] In this scenario, in 102, traverse the shader code corresponding to the current operating platform to detect whether there is a numeric field or keyword in the shader code. Further, in 102, if the start position of the numeric field or keyword and the end position of the numeric field or keyword are detected in the shader code, it is determined that there is a numeric field or keyword in the shader code. Thus, based on the start position and the end position, the numeric field or keyword in the shader code is identified. For the numeric field identified in the shader code, based on the first matching relationship between the numeric field and the rendering step, obtain the setting parameters and / or the rendering steps to be enabled in the rendering process that match the identified numeric field. For the keyword identified in the shader code, according to the second matching relationship between the keyword and the rendering step, obtain the setting parameters and / or the rendering steps to be enabled in the rendering process that match the identified keyword.
[0074] In the second implementation manner, it is assumed that the pre-set data type is a symbol type. Optionally, the pre-set symbol types include a right parenthesis, a space, a dot symbol, and a comma. Based on this, such a practical application scenario is assumed: detecting the right parenthesis, dot symbol, space, and comma in the shader code corresponding to the current operating platform.
[0075] In this scenario, in 102, the shader code corresponding to the current operating platform is traversed to detect whether any one of the right parenthesis, space, dot, and comma (i.e., the pre-set symbol types) exists in the shader code. Further, in 102, if any one of the right parenthesis, space, dot, and comma is detected in the shader code, the channel recognition function is called based on the string before the detected symbol for channel recognition. Optionally, the ComputeMask function is called for channel recognition, which is mainly used to parse the channel selection code. Further, according to the channel recognition result output by the channel recognition function, the setting parameters associated with the channel selection and the data type after casting are obtained. For example, in the shader code 0.6.rr is equivalent to float2(0.6, 0.6), and through the parsing function, the result after casting can be obtained, that is, the 0.6float data type can be cast to the float2 type.
[0076] For example, if any one of the right parenthesis, space, and comma is detected in the shader code, since these three characters will terminate the parsing of strings and numbers, if there is a string before the detected character, an error return process is executed. If the character before the detected character is a number, the number is parsed, and the return result of the floating-point type is set according to the parsed number. If the current detected character is a comma, the starting position of the return result is offset according to the data type before the comma, that is, the ComponentIndex parameter in the ExpressionState structure is set. If the current detected character is a right parenthesis, the channel selection code is obtained through the parsing function, and the return result is set according to the obtained channel selection code.
[0077] For example, if a dot is detected in the shader code, the following processing flow is executed: First, determine the position of the dot in the shader code, and select the processing method according to the position of the dot. If the dot is in the middle of parsing a number (for example, the dot in 1.32), in this case, the dot does not need to be processed. If the character after the dot is a letter, determine whether the character before the dot is a number. If the character before the dot is a number, the channel recognition function is called to obtain the channel selection code, and the return result is set according to the obtained channel selection code.
[0078] In the third implementation manner, it is assumed that the pre-set data type is the symbol type. Optionally, the pre-set symbol type includes a comma. Based on this, a practical application scenario is assumed: detecting commas in the shader code corresponding to the current operating platform.
[0079] In this scenario, detecting whether the shader code corresponding to each operating platform in 102 contains a pre-set data type can be implemented as follows: traversing the shader code corresponding to the current operating platform to detect whether there is a pre-set symbol type in the shader code.
[0080] Furthermore, if the shader code corresponding to the current operating platform in 102 contains a pre-set data type, then parse the shader code to obtain the setting parameters and / or rendering process corresponding to the target material in the current operating platform, which can be implemented as follows: if a comma in the shader code is detected, then obtain the corresponding setting parameters according to the string before the comma. Specifically, if the string before the comma is a numeric field, then the setting parameter corresponds to the parsed data field; if the string before the comma is a MakeFloat type statement, then the setting parameter corresponds to a preset value. For example, if a comma in the shader code is detected and the Digit property in the ExpressionState structure is not -1, in this case, it can be determined that the string before the comma is a numeric field. For example, a MakeFloat type statement is a statement that appears during the construction of data such as float3(1, 2, 3), etc.
[0081] The fourth implementation manner, assuming that the pre-set data type is a symbol type. Optionally, the pre-set symbol type includes a left parenthesis. Based on this, an actual application scenario is assumed: detecting the left parenthesis in the shader code corresponding to the current operating platform.
[0082] Specifically, if the current character is a left parenthesis, then none of a number, a non-keyword letter, or a left parenthesis will appear before the current character. If the above situation occurs, it means that the parsing function has detected an error. At this time, an alarm needs to be given and the detection process of the current character needs to be exited, and the detection process of the next character needs to be entered. If a left parenthesis is detected and no detection error occurs, in this case, the position where the left parenthesis is located needs to be recorded as the start position of the shader code segment to be detected, and the matching right parenthesis needs to be found as the end position of the shader code segment to be detected. Furthermore, another parsing function is called to process (here it can be a self-call) the shader code segment between the above two parentheses. Specifically, if there is a dot symbol after the found right parenthesis, then the channel selection code is parsed through the called parsing function. If there is no dot symbol after the found right parenthesis, then it can be determined whether the data type corresponding to the shader code segment matches the keyword type outside the parentheses. If they match, a floating-point type return result is set; if they do not match, a prompt message indicating a detection error is returned.
[0083] For example, during the process of detecting the left parenthesis in the shader code corresponding to the current operating platform, if a left parenthesis is detected, then it can first be determined whether the left parenthesis (i.e., the current character) is a MakeFloat type statement that has been processed by the parsing function. If the left parenthesis is a MakeFloat type statement that has been processed by the parsing function, in this case, the left parenthesis is the parenthesis within the MakeFloat statement. According to the MakeFloat statement rules, find the start position and end position of the MakeFloat statement, and call the ParseExpression function to process the channel selection code at the end position of the MakeFloat statement, and based on the function return value, set the parsing result corresponding to the shader code segment corresponding to the left parenthesis. Such as channel selection parameters, the number of channels, etc. If the left parenthesis (i.e., the current character) is a data type that has not been processed by the parsing function, in this case, identify the data type with the MakeFloat statement as the starting data type code.
[0084] It should be noted that the detection processes for different data in the above scenarios can be executed synchronously or asynchronously. That is, the embodiments of the present invention do not limit the number of times of traversing the shader code. To improve the rendering efficiency, optionally, synchronously execute the above detection process of the shader code, so that the optimization of the target material in each operating platform can be accurately identified through one traversal process.
[0085] The rendering device for the material effect of one or more embodiments of the present invention will be described in detail below. Those skilled in the art can understand that these rendering devices for the material effect can all be configured by using commercially available hardware components through the steps taught by this solution.
[0086] Figure 2 It is a schematic structural diagram of a rendering device for the material effect provided by the embodiment of the present invention, as Figure 2 shown, the rendering device for the material effect includes: a communication module 11, a processing module 12, and a display module 13.
[0087] A generation module 11, configured to, in response to an operation on a material property node in a material editor, generate shader codes corresponding to each operating platform based on the material property node, where the material property node is associated with a target material reused by multiple operating platforms, and the material property node is used to set the material effects presented by the target material in each operating platform respectively;
[0088] A detection module 12, configured to detect the shader codes corresponding to each operating platform to obtain the rendering settings corresponding to the target material in each operating platform;
[0089] A rendering module 13, configured to render the material effect corresponding to the target material in each operating platform according to the rendering settings.
[0090] In an optional embodiment, the generating module 11 is specifically configured to:
[0091] For the material property nodes associated with the target material, obtain the material property parameters in the material property nodes configured for each operating platform; and / or
[0092] Obtain the connection relationships between the material property nodes, where the connection relationships are used to indicate the material effects applied by the target material in multiple operating platforms;
[0093] Generate shader codes corresponding to each operating platform according to the connection relationships and / or the material property parameters.
[0094] In an optional embodiment, the detecting module 12 is specifically configured to:
[0095] Detect whether the shader codes corresponding to each operating platform contain a preset data type, where the preset data type includes one or more of numbers, floating-point numbers, symbols, and keywords associated with rendering operations;
[0096] If the shader code corresponding to the current operating platform contains the preset data type, parse the shader code to obtain the setting parameters and / or rendering process corresponding to the target material in the current operating platform.
[0097] In an optional embodiment, the detecting module 12 detecting whether the shader codes corresponding to each operating platform contain a preset data type is specifically configured to:
[0098] Traverse the shader code corresponding to the current operating platform to detect whether there are digital fields or keywords in the shader code;
[0099] During the process that the detecting module 12 parses the shader code to obtain the setting parameters and / or rendering process corresponding to the target material in the current operating platform if the shader code corresponding to the current operating platform contains the preset data type, it is specifically configured to:
[0100] If the start position and the end position of a digital field or keyword are detected in the shader code, determine that there is a digital field or keyword in the shader code;
[0101] Identify the digital field or keyword in the shader code according to the start position and the end position;
[0102] Based on the first matching relationship between the digital field and the rendering step, obtain the set parameters matched by the identified digital field and / or the rendering steps to be enabled in the rendering process; or
[0103] According to the second matching relationship between the keyword and the rendering step, obtain the set parameters matched by the identified keyword and / or the rendering steps to be enabled in the rendering process.
[0104] In an alternative embodiment, during the process that the detection module 12 detects whether the shader code corresponding to each operating platform contains a preset data type, it is specifically configured as follows:
[0105] Traverse the shader code corresponding to the current operating platform to detect whether there is a preset symbol type in the shader code, and the preset symbol type includes a right parenthesis or a dot symbol;
[0106] During the process that the detection module 12 parses the shader code to obtain the set parameters corresponding to the target material in the current operating platform if the shader code corresponding to the current operating platform contains a preset data type, it is specifically configured as follows:
[0107] If a right parenthesis or a dot symbol in the shader code is detected, call a channel recognition function for channel recognition according to the string before the right parenthesis or the dot symbol;
[0108] According to the channel recognition result output by the channel recognition function, obtain the set parameters associated with the channel selection and the data type after forced conversion.
[0109] In an alternative embodiment, during the process that the detection module 12 detects whether the shader code corresponding to each operating platform contains a preset data type, it is specifically configured as follows:
[0110] Traverse the shader code corresponding to the current operating platform to detect whether there is a preset symbol type in the shader code, and the preset symbol type includes a comma;
[0111] During the process that the detection module 12 parses the shader code to obtain the set parameters corresponding to the target material in the current operating platform if the shader code corresponding to the current operating platform contains a preset data type, it is specifically configured as follows:
[0112] If a comma in the shader code is detected, obtain the corresponding set parameters according to the string before the comma;
[0113] Wherein, if the string before the comma is a numeric field, the set parameter corresponds to the parsed data field; if the string before the comma is a MakeFloat type statement, the set parameter corresponds to a preset value.
[0114] In an alternative embodiment, the detection module 12 is further configured to, after parsing the shader code, increase the start position of the parsing result of the shader code.
[0115] In an alternative embodiment, when the shader code corresponding to the current operating platform contains a multi-layer nested structure, the detection module 12 is specifically configured during the process of parsing the shader code as follows:
[0116] Parse the shader code in the way of function self - call to obtain a call result in the form of a multi - channel vector;
[0117] Set the parsing result of the multi - layer nested structure according to the number of channels and data type in the call result.
[0118] In an alternative embodiment, the rendering module 13 is specifically configured as follows:
[0119] Based on the rendering settings, determine the rendering steps and / or set parameters to be enabled in the rendering process of the target material on each operating platform;
[0120] Add the rendering steps and / or the set parameters to the shader files corresponding to each operating platform, and transmit the corresponding shader files to each operating platform, so that each operating platform executes the rendering process of the target material according to the corresponding shader file.
[0121] Figure 2 The rendering device for the material effect shown can execute the methods provided in the foregoing embodiments. For parts not described in detail in this embodiment, reference can be made to the relevant descriptions in the foregoing embodiments, which will not be elaborated here. In practical applications, Figure 2 The rendering device for the material effect shown can be implemented in the form of an application.
[0122] In a possible design, the above - mentioned Figure 2 structure of the rendering device for the material effect shown can be implemented as an electronic device. As Figure 3 shown, the electronic device may include: a processor 21 and a memory 22. Wherein, an executable code is stored on the memory 22, and when the executable code is executed by the processor 21, at least the processor 21 can implement the rendering method for the material effect provided in the foregoing embodiments. Among them, a communication interface 23 may also be included in the structure of the electronic device for communicating with other devices or communication networks.
[0123] In addition, an embodiment of the present invention provides a non-transitory machine-readable storage medium, on which executable code is stored. When the executable code is executed by a processor of a wireless router, the processor is caused to execute the rendering method of the material effect provided in each of the foregoing embodiments.
[0124] The device embodiments described above are merely illustrative. The various modules described as separate components may or may not be physically separated. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment. A person of ordinary skill in the art can understand and implement it without creative effort.
[0125] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of adding a necessary general hardware platform. Of course, it can also be implemented by a combination of hardware and software. Based on such an understanding, the essence of the above technical solution, or the part that makes a contribution, can be embodied in the form of a computer product. The present invention can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0126] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit them. Although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions described in the foregoing embodiments, or perform equivalent replacements on some of the technical features. These modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A rendering method for a material effect, characterized in that, Including: In response to an operation on a material property node in a material editor, generating shader codes corresponding to each operating platform based on the material property node, where the material property node is associated with a target material reused by multiple operating platforms, and the material property node is used to set the material effects presented by the target material in each operating platform respectively; Detecting the shader codes corresponding to each operating platform to obtain the rendering settings of the target material corresponding to each operating platform; Rendering the material effects corresponding to the target material in each operating platform according to the rendering settings; Among them, the generating shader codes corresponding to each operating platform based on the material property node includes: For the material property node associated with the target material, obtaining the material property parameters in the material property node configured for each operating platform, where different values of the material property parameters indicate enabling or disabling the material property corresponding to the material property node in the operating platform; and / or Obtaining the connection relationships between the material property nodes, where the connection relationships are used to indicate the material effects applied by the target material in multiple operating platforms; among them, if the connection relationship is that a material property node is connected to an operating platform, it means that the operating platform enables the material property corresponding to the material property node; If the connection relationship is that a material property node is disconnected from an operating platform, it means that the operating platform disables the material property corresponding to the material property node; Generating shader codes corresponding to each operating platform according to the connection relationships and / or the material property parameters.
2. The method according to claim 1, characterized in that The detecting the shader codes corresponding to each operating platform to obtain the rendering settings of the target material corresponding to each operating platform includes: Detecting whether the shader codes corresponding to each operating platform contain a pre-set data type, where the pre-set data type includes one or more of numbers, floating-point numbers, symbols, and keywords associated with rendering operations; If the shader code corresponding to the current operating platform contains a pre-set data type, parsing the shader code to obtain the setting parameters and / or rendering process corresponding to the target material in the current operating platform.
3. The method according to claim 2, wherein The detecting whether the shader codes corresponding to each operating platform contain a pre-set data type includes: Traversing the shader code corresponding to the current operating platform to detect whether there is a numeric field or keyword in the shader code; The if the shader code corresponding to the current operating platform contains a pre-set data type, parsing the shader code to obtain the setting parameters and / or rendering process corresponding to the target material in the current operating platform includes: If the start position and the end position of a numeric field or keyword are detected in the shader code, it is determined that there is a numeric field or keyword in the shader code; Identifying the numeric field or keyword in the shader code according to the start position and the end position; Based on the first matching relationship between the numeric field and the rendering step, obtaining the setting parameters and / or the rendering steps to be enabled in the rendering process matched by the identified numeric field; or Obtain the set parameters matched by the recognized keywords and / or the rendering steps to be enabled in the rendering process according to the second matching relationship between the keywords and the rendering steps.
4. The method according to claim 2, wherein The detection of whether the shader code corresponding to each operating platform contains a preset data type includes: Traverse the shader code corresponding to the current operating platform to detect whether there is a preset symbol type in the shader code, and the preset symbol type includes a right parenthesis or a dot symbol; If the shader code corresponding to the current operating platform contains a preset data type, then parse the shader code to obtain the set parameters corresponding to the target material in the current operating platform, including: If a right parenthesis or a dot symbol in the shader code is detected, call a channel recognition function to perform channel recognition according to the string before the right parenthesis or the dot symbol; Obtain the set parameters associated with channel selection and the data type after forced conversion according to the channel recognition result output by the channel recognition function.
5. The method according to claim 2, characterized in that, The detection of whether the shader code corresponding to each operating platform contains a preset data type includes: Traverse the shader code corresponding to the current operating platform to detect whether there is a preset symbol type in the shader code, and the preset symbol type includes a comma; If the shader code corresponding to the current operating platform contains a preset data type, then parse the shader code to obtain the set parameters corresponding to the target material in the current operating platform, including: If a comma in the shader code is detected, obtain the corresponding set parameter according to the string before the comma; Among them, if the string before the comma is a numeric field, the set parameter corresponds to the parsed data field; if the string before the comma is a MakeFloat type statement, the set parameter corresponds to a preset value.
6. The method according to claim 2, wherein After parsing the shader code, it further includes: Increase the start position of the parsing result of the shader code.
7. The method according to claim 2, characterized in that If the shader code corresponding to the current operating platform contains a multi-layer nested structure, then parsing the shader code includes: Parse the shader code in the way of function self-call to obtain the call result in the form of a multi-channel vector corresponding thereto; Set the parsing result of the multi-layer nested structure according to the number of channels and the data type in the call result.
8. The method according to claim 1, wherein Rendering the material effect corresponding to the target material in each operating platform according to the rendering settings includes: Determine the rendering steps and / or set parameters to be enabled in the rendering process of the target material in each operating platform based on the rendering settings; Add the rendering steps and / or the set parameters to the shader files corresponding to each operating platform, and transmit the corresponding shader files to each operating platform so that each operating platform executes the rendering process of the target material according to the corresponding shader file.
9. A rendering device for a material effect, characterized in that, Including: A generation module, configured to generate shader codes corresponding to each operating platform based on the material property node in response to an operation on the material property node in the material editor. The material property node is associated with a target material reused by multiple operating platforms, and the material property node is used to set the material effects presented by the target material in each operating platform respectively; A detection module, configured to detect the shader codes corresponding to each operating platform to obtain the rendering settings corresponding to the target material in each operating platform; A rendering module, configured to render the material effects corresponding to the target material in each operating platform according to the rendering settings; Wherein, generating the shader codes corresponding to each operating platform based on the material property node includes: For the material property node associated with the target material, obtaining the material property parameters in the material property node configured for each operating platform, where different values of the material property parameters indicate enabling or disabling the material property corresponding to the material property node in the operating platform; and / or Obtaining the connection relationships between the material property nodes, where the connection relationships are used to indicate the material effects applied by the target material in multiple operating platforms; wherein, if the connection relationship is that the material property node is connected to the operating platform, it means that the operating platform enables the material property corresponding to the material property node; If the connection relationship is that the material property node is disconnected from the operating platform, it means that the operating platform disables the material property corresponding to the material property node; Generating the shader codes corresponding to each operating platform according to the connection relationships and / or the material property parameters.