glsl

Shader Time Uniform - clock_gettime being truncated

时光怂恿深爱的人放手 提交于 2019-12-13 16:13:09
问题 Take this function getting time as a double using clock_gettime: // return current time in milliseconds static double time_get_ms(void) { struct timespec res; #ifdef ANDROID clock_gettime(CLOCK_REALTIME_HR, &res); #else clock_gettime(CLOCK_REALTIME, &res); #endif return (double)(1000.0*res.tv_sec + res.tv_nsec/1e6); } Sending it to a shader requires conversion to float. The mantissa is being overflowed and is truncated on the way to the shader. Example: As a double = 1330579093642.441895 As a

Instanced drawing with OpenGL ES 2.0 on iOS

左心房为你撑大大i 提交于 2019-12-13 11:51:03
问题 In short: Can anyone confirm whether it is possible to use the built-in variable gl_InstanceID (or gl_InstanceIDEXT ) in a vertex shader using OpenGL ES 2.0 on iOS with GL_EXT_draw_instanced enabled? Longer: I want to draw multiple instances of an object using glDrawArraysInstanced and gl_InstanceID, and I want my application to run on multiple platforms, including iOS. The specification clearly says that these features require ES 3.0. According to the iOS Device Compatibility Reference ES 3

GLSL indexing into uniform array with variable length

北慕城南 提交于 2019-12-13 11:40:23
问题 I am passing an uniform array to geometry shader and want to index into it using a variable. I can use variable length array & index with fixed number (numeric constant) OR I can define a fixed length array & index using varible. However I can't index into variable length array using a variable. Below is pseudo code for geometry shader with cases that work & case that doesn't work This works: uniform vec2 dimensions[2]; // some code which computes index which is an int float dimX = dimensions

GLSL shader to boost the color

只愿长相守 提交于 2019-12-13 11:11:25
问题 Is their any GLSL shader that can help me to "boost" the color of a texture ? How to write such shader ? I would like to do something like the picture below : 回答1: It seems they are mostly boosting saturation here, so that's what you'd need to do in your fragment shader. To boost saturation, you need to take your data from the RVB color space to the HSL (hue saturation lightness) space. you then need to do: hslColor = vec3(hslCOlor.x, hslColor.y * **boost**, hslCOlor.z); Of course to do that

GLSL error: `out' qualifier only valid for function parameters in GLSL 1.10 [closed]

扶醉桌前 提交于 2019-12-13 10:38:08
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . My shaders have in/out keywords. But I've got GLSL compile error: 'out' qualifier only valid for function parameters in GLSL 1.10 . Shaders have #version 330 directive. Calling glGetString(GL_SHADING_LANGUAGE_VERSION) returns 3.30. Here is my project: github.com/wlad031/ssu-coursework-2016 . Input folder

Loading External Shaders Using THREE.JS

时光怂恿深爱的人放手 提交于 2019-12-13 08:50:05
问题 I am trying to make a THREE.JS scene with GLSL shaders applied, but am having trouble figuring out how to make it load my shaders. The scene appears to work, but the shaders don't do what they're supposed to. I'm using a shader loader function I found that uses pure THREE.JS instead of AJAX or Jquery. Here is the main javascript for my scene. var container, renderer, scene, camera, light, mesh, controls, start = Date.now(), fov = 30; window.addEventListener( 'load', function() { container =

Why does my three.js canvas masking not work?

这一生的挚爱 提交于 2019-12-13 08:43:39
问题 I'm trying to reproduce example of Szenia Zadvornykh presented here https://medium.com/@Zadvorsky/webgl-masking-composition-75b82dd4cdfd His demo is based on three.js r80, so I referenced r101 and tried to remove most of unrelated parts, and just have scene with grid and png mask on top. Here's my code: http://jsfiddle.net/mmalex/y2kt3Lrf/ Having commented // composer.addPass(maskPass) the grid shows up. But it does not seem like uniform sampler2D tDiffuse has the output of render pass. I

c++/OpenGL/GLSL, textures with “random” artifacts

风格不统一 提交于 2019-12-13 07:57:34
问题 Would like to know if someone has experienced this and knows the reason. I'm getting these strange artifacts after using "texture arrays" http://i.imgur.com/ZfLYmQB.png (My gpu is AMD R9 270) ninja edit deleted the rest of the post for readability since it was just showing code where the problem could have been, since the project is open source now I only show the source of the problem(fragment shader) Frag: #version 330 core layout (location = 0) out vec4 color; uniform vec4 colour; uniform

Opengl ES diffuse shader not working

笑着哭i 提交于 2019-12-13 07:06:42
问题 I'm implementing simple ray tracing for spheres in a fragment shader and I'm currently working on the function that computes color for a diffusely shaded sphere. Here is the code for the function: vec3 shadeSphere(vec3 point, vec4 sphere, vec3 material) { vec3 color = vec3(1.,2.,3.); vec3 N = (point - sphere.xyz) / sphere.w; vec3 diffuse = max(dot(Ldir, N), 0.0); vec3 ambient = material/5; color = ambient + Lrgb * diffuse * max(0.0, N * Ldir); return color; } I'm getting errors on the two

Precision loss with mod in GLSL

江枫思渺然 提交于 2019-12-13 06:42:58
问题 I'm repeating a texture in the vertex shader (for storage, not for repeating at the spot). Is this the right way? I seem to lose precision somehwere. varying vec2 texcoordC; texcoordC = gl_MultiTexCoord0.xy; texcoordC *= 10.0; texcoordC.x = mod(texcoordC.x, 1.0); texcoordC.y = mod(texcoordC.y, 1.0); ADDED: I then save (storage) the texcoord in the color, print it to the texture and later use that texture again. When I retrieve the color from the texture, I find the texcoords and use them to