1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| CCEffect %{ techniques: - name: portal-dissolve passes: - vert: portal-vs:vert frag: portal-fs:frag properties: &props mainTexture: { value: white } baseColor: { value: [1, 1, 1, 1], editor: { type: color } } dissolveTexture: { value: white } dissolveAmount: { value: 0.0, range: [0, 1] } portalColor: { value: [0, 0.5, 1, 1], editor: { type: color } } energyColor: { value: [0, 1, 1, 1], editor: { type: color } } spiralSpeed: { value: 2.0, range: [0.1, 10] } spiralTightness: { value: 5.0, range: [1, 20] } energyIntensity: { value: 3.0, range: [1, 10] } distortionStrength: { value: 0.1, range: [0, 0.5] } }%
CCProgram portal-vs %{ #include <surface-vertex> }%
CCProgram portal-fs %{ #include <surface-fragment> uniform sampler2D mainTexture; uniform vec4 baseColor; uniform sampler2D dissolveTexture; uniform float dissolveAmount; uniform vec4 portalColor; uniform vec4 energyColor; uniform float spiralSpeed; uniform float spiralTightness; uniform float energyIntensity; uniform float distortionStrength; void surf(in SurfaceIn In, inout SurfaceOut Out) { vec2 uv = In.uv; vec2 center = vec2(0.5, 0.5); vec2 toCenter = uv - center; float distance = length(toCenter); float angle = atan(toCenter.y, toCenter.x); float spiral = angle + distance * spiralTightness + cc_time.x * spiralSpeed; vec2 spiralUV = uv + vec2(cos(spiral), sin(spiral)) * distortionStrength * distance; vec4 albedo = texture(mainTexture, spiralUV) * baseColor; float noise = texture(dissolveTexture, spiralUV).r; float radialGradient = 1.0 - distance * 2.0; noise = mix(noise, radialGradient, 0.3); if (noise < dissolveAmount) { discard; } float portalEnergy = sin(spiral * 2.0) * 0.5 + 0.5; portalEnergy *= smoothstep(0.0, 0.3, distance) * smoothstep(0.8, 0.0, distance); float edgeFactor = 1.0 - smoothstep(dissolveAmount, dissolveAmount + 0.1, noise); vec3 finalEmissive = portalEnergy * portalColor.rgb + edgeFactor * energyColor.rgb * energyIntensity; Out.albedo = albedo; Out.normal = normalize(In.worldNormal); Out.metallic = 0.0; Out.roughness = 0.5; Out.emissive = finalEmissive; Out.ao = 1.0; } }%
|