glsl

glsl shader compilation issue at runtime

主宰稳场 提交于 2019-12-06 02:44:47
问题 I'm working on a project that uses OpenGL 4.0 shaders. I have to supply the call to glShaderSource() with an array of char arrays, which represents the source of the shader. The shader compilation is failing, with the following errors: (0) : error C0206: invalid token "<null atom>" in version line (0) : error C0000: syntax error, unexpected $end at token "<EOF>" Here's my (hello world) shader - straight from OpenGL 4.0 shading language cookbook #version 400 in vec3 VertexPosition; in vec3

OpenGL Getting Shader Attached to Program

社会主义新天地 提交于 2019-12-06 02:33:56
问题 Is there a way to access the shaders attached to a program? That is, given a program, can I do something like: vertexShader = getVertexShaderFromProgram(program); (I would like to log shader compilation status within my function that validates my program, but I only keep a reference to the program, not the shaders.) 回答1: glGetAttachedShaders() to get the names of the shaders attached to the given program object. glGetShaderiv( ..., GL_SHADER_TYPE, ... ) to get the type (vertex, geometry,

glsl double-precision vertex buffer

断了今生、忘了曾经 提交于 2019-12-06 02:16:50
If I create a double-precision vertex buffer, for example: GLuint vertBuffer, spanBuffer, spanCount, patchSize, program; // already setup glUseProgram (program); glEnableClientState (GL_VERTEX_ARRAY); glBindBuffer (GL_ARRAY_BUFFER, vertBuffer); glVertexPointer (3, GL_DOUBLE, 0, 0); glPatchParameteri (GL_PATCH_VERTICES, patchSize); glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, spanBuffer); glDrawElements (GL_PATCHES, spanCount * patchSize, GL_UNSIGNED_INT, 0); How do I access the double precision data in my vertex shader? Should I be able to do this? // GLSL VERTEX SHADER #version 410 in dvec4 gl

GL_APPLE_shader_framebuffer_fetch gl_lastFragData

旧街凉风 提交于 2019-12-06 01:49:37
问题 Apple introduced a new shader extension called GL_APPLE_shader_framebuffer_fetch, which allows fully programmable blending. There is also a wwdc video explaining the functionallity. It's the video 513 of wwdc 2012. Sadly this extension doesn’t work for me. F-Shader: #extension GL_APPLE_shader_framebuffer_fetch : require varying lowp vec4 colorVarying; void main(void) { gl_FragColor = gl_lastFragData[0] + vec4(colorVarying.x, colorVarying.y, colorVarying.z, 1.0); } Debug output: extension ‘GL

Normal mapping and phong shading with incorrect specular component

匆匆过客 提交于 2019-12-06 01:35:36
问题 I'm implementing normal/bump mapping in world space coordinates (I find those easier to work with) and my lighting worked fine without normal mapping, but when introducing normal mapping (and the new vectors calculated with the TBN matrix) the specular component of my lighting is off. The specular component is not between the camera and the light where it should be so something is wrong. However, looking at my code I could not find any issues. The tangent and bitangent come from the ASSIMP

Are there any non-mobile graphics cards that don't support “precision highp float”?

安稳与你 提交于 2019-12-06 01:21:47
I know it is common for mobile phones to not support 'precision highp float' in fragment shaders, but are there any desktop or laptop GPUs that don't support it? In other words, if I'm only writing my shader code for use in desktop/laptop scenarios, do I really need to do this conditional stuff recommended in the OpenGL ES 2.0 book? #ifdef GL_FRAGMENT_PRECISION_HIGH precision highp float; #else precision mediump float; #endif Or can I just stick with declaring it 'highp' and be done with it? Most Intel GPUs don't support it; so that would be most of the laptop market. I don't know what the

How can I correctly unpack a V210 video frame using GLSL?

拥有回忆 提交于 2019-12-05 23:50:20
问题 I have 10-bit YUV (V210) video frames coming in from a capture card, and I would like to unpack this data inside of a GLSL shader and ultimately convert to RGB for screen output. I'm using a Quadro 4000 card on Linux (OpenGL 4.3). I am uploading the texture with the following settings: video frame: 720x486 pixels physically occupies 933120 bytes in 128-byte aligned memory (stride of 1920) texture is currently uploaded as 480x486 pixels (stride/4 x height) since this matches the byte count of

Selective nvidia #pragma optionNV(unroll all)

雨燕双飞 提交于 2019-12-05 23:14:35
I'm playing around with nvidia's unroll loops directive, but haven't seen a way to turn it on selectively. Lets say I have this... void testUnroll() { #pragma optionNV(unroll all) for (...) ... } void testNoUnroll() { for (...) ... } Here, I'm assuming both loops end up being unrolled. To stop this I think the solution will involve resetting the directive after the block I want affected, for example: #pragma optionNV(unroll all) for (...) ... #pragma optionNV(unroll default) //?? However I don't know the keyword to reset the unroll behaviour to the initial/default setting. How can this be done

Passing an array of vec2 to shader in THREE.js

时光总嘲笑我的痴心妄想 提交于 2019-12-05 21:54:23
I've been searching the web for a while now and did not find the correct answer yet. I found the list of uniform types THREE.js uses, and I think the following code should be correct. At the last line I define an uniform array of Vector2. uniforms: { "center": { type: "v2", value: new THREE.Vector2( 0.5, 0.5 ) }, "aspectRatio": { type: "f", value: null }, "radius": { type: "f", value: 0.1 }, "pointList": { type: "v2v", value: [] }, }, In my js script I pass this array as follows. This should work too, I guess: // Add effects effect = new THREE.ShaderPass( THREE.MetaBalls2D ); effect

Converting GLSL modern OpenGL 3.2

早过忘川 提交于 2019-12-05 21:06:57
I'm following a freetype tutorial on wikibooks on a mac running 10.9 with Xcode 5. I have it running with shader version 120 but I want to use some modern features so I set the SDL hints to OpenGL 3.2 and convert my shaders to 150. The problem is in version 150, the use of texture2D will prevent the shader from compiling. Here is the version 120 of the shaders: const GLchar* vTextSource = "#version 120\n" "attribute vec4 coord;" "varying vec2 texcoord;" "void main(void) {" " gl_Position = vec4(coord.xy, 0, 1);" " texcoord = coord.zw;" "}"; const GLchar* fTextSource = "#version 120\n" "varying