PurpleKingdomGames / ultraviolet

Scala 3 to GLSL transpiler library
https://ultraviolet.indigoengine.io/
MIT License
59 stars 2 forks source link

Fixed #91: If statements can be assigned to vars #106

Closed davesmith00000 closed 10 months ago

davesmith00000 commented 10 months ago

Relates to: https://github.com/PurpleKingdomGames/ultraviolet/issues/91

This code:

var i1: vec2 = null
i1 = if x0.x > x0.y then vec2(1.0, 0.0) else vec2(0.0, 1.0)

Was producing this invalid GLSL:

vec2 x0=vec2(1.0,2.0);
vec2 i1;
i1=if(x0.x>x0.y){  vec2(1.0,0.0)}else{  vec2(0.0,1.0)}
vec4(i1,0.0,1.0);

Instead of this valid GLSL:

vec2 x0=vec2(1.0,2.0);
vec2 i1;
if(x0.x>x0.y){
  i1=vec2(1.0,0.0);
}else{
  i1=vec2(0.0,1.0);
}
vec4(i1,0.0,1.0);