- Home /
Making the Specular map separate in a shader (not as alpha)?
I'm not good with shaders.
Can someone tell me how I would take the skin shader below (from the wiki) and make the specular map be a separate texture instead of getting it from the alpha of the MainTex?
I'm loading textures from the user's hard drive and since Unity can't load a DDS or anything with an actual alpha channel (unless I use an asset pack but user's can't make those) I need to use a separate texture as the spec map.
Thanks in advance!
Shader "Skin/Bumped Specular" { Properties { _Color ("Main Color", Color) = (1,1,1,1) _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1) _Shininess ("Shininess", Range (0.01, 1)) = 0.078125 _MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {} _BumpMap ("Bump (RGB)", 2D) = "white" {} _RimTex ("Rim ramp (GRB) Fresnel ramp (A)", 2D) = " grey" {} _WrapTex ("Wrap ramp (RGBA)", 2D) = "grey" {} }
// ------------------------------------------------------------------ // Fragment program
SubShader { Blend AppSrcAdd AppDstAdd Fog { Color [_AddFog] } TexCount 4
UsePass "Skin/Specular/BASE"
// Pixel lights
Pass {
Name "PPL"
Tags { "LightMode" = "Pixel" }
CGPROGRAM #pragma vertex vert #pragma fragment frag #pragma multi_compile_builtin #pragma fragmentoption ARB_fog_exp2 #pragma fragmentoption ARB_precision_hint_fastest #include "UnityCG.cginc" #include "AutoLight.cginc" #include "skinhelpers.cginc" struct v2f { V2F_POS_FOG; LIGHTING_COORDS float3 uvK; // xy = UV, z = specular K float3 viewDirT; float3 lightDirT; float2 bumpUV; };
uniform float _Shininess; uniform float4 _MainTex_ST, _BumpMap_ST;
v2f vert (appdata_tan v) { v2f o; PositionFog( v.vertex, o.pos, o.fog ); o.uvK.z = _Shininess * 128; o.uvK.xy = TRANSFORM_TEX(v.texcoord, _MainTex); o.bumpUV = TRANSFORM_TEX(v.texcoord, _BumpMap);
TANGENT_SPACE_ROTATION;
o.lightDirT = normalize (mul (rotation, ObjSpaceLightDir( v.vertex )));
o.viewDirT = normalize (mul (rotation, ObjSpaceViewDir( v.vertex )));
TRANSFER_VERTEX_TO_FRAGMENT(o);
return o;
}
uniform sampler2D _MainTex; uniform sampler2D _BumpMap;
float4 frag (v2f i) : COLOR {
half4 texcol = tex2D( _MainTex, i.uvK.xy ); float3 normalT = normalize (tex2D (_BumpMap, i.bumpUV).rgb * 2 - 1); return SpecularLightWrap(i.lightDirT, i.viewDirT, normalT, texcol, i.uvK.z, LIGHT_ATTENUATION(i)); } ENDCG
}
}
Fallback "Skin/Specular", 0 }
Unity can import DDS files with alpha channels. Search this site, and just drag a .dds into your project. Obviously, import settings for these will be disabled. I might be that not all .dds variants can be interpreted, but I'm not usre about that.
I'm talking about loading the DDS at runtime from the user's hard drive. I know Unity can load DDS into the project, I do it all the time, but that's not what I need here.
Answer by Mike 3 · Jul 06, 2010 at 10:16 AM
Not sure how to fix your shader (sorry about that), but unity can load TGA files at editor time and runtime easily enough, and they have a separate alpha channel
I tried to load a TGA last night with no luck. Also on the texture format page in the docs it says it can load only PNG and JPG out of the box. I'll look around though and see if someone has written a TGA importer.
I'd prefer to have it load up ARGB DDS textures but TGA will do also if I can only find a way to import them on the fly.
I would really like to know how to do this as well, I have tried Alpha on a PNG and I have not had any success.
Answer by Eric5h5 · Jul 06, 2010 at 11:58 AM
Unity can load graphics at runtime (which I assume is what you're talking about) with alpha channels from any format as long as you can code/find an importer for it.
Yeah I'm going to look for some sort of importer I suppose. If I can find one then I don't have to worry about changing the shader code.
Your answer
Follow this Question
Related Questions
How to make a specular shader fully transparent 0 Answers
Glass Shader with Strumpy Shader Editor 1 Answer
About shader! 0 Answers
Unity Shader: Specular reflection as Alpha Value. 2 Answers
Shader alpha setting being ignored? 1 Answer