'How Can I Get Result of Math Operation in WebGL Shader
There is a slow math operation. I don't want to do this by using javascript, I want to do in WebGL Shaders, but I need to get the value result of this operation.
var VertexShaderCode = `
precision lowp float;
uniform float value;
float result;
void main(void) {
result = ........ // math operation
// return result
gl_Position = vec4(0, 0, 0, 1);
}
`
var vertexShader = gl.createShader(gl.VERTEX_SHADER)
gl.shaderSource(vertexShader, VertexShaderCode)
gl.compileShader(vertexShader)
var FragmentShaderCode = `precision lowp float;
void main() {
gl_FragColor= vec4(0);
}`
var fragmentShader = gl.createShader(gl.FRAGMENT_SHADER)
gl.shaderSource(fragmentShader, FragmentShaderCode)
gl.compileShader(fragmentShader)
var shaderProgram = gl.createProgram()
gl.attachShader(shaderProgram, vertexShader)
gl.attachShader(shaderProgram, fragmentShader)
gl.linkProgram(shaderProgram)
return shaderProgram
How can I do this?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
