diff --git a/src/analyzer.fs b/src/analyzer.fs index 07fda902..08b45f12 100644 --- a/src/analyzer.fs +++ b/src/analyzer.fs @@ -32,6 +32,15 @@ module private VariableInlining = mapExpr (mapEnv collectLocalUses id) expr |> ignore result + let isEffectivelyConst (ident: Ident) = + if ident.AsResolvedVar.IsSome then + // A variable not reassigned is effectively constant. + not ident.AsResolvedVar.Value.isLValue + elif Builtin.pureBuiltinFunctions.Contains ident.Name then + true + else + false + // Mark variables as inlinable when possible. // Variables are always safe to inline when all of: // - the variable is used only once in the current block @@ -46,8 +55,8 @@ module private VariableInlining = // - it depends only on variables proven constants let markInlinableVariables block = // Variables that are defined in this scope. - // The booleans indicate if the variable initialization has dependencies / unsafe dependencies. - let localDefs = Dictionary() + // The boolean indicate if the variable initialization is const. + let localDefs = Dictionary() // List of expressions in the current block. Do not look in sub-blocks. let mutable localExpr = [] for stmt: Stmt in block do @@ -60,16 +69,8 @@ module private VariableInlining = | Some init -> localExpr <- init :: localExpr let deps = collectReferencesSet init - let hasUnsafeDep = deps |> Seq.exists (fun ident -> - if ident.AsResolvedVar <> None then - // A variable not reassigned is effectively constant. - ident.AsResolvedVar.Value.isLValue - elif Builtin.pureBuiltinFunctions.Contains ident.Name then - false - else - true - ) - localDefs.[def.name.Name] <- (def.name, deps.Count > 0, hasUnsafeDep) + let isConst = deps |> Seq.forall isEffectivelyConst + localDefs.[def.name.Name] <- (def.name, isConst) | Expr e | Jump (_, Some e) -> localExpr <- e :: localExpr | Verbatim _ | Jump (_, None) | Block _ | If _| ForE _ | ForD _ | While _ | DoWhile _ | Switch _ -> () @@ -78,48 +79,63 @@ module private VariableInlining = let allReferences = collectReferences block for def in localDefs do - let ident, hasInitDeps, hasUnsafeDeps = def.Value + let ident, isConst = def.Value if not ident.ToBeInlined && not ident.AsResolvedVar.Value.isLValue then - // AggroInlining could in theory do inlining when hasUnsafeDeps=false. - // However, it seems to increase the compressed size, and might affect performance. - if options.aggroInlining && not hasInitDeps then - ident.ToBeInlined <- true match localReferences.TryGetValue(def.Key), allReferences.TryGetValue(def.Key) with - | (true, 1), (true, 1) when not hasUnsafeDeps -> ident.ToBeInlined <- true + | (true, 1), (true, 1) when isConst-> ident.ToBeInlined <- true | (false, _), (false, _) -> ident.ToBeInlined <- true | _ -> () - let maybeInlineVariables li = - let mapInnerDecl = function - | ({typeQ = tyQ}, defs) as d when List.contains "const" tyQ -> + // Inline some variables, regardless of where they are used or how often they are used. + let maybeInlineVariables topLevel = + let isTrivialExpr = function + | Var v when v.Name = "true" || v.Name = "false" -> true + | Int _ + | Float _ -> true + | _ -> false + + // Detect if a variable can be inlined, based on its value. + let canBeInlined (init: Expr) = + match init with + | e when isTrivialExpr e -> true + | _ when not options.aggroInlining -> false + // Allow a few things to be inlined with aggroInlining + | Var v + | Dot (Var v, _) -> isEffectivelyConst v + | FunCall(Op op, args) -> + not (Builtin.assignOps.Contains op) && + args |> List.forall isTrivialExpr + | FunCall(Var fct, args) -> + Builtin.pureBuiltinFunctions.Contains fct.Name && + args |> List.forall isTrivialExpr + | _ -> false + + let mapInnerDecl isTopLevel = function + | (ty: Type, defs) as d when not ty.IsExternal -> for (def:DeclElt) in defs do - // AggroInlining: unconditional inlining of anything marked "const". - // Note: this is unsafe if the init value depends on something mutable. - if options.aggroInlining then - def.name.ToBeInlined <- true - // Otherwise, inline only trivial constants. - else match def.init with - | Some (Var v) when v.Name = "true" || v.Name = "false" -> + if not def.name.AsResolvedVar.Value.isLValue then + if def.init.IsNone then + // Top-level values are special, in particular in HLSL. Keep them for now. + if not isTopLevel then def.name.ToBeInlined <- true - | Some (Int _) - | Some (Float _) -> - def.name.ToBeInlined <- true - | _ -> () + elif canBeInlined def.init.Value then + def.name.ToBeInlined <- true d | d -> d let mapStmt = function - | Decl d -> Decl (mapInnerDecl d) + | Decl d -> Decl (mapInnerDecl false d) | s -> s let mapExpr _ e = e let mapTLDecl = function - | TLDecl d -> TLDecl (mapInnerDecl d) + | TLDecl d -> TLDecl (mapInnerDecl true d) | d -> d - li + topLevel |> mapTopLevel (mapEnv mapExpr mapStmt) |> List.map mapTLDecl - let markLValues li = + let markLValues topLevel = + let findWrites (env: MapEnv) = function | Var v as e when env.isLValue && v.AsResolvedVar <> None -> v.AsResolvedVar.Value.isLValue <- true @@ -137,11 +153,13 @@ module private VariableInlining = e | _ -> e | e -> e - mapTopLevel (mapEnv findWrites id) li + mapTopLevel (mapEnv findWrites id) topLevel let markInlinableVariables = VariableInlining.markInlinableVariables let markLValues = VariableInlining.markLValues -let maybeInlineVariables = VariableInlining.maybeInlineVariables +let maybeInlineVariables topLevel = + if options.noInlining then topLevel + else VariableInlining.maybeInlineVariables topLevel // Create ResolvedIdent for each declaration in the file. diff --git a/src/ast.fs b/src/ast.fs index e57d9412..8c8485f0 100644 --- a/src/ast.fs +++ b/src/ast.fs @@ -67,7 +67,9 @@ and Type = { name: TypeSpec // e.g. int typeQ: string list // type qualifiers, e.g. const, uniform, out, inout... arraySizes: Expr list // e.g. [3][5] -} +} with + member this.IsExternal = + List.exists (fun s -> Set.contains s Builtin.externalQualifier) this.typeQ and DeclElt = { name: Ident // e.g. foo diff --git a/src/builtin.fs b/src/builtin.fs index 889c5e4e..1f7a0de8 100644 --- a/src/builtin.fs +++ b/src/builtin.fs @@ -66,3 +66,7 @@ let pureBuiltinFunctions = vectorFunctions + castFunctions + textureFunctions + +// Type qualifiers telling that a global variables is an 'external' name +// (it may be referenced from other files). +let externalQualifier = set ["in"; "out"; "attribute"; "varying"; "uniform"] diff --git a/src/renamer.fs b/src/renamer.fs index 87c74a5a..b8613c93 100644 --- a/src/renamer.fs +++ b/src/renamer.fs @@ -242,11 +242,7 @@ module private RenamerImpl = let aux (env: Env) (decl: Ast.DeclElt) = Option.iter (renExpr env) decl.init Option.iter (renExpr env) decl.size - let ext = - let tyQSet = Set.ofList ty.typeQ - let extQ = ["in"; "out"; "attribute"; "varying"; "uniform"] - List.exists (fun s -> Set.contains s tyQSet) extQ - let isExternal = isTopLevel && (ext || options.hlsl) + let isExternal = isTopLevel && (ty.IsExternal || options.hlsl) if (isTopLevel && options.preserveAllGlobals) || List.contains decl.name.Name options.noRenamingList then diff --git a/tests/compression_results.log b/tests/compression_results.log index 9784c844..6eeb2864 100644 --- a/tests/compression_results.log +++ b/tests/compression_results.log @@ -1,23 +1,23 @@ -clod.frag... 8895 => 1533.510 -audio-flight-v2.frag 4586 => 895.242 -buoy.frag 4148 => 632.447 -controllable-machinery.frag 7771 => 1227.917 +clod.frag... 8918 => 1534.693 +audio-flight-v2.frag 4584 => 898.967 +buoy.frag 4137 => 630.100 +controllable-machinery.frag 7760 => 1219.338 ed-209.frag 7860 => 1355.308 elevated.hlsl 3405 => 603.218 -endeavour.frag 2642 => 541.090 -from-the-seas-to-the-stars.frag 14320 => 2334.199 -frozen-wasteland.frag 4601 => 809.115 -kinder_painter.frag 2891 => 447.986 -leizex.frag 2298 => 512.987 -lunaquatic.frag 5231 => 1055.816 +endeavour.frag 2627 => 536.451 +from-the-seas-to-the-stars.frag 14308 => 2332.018 +frozen-wasteland.frag 4597 => 809.000 +kinder_painter.frag 2871 => 447.691 +leizex.frag 2311 => 510.372 +lunaquatic.frag 5257 => 1049.740 mandelbulb.frag 2403 => 547.468 -ohanami.frag 3254 => 727.478 -orchard.frag 5584 => 1037.403 +ohanami.frag 3256 => 722.517 +orchard.frag 5574 => 1034.487 oscars_chair.frag 4651 => 986.364 robin.frag 6333 => 1055.863 -slisesix.frag 4571 => 930.275 +slisesix.frag 4581 => 933.929 terrarium.frag 3634 => 747.342 -the_real_party_is_in_your_pocket.frag 12187 => 1813.123 +the_real_party_is_in_your_pocket.frag 12168 => 1811.526 valley_ball.glsl 4386 => 888.496 yx_long_way_from_home.frag 2975 => 610.699 -Total: 118626 => 21293.347 +Total: 118596 => 21265.585 diff --git a/tests/real/audio-flight-v2.frag.expected b/tests/real/audio-flight-v2.frag.expected index 6a1165dc..36cf2d8e 100644 --- a/tests/real/audio-flight-v2.frag.expected +++ b/tests/real/audio-flight-v2.frag.expected @@ -105,7 +105,6 @@ vec2 edge(vec2 p) -1.: 1.); } -float ths=13.25; vec2 map(vec3 p,float sg) { vec2 res=vec2(100,-1); @@ -162,7 +161,7 @@ vec2 map(vec3 p,float sg) flight+=.00025/(1e-7+blt*blt); if(sg==1.&&zprs<.1) glow+=.00015/(2e-6+dlt*dlt); - if(sg==1.&&tmths) + if(tm>13.25) C=h*diff+spec; else if(m==3.||m==4.) C=hsv2rgb(vec3(s_hp.z*.01,.8,.6))*diff; } - if(tm>ths) + if(tm>13.25) { if(mod(T,.1)<.05) FC=vec3(.8); diff --git a/tests/real/controllable-machinery.frag.expected b/tests/real/controllable-machinery.frag.expected index 563c7ddc..2299eb31 100644 --- a/tests/real/controllable-machinery.frag.expected +++ b/tests/real/controllable-machinery.frag.expected @@ -154,8 +154,7 @@ float GearDf(vec3 p) } float ObjDf(vec3 p) { - vec4 a4; - vec3 q,bPos; + vec3 q; float dMin,d,r,a; dMin=dstFar; q=p-vec3(1.13+bEdge,bEdge,1); @@ -355,7 +354,7 @@ vec3 ShowScene(vec3 ro,vec3 rd) { vec4 col4; vec3 vn,col,q; - float dstObj,dstGear,dstBlk,sh,s,r,a,nDotL; + float dstObj,dstGear,dstBlk,sh,r,a,nDotL; int idObjT; bool isMet; tCyc=18.5; diff --git a/tests/real/disco.expected b/tests/real/disco.expected index 05c451ab..ebfafc1f 100644 --- a/tests/real/disco.expected +++ b/tests/real/disco.expected @@ -6,4 +6,4 @@ var var_TEX2 = "D" var var_TEX3 = "y" var var_TIME = "v" -var disco_frag = `uniform vec2 s;uniform float v;uniform sampler2D f,C,D,y;vec4 n(vec2 s,float f){float c=3.1415,y=v*sign(f),a=s.x*320.*.0065*f,i=s.y*240.*.006*f,C=sqrt(a*a+i*i);if(C>1.)return vec4(0);{float r=-.4*sign(f)+sin(y*.05),n=sqrt(1.-a*a-i*i),u=i*sin(r)-n*cos(r);i=i*cos(r)+n*sin(r);n=acos(i);r=acos(a/sin(n))/(2.*c)*120.*sign(u)-y;n=n*60./c;u=cos(floor(n/c));C=pow(abs(cos(r)*sin(n)),.2)*.1/(u+sin(float(int((r+c/2.)/c))+y*.6+cos(u*25.)))*pow(1.-C,.9);vec4 g;g=C<0.?vec4(-C/2.*abs(cos(y*.1)),0,-C*2.*abs(sin(y*.04)),1):vec4(C,C*2.,C*2.,1);return g;}}void main(){vec2 f=-1.+2.*gl_FragCoord.xy/s.xy;vec4 r=vec4(0);for(int i=80;i>0;i--)r+=n(f,1.-float(i)/80.)*(.008-float(i)*5e-5);vec4 i=n(f,1.);gl_FragColor=(i.w==0.?n(f,-.2)*.02:i)+sqrt(r);}` +var disco_frag = `uniform vec2 s;uniform float v;uniform sampler2D f,C,D,y;vec4 n(vec2 s,float f){float c=v*sign(f),a=s.x*320.*.0065*f,i=s.y*240.*.006*f,y=sqrt(a*a+i*i);if(y>1.)return vec4(0);{float r=-.4*sign(f)+sin(c*.05),n=sqrt(1.-a*a-i*i),u=i*sin(r)-n*cos(r);i=i*cos(r)+n*sin(r);n=acos(i);r=acos(a/sin(n))/6.283*120.*sign(u)-c;n=n*60./3.1415;u=cos(floor(n/3.1415));y=pow(abs(cos(r)*sin(n)),.2)*.1/(u+sin(float(int((r+1.57075)/3.1415))+c*.6+cos(u*25.)))*pow(1.-y,.9);vec4 g;g=y<0.?vec4(-y/2.*abs(cos(c*.1)),0,-y*2.*abs(sin(c*.04)),1):vec4(y,y*2.,y*2.,1);return g;}}void main(){vec2 f=-1.+2.*gl_FragCoord.xy/s.xy;vec4 r=vec4(0);for(int i=80;i>0;i--)r+=n(f,1.-float(i)/80.)*(.008-float(i)*5e-5);vec4 i=n(f,1.);gl_FragColor=(i.w==0.?n(f,-.2)*.02:i)+sqrt(r);}` diff --git a/tests/real/endeavour.frag.expected b/tests/real/endeavour.frag.expected index f788832e..bc474533 100644 --- a/tests/real/endeavour.frag.expected +++ b/tests/real/endeavour.frag.expected @@ -75,10 +75,9 @@ void scene(vec3 x,out vec2 sdf) stroke(sdb.x,.003*step(dis,0.),sdb.x); sdf.x=max(sdf.x,-da); add(sdf,sdb,sdf); - float dr=.1; - vec3 y=mod(x,dr)-.5*dr; - float guard=-length(max(abs(y)-vec3(.5*dr*c.xx,.6),0.)); - guard=abs(guard)+dr*.1; + vec3 y=mod(x,.1)-.05; + float guard=-length(max(abs(y)-vec3(.05*c.xx,.6),0.)); + guard=abs(guard)+.01; sdf.x=min(sdf.x,guard); } void normal(vec3 x,out vec3 n) @@ -108,8 +107,8 @@ void mainImage(out vec4 fragColor,vec2 fragCoord) vec2 uv=fragCoord/iResolution.yy-.5*vec2(a,1),s; vec3 col=c.yyy,o=.5*c.yyx+.3*iTime*c.yxy,t=vec3(uv,0)+.3*iTime*c.yxy+c.yxy,dir=normalize(t-o),x; float d=(.04-o.z)/dir.z; - int N=450,i; - for(i=0;i>5)+k[1],v.y+=(v.x<<4)+k[2]^v.x+sum^(v.x>>5)+k[3]; + sum+=2654435769,v.x+=(v.y<<4)+k[0]^v.y+sum^(v.y>>5)+k[1],v.y+=(v.x<<4)+k[2]^v.x+sum^(v.x>>5)+k[3]; return v; } mat2 rotmat(float a) @@ -336,7 +336,6 @@ void main() } p.x-=2; p.y+=time2/14.; - float c; } else if(w.w<.26) w.x=R(),w.y=R(),w.z=R(),w.w=R(),p=(w.xyz*2-1)*3,p.x-=2,col=vec3(w.w)/2,w.w=R(),col+=vec3(1,1,.5)*pow(.5+.5*cos(w.w*6+time*3),32.)*.1; diff --git a/tests/real/frozen-wasteland.frag.expected b/tests/real/frozen-wasteland.frag.expected index 9891a517..4baaafb1 100644 --- a/tests/real/frozen-wasteland.frag.expected +++ b/tests/real/frozen-wasteland.frag.expected @@ -167,13 +167,13 @@ float fogmap(vec3 p,float d) } float march(vec3 ro,vec3 rd,out float drift,vec2 scUV) { - float precis=.1,mul=.34,h,d=hash12(scUV)*1.5; + float mul=.34,h,d=hash12(scUV)*1.5; drift=0.; for(int i=0;iFAR) + if(h<.1*(1.+d*.05)||d>FAR) break; drift+=fogmap(p,d); d+=h*mul; diff --git a/tests/real/kinder_painter.expected b/tests/real/kinder_painter.expected index 646d54ea..f57a90be 100644 --- a/tests/real/kinder_painter.expected +++ b/tests/real/kinder_painter.expected @@ -122,7 +122,6 @@ "}" "bool x(vec3 v,vec3 z,float i)" "{" - "float y;" "bvec4 b;" "b.x=d(r[0],v,z,i);" "b.y=d(r[1],v,z,i);" @@ -156,11 +155,9 @@ "}" "void main()" "{" - "vec4 f,i,w;" - "vec3 y;" - "vec4 o;" - "vec2 x=-1.+2.*gl_FragCoord.xy/v.xy;" - "x*=vec2(v.x/v.y,1);" + "vec4 f,i,w,o;" + "vec2 y=-1.+2.*gl_FragCoord.xy/v.xy;" + "y*=vec2(v.x/v.y,1);" "r[0]=vec4(1.2*sin(2.073423*z),0,1.8*sin(2.450409*z+1.),1);" "r[1]=vec4(1.5*sin(1.947761*z+4.),sin(1.822099*z+1.9),1.8*sin(1.822099*z),1);" "r[2]=vec4(-1.2,0,0,.4);" @@ -173,9 +170,9 @@ "b[3]=vec4(.5,.5,.7,3);" "b[4]=vec4(1,.9,.9,2);" "b[5]=vec4(1,.9,.9,2);" - "float a=.15*z-6.2831*s.x/v.x,c=2.+3.*s.y/v.y;" - "vec2 g=vec2(cos(a),sin(a));" - "vec3 n=normalize(vec3(x.x*g.x-g.y,x.y,g.x+x.x*g.y)),t=vec3(c*g.y,0,-c*g.x);" + "float x=.15*z-6.2831*s.x/v.x,a=2.+3.*s.y/v.y;" + "vec2 g=vec2(cos(x),sin(x));" + "vec3 n=normalize(vec3(y.x*g.x-g.y,y.y,g.x+y.x*g.y)),t=vec3(a*g.y,0,-a*g.x);" "float u=m(t,n,i,w);" "vec3 e=t+n*u;" "f.xyz=vec3(0,1.5,-3)-e;" diff --git a/tests/real/leizex.expected b/tests/real/leizex.expected index abb42631..51233482 100644 --- a/tests/real/leizex.expected +++ b/tests/real/leizex.expected @@ -63,9 +63,9 @@ _leizex_frag: db '}' db 'vec3 x(vec3 v)' db '{' - db 'float f,y=2e-4;' - db 'vec3 x=vec3(c(v+vec3(y,0,0),f)-c(v-vec3(y,0,0),f),c(v+vec3(0,y,0),f)-c(v-vec3(0,y,0),f),c(v+vec3(0,0,y),f)-c(v-vec3(0,0,y),f));' - db 'return normalize(x);' + db 'float f;' + db 'vec3 y=vec3(c(v+vec3(2e-4,0,0),f)-c(v-vec3(2e-4,0,0),f),c(v+vec3(0,2e-4,0),f)-c(v-vec3(0,2e-4,0),f),c(v+vec3(0,0,2e-4),f)-c(v-vec3(0,0,2e-4),f));' + db 'return normalize(y);' db '}' db 'void c(out vec3 v,out vec3 f,vec2 n,float x)' db '{' @@ -81,8 +81,8 @@ _leizex_frag: db '}' db 'vec3 c(vec3 v,float x,vec3 y)' db '{' - db 'float f=5e-4,m=c(256.*y);' - db 'vec3 n=vec3(c(256.*(y+vec3(f,0,0)))-m,c(256.*(y+vec3(0,f,0)))-m,c(256.*(y+vec3(0,0,f)))-m);' + db 'float f=c(256.*y);' + db 'vec3 n=vec3(c(256.*(y+vec3(5e-4,0,0)))-f,c(256.*(y+vec3(0,5e-4,0)))-f,c(256.*(y+vec3(0,0,5e-4)))-f);' db 'return normalize(v+x*n);' db '}' db 'void main()' diff --git a/tests/real/lunaquatic.frag.expected b/tests/real/lunaquatic.frag.expected index d6a0ee56..671ea799 100644 --- a/tests/real/lunaquatic.frag.expected +++ b/tests/real/lunaquatic.frag.expected @@ -5,7 +5,7 @@ uniform vec2 resolution; uniform float time; vec4 artifactPos; vec3 lightPos,lightDir,ro,rd; -float FAR,EXPLOSIONTIME,pi,eps=1e-4; +float FAR,EXPLOSIONTIME,pi; float saturate(float x) { return clamp(x,0.,1.); @@ -113,7 +113,7 @@ vec3 calculateSky(vec3 ro,vec3 rd,int addPlanet) vec4 p=calcPlanet(ro,rd); color+=coeff*saturate(1.-p.w)+p.xyz; } - rd.xy+=ro.xy*eps; + rd.xy+=ro.xy*1e-4; color+=(calculateSkySub(normalize(rd+vec3(sin(Y.z*.1),0,cos(Y.z*.1))*.1)*3.)+calculateSkySub(normalize(rd+vec3(sin(Y.z*.1),0,cos(Y.z*.1))*.2)*5.)*.1+calculateSkySub(normalize(rd+vec3(sin(Y.z*.1),0,cos(Y.z*.1))*.4)*7.)*.1-calculateSkySub(normalize(rd+vec3(sin(Y.z*.2),0,0)*.5))*1.5)*saturate(rd.y+.5); return color; } @@ -173,7 +173,7 @@ vec3 calcScene(vec3 ro,vec3 rd) if(rd.y<-.01&&traceTerrain(ro+rd*upperPlane,rd,finalDepth,finalDepth)>0) { finalDepth+=upperPlane; - vec3 pos=ro+rd*finalDepth,normal=normalize(normalize(vec3(height(pos.xz-vec2(eps,0))-height(pos.xz+vec2(eps,0)),eps*2.,height(pos.xz-vec2(0,eps))-height(pos.xz+vec2(0,eps))))+(getWaterNormal(pos*.2)*1.5+getWaterNormal(pos*.1))*max(0.,1.-finalDepth/FAR*7.)); + vec3 pos=ro+rd*finalDepth,normal=normalize(normalize(vec3(height(pos.xz-vec2(1e-4,0))-height(pos.xz+vec2(1e-4,0)),2e-4,height(pos.xz-vec2(0,1e-4))-height(pos.xz+vec2(0,1e-4))))+(getWaterNormal(pos*.2)*1.5+getWaterNormal(pos*.1))*max(0.,1.-finalDepth/FAR*7.)); color=max(0.,dot(normal,lightDir)+pow(max(0.,dot(normal,normalize(lightDir-rd))),2.))*calculateSky(pos,reflect(rd,normal),1); calcBurn(pos.xz,normal,color); color=mix(color,calculateSky(ro,rd,0),saturate(finalDepth/FAR*1.6+saturate(dot(normalize(normal+rd*.2),rd)))); @@ -225,7 +225,7 @@ void main() if(isoDistance22)) gl_FragColor.xyz=vec3(.5,1,.6)/3; vec3 ld=normalize(vec3(1,3+cos(ti)/2,1+sin(ti*3)/2)); - float e=.01,d2=f(ro+rd*t+ld*e),l=max(0,(d2-d)/e),d3=f(ro+rd*t+vec3(0,1,0)*e),l2=max(0,.5+.5*(d3-d)/e); + float d2=f(ro+rd*t+ld*.01),l=max(0,(d2-d)/.01),d3=f(ro+rd*t+vec3(0,1,0)*.01),l2=max(0,.5+.5*(d3-d)/.01); { vec3 rp=ro+rd*t; if(ti>12&&ti<22) @@ -83,7 +83,7 @@ void main() gl_FragColor.xyz=vec3(.65); } vec3 ld=normalize(vec3(1,3+cos(ti)/2,1+sin(ti*3)/2)); - float e=.01,d2=f(ro+rd*t+ld*e),l=max(0,(d2-d)/e),d3=f(ro+rd*t+vec3(0,1,0)*e),l2=max(0,.5+.5*(d3-d)/e); + float d2=f(ro+rd*t+ld*.01),l=max(0,(d2-d)/.01),d3=f(ro+rd*t+vec3(0,1,0)*.01),l2=max(0,.5+.5*(d3-d)/.01); { vec3 rp=ro+rd*t; if(ti>12&&ti<17) diff --git a/tests/real/robin.frag.expected b/tests/real/robin.frag.expected index 72d5c1db..0ca68a20 100644 --- a/tests/real/robin.frag.expected +++ b/tests/real/robin.frag.expected @@ -183,8 +183,7 @@ vec3 DoLighting(vec3 mat,vec3 pos,vec3 normal,vec3 eyeDir,float d,float specular } vec3 GetNormal(vec3 p,float sphereR) { - vec2 eps=vec2(.01,0); - return normalize(vec3(Map(p+eps.xyy)-Map(p-eps.xyy),Map(p+eps.yxy)-Map(p-eps.yxy),Map(p+eps.yyx)-Map(p-eps.yyx))); + return normalize(vec3(Map(p+vec2(.01,0).xyy)-Map(p-vec2(.01,0).xyy),Map(p+vec2(.01,0).yxy)-Map(p-vec2(.01,0).yxy),Map(p+vec2(.01,0).yyx)-Map(p-vec2(.01,0).yyx))); } float SphereRadius(float t) { diff --git a/tests/real/slisesix.frag.expected b/tests/real/slisesix.frag.expected index a29cda1d..ce306d96 100644 --- a/tests/real/slisesix.frag.expected +++ b/tests/real/slisesix.frag.expected @@ -108,12 +108,11 @@ float map(vec3 pos,out int sid,out int submat) } vec3 calcNormal(vec3 pos) { - float eps=2e-4; vec3 nor; int kk,kk2; - nor.x=map(vec3(pos.x+eps,pos.yz),kk,kk2)-map(vec3(pos.x-eps,pos.yz),kk,kk2); - nor.y=map(vec3(pos.x,pos.y+eps,pos.z),kk,kk2)-map(vec3(pos.x,pos.y-eps,pos.z),kk,kk2); - nor.z=map(vec3(pos.xy,pos.z+eps),kk,kk2)-map(vec3(pos.xy,pos.z-eps),kk,kk2); + nor.x=map(vec3(pos.x+2e-4,pos.yz),kk,kk2)-map(vec3(pos.x-2e-4,pos.yz),kk,kk2); + nor.y=map(vec3(pos.x,pos.y+2e-4,pos.z),kk,kk2)-map(vec3(pos.x,pos.y-2e-4,pos.z),kk,kk2); + nor.z=map(vec3(pos.xy,pos.z+2e-4),kk,kk2)-map(vec3(pos.xy,pos.z-2e-4),kk,kk2); return normalize(nor); } void main() @@ -157,16 +156,16 @@ void main() if(matID!=666) { vec3 nor=calcNormal(pos); - float kke=1e-4,bumpa=.0075; + float bumpa=.0075; if(matID!=5) bumpa*=.75; if(matID==4) bumpa*=.5; - bumpa/=kke; + bumpa/=1e-4; float kk=fbm(32.*pos); - nor.x+=bumpa*(fbm(32.*vec3(pos.x+kke,pos.yz))-kk); - nor.y+=bumpa*(fbm(32.*vec3(pos.x,pos.y+kke,pos.z))-kk); - nor.z+=bumpa*(fbm(32.*vec3(pos.xy,pos.z+kke))-kk); + nor.x+=bumpa*(fbm(32.*vec3(pos.x+1e-4,pos.yz))-kk); + nor.y+=bumpa*(fbm(32.*vec3(pos.x,pos.y+1e-4,pos.z))-kk); + nor.z+=bumpa*(fbm(32.*vec3(pos.xy,pos.z+1e-4))-kk); nor=normalize(nor); float spe=0.; vec3 lig=vec3(.5-pos.x,.8-pos.y,1.5-pos.z); diff --git a/tests/real/sult.expected b/tests/real/sult.expected index 7b60002f..2cba9407 100644 --- a/tests/real/sult.expected +++ b/tests/real/sult.expected @@ -5,47 +5,44 @@ # define VAR_time "m" const char *sult_frag = - "float v=5.,z=.9,x=0.,a=90.,y=0.;" - "vec3 d=vec3(1),n=vec3(0,0,1),s=vec3(0,0,1.5);" + "vec3 y=vec3(1),v=vec3(0,0,1),x=vec3(0,0,1.5);" "uniform vec2 r;" "uniform float m;" - "vec3 rotatey(vec3 v,float d)" + "vec3 rotatey(vec3 v,float y)" "{" - "return vec3(v.x*cos(d)+v.z*sin(d),v.y,v.z*cos(d)-v.x*sin(d));" + "return vec3(v.x*cos(y)+v.z*sin(y),v.y,v.z*cos(y)-v.x*sin(y));" "}" - "float f=0.,k=10.;" - "float e(vec3 d)" + "float f=0.;" + "float n(vec3 v)" "{" - "float y=m,k,a=0.,c,w,C;" + "float y=m,k,s=0.;" "vec3 r;" - "d+=(sin(d.zxy*1.7+y)+sin(d.yzx+y*3.))*.2;" - "a=v<6.?" - "length(d.xyz*vec3(1,1,.1)-vec3(0,-.1,y*.15-.3))-.34:" - "length(d.xy+vec2(0,.7))-.3+(sin(d.z*17.+y*.6)+sin(d.z*2.)*6.)*.01;" - "d.xy=vec2(atan(d.x,d.y)*1.113,1.6-length(d.xy)-sin(y*2.)*.3);" - "r=fract(d.xzz+.5).xyz-.5;" - "r.y=(d.y-.35)*1.3;" - "k=max(abs(d.y-.3)-.05,abs(length(fract(d.xz)-.5)-.4)-.03);" - "f=step(a,k);" - "return min(min(k,a),d.y-.2);" + "v+=(sin(v.zxy*1.7+y)+sin(v.yzx+y*3.))*.2;" + "s=length(v.xyz*vec3(1,1,.1)-vec3(0,-.1,y*.15-.3))-.34;" + "v.xy=vec2(atan(v.x,v.y)*1.113,1.6-length(v.xy)-sin(y*2.)*.3);" + "r=fract(v.xzz+.5).xyz-.5;" + "r.y=(v.y-.35)*1.3;" + "k=max(abs(v.y-.3)-.05,abs(length(fract(v.xz)-.5)-.4)-.03);" + "f=step(s,k);" + "return min(min(k,s),v.y-.2);" "}" - "vec3 diffdark=vec3(.19,.2,.24),w=vec3(1),C=vec3(.45,.01,0),c=vec3(.17,0,0);" + "vec3 diffdark=vec3(.19,.2,.24),k=vec3(1),z=vec3(.45,.01,0),s=vec3(.17,0,0);" "void main()" "{" - "vec2 l=-1.+2.*gl_FragCoord.xy/r.xy;" - "vec3 F=normalize(rotatey(rotatey(vec3(l.y*z,l.x*z*1.33,1),-x*.035).yxz,(a+y*m)*.035)),J=n+s*m;" - "float u=1.,H=0.,g,E,D=0.,B,p,A,G;" - "vec3 I=vec3(.01,0,0),K=I.yyy,L;" + "vec2 d=-1.+2.*gl_FragCoord.xy/r.xy;" + "vec3 a=normalize(rotatey(rotatey(vec3(d.y*.9,d.x*.9*1.33,1),0.).yxz,(90.+0.*m)*.035)),c=v+x*m;" + "float u=1.,l=0.,g,w,C=0.,F,p,H,G;" + "vec3 E=vec3(.01,0,0),D=E.yyy,B;" "for(;u>.1;)" "{" - "for(g=D,E=1.;g.005;g+=E)" - "E=e(J+F*g);" - "if(g.005;g+=w)" + "w=n(c+a*g);" + "if(g<10.)" + "c+=a*g,F=n(c),H=f,B=normalize(-vec3(F-n(c+E.xyy),F-n(c+E.yxy),F-n(c+E.yyx))),p=clamp(n(c+B*.05)*4.+n(c+B*.1)*2.+.5,.1,1.),l=H*.3,B=normalize(B+step(4.,5.)*f*sin(c.yzx*40.)*.05),a=reflect(a,B),G=clamp(dot(normalize(y),B),0.,1.),B=mix(mix(diffdark,k,G),z*(G+.2),H)+vec3(.7*pow(clamp(dot(normalize(y),a),0.,1.),12.)),D+=u*mix(B*p,s,g/10.),u*=l*(1.-g/10.),C=.1;" "else" - " K+=u*c,u=0.;" + " D+=u*s,u=0.;" "}" - "gl_FragColor.xyz=K;" + "gl_FragColor.xyz=D;" "gl_FragColor.w=1.;" "}"; diff --git a/tests/real/the_real_party_is_in_your_pocket.frag.expected b/tests/real/the_real_party_is_in_your_pocket.frag.expected index 23eb200a..54c6f3be 100644 --- a/tests/real/the_real_party_is_in_your_pocket.frag.expected +++ b/tests/real/the_real_party_is_in_your_pocket.frag.expected @@ -79,20 +79,19 @@ const char *the_real_party_is_in_your_pocket_frag = "float m(vec3 y,float x,float l,float z,bool a)" "{" "vec3 f=y;" - "float i=.69;" "f.xy-=vec2(.29,-.745);" - "f.xy=m(i)*f.xy;" - "vec2 n=vec2(.04,.05),s=f.xy;" + "f.xy=m(.69)*f.xy;" + "vec2 n=vec2(.04,.05),i=f.xy;" "f.xy=mod(f.xy,n)-n/2.;" "float r=v(vec2(length(f.xy),f.z),vec2(l,x))-z;" - "r=max(r,abs(s.y-.05)-(a?" + "r=max(r,abs(i.y-.05)-(a?" ".3:" ".15));" "if(a)" - "r=max(r,abs(s.x-.04)-.13);" - "s.xy=m(-i)*s.xy;" - "r=max(r,abs(s.x-.12+n.x)-.125);" - "r=max(r,abs(s.y-s.x*.2+.015+(a?" + "r=max(r,abs(i.x-.04)-.13);" + "i.xy=m(-.69)*i.xy;" + "r=max(r,abs(i.x-.12+n.x)-.125);" + "r=max(r,abs(i.y-i.x*.2+.015+(a?" "-.03:" "0.))-.1265);" "return r;" @@ -112,19 +111,19 @@ const char *the_real_party_is_in_your_pocket_frag = "y.xz=y.xz*m(-.5*l);" "vec2 f=y.xy;" "f.x=abs(f.x);" - "float a=m(m(f.x-.55,length(f-vec2(0,.8))-1.76,49.),f.y-.95,83.2),z=y.z-.14,s=-y.z-.09-(1.-x(.9,y.y+.3+.1)-x(.55,-y.y-.3-.17))*.17,i=m(m(f.x-.48,length(f-vec2(0,2.5))-2.5,117.),f.y-.87,80.);" + "float a=m(m(f.x-.55,length(f-vec2(0,.8))-1.76,49.),f.y-.95,83.2),z=y.z-.14,r=-y.z-.09-(1.-x(.9,y.y+.3+.1)-x(.55,-y.y-.3-.17))*.17,i=m(m(f.x-.48,length(f-vec2(0,2.5))-2.5,117.),f.y-.87,80.);" "if(y.z>.01)" "z+=mix(.02,pow(max(0.,v(y.xy-vec2(0,.25+pow(abs(y.x),3.)),vec2(.32,.94))-.05)*1e2,1.3)/1500.,1.-x(-.001,i));" "if(y.z<0.)" - "s=v(s,m(y-vec3(0,0,-.1),vec3(.5,.5,.055))-.04,64.);" + "r=v(r,m(y-vec3(0,0,-.1),vec3(.5,.5,.055))-.04,64.);" "f.x-=.09;" "f.y+=.635;" "a=m(a,z,192.);" - "float r=a,c=.001+v(length(f)-.01,v(length(f-vec2(.036,0))-.01,length(f-vec2(-.036,0))-.01,40.),40.);" + "float s=a,c=.001+v(length(f)-.01,v(length(f-vec2(.036,0))-.01,length(f-vec2(-.036,0))-.01,40.),40.);" "a=m(a,-y.z-.09,64.);" "if(y.z<0.)" - "a=v(a,m(r+.03,s,64.),256.);" - "r=1.;" + "a=v(a,m(s+.03,r,64.),256.);" + "s=1.;" "a=m(m(a,min(y.z,-c+.003),256.),min(y.z,-abs(i)-.001),448.);" "a=m(a,min(y.z-.13,-v(y.xy-vec2(0,-.118))),512.);" "a=m(a,min(y.z-.13,-abs(length(vec2(max(abs(y.x)-.12,0.),y.y+.117))-.035)+.003),512.);" @@ -166,18 +165,18 @@ const char *the_real_party_is_in_your_pocket_frag = "f.x-=clamp(f.x,-2.,0.);" "t=m(t,-max(-h.z,-length(f)*sign(f.y)+.565),512.);" "if(t0.&&h.x0.&&h.xh.y||abs(e)<1e-5)" "break;" @@ -217,7 +215,7 @@ const char *the_real_party_is_in_your_pocket_frag = "}" "if(d0.&&c.x<0.&&c.y<0.)" - "a=vec3(-c*.5,0).zxy,m=i.y;" - "else if(r>0.&&(r0.&&c.x<0.&&c.y<0.)" + "a=vec3(-c*.5,0).zxy,m=h.y;" "else if(d>0.&&(d0.&&(r5.||abs(w.y)>2.5||abs(w.z)>3.3?" "vec4(-1):" @@ -248,156 +246,156 @@ const char *the_real_party_is_in_your_pocket_frag = "vec3 h(vec3 y,vec3 v)" "{" "vec3 a=vec3(0),f=vec3(1);" - "bool l=false;" - "for(int i=0;i<4;++i)" + "bool i=false;" + "for(int r=0;r<4;++r)" "{" "v=normalize(v);" - "vec3 z,c,e;" - "vec4 r=s(y,v,z);" - "float d=r.x;" + "vec3 l;" + "vec4 h=s(y,v,l);" + "float d=h.x;" "if(d<0.)" "{" "a+=max(f*vec3(.9)*(.5+.5*dot(v,normalize(vec3(-2,4,1))))*.4*1.3*vec3(1,.9,.65)+f*vec3(.9)*step(.9,dot(v,normalize(vec3(6,2,1))))*10.4*2.3+f*vec3(.9)*step(.95,dot(v,normalize(vec3(-2,1,3))))*10.4*1.5,0.)*pow(max(.5+.5*-v.z,0.),.2);" "break;" "}" - "float w=floor(r.y/8.);" - "r.y=mod(r.y,8.);" - "vec3 h=y+v*d;" + "float w=floor(h.y/8.);" + "h.y=mod(h.y,8.);" + "vec3 c=y+v*d;" "vec2 p=vec2(6.28319*m(),m()*2.-1.);" - "vec3 k=z+vec3(sqrt(1.-p.y*p.y)*vec2(cos(p.x),sin(p.x)),p.y);" - "float t=r.y>1.5?" - "mix(h.x>0.?" + "vec3 k=l+vec3(sqrt(1.-p.y*p.y)*vec2(cos(p.x),sin(p.x)),p.y);" + "float z=h.y>1.5?" + "mix(c.x>0.?" ".1:" - ".05,.5,pow(1.-clamp(dot(-v,z),0.,1.),2.)):" - "mix(.2,.8,pow(1.-clamp(dot(-v,z),0.,1.),1.5));" - "if(r.y>5.5&&r.y<6.5)" + ".05,.5,pow(1.-clamp(dot(-v,l),0.,1.),2.)):" + "mix(.2,.8,pow(1.-clamp(dot(-v,l),0.,1.),1.5));" + "if(h.y>5.5&&h.y<6.5)" "{" - "if(l)" + "if(i)" "break;" - "y=h+z*2e-4;" - "f*=mix(.1,.8,pow(1.-clamp(dot(-v,z),0.,1.),3.))*mix(vec3(1),vec3(1,.9,.5),.5);" - "v=reflect(v,z)+(vec3(m(),m(),m())-.5)*.3;" + "y=c+l*2e-4;" + "f*=mix(.1,.8,pow(1.-clamp(dot(-v,l),0.,1.),3.))*mix(vec3(1),vec3(1,.9,.5),.5);" + "v=reflect(v,l)+(vec3(m(),m(),m())-.5)*.3;" "}" - "else if(r.y>4.5&&r.y<5.5)" + "else if(h.y>4.5&&h.y<5.5)" "{" - "if(l)" + "if(i)" "break;" - "t=.02;" - "if(m()>t)" - "y=h-z*2e-4*-sign(v.z),v+=(vec3(m(),m(),m())-.5)*.1;" + "z=.02;" + "if(m()>z)" + "y=c-l*2e-4*-sign(v.z),v+=(vec3(m(),m(),m())-.5)*.1;" "else" - " y=h+z*2e-4,v=reflect(v,z)+(vec3(m(),m(),m())-.5)*.3;" + " y=c+l*2e-4,v=reflect(v,l)+(vec3(m(),m(),m())-.5)*.3;" "}" - "else if(r.y<.5||r.y>2.5)" + "else if(h.y<.5||h.y>2.5)" "{" - "vec3 b=r.y>2.5?" + "vec3 t=h.y>2.5?" "vec3(.08):" "vec3(.7);" - "if(r.y>3.5)" + "if(h.y>3.5)" "{" - "b=vec3(.008);" - "if(!l)" + "t=vec3(.008);" + "if(!i)" "{" - "if(h.y>.5)" + "if(c.y>.5)" "{" - "vec2 o=r.zw-vec2(-.38,.6);" - "float g=min(min(min(min(min(min(max(length(o-vec2(.005))-.0125,-length(o-vec2(-.012,.005))+.025),max(length(o-vec2(-.02,.005))-.0125,-length(o-vec2(-.045,.005))+.03)),max(length(o-vec2(.005))-.0125,-length(o-vec2(-.012,.005))+.025)),max(length(o-vec2(.03,.005))-.0125,-length(o-vec2(.02,.005))+.02)),abs(length(o-vec2(-.037,-.0398))-.0104)),n(o,vec2(-.064,-.05),vec2(-.064,-.03))),max(-o.x-.063,abs(length(vec2(max(0.,o.x+.06),o.y+.035))-.006)));" - "o.x-=.091;" - "g=min(g,n(o,vec2(-.064,-.05),vec2(-.064,-.03)));" - "g=min(g,max(-o.x-.063,abs(length(vec2(max(0.,o.x+.06),o.y+.035))-.006)));" - "g=min(g,n(o,vec2(-.054,-.05),vec2(-.059,-.041)));" - "o.x+=.091;" - "g=min(g,n(o,vec2(.009,-.05),vec2(.009,-.03)));" - "g=min(g,n(o,vec2(.009,-.05),vec2(.018,-.05)));" - "g=min(g,n(o,vec2(.009,-.03),vec2(.018,-.03)));" - "g=min(g,n(o,vec2(.009,-.039),vec2(.018,-.039)));" - "o.x=abs(o.x+.01);" - "o.x=abs(o.x-.006);" - "g=min(g,n(o,vec2(0,-.05),vec2(.006,-.03)));" - "b=mix(b,vec3(.3),step(g-.0018,0.));" + "vec2 e=h.zw-vec2(-.38,.6);" + "float b=min(min(min(min(min(min(max(length(e-vec2(.005))-.0125,-length(e-vec2(-.012,.005))+.025),max(length(e-vec2(-.02,.005))-.0125,-length(e-vec2(-.045,.005))+.03)),max(length(e-vec2(.005))-.0125,-length(e-vec2(-.012,.005))+.025)),max(length(e-vec2(.03,.005))-.0125,-length(e-vec2(.02,.005))+.02)),abs(length(e-vec2(-.037,-.0398))-.0104)),n(e,vec2(-.064,-.05),vec2(-.064,-.03))),max(-e.x-.063,abs(length(vec2(max(0.,e.x+.06),e.y+.035))-.006)));" + "e.x-=.091;" + "b=min(b,n(e,vec2(-.064,-.05),vec2(-.064,-.03)));" + "b=min(b,max(-e.x-.063,abs(length(vec2(max(0.,e.x+.06),e.y+.035))-.006)));" + "b=min(b,n(e,vec2(-.054,-.05),vec2(-.059,-.041)));" + "e.x+=.091;" + "b=min(b,n(e,vec2(.009,-.05),vec2(.009,-.03)));" + "b=min(b,n(e,vec2(.009,-.05),vec2(.018,-.05)));" + "b=min(b,n(e,vec2(.009,-.03),vec2(.018,-.03)));" + "b=min(b,n(e,vec2(.009,-.039),vec2(.018,-.039)));" + "e.x=abs(e.x+.01);" + "e.x=abs(e.x-.006);" + "b=min(b,n(e,vec2(0,-.05),vec2(.006,-.03)));" + "t=mix(t,vec3(.3),step(b-.0018,0.));" "}" - "if(length(r.zw-vec2(-.43,.605))<.014)" - "a+=f*3.*vec3(1,.01,.01)*(.8+8.*(1.-x(.01,length(r.zw-vec2(-.43,.605)))));" - "if(r.w>0.&&h.y<.2)" + "if(length(h.zw-vec2(-.43,.605))<.014)" + "a+=f*3.*vec3(1,.01,.01)*(.8+8.*(1.-x(.01,length(h.zw-vec2(-.43,.605)))));" + "if(h.w>0.&&c.y<.2)" "{" - "b=mix(b,vec3(.3),step(n(r.zw-vec2(0,.103)),0.));" + "t=mix(t,vec3(.3),step(n(h.zw-vec2(0,.103)),0.));" "{" - "vec2 o=vec2(-.09,.03),g=vec2(-.1,0);" - "b=mix(b,vec3(.520661,.00153787,.064975),step(min(m(r.zw-vec2(.16,.103),g,g+normalize(g-o)*.03,vec2(-.065,-.026)),m(r.zw-vec2(.16,.103),vec2(-.07,.02),o,g))-.007,0.));" + "vec2 e=vec2(-.09,.03),b=vec2(-.1,0);" + "t=mix(t,vec3(.520661,.00153787,.064975),step(min(m(h.zw-vec2(.16,.103),b,b+normalize(b-e)*.03,vec2(-.065,-.026)),m(h.zw-vec2(.16,.103),vec2(-.07,.02),e,b))-.007,0.));" "}" "{" - "vec2 o=r.zw-vec2(.16,.103);" - "o-=vec2(-.029,-.015);" - "o.x+=cos(o.y*30.)*.01;" - "o.y-=cos(o.x*20.)*.01;" - "b=mix(b,vec3(.093564,.0865052,.434048),step(abs(length(o)-.02)-.007,0.));" + "vec2 e=h.zw-vec2(.16,.103);" + "e-=vec2(-.029,-.015);" + "e.x+=cos(e.y*30.)*.01;" + "e.y-=cos(e.x*20.)*.01;" + "t=mix(t,vec3(.093564,.0865052,.434048),step(abs(length(e)-.02)-.007,0.));" "}" "{" - "vec2 o=r.zw-vec2(.16,.103),g=vec2(-.007,0),C=vec2(-.007,-.0205);" - "b=mix(b,vec3(.186082,.481799,.0177778),step(min(m(o,C,C+normalize(C-g)*.01,vec2(.02,-.02)),m(o,vec2(-.01,.02),g,C))-.007,0.));" + "vec2 e=h.zw-vec2(.16,.103),b=vec2(-.007,0),o=vec2(-.007,-.0205);" + "t=mix(t,vec3(.186082,.481799,.0177778),step(min(m(e,o,o+normalize(o-b)*.01,vec2(.02,-.02)),m(e,vec2(-.01,.02),b,o))-.007,0.));" "}" "{" - "vec2 o=r.zw-vec2(.16,.103);" - "o-=vec2(.045,-.015);" - "o.x+=cos(o.y*20.+1.)*.005;" - "o.y-=cos(o.x*20.+25.)*.01;" - "b=mix(b,vec3(.730857,.454964,.000553633),step(abs(length(o)-.02)-.007,0.));" + "vec2 e=h.zw-vec2(.16,.103);" + "e-=vec2(.045,-.015);" + "e.x+=cos(e.y*20.+1.)*.005;" + "e.y-=cos(e.x*20.+25.)*.01;" + "t=mix(t,vec3(.730857,.454964,.000553633),step(abs(length(e)-.02)-.007,0.));" "}" "{" - "vec2 o=r.zw-vec2(.24,.103),g=vec2(-.002,0),C=vec2(-.007,.016),D=C+normalize(C-g)*.012,B=vec2(.02),A=vec2(.002,-.007),E=vec2(.025,-.028);" - "b=mix(b,vec3(0,.332318,.292872),step(min(min(min(m(o,C,D,B),m(o,vec2(-.006,-.026),g,C)),m(o,B,D+normalize(B-D)*.05,A)),m(o,A,(A+E)/2.+vec2(.001),E))-.007,0.));" + "vec2 e=h.zw-vec2(.24,.103),b=vec2(-.002,0),o=vec2(-.007,.016),C=o+normalize(o-b)*.012,g=vec2(.02),D=vec2(.002,-.007),B=vec2(.025,-.028);" + "t=mix(t,vec3(0,.332318,.292872),step(min(min(min(m(e,o,C,g),m(e,vec2(-.006,-.026),b,o)),m(e,g,C+normalize(g-C)*.05,D)),m(e,D,(D+B)/2.+vec2(.001),B))-.007,0.));" "}" "}" "{" - "vec2 o=vec2(160,144)/1.5,g=(r.zw-vec2(-.001,.486))*3.75*vec2(o.y/o.x,1)*.5+.5,C=fract(g*o);" - "g=floor(g*o)/o;" - "if(max(abs(g.x-.5),abs(g.y-.5))<.5)" + "vec2 e=vec2(160,144)/1.5,b=(h.zw-vec2(-.001,.486))*3.75*vec2(e.y/e.x,1)*.5+.5,o=fract(b*e);" + "b=floor(b*e)/e;" + "if(max(abs(b.x-.5),abs(b.y-.5))<.5)" "{" - "vec3 D=vec3(0);" - "vec2 B=(g*2.-1.)*vec2(o.x/o.y,1);" - "float A=min(min(min(min(min(min(min(min(min(min(min(min(min(min(min(min(min(n(vec4(1.54,.53,.91,.72),B),n(vec4(.63,.78,.91,.72),B)),n(vec4(.61,1.675,.72,.64),B)),n(vec4(2.7,3.11,.72,.64),B)),n(vec4(3.45,3.65,.72,.64),B)),n(vec4(4.71,5.02,.72,.64),B)),n(vec4(5.3,5.51,.72,.64),B)),n(vec4(5.96,6.43,.72,.64),B)),n(vec4(3.2,1.27,.45,.35),B)),n(vec4(1.3,2.3,.45,.35),B)),n(vec4(2.58,4.2,.45,.35),B)),n(vec4(3.2,3.95,.35,.25),B)),n(vec4(5.2,5.93,.35,.25),B)),n(vec4(7.9,8.15,.35,.25),B)),n(vec4(.2,1.16,.32,.17),B)),max(length(B)-.84,-length(B)+.72)),max(length(B)-.52,-length(B)+.45)),max(length(B)-.17,-length(B)+.08)),E=floor(g.y*8.);" - "D=.5+.5*cos(vec3(.8,.3,2)*(E+1.));" - "D=mix(D,vec3(1),step(A,0.));" - "D*=vec3(1,1,.8);" - "D*=smoothstep(.1,.2,C.x)*smoothstep(.1,.2,C.y);" - "a+=f*3.*D;" - "b=vec3(.1);" + "vec3 C=vec3(0);" + "vec2 g=(b*2.-1.)*vec2(e.x/e.y,1);" + "float D=min(min(min(min(min(min(min(min(min(min(min(min(min(min(min(min(min(n(vec4(1.54,.53,.91,.72),g),n(vec4(.63,.78,.91,.72),g)),n(vec4(.61,1.675,.72,.64),g)),n(vec4(2.7,3.11,.72,.64),g)),n(vec4(3.45,3.65,.72,.64),g)),n(vec4(4.71,5.02,.72,.64),g)),n(vec4(5.3,5.51,.72,.64),g)),n(vec4(5.96,6.43,.72,.64),g)),n(vec4(3.2,1.27,.45,.35),g)),n(vec4(1.3,2.3,.45,.35),g)),n(vec4(2.58,4.2,.45,.35),g)),n(vec4(3.2,3.95,.35,.25),g)),n(vec4(5.2,5.93,.35,.25),g)),n(vec4(7.9,8.15,.35,.25),g)),n(vec4(.2,1.16,.32,.17),g)),max(length(g)-.84,-length(g)+.72)),max(length(g)-.52,-length(g)+.45)),max(length(g)-.17,-length(g)+.08)),B=floor(b.y*8.);" + "C=.5+.5*cos(vec3(.8,.3,2)*(B+1.));" + "C=mix(C,vec3(1),step(D,0.));" + "C*=vec3(1,1,.8);" + "C*=smoothstep(.1,.2,o.x)*smoothstep(.1,.2,o.y);" + "a+=f*3.*C;" + "t=vec3(.1);" "}" "}" "}" "}" - "if(r.y>3.&&r.y<3.2)" - "b=vec3(.4);" - "f*=b;" - "y=h+z*2e-4;" + "if(h.y>3.&&h.y<3.2)" + "t=vec3(.4);" + "f*=t;" + "y=c+l*2e-4;" "v=k;" - "l=true;" + "i=true;" "}" "else" "{" - "vec3 o=w>1.5?" + "vec3 e=w>1.5?" "vec3(1,.02,.2):" "w>.5?" "vec3(.2,1,.02):" "vec3(.02,.2,1);" - "if(m()>mix(.2,1.,t))" + "if(m()>mix(.2,1.,z))" "{" - "if(r.y>1.5)" - "o=vec3(.02);" - "f*=o;" - "y=h+z*2e-4;" + "if(h.y>1.5)" + "e=vec3(.02);" + "f*=e;" + "y=c+l*2e-4;" "v=k;" - "l=true;" + "i=true;" "}" "else" "{" - "if(l)" + "if(i)" "break;" - "f*=r.y>1.5?" + "f*=h.y>1.5?" "vec3(.5):" - ".9*mix(o,vec3(1),.25);" - "y=h+z*2e-4;" - "v=reflect(v,z)+(vec3(m(),m(),m())-.5)*.4;" + ".9*mix(e,vec3(1),.25);" + "y=c+l*2e-4;" + "v=reflect(v,l)+(vec3(m(),m(),m())-.5)*.4;" "}" "}" "if(max(f.x,max(f.y,f.z))<.001)" @@ -411,11 +409,11 @@ const char *the_real_party_is_in_your_pocket_frag = "for(int a=0;a<16;++a)" "{" "y=float(a)+gl_TexCoord[0].x*16.;" - "float l=m()*6.28319;" - "vec2 o=vec2(cos(l),sin(l))*sqrt(1.-sqrt(1.-m()))*1.2;" + "float e=m()*6.28319;" + "vec2 l=vec2(cos(e),sin(e))*sqrt(1.-sqrt(1.-m()))*1.2;" "if(int(y)%4==0)" - "o*=15.*length(o);" - "v+=h(vec3(0,0,4.8),vec3((gl_FragCoord.xy-vec2(960,540)+o)/540.,-3.5))/48.;" + "l*=15.*length(l);" + "v+=h(vec3(0,0,4.8),vec3((gl_FragCoord.xy-vec2(960,540)+l)/540.,-3.5))/48.;" "}" "v/=(v+1.)/2.;" "gl_FragColor.xyz=pow(v+.01*vec3(1,1,.5),vec3(1./2.2))+m()/1e2;" diff --git a/tests/unit/array.frag.expected b/tests/unit/array.frag.expected index 5b394110..b800cd67 100644 --- a/tests/unit/array.frag.expected +++ b/tests/unit/array.frag.expected @@ -7,11 +7,7 @@ const char *array_frag = "float a[5]=float[5](3.4,4.2,5.,5.2,1.1);" "float b[5]=float[5](3.4,4.2,5.,5.2,1.1),c[]=float[](3.4,4.2,5.,5.2,1.1),d[5]=float[](3.4,4.2,5.,5.2,1.1),e[]=float[5](3.4,4.2,5.,5.2,1.1);" "void arrayTypes()" - "{" - "vec4 a[3];" - "vec4[2] b[3];" - "vec4[3] c;" - "}" + "{}" "float[2] func_bank(float[2] res)" "{" "float a=res[0],b=res[1];" diff --git a/tests/unit/blocks.expected b/tests/unit/blocks.expected index 35eebd40..74917df6 100644 --- a/tests/unit/blocks.expected +++ b/tests/unit/blocks.expected @@ -48,13 +48,9 @@ const char *blocks_frag = "}" "float removeUselessElseAfterReturn2(float f)" "{" - "float a=2.;" - "if(f2.*f? + return x>246913578.? 1e2: - x>f? + x>123456789.? 101.: 102.; } @@ -35,15 +33,13 @@ void notevil(float x) } float inl7() { - float f=101.; - notevil(f); - return f; + notevil(101.); + return 101.; } int inl8(ivec3 x) { - int i=1; - x[i]+=1; - return x[i]+i; + x[1]+=1; + return x[1]+1; } float noinl1() { @@ -88,10 +84,9 @@ float noinl7(const float x) { return x+1.2; } -float quux=1.; float noinl8() { - return quux+2.; + return 3.; } float noinl9(float x) { diff --git a/tests/unit/inline-fn.aggro.expected b/tests/unit/inline-fn.aggro.expected index fbf19064..ab993a3d 100644 --- a/tests/unit/inline-fn.aggro.expected +++ b/tests/unit/inline-fn.aggro.expected @@ -29,11 +29,6 @@ float notShadowedFunc(inout float notinlinable) notinlinable=2.; return-2.; } -float shadowedVar=0.,notShadowedVar=1.; -float A1() -{ - return shadowedVar; -} float A3() { float a=10.; @@ -84,7 +79,7 @@ float G1(float g1,float g2) } float f() { - float shadowedVar=-1.,shadowedFunc=-2.,_A1=A1(),_A3=A3(),_A4=notShadowedFunc(globalFloat); + float shadowedVar=-1.,shadowedFunc=-2.,_A3=A3(),_A4=notShadowedFunc(globalFloat); int sep; float _B1=B1()+B1(); sep++; @@ -98,7 +93,7 @@ float f() sep++; shadowedVar++; shadowedFunc++; - return shadowedVar+shadowedFunc+_A1+notShadowedVar+_A3+_A4+_B1+4.+_C1+(3.+sin(0.))+_D1+9.+_E1+_E2+_E3+_E4+_E5+7.+_F2+_F3; + return shadowedVar+shadowedFunc+1.+_A3+_A4+_B1+4.+_C1+(3.+sin(0.))+_D1+9.+_E1+_E2+_E3+_E4+_E5+7.+_F2+_F3; } float g() { diff --git a/tests/unit/inline-fn.expected b/tests/unit/inline-fn.expected index a760ea43..ab993a3d 100644 --- a/tests/unit/inline-fn.expected +++ b/tests/unit/inline-fn.expected @@ -12,8 +12,7 @@ float c() } float d() { - float f=7.; - return f*f+1.+4.; + return 54.; } float e() { @@ -30,11 +29,6 @@ float notShadowedFunc(inout float notinlinable) notinlinable=2.; return-2.; } -float shadowedVar=0.,notShadowedVar=1.; -float A1() -{ - return shadowedVar; -} float A3() { float a=10.; @@ -85,7 +79,7 @@ float G1(float g1,float g2) } float f() { - float shadowedVar=-1.,shadowedFunc=-2.,_A1=A1(),_A3=A3(),_A4=notShadowedFunc(globalFloat); + float shadowedVar=-1.,shadowedFunc=-2.,_A3=A3(),_A4=notShadowedFunc(globalFloat); int sep; float _B1=B1()+B1(); sep++; @@ -99,7 +93,7 @@ float f() sep++; shadowedVar++; shadowedFunc++; - return shadowedVar+shadowedFunc+_A1+notShadowedVar+_A3+_A4+_B1+4.+_C1+(3.+sin(0.))+_D1+9.+_E1+_E2+_E3+_E4+_E5+7.+_F2+_F3; + return shadowedVar+shadowedFunc+1.+_A3+_A4+_B1+4.+_C1+(3.+sin(0.))+_D1+9.+_E1+_E2+_E3+_E4+_E5+7.+_F2+_F3; } float g() { diff --git a/tests/unit/inline.aggro.expected b/tests/unit/inline.aggro.expected index e7a03867..ed0339da 100644 --- a/tests/unit/inline.aggro.expected +++ b/tests/unit/inline.aggro.expected @@ -60,3 +60,9 @@ int dependOnConst() { return(time+sync)*2*3; } +float noinl179(float x) +{ + float old=x; + x=1e2; + return old+x; +} diff --git a/tests/unit/inline.expected b/tests/unit/inline.expected index e8920acc..ed0339da 100644 --- a/tests/unit/inline.expected +++ b/tests/unit/inline.expected @@ -3,8 +3,7 @@ float result; void main() { - float x=.5; - result=.6*x*x; + result=.15; } int arithmetic() { @@ -16,8 +15,7 @@ int vars(int arg,int arg2) } int arithmetic2() { - int a=2; - return 4*a*(a+3); + return 40; } int unusedVars() { @@ -62,3 +60,9 @@ int dependOnConst() { return(time+sync)*2*3; } +float noinl179(float x) +{ + float old=x; + x=1e2; + return old+x; +} diff --git a/tests/unit/inline.frag b/tests/unit/inline.frag index 45fa2940..f71cd04b 100644 --- a/tests/unit/inline.frag +++ b/tests/unit/inline.frag @@ -96,4 +96,11 @@ int dependOnConst() { int x = time + sync; int y = x * 2; return y*3; -} \ No newline at end of file +} + +// repro for #179 +float noinl179(float x) { + float old = x; + x = 100.0; + return old + x; +} diff --git a/tests/unit/inline.no.expected b/tests/unit/inline.no.expected index c57ca8a0..3e5b7af1 100644 --- a/tests/unit/inline.no.expected +++ b/tests/unit/inline.no.expected @@ -46,9 +46,10 @@ int dont_inline_lvalue() return 3; } vec4 fragColor247; +const float t247=3.; void main247() { - fragColor247=vec4(3); + fragColor247=vec4(t247); } vec4 fragColor248; void main248() @@ -69,3 +70,9 @@ int dependOnConst() int x=time+sync,y=x*2; return y*3; } +float noinl179(float x) +{ + float old=x; + x=1e2; + return old+x; +} diff --git a/tests/unit/switch.expected b/tests/unit/switch.expected index 1043474e..633521f7 100644 --- a/tests/unit/switch.expected +++ b/tests/unit/switch.expected @@ -33,12 +33,12 @@ float D() { switch(42){ case 42: - float G=4.2; - float k=2.4; - return G+k; + + + return 6.6; case 43: - float D=4.3; - return D+3.4; + + return 7.7; default: return 0.; }