跳到主要内容

egret.web.EgretShaderLib

   egret.web

   public class EgretShaderLib

公共属性

属性
blur_frag : string
[静态]
colorTransform_frag : string
[静态]
colorTransform_frag_etc_alphamask_frag : string
[静态]"precision mediump float; varying vec2 vTextureCoord; varying vec4 vColor; uniform mat4 matrix; uniform vec4 colorAdd; uniform sampler2D uSampler; uniform sampler2D uSamplerAlphaMask; void main(void){ float alpha = texture2D(uSamplerAlphaMask, vTextureCoord).r; if (alpha < 0.0039) { discard; } vec4 texColor = texture2D(uSampler, vTextureCoord); if(texColor.a > 0.0) { // 抵消预乘的alpha通道 texColor = vec4(texColor.rgb / texColor.a, texColor.a); } vec4 v4Color = clamp(texColor matrix + colorAdd, 0.0, 1.0); v4Color.rgb = v4Color.rgb alpha; v4Color.a = alpha; gl_FragColor = v4Color * vColor; }"
default_vert : string
[静态]
glow_frag : string
[静态]
primitive_frag : string
[静态]
texture_etc_alphamask_frag : string
[静态]"precision lowp float; varying vec2 vTextureCoord; varying vec4 vColor; uniform sampler2D uSampler; uniform sampler2D uSamplerAlphaMask; void main(void) { float alpha = texture2D(uSamplerAlphaMask, vTextureCoord).r; if (alpha < 0.0039) { discard; } vec4 v4Color = texture2D(uSampler, vTextureCoord); v4Color.rgb = v4Color.rgb alpha; v4Color.a = alpha; gl_FragColor = v4Color vColor; }"
texture_frag : string
[静态]

属性详细信息

blur_frag

blurfrag : string = "precision mediump float;\r\nuniform vec2 blur;\r\nuniform sampler2D uSampler;\r\nvarying vec2 vTextureCoord;\r\nuniform vec2 uTextureSize;\r\nvoid main()\r\n{\r\n const int sampleRadius = 5;\r\n const int samples = sampleRadius 2 + 1;\r\n vec2 blurUv = blur / uTextureSize;\r\n vec4 color = vec4(0, 0, 0, 0);\r\n vec2 uv = vec2(0.0, 0.0);\r\n blurUv /= float(sampleRadius);\r\n\r\n for (int i = -sampleRadius; i <= sampleRadius; i++) {\r\n uv.x = vTextureCoord.x + float(i) _ blurUv.x;\r\n uv.y = vTextureCoord.y + float(i) * blurUv.y;\r\n color += texture2D(uSampler, uv);\r\n }\r\n\r\n color /= float(samples);\r\n gl_FragColor = color;\r\n}"

  • 支持版本:all
  • 运行平台:Web,Native

colorTransform_frag

colorTransformfrag : string = "precision mediump float;\r\nvarying vec2 vTextureCoord;\r\nvarying vec4 vColor;\r\nuniform mat4 matrix;\r\nuniform vec4 colorAdd;\r\nuniform sampler2D uSampler;\r\n\r\nvoid main(void) {\r\n vec4 texColor = texture2D(uSampler, vTextureCoord);\r\n if(texColor.a > 0.) {\r\n // 抵消预乘的alpha通道\r\n texColor = vec4(texColor.rgb / texColor.a, texColor.a);\r\n }\r\n vec4 locColor = clamp(texColor matrix + colorAdd, 0., 1.);\r\n glFragColor = vColor vec4(locColor.rgb * locColor.a, locColor.a);\r\n}"

  • 支持版本:all
  • 运行平台:Web,Native

colorTransform_frag_etc_alphamask_frag

colorTransformfrag_etc_alphamask_frag : string = "precision mediump float;\r\nvarying vec2 vTextureCoord;\r\nvarying vec4 vColor;\r\nuniform mat4 matrix;\r\nuniform vec4 colorAdd;\r\nuniform sampler2D uSampler;\r\nuniform sampler2D uSamplerAlphaMask;\r\n\r\nvoid main(void){\r\nfloat alpha = texture2D(uSamplerAlphaMask, vTextureCoord).r;\r\nif (alpha < 0.0039) { discard; }\r\nvec4 texColor = texture2D(uSampler, vTextureCoord);\r\nif(texColor.a > 0.0) {\r\n // 抵消预乘的alpha通道\r\ntexColor = vec4(texColor.rgb / texColor.a, texColor.a);\r\n}\r\nvec4 v4Color = clamp(texColor matrix + colorAdd, 0.0, 1.0);\r\nv4Color.rgb = v4Color.rgb _ alpha;\r\nv4Color.a = alpha;\r\ngl_FragColor = v4Color * vColor;\r\n}"

  • 支持版本:all
  • 运行平台:Web,Native

"precision mediump float; varying vec2 vTextureCoord; varying vec4 vColor; uniform mat4 matrix; uniform vec4 colorAdd; uniform sampler2D uSampler; uniform sampler2D uSamplerAlphaMask; void main(void){ float alpha = texture2D(uSamplerAlphaMask, vTextureCoord).r; if (alpha < 0.0039) { discard; } vec4 texColor = texture2D(uSampler, vTextureCoord); if(texColor.a > 0.0) { // 抵消预乘的alpha通道 texColor = vec4(texColor.rgb / texColor.a, texColor.a); } vec4 v4Color = clamp(texColor matrix + colorAdd, 0.0, 1.0); v4Color.rgb = v4Color.rgb alpha; v4Color.a = alpha; gl_FragColor = v4Color * vColor; }"

default_vert

default_vert : string = "attribute vec2 aVertexPosition;\r\nattribute vec2 aTextureCoord;\r\nattribute vec4 aColor;\r\n\r\nuniform vec2 projectionVector;\r\n// uniform vec2 offsetVector;\r\n\r\nvarying vec2 vTextureCoord;\r\nvarying vec4 vColor;\r\n\r\nconst vec2 center = vec2(-1.0, 1.0);\r\n\r\nvoid main(void) {\r\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\r\n vTextureCoord = aTextureCoord;\r\n vColor = aColor;\r\n}"

  • 支持版本:all
  • 运行平台:Web,Native

glow_frag

glowfrag : string = "precision highp float;\r\nvarying vec2 vTextureCoord;\r\n\r\nuniform sampler2D uSampler;\r\n\r\nuniform float dist;\r\nuniform float angle;\r\nuniform vec4 color;\r\nuniform float alpha;\r\nuniform float blurX;\r\nuniform float blurY;\r\n// uniform vec4 quality;\r\nuniform float strength;\r\nuniform float inner;\r\nuniform float knockout;\r\nuniform float hideObject;\r\n\r\nuniform vec2 uTextureSize;\r\n\r\nfloat random(vec2 scale)\r\n{\r\n return fract(sin(dot(gl_FragCoord.xy, scale)) 43758.5453);\r\n}\r\n\r\nvoid main(void) {\r\n vec2 px = vec2(1.0 / uTextureSize.x, 1.0 / uTextureSize.y);\r\n // TODO 自动调节采样次数?\r\n const float linearSamplingTimes = 7.0;\r\n const float circleSamplingTimes = 12.0;\r\n vec4 ownColor = texture2D(uSampler, vTextureCoord);\r\n vec4 curColor;\r\n float totalAlpha = 0.0;\r\n float maxTotalAlpha = 0.0;\r\n float curDistanceX = 0.0;\r\n float curDistanceY = 0.0;\r\n float offsetX = dist cos(angle) px.x;\r\n float offsetY = dist sin(angle) px.y;\r\n\r\n const float PI = 3.14159265358979323846264;\r\n float cosAngle;\r\n float sinAngle;\r\n float offset = PI 2.0 / circleSamplingTimes random(vec2(12.9898, 78.233));\r\n float stepX = blurX px.x / linearSamplingTimes;\r\n float stepY = blurY px.y / linearSamplingTimes;\r\n for (float a = 0.0; a <= PI 2.0; a += PI 2.0 / circleSamplingTimes) {\r\n cosAngle = cos(a + offset);\r\n sinAngle = sin(a + offset);\r\n for (float i = 1.0; i <= linearSamplingTimes; i++) {\r\n curDistanceX = i stepX cosAngle;\r\n curDistanceY = i stepY sinAngle;\r\n if (vTextureCoord.x + curDistanceX - offsetX >= 0.0 && vTextureCoord.y + curDistanceY + offsetY <= 1.0){\r\n curColor = texture2D(uSampler, vec2(vTextureCoord.x + curDistanceX - offsetX, vTextureCoord.y + curDistanceY + offsetY));\r\n totalAlpha += (linearSamplingTimes - i) curColor.a;\r\n }\r\n maxTotalAlpha += (linearSamplingTimes - i);\r\n }\r\n }\r\n\r\n ownColor.a = max(ownColor.a, 0.0001);\r\n ownColor.rgb = ownColor.rgb / ownColor.a;\r\n\r\n float outerGlowAlpha = (totalAlpha / maxTotalAlpha) strength alpha (1. - inner) max(min(hideObject, knockout), 1. - ownColor.a);\r\n float innerGlowAlpha = ((maxTotalAlpha - totalAlpha) / maxTotalAlpha) strength alpha inner ownColor.a;\r\n\r\n ownColor.a = max(ownColor.a knockout _ (1. - hideObject), 0.0001);\r\n vec3 mix1 = mix(ownColor.rgb, color.rgb, innerGlowAlpha / (innerGlowAlpha + ownColor.a));\r\n vec3 mix2 = mix(mix1, color.rgb, outerGlowAlpha / (innerGlowAlpha + ownColor.a + outerGlowAlpha));\r\n float resultAlpha = min(ownColor.a + outerGlowAlpha + innerGlowAlpha, 1.);\r\n gl_FragColor = vec4(mix2 * resultAlpha, resultAlpha);\r\n}"

  • 支持版本:all
  • 运行平台:Web,Native

primitive_frag

primitive_frag : string = "precision lowp float;\r\nvarying vec2 vTextureCoord;\r\nvarying vec4 vColor;\r\n\r\nvoid main(void) {\r\n gl_FragColor = vColor;\r\n}"

  • 支持版本:all
  • 运行平台:Web,Native

texture_etc_alphamask_frag

textureetc_alphamask_frag : string = "precision lowp float;\r\nvarying vec2 vTextureCoord;\r\nvarying vec4 vColor;\r\nuniform sampler2D uSampler;\r\nuniform sampler2D uSamplerAlphaMask;\r\nvoid main(void) {\r\nfloat alpha = texture2D(uSamplerAlphaMask, vTextureCoord).r;\r\nif (alpha < 0.0039) { discard; }\r\nvec4 v4Color = texture2D(uSampler, vTextureCoord);\r\nv4Color.rgb = v4Color.rgb alpha;\r\nv4Color.a = alpha;\r\nglFragColor = v4Color vColor;\r\n}"

  • 支持版本:all
  • 运行平台:Web,Native

"precision lowp float; varying vec2 vTextureCoord; varying vec4 vColor; uniform sampler2D uSampler; uniform sampler2D uSamplerAlphaMask; void main(void) { float alpha = texture2D(uSamplerAlphaMask, vTextureCoord).r; if (alpha < 0.0039) { discard; } vec4 v4Color = texture2D(uSampler, vTextureCoord); v4Color.rgb = v4Color.rgb alpha; v4Color.a = alpha; gl_FragColor = v4Color vColor; }"

texture_frag

texture_frag : string = "precision lowp float;\r\nvarying vec2 vTextureCoord;\r\nvarying vec4 vColor;\r\nuniform sampler2D uSampler;\r\n\r\nvoid main(void) {\r\n gl_FragColor = texture2D(uSampler, vTextureCoord) * vColor;\r\n}"

  • 支持版本:all
  • 运行平台:Web,Native