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
0
Question by Oliver Eberlei · Jan 17, 2012 at 07:32 PM · shadershaderlabconversionsurface shader

Converting Fixed Function Shader to Surface Shader

Hi everyone,

I am trying to convert a custom fixed function shader to a surface shader to get realtime shadows working but I am stuck on one command, which is

 SetTexture [_MainTex] 
 {
     Combine previous * primary DOUBLE
 }

The previous part is

 fixed4 c = tex * _Color;

but I am not sure what primary and DOUBLE equate to. I hope someone can help.

Cheers, Oliver

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
-1

Answer by Kryptos · Jan 18, 2012 at 08:37 AM

RTFM.

ShaderLab syntax references: http://unity3d.com/support/documentation/Components/SL-Shader.html

Primary and DOUBLE are related to texturing: http://unity3d.com/support/documentation/Components/SL-SetTexture.html

Comment
Add comment · Show 3 · 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 Oliver Eberlei · Jan 18, 2012 at 01:15 PM 0
Share

Oh come on. Give me some credit.

Of course I read the manual, but

 Primary is the color from the lighting calculation or the vertex color if it is bound. 

Does not help me much finding equivalent functionality for surface shaders. And yes, I have searched the forums, the documents and the answers section.

Also

 The formulas specified above can optionally be followed by the keywords Double or Quad to make the resulting color 2x or 4x as bright. 

I tried

 c = c * 2; // too bright
 c = c * c; // too dark
 c = c * c * 2; // too red

what does 2x as bright mean. Its not very easy to put that into code for me.

I even opened the compiled shader to search for the statement, but even in compiled form it is still

 Combine previous * primary DOUBLE
avatar image Kryptos · Jan 18, 2012 at 01:25 PM 0
Share

Sorry I did not mean to insult you.

Getting realtime shadows to work have nothing to do with the use of surface shader ins$$anonymous$$d of fixed function. Realtime shadows work perfectly with fixed function.

$$anonymous$$ake sure that your shader is rendering in the opaque queue.

 Tags { "RenderType"="Opaque" }

See: http://unity3d.com/support/documentation/$$anonymous$$anual/Shadows.html and http://unity3d.com/support/documentation/$$anonymous$$anual/Shadow%20Troubleshooting.html

avatar image Oliver Eberlei · Jan 18, 2012 at 02:10 PM 0
Share

No worries :)

You are right, I forgot to specify, casting shadows does work, but receiving shadows was the problem. They would just not be drawn.

Anyways, I now use the surface shader below and receiving shadows works fine now. Thank you anyways for your help.

Oh, and for anyone wondering. DOUBLE does mean c = c * 2; $$anonymous$$y 'c' was just too bright to begin with.

avatar image
0

Answer by Oliver Eberlei · Jan 18, 2012 at 02:07 PM

I have been playing around with the surface shader to make the lightning calculations look the similar to the ones produced by the fixed function shader. This is the surface shader I ended up with, it looks hacked, but at least in the game it looks the same and receiving shadows works properly now.

I used the Self-Illumination/Diffuse Shader as a starting point.

void surf (Input IN, inout SurfaceOutput o) { fixed4 tex = tex2D(_MainTex, IN.uv_MainTex); fixed4 c = tex * _Color * 0.5; //Why 0.5? I tried to match the lighting //on a white sphere first and this worked //but it was just a guessed number o.Albedo = c.rgb; o.Emission = c.rgb * tex2D(_Illum, IN.uv_Illum).a;

 o.Albedo = o.Albedo * 0.5865;     //These two values are magic numbers I just
 o.Emission = o.Emission * 1.173; //found through trial and error

 o.Albedo = o.Albedo * 2; //This is the DOUBLE part
 o.Emission = o.Emission * 2;

 o.Alpha = c.a;

}

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Project UVs from arbitrary direction vector in shader 0 Answers

Switching shader Lighting On/Off from script 1 Answer

Surface Shaders have Slight Trasparency. Why? 0 Answers

viewDir changes with o.Normal 1 Answer

Simple cartoon water shader shoreline 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