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 jamesflowerdew · Aug 14, 2014 at 02:13 PM · shaderlabsurface

Vert/Frag, Fixed function, Surface shaders, unitycg.inc etc?

Hi,

I've been working with shaders a while now and am still utterly baffled by some core understanding of what's going on.

My limited understanding (or lack therein) is:

-Fixed function shaders work on pretty much anything, they are usually the fastest.

-vert/frag shaders work on modern machines, and can be faster than the above, but won't work on "dinosaurs" (a unity definition that sometimes seems to span everything over 4 years old or costing less than a grand).

-Surface shaders are prettied up vert/frag shaders with a load of unity specific stuff thrown in to handle lights, bumpmaps etc for you, again forget older/simpler devices.

Excuse my layman's descriptions above, but the terminology I'm finding online is at least half of the problem. Also excuse the fact that it may be utterly wrong, but it is based on months of exploration (unity docs/nvidia/jessys videos/trial and error).

Barr the work of Jessy, which is coherent and useable, Much documentation seems to leap from glaringly obvious "this is a colour" statements and a few unusably simple examples to the wildly obtuse with nothing in between, and unity's shaders have a tendency to rely on libraries that are hard to find and easy to conflict with (I spent a week discovering that I couldn't use the worldNormal variable for triplanar uv testing because it needs to remain untouched for something happening specifically under the hood in unity).

I recently found this, which really confused me:

 Properties {
         _MainTex ("Base (RGB)", 2D) = "white" {}
     }
 SubShader {
         Tags { "Queue" = "Transparent" "IgnoreProjector"="True"  }
         
         Pass {
 
             CGPROGRAM
 // Upgrade NOTE: excluded shader from OpenGL ES 2.0 because it does not contain a surface program or both vertex and fragment programs.
 #pragma exclude_renderers gles
 
             #pragma vertex vert
             #include "UnityCG.cginc"
             
 
             struct v2f {
                 float4 pos : POSITION;
                 float fog : FOGC;
                 float4 color : COLOR0;
                 float2 uv : TEXCOORD0;
             };
 
             v2f vert (appdata_full v) {
                 v2f o;
                 
                 o.pos = mul(UNITY_MATRIX_P, mul(UNITY_MATRIX_MV, float4(0.0, 0.0, 0.0, 1))+ float4(v.vertex.x, v.vertex.y, v.vertex.z, 0.0));
             
                 o.fog = o.pos.z;
                 o.uv.x = v.texcoord.x;
                 o.uv.y = v.texcoord.y;
                 o.color = v.color;
                 return o;
             }
             ENDCG            
 
             ColorMask rgb
             Blend SrcAlpha OneMinusSrcAlpha
             ZWrite Off Cull Off
             
             AlphaTest Greater 0
             SetTexture [_MainTex] { combine texture * primary, texture }
         }
     }
     
     Fallback Off
 }
 

It's actually not what I need, but I got fairly excited at the ability to access and possibly bypass vertex/normal data, for this problem, and more.

What firstly confuses me here is that it mixes a vert cg-function with a fixed function shader. is there any beneit to this?

Secondly, even disregarding the "UNITY_MATRIX_P"etc stuff this shader needs unitycg.inc. Again, why?

Can shaders be "coded" at all and yet work within older environments?

If so, an example of a fixed function shader (or other kind of shader that's DX7 frendly) with hacked vertex data and no funny includes would be really appreciated.

What variables and edits can be pushed through a fixed function shader, before it becomes unusable on old machines and thus a pointless and academic pursuit?

All I want to do at this point is access a vertex/face normal in a fixed function shader and either ignore it, or force it to a given unchanging value, but generally some good documentation written in plain english would be a godsend If anybody knows of it.

I can achieve quite a lot with surface and fragment shaders now, but my emphasis as a web developer is on speed and compatibility (old pcs, old phones, Integrated graphics cards) so getting maximum leverage out of fixed function shaders is what I think I need.

Any help here greatly appreciated.

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

0 Replies

· Add your reply
  • Sort: 

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

21 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 avatar image avatar image avatar image avatar image

Related Questions

Simple Cg shader not compiling 1 Answer

How do I incorporate per-vertex lighting data into a surface shader? 0 Answers

Is Vertex Lighting still computed if no lights are in the scene? 0 Answers

Bump Map, Specular and Shininess Shader 0 Answers

ShaderLab: Adding functions. 1 Answer


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