Looking for something kinda specific...

I’m a total novice when it comes to writing shaders, and I’m trying to figure out a solution for something that I’d expect to be pretty simple. I’m hoping someone can point me in the right direction.

For most of my iPhone projects, I use this simple shader I grabbed from the Unify wiki ages ago. It’s a simple self-illuminated alpha blended shader that is perfect for faux-2d graphics and GUI elements.

Shader "My Shaders/AlphaSelfIllum" {
    Properties {
        _Color ("Color Tint", Color) = (1,1,1,1)
        _MainTex ("SelfIllum Color (RGB) Alpha (A)", 2D) = "white"
    }
    Category {
       Lighting On
       ZWrite Off
       Cull Back
       Blend SrcAlpha OneMinusSrcAlpha
       Tags {Queue=Transparent}
       SubShader {
            Material {
               Emission [_Color]
            }
            Pass {
               SetTexture [_MainTex] {
                      Combine Texture * Primary, Texture * Primary
                }
            }
        }
    }
}

The only thing I’d like to be able to do differently with this shader is use the “Color Tint” to “over-expose” the base texture. With the version above, the default for the Color Tint is pure white, and cranking it down to grey or black will darken and eventually completely blacken the image. How would I go about doing the opposite, where I have black (or even 50% grey) be the baseline? The goal is to be able to make elements in my scene “flash” procedurally by brightening the color in the material at runtime.

                      Combine Texture * Primary DOUBLE, Texture * Primary

You can also put “quad” in there instead.

–Eric

That’ll work perfectly, thanks. :slight_smile:

Not directly related to your question, but… Are you using any actual lights? Because this shader does compute lighting; and if by chance you don’t need that it could be made faster.

No “real” lights, only the ambient light in the scene which is solid white. In fact, even that is largely unnecessary if the shader itself could simply render at 100% no matter what.

Try something like this (typing outta my head, might not work):

Shader "My Shaders/WooHoo" { 
    Properties { 
        _Color ("Tint", Color) = (0.5,0.5,0.5,0.5)
        _MainTex ("Color (RGB) Alpha (A)", 2D) = "white" {}
    } 
    SubShader {
        Tags {"Queue"="Transparent"}
        Pass {
            ZWrite Off
            Blend SrcAlpha OneMinusSrcAlpha
            SetTexture [_MainTex] {
                constantColor [_Color]
                combine texture * constant double
            } 
        } 
    } 
}

This one will just do texturecolor2 (so gray color would be “neutral”), and use alpha blending. Will not react to any lights or ambient.

Thanks, Aras, that produces almost identical results, except the alpha channel was getting blown out. I fixed this by replacing this line:

combine texture * constant double

…with something more like the first shader I posted:

combine Texture * constant double, Texture * Primary

You probably want “combine texture * constant double, texture * constant” if you want to control resulting alpha with both texture the color. Since lighting is off, “primary” will always be white.

Yup, you would be correct! :slight_smile: