Hello
I have plane and I want to show something like bellow picture and it’s move by uTime
To be able to see what calculation I did, I displayed it as a colored waveform through the fragment and it works fine but I expect vertex to work like fragment, but it doesn’t
my vertex shader :
attribute vec3 aPosition;
attribute vec2 aUv0;
uniform mat4 matrix_model;
uniform mat4 matrix_viewProjection;
uniform float u_Time;
uniform float u_Float;
uniform float u_Float1;
uniform float u_Float2;
varying vec2 uv2;
varying vec3 position2;
void main(void)
{
uv2 = aUv0;
position2 = aPosition;
// VectorSplitter
float x = aPosition.x;
float z = aPosition.z;
//Multiply
float output6 = u_Time * u_Float;
//Subtract
float output5 = x - output6;
//Divide
float output4 = output5 / u_Float1;
//Sin
float output3 = sin(output4);
//Multiply
float output2 = output3 * u_Float2;
//VectorMerger
vec3 xyz2 = vec3(x, output2, z).xyz;
gl_Position = matrix_viewProjection * matrix_model * vec4(xyz2, 1.0);
}
my fragment shader :
varying vec2 uv2;
varying vec3 position2;
uniform float u_Time;
uniform float u_Float;
uniform float u_Float1;
uniform float u_Float2;
void main(void)
{
//VectorSplitter
float x = position2.x;
float z = position2.z;
//Multiply
float output6 = u_Time * u_Float;
//Subtract
float output5 = x - output6;
//Divide
float output4 = output5 / u_Float1;
//Sin
float output3 = sin(output4);
//Multiply
float output2 = output3 * u_Float2;
//VectorMerger
vec3 xyz2 = vec3(0, output2, 0).xyz;
gl_FragColor = vec4(xyz2, 1.0);
}
my shader .js
var ShaderTestTwo = pc.createScript('shaderTestTwo');
ShaderTestTwo.attributes.add('vs', {
type: 'asset',
assetType: 'shader',
title: 'Vertex Shader'
});
ShaderTestTwo.attributes.add('fs', {
type: 'asset',
assetType: 'shader',
title: 'Fragment Shader'
});
// initialize code called once per entity
ShaderTestTwo.prototype.initialize = function() {
// console.log('>>>>', this.app.graphicsDevice.precision)
this._time = 0;
let fShaderPercision = "precision " + this.app.graphicsDevice.precision + " float;\n";
fShaderPercision = fShaderPercision + this.fs.resource
var shaderDefinition = {
attributes: {
aPosition: pc.SEMANTIC_POSITION,
aUv0: pc.SEMANTIC_TEXCOORD0
},
vshader: this.vs.resource,
fshader: fShaderPercision
};
var shader = new pc.Shader(this.app.graphicsDevice, shaderDefinition);
this.material = new pc.Material();
// this.material.setParameter('uTime', 0);
this.material.setParameter('u_Time', 1);
this.material.setParameter('u_Float', 0.1);
this.material.setParameter('u_Float1', 0.02);
this.material.setParameter('u_Float2', 0.3);
this.material.setShader(shader);
// Replace the material on the model with our new material
var renders = this.entity.findComponents('render');
for (var i = 0; i < renders.length; ++i) {
var meshInstances = renders[i].meshInstances;
for (var j = 0; j < meshInstances.length; j++) {
meshInstances[j].material = this.material;
}
}
};
// update code called every frame
ShaderTestTwo.prototype.update = function(dt) {
this._time += dt;
this.material.setParameter('u_Time', this._time);
};