glsl

GLSL fixed function fragment program replacement

旧时模样 提交于 2019-11-26 09:14:17
问题 When using the OpenGL fixed function pipeline for vertex setup, how a fragment program looks like that is compatible to the fixed function vertex setup? I guess that usually depends on the number of light sources and texture layers etc.. So for example how does a simple non-texture one-lightsource goraud shading fragment program look like that replaces GL\'s fixed function shader? 回答1: While Gouraud shading calculates the light in the the vertex shader, Phong shading calculates the light in

How to correctly linearize depth in OpenGL ES in iOS?

隐身守侯 提交于 2019-11-26 08:53:21
问题 I\'m trying to render a forrest scene for an iOS App with OpenGL. To make it a little bit nicer, I\'d like to implement a depth effect into the scene. However I need a linearized depth value from the OpenGL depth buffer to do so. Currently I am using a computation in the fragment shader (which I found here). Therefore my terrain fragment shader looks like this: #version 300 es precision mediump float; layout(location = 0) out lowp vec4 out_color; float linearizeDepth(float depth) { return 2.0

What is state-of-the-art for text rendering in OpenGL as of version 4.1? [closed]

≡放荡痞女 提交于 2019-11-26 08:38:45
问题 There are already a number of questions about text rendering in OpenGL, such as: How to do OpenGL live text-rendering for a GUI? But mostly what is discussed is rendering textured quads using the fixed-function pipeline. Surely shaders must make a better way. I\'m not really concerned about internationalization, most of my strings will be plot tick labels (date and time or purely numeric). But the plots will be re-rendered at the screen refresh rate and there could be quite a bit of text (not

How to calculate Tangent and Binormal?

夙愿已清 提交于 2019-11-26 08:00:34
问题 Talking about bump mapping, specular highlight and these kind of things in OpenGL Shading Language (GLSL) I have: An array of vertices (e.g. {0.2,0.5,0.1, 0.2,0.4,0.5, ...}) An array of normals (e.g. {0.0,0.0,1.0, 0.0,1.0,0.0, ...}) The position of a point light in world space (e.g. {0.0,1.0,-5.0}) The position of the viewer in world space (e.g. {0.0,0.0,0.0}) (assume the viewer is in the center of the world) Now, how can I calculate the Binormal and Tangent for each vertex? I mean, what is

How to recover view space position given view space depth value and ndc xy

六眼飞鱼酱① 提交于 2019-11-26 05:36:55
问题 I am writing a deferred shader, and am trying to pack my gbuffer more tightly. However, I cant seem to compute the view position given the view space depth correctly // depth -> (gl_ModelViewMatrix * vec4(pos.xyz, 1)).z; where pos is the model space position // fov -> field of view in radians (0.62831855, 0.47123888) // p -> ndc position, x, y [-1, 1] vec3 getPosition(float depth, vec2 fov, vec2 p) { vec3 pos; pos.x = -depth * tan( HALF_PI - fov.x/2.0 ) * (p.x); pos.y = -depth * tan( HALF_PI

Why transforming normals with the transpose of the inverse of the modelview matrix?

痞子三分冷 提交于 2019-11-26 05:18:47
问题 I am working on some shaders, and I need to transform normals. I read in few tutorials the way you transform normals is you multiply them with the transpose of the inverse of the modelview matrix . But I can\'t find explanation of why is that so, and what is the logic behind that? 回答1: Take a look at this tutorial: https://paroj.github.io/gltut/Illumination/Tut09%20Normal%20Transformation.html You can imagine that when the surface of a sphere stretches (so the sphere is scaled along one axis

How does this faking the light work on aerotwist?

余生颓废 提交于 2019-11-26 04:55:54
问题 I am trying to read up this tutorial: https://aerotwist.com/tutorials/an-introduction-to-shaders-part-2/ but I am not able to follow up. Basically the code creates a directional light by using shaders that run directly on the GPU. This is the code: // same name and type as VS varying vec3 vNormal; void main() { // calc the dot product and clamp // 0 -> 1 rather than -1 -> 1 vec3 light = vec3(0.5,0.2,1.0); // ensure it\'s normalized light = normalize(light); // calculate the dot product of //

How to implement 2D raycasting light effect in GLSL

邮差的信 提交于 2019-11-26 03:59:35
问题 This was originally asked by @sydd here. I was curious about it so I try to code it but It was closed/deleted before I could answer so here it is. Question: How to reproduce/implement this 2D ray casting lighting effect in GLSL ? The effect itself cast rays from mouse position to every direction, accumulating background map alpha and colors affecting the pixels strength. So the input should be: mouse position background RGBA map texture 回答1: Background map Ok I created a test RGBA map as 2

Passing a list of values to fragment shader

南笙酒味 提交于 2019-11-26 03:36:51
问题 I want to send a list of values into a fragment shader. It is a possibly large (couple of thousand items long) list of single precision floats. The fragment shader needs random access to this list and I want to refresh the values from the CPU on each frame. I\'m considering my options on how this could be done: As a uniform variable of array type (\"uniform float x[10];\"). But there seems to be limits here, on my GPU sending more than a few hundred values is very slow and also I\'d have to

OpenGL - How to create Order Independent transparency?

被刻印的时光 ゝ 提交于 2019-11-26 02:39:15
问题 I\'ve been working on a game engine for educational purposes and I came across this issue I cannot seem to find an answer for: Alpha channel only works for objects that have already been drawn before the object that has the alpha channel (For example: in a scene with 3 objects, let\'s say a cat, a dog and a bottle(transparent). both the cat and the dog are behind the bottle; the dog is drawn first, the bottle second, the cat third. only the dog will be seen through the bottle). Here\'s a