Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Aeleck · Oct 08, 2016 at 05:40 AM · shaderseffects

Multiple objects lighting wall that is otherwise transparent

I am working on a game where many objects may get near a boundary, or wall that would just be a plane that has a grid texture applied. I made a frag shader that makes a spotlight in a way where given a world position, it shows full opacity of the texture at that world location and then fades to transparency from there. Kind of like a spot light that shows the texture that as the light fades, the texture becomes transparent (see picture). My problem is that I want this wall or boundary to support having many objects (maybe up to 100 or 200) that when near it, it shows the texture in that way, but keep them synced up like it was just multiple spot lights on a wall with a grid texture. The objects near the wall will be moving around, the wall is there to show a boundary when they get close. I searched and found that I can in fact have arrays in the shader, and I could set the array via scripting of the positions, but to be honest, I don't know how to properly implement a for loop in the shader without messing it up the shader (not too experienced with shaders is what I mean) and due to "unrolling" by the compiler, my array of possible positions is limited, which is not idea. So I'm asking does anyone have any ideas or solutions for the effect I'm trying to create, but falling short of?

The white is just the clear color. It is a plane with a grid texture and shader mentioned above and written below. alt text

 // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
 
 Shader "Unlit/TextureSpotLight"
 {
     Properties
     {
         _MainTex("Texture", 2D) = "white" {}
         _Tint("Tint", Color) = (1.0, 1.0, 1.0, 1.0)
         _SpotPos("Spotlight Position & Size", vector) = (0, 0, 0, 1)
         _FallOff("Fall off rate", float) = 5.0
 
     }
         SubShader
     {
         Tags{ "RenderType" = "Transparent" "Queue" = "Transparent" }
         LOD 100
 
         Blend srcAlpha oneMinusSrcAlpha
         ZWrite Off
         Pass
     {
         CGPROGRAM
 #pragma vertex vert
 #pragma fragment frag
 
 #include "UnityCG.cginc"
 
         struct appdata
     {
         float4 vertex : POSITION;
         float2 uv : TEXCOORD0;
     };
 
     struct v2f
     {
         float2 uv : TEXCOORD0;
         float4 vertex : SV_POSITION;
         float3 worldPos : TEXCOORD1;
     };
 
     sampler2D _MainTex;
     float4 _MainTex_ST;
     float4 _SpotPos;
     float4 _Tint;
     float _FallOff;
     float3 _Positions[10];
 
     v2f vert(appdata v)
     {
         v2f o;
         o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
         o.uv = TRANSFORM_TEX(v.uv, _MainTex);
         o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
         return o;
     }
 
     fixed4 frag(v2f i) : SV_Target
     {
         // sample the texture
         fixed4 col = tex2D(_MainTex, i.uv) * _Tint;
         float3 offset = _SpotPos.xyz - i.worldPos;
         float range = dot(offset, offset) / (_SpotPos.w * _SpotPos.w);
         range = 1.0f - saturate(range);
         range *= range * _FallOff; // this multiplier controls the sharpness of the fade around the edge.               
         col.a *= saturate(range);
     return col;
     }
         ENDCG
     }
     }
 }

screenshot-4.png (98.6 kB)
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
0

Answer by sid4 · Oct 08, 2016 at 06:04 PM

Try messing with the shader properties in unitys shader area it has settings for this and especially for reflections

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

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

Creating jittery sprites motion with shaders? 2 Answers

BLUR Shader with Alpha Channel 1 Answer

Drawing sprite along colliders 1 Answer

Multitouch water ripple shader - Need help!!! 0 Answers

Fading out the edges of a mesh without using a material 0 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