- Home /
Initilization of variables in shader
Hi,
I've tried to convert some shaders from GLSL (shadertoy) to HLSL, but there is a one really weird moment. When I'm just replacing all GLSL functions to HLSL it works fine. But there are some variables in shader wich written like this:
float2 p,q,v,S=float2(27,-28);
I've replaced the to this:
float2 p=float2(27,-28);
float2 q=float2(27,-28);
float2 v=float2(27,-28);
float2 S=float2(27,-28);
And suddenly it stops working properly. Maybe I've missed some core programming concept or something, but there two variants should be identical, right?
Answer by bpaynom · Feb 01, 2019 at 11:02 AM
I don't remember the last time i wrote HLSL, but I think that line it's the same :
float2 p = float2(0,0);
float2 q = float2(0,0);
float2 v = float2(0,0);
float2 S = float2(27,-28);
Sorry if I'm wrong, but let's get a try.
I can't verify that this is true, but i was thinking along the same line. Since most shader languages are based on C, if you declare multiple variables with a single type, each need to have it's own initial value. So in the original code the assignment only affects the last variable. That's why it's generally adviced to not declare multiple variables on the same line. Our case here would match their second noncompliant code example.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
[C# Code] Why am I getting this error??? 1 Answer
Do TEXCOORDS need to be in sequence? 1 Answer
Is it possible to read light value per vertex with a shader? 0 Answers
doubles and compute shaders 1 Answer