Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Ony · Jul 06, 2010 at 09:45 AM · shaderloadalphaspeculardds

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 }

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Wolfram · Aug 17, 2010 at 04:03 PM 0
Share

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.

avatar image Ony · Aug 17, 2010 at 08:21 PM 0
Share

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.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

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

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Ony · Jul 06, 2010 at 06:02 PM 0
Share

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.

avatar image Ony · Jul 06, 2010 at 06:09 PM 0
Share

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.

avatar image skovacs1 · Jul 07, 2010 at 04:53 PM 0
Share

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

avatar image w1nterl0ng · Jul 29, 2010 at 02:52 AM 0
Share

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.

avatar image
0

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Ony · Jul 06, 2010 at 06:03 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

No one has followed this question yet.

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges