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 RickF · Feb 26, 2014 at 02:38 AM · shaderfunctionvertexsurfaceunlit

How do I create an unlit reflective shader.

I need a shader that has maincolor, reflection color, Base (RGB) texture, and a reflection cubemap.

Basically the built in "reflective/ bumped unlit" shader, minus the normal map support.

However, in my failed attempts to modify and remove the normal map input, I found that i shouldn't use a surface shader if the material is not going to use lighting. Alas, I cannot find a vertex-fragment, or fixed function shader anywhere that supports cubemapped reflections.

Does anyone know where to find one?

I already have a simple unlit textured shader (obviously), but no reference in how to add cubemapped reflections to it. Help please. It would be much appreciated.

Comment
Add comment · Show 1
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 RickF · Feb 26, 2014 at 02:44 AM 0
Share

Or if someone can show me how to remove the normal map from this shader I would take that as well. Even though it sounds like that might not be best practice, it will work for me for now. Thanks.

 Shader "Custom/Reflective-NOTBumped_Unlit_rf" {
 
 Properties {
     _Color ("$$anonymous$$ain Color", Color) = (1,1,1,1)
     _ReflectColor ("Reflection Color", Color) = (1,1,1,0.5)
     _$$anonymous$$ainTex ("Base (RGB), RefStrength (A)", 2D) = "white" {}
     _Cube ("Reflection Cubemap", Cube) = "" { TexGen CubeReflect }
     _Bump$$anonymous$$ap ("Normalmap", 2D) = "bump" {}
 }
 
 Category {
     Tags { "RenderType"="Opaque" }
     LOD 250
     
     // ------------------------------------------------------------------
     // Shaders
 
     SubShader {
         // Always drawn reflective pass
         Pass {
             Name "BASE"
             Tags {"Light$$anonymous$$ode" = "Always"}
 CGPROGRA$$anonymous$$
 #pragma vertex vert
 #pragma fragment frag
 #pragma fragmentoption ARB_precision_hint_fastest
 
 #include "UnityCG.cginc"
 
 struct v2f {
     float4 pos : SV_POSITION;
     float2    uv        : TEXCOORD0;
     float2    uv2        : TEXCOORD1;
     float3    I        : TEXCOORD2;
     float3    TtoW0     : TEXCOORD3;
     float3    TtoW1    : TEXCOORD4;
     float3    TtoW2    : TEXCOORD5;
 };
 
 uniform float4 _$$anonymous$$ainTex_ST, _Bump$$anonymous$$ap_ST;
 
 v2f vert(appdata_tan v)
 {
     v2f o;
     o.pos = mul (UNITY_$$anonymous$$ATRIX_$$anonymous$$VP, v.vertex);
     o.uv = TRANSFOR$$anonymous$$_TEX(v.texcoord,_$$anonymous$$ainTex);
     o.uv2 = TRANSFOR$$anonymous$$_TEX(v.texcoord,_Bump$$anonymous$$ap);
     
     o.I = -WorldSpaceViewDir( v.vertex );
     
     TANGENT_SPACE_ROTATION;
     o.TtoW0 = mul(rotation, _Object2World[0].xyz * unity_Scale.w);
     o.TtoW1 = mul(rotation, _Object2World[1].xyz * unity_Scale.w);
     o.TtoW2 = mul(rotation, _Object2World[2].xyz * unity_Scale.w);
     
     return o; 
 }
 
 uniform sampler2D _Bump$$anonymous$$ap;
 uniform sampler2D _$$anonymous$$ainTex;
 uniform samplerCUBE _Cube;
 uniform fixed4 _ReflectColor;
 uniform fixed4 _Color;
 
 fixed4 frag (v2f i) : COLOR
 {
     // Sample and expand the normal map texture    
     fixed3 normal = UnpackNormal(tex2D(_Bump$$anonymous$$ap, i.uv2));
     
     fixed4 texcol = tex2D(_$$anonymous$$ainTex,i.uv);
     
     // transform normal to world space
     half3 wn;
     wn.x = dot(i.TtoW0, normal);
     wn.y = dot(i.TtoW1, normal);
     wn.z = dot(i.TtoW2, normal);
     
     // calculate reflection vector in world space
     half3 r = reflect(i.I, wn);
     
     fixed4 c = UNITY_LIGHT$$anonymous$$O$$anonymous$$_A$$anonymous$$BIENT * texcol;
     c.rgb *= 2;
     fixed4 reflcolor = texCUBE(_Cube, r) * _ReflectColor * texcol.a;
     return c + reflcolor;
 }
 ENDCG  
         } 
     }
     
     // ------------------------------------------------------------------
     //  No vertex or fragment programs
     
     SubShader {
         Pass { 
             Tags {"Light$$anonymous$$ode" = "Always"}
             Name "BASE"
             BindChannels {
                 Bind "Vertex", vertex
                 Bind "Normal", normal
             }
             SetTexture [_Cube] {
                 constantColor [_ReflectColor]
                 combine texture * constant
             }
         }
     }
 }
     
 FallBack "VertexLit", 1
 
 } 

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

20 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

Related Questions

Vertex program max instructions limit 2 Answers

Vertex Texture Lookup Breaking in Unity 3.5 0 Answers

Surface Shader, run vertex multiple times 0 Answers

iPhone Shader - Unlit, 2 textures (alpha blend), Base needs tint. 1 Answer

Fake PS1 "jittery movement" effect in Unity? 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