- Home /
What is a fragment?
I was looking at the Optimizing Graphics Performance http://docs.unity3d.com/Documentation/Manual/OptimizingGraphicsPerformance.html
and it said,"Choose to use less textures per fragment."
So what is a fragment and how can I choose to use less of them?
Thanks for all the help in advance!
Answer by whydoidoit · May 17, 2013 at 07:19 PM
So it's referring to the fragment program in the shader. Shaders (at least in Unity) have basically two things that happen.
1) Every model vertex is run through the vertex program of the chosen shader. This program outputs data that will be consumed per pixel (or fragment) that will actually need to be drawn to the screen. The vertex program provides these outputs per vertex (including the "projection position" of the vertex) and the GPU "interpolates" them for each fragment to be drawn on the screen.
The practical upshot of this is that you configure models by putting things on vertices (like UV coordinates, positions, normals etc) and then the GPU handles making up the faces by working out what values should be used for a particular point on a particular triangle. This is what it passes on to the fragment program.
2) Every fragment between the vertices that is considered visible is coloured by the fragment program. Basically this gets those interpolated vertex outputs and decides what colour the pixel should be.
So for example the fragment program gets passed a coordinate from a texture based on the UVs at the three points that make up the triangle that this pixel is part of, it gets passed any other information that the shader author needs to colour the final pixel.
So if you use basic "Diffuse" there is one texture to be read for the model fragments. That texture is read, the pixel is lit based on the appropriate lights (the number and method is down to the shader) and then the colour is output and that is what is written to the display.
If you use a bumped specular shader then it's got a lot more textures to read from. If you use a reflective shader then that's a bunch of complex lookups too.
The lightest weight shader would be one that used no texture at all! Perhaps using colours set at the vertices to decide on what colour should be supplied to the lighting calculation.
So if you want to reduce the number of textures per fragment, choose shaders that only have 1 texture input - like Diffuse.
For improved performance you can also choose vertex lit shaders because they do the lighting calculation per vertex rather than per pixel, or of course you could have totally unlit textures (which are normally used for 2D graphics, but I saw a great game in 3D using them recently).
Vertex lit shaders are useless if you are using lots of dynamic point or spot lights (though Lightmapping can fix this if your lights and lit objects are static).
@whydoidoit ! urgent attention!
unity serializer customer in need of help for a couple days! :)
http://answers.unity3d.com/questions/457932/unity-serializer-will-not-save-integers-which-have.html
Nice information. I just want to add that there is a difference between a fragment and a pixel, though. They are often treated the same in some documentation but they are not the same. I.$$anonymous$$ there could be many more fragments operated on than "pixels" in the rendered image. And I do not mean pixels on the screen but rather like the way Texture2D uses pixels to describe the smallest element on the texture.
The reason: something like maybe you have 4 fragments for every "pixel" that will be in the image that way you can use the fragment shader to do some averaging on those four fragments and get a nicer picture in the end.
The only true pixels are the ones on your monitor, the physical electronics that produce light.
Your answer
Follow this Question
Related Questions
Is there a way to write a Demosaicing fragment shader? 1 Answer
Level load Time on Unity Android (Pro) 1 Answer
How to force static batching being performed at runtime? 0 Answers
Webplayer crashes on Chrome, but not on any other browser. Any way to avoid ? 1 Answer
Setting Material Textures at runtime for the rest of the game 0 Answers