hello everyone! i'm building my own shader derived from the standard specular shader and I've got this issue: this is my albedo: this is the alpha channel of albedo: and this is the result using a specular reflectivity color of 109 109 109: Code (csharp): o.Specular = _SpecColor.rgb; now, I've got to hack this thing and use directly a float value as specular reflectivity: Code (csharp): o.Specular = fixed3(0.427, 0.427, 0.427); and I obtain this: that's wrong, to have the same image I need to use this value: Code (csharp): o.Specular = fixed3(0.2, 0.2, 0.2); that's the 51 51 51 rgb color... why this? where I'm wrong? I'm on Deferred/Linear on unity 5.4.0p2 thanks for your patience
First of all you should provide the source code otherwise there's too much guess work as to what you're actually trying to do. Standard shader (specular) derives reflectivity from the specular color. reflectivity of a given fragment = max(max(SpecularColor.r, SpecularColor.g), SpecularColor.b). (or simply SpecularColor.r on SM2). On the other hand the half3(0.22, 0.22, 0.22) color does play a role but in the Metallic workflow not the Specular one. Either you confused the two somehow or you didn't express clearly enough what you want to achieve.
This is actually a very straight forward issue. Specular color normally comes from an sRGB texture, so 109, 109, 109 is actually a value of 0.1529, 0.1529, 0.1529 in the shader when using linear color space rendering. The conversion formula for going from the 0-255 value to the linear value (and back) is here: https://en.wikipedia.org/wiki/SRGB However you can get a very close approximation by doing: (color value/255)^2.2 which in the case of 109 gives (109/255)^2.2 = 0.1542 Inversely a value of 0.427 in the shader is 174/255 in sRGB "gamma space".
ghiboz, I've tested something similar to your needs using alpha as a trasparent mask for shadowing. This is my results It's clear that alpha is not affected by the "bypass sRGB sampling"..but what it's not clear also for me and I'd like to know is... ... in the alpha channel world...if I'd like to set a mid-grey that influence something for half of the channel...what color should I use? Alpha channel is not in linear mode? If it's gamma corrected, why the "bypass sRGB sampling" works only for the RGB channel? I come from the Not RealTime Renderer and there all maps related to shading operations (like normal maps, alpha, bumps, displacement, etc...) must be in linear mode and there are controls to force the linearity when using this kind of mapping...where am I wrong with Unity? I've prepared a scene to better understand what I did... TestGamma thank in advance!
thanks for all your replies. here is my shader: Code (CSharp): Shader "ghiboz/specular v1" { Properties { _MainTex("Albedo", 2D) = "white" {} _NormalMap("NormalMap", 2D) = "bump" {} _SpecColor("Specular", Color) = (0.21569, 0.21569, 0.21569) } // SM3+ SubShader { Tags{ "RenderType" = "Opaque" } CGPROGRAM #pragma surface surf StandardSpecular fullforwardshadows addshadow #pragma exclude_renderers gles #pragma target 3.0 struct Input { float4 color : COLOR; float2 uv_MainTex; float2 uv_NormalMap; float3 viewDir; }; sampler2D _MainTex; sampler2D _NormalMap; void surf(Input IN, inout SurfaceOutputStandardSpecular o) { // tex fixed4 albedo1 = tex2D(_MainTex, IN.uv_MainTex); fixed3 normal1 = UnpackNormal(tex2D(_NormalMap, IN.uv_NormalMap)); // specular o.Specular = _SpecColor.rgb; //o.Specular = fixed3(0.2, 0.2, 0.2); o.Smoothness = albedo1.a; o.Normal = normal1; } ENDCG } CustomEditor "grs_ShaderRoadGUI" } @michal_gjk , here is the chart of the specular shader: https://blogs.unity3d.com/wp-content/uploads/2014/11/UnitySpecularChart.png and tell that the specular rgb defines the reflectivity of a material...
I already wrote you how Speccolor relates to reflectivity in the standard spec workflow. You may want to look into UnityStandardUtils.cginc for details of how albedo, specular and reflectivity are calculated in both specular and metallic workflow.
The alpha component is always linear, and Unity sets normal maps to be linear for all channels. Modern GPUs have the option to treat just the RGB as being sRGB values (hence sRGB and not sRGBA) and will convert them from "gamma" space values to linear space automatically if the target render buffer is in linear. Otherwise in gamma space rendering it just leaves all texture values as they are and does not apply an sRGB conversion to either sRGB color channels, or linear channels. I believe a small group of GPUs have support for treating alpha as an sRGB channel as well, but it's not common so Unity doesn't offer support for it.
There are actually built in functions for going from gamma to linear space and back that are still approximations but surprisingly accurate ones. Use GammaToLinearSpace(value) when converting a linear texture channel output into the equivalent sRGB texture output.
you have forgotten to write to o.Albedo like this: o.Albedo = albedo1.rgb; i do not know what shaderlab does with a shader that does not write to albedo...
lol! that was a copy/paste error, 'cause the original shader was much bigger, i've extracted only the parts relative to the issue...