简体   繁体   中英

How can i initialize constant with derived values in HLSL?

I'm trying to migrate this glsl code into hlsl (unity shader). But the compiler complains about the following lines:

#define Length float
const Length m = 1.0;
const Length km = 1000.0 * m;

where km is derived from m , and the error msg said:

'km': initial value must be a literal expression

Is there any way to solve this without just replacing m with its literal value manually?

I tried to google this but found nothing related, or maybe this question is just a complaint about HLSL's weak compiler.

According to glsl-to-hlsl-reference , we should use static const qualifiers in hlsl.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM