glsl

How to create fog using Open GL ES 2.0 or WebGL?

元气小坏坏 提交于 2019-12-06 08:31:31
问题 I would like to create a fog effect for my game but I can't find any tutorials on how to do it using OpenGL ES 2.0. If anyone has links to tutorials, can provide an explanation, or source code I would be grateful. 回答1: There's a section on replicating fixed-function fog using shaders in the OpenGL ES 2.0 Programming Guide on page 224. The source code is available on the google code project (MIT License). It's a gigantic rendermonkey XML file, but the shader source embedded in it is pretty

Linearize depth

元气小坏坏 提交于 2019-12-06 07:59:56
In OpenGL you can linearize a depth value like so: float linearize_depth(float d,float zNear,float zFar) { float z_n = 2.0 * d - 1.0; return 2.0 * zNear * zFar / (zFar + zNear - z_n * (zFar - zNear)); } (Source: https://stackoverflow.com/a/6657284/10011415 ) However, Vulkan handles depth values somewhat differently ( https://matthewwellings.com/blog/the-new-vulkan-coordinate-system/ ). I don't quite understand the math behind it, what changes would I have to make to the function to linearize a depth value with Vulkan? The important difference between OpenGL and Vulkan here is that the

How to input video (frames) into a GLSL shader

人走茶凉 提交于 2019-12-06 07:38:21
I'm trying to do video processing using GLSL. I'm using OpenCV to open a video file up and take each frame as a single image an then I want to use each frame in a GLSL shader What is the best/ideal/smart solution to using video with GLSL? Reading From Video VideoCapture cap("movie.MOV"); Mat image; bool success = cap.read(image); if(!success) { printf("Could not grab a frame\n\7"); exit(0); } Image to Texture GLuint tex; glGenTextures(1, tex); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, tex); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image.cols, image.rows, 0, GL_BGR, GL_UNSIGNED

Passing uint attribute to GLSL

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-06 07:32:54
问题 I'm trying to pass a bunch of consecutive unsigned ints as attribute to my GLSL shader. So far I came up with s_number = glGetAttribLocation(shader, "number"); numberData = new GLuint[dotAmount]; for (GLuint i = 0; i < dotAmount; i++) { numberData[i] = i; } glGenBuffers(1, &vertBuf); glBindBuffer(GL_ARRAY_BUFFER, vertBuf); glBufferData( GL_ARRAY_BUFFER, sizeof(dotAmount), numberData, GL_STATIC_DRAW ); The rendering function is glUseProgram(shader); [..] glEnableVertexAttribArray(s_number);

Mapbox Android SDK crash - “java.lang.Error: Vertex shader fill failed to compile”

谁都会走 提交于 2019-12-06 07:29:10
After upgrading my Android Studio version to 2.1.3, my application crashes every time I launch it. More precisely, it crashes when trying to load my Mapbox View (that was perfectly working before that). I did some research, and it seems to be a known issue, but I couldn't find any workaround to pass through it... I think it MAY be a problem with the Emulator only, but for now I couldn't try on a lot of physical devices, so I'm not sure about that. But anyway, I really need to use the emulator to debug my app. If someone has any information about that it will be really helpful. Thank a lot!

Which GLSL ES extensions are available on various iOS devices?

杀马特。学长 韩版系。学妹 提交于 2019-12-06 07:18:19
I'm looking for a list of all extensions available on any iOS devices (and which are available on which device). I haven't found the right page in the apple docs despite a lot of searching, but I'm sure it's there somewhere. Any pointers? C0deH4cker This code should print out all extensions: NSString *extensionString = [NSString stringWithUTF8String:(char *)glGetString(GL_EXTENSIONS)]; NSArray *extensions = [extensionString componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; for (NSString *oneExtension in extensions) NSLog(@"%@", oneExtension); Source: http:/

How should you efficiently batch complex meshes?

爱⌒轻易说出口 提交于 2019-12-06 06:42:13
问题 What is the best way to render complex meshes? I wrote different solutions below and wonder what is your opinion about them. Let's take an example: how to render the 'Crytek-Sponza' mesh? PS: I do not use Ubershader but only separate shaders If you download the mesh on the following link: http://graphics.cs.williams.edu/data/meshes.xml and load it in Blender you'll see that the whole mesh is composed by about 400 sub-meshes with their own materials/textures respectively. A dummy renderer

Shader - Simple SSS lighting issue

故事扮演 提交于 2019-12-06 06:29:31
I am trying to create a simple subsurface scattering effect using a shader but I am facing a small issue. Look at those screenshots. The three images represents three lighting states (above surface, really close to surface, subsurface) with various lighting colors (red and blue) and always the same subsurface color (red). As you might notice when the light is above the surface and really close to this surface its influence appears to minimize which is the expected behavior. But the problem is that is behaves the same for the subsurface part, this is normal according to my shader code but in my

How fragment shader determines the number of fragments from vertex shader output?

你说的曾经没有我的故事 提交于 2019-12-06 06:07:22
问题 I'm familiar with vertex and fragment shaders but still confused about how a fragment shader determines the amount of fragments from the output of vertex shader. If I have 3 vertices and I draw a triangle primitive in GLSL, then vertex shader will run three times for every vertex and then fragment shader will run many times (depending upon the number of fragments, once for each fragment). I want to know how fragment shader determines the fragments? Does it use gl_Position? If I don't set gl

Blending anti-aliased circles with regl

橙三吉。 提交于 2019-12-06 05:37:21
问题 I'm rendering circles using regl, and have three goals: The canvas should be transparent, showing HTML content behind it. Circles should be antialiased smoothly. Overlapping circles should look reasonable (blend colors, no corners showing) So far, I have this: Glitch code and demo. UPDATE: The demo links now reflect the working, accepted answer. Code below is unchanged. index.js const regl = require('regl'); const glsl = require('glslify'); const vertexShader = glsl.file('../shaders/vertex