glsl

Explanation of dFdx

江枫思渺然 提交于 2019-12-18 10:19:50
问题 I am trying to understand the dFdx and dFdy functions in GLSL. I understand the following: The derivative is the rate of change The partial derivative of a function with two parameters is when you differentiate the function while keeping one of the parameters constant. dFdx and dFdy find the rate that a value changes between the current fragment and a neighboring fragment. I don't understand what the rate of change is referring to. Is it the rate of change of fragment coordinates? Could it

How to implement MeshNormalMaterial in THREE.js by GLSL?

故事扮演 提交于 2019-12-18 05:12:32
问题 I want to implement a shader like MeshNormalMaterial, but I have no idea how to convert normal to color. In THREE.js: My test1: varying vec3 vNormal; void main(void) { vNormal = abs(normal); gl_Position = matrix_viewProjection * matrix_model * vec4(position, 1.0); } varying vec3 vNormal; void main(void) { gl_FragColor = vec4(vNormal, 1.0); } My test2: varying vec3 vNormal; void main(void) { vNormal = normalize(normal) * 0.5 + 0.5; gl_Position = matrix_viewProjection * matrix_model * vec4

Core profile vs version string? Only getting GLSL 1.3/OGL 3.0 in mesa 10.0.1

℡╲_俬逩灬. 提交于 2019-12-18 04:49:08
问题 In theory, mesa 10.0.1 should support OpenGL 3.3 but currently I'm only getting 3.0 support. glxinfo gives some confusing results... [pdel@architect build]$ glxinfo | grep -i opengl OpenGL vendor string: Intel Open Source Technology Center OpenGL renderer string: Mesa DRI Intel(R) Ivybridge Mobile OpenGL core profile version string: 3.3 (Core Profile) Mesa 10.0.1 OpenGL core profile shading language version string: 3.30 OpenGL core profile context flags: (none) OpenGL core profile profile

GLSL float/vec3/vec4 array max size = GL_MAX_VERTEX_UNIFORM_VECTORS?

六月ゝ 毕业季﹏ 提交于 2019-12-18 03:39:18
问题 I run glGetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS, &maxVertUniformsVect); and get 1024. Than in GLSL I do uniform mediump vec4[1020] instance_mat and that was ok. But with vec3/vec2/float it fails: uniform mediump float[1030] instance_mat; // fails //uniform mediump vec2[1030] instance_mat; // and this //uniform mediump vec3[1030] instance_mat; // and this With following error: cannot locate suitable resource to bind variable "instance_mat". Possibly large array. The question is: Does GL_MAX

GLSL, Array of textures of differing size

让人想犯罪 __ 提交于 2019-12-17 22:42:45
问题 When doing multitexturing in GLSL, is there anyway to have an indexable array of samplers where each texture is a different size? This syntax isn't valid: uniform sampler2D texArray[5]; Right now it seems like the only option is to individually create the samplers: uniform sampler2D tex1; uniform sampler2D tex2; uniform sampler2D tex3; uniform sampler2D tex4; uniform sampler2D tex5; But then I can't iterate through them, which is a real pain in the ass. Is there a solution? 回答1: This syntax

Curved Frosted Glass Shader?

若如初见. 提交于 2019-12-17 21:16:13
问题 Well making something transparent isn't that difficult, but i need that transparency to be different based on an object's curve to make it look like it isn't just a flat object. Something like the picture below. The center is more transparent than the sides of the cylinder, it is more black which is the background color. Then there is the bezel which seems to have some sort of specular lighting at the top to make it more shiny, but i'd have no idea how to go about that transparency in that

Texture coordinates near 1 behave oddly

老子叫甜甜 提交于 2019-12-17 20:48:48
问题 I'm using (Py)OpenGL to display 256 colors indexed images. I use a shader together with a 1D texture containing the palette. Here's the Fragment shader code : #version 330 uniform sampler2D texture; uniform sampler1D palette; void main() { vec2 uv = gl_TexCoord[0].xy; vec4 color = texture2D(texture, uv); gl_FragColor = texture1D(palette, color.a) ; } To avoid rounding errors, all MAG and MIN filters are set to NEAREST. The way I was seeing the texture coordinates for the 1D texture was :

Modern OpenGL: VBO, GLM and Matrix Stacks

孤街浪徒 提交于 2019-12-17 18:47:51
问题 After searching and reading about Modern OpenGL in order to upgrade my existing project, I'm a bit confused, since my 3D framework based on OpenGL 2.1. so, as far as I learn... We need to generate our Vertex-Buffer-Objects from vertices, indices, normals, colors, uvs, etc. then we can use GLM for matrix transformation, and we only use VBO to create or manipulate meshes, finally we pass everything into GLSL vertex shader like this... glm::mat4 MVP = projection * view * model;

OpenGL 4.1(?) under Mavericks

怎甘沉沦 提交于 2019-12-17 18:26:27
问题 I've just upgraded my MacBook Pro to Mavericks (MacOS 10.9), including Xcode. According to Apple's "OpenGL Capabilities Table", this version has support for OpenGL 4.1, but a call to glGetString(GL_VERSION) returns "1.2" and my GLSL 3.30 shader, which begins with "#version 330" refuses to load, saying that version is not supported. Do I need to do something to Mavericks to enable 4.1 support? 回答1: When you request your pixel format using one of the lower-level APIs on OS X, you need to add

OpenGL - How to access depth buffer values? - Or: gl_FragCoord.z vs. Rendering depth to texture

筅森魡賤 提交于 2019-12-17 17:58:11
问题 I want to access the depth buffer value at the currently processed pixel in a pixel shader. How can we achieve this goal? Basically, there seems to be two options: Render depth to texture. How can we do this and what is the tradeoff? Use the value provided by gl_FragCoord.z - But: Is this the correct value? 回答1: On question 1: You can't directly read from the depth buffer in the fragment shader (unless there are recent extensions I'm not familiar with). You need to render to a Frame Buffer