Rendering a Texture and HLSL "texture" so it looks like it should

I don’t know if this is best forum section to post this question in…
I have a texture made from the output of an HLSL program…
Now this was/is only for testing purposes…as I am having problems getting the full blown HLSL to appear exactly as the static texture version of it…

Here is the faked HLSL texture/material

Here is what the texture/material looks like using custom HLSL node. Notice how the colors are washed out.

Here is the UE5.3 material with the custom HLSL node.
gradient2.zip (8.2 KB)

Here is screen cap of the material (if you prefer to look at this rather than the material in the zip file)

Here is the HLSL (again this is all set up already in the material in the zip file…but if you prefer having the actual text here it is)

#define HLSL 
    //#define GLSL 
#ifdef HLSL
#define vec2 float2
#define vec3 float3
#define vec4 float4
#define mix lerp
#define fract frac
#define mat2 float2x2
#define mat3 float3x3
#define mod fmod
#define atan atan2
#endif

#define PI 3.141592654

vec4 firstColor = vec4(1.0,0.0,0.0,1.0); //red
vec4 middleColor = vec4(0.0,1.0,0.0,1.0); // green
vec4 endColor = vec4(0.0,0.0,1.0,1.0); // blue
double d = 0.0;
    vec2 xy = UV.xy;
    float h = 0.5; // adjust position of middleColor
    vec4 col = mix(mix(firstColor, middleColor, xy.x/h), mix(middleColor, endColor, (xy.x - h)/(1.0 - h)), step(h, xy.x));
    vec4 fragColor = col;
    return fragColor;

As you can see…the real HLSL material does not appear the same as the fake HLSL material (a texture image export of HLSL output from Visual Studio Code). The question is why? Is there something I can do to fix it?

I initially thought the issue was a color space problem. But the texture output of the HLSL from VSC…when I use that…to fake it…it will appear correctly.

But if I use the actual HLSL node in the material…the colors are all washed out. With other complex HLSL shader examples the result is very noticeable. In VSC when I run the HLSL shader program, I get vibrant well defined colors. When I do so in UE, in a material with the exact same HLSL code in a custom node…the colors get washed out.

Is this an issue with the shader compiler settings?
I am guessing that precision is being lost…resulting in this washed out appearance end result.

it’s called srgb and linear “colorspace” (i hate this gimmick buzzword). you gotta multiply the result with itself. aka square it. the inverse is a square root, obviously.

1 Like

Holy mackerel!!!
That fixed it!!!

How in hell did you know about that???
I haven’t seen this mentioned before.

:grinning: :smiley: :smile: :grin: :laughing: :sweat_smile: :rofl: :joy:

Now I can fix all the other washed out HLSL materials I made!

:smiley: