glsles

Three.js - Using multiple textures in a single PointCloud

三世轮回 提交于 2019-11-30 15:37:45
I'm trying to use multiple textures in a single PointCloud using a ShaderMaterial. I'm passing a texture array to the shader along with texture index attributes and selecting the appropriate texture to use in the fragment shader. Relevant Setup Code: var particleCount = 100; var uniforms = { textures: { type: 'tv', value: this.getTextures() } }; var attributes = { texIndex: { type: 'f', value: [] }, color: { type: 'c', value: [] }, }; var material = new THREE.ShaderMaterial({ uniforms: uniforms, attributes: attributes, vertexShader: document.getElementById('vertexShader').textContent,

Index expression must be constant - WebGL/GLSL error

蓝咒 提交于 2019-11-29 17:06:01
问题 I'm having trouble accessing an array in a fragment shader using a non-constant int as the index. I've removed the formula as it wouldn't make much sense here anyway, but my code is meant to calculate the tileID based on the current pixel and use that to determine the color. Here's my code: int tileID = <Insert formula here>; vec3 colorTest; int arrayTest[1024]; for (int x = 0; x < 1024; x++) { if (x == 1) arrayTest[x] = 1; else arrayTest[x] = 2; } if (arrayTest[tileID] == 1) colorTest = vec3

normal matrix for non uniform scaling

隐身守侯 提交于 2019-11-28 12:53:13
Im trying to calculate the normal matrix for my GLSL shaders on OpenGL 2.0. The theory is : a normal matrix is the top left 3x3 matrix of the ModelView, transposed and inverted. It seems to be correct as I have been rendering my scenes correctly, until I imported a model from maya and found non-uniform scales. Loaded models have a weird lighting, while my procedural ones are correct, so I put my money on the normal matrix calculation. How is it computed with non uniform scale? You already figured out that you need the transposed inverted matrix for transforming the normals. For a scaling

Writing to gl_FragColor causes INVALID_OPERATION on Android

大兔子大兔子 提交于 2019-11-28 05:35:59
问题 I'm trying to master OGLES2 for NDK and stuck with GLSL shaders. The situation is similar to the one already highlighted here, but it seems the reason behind it is somewhat different. I have the simpliest shaders possible. Vertex: #version 110 attribute vec3 vPosition; void main(void) { gl_Position = vec4(vPosition, 1.0); gl_FrontColor = gl_BackColor = vec4(0.3, 0.3, 0.3, 1); // *** } Fragment: #version 110 void main(void) { gl_FragColor = gl_Color; } Easy and straight-forward. I even define

How do I convert between float and vec4,vec3,vec2?

六眼飞鱼酱① 提交于 2019-11-27 23:18:32
This question is very related to the question here( How do I convert a vec4 rgba value to a float? ). There is some of articles or questions related to this question already, but I wonder most of articles are not identifying which type of floating value. As long as I can come up with, there is some of floating value packing/unpacking formula below. unsigned normalized float signed normalized float signed ranged float (the floating value I can find range limitation) unsigned ranged float unsigned float signed float However, these are just 2 case actually. The other packing/unpacking can be

How do you pack one 32bit int Into 4, 8bit ints in glsl / webgl?

余生长醉 提交于 2019-11-27 03:51:58
I'm looking to parallelize some complex math, and webgl looks like the perfect way to do it. The problem is, you can only read 8 bit integers from textures. I would ideally like to get 32 bit numbers out of the texture. I had the idea of using the 4 color channels to get 32 bits per pixel, instead of 4 times 8 bits. My problem is, glsl doesn't have a "%" operator or any bitwise operator! TLDR: How do I convert a 32bit number to 4 8bit numbers by using the operators in glsl. Some extra info on the technique (using bitwise operators): How to store a 64 bit integer in two 32 bit integers and

How do I convert between float and vec4,vec3,vec2?

送分小仙女□ 提交于 2019-11-26 23:17:57
问题 This question is very related to the question here(How do I convert a vec4 rgba value to a float?). There is some of articles or questions related to this question already, but I wonder most of articles are not identifying which type of floating value. As long as I can come up with, there is some of floating value packing/unpacking formula below. unsigned normalized float signed normalized float signed ranged float (the floating value I can find range limitation) unsigned ranged float