glsl

How to send my model matrix only once per model to shaders

隐身守侯 提交于 2019-12-10 12:04:01
问题 For reference, I'm following this tutorial. Now suppose I have a little application with multiple types of model, if I understand correctly I have to send my MPV matrix from the CPU to the GPU (in other words to my vertex shader) for each model, because each model might have a different model matrix from one to another. Now looking at the tutorial and this post, I understand that the call to send the matrix to my shader ( glUniformMatrix4fv(myMatrixID, 1, GL_FALSE, &myModelMVP[0][0]) ) should

GLSL mixing base texture with decal texture at needed place

♀尐吖头ヾ 提交于 2019-12-10 11:58:06
问题 Lets say we texturing quad (two triangles). I think what this question is similiar to texture splatting like in next example precision lowp float; uniform sampler2D Terrain; uniform sampler2D Grass; uniform sampler2D Stone; uniform sampler2D Rock; varying vec2 tex_coord; void main(void) { vec4 terrain = texture2D(Terrain, tex_coord); vec4 tex0 = texture2D(Grass, tex_coord * 4.0); // Tile vec4 tex1 = texture2D(Rock, tex_coord * 4.0); // Tile vec4 tex2 = texture2D(Stone, tex_coord * 4.0); //

How to use glslang

穿精又带淫゛_ 提交于 2019-12-10 11:11:58
问题 I am trying to use glslang to compile glsl shader code to SPIR-V binaries. The glslang project can be found here: https://github.com/KhronosGroup/glslang It works well via the glslangValidator.exe manually in the command line. But i would like to use the c++ interface. I have build the project as described on the github page, and now I am struggling with how to actually use the interface. I would rather not actually include any projects in my solution (I am using Visual Studio), but link the

How to repeatedly update a uniform data for number of objects inside a single Vulkan render pass and make the update synchronized?

五迷三道 提交于 2019-12-10 10:57:27
问题 I'm trying to port my OpenGL 3D game engine to Vulkan. There are large numbers of 3D objects in the game scene and each has it own attributes (model matrix, lights, etc.) and the objects are completely dynamic, which means some 3D objects may come in and others may be removed during the game play. with OpenGL, I grouped 3D object's attribute into a uniform buffer in shader (code simplified): layout(std140, set = 0, binding = 0) uniform object_attrib { vec3 light_pos; vec3 light_color; mat4

Qt & OpenGL OS X: GLSL shader version only 120 on Mountain Lion

若如初见. 提交于 2019-12-10 10:49:04
问题 I'm trying to move some code from the fixed function OpenGL to GLSL shaders, by following along with the arcsynthesis tutorials. First I ran into the issue that version 330 isn't available which after a quick search seemed common, but the recommendation is that 150 should work fine. However, aside from 120 there's no other GLSL shader versions available, is this normal for a 2013 Macbook Air on 10.8.4? Or is there some weirdness going on with the combination of OpenGL + Qt 5 under OS X? EDIT:

Selective nvidia #pragma optionNV(unroll all)

扶醉桌前 提交于 2019-12-10 09:51:55
问题 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

for-loop in shader code working with hardcoded number but not with uniform variable

大城市里の小女人 提交于 2019-12-10 05:37:14
问题 I asked for help about an OpenGL ES 2.0 Problem in this question. What seems to be the answer is very odd to me. Therefore I decided to ask this question in hope of being able to understand what is going on. Here is the piece of faulty vertex-shader code: // a bunch of uniforms and stuff... uniform int u_lights_active; void main() { // some code... for ( int i = 0; i < u_lights_active; ++i ) { // do some stuff using u_lights_active } // some other code... } I know this looks odd but this is

OpenGL: Gamma corrected image doesn't appear linear

强颜欢笑 提交于 2019-12-10 04:59:31
问题 I'm using OpenGL for rendering, and when I write linear values to the default framebuffer (without any gamma correction) they appear linear on my monitor. This goes against everything I thought I knew about gamma correction (as explained here: http://gamedevelopment.tutsplus.com/articles/gamma-correction-and-why-it-matters--gamedev-14466 ). Without gamma correction, I would expect to see mid-range colors darkened non-linearly by my monitor. But here is what I actually see; first with no gamma

GLSL Shader to convert six textures to Equirectangular projection

有些话、适合烂在心里 提交于 2019-12-10 00:31:00
问题 I want to create an equirectangular projection from six quadratic textures, similar to converting a cubic projection image to an equirectangular image, but with the separate faces as textures instead of one texture in cubic projection. I'd like to do this on the graphics card for performance reasons, and therefore want to use a GLSL Shader. I've found a Shader that converts a cubic texture to an equirectangular one: link 回答1: Step 1: Copy your six textures into a cube map texture. You can do

How to select the front triangles of a stl model or a triangular mesh?

淺唱寂寞╮ 提交于 2019-12-09 23:01:13
问题 There is a stl model(triangular mesh). I want to use a adjustable, rectangular shape to make selections. Like below picture. But I don't want the triangles on the other side are selected. That's to say only the visible triangles in the rectangular can be selected. AFAIK, there is a method to do this. First render each triangle with a specific and unique color. Then, retrieve the color of the pixels in the select rectangular, and convert those colors back to the original identifier. The