glsl

three.js / webGL / GLSL - utilizing random math

拈花ヽ惹草 提交于 2019-12-03 21:57:09
I am using three.js to call a fragment shader - that shader specifies a color for my material, broken out into rgb - and I want to see if I can multiply those colors by a random value. This is the code I'm using so far: gl_FragColor = vec4( color.r*.5, color.g, color.b, smoothstep( 8000.0, -8000.0, gl_FragCoord.z / gl_FragCoord.w ) ); //MH - creates colors by multiplying color values and this is what I'd want to do if it were javascript, though obviously this doesn't work inside a GLSL shader script: gl_FragColor = vec4( color.r*Math.random(), color.g, color.b, smoothstep( 8000.0, -8000.0, gl

Setting the values of a struct array from JS to GLSL

孤者浪人 提交于 2019-12-03 21:32:22
问题 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

Instanced drawing with OpenGL ES 2.0 on iOS

落爺英雄遲暮 提交于 2019-12-03 19:07:24
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.0 is only available on a few devices (those based on the A7 GPU; so iPhone 5s, but not on iPhone 5 or

GPGPU programming with OpenGL ES 2.0

独自空忆成欢 提交于 2019-12-03 18:46:13
问题 I am trying to do some image processing on the GPU, e.g. median, blur, brightness, etc. The general idea is to do something like this framework from GPU Gems 1. I am able to write the GLSL fragment shader for processing the pixels as I've been trying out different things in an effect designer app. I am not sure however how I should do the other part of the task. That is, I'd like to be working on the image in image coords and then outputting the result to a texture. I am aware of the gl

GLSL: gl_FragCoord issues

穿精又带淫゛_ 提交于 2019-12-03 17:46:02
问题 I am experimenting with GLSL for OpenGL ES 2.0. I have a quad and a texture I am rendering. I can successfully do it this way: //VERTEX SHADER attribute highp vec4 vertex; attribute mediump vec2 coord0; uniform mediump mat4 worldViewProjection; varying mediump vec2 tc0; void main() { // Transforming The Vertex gl_Position = worldViewProjection * vertex; // Passing The Texture Coordinate Of Texture Unit 0 To The Fragment Shader tc0 = vec2(coord0); } //FRAGMENT SHADER varying mediump vec2 tc0;

Why am I not able to attach this texture uniform to my GLSL fragment shader?

喜夏-厌秋 提交于 2019-12-03 17:14:22
In my Mac application, I define a rectangular texture based on YUV 4:2:2 data from an attached camera. Using standard vertex and texture coordinates, I can draw this to a rectangular area on the screen without any problems. However, I would like to use a GLSL fragment shader to process these image frames on the GPU, and am having trouble passing in the rectangular video texture as a uniform to the fragment shader. When I attempt to do so, the texture simply reads as black. The shader program compiles, links, and passes validation. I am receiving the proper address for the uniform from the

What is the actual number of vertex uniform components for GLSL shader on ATI graphics card?

ぃ、小莉子 提交于 2019-12-03 16:58:01
问题 I'm writing a GLSL vertex shader for an iMac with a AMD Radeon HD 6970M 2048 MB graphics card: GL_MAX_VERTEX_ATTRIBS: 16 GL_MAX_VERTEX_UNIFORM_COMPONENTS: 4096 GL_VERSION: 2.1 ATI-7.12.9 GL_SHADING_LANGUAGE_VERSION: 1.20 In my shader I would like to have a large array of uniform mat4s: uniform mat4 T[65] but if I try to have 65 of these my shader (secretly) switches to Apple Software Renderer mode. If I instead use 64: uniform mat4 T[64] everything is fine. Seems to be a problem with

THREE.js repeat wrapping texture in shader

余生长醉 提交于 2019-12-03 16:45:12
I want to repeat wrapping texture in THREE.js shader. The original texture image is: I want it to repeat 4x4 times which will looks like: But with the following code, it turns out to be: Vertex shader: varying vec2 vUv; uniform float textRepeat; void main() { // passing texture to fragment shader vUv = uv * textRepeat; gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0); } Fragment shader: varying vec2 vUv; uniform sampler2D texture; void main() { // add origianl texture gl_FragColor = texture2D(texture, vUv); } uniforms in a JavaScript file, in which textureRepeat gives the

When switching to GLSL 300, met the following error

流过昼夜 提交于 2019-12-03 16:15:55
when I switch to use OpenGL ES 3 with GLSL 300, I met the following error in my frag shader undeclared identifier gl_FragColor when using GLSL 100, everything is fine. Modern versions of GLSL do fragment shader outputs simply by declaring them as out values, and gl_FragColor is no longer supported, hence your error. Try this: out vec4 fragColor; void main() { fragColor = vec4(1.0, 0.0, 0.0, 1.0); } Note that gl_FragDepth hasn't changed and is still available. For more information see https://www.opengl.org/wiki/Fragment_Shader The predefined variable gl_FragColor does not exist anymore in GLSL

Why does GLSL's arithmetic functions yield so different results on the iPad than on the simulator?

岁酱吖の 提交于 2019-12-03 15:32:33
I'm currently chasing some bugs in my OpenGL ES 2.0 fragment shader code which is running on iOS devices. The code runs fine in the simulator, but on the iPad it has huge problems and some of the calculations yield vastly different results, I had for example 0.0 on the iPad and 4013.17 on the simulator, so I'm not talking about small differences which could be the result of some rounding errors. One of the things I noticed is that, on the iPad, float1 = pow(float2, 2.0); can yield results which are very different from the results of float1 = float2 * float2; Specifically, when using pow(x, 2.0