A coloring method and apparatus
By acquiring the configuration and resource information of the terminal device, determining the target shading mode and generating the target shading code, the problem of having to write separate codes for different shading pipelines is solved, and efficient shading mode switching and code reuse are achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-30
- Publication Date
- 2026-03-10
AI Technical Summary
Different coloring pipelines require separate code, which is inefficient.
By obtaining the configuration information and shading resource information of the terminal device, the target shading mode is determined, and the target shading code is generated based on the material template, lighting template and target shading path to achieve shading in different shading modes.
It improves code reusability and efficiency, enabling different shading modes to be implemented with a single set of shading resource information.
Smart Images

Figure CN114119845B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of computer technology, and more specifically, to a coloring method and apparatus. Background Technology
[0002] A shader is an editable program used to implement image rendering, replacing the fixed rendering pipeline. Shaders replace the traditional fixed rendering pipeline, enabling computations in 3D graphics. Due to their editability, they can achieve a wide variety of image effects without being limited by the graphics card's fixed rendering pipeline. Different shading strategies can be used for different architectures or performance levels of terminal devices; these shading strategies are often called shading pipelines. Each shading pipeline requires its own code, which is inefficient. Summary of the Invention
[0003] This disclosure provides at least one coloring method and apparatus.
[0004] In a first aspect, embodiments of this disclosure provide a coloring method, including:
[0005] Obtain the configuration information and shading resource information of the terminal device; the shading resource information includes the material template of the object to be shaded, the lighting template of the object to be shaded, and the shading paths of multiple shading modes;
[0006] Based on the configuration information, a target shading mode is determined from the plurality of shading modes;
[0007] Based on the material template, the lighting template, and the target shading path corresponding to the target shading mode, generate the target shading code corresponding to the target shading mode;
[0008] The object to be colored is colored based on the target coloring code.
[0009] In one optional implementation, determining the target shading mode from the plurality of shading modes based on the configuration information includes:
[0010] The target shading mode is determined based on at least one of the device model identifier, central processing unit information, graphics processing unit information, and preset shading mode in the configuration information.
[0011] In one optional implementation, generating the target shading code corresponding to the target shading mode based on the material template, the lighting template, and the target shading path corresponding to the target shading mode includes:
[0012] Traverse the target coloring path to determine multiple code reference nodes within the target coloring path;
[0013] For each code reference node, a target code segment matching the code reference node is determined from the material template and the lighting template;
[0014] The target code segment is added to the corresponding code reference node to obtain the colored code.
[0015] In one optional implementation, determining the target code segment matching the code reference node from the material template and the lighting template for each code reference node includes:
[0016] For each code reference node, a target code segment matching the code reference node is determined from the material template, the lighting template, and the preset scene effect template.
[0017] In one optional implementation, the target shading mode includes a deferred shading mode; when the target shading mode is a deferred shading mode, the step of shading the object to be shaded based on the target shading code includes:
[0018] Based on the vertex shading code in the target shading code, the vertex shading function in the material template is called to shade the vertices in the object to be shaded;
[0019] Based on the pixel coloring code in the target code, the pixel coloring function in the material template is called to color the pixels in the object to be colored;
[0020] Based on the deferred shading code in the target code, the material information in the material template is stored in the target geometry buffer;
[0021] After detecting a shading trigger event for the background lighting in the object to be shaded, the material information in the target geometry buffer is read, and the background lighting in the object to be shaded is shaded based on the lighting shading code in the target code and the read material information.
[0022] In an optional implementation, after calling the vertex shading function in the material template based on the vertex shading code in the target shading code to shade the vertices of the object to be shaded, the method further includes:
[0023] Based on the vertex lighting shading code in the target shading code, the vertex lighting shading function in the material template is called to shading the lighting of the vertices in the object to be shaded.
[0024] In one optional implementation, the target shading mode includes a standard shading mode; when the target shading mode is a standard shading mode, the step of shading the object to be shaded based on the target shading code includes:
[0025] Based on the vertex shading code in the target shading code, the vertex shading function in the material template is called to shade the vertices in the object to be shaded;
[0026] Based on the pixel coloring code in the target code, the pixel coloring function in the material template is called to color the pixels in the object to be colored;
[0027] Based on the lighting shading code in the target code and the material information read from the material template, the background lighting of the object to be shaded is colored.
[0028] Secondly, embodiments of this disclosure also provide a coloring apparatus, comprising:
[0029] The acquisition module is used to acquire the configuration information and shading resource information of the terminal device; the shading resource information includes the material template of the object to be shaded, the lighting template of the object to be shaded, and the shading paths of multiple shading modes;
[0030] The determining module is configured to determine a target shading mode from the plurality of shading modes based on the configuration information;
[0031] The generation module is used to generate target shading code corresponding to the target shading mode based on the material template, the lighting template, and the target shading path corresponding to the target shading mode;
[0032] The coloring module is used to color the object to be colored based on the target coloring code.
[0033] In one optional implementation, the determining module is specifically used for:
[0034] The target shading mode is determined based on at least one of the device model identifier, central processing unit information, graphics processing unit information, and preset shading mode in the configuration information.
[0035] In one optional implementation, the generation module is specifically used for:
[0036] Traverse the target coloring path to determine multiple code reference nodes within the target coloring path;
[0037] For each code reference node, a target code segment matching the code reference node is determined from the material template and the lighting template;
[0038] The target code segment is added to the corresponding code reference node to obtain the colored code.
[0039] In one optional implementation, when the generation module determines the target code segment matching the code reference node from the material template and the lighting template for each code reference node, it is used to:
[0040] For each code reference node, a target code segment matching the code reference node is determined from the material template, the lighting template, and the preset scene effect template.
[0041] In one optional implementation, the target shading mode includes a deferred shading mode; when the target shading mode is a deferred shading mode, the shading module is used to:
[0042] Based on the vertex shading code in the target shading code, the vertex shading function in the material template is called to shade the vertices in the object to be shaded;
[0043] Based on the pixel coloring code in the target code, the pixel coloring function in the material template is called to color the pixels in the object to be colored;
[0044] Based on the deferred shading code in the target code, the material information in the material template is stored in the target geometry buffer;
[0045] After detecting a shading trigger event for the background lighting in the object to be shaded, the material information in the target geometry buffer is read, and the background lighting in the object to be shaded is shaded based on the lighting shading code in the target code and the read material information.
[0046] In an optional implementation, after calling the vertex shading function in the material template based on the vertex shading code in the target shading code to shade the vertices of the object to be shaded, the shading module is further configured to:
[0047] Based on the vertex lighting shading code in the target shading code, the vertex lighting shading function in the material template is called to shading the lighting of the vertices in the object to be shaded.
[0048] In one optional implementation, the target shading mode includes a standard shading mode; when the target shading mode is a standard shading mode, the shading module is used to:
[0049] Based on the vertex shading code in the target shading code, the vertex shading function in the material template is called to shade the vertices in the object to be shaded;
[0050] Based on the pixel coloring code in the target code, the pixel coloring function in the material template is called to color the pixels in the object to be colored;
[0051] Based on the lighting shading code in the target code and the material information read from the material template, the background lighting of the object to be shaded is colored.
[0052] Thirdly, embodiments of this disclosure also provide an electronic device, including: a processor, a memory, and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor communicates with the memory via the bus, and when the machine-readable instructions are executed by the processor, the steps of the first aspect above, or any possible implementation of the first aspect, are performed.
[0053] Fourthly, embodiments of this disclosure also provide a computer-readable storage medium storing a computer program that, when executed by a processor, performs the steps of the first aspect or any possible implementation of the first aspect.
[0054] The coloring method and apparatus provided in this disclosure first acquire configuration information and coloring resource information of a terminal device. The coloring resource information includes a material template of the object to be colored, a lighting template of the object to be colored, and coloring paths for multiple coloring modes. Then, based on the configuration information, a target coloring mode is determined from the multiple coloring modes. Next, based on the material template, the lighting template, and the target coloring path corresponding to the target coloring mode, target coloring code corresponding to the target coloring mode is generated. Finally, the object to be colored is colored based on the target coloring code. This disclosure determines the target coloring mode using configuration information and coloring resource information, and then generates the target coloring code corresponding to the target coloring mode based on the target coloring mode and coloring resource information. Only one set of coloring resource information is needed to achieve coloring for different coloring modes, improving code reusability and efficiency.
[0055] To make the above-mentioned objects, features and advantages of this disclosure more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description
[0056] To more clearly illustrate the technical solutions of the embodiments of this disclosure, the accompanying drawings used in the embodiments will be briefly described below. These drawings are incorporated in and constitute a part of this specification. They illustrate embodiments conforming to this disclosure and, together with the specification, serve to explain the technical solutions of this disclosure. It should be understood that the following drawings only show some embodiments of this disclosure and should not be considered as limiting the scope. Those skilled in the art can obtain other related drawings based on these drawings without creative effort.
[0057] Figure 1 A flowchart of a coloring method provided by an embodiment of this disclosure is shown;
[0058] Figure 2 A flowchart of another coloring method provided by an embodiment of this disclosure is shown;
[0059] Figure 3 A flowchart of another coloring method provided by an embodiment of this disclosure is shown;
[0060] Figure 4 A schematic diagram of a coloring apparatus provided in an embodiment of this disclosure is shown;
[0061] Figure 5 A schematic diagram of an electronic device provided in an embodiment of this disclosure is shown. Detailed Implementation
[0062] To make the objectives, technical solutions, and advantages of the embodiments of this disclosure clearer, the technical solutions of the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this disclosure, and not all of them. The components of the embodiments of this disclosure described and shown in the accompanying drawings can generally be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of this disclosure provided in the accompanying drawings is not intended to limit the scope of the claimed disclosure, but merely represents selected embodiments of this disclosure. All other embodiments obtained by those skilled in the art based on the embodiments of this disclosure without inventive effort are within the scope of protection of this disclosure.
[0063] It should be noted that similar labels and letters in the following figures indicate similar items. Therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures.
[0064] In this document, the term "and / or" merely describes a relationship, indicating that three relationships can exist. For example, A and / or B can represent three cases: A alone, A and B simultaneously, and B alone. Furthermore, the term "at least one" in this document means any combination of at least two of any one or more elements. For example, including at least one of A, B, and C can mean including any one or more elements selected from the set consisting of A, B, and C.
[0065] To address the technical issue of requiring separate code for different coloring pipelines, this disclosure provides a coloring method. By determining the target coloring mode through configuration information and coloring resource information, and then generating the target coloring code corresponding to the target coloring mode based on the target coloring mode and coloring resource information, only one set of coloring resource information is needed to achieve coloring for different coloring modes, thereby improving code reusability and efficiency.
[0066] To facilitate understanding of this embodiment, a coloring method disclosed in this disclosure will first be described in detail. The executing entity of the coloring method provided in this disclosure is generally a computer device with certain computing capabilities, such as a terminal device, a server, or other processing device. In some possible implementations, the coloring method can be implemented by a processor calling computer-readable instructions stored in memory.
[0067] See Figure 1 The diagram shows a flowchart of a coloring method provided in an embodiment of this disclosure. The method includes steps S101 to S104, wherein:
[0068] S101. Obtain the configuration information and shading resource information of the terminal device; the shading resource information includes the material template of the object to be shading, the lighting template of the object to be shading, and the shading paths of multiple shading modes.
[0069] The terminal device can be a device that performs shading and rendering, and the configuration information of the interrupt device can include at least one of the following: the terminal device's device model identifier, central processing unit information, graphics processing unit information, preset shading mode, etc.
[0070] The aforementioned shading resource information can be pre-written modular shading code. The material template can include the material information, texture information, and shading functions of the object to be shaded. The lighting template can include various types and styles of lighting shading functions and parameters. The shading path can include the code framework of the shading pipeline, which specifies the execution order of the code of each module in the shading pipeline.
[0071] S102. Based on the configuration information, determine the target shading mode from the plurality of shading modes.
[0072] In this step, the target coloring mode that matches the configuration information can be queried based on the configuration information and the preset configuration-mode mapping table.
[0073] The target shading mode described above can be matched with the shading pipeline, and different shading pipelines can correspond to different shading codes.
[0074] S103. Based on the material template, the lighting template, and the target shading path corresponding to the target shading mode, generate the target shading code corresponding to the target shading mode.
[0075] In this step, target shading code corresponding to the target shading mode can be generated based on the material template, lighting template, and target shading path that match the target shading mode. For example, the target shading path can be traversed to determine multiple code reference nodes within it. Based on the information of each code reference node, a target code segment matching the reference node can be determined from the material template and lighting template for each reference node. Then, the target code segment is added to the corresponding code reference node to obtain the target shading code. Since the target shading path matches the target shading mode, the obtained target shading code also matches the target shading mode.
[0076] In this way, the target shading code corresponding to different pipelines can be obtained through different shading paths, material templates, and lighting templates.
[0077] Here, the code reference node can also reference preset scene effect templates. The scene effect templates include some common scene effect coloring code. By modularizing them into scene effect templates, the reusability of the code can be improved.
[0078] S104. Based on the target coloring code, color the object to be colored.
[0079] In this step, the target coloring code can be executed sequentially, and the object to be colored can be colored using the target coloring code.
[0080] See Figure 2As shown, another shading method provided in this embodiment of the present disclosure is used. In this shading method, the target shading mode is a deferred shading mode. First, the target shading code is executed. Based on the vertex shading code in the target shading code, the vertex shading function in the material template is called to shade the vertices in the object to be shaded, and vertex shading products are obtained. Then, based on the pixel shading code in the target code, the pixel shading function in the material template is called to shade the pixels in the object to be shaded. Finally, based on the deferred shading code in the target code, the material information in the material template is stored in the target geometry buffer, ending the first stage of shading. After detecting a shading trigger event for the background lighting in the object to be shaded, the second stage of shading can begin. The material information in the target geometry buffer is read, and the background lighting in the object to be shaded is shaded based on the lighting shading code in the target code and the read material information. Figure 2 In the target code, there can be one or more code reference nodes (i.e. slots) that reference scene effect templates. These nodes can call the code in the scene effect templates to add scene effects to the scene. Scene effect templates can include things like fog, weather, dissolution, etc.
[0081] In this way, by delaying the rendering of lighting shading, which has a smaller impact on the effect, the terminal device can prioritize rendering the colors of vertices and pixels, thereby improving the performance of shading.
[0082] The above shading trigger events can be set according to the delay duration or delay conditions. For example, the shading trigger event can be set to be set after all vertices and pixels have been shaded.
[0083] The above-mentioned shading method can also perform lighting shading on vertices. After the vertices are shading, the vertex lighting shading function in the material template can be called based on the vertex lighting shading code in the target shading code to shading the lighting of the vertices in the object to be shading.
[0084] See Figure 3As shown, this is another shading method provided in an embodiment of the present disclosure. In this shading method, the target shading mode is the standard shading mode. The method first calls the vertex shading function in the material template based on the vertex shading code in the target shading code to shade the vertices of the object to be shaded, obtaining vertex shading products. Then, based on the pixel shading code in the target code, it calls the pixel shading function in the material template to shade the pixels of the object to be shading. Finally, based directly on the lighting shading code in the target code and the material information read from the material template, it shades the background lighting of the object to be shading without delayed rendering. Similarly, this shading method can also call a scene effect template through a slot to add scene effects.
[0085] The shading method provided in this disclosure first obtains configuration information and shading resource information of the terminal device. The shading resource information includes a material template of the object to be shading, a lighting template of the object to be shading, and shading paths for multiple shading modes. Then, based on the configuration information, a target shading mode is determined from the multiple shading modes. Next, based on the material template, the lighting template, and the target shading path corresponding to the target shading mode, target shading code corresponding to the target shading mode is generated. Finally, the object to be shading is shading based on the target shading code. This disclosure determines the target shading mode through configuration information and shading resource information, and generates target shading code corresponding to the target shading mode based on the target shading mode and shading resource information. Only one set of shading resource information is needed to achieve shading for different shading modes, improving code reusability and efficiency.
[0086] Those skilled in the art will understand that, in the above-described method of the specific implementation, the order in which each step is written does not imply a strict execution order and does not constitute any limitation on the implementation process. The specific execution order of each step should be determined by its function and possible internal logic.
[0087] Based on the same inventive concept, this disclosure also provides a coloring apparatus corresponding to the coloring method. Since the principle of the apparatus in this disclosure for solving the problem is similar to the coloring method described above in this disclosure, the implementation of the apparatus can refer to the implementation of the method, and repeated details will not be repeated.
[0088] Reference Figure 4 The diagram shown is a schematic representation of a coloring apparatus provided in an embodiment of this disclosure. The apparatus includes:
[0089] The acquisition module 410 is used to acquire the configuration information and shading resource information of the terminal device; the shading resource information includes the material template of the object to be shaded, the lighting template of the object to be shaded, and the shading paths of multiple shading modes;
[0090] The determining module 420 is used to determine a target shading mode from the plurality of shading modes based on the configuration information;
[0091] The generation module 430 is used to generate target shading code corresponding to the target shading mode based on the material template, the lighting template and the target shading path corresponding to the target shading mode;
[0092] The coloring module 440 is used to color the object to be colored based on the target coloring code.
[0093] In one optional implementation, the determining module 420 is specifically used for:
[0094] The target shading mode is determined based on at least one of the device model identifier, central processing unit information, graphics processing unit information, and preset shading mode in the configuration information.
[0095] In one optional implementation, the generation module 430 is specifically used for:
[0096] Traverse the target coloring path to determine multiple code reference nodes within the target coloring path;
[0097] For each code reference node, a target code segment matching the code reference node is determined from the material template and the lighting template;
[0098] The target code segment is added to the corresponding code reference node to obtain the colored code.
[0099] In an optional implementation, when the generation module 430 determines the target code segment matching the code reference node from the material template and the lighting template for each code reference node, it is used to:
[0100] For each code reference node, a target code segment matching the code reference node is determined from the material template, the lighting template, and the preset scene effect template.
[0101] In one optional implementation, the target shading mode includes a deferred shading mode; when the target shading mode is a deferred shading mode, the shading module 440 is configured to:
[0102] Based on the vertex shading code in the target shading code, the vertex shading function in the material template is called to shade the vertices in the object to be shaded;
[0103] Based on the pixel coloring code in the target code, the pixel coloring function in the material template is called to color the pixels in the object to be colored;
[0104] Based on the deferred shading code in the target code, the material information in the material template is stored in the target geometry buffer;
[0105] After detecting a shading trigger event for the background lighting in the object to be shaded, the material information in the target geometry buffer is read, and the background lighting in the object to be shaded is shaded based on the lighting shading code in the target code and the read material information.
[0106] In an optional implementation, after the vertex shading function in the material template is called based on the vertex shading code in the target shading code to shade the vertices in the object to be shaded, the shading module 440 is further configured to:
[0107] Based on the vertex lighting shading code in the target shading code, the vertex lighting shading function in the material template is called to shading the lighting of the vertices in the object to be shaded.
[0108] In one optional implementation, the target shading mode includes a standard shading mode; when the target shading mode is a standard shading mode, the shading module is used to:
[0109] Based on the vertex shading code in the target shading code, the vertex shading function in the material template is called to shade the vertices in the object to be shaded;
[0110] Based on the pixel coloring code in the target code, the pixel coloring function in the material template is called to color the pixels in the object to be colored;
[0111] Based on the lighting shading code in the target code and the material information read from the material template, the background lighting of the object to be shaded is colored.
[0112] The processing flow of each module in the device and the interaction flow between each module can be referred to the relevant descriptions in the above method embodiments, and will not be detailed here.
[0113] Corresponding to Figure 1 In addition to the coloring method described in the present disclosure, this embodiment also provides an electronic device 500, such as... Figure 5 The diagram shown is a structural schematic of an electronic device 500 provided in an embodiment of this disclosure, including:
[0114] The system includes a processor 51, a memory 52, and a bus 53. The memory 52 stores execution instructions and includes main memory 521 and external memory 522. The main memory 521, also called internal memory, temporarily stores the computational data in the processor 51, as well as data exchanged with external memory such as a hard disk. The processor 51 exchanges data with the external memory 522 through the main memory 521. When the electronic device 500 is running, the processor 51 communicates with the memory 52 through the bus 53, causing the processor 51 to execute the following instructions:
[0115] Obtain the configuration information and shading resource information of the terminal device; the shading resource information includes the material template of the object to be shaded, the lighting template of the object to be shaded, and the shading paths of multiple shading modes;
[0116] Based on the configuration information, a target shading mode is determined from the plurality of shading modes;
[0117] Based on the material template, the lighting template, and the target shading path corresponding to the target shading mode, generate the target shading code corresponding to the target shading mode;
[0118] The object to be colored is colored based on the target coloring code.
[0119] In one optional implementation, the instructions executed by the processor 51, wherein determining the target shading mode from the plurality of shading modes based on the configuration information, includes:
[0120] The target shading mode is determined based on at least one of the device model identifier, central processing unit information, graphics processing unit information, and preset shading mode in the configuration information.
[0121] In one optional implementation, the instructions executed by the processor 51, including the step of generating target shading code corresponding to the target shading mode based on the material template, the lighting template, and the target shading path corresponding to the target shading mode, include:
[0122] Traverse the target coloring path to determine multiple code reference nodes within the target coloring path;
[0123] For each code reference node, a target code segment matching the code reference node is determined from the material template and the lighting template;
[0124] The target code segment is added to the corresponding code reference node to obtain the colored code.
[0125] In one optional implementation, the instructions executed by the processor 51, wherein determining the target code segment matching the code reference node from the material template and the lighting template for each code reference node, includes:
[0126] For each code reference node, a target code segment matching the code reference node is determined from the material template, the lighting template, and the preset scene effect template.
[0127] In one optional implementation, the target shading mode in the instructions executed by the processor 51 includes a deferred shading mode; when the target shading mode is a deferred shading mode, the step of shading the object to be shaded based on the target shading code includes:
[0128] Based on the vertex shading code in the target shading code, the vertex shading function in the material template is called to shade the vertices in the object to be shaded;
[0129] Based on the pixel coloring code in the target code, the pixel coloring function in the material template is called to color the pixels in the object to be colored;
[0130] Based on the deferred shading code in the target code, the material information in the material template is stored in the target geometry buffer;
[0131] After detecting a shading trigger event for the background lighting in the object to be shaded, the material information in the target geometry buffer is read, and the background lighting in the object to be shaded is shaded based on the lighting shading code in the target code and the read material information.
[0132] In an optional implementation, after executing the vertex shading code based on the target shading code and calling the vertex shading function in the material template to shade the vertices of the object to be shaded, the processor 51 is further configured to execute:
[0133] Based on the vertex lighting shading code in the target shading code, the vertex lighting shading function in the material template is called to shading the lighting of the vertices in the object to be shaded.
[0134] In one optional implementation, the target shading mode includes a standard shading mode; in the instructions executed by the processor 51, when the target shading mode is a standard shading mode, the step of shading the object to be shaded based on the target shading code includes:
[0135] Based on the vertex shading code in the target shading code, the vertex shading function in the material template is called to shade the vertices in the object to be shaded;
[0136] Based on the pixel coloring code in the target code, the pixel coloring function in the material template is called to color the pixels in the object to be colored;
[0137] Based on the lighting shading code in the target code and the material information read from the material template, the background lighting of the object to be shaded is colored.
[0138] This disclosure also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, performs the steps of the coloring method described in the above method embodiments. The storage medium may be a volatile or non-volatile computer-readable storage medium.
[0139] This disclosure also provides a computer program product carrying program code. The program code includes instructions that can be used to execute the steps of the coloring method described in the above method embodiments. For details, please refer to the above method embodiments, which will not be repeated here.
[0140] The aforementioned computer program product can be implemented through hardware, software, or a combination thereof. In one optional embodiment, the computer program product is specifically embodied in a computer storage medium; in another optional embodiment, the computer program product is specifically embodied in a software product, such as a software development kit (SDK), etc.
[0141] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems and devices described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here. In the several embodiments provided in this disclosure, it should be understood that the disclosed systems, devices, and methods can be implemented in other ways. The device embodiments described above are merely illustrative. For example, the division of units is only a logical functional division; in actual implementation, there may be other division methods. Furthermore, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Another point is that the displayed or discussed mutual coupling or direct coupling or communication connection may be through some communication interfaces; the indirect coupling or communication connection of devices or units may be electrical, mechanical, or other forms.
[0142] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0143] In addition, the functional units in the various embodiments of this disclosure can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0144] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a processor-executable, non-volatile, computer-readable storage medium. Based on this understanding, the technical solution of this disclosure, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this disclosure. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0145] Finally, it should be noted that the above-described embodiments are merely specific implementations of this disclosure, used to illustrate the technical solutions of this disclosure, and not to limit it. The protection scope of this disclosure is not limited thereto. Although this disclosure has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art can still modify or easily conceive of changes to the technical solutions described in the foregoing embodiments, or make equivalent substitutions for some of the technical features, within the scope of the technology disclosed in this disclosure. Such modifications, changes, or substitutions 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 this disclosure, and should all be covered within the protection scope of this disclosure. Therefore, the protection scope of this disclosure should be determined by the protection scope of the claims.
Claims
1. A coloring method characterized by, The method comprises the following steps: obtaining configuration information of a terminal device and shading resource information; the shading resource information is pre-written modular shading code, and the shading resource information comprises a material template of an object to be shaded, an illumination template of the object to be shaded, and a shading path of a plurality of shading modes; the shading path comprises a code framework of a shading pipeline to specify an execution order of each module code in the shading pipeline; determining a target shading mode from the plurality of shading modes based on the configuration information; generating target shading code corresponding to the target shading mode based on the material template, the illumination template, and a target shading path corresponding to the target shading mode; the target shading code comprises at least one slot referencing a scene effect template, and the slot is used to call code in the scene effect template to add a scene special effect to a scene; shading the object to be shaded based on the target shading code.
2. The method of claim 1, wherein, The method further comprises the following steps: determining the target shading mode based on at least one of a device model identifier, central processing unit information, graphics processing unit information, and a preset shading mode in the configuration information.
3. The method of claim 1, wherein, The method further comprises the following steps: traversing the target shading path to determine a plurality of code reference nodes in the target shading path; for each code reference node, determining a target code segment matching the code reference node from the material template and the illumination template; adding the target code segment to the corresponding code reference node to obtain the shading code.
4. The method of claim 3, wherein, The method further comprises the following steps: for each code reference node, determining a target code segment matching the code reference node from the material template, the illumination template, and a preset scene effect template.
5. The method of claim 1, wherein, The target shading mode comprises a deferred shading mode; in the case where the target shading mode is the deferred shading mode, the shading of the object to be shaded based on the target shading code comprises the following steps: calling a vertex shading function in the material template based on vertex shading code in the target shading code to shade a vertex in the object to be shaded; calling a pixel shading function in the material template based on pixel shading code in the target code to shade a pixel in the object to be shaded; storing material information in the material template to a target geometry buffer based on deferred shading code in the target code; after detecting a shading trigger event for background illumination in the object to be shaded, reading the material information in the target geometry buffer, and shading the background illumination in the object to be shaded based on illumination shading code in the target code and the read material information.
6. The method of claim 5, wherein, After the vertex in the to-be-shaded object is shaded based on the vertex shading code in the target shading code and the vertex shading function in the material template is called, the method further comprises: After the vertex in the to-be-shaded object is shaded based on the vertex shading code in the target shading code and the vertex shading function in the material template is called, the method further comprises:
7. The method of claim 1, wherein, The target shading mode comprises a standard shading mode; in the case that the target shading mode is the standard shading mode, the shading of the to-be-shaded object based on the target shading code comprises: shading the vertex in the to-be-shaded object based on the vertex shading code in the target shading code and calling the vertex shading function in the material template; shading the pixel in the to-be-shaded object based on the pixel shading code in the target code and calling the pixel shading function in the material template; shading the background light in the to-be-shaded object based on the light shading code in the target code and the information of the material read from the material template.
8. A coloring device characterized by comprising: Comprise: an acquisition module, configured to acquire configuration information of a terminal device and shading resource information; wherein the shading resource information is pre-written modular shading code, and the shading resource information comprises a material template of a to-be-shaded object, a light template of the to-be-shaded object, and shading paths of a plurality of shading modes, wherein the shading path comprises a code framework of a shading pipeline to specify an execution order of each module code in the shading pipeline; a determination module, configured to determine a target shading mode from the plurality of shading modes based on the configuration information; a generation module, configured to generate target shading code corresponding to the target shading mode based on the material template, the light template, and a target shading path corresponding to the target shading mode, wherein the target shading code comprises at least one slot referencing a scene effect template, and the slot is used to call a code in the scene effect template to add a scene special effect to a scene; a shading module, configured to shade the to-be-shaded object based on the target shading code.
9. An electronic device, comprising: Comprise: a processor, a memory and a bus, the memory stores machine readable instructions executable by the processor, when the electronic device is running, the processor and the memory communicate through the bus, the machine readable instructions are executed by the processor to execute the steps of the shading method in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, The computer readable storage medium stores a computer program, and the computer program is executed by the processor to execute the steps of the shading method in any one of claims 1 to 7.
Citation Information
Patent Citations
Shader simplifying method, shader simplifying device and graphic rendering method based on code motion
CN104537706A