manual lens distortion fix using vertex shader - glsl

Need help with manual lens distortion fix using vertex shader.
I would like to add lens distortion fix using vertex shader as available here
https://github.com/googlesamples/tango-examples-unity/blob/master/TangoWithCardboardExperiments/Assets/Cardboard/Distortion/CardboardDistortion.cginc
Since I didnt use UNITY engine,I need to know how to calculate the five constant use in the function.
float4x4 _Undistortion;
float _MaxRadSq;
float _NearClip;
float4x4 _RealProjection;
float4x4 _FixProjection;
i would be appreciated if anyone could point me to some infos or explanation.
Thanks.

Here is the example of how you use that shader program.
I'm not familiar with Unity Shaders either, but it seems like those variables starts with underscore are called shader properties.
Search this repository with "Shader.SetGlobal" or the variable name and I'm pretty sure you will find other variables as well.
https://github.com/googlearchive/tango-examples-unity/blob/039b3d6a3d05d4fd86e0754690d61a4690aeb5a9/TangoWithCardboardExperiments/Assets/Cardboard/Scripts/CardboardEye.cs

Related

How to disable weighted interpolation GLSL? (how to just average the vertex values)

I would like to have the normal vector of the fragments on a single face in my mesh be the same for all fragments.
Due to the way my engine works I cannot enable provoking vertices. Don't bring them up in your reply, i've looked into it already.
I'd like all fragments to take the three values of that face and average them without weighting, interpolation, etc.
To clarify:
I want a variable output from the vertex shader to the fragment shader with strict averaging, no interpolation. Is there some qualifier or technique I could use in OpenGL to achieve this?
I would be even happier if i could just get the values from each vertice and interpolate them myself, I have some awesome shader ideas if I can!
Thanks.
khronos.org/opengl/wiki/Type_Qualifier_(GLSL)#Interpolation_qualifiers

How hard would it be to write this shader? Multipoint shadow lighting

So, I have a simple project right now. Basically its just a bunch of cuboids that are all axis alligned... so it has really simple geometry.
Anyway I am considering adding a better shader to it. Currently I am using the "flat shader" that is a stock shader in GLShaderManager. It is coloring everything with a flat color. However I would love if I could build a shader like the following.
Basically I want a shader that has an array of point lights at various positions with varying intensities.
Probably defined like this.
struct Light {
float x;
float y;
float z;
float intensity;
};
Light Lighting[20];
And basically based on the level geometry and lights, I would love to simulate basic lighting and shadows, also it would be cool to have a circle under the player (like the player is actually their).
How hard would this be to make? How would I pass it my level geometry and light array. (note even though each cuboid is its own QUADS batch it will be easy to make any kind of variable that stores the data).
I am using Glew, GLTools, GLShaderManager, GLBatch, visual studio 2010, probably whatever "GSHL".
If you could just let me know how complicated a shader like this would be let me know. Also if it is easy to find a shader that works like this online if you could link it.
Also what are the difference between the two types of shaders? (Vertex, and fragment).
I would say it's relatively simple, but the thing about modern GL is that the initial learning curve is quite steep. At first it seems like you have to roll up your sleeves and learn how to do everything (essentially true) but later, it starts to seem like it made things easier than ever before with much more predictable behaviors since you're in the driver's seat.
One of the first things you want to learn to do is understand how to specify attributes from CPU to GPU. For attributes which don't vary on a per-vertex or per-fragment basis such as your light positions and intensities, you want uniform attributes. Check out examples utilizing the glUniform* functions to see how to do this. This will allow you to then experiment, passing values from the CPU side to the GPU side and then seeing how they affect the shader to accelerate your learning.
After that, it's worth learning how direct lighting is computed given a ray bouncing off a surface with phong shading, separating ambient, diffuse, and specular terms.
Later you might even want to store this light data into an environment map. That'll give you the ability to use as many lights as you want without affecting the speed of the shader.
About vertex vs. fragment shaders, vertex shaders compute things on a vertex-by-vertex basis, including data for the fragment shader to then use. The fragment shader is kind of like a pixel shader (in HLSL, it's actually just called a 'pixel shader'). It deals with rasterizing what's in between those vertices and is operating on a pixel-by-pixel basis (however with some potential overdraw). Often for lighting, the real heart of the logic will be in the fragment shader, while the vertex shader serves as an intermediary step to compute all the relevant values for the fragment shader to interpolate and use. The vertex shader is part of the 3D geometry pipeline, while the fragment shader is part of 2D rasterization.
It shouldn't take too long or be too hard to get the hang of this, but you want to approach this kind of slowly and in babysteps. There's a lot of setup work involved in establishing a lighting/shading pipeline for your software with the precise characteristics you want, and for the final work, you want to kind of plan ahead. So it's good to establish a separate scrap project and start experimenting away to figure out how things work.

Modifying a tessellation vertex in DirectX Shader

I've followed the tessellation tutorial on Rastertek's website and have managed to get it working.
I'm just wondering if its possible to modify a subdivisions vertex in one of the shader files.
The result I'm looking for is to divide up a plane into subdivisions and then manipulate the subdivisions to create waves, is that possible or have I completed missed something? :)
Found out how to do it.
Modifications can be made after the vertex position has been calculated in the domain shader.
:D

Three.js and GLSL - Kaleidoscope shader

I'm starting and experimenting with GLSL and WebGL. Using Three.js r52.
I have a simple plane geom mesh with a Shader material.
I'm already passing a texture as uniform property, and I was able to manipulate it in different ways.
But, when I try to experiment the shaders from Shader Toy, more specifically this one http://www.iquilezles.org/apps/shadertoy/?p=Kaleidoscope , doesn't work the same way.
I think has something to do with positions.
Anyone have a clue about what could be the problem?

Using both programmable and fixed pipeline functionality in OpenGL

I have a vertex shader that transforms vertices to create a fisheye affect. Is is possible to just use just the vertex shader and use fixed pipeline for the fragment portion.
So basically i have an application that doesnt use shaders. I want to apply a fisheye affect using a vertex shader to transform all vertices, and then leave it to the application to take care to lighting, texturing, etc?
If this is not possible, is it possible to get a fisheye affect by messing with the contents of the gl back buffer?
Thanks
If your code is on fixed function, then what you described is a problem - that's why having your graphics code in shaders is good: they let you change anything easily. Remember to use them in your next project. :)
OK, but for this particular I assume that you don't want to rewrite your whole rendering from scratch to shaders now...
You mentioned you want to have a "fisheye effect". Seems like you're lucky, because I believe you don't need shaders for that effect! If we're talking about the same effect, then you can achieve it just by replacing the GL_PROJECTION matrix from OpenGL's fixed function to a perspective matrix with a wider angle of vision.
Yes, it's possible, altough some cards (notably ATI) don't support using a vertex shader without a fragment shader.