glsl

Synchronisation in OpenGL (part 1.1)

 ̄綄美尐妖づ 提交于 2019-12-20 03:47:11
问题 My questions pertain to the use of a single OpenGL 4.5 context without any direct memory mapping or explicit synchronisation (hypothetically), with both rendering shaders (invoked with glDrawArrays() ) and compute shaders (invoked with glDispatchCompute() ). Question 1.1: Are all changes to rendering state – such as with glUseProgram() , glEnable() / glDisable() , glStencilFunc() , glStencilOp() , glClearColor() , glStencilMask() , glClearStencil() , glBlendFunc() , glColorMask() , etc. –

Is it ever reasonable to do computations outside of main in an OpenGL shader?

耗尽温柔 提交于 2019-12-20 02:52:52
问题 I have some vertex shader code somewhat like the following (this is a bit of simplified example): attribute vec2 aPosition; attribute vec4 aColor; varying lowp vec4 vColor; uniform vec4 uViewport; mat4 viewportScale = mat4(2.0 / uViewport.z, 0, 0, 0, 0, -2.0 / uViewport.w, 0,0, 0, 0,1,0, -1,+1,0,1); void main() { vec2 pos = aPosition; gl_Position = viewportScale * vec4(pos, 0, 1); vColor = vec4(aColor.rgb*aColor.a, aColor.a); } In particular, the viewportScale matrix is calculated from the

GLSL Spinlock Never Terminates

若如初见. 提交于 2019-12-19 10:14:03
问题 I'm trying to implement a GLSL spinlock to be able to implement single-pass depth peeling. I'm having trouble because examples of locking texture use are scarce. I have to admit that I don't really know what I'm doing, here, so I describe probably more context than is necessary, just to be safe. I wrote a fragment program which should do effectively nothing: #version 420 core //The lock texture holds either 0 or 1. //0 means that the texture is available. //1 means that the texture is locked.

GPU ray casting (single pass) with 3d textures in spherical coordinates

为君一笑 提交于 2019-12-19 10:04:47
问题 i' am implementing an algorithm of volume rendering "GPU ray casting single pass". For this, i used a float array of intensity values as 3d textures ( this 3d textures describes a regular 3d grid in spherical coordinates ). Here there are example of array values: 75.839354473071637, 64.083049468866022, 65.253933716444365, 79.992431196592577, 84.411485976957096, 0.0000000000000000, 82.020319431382831, 76.808403454586994, 79.974774618246158, 0.0000000000000000, 91.127273013466336, 84

Blend two canvases onto one with WebGL

家住魔仙堡 提交于 2019-12-19 07:09:16
问题 What I'm trying to do is blend two canvases onto a single canvas for a drawing app I am creating. I know Javascript very well, but I really don't have any clue where to start with WebGL and since it isn't a very hard task to do, I'm assuming it would be yield quicker processing speeds if I don't use another library like Three.js or others of that sort. What I already have are canvases that the user will be drawing on (Let's call them canvas A and B) which are both hidden and canvas C which is

Drawing lines with GLSL

我只是一个虾纸丫 提交于 2019-12-19 04:57:14
问题 is it possible to draw a line with GLSL using GL_TRIANGLES? The reason why i ask is i'm trying to draw a line with adobes molehill and it only draws triangle. Cheers 回答1: if you set edge rendering to be on, just draw a triangle with point 1 and 3 at the same position. It's not efficient, but it works. 回答2: If you can, use a geometry shader. Pass in two vertices and a line width, generate 4 points forming two triangles by shifting the vertices, render and be done... But drawing wide lines

OpenGL Compute Shader SSBO

不问归期 提交于 2019-12-18 17:12:21
问题 I want a compute shader that writes 1's in the output buffer. I compile the shader and attach it to the program without problem, then I call glDispatchCompute() function and I wait until compute shader ends. But when I see the array, there are only 0's. Can anyone tell me where is the mistake? This is my compute shader code: #version 430 core layout (local_size_x = 2) in; layout(std430, binding=0) writeonly buffer Pos{ float Position[]; }; void main(){ Position[gl_GlobalInvocationID.x] = 1.0f

billboarding vertices in the vertex shader

前提是你 提交于 2019-12-18 16:58:36
问题 Code demonstrating issue (comment/uncomment out the gl_Position lines in the vertex shader) var scene; var book; var shaderMaterial; var renderer = new THREE.WebGLRenderer({ antialias: true }); renderer.setClearColor(0x000000); document.body.appendChild(renderer.domElement); var camera = new THREE.PerspectiveCamera(55, 1, 0.1, 40000); window.onresize = function () { renderer.setSize(window.innerWidth, window.innerHeight); camera.aspect = window.innerWidth / window.innerHeight; camera

GLSL shader that scroll texture

那年仲夏 提交于 2019-12-18 13:36:07
问题 How to scrolling a texture on a plane? So I have a plane with a texture, can I use a shader to scroll left from right (infinite) the texture on it? 回答1: Setup the texture wrapping mode using glTexParameteri(TextureID, L_TEXTURE_WRAP_S, GL_REPEAT) Add the float uniform named Time to your texturing shader Use something like texture2D(sampler, u + Time, v) while fetching texture sample. Update the Time uniform using some timer in your code. Here's a GLSL shader: /*VERTEX_PROGRAM*/ in vec4 in

GLSL: How to get pixel x,y,z world position?

守給你的承諾、 提交于 2019-12-18 10:34:12
问题 I want to adjust the colors depending on which xyz position they are in the world. I tried this in my fragment shader: varying vec4 verpos; void main(){ vec4 c; c.x = verpos.x; c.y = verpos.y; c.z = verpos.z; c.w = 1.0; gl_FragColor = c; } but it seems that the colors change depending on my camera angle/position, how do i make the coords independent from my camera position/angle? Heres my vertex shader: varying vec4 verpos; void main(){ gl_Position = ftransform(); verpos = gl_ModelViewMatrix