Hello all!
I’m utilizing Cocos Creator model 3.8.6.
I would like a shader that attracts the outer define of a sprite. It might be attention-grabbing to write down it myself, however difficulties arose.
Since this shader attracts the outer contour, I would like to arrange sprites with a ample dimension upfront and disable trimming within the editor.
Principally, I solely have to go two parameters to the shader:
- Shade
- Thickness
One thing like this:
properties:
outlineColor: { worth: [1.0, 1.0, 1.0, 1.0], editor: { sort: colour } }
thickness: { worth: 1.0 }
...
uniform Fixed{
vec4 outlineColor;
float thickness;
};
At first I attempted to make use of the textureOffset operate:
vec4 topColor = textureOffset(cc_spriteTexture, uv0, ivec2(0, 1));
However I obtained an error:
ERROR: 0:80: 'texture2DOffset' : no matching overloaded operate discovered
ERROR: 0:80: '=' : dimension mismatch
ERROR: 0:80: '=' : can not convert from 'const mediump float' to 'highp 4-component vector of float'
I don’t perceive learn how to convert. I borrowed the framework for the shader experiment from the built-in shader “builtin-sprite.impact”, which is situated in “3.8.6resourcesresources3dengineeditorassetseffectsfor2d”. What will be performed about this? I’m wondering what it writes about texture2DOffset, though I used textureOffset.
Since I don’t know the reply but, I made a decision to go one other manner – add an offset to the present uv. However so as to do that, I have to know the texel dimension or at the least the feel dimension. I write:
ivec2 textureSize = textureSize(cc_spriteTexture, 0);
I obtain:
ERROR: 0:80: 'texture2DSize' : no matching overloaded operate discovered
ERROR: 0:80: '=' : can not convert from 'const mediump float' to 'mediump 2-component vector of int'
I couldn’t consider something smarter than including the textureSize parameter:
properties:
textureSize: { worth: [0, 0], editor: { sort: vec2 } }
outlineColor: { worth: [1.0, 1.0, 1.0, 1.0], editor: { sort: colour } }
thickness: { worth: 1.0 }
...
uniform Fixed{
vec4 outlineColor;
vec2 textureSize;
float thickness;
};
I don’t like this. How can the scenario be improved?
One other query associated to atlases. After all I need to take my sprites and put them in an atlas. After all, I can add an enormous empty area between the sprites. Or I cannot add it. However what I undoubtedly don’t want is to learn pixels of the neighboring sprite from the present sprite. Is it potential to by some means trim texture coordinates within the shader in the event that they transcend the present sprite within the atlas? Effectively, at the least one thing that may assist. Possibly get the minimal and most uv. Any concepts?

