Shader_Minifier
Shader_Minifier copied to clipboard
Various mathematical transformations
trafficstars
Generally an improvement:
- [ ]
cross(-a,b)orcross(a,-b)or-cross(a,b)->cross(b,a)(related issue: sign cancellation) - [ ] Left vs right multiplication:
transpose(mat)*vec->vec*matvec*transpose(mat)->mat*vec - [ ]
transpose(a)*transpose(b)->transpose(b*a) - [x]
distance(a,b)->length(a-b)(completed in 40dae3c)
Only if there's a flag to turn it off (otherwise could hurt compression):
- [ ]
sqrt(dot(a,a))->length(a) - [ ] min/max simplification (related issue: sign cancellation)
min(-a,-b)->-max(a,b)-max(a,-b)->min(-a,b)and so-forth. - [ ] Common cross-product expansions:
cross(vec3(1,0,0),a)->vec3(0,-a.z,a.y)cross(vec3(0,1,0),a)->vec3(a.z,0,-a.x)cross(vec3(0,0,1),a)->vec3(-a.y,a.x,0)( perhaps generalized tocross(vec3(d,0,0),a)->d*vec3(0,-a.z,a.y)etc. (whendis known to be scalar type), though this doesn't seem common )
Expected impact on precision: none, driver shader compilers typically perform similar transformations anyway.