Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Diet-Chugg · May 17, 2013 at 07:09 PM · optimizationfragment

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!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
5
Best Answer

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).

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Diet-Chugg · May 17, 2013 at 07:36 PM 0
Share

great answer. Thanks again!

avatar image Fattie · May 18, 2013 at 08:23 AM 0
Share

@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

avatar image GKiernozek · Jul 13, 2017 at 02:32 PM 0
Share

which game? :)

avatar image Jwizard93 · Jul 13, 2017 at 04:44 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges