I ported chrisbrobs Dropshadow from C2 to C3, see example below. Also works with animation frames during runtime.
General C2->C3 effect porting notes.
- These notes mostly apply to effect distortions which modify the uv coordinates or sample the background not directly under the current pixel being rendered.
- The c2 uniforms pixelHeight and pixelWidth have been replaced by vec2 pixelSize.
- When converting, I remove the above uniforms and add 'float pixelWidth = pixelSize.x;' and 'float pixelHeight = pixelSize.y;' to the top of the new shader code.
- C3 textures are usually placed in sprite-sheets, while in at least preview mode, C2 used one sprite-sheet per texture, so the UV coordinates for a particular C3 texture/image do not range from 0-1, like they do in C2. Instead the entire C3 sprite-sheet a texture is included in ranges from 0-1 and particular C3 texture is packed within that range with other textures.
- To help with this, some new uniforms are added: srcStart, StartEnd srcOriginStart, srcOriginEnd.
- Read the below SDK docs to for more details on these uniforms, but generally, they show the start and end UV coordinates of the current texture within the overall sprite-sheet it's contained in.
- Be wary of converting hardcoded numbers like 0.0, 1.0, 0.5 which are meant to indicate the top of the texture, bottom of texture, middle of texture. If they are used to indicate these aspects of a texture, replace them with the new uniforms (or formulas using the new uniforms.)
- The normalize formula can help with converting 0-1 ranges in C2 to similar ranges in C3 for uv coordinates.
- For example to find the 0-1 range of the current UV, use: 'mediump vec2 n = (vTex - srcStart) / (srcEnd - srcStart)'
- An example conversion just required adding srcOriginStart, srcOriginEnd uniforms, converting vTex to a normalized value: mediump vec2 vTexN = (vTex-srcOriginStart)/(srcOriginEnd-srcOriginStart); , replacing vTex with vTexN in the rest of the code and 'denormalizing' when samping the foreground using srcOriginStart and srcOriginEnd: lowp vec4 front = texture2D(samplerFront, mix(srcOriginStart, srcOriginEnd, frontUV));
- Another example from Dropshadow, a parameter uniform 'Rescalefactor' was passed into the effect which indicated in the range from 0-1, when to start applying the Dropshadow on the sprite. However since the texture for the sprite was in a sprite-sheet, an absolute value is not appropriate, instead, the following formulas were used to calculate a normalized Rescalefactor based on the image's location in the sprite-sheet.
- 'float srcHeight = srcOriginEnd.y - srcOriginStart.y;', 'float normalizedRescalefactor = Rescalefactor*srcHeight+srcOriginStart.y;'
See uniforms and more hints for C3 in the SDK documentation: