zhuguoqing ff550d5d6a init
2022-05-22 10:32:02 +08:00

59 lines
1.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const renderEngine = cc.renderer.renderEngine;
const renderer = renderEngine.renderer;
let ShaderMaterial = require('ShaderMaterial');
const shader = {
name: 'niuqu',
params: [
{ name: 'u_displacement', type: renderer.PARAM_TEXTURE_2D },
{ name: 'u_magnitude', type: renderer.PARAM_FLOAT },//0-0.1
{ name: 'u_strength', type: renderer.PARAM_FLOAT2 },//0-1
{ name: 'time', type: renderer.PARAM_FLOAT },//0-1
],
start(material, params) {
material.cusparmas = {}
material.cusparmas._start = 0;
material.setParamValue('u_magnitude', params.u_magnitude);
material.setParamValue('u_strength', params.u_strength);
material.setParamValue('u_displacement', params.u_displacement._texture);
material.setParamValue('time', 0);
},
update(material, dt) {
material.cusparmas._start+=dt
material.setParamValue('time', material.cusparmas._start);
},
defines: [],
frag: `
uniform sampler2D texture;
uniform vec4 color;
varying vec2 uv0;
varying vec2 uv1;
varying vec2 uv2;
varying vec2 uv3;
uniform float time;
uniform sampler2D u_displacement;
uniform float u_magnitude;//波长
uniform vec2 u_strength;//振幅
void main() {
vec2 disp = texture2D(u_displacement, uv0 + u_strength * time).xy;
//disp的范围是0-1这步操作让其变成-1 到 1 乘以 参数
disp = ((disp * 2.0) - 1.0) * u_magnitude;
//uv坐标偏移
gl_FragColor = texture2D(texture, uv0 + disp)*vec4(0.9,0.9,1.0,0.5);
}`,
};
ShaderMaterial.addShader(shader);