-
Notifications
You must be signed in to change notification settings - Fork 11
WebGL to DCTL
This article is mainly based on @J-i-P-i's excellent WSL post "Convert a Shadertoy WebGL Code to DCTL" which is the main basis and origin for this whole repository.
Before converting a Shadertoy you should have a look if the code contains something yet not possible to convert:
- dFdx / dFdy
- texelfetch
For other challenges there might be workarounds, but you should check the impact on the resulting image beforehand:
- for
textureLod
omittimg the LOD by using_tex2DVecN
might be sufficient - ...
Replace WebGL's vec2
, vec3
, vec4
types by DCTL's float2
, float3
, float4
. Note that for r-values you must use the corresponding to_float
-functions.
For example ...
vec3 v = vec3(.2,.4,1.3);
... translates to ...
float3 v = to_float3(0.2f,0.4f,1.3f);
One speciality with those vector types ist, that accessing multiple vector elements at ones (e.g. float2 c=coords.xy
) must be resolved to single element access (the example could be converted to float2 c = to_float2(coords.x,coords.y)
). See swizzling for further details and more examples.
DCTL provides a lot of substitutes like _sinf(float)
, _cosf(float)
for the common math functions sin(T)
, cos(T)
to avoid ambiguities in particular with single precision, and double precision floating point types, and overloaded functions.
replace | with |
---|---|
sin, cos, pow | _sinf, _cosf, _powf |
max, min | _fmaxf, _fminf |
abs, mod | _fabs, mod_f (Incompatibility) |
atan | _atan2f (possibly on _atan2f (var, 1.0f); expand) |
clamp, dot, step | no replacement needed |
mix | _mix |
See math.h for further details.