把shadertoy 搬到cocoscreaor的方法
把shadertoy 搬到cocoscreaor的方法
// Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. // Note: Current format version is experiment, the format may be changed. // The future format may not be compatible, you may need to update the script manually. // 注意:当前版本的格式是实验性的,之后还会进行修改。 // 后续版本的格式不保证兼容当前格式,可能需要手动升级到最新版本。, %{ techniques: [ { passes: [ { vert: vs frag: fs cullMode: none blend: true } ] layer: 0 } ] properties: { texture: { type: sampler2D value: null } color: { type: color4 displayName:'颜色' value: [1, 1, 1, 1] } resolution:{ type:vec3, displayName:'分辨率' value:[1280,720,0] } time:{ type:float, value:0.01 } } %} %% vs { precision highp float; uniform mat4 cc_matViewProj; attribute vec3 a_position; attribute vec2 a_uv0; varying vec2 uv0; void main () { vec4 pos = cc_matViewProj * vec4(a_position, 1); gl_Position = pos; uv0 = a_uv0; } } %% fs { precision highp float; uniform sampler2D texture; uniform vec4 color; varying vec2 uv0; uniform vec3 resolution; uniform float time; const float count = 10.0; const float speed = 5.0; float Hash( vec2 p, in float s) { vec3 p2 = vec3(p.xy,27.0 * abs(sin(s))); return fract(sin(dot(p2,vec3(27.1,61.7, 12.4)))*273758.5453123); } float noise(in vec2 p, in float s) { vec2 i = floor(p); vec2 f = fract(p); f *= f * (3.0-2.0*f); return mix(mix(Hash(i + vec2(0.,0.), s), Hash(i + vec2(1.,0.), s),f.x), mix(Hash(i + vec2(0.,1.), s), Hash(i + vec2(1.,1.), s),f.x), f.y) * s; } float fbm(vec2 p) { float v = 0.0; v += noise(p * 01., 0.5); v += noise(p * 02., 0.25); v += noise(p * 04., 0.125); v += noise(p * 08., 0.0625); v += noise(p * 16., 0.03125); return v; } void main () { float worktime = time * speed; vec2 uv = ( gl_FragCoord.xy / resolution.xy ) * 2.0 - 1.0; uv.x *= resolution.x/resolution.y; vec3 finalColor = vec3( 0.0, 0.0, 0.0 ); for( float i = 1.0; i < count; i++ ) { float t = abs(1.0 / ((uv.x + fbm( uv + worktime / i )) * (i * 100.0))); finalColor += t * vec3( i * 0.075, 0.5, 2.0 ); } gl_FragColor = vec4( finalColor, 1.0 ); } }
直接把fs替换下就好了
如果遇到什么不懂的地方直接关注公众号留言(本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须在文章页面给出原文连接,否则保留追究法律责任的权利。)
作者:newmiracle
出处:https://www.cnblogs.com/newmiracle/