Hot answers tagged fragment-shader
5
A fragment pipe is a portion of the pixel pipeline that processes fragments. The more you have, the more you can parallelize fragment rendering. More is better, but like many things you get diminishing returns. You can learn more about the graphics pipeline here. The pixel pipeline is what's responsible for creating what goes in each pixel on screen, ...
4
CG (as your tags indicate) supports the WPOS semantic in some profiles, for example this one. An input parameter bound to the WPOS semantic will get the window position (with the origin in the lower-left) of the fragment.
Other languages, like GLSL, have similar predefined uniforms or inputs (gl_FragCoord for example), although the specifics of their value ...
4
Let's provide a complete answer.
First:
texture2D(TextureUnit, vec2(gl_TexCoord[0]))
Since we're talking about RGTC, we're in GL 3.x+ land. You shouldn't be using texture2D anymore; just use texture. That way, if you change the type of TextureUnit, everything will still work. But that's minor.
Also, vec(gl_TexCoord[0]) is better spelled ...
3
From the shader's perspective, a block-compressed texture like BC4/RGTC1 behaves just like any other texture; the GPU hardware automatically handles the block decompression and filtering on your behalf. BC4 is a single-channel texture, so you are correct: use texture2D() -- or texture() in more recent GL versions -- and the data you want will be in the ...
3
In case of having one-channel images you should use texture2D as follows
float TexColor = texture2D(TextureUnit, gl_TexCoord[0]).r
which basically forces to read only the first (and only) channel of the image and stores its value into TexColor. At least, this is how I handle shadow maps for example (which are stored in one-channel images.
2
I've decided to go with a fragment shader approach via discontinuity filtering of the depth buffer. Reasons for this are:
World vertex count is very, very high due to immense view distances, even with mesh LoD;
I am doing a number of other fragment shader operations, such as DoF blur which can benefit by the same structures (box or gaussian ...
1
You're not interpolating the texture coordinates at all. You're sampling a single point at all times.
f(N) = (N + 0.5) / 256
N = 0 -> 0.001953125
N = 64 -> 0.251953125
N = 128 -> 0.501953125
So in case of (0,0) you're always sampling a point near top corner, and with (128,128) you're sampling a single point near the center, but somewhat on the ...
1
No. Object culling (discarding a whole mesh) must be done before submitting your drawing commands to the GPU.
Remember that the shaders are running at various stages of the pipeline. The vertex shader is run after submitting objects to the GPU. And operates on the vertex level only - it has no cinder of any other vertices, primitives, or the rendered ...
1
Well, I'm pretty sure, the fragment shader doesn't have a concept of a mesh. I'm mostly sure the vertex shader doesn't either. You could update the vertex shader to let it know which mesh it's processing via a uniform variable, but I assume you want something all GPU side.
So I believe the answer is, no, it does not. However, I'd love to be wrong, I think ...
Only top voted, non community-wiki answers of a minimum length are eligible