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 Kiloblargh · Feb 25, 2013 at 08:21 AM · shaderoptimizationalphacubemapunlit

What- if anything- is wrong with this shader (alpha/reflective/unlit)?

So I just wrote my first shader, and of course by "wrote" I mean hacked together from existing shaders in half an hour on a caffeine high, and to my astonishment it actually did what I was trying to make it do. I can only attribute that to an extreme case of beginner's luck. But I have the feeling it's not at all optimal. Could I do the same thing a better way if I knew what I was doing?

The main thing bugging me is the lightModel (Lambert) in the surface shader. It seems the only options are Lambert and BlinnPhong, but I think the lightingModel ought to be null, because I don't have diffuse or specular lighting going on, only emissive. But I don't know how to do that, or if it would make any difference after saying Lighting Off. Or if anything using the surface shader system is going to be unnecessarily slow compared to writing a proper CGPROGRAM, which I initially tried to figure out from looking the builtin reflective shaders and couldn't quite decipher.

I feel this isn't a great question to be asking here- since it's working now- but at least I'm not asking you to teach me how Unity works and then program my awesome new Slender clone for me, right...?

Here's the shader script in question:

 Shader "Reflective/Alpha/Unlit" 
 {
 Properties 
     {
     _Cube ("Cubemap", Cube) = "" { TexGen CubeReflect }
     }
 
 Category 
     {
     Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
         Blend SrcAlpha OneMinusSrcAlpha
         Cull Back Lighting Off ZWrite On Fog { Color (0,0,0,0) }
     BindChannels 
         {
         Bind "Color", color
         Bind "Vertex", vertex
         Bind "TexCoord", texcoord
         }
     SubShader
          {
         CGPROGRAM
       #pragma surface surf Lambert alpha
       struct Input {
           float3 worldRefl;
       };
       samplerCUBE _Cube;
       void surf (Input IN, inout SurfaceOutput o) {
           o.Alpha = texCUBE (_Cube, IN.worldRefl).a;
           o.Emission = texCUBE (_Cube, IN.worldRefl).rgb;
       }
       ENDCG
         }
     }
 }


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

Answer by Philipp · Feb 25, 2013 at 10:17 AM

You seem to be on track, as far as I can tell.

You can write your own lighting functions for surface shaders and create unlit (or just emissive) shaders that way. These two manual pages should get you started: http://docs.unity3d.com/Documentation/Components/SL-SurfaceShaderLighting.html http://docs.unity3d.com/Documentation/Components/SL-SurfaceShaderLightingExamples.html

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

10 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

Related Questions

how can i modify this shader for transparency? 1 Answer

Unlit Shader with alpha mask 2 Answers

Add reflection to refractive shader 1 Answer

Merging (alpha) Unlit shader with Cutout shader 3 Answers

How do I add transparency to a cg vertex lit shader 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