Hello all!
I’m utilizing Cocos Creator model 3.8.6.
I want a shader that attracts the outer define of a sprite. It might be fascinating to put in writing it myself, however difficulties arose.
Since this shader attracts the outer contour, I want to organize sprites with a ample measurement prematurely and disable trimming within the editor.
Mainly, I solely have to cross two parameters to the shader:
- Shade
- Thickness
One thing like this:
properties:
outlineColor: { worth: [1.0, 1.0, 1.0, 1.0], editor: { sort: coloration } }
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't convert from 'const mediump float' to 'highp 4-component vector of float'
I don’t perceive how you can 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 might be carried out 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 means – add an offset to the present uv. However with the intention to do that, I have to know the texel measurement or not less than the feel measurement. I write:
ivec2 textureSize = textureSize(cc_spriteTexture, 0);
I obtain:
ERROR: 0:80: 'texture2DSize' : no matching overloaded operate discovered
ERROR: 0:80: '=' : can't 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: coloration } }
thickness: { worth: 1.0 }
...
uniform Fixed{
vec4 outlineColor;
vec2 textureSize;
float thickness;
};
I don’t like this. How can the state of affairs be improved?
One other query associated to atlases. In fact I wish to take my sprites and put them in an atlas. In fact, I can add an enormous empty house between the sprites. Or I can’t add it. However what I positively don’t need is to learn pixels of the neighboring sprite from the present sprite. Is it attainable to one way or the other trim texture coordinates within the shader in the event that they transcend the present sprite within the atlas? Properly, not less than one thing that can assist. Perhaps get the minimal and most uv. Any concepts?


