• 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 Dicejss · Jun 29, 2013 at 04:06 PM · lightingshadersrampstrumpy

Lighting Artifact from Strumpy Ramp Shader

Hi guys so I need a little help here I'm a 3D artist and don't know much about programming shaders but I've been doing a lot of research here lately to try and fix this lighting issue with my ramp shader.

alt text

Basically when a light hits the geometry it makes this white square in the area on screen from where it is hitting. I've messed around and I can set the Build Settings > Player Settings > Rendering Path to Deferred Lighting will remove the white box artifact as well but deferred lighting also has it's drawbacks such as for transparent shaders.

alt text

Any ideas on how I can fix this in my shader and be able to use Forward Lighting? What's weird is I've done a ramp shader before in strumpy this was a good while back and I didn't have this problem. Thanks in advance for your help.

Here's the shader code:

 Shader "Ramp/Diff Illum Detail"
 {
     Properties 
     {
         _Color("_Color", Color) = (1,1,1,1)
         _MainTex("_MainTex", 2D) = "black" {}
         _Illum("_Illum", 2D) = "black" {}
         _Ramp("_Ramp", 2D) = "black" {}
         _Emission("_Emission", Range(0,1) ) = 1
         _Detail("_Detail", 2D) = "black" {}
         _Offset("_Offset", Float) = 0.05
 
     }
     
     SubShader 
     {
         Tags
         {
             "Queue"="Geometry"
             "IgnoreProjector"="True"
             "RenderType"="Opaque"
         }
 
             Cull Back
             ZWrite On
             ZTest LEqual
             ColorMask RGBA
             LOD 100
             Blend SrcAlpha OneMinusSrcAlpha
 
 
         CGPROGRAM
 #pragma surface surf BlinnPhongEditor  vertex:vert
 #pragma target 3.0
 
 
             float4 _Color;
             sampler2D _MainTex;
             sampler2D _Illum;
             sampler2D _Ramp;
             float _Emission;
             sampler2D _Detail;
             float _Offset;
 
             struct EditorSurfaceOutput {
                 half3 Albedo;
                 half3 Normal;
                 half3 Emission;
                 half3 Gloss;
                 half Specular;
                 half Alpha;
                 half4 Custom;
             };
             
             inline half4 LightingBlinnPhongEditor_PrePass (EditorSurfaceOutput s, half4 light)
             {
                 float4 Luminance0= Luminance( light.xyz ).xxxx;
                 float4 Assemble0=float4(Luminance0.x, float4( 0.0, 0.0, 0.0, 0.0 ).y, float4( 0.0, 0.0, 0.0, 0.0 ).z, float4( 0.0, 0.0, 0.0, 0.0 ).w);
                 float4 Tex2D0=tex2D(_Ramp,Assemble0.xy);
                 float4 Multiply0=Tex2D0 * float4( s.Albedo.x, s.Albedo.y, s.Albedo.z, 1.0 );
                 return Multiply0;
 
             }
 
             inline half4 LightingBlinnPhongEditor (EditorSurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
             {
                 half3 h = normalize (lightDir + viewDir);
                 
                 half diff = max (0, dot ( lightDir, s.Normal ));
                 
                 float nh = max (0, dot (s.Normal, h));
                 float spec = pow (nh, s.Specular*128.0);
                 
                 half4 res;
                 res.rgb = _LightColor0.rgb * diff;
                 res.w = spec * Luminance (_LightColor0.rgb);
                 res *= atten * 2.0;
 
                 return LightingBlinnPhongEditor_PrePass( s, res );
             }
             
             struct Input {
                 float2 uv_MainTex;
                 float4 fullMeshUV1;
                 float3 worldPos;
                 float2 uv_Illum;
 
             };
 
             void vert (inout appdata_full v, out Input o) {
                 float4 VertexOutputMaster0_0_NoInput = float4(0,0,0,0);
                 float4 VertexOutputMaster0_1_NoInput = float4(0,0,0,0);
                 float4 VertexOutputMaster0_2_NoInput = float4(0,0,0,0);
                 float4 VertexOutputMaster0_3_NoInput = float4(0,0,0,0);
                 
                 o.fullMeshUV1 = v.texcoord;
 
             }
             
 
             void surf (Input IN, inout EditorSurfaceOutput o) {
                 o.Normal = float3(0.0,0.0,1.0);
                 o.Alpha = 1.0;
                 o.Albedo = 0.0;
                 o.Emission = 0.0;
                 o.Gloss = 0.0;
                 o.Specular = 0.0;
                 o.Custom = 0.0;
                 
                 float4 Tex2D0=tex2D(_MainTex,(IN.uv_MainTex.xyxy).xy);
                 float4 Mask0=float4(float4( IN.worldPos.x, IN.worldPos.y,IN.worldPos.z,1.0 ).x,float4( IN.worldPos.x, IN.worldPos.y,IN.worldPos.z,1.0 ).y,0.0,0.0);
                 float4 Multiply4=Mask0 * _Offset.xxxx;
                 float4 Add0=(IN.fullMeshUV1) + Multiply4;
                 float4 Tex2D2=tex2D(_Detail,Add0.xy);
                 float4 Multiply2=Tex2D0 * Tex2D2;
                 float4 Tex2D1=tex2D(_Illum,(IN.uv_Illum.xyxy).xy);
                 float4 Multiply0=Tex2D1 * _Emission.xxxx;
                 float4 Multiply1=_Color * Multiply0;
                 float4 Master0_1_NoInput = float4(0,0,1,1);
                 float4 Master0_3_NoInput = float4(0,0,0,0);
                 float4 Master0_4_NoInput = float4(0,0,0,0);
                 float4 Master0_5_NoInput = float4(1,1,1,1);
                 float4 Master0_7_NoInput = float4(0,0,0,0);
                 float4 Master0_6_NoInput = float4(1,1,1,1);
                 o.Albedo = Multiply2;
                 o.Emission = Multiply1;
 
                 o.Normal = normalize(o.Normal);
             }
         ENDCG
     }
     Fallback "Ramp/Basic"
 }


lightartifact.jpg (73.2 kB)
deferredlighting.jpg (94.5 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 powdered_swords · Jun 29, 2013 at 04:49 PM

I hate that particular issue. I've spent hours looking for solutions to it and the answer is so simple. I'm 99% sure that you haven't set your ramp texture wrap mode to clamp. If the incoming light value is over one it will start wrapping around and sample from the wrong side of the texture.

Comment
Add comment · Show 5 · 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 Dicejss · Jun 29, 2013 at 06:13 PM 0
Share

Well I was hopeful that would fix it but after setting it to Clamp the artifact is still there. Got any other ideas? Thanks for your input.

avatar image powdered_swords · Jun 29, 2013 at 08:01 PM 0
Share

ahh I was so sure that would be it. could you post a screenshot of the artifact perhaps that would help narrow down the possibilities

avatar image Dicejss · Jun 29, 2013 at 08:46 PM 0
Share

I did already but here is another one showing two lights both doing the same thing. All assets they are hitting using my ramp shader do that except the terrain of course.

alt text

lightartifact2.jpg (46.6 kB)
avatar image Design.PierreFX · Jul 06, 2013 at 03:36 PM 0
Share

I'm having this issue as well, I thought it was something in the way vertex/fragment shaders are being processed. But you're doing a surface shader and it occurs as well! This does not occur on built-in shaders though... trying to find the delta.

avatar image Dicejss · Jul 08, 2013 at 06:05 AM 0
Share

Ugh I wish I knew what is causing it but even with the programming background I have as an artist. I'm out of ideas on how to fix it.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

17 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

Related Questions

Lighting works for iPad but not iPhone? 0 Answers

How to illuminate sprite's back and front face but display result of lighting only on the front face? 0 Answers

Multiple lights disable additive intensity for Sprites-Diffuse? 0 Answers

Rim Lighting around the cross section 0 Answers

How to fix Material with custom shader turning Black in Playmode (Light Weight Render Pipeline) 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