Dynamically compiling and running shaders from a file in XNA

im wonders if it is possible to dynamically compile a pixel shader from a file and apply it to the grid.

First, I just start with some background information. I have a system that creates HLSL pixel shaders based on a series of data, which is not very important for the question. The important thing is that these shaders do not use methods or passes. Since they are not intended to be used as .fx files.

The method ShaderCompiler.CompileFromFile()is able to successfully compile the file into CompiledShader.

Is it possible to apply this shader to the grid?

Since I do not want to find an entry point for each file, to wrap it in a technique so that it can be compiled as Effect.

+3
source share
1 answer

First of all, if your shader does not have an entry point, you are not really compiling anything! HLSL features (it seems this is what you are working with) are included at the beginning, starting at the entry point. If you do not have an entry point, then you have an empty shader.

(You can confirm this by examining the resulting shader after compiling it. Mark this question and answer for instructions .)

, - . . . ShaderCompiler.CompileFromFile, Stream, .

, XNA 3.1 :

CompiledShader cs = ShaderCompiler.CompileFromFile(...);
PixelShader ps = new PixelShader(graphicsDevice, cs.GetShaderCode());
graphicsDevice.PixelShader = ps;

XNA, , ModelMeshPart.Draw . Model.

, ShaderCompiler, CompiledShader, PixelShader XNA XNA 4.0. . XNA 4.0 .

(, Effect XNA 4.0 XNA 3.1 PixelShader , Effect, Effect.CompileEffectFromSource, XNA 3.1, ShaderCompiler)

+6

Source: https://habr.com/ru/post/1762773/


All Articles