'WebGL How to pass big numbers to shaders
I am making app by using javascript and webgl. I need to pass big numbers (for example 1647843999744
) to shader but when I get this value with this code gl.getUniform(this.shaderProgram, this.maxTimeLoc)
, I see different value. 1647843999744
is changing to 1647844041000
.
This is my code
createShaderProgram: function () {
const { gl } = this
var VertexShaderCode = `
precision lowp float;
attribute vec4 vertexPos;
uniform mat4 modelViewMatrix;
uniform mat4 projectionMatrix;
uniform vec3 transPos;
uniform float maxPointSize;
uniform float minPointSize;
uniform float maxTime;
uniform float minTime;
varying float scale;
void main(void) {
scale = (vertexPos.w - minTime) / (maxTime - minTime);
gl_Position = projectionMatrix * modelViewMatrix * vec4(vertexPos.xyz - transPos.xyz, 1.0);
gl_PointSize = minPointSize + ((maxPointSize - minPointSize)*scale);
}
`
var vertexShader = gl.createShader(gl.VERTEX_SHADER)
gl.shaderSource(vertexShader, VertexShaderCode)
gl.compileShader(vertexShader)
var FragmentShaderCode = `
precision lowp float;
varying float scale;
uniform vec3 startColor;
uniform vec3 endColor;
uniform bool applyOpacity;
void main() {
float r = 0.0;
vec2 cxy = 2.0 * gl_PointCoord - 1.0;
r = dot(cxy, cxy);
if(r > 1.0 ){ discard;}
vec3 factor = (endColor - startColor) * r;
if(applyOpacity==true){
gl_FragColor = vec4(startColor + factor, scale * (1.0-r));
}else{
gl_FragColor = vec4(startColor + factor, 1.0 - r);
}
}`
var fragmentShader = gl.createShader(gl.FRAGMENT_SHADER)
gl.shaderSource(fragmentShader, FragmentShaderCode)
gl.compileShader(fragmentShader)
this.shaderProgram = gl.createProgram()
gl.attachShader(this.shaderProgram, vertexShader)
gl.attachShader(this.shaderProgram, fragmentShader)
gl.linkProgram(this.shaderProgram)
}
Any ideas?What should I do?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|