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
1
Question by TheCatProblem · Apr 02, 2013 at 02:28 PM · shaderlightmapuv mappinglegacyself-illumination

Can I make the self-illumin shader use a second UV channel for the illumination texture?

I've made a simple test model in 3ds Max consisting of two intersecting planes (exported from 3ds Max as an FBX file). Each plane uses a different material. The mesh has two UV channels: the first channel maps the textures and the second channel consists of an automatic flatten unwrap performed by 3ds Max for the illumination texture (for this example, I'm using an ambient occlusion texture as the illumination texture rather than a lightmap, but that doesn't affect the issue at hand).

Once imported into Unity, the object's two materials work properly if set to use a legacy lightmapped shader: the lightmap texture uses the second UV channel and is mapped to the object correctly. However, if the object's materials are set to use a self-illumination shader, the second UV channel is ignored and the illumination texture is mapped to the object using the first UV channel. The image below illustrates the problem.

The object on the left uses a self-illumination shader for its materials; the object on the right uses a legacy lightmapped shader for its materials.

The object on the left uses a self-illumination shader for its materials; the object on the right uses a legacy lightmapped shader for its materials.

The two versions of one of the object's materials are shown in the image below.

Comparison of shader settings.

Is there any way I can make the self-illumin shader use the second UV channel when mapping the illumination texture to the model? If not, what are the disadvantages associated with using a legacy lightmapped shader? Should I just write my own version of the self-illumin shader that uses the second UV channel when applying the illumination texture?

Any thoughts on this would be appreciated!

comparison - self-illumin on left, legacy lightmapped on right.png (88.6 kB)
comparison of shader settings.png (35.3 kB)
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by TheCatProblem · Apr 02, 2013 at 09:56 PM

As it turns out, it's extremely easy to modify the standard self-illumin diffuse shader so it uses the second UV channel when applying the illumination texture.

Here's the code for the modified shader (the source code for Unity's built-in shaders is available from the Unity download archive):

 Shader "Custom/Self-Illumin Diffuse" {
 Properties {
     _Color ("Main Color", Color) = (1,1,1,1)
     _MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
     _Illum ("Illumin (A)", 2D) = "white" {}
     _EmissionLM ("Emission (Lightmapper)", Float) = 0
 }
 
 SubShader {
     Tags { "RenderType" = "Opaque" }
     LOD 200
     
 CGPROGRAM
 #pragma surface surf Lambert
 
 sampler2D _MainTex;
 sampler2D _Illum;
 fixed4 _Color;
 
 struct Input {
     float2 uv_MainTex;
     float2 uv2_Illum; // Originally float2 uv_Illum;
 };
 
 void surf (Input IN, inout SurfaceOutput o) {
     fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
     fixed4 c = tex * _Color;
     o.Albedo = c.rgb;
     o.Emission = c.rgb * UNITY_SAMPLE_1CHANNEL(_Illum, IN.uv2_Illum);
     o.Alpha = c.a;
 }
 ENDCG
 } 
 FallBack "Legacy Shaders/Lightmapped/Diffuse"
 }
 

It was only necessary to change "uv_Illum" to "uv2_Illum" everywhere the former appeared (as documented on the Writing Surface Shaders reference page, a texture name that starts with "uv2" instead of "uv" will use the second UV channel).

Hopefully this information will be of use to someone else in the future.

Comment
Add comment · 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

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

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can you still use the old legacy lightmapped shaders? 1 Answer

Unity 3 Problem: Legacy Lightmap Shaders don't seem to work. 1 Answer

Is it possible to make a Self Illum bumped shader using uv2 for an illum map 0 Answers

Emissive shaders not working 0 Answers

Is there a way to change the shader on all meshes without doing it manually one by one? 3 Answers


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