glsl

Passing custom type (struct) uniform from Qt to GLSL using QGLShaderProgram

筅森魡賤 提交于 2019-12-05 12:26:49
I defined a struct for light parameters which contains two vectors. The struct is defined in both C++ and GLSL in an analogous way (note: QVector3D encapsulates 3 float s, not double s): C++ host program: struct LightParameters { QVector3D pos; QVector3D intensity; }; Fragment Shader: struct LightParameters { vec3 pos; vec3 intensity; }; In the fragment shader, I also define the following uniforms. The numbers of lights is limited to 8, so the uniform array has a constant size (but only numLights are actually used): const int maxLights = 8; uniform int numLights; uniform LightParameters lights

GLSL: Can't get uniforms location

孤街醉人 提交于 2019-12-05 10:49:28
My problem is fact that I can't get some uniforms location, when location of others I get without problems. For example I have in VS uniforms called "MVP" and "Model" and I have "MVP" location without problems, but I don't have "Model" location which I use symmetrically. In the same manner I can't get location of fields from Light structure in FS. Its code passing data into shader: bool Shader::SetShaderParameters(mat4 MVPMatrix,mat4 Model,GLint textureUnit) { GLuint matrixLocation = glGetUniformLocation(programID,"MVP"); if(matrixLocation==-1) return false; glUniformMatrix4fv(matrixLocation,1

Uniform vertex displacement for skinned mesh shader (Animated outline, Three.js)

荒凉一梦 提交于 2019-12-05 10:44:00
I think I've solved implementation of rendering borders/outlines over meshes in Three.js, a technique many games use for highlighting objects/characters. Diablo 1 and 3 for example Here are details and demo of my solution . Now what remains to be done are animated meshes (for characters etc). The problem is, skinned mesh is animated with a vertex shader and I also used a shader to scale (displace) the mesh out along the normals. It might be pretty straight-forward but unfortunately my math skills are pretty much non-existent. The problem So to have the meshes scaled up AND animated in the

GLSL 4.1 with gl_ModelViewProjectionMatrix

我怕爱的太早我们不能终老 提交于 2019-12-05 10:42:40
I am working on a glsl shader program as part of a plugin that runs inside a "closed source" application. The application (maya) is written using opengl 2.1, but our graphics cards support opengl/glsl 4.1 and I want to use tessellation and geometry shaders in my program. The application sets up the opengl viewport and the traditional model/view matrix stack and I do not have control over that part of the code. My pass-through vertex shader uses GLSL 1.2 and works fine: // GLSL VERTEX SHADER #version 120 void main () { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; } My pass-through

Disable GLSL compiler optimization

只谈情不闲聊 提交于 2019-12-05 10:32:16
I am using OpenGL 4.2 with GLSL 420 .I need to prevent the GLSL compiler from optimizing out unused uniforms as those serve for occasional tests. I have tried to put: #version 420 #pragma optimize (off) ... ...... But it seems to have no effect.The compiler still cleans all the unused uniforms.I am running on NVidia drivers v319 on Linux with GeForce 680GTX Andon M. Coleman Inactive uniform determination is not an optimization. It is a consequence of how unextended GLSL programs work, they are compiled and then linked together and because of this implementations know exactly which paths

Replacement for gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;

末鹿安然 提交于 2019-12-05 10:32:11
问题 There are a couple of questions like this, but I still haven't really understood. I was coding with OpenGL over 10 years ago and noticed how difficult it is to get into modern OpenGL. The OpenGL.org page is a horrible mess when it comes to examples, you never know what version it is, any version seems to be mixed up in various code examples. Alright, I have an old code I want to update to OpenGL >3 at least. So first thing I did was to move on from glVertex3fv to finally make it with

GLSL Error #132 Syntax error: “gl_position” parse error

只愿长相守 提交于 2019-12-05 08:25:26
I've tried my best to find the answer to this problem or any error i had made in the code, but i just couldn't find anything.. If this helps, i have a sapphire Radeon HD 6950 graphics card and it uses an AMD Radeon HD 6900 series driver. The Error Message: Wed May 27 13:55:50 CDT 2015 INFO:Use Java PNG Loader = true Vertex shader failed to compile with the following errors: ERROR: 0:26: error(#132) Syntax error: "gl_Position" parse error ERROR: error(#273) 1 compilation errors. No code generated Could not Compile Shader. Vertex Shader: #version 400 core in vec3 position; in vec2 textureCoords;

OpenGLES 2.0: gl_VertexID equivalent?

放肆的年华 提交于 2019-12-05 08:16:18
I'm trying to create a grid of points by calculating vertex positions dynamically, based on their index in the array of vertices sent to the shader. Is there an equivalent of the gl_VertexID variable that I can call from within my shader? Or another way of accessing their position in the array without having to send more data to the GPU? Thank, Josh. Here's my vertex shader: attribute vec4 vertexPosition; uniform mat4 modelViewProjectionMatrix; vec4 temp; uniform float width; void main() { temp = vertexPosition; // Calculate x and y values based on index: temp.y = floor(gl_VertexID/width);

Shader's function parameters performance

只谈情不闲聊 提交于 2019-12-05 08:09:11
I'm trying to understand how passing parameters is implemented in shader languages. I've read several articles and documentation, but still I have some doubts. In particular I'm trying to understand the differences with a C++ function call, with a particular emphasis on performances. There are slightly differences between HSLS,Cg and GLSL but I guess the underline implementation is quite similar. What I've understood so far: Unless otherwise specified a function parameter is always passed by value (is this true even for matrix?) Passing by value in this context hasn't the same implications as

Full setup of Transform Feedback(openGL)

随声附和 提交于 2019-12-05 07:59:10
GLSL 1.50, openGL 3.3. I've been lately trying to get my tranform feedback working but without success. I still receive error after glBeginTranformFeedback() and as I haven't found any full working code I have stacked up my knowledge with some code that I found and documentation, it should be working well by now but I am missing something. So if anybody got full code (initializing of buffers, setting up, updating, rendering, reading back) it would definitelly help and if you don't but know what's going on you could take look at my code. I excluded some benchmarking, handling of windows and it