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)
#Shaders are ignoring the red channel for the albedo
1 messages · Page 1 of 1 (latest)
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
Posting code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
Could it be that for some reason the tint color is set to Cyan (not the user, the color :D) in the material inspector ?
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
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)
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
How does the texture look in assets? Maybe check it's import settings
this is the texture, it's a jpg with srgb settings
Fore the sake of it, can you take a screenshot of the texture import settings with its preview ?
And the importer preview does show the texture like it should be, right ?
Yes
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 ?
Lemme see
See the thing is that the shader seems to work fine in the editor, but when it game it just doesn't?
Oh, so it's the script that changes the material in game that could "break" it ?
Mind showing the full script ?
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)