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
2
Question by clamp · Apr 05, 2011 at 04:29 PM · shaderssurface

unity shaders: what is surf?

hello, to my understanding a CG shader must always contain a vertex program and a fragment program.

but when looking at unity shaders i sometimes see

#pragma surface surf Lambert

and then the implementation of this surf function

void surf (Input IN, inout SurfaceOutput o) { ... }

what exactly is this surface function as opposed to normal shaders?

thanks!

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

2 Replies

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

Answer by xCRKx TyPHooN · Apr 05, 2011 at 05:56 PM

To my understanding, surface shaders are the top most layer of a shader. The vertex and fragment programs still exist in the lower levels, its just handled for you when you use the syntax. Ultimately, this allows you to design and write your own shaders quickly without the need to write the necessary sub-code. On the flip side, you lose control and flexibility. For a complex shader its probably best to write the shader from scratch using the vertex/fragment functionality.

Here is a good link for surface shaders

Unity Surface Shader Examples

Comment
Add comment · 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
2

Answer by Owen-Reynolds · Apr 05, 2011 at 05:21 PM

Not exactly an answer, but you are allowed to write just a vert or fragment program by itself.

Without any shader code, the graphics card runs the "built-in" vertex and fragment shaders. They do about what you think -- the default VS puts the vert where the camera should see it, passes along one set of UV coords, and the normal. The default FragS applies one texture with diffuse lighting.

There are piles of switches you can set, like turning on specular, setting specular color, setting an extra texture (with a required setting for how they combine.) ShaderLab code is an easyish way to set those switches. Of course, the settings don't affect your shaders. They are for the default shaders only, which your own Vert or Frag shaders replace.

DISCLAIMER: I've used OpenGL to do the stuff below, but not ShaderLab

Suppose you just want to wiggle the verts around. You write your vert shader, and then request "the built-in shader with settings for Lambert lighting" (I believe Lambert was the first to write a diffuse only, no specular yet.)

Suppose you just want to wavy-blend 6 textures on a sin wave. You write only the fragment shader and say "set up the default VS that sends me 6 UVs."

In theory, using a built-in might run faster. Using a built-in with 20 settings to accomplish something you could do in two lines of shader code might run faster or slower. An Andriod or Iphone might prefer built-in shaders more or less than a PC would.

Comment
Add comment · 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

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

No one has followed this question yet.

Related Questions

Extruded Surface Shader + Inner Fill Color 0 Answers

Can vertex colours be SET in a surface shader? Or must it be done through code? 1 Answer

Shader add vertex displacement 0 Answers

How can I get shadows in a transparent Surface Shader? 0 Answers

Why does the 3D Text shader show specular at certain angles? 2 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