Before updating to Windows 10 you may need to return your Pro license. More information here

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);

 o.lightDirT = normalize (mul (rotation, ObjSpaceLightDir( v.vertex )));
 o.viewDirT = normalize (mul (rotation, ObjSpaceViewDir( v.vertex )));

 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 }

more ▼

asked Jul 06, 2010 at 09:45 AM

avatar image

1.6k 83 81 106

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.

Aug 17, 2010 at 04:03 PM Wolfram

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.

Aug 17, 2010 at 08:21 PM Ony
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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

more ▼

answered Jul 06, 2010 at 10:16 AM

avatar image

Mike 3
34.6k 28 156 319

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.

Jul 06, 2010 at 06:02 PM Ony

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.

Jul 06, 2010 at 06:09 PM Ony

PNG's support alpha channel, so what's the problem?

Jul 07, 2010 at 04:53 PM skovacs1

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.

Jul 29, 2010 at 02:52 AM w1nterl0ng
(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Jul 06, 2010 at 11:58 AM

avatar image

121k 79 363 774

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.

Jul 06, 2010 at 06:03 PM Ony
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Jul 06, 2010 at 09:45 AM

Seen: 5249 times

Last Updated: Jul 06, 2010 at 09:45 AM