glsl

Draw 2D Mesh Grid using GLSL in 3D space

家住魔仙堡 提交于 2019-12-01 01:29:07
I'm hoping to draw a 2D Grid within a finite space on the X axis using OpengGL 4.0. I wish to use GLSL using vert/frag shaders etc for rending the light (making them appear). It can be done with the simplest code using older OpenGL 2.0 methods but then of course it doesn't use lighting/shaders to colour them: void Draw_Grid() { for(float i = -500; i <= 500; i += 5) { glBegin(GL_LINES); glColor3ub(150, 190, 150); glVertex3f(-500, 0, i); glVertex3f(500, 0, i); glVertex3f(i, 0,-500); glVertex3f(i, 0, 500); glEnd(); } } But I can'd find any tutorials other than this one which I don't understand

Setting the values of a struct array from JS to GLSL

天涯浪子 提交于 2019-12-01 00:15:28
I've been trying to make a structure that will contain all the lights of my WebGL app, and I'm having troubles setting up it's values from JS. The structure is as follows: struct Light { vec4 position; vec4 ambient; vec4 diffuse; vec4 specular; vec3 spotDirection; float spotCutOff; float constantAttenuation; float linearAttenuation; float quadraticAttenuation; float spotExponent; float spotLightCosCutOff; }; uniform Light lights[numLights]; After testing LOTS of things I made it work but I'm not happy with the code I wrote: program.uniform.lights = []; program.uniform.lights.push({ position: "

THREE.js - Billboard Vertex Shader

烈酒焚心 提交于 2019-11-30 23:09:40
I have the need to orientate an instance of THREE.Mesh to always face the camera. I know I could just use the [THREE.Mesh].lookAt() method, but I'm trying to work on my GLSL chops a bit more and want to be able to do this in a vertex shader. I've read through NeHe's Billboarding tutorial , and it makes sense to me. Well, all apart from the bit where one applies these orientation vectors to each vertex. I feel like I'm very close to getting this working, but as it stands at the moment, my vertex shader is looking more like a 90s rave video than a billboard: Progress so far fiddle: http:/

Performance of integer and bitwise operations on GPU

萝らか妹 提交于 2019-11-30 22:06:44
问题 Though GPUs are supposed for use with floating point data types, I'd be interested in how fast can GPU process bitwise operations. These are the fastest possible on CPU, but does GPU emulate bitwise operations or are they fully computed on hardware? I'm planning to use them inside shader programs written with GLSL. Also I'd suppose that if bitwise operations have full preformance, integer data types should have also, but I need confirmation on that. To be more precise, targeted versions are

Do OpenGL GLSL samplers always return floats from 0.0 to 1.0?

旧街凉风 提交于 2019-11-30 20:46:54
I've created a couple of floating point RGBA texture... glBindTexture( GL_TEXTURE_2D, texid[k] ); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); glTexImage2D(GL_TEXTURE_2D, 0, 4, width, height, 0, GL_RGBA, GL_FLOAT, data); and then I double-buffer render/sample into them alternately in a shader program glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL

Count pixels by color in webgl fragment shader

一笑奈何 提交于 2019-11-30 20:36:22
问题 I have 2d texture S and want to return 3d texture H, such that pixel H[r,g,b] is equal to number of pixels of color rgb in texture S. Basically histogram of colors in texture S. I know about occlusion queries, but it's only available in webgl2, and IIUC even there only with boolean results, and besides I would need to do separate query for each color. Ideally I'd like to do this in one fragment shader pass. Is there any way to do reduce (fold) operations in fragment shaders? Why I need this

Draw 2D Mesh Grid using GLSL in 3D space

巧了我就是萌 提交于 2019-11-30 19:52:36
问题 I'm hoping to draw a 2D Grid within a finite space on the X axis using OpengGL 4.0. I wish to use GLSL using vert/frag shaders etc for rending the light (making them appear). It can be done with the simplest code using older OpenGL 2.0 methods but then of course it doesn't use lighting/shaders to colour them: void Draw_Grid() { for(float i = -500; i <= 500; i += 5) { glBegin(GL_LINES); glColor3ub(150, 190, 150); glVertex3f(-500, 0, i); glVertex3f(500, 0, i); glVertex3f(i, 0,-500); glVertex3f

“GL_HALF_FLOAT” with OpenGL Rendering and GLSL

孤者浪人 提交于 2019-11-30 19:38:16
问题 I am programming an OpenGL renderer in C++. I want it to be as efficient as possible and each vertex/normal/UV tex coord/tangents/etc to take up as little memory as possible. I am using indexes, line strips, and fans. I was thinking that 32bit floating points are not necessary and 16 bit Floating points should be fine, at least for some of these like normals and UVs. I can't seem to find any examples of this anywhere. I can find talk of "GL_HALF_FLOAT", but no real examples. Am I on the right

Is it possible for a vertex attribute to be an array in GLSL-ES 2.0?

僤鯓⒐⒋嵵緔 提交于 2019-11-30 19:31:42
In GLSL-ES it's possible to have arrays. For example, the GLSL ES Specification gives the following example of a uniform variable that's an array: uniform vec4 lightPosition[4]; Is it possible to have vertex attributes that are arrays? In other words, is the following legal according to the spec? attribute vec4 foo[3]; // three vec4s per vertex Is the answer (either yes or no) explicitly mentioned anywhere in the GLSL ES Specification? (I can't find it, but I haven't read every line of the spec.) Also, if it is legal, how does one initialize such an attribute using the OpenGL ES 2.0 API?

GLSL sampler2D in struct

只谈情不闲聊 提交于 2019-11-30 17:06:06
问题 In GLSL there seems to be linking error of shaders when I try to pass a uniform struct with a sampler2D attribute to a function which is forward declared. The code works if I remove forward declaration and move the function above main. Is this illegal code? #version 330 core in vec2 texcoords; out vec4 color; struct Material{ sampler2D tex; // Sampler inside a struct }; uniform Material material; // Forward Declaration vec4 add(Material m); void main() { color = add(material); } // Function