#Shaders are ignoring the red channel for the albedo

1 messages · Page 1 of 1 (latest)

tawdry summit
#

hey guys! i'm learning how to make shaders and i'm making this basic image overlayer (through some googling and stuff online). for some reason, the shader seems to be ignoring the red channel. any idea why? i haven't used any of the properties aside from the _MainTex (since i want to get the texture right first) so _Color, _Gloss, _Metallic are all white, 0.5 and 0.5 respectively. i've attached the shader, a screenshot of what the texture appears as and what the texture actually is in case anyone wants to take a look (i couldn't take a proper screenshot but hopefully it at least conveys the message, the object is supposed to be an open coconut)

exotic lantern
#

Would be easier if you uploaded the shader as a .txt file so discord embeds the code, or one of the sites mentioned in !code

willow treeBOT
sick jacinth
#

Could it be that for some reason the tint color is set to Cyan (not the user, the color :D) in the material inspector ?

tawdry summit
#

I've been setting it to white just before i set the texture

#

correction: right after, but same thing

#

also here's the shader as a code block

Shader "Custom/TexturedOverlay"
{
    Properties
    {
        _Color ("Tint Color", Color) = (1, 1, 1, 1)
        _MainTex ("Overlay Texture", 2D) = "white" {}
        _Gloss ("Gloss", Range(0, 1)) = 0.5
        _Metallic("Metallic", Range(0, 1)) = 0.5
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }

        CGPROGRAM
        #pragma surface surf Standard fullforwardshadows
        #pragma target 3.0

        sampler2D _MainTex;

        struct Input
        {
            float2 uv_MainTex;
        };

        fixed4 _Color;
        half _Gloss;
        half _Metallic;

        void surf(Input IN, inout SurfaceOutputStandard o)
        {
            fixed4 texColor = tex2D(_MainTex, IN.uv_MainTex) * _Color;
            o.Albedo = texColor.rgb;
            o.Smoothness = _Gloss;
            o.Metallic = _Metallic;
            o.Alpha = texColor.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}
#

here's the shader property stuff, just to be safe

exotic lantern
#

If metallic is 0.5 might be colour from the skybox / reflection probes. Would make more sense to default that to 0 (in shader code and material)

tawdry summit
#

it's now brighter instead

#

so i've set the color tint property to red, green and blue through testing and they all seemed to have colored accordingly

#

there's a good chance the issue lies in tex2D but i'm not sure why or how

exotic lantern
#

How does the texture look in assets? Maybe check it's import settings

tawdry summit
sick jacinth
tawdry summit
#

it's mostly the default stuff, except for the srgb flag being set to true

sick jacinth
#

And the importer preview does show the texture like it should be, right ?

tawdry summit
#

Yes

sick jacinth
#

I'm getting out of idea .... If you apply a white texture, is it also looking green ?
If you apply your texture to a regular lit material, does it display properly ?

tawdry summit
#

Lemme see

#

See the thing is that the shader seems to work fine in the editor, but when it game it just doesn't?

sick jacinth
#

Oh, so it's the script that changes the material in game that could "break" it ?
Mind showing the full script ?

tawdry summit
#

oop sorry, got a bit busy but here's basically all there is to it, i create a new instance of a material with the backup shader to use (mainly just for testing)