A multi-platform shader usage method and related device
By converting the initial shader into shader files corresponding to multiple platforms and generating configuration files, the complex problem of cross-platform shader conversion is solved, and efficient cross-platform rendering and simplified configuration process is achieved.
Patent Information
- Application Number
- CN202111627013.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-28
- Publication Date
- 2025-04-15
- Estimated Expiration
- 2041-12-28
AI Technical Summary
Existing cross-platform shader conversion is more complex, resulting in inefficient writing and debugging shader files on different platforms and poor reading.
Provide a multi-platform shader usage method. By obtaining the initial shader, converting it into shader files corresponding to multiple platforms, and generating configuration files, retrieving the target attribute value according to the rendering instructions, parameter configuration of the target shader, and finally achieving cross-platform rendering.
It realizes the use of cross-platform shaders on different platforms, improves writing and debugging efficiency, simplifies the configuration process, and enhances the readability of shader files.
Smart Images

Figure CN114356289B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image processing, and in particular to a multi-platform based shader use method and related equipment. Background Art
[0002] There are more and more renderers on the market, and renderers produced by different manufacturers have different advantages. Therefore, cross-platform rendering has become the choice of more and more companies. In the process of cross-platform rendering, writing shaders is the most important part. If there is a lack of a cross-platform shader conversion program, it is necessary to manually write shader files for multiple platforms, such as common shaders GLSL, ESSL, HLSL, etc., which is very inefficient. Moreover, due to the large number of parameters used in the rendering process, errors often occur during the self-compilation process, and the backend needs to be constantly compiled and debugged. In addition, after writing the shader file on platform A and exporting it to other platforms, the readability of the shader file is poor. Summary of the invention
[0003] The technical problem to be solved by the present invention is that the existing cross-platform shader conversion is relatively complicated. In view of the shortcomings of the existing technology, a multi-platform shader use method and related equipment are provided.
[0004] In order to solve the above technical problems, the technical solution adopted by the present invention is as follows:
[0005] A method for using a shader based on multiple platforms, the method comprising:
[0006] Get the initial shader to be processed;
[0007] According to a preset conversion format, converting the initial shader into a plurality of shader files corresponding to the shader format;
[0008] Generate a configuration file corresponding to the initial shader according to the first attribute value of the shader file and the second attribute value of the initial shader;
[0009] When a rendering instruction is detected, the configuration file is retrieved according to a shader format in the rendering instruction to obtain a target attribute value corresponding to the rendering format;
[0010] According to the second attribute value, parameter configuration is performed on a target shader corresponding to the rendering instruction to obtain a rendering shader;
[0011] Based on the rendering shader, a rendering file corresponding to the rendering instruction is rendered.
[0012] The multi-platform based shader use method, wherein the obtaining of the initial shader to be processed comprises:
[0013] Get the shader name and shader address to be processed;
[0014] The initial shader is obtained based on the shader name and the shader address.
[0015] The multi-platform based shader usage method, wherein the step of retrieving the configuration file according to the shader format in the rendering instruction to obtain the target attribute value corresponding to the rendering format comprises:
[0016] According to the shader format in the rendering instruction, a configuration file is retrieved, and a first attribute value corresponding to the shader format is used as a candidate attribute value;
[0017] A target attribute value among the candidate attribute values is determined according to the rendering type in the rendering instruction.
[0018] The multi-platform based shader use method, wherein the step of converting the initial shader into a plurality of shader files corresponding to the shader format according to a preset conversion format comprises:
[0019] Convert the initial shader into spv metadata, and input the spv metadata into a preset SPIRV-CROSS;
[0020] According to a preset conversion format, the SPIRV-CROSS is controlled to convert the spv metadata into a shader file corresponding to the shader format.
[0021] The multi-platform based shader usage method, wherein the format of the configuration file is json format.
[0022] The multi-platform based shader usage method, wherein the first attribute value includes the file name, function name, whether it is a built-in shader and the shader stage.
[0023] The multi-platform based shader using method, wherein the second attribute value includes a layout list, a texture array, and uniform block information.
[0024] A shader using device based on multiple platforms, comprising:
[0025] An acquisition module is used to obtain the initial shader to be processed;
[0026] A conversion module, used for converting the initial shader into a plurality of shader files corresponding to the shader format according to a preset conversion format;
[0027] A generating module, configured to generate a configuration file corresponding to the initial shader according to the first attribute value of the shader file and the second attribute value of the initial shader;
[0028] A retrieval module, configured to retrieve the configuration file according to a shader format in the rendering instruction when a rendering instruction is detected, and obtain a target attribute value corresponding to the rendering format;
[0029] A configuration module, configured to perform parameter configuration on a target shader corresponding to the rendering instruction according to the second attribute value to obtain a rendering shader;
[0030] A rendering module is used to render a rendering file corresponding to the rendering instruction based on the rendering shader.
[0031] The multi-platform based shader using device, wherein the acquisition module is specifically used for:
[0032] Get the shader name and shader address to be processed;
[0033] The initial shader is obtained based on the shader name and the shader address.
[0034] The multi-platform based shader using device, wherein the retrieval module is specifically used for:
[0035] According to the shader format in the rendering instruction, a configuration file is retrieved, and a first attribute value corresponding to the shader format is used as a candidate attribute value;
[0036] A target attribute value among the candidate attribute values is determined according to the rendering type in the rendering instruction.
[0037] The multi-platform based shader using device, wherein the conversion module is used for:
[0038] Convert the initial shader into spv metadata, and input the spv metadata into a preset SPIRV-CROSS;
[0039] According to a preset conversion format, the SPIRV-CROSS is controlled to convert the spv metadata into a shader file corresponding to the shader format.
[0040] The multi-platform based shader using device, wherein the format of the configuration file is json format.
[0041] The multi-platform based shader using device, wherein the first attribute value includes a file name, a function name, whether it is a built-in shader, and a shader stage.
[0042] The multi-platform based shader using device, wherein the second attribute value includes a layout list, a texture array, and uniform block information.
[0043] A computer-readable storage medium stores one or more programs, wherein the one or more programs can be executed by one or more processors to implement the steps in any of the above-mentioned multi-platform based shader use methods.
[0044] A terminal device comprises: a processor, a memory and a communication bus; the memory stores a computer-readable program executable by the processor;
[0045] The communication bus realizes the connection and communication between the processor and the memory;
[0046] When the processor executes the computer-readable program, the steps in any of the above-mentioned multi-platform based shader use methods are implemented.
[0047] Beneficial effects: This solution provides a multi-platform shader usage method, which first obtains the initial shader to be processed, and then converts the initial shader into several shader files in different shader formats. Then, the file name and other information of the shader file are used as the first attribute value, and the specific parameters of the initial shader used for rendering are used as the second attribute value to generate a configuration file containing these two attribute values. When rendering is required, the rendering instruction contains what shader is needed for rendering, that is, the shader format is specified. Therefore, according to the shader format, by searching in the configuration file, the shader file that can be used and the specific parameters used for rendering can be obtained, and the two are used as target attribute values to perform rendering operations on the rendering file that needs to be rendered. Therefore, on different platforms, based on this configuration file, the calling of different types of shader files and the configuration of specific rendering parameters can be realized, thereby realizing the use of cross-platform shaders. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] Figure 1 The present invention provides a flowchart of a method for using a shader based on multiple platforms.
[0049] Figure 2 A schematic diagram of an input initial shader and an output shader file of a multi-platform based shader using method provided by the present invention.
[0050] Figure 3 A schematic diagram of generating shader files and configuration files for the multi-platform shader usage method provided by the present invention.
[0051] Figure 4A schematic diagram of file information of a configuration file of a multi-platform shader usage method provided by the present invention.
[0052] Figure 5 The present invention provides a first schematic diagram of a first attribute value in a configuration file of a multi-platform shader usage method provided by the present invention.
[0053] Figure 6 This is a second schematic diagram of the first attribute value in the configuration file of the multi-platform shader usage method provided by the present invention.
[0054] Figure 7 A schematic diagram of a layout list in a configuration file of a multi-platform shader usage method provided by the present invention.
[0055] Figure 8 A schematic diagram of a texture array in a configuration file of a multi-platform shader usage method provided by the present invention.
[0056] Fig. 9 A schematic diagram of Uniform block information in a multi-platform shader usage method provided by the present invention.
[0057] Fig.10 A schematic structural diagram of a multi-platform shader using device provided by the present invention.
[0058] Fig.11 This is a structural principle diagram of the terminal device provided by the present invention. DETAILED DESCRIPTION
[0059] The present invention provides a method for using a shader based on multiple platforms. In order to make the purpose, technical solution and effect of the present invention clearer and more specific, the present invention is further described in detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.
[0060] It will be understood by those skilled in the art that, unless expressly stated, the singular forms "one", "said", and "the" used herein may also include plural forms. It should be further understood that the term "comprising" used in the specification of the present invention refers to the presence of the features, integers, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or groups thereof. It should be understood that when we refer to an element as being "connected" or "coupled" to another element, it may be directly connected or coupled to the other element, or there may be intermediate elements. In addition, the "connection" or "coupling" used herein may include wireless connection or wireless coupling. The term "and / or" used herein includes all or any unit and all combinations of one or more associated listed items.
[0061] It will be understood by those skilled in the art that, unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as generally understood by those skilled in the art in the art to which the present invention belongs. It should also be understood that terms such as those defined in general dictionaries should be understood to have meanings consistent with the meanings in the context of the prior art, and will not be interpreted with idealized or overly formal meanings unless specifically defined as herein.
[0062] like Figure 1 As shown, this implementation provides a method for using a shader based on multiple platforms. For the convenience of description, a common server is used as the execution subject for description. The server here can be replaced by a device with data processing function such as a tablet or a computer. The method for using a shader based on multiple platforms includes the following steps:
[0063] S10. Obtain an initial shader to be processed.
[0064] Specifically, the initial shader is a shader that can be used on a certain platform, and the format of the initial shader can be any common shader, for example, a shader in the GLSL format written in the OpenGL shader language.
[0065] Build the shader conversion project in advance through cmake. The main function of the shader conversion program can accept multiple input parameters. These input parameters mainly include external customization to specify the input file path, output file path, input file name and output file name. The following is an example of input and output parameters:
[0066] inVertPath: Input vertex shader file resource path;
[0067] inFragPath: Input fragment shader file resource path;
[0068] outVertName: output vertex shader file name;
[0069] outFragName: output fragment shader file name;
[0070] outJsonName: output shader configuration file name;
[0071] outPathName: Output path of shader resources and configuration files.
[0072] like Figure 2As shown, the input file path and the input file name are obtained, and the shader conversion project can obtain the initial shader. Therefore, the name and address of the shader to be processed are first obtained, and then the initial shader is obtained based on the shader name and the shader address.
[0073] S20. According to a preset conversion format, convert the initial shader into a plurality of shader files corresponding to the shader format.
[0074] Specifically, a shader format to be converted from the initial shader is preset as a conversion format, and this shader format is a shader different from the initial shader platform, for example, the conversion format used is Metal, ESSL, HLSL, SPIRV.
[0075] After obtaining the initial shader (the shader in the GLSL format) to be converted, it needs to be converted. There are many ways to convert a shader in one format into a shader in another format, and any shader conversion method can be used in this solution.
[0076] In order to facilitate the conversion to obtain the shader file, a shader conversion method is provided in this embodiment. In this embodiment, the open source libraries glslang and SPIRV_Cross provided by the Khronos Group are introduced. After obtaining the initial shader, the initial shader is converted into spv metadata through the glslang library and written into the corresponding .spv file. The spv metadata is then input into the SPIRV-Cross converter. The SPIRV-Cross converter can convert files in the SPIR-V format into files in other formats. Therefore, the spv metadata can be converted into a shader file corresponding to the conversion format. Figure 3 As shown, the language type of the input initial shader is GLSL. After SPIRV-Cross conversion, the output language types include Metal, ELSL and HLSL, and the file formats of the shader files are metal, glsl and hlsl respectively.
[0077] S30. Generate a configuration file corresponding to the initial shader according to the first attribute value of the shader file and the second attribute value of the initial shader.
[0078] Specifically, after obtaining the converted shader file, the shader name, function name, shader stage and other contents can be obtained. For example, the format of the shader file is HLSL, its file name is "vertex_1_tex_map.vert.hlsl", the calling function name is main function, and its shader stage is vertex (vert) stage. Among them, the shader stage also includes frag (fragment), geom (geometry), tesc (subdivision control), tese (subdivision calculation), comp (calculation) and other stages. The file name determines the name of the shader used when rendering is required, the function name determines which function is used to input the content to be rendered during rendering, and the shader stage is used to define the main purpose of this shader. This information can determine how to select and call the shader file for rendering during subsequent rendering. Therefore, the information that can determine the use of the shader file is used as the first attribute value of the shader file.
[0079] The initial shader has certain processing logic and processing parameters when rendering. After the shader conversion, these processing logic and processing parameters may not be retained. Therefore, in order to ensure that the converted shader file can be processed according to the processing logic and parameters of the initial shader, the processing logic and processing parameters are used as the second attribute value. The second attribute value may include layout list (layoutlist), texture array (textures), uniform block (UniformBlock).
[0080] The second attribute value can be extracted when the initial shader is obtained, and the first attribute value can be generated when different shader files are generated. After obtaining the first attribute value and the second attribute value, they are written into a preset empty file according to certain writing rules to obtain a configuration file.
[0081] It is worth noting that an empty file does not refer to a file without content but a file that has a file description but has not yet written the first attribute value and the second attribute value. Figure 4 As shown, before the first attribute value and the second attribute value written in the empty file, there is a part of the file description. The shader conversion project adopted in this embodiment is C++ language, so the example of the configuration file is shown in C++ language. Since the configuration file is too long, it is divided into several sections for description.
[0082] The first part of the configuration file (the first to fourth lines) is the file description, followed by the first attribute values of the GLSL, GLSLES, HLSL, METAL, and SPIRV shaders, and then the specific information of the layout list, texture array, and uniform block.
[0083] In order to facilitate subsequent search and retrieval, in this solution, the configuration file is in JSON format. JSON is a lightweight data exchange format that is easy for people to read and write, and is also easy for machines to parse and generate. As long as the JSON syntax rules are followed, the definition of data parameters can be freely played. Figure 3 As shown, the configuration file can be generated by editing with TProgram.
[0084] S40: When a rendering instruction is detected, the configuration file is searched according to a shader format in the rendering instruction to obtain a target attribute value corresponding to the rendering format.
[0085] Specifically, when a certain rendering object needs to be rendered, a rendering instruction is generated, and the rendering instruction includes information such as the object to be rendered and the shader format to be used for rendering. When a rendering instruction is detected, the configuration file is retrieved according to the shader format in the rendering instruction to obtain the first attribute value corresponding thereto, that is, the target attribute value.
[0086] For example, the shader format in the current rendering instruction is HLSL, and the configuration file is directly retrieved. There is only a first attribute value of the HLSL shader in the configuration file, so the first attribute value of the HLSL is used as the target attribute value.
[0087] Furthermore, the shader file in HLSL format includes a vertex shader and a fragment shader. The rendering instruction also includes a rendering type, which includes vertex rendering, fragment rendering, etc. Therefore, when further determining the target attribute value, the configuration file is first retrieved according to the shader format in the rendering instruction, and the first attribute value corresponding to the shader format is used as a candidate attribute value. Then, the target attribute value among the candidate attribute values is determined according to the rendering type in the rendering instruction.
[0088] S50. According to the second attribute value, configure parameters of a target shader corresponding to the rendering instruction to obtain a rendering shader.
[0089] Specifically, after the target attribute value is determined, the shader file corresponding to the target attribute value, that is, the target shader, can be called based on the target attribute value. At the same time, the specific parameters in the target shader need to be configured according to the second attribute value. Figure 7 to Figure 9 As shown, the specific information of the layout list, texture array and uniform block are recorded in the configuration file. The second attribute value can be assigned to the target shader to obtain the rendering shader.
[0090] In this embodiment, the layout list includes the vertex shader attribute object position (index), attribute name (name), data type (type) and data type description (typeDesc), where the attribute names include "aPosition" and "aTexAttr1", and the data type may include floating point type and other types. The texture array includes a texture binding point (binding), a position (index), a texture name (name), a texture type (type) and a texture description (typeDesc). The uniform block information includes information of multiple uniform blocks, each of which includes a binding point (binding), a name (name), a block type (isShare), and uniform block parameters (parameters). The uniform block parameters include a block attribute name (name), an offset in the uniform block (offset), a data type (type), a data type description (typeDesc), and a default value (value).
[0091] Furthermore, when configuring parameters, there are some parameters, such as Fig. 9 In the uniform block part, the value can be null, which means the default value in the initial shader. However, when configuring the target shader, when the corresponding second attribute value is null, the default value of the target shader is used as the second attribute value of the target shader.
[0092] Furthermore, the target shader can be a shader in a shader file or another self-compiled shader. For example, a self-compiled shader is created in advance, and the self-compiled shader can be connected to the interface of other shader files to call some functions of other shader files. When the target shader corresponding to the rendering instruction is a self-compiled shader, the parameter configuration of the self-compiled shader is completed based on the second attribute value.
[0093] When the target shader includes a self-compiled shader, such as Figure 5 As shown, the first attribute value also includes whether it is a built-in shader, that is, whether the shader text is a shader built into the self-compiled shader. If so, the shader text is no longer called, but the built-in shader is directly used as the shader for rendering.
[0094] S60: Rendering a rendering file corresponding to the rendering instruction based on the rendering shader.
[0095] Specifically, since the formats of the converted shader files are various, different types of shader files can be used for rendering processing for the same rendering file, thereby achieving cross-platform rendering, without the need to compile shaders that can be rendered on multiple platforms.
[0096] Based on the above multi-platform shader use method, the above invention also provides a multi-platform shader use device, such as Fig.10 Including:
[0097] An acquisition module 110 is used to acquire an initial shader to be processed;
[0098] A conversion module 120, configured to convert the initial shader into a plurality of shader files corresponding to the shader format according to a preset conversion format;
[0099] A generating module 130, configured to generate a configuration file corresponding to the initial shader according to the first attribute value of the shader file and the second attribute value of the initial shader;
[0100] A retrieval module 140 is used to retrieve the configuration file according to the shader format in the rendering instruction when a rendering instruction is detected, and obtain a target attribute value corresponding to the rendering format;
[0101] A configuration module 150, configured to perform parameter configuration on a target shader corresponding to the rendering instruction according to the second attribute value to obtain a rendering shader;
[0102] The rendering module 160 is used to render the rendering file corresponding to the rendering instruction based on the rendering shader.
[0103] The multi-platform based shader using device, wherein the acquisition module 110 is specifically used for:
[0104] Get the shader name and shader address to be processed;
[0105] The initial shader is obtained based on the shader name and the shader address.
[0106] The multi-platform based shader using device, wherein the retrieval module 140 is specifically used for:
[0107] According to the shader format in the rendering instruction, a configuration file is retrieved, and a first attribute value corresponding to the shader format is used as a candidate attribute value;
[0108] A target attribute value among the candidate attribute values is determined according to the rendering type in the rendering instruction.
[0109] The multi-platform based shader using device, wherein the conversion module 120 is used for:
[0110] Convert the initial shader into spv metadata, and input the spv metadata into a preset SPIRV-CROSS;
[0111] According to a preset conversion format, the SPIRV-CROSS is controlled to convert the spv metadata into a shader file corresponding to the shader format.
[0112] The multi-platform based shader using device, wherein the format of the configuration file is json format.
[0113] The multi-platform based shader using device, wherein the first attribute value includes a file name, a function name, whether it is a built-in shader, and a shader stage.
[0114] The multi-platform based shader using device, wherein the second attribute value includes a layout list, a texture array, and uniform block information.
[0115] Based on the above multi-platform shader usage method, the present invention also provides a terminal device, such as Fig.11 As shown, it includes at least one processor 20; a display screen 21; and a memory 22, and may also include a communications interface 23 and a bus 24. The processor 20, the display screen 21, the memory 22, and the communications interface 23 may communicate with each other through the bus 24. The display screen 21 is configured to display a preset user guide interface in the initial setting mode. The communications interface 23 may transmit information. The processor 20 may call the logic commands in the memory 22 to execute the method in the above embodiment.
[0116] In addition, the logic commands in the memory 22 described above can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product.
[0117] The memory 22, as a computer-readable storage medium, can be configured to store software programs, computer executable programs, such as program commands or modules corresponding to the methods in the embodiments of the present disclosure. The processor 20 executes functional applications and data processing by running the software programs, commands or modules stored in the memory 22, that is, implementing the methods in the above embodiments.
[0118] The memory 22 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and at least one application required for a function; the data storage area may store data created according to the use of the terminal device, etc. In addition, the memory 22 may include a high-speed random access memory and may also include a non-volatile memory. For example, a variety of media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk, may also be a transient computer-readable storage medium.
[0119] In addition, the specific process of loading and executing the above-mentioned computer-readable storage medium and the multiple command processors in the terminal device has been described in detail in the above-mentioned method, and will not be described one by one here.
[0120] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for using a shader based on multiple platforms, characterized in that: The method comprises: Get the initial shader to be processed; According to a preset conversion format, converting the initial shader into a plurality of shader files corresponding to the conversion format; Generate a configuration file corresponding to the initial shader according to the first attribute value of the shader file and the second attribute value of the initial shader; When a rendering instruction is detected, the configuration file is retrieved according to a shader format in the rendering instruction to obtain a target attribute value corresponding to the rendering instruction; According to the second attribute value, parameter configuration is performed on a target shader corresponding to the rendering instruction to obtain a rendering shader; Rendering a rendering file corresponding to the rendering instruction based on the rendering shader; The initial shader has certain processing logic and processing parameters when rendering. After the shader conversion, the processing logic and the processing parameters may not be retained. Therefore, in order to ensure that the converted shader file can be processed according to the processing logic and processing parameters of the initial shader, the processing logic and the processing parameters are used as the second attribute value; the second attribute value can be extracted when the initial shader is obtained, and the first attribute value can be generated when different shader files are generated; after obtaining the first attribute value and the second attribute value, the first attribute value and the second attribute value are written into a preset empty file according to certain writing rules to obtain the configuration file; the empty file does not refer to a file without content, but refers to a file that already has a file description but has not yet written the first attribute value and the second attribute value; The retrieving the configuration file according to the shader format in the rendering instruction to obtain the target attribute value corresponding to the rendering instruction includes: According to the shader format in the rendering instruction, a configuration file is retrieved, and a first attribute value corresponding to the conversion format pair is used as a candidate attribute value; Determining a target attribute value among the candidate attribute values according to a rendering type in the rendering instruction; The rendering instruction also includes a rendering type, which includes vertex rendering and fragment rendering; when further determining the target attribute value, the configuration file is first retrieved according to the shader format in the rendering instruction, and the first attribute value corresponding to the conversion format is used as a candidate attribute value; then, the target attribute value among the candidate attribute values is determined according to the rendering type in the rendering instruction.
2. The multi-platform shader usage method according to claim 1, characterized in that: The obtaining of the initial shader to be processed comprises: Get the shader name and shader address to be processed; The initial shader is obtained based on the shader name and the shader address.
3. The method for using a shader based on multiple platforms according to claim 1, characterized in that: The step of converting the initial shader into a plurality of shader files corresponding to the conversion format according to a preset conversion format includes: Convert the initial shader into spv metadata, and input the spv metadata into a preset SPIRV-CROSS; According to a preset conversion format, the SPIRV-CROSS is controlled to convert the spv metadata into a shader file corresponding to the conversion format.
4. The method for using a shader based on multiple platforms according to claim 3, characterized in that: The format of the configuration file is json format.
5. The method for using a shader based on multiple platforms according to claim 3, characterized in that: The first attribute value includes the file name, function name, whether it is a built-in shader, and the shader stage.
6. The method for using a shader based on multiple platforms according to claim 3, characterized in that: The second attribute value includes a layout list, a texture array, and uniform block information.
7. A shader using device based on multiple platforms, characterized in that: include: An acquisition module is used to obtain the initial shader to be processed; A conversion module, used for converting the initial shader into a plurality of shader files corresponding to the conversion format according to a preset conversion format; A generating module, configured to generate a configuration file corresponding to the initial shader according to the first attribute value of the shader file and the second attribute value of the initial shader; A retrieval module, configured to retrieve the configuration file according to a shader format in the rendering instruction when a rendering instruction is detected, and obtain a target attribute value corresponding to the rendering instruction; A configuration module, configured to perform parameter configuration on a target shader corresponding to the rendering instruction according to the second attribute value to obtain a rendering shader; A rendering module, used for rendering a rendering file corresponding to the rendering instruction based on the rendering shader; The initial shader has certain processing logic and processing parameters when rendering. After the shader conversion, the processing logic and the processing parameters may not be retained. Therefore, in order to ensure that the converted shader file can be processed according to the processing logic and processing parameters of the initial shader, the processing logic and the processing parameters are used as the second attribute value; The second attribute value can be extracted when the initial shader is obtained, and the first attribute value can be generated when different shader files are generated; After obtaining the first attribute value and the second attribute value, the first attribute value and the second attribute value are written into a preset empty file according to a certain writing rule to obtain the configuration file; the empty file does not refer to a file without content, but refers to a file that has a file description but has not yet written the first attribute value and the second attribute value; The retrieval module is specifically used to: retrieve the configuration file according to the shader format in the rendering instruction, and use the first attribute value corresponding to the conversion format pair as a candidate attribute value; Determining a target attribute value among the candidate attribute values according to a rendering type in the rendering instruction; The rendering instruction also includes a rendering type, which includes vertex rendering and fragment rendering; when further determining the target attribute value, firstly searching the configuration file according to the shader format in the rendering instruction, and taking the first attribute value corresponding to the conversion format as a candidate attribute value; Then, according to the rendering type in the rendering instruction, a target attribute value among the candidate attribute values is determined.
8. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the steps in the multi-platform based shader use method as described in any one of claims 1 to 6.
9. A terminal device, characterized in that: include: Processor, memory and communication bus; The memory stores a computer-readable program executable by the processor; The communication bus realizes the connection and communication between the processor and the memory; When the processor executes the computer-readable program, the processor implements the steps of the multi-platform shader use method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Image rendering method, image rendering device and electronic device
CN106997610A
Conversion method and device of shader and electronic equipment
CN111796867A