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 xtram · May 09, 2011 at 07:18 PM · shadershaderlabporting

Getting Light Attenuation in shaders

I'm currently porting our Shaders from unity 2.6 to 3.3 and I have a question for the esteemed unity graphics gurus.

I did a "Unlit with shadows" shader by hacking the per-pixel light pass in the normal-diffuse shader.

The result is an unlit texture that still "receives" shadows by directly blending the shadow map info.

Here is the base 2.6 shader, I have multiple variants for alpha and lightmapped sources

Shader "Unlit/Shadows" {

 Properties {
 _ShadowIntensity ("Shadow Intensity", Range (0, 1)) = 0.6
     _MainTex ("Base (RGB)", 2D) = "white" {}
 }

Category { Tags { "RenderType"="Opaque" } LOD 200 Blend Off

 // ------------------------------------------------------------------
 // ARB fragment program

 SubShader {
     // Ambient pass
     Pass {
         Name "BASE"
         Tags {"LightMode" = "PixelOrNone"}
         SetTexture [_MainTex]
     }

     Pass {
         Name "BASE"
         Tags {"LightMode" = "Vertex"}
         SetTexture [_MainTex]
     }

     // Pixel lights
     Pass {
         Blend SrcAlpha OneMinusSrcAlpha

         Name "PPL"
         Tags { "LightMode" = "Pixel" }

CGPROGRAM #pragma vertex vert #pragma fragment frag #pragma multi_compile_builtin #pragma fragmentoption ARB_fog_exp2 #pragma fragmentoption ARB_precision_hint_fastest #include "UnityCG.cginc" #include "AutoLight.cginc"

struct v2f { V2F_POS_FOG; LIGHTING_COORDS float2 uv; float3 normal; float3 lightDir; };

uniform float4 _MainTex_ST;

v2f vert (appdata_base v) { v2f o; PositionFog( v.vertex, o.pos, o.fog ); o.normal = v.normal; o.uv = TRANSFORM_TEX(v.texcoord, _MainTex); o.lightDir = ObjSpaceLightDir( v.vertex ); TRANSFER_VERTEX_TO_FRAGMENT(o); return o; }

uniform sampler2D _MainTex; uniform float _ShadowIntensity;

float4 frag (v2f i) : COLOR { float atten = LIGHT_ATTENUATION(i);

 half4 c;
 c.rgb = 0;
 c.a = (1-atten) * _ShadowIntensity; 
 return c;

} ENDCG } }
}

Fallback "Unlit/Simple"

}

When porting to 3.3 unity comments the whole per-pixel pass, how can I implement this in the new shaderlab? The Surface shader pass might seem overkill since I don't think I need the normals and such.

I'll also glady accept any info on how to improve this shader :) Feel free to copy/hack/use it as you wish

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

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

No one has followed this question yet.

Related Questions

Shadow Support in Custom Shader 0 Answers

How would I grab the lighting pass in a post process shader for deferred lighting? 0 Answers

Pass ShaderLab properties to Standard cginc 2 Answers

Shader compiler: internal error compiling shader snippet type=0 platform=0: 1 Answer

[Unity3] How can I fix this shader 'texture' syntax error under 3.0? 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