Hot answers tagged glsl
5
You can't do it with just that information. You need more.
For example, I assume you also actually have a the world, view, and projection transformation matrices available to you. In that case, you can compute the vertex's position in view space by multiplying it by the world matrix and then by the view matrix.
Since you're in view space, the eye is at (0, ...
5
If you mean: Can I compute a variable in the first fragment and pass it around? No, not like that. The fragments are processed in parallel.
If you need to do that, compute the variable CPU side and pass it in as a uniform. If you needed to do a lot of computation you could output to a texture or a buffer and then read it back, but you only need one float ...
2
As you already have a delta time in seconds, and also the 'speed' of the texture in whatever units you use per second, then you simply need to move the texture by the speed (0.001) multiplied by the delta in seconds. Say if you have a delta of 0.5 seconds, the movement would be 0.0005, which is what you want.
To implement it in your program, change
...
2
This is solved in diffrent ways, some solve it by using #ifdefs, some solve it by branching And some solve it by having input values that updates per every object so you store an overall painting scheeme for the defualt shader.
and when it comes to scale of the game, it´s actualy no way around this. You will need more shaders for diffrent materials and ...
2
How do I use the engine's vertex shader while still allowing the programmer to provide his/her own vertex shader for other calculations in their game? What is the normal approach here?
There is no normal approach because engines generally don't let you do that.
Generally speaking, engines take one of two approaches: either the user provides none of a ...
2
Higher-end engines typically use a higher-level abstraction than an individual shader.
Simpler games just allow each model/material to specify shaders and then to use HLSL includes or the like to allow all common code to be easily reused. You'll need a bit of discipline in applying the shader includes properly and it can be a bit repetitive sometimes, but ...
1
Unless you are pre-transforming all of your vertex data, vertices should come into the vertex shader in object/model space. This is typically where the vertices are converted into screen space by transforming the vertex by the world, view, and projection matrices. If you want to perform operations on the vertices in world space, then either pass through the ...
1
This is just using regular old sine and cosine to step around the circumference of a circle and place points. You just need to know the center of the circle, the radius and how many points you want. The following pseudo code will output a set of points that make up the positions of dots you need to make a circle of points:
circleXY(Vector3f center, float ...
1
As Lewis said, fragments are processed in parrallel, each fragment shader is executed once per fragment. In GLSL there are three ways to communicate between your application and your shaders:
uniform variables: variables that are set from user code, but only are allowed to change between different glDraw* calls. Uniforms can be queried and set by the ...
1
To answer my own question, here's what I got working:
The scaling in the GLSL vertex shader is:
gl_PointSize = (heightOfNearPlane * pointSize) / gl_Position.w;
Where you compute your heightOfNearPlane using the viewport height and the field-of-view angle you constructed the perspective matrix with:
float fovy = 60; // degrees
int viewport[4];
...
Only top voted, non community-wiki answers of a minimum length are eligible
