HLSL Pixel Shader - Global Variables?

I am new to HLSL and shaders. I can not replace the color that I get. It is intended for use in 2D text, that is, in subtitles. The problem is that if I set osd_color outside of main (), it does not display anything. I use Shazzam Shader Editor 1.4 to quickly see the effect, however in the program.

sampler2D texture0 : register(s0); float4 osd_color = float4(0,0,0,1); struct PixelShaderInput { float2 uv0: TEXCOORD0; float4 color: COLOR; }; float4 main(PixelShaderInput input): COLOR { float4 color = tex2D(texture0, input.uv0) * osd_color; return color; } 

Hope you can help.

Edit:

While I'm in, if I want to add a shadow / path and return its color, how would I do it? Let them say that every variable works. And osd_color is white, and float4 is black. I tried:

 float4 outline = tex2D(texture0, (input.uv0 * 1.1) ) * outline_color; return color + outline; 

With this, all I get is white (osd_color) ..

+4
source share
1 answer

You need to manage the memory of non-static variables yourself. A static variable will save your day:

 static float4 osd_color = float4(0,0,0,1); 

When using static, everything works as expected, since the compiler takes care of reserving some memory for the color value. If there is no static file, you need to manage the memory or your application yourself, which means that you need to get the default value for the variable and manually copy it to a constant buffer, for example.

+3
source

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


All Articles