Shader help for my game

edited in Questions and Answers
Hi guys

I recently started looking into using shaders to simulate lighting and shadows for Grave Days. I found this pretty cool package on the Unity asset store for $15:
https://www.assetstore.unity3d.com/en/#!/content/3787

I bet I would've been able to make this had I taken the time to learn shaders with the rest of you guys and saved some money, but the package looks nice, and maybe I can learn something from it now.

The issue I have with it though, is that the light from this package is fading my textures, and I believe it is a simple shader issue. This is what I expect (and get from normal Unity Lighting):
image

This is what the package produces (Unity lighting switched off) - ignore the tree, just look at the grass and dirt path: image

The image here seems to be over-bright and faded. The light shouldn't really over-ride the colour of the textures too much, it should just make it "brighter" or darker. Don't know if I'm using the right terminology here, but I think the above pictures explain what I mean.

I had to attach this shader to my background objects (grass and dirt):
Shader "2DVLS/Diffuse" {
    Properties
    {
        _MainTex ("Base (RGB) Trans. (Alpha)", 2D) = "white" { }
    }

    Category
    {
        ZWrite On
        Cull Back
        Lighting Off

        SubShader
        {
		    Pass 
			{
				ColorMask 0
			}

            Pass
            {
           		Blend DstColor DstAlpha

                SetTexture [_MainTex] 
				{ 
                	combine texture
                }             
            }
        } 
    }

	Fallback "Diffuse"
}


And this to my game object that acts as a light source:
Shader "2DVLS/Light" {
    Properties 
	{
        _MainTex ("SelfIllum Color (RGB) Alpha (A)", 2D) = "white" {}
    }

    Category {
	
       Lighting Off
       ZWrite Off
       Fog { Mode Off }
       Blend One One
       
	   BindChannels {
              Bind "Color", color
              Bind "Vertex", vertex
              Bind "TexCoord", texcoord
       }
       
	   SubShader 
	   {
            Pass 
			{
               SetTexture [_MainTex] 
			   {
                    Combine texture * primary
               }
            }
        } 
    }
}


I'll owe anyone who can help me out with this even a bit a Wookie life debt. Even just a point in the right direction so that maybe I can figure this out myself.
normal_bright.jpg
700 x 500 - 389K
dull.jpg
700 x 500 - 291K

Comments

  • What is in the alpha channel of your textures?
  • edited
    @Squidcor I'm not really sure. The background textures don't seem to have a alpha or color slider. The script for the light object I spoke about also does not have a color slider at the shader. It does however have a texture for the light, which is just a white dot that fades to black... but the script itself has a light color slider... But anyway I seemed to have solved it just now!

    I changed the blend in the diffuse shader to
    Blend DstColor zero


    Not really sure why this worked though. I was just messing around using this: http://docs.unity3d.com/Manual/SL-Blend.html as reference.
  • edited
    Wait, this doesn't do quite what I want yet. At the moment when I set my light to be black, the background doesn't go pitch black. I think my problem I had initially though had something to do with the alpha channel as you said.

    EDIT: I managed to get it completely black by removing the blending from the lighting shader. It feels like a silly thing to do since I'm not sure why it was there in the first place, or what the intended purpose for it is. But hey, if the end result is fine, then I suppose all is good. I suppose it might be necessary for multiple lights or something.
  • I kinda have it figured out now. For some reason though it also blends with the background colour of my camera, but the problem is solved if I change this to black. I wanted to know though if there is an easy way to add tint colour to my "diffuse" shader. I added this
    _tintColor ("Tint Color", Color) = (1, 1, 1, 1)
    to my properties, which then gives me a colour selector in the Unity GUI, but I don't know how to further implement it in the shader. I tried just multiplying it with stuff (mindlessly), but I get errors
Sign In or Register to comment.