Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by ashene · Jan 28, 2018 at 01:33 AM · shadershader programmingsurface shaderuvsuv2

Problem with surface shader using uv2

Hey I'm writing a surface shader that needs to use UV2 on a model, however the texture doesn't appear to be using the uvs at all when I apply them to the model.

 Shader "Custom/shaderEnvironment" {
     Properties {
         _Color ("Color", Color) = (1,1,1,1)
         _MainTex ("Albedo (RGB)", 2D) = "white" {}
         [Toggle(TOGGLE)] _DetailToggle ("Enable Primary Detail", Float) = 0
         _DetailTex ("Primary Detail (RGB)", 2D) = "white" {}
         [Toggle(TOGGLE2)] _Detail2Toggle ("Enable Secondary Detail", Float) = 0
         _Detail2Tex ("Secondary Detail (RGB)", 2D) = "white" {}
         [Toggle(TOGGLE3)] _Detail3Toggle ("Enable Micro Detail", Float) = 0
         _Detail3Tex ("Micro Detail (RGB)", 2D) = "white" {}
         _Lightmaps ("Lightmaps", 2D) = "black" {}
         _Glossiness ("Smoothness", Range(0,1)) = 0.5
         _Metallic ("Metallic", Range(0,1)) = 0.0
     }
     SubShader {
         Tags { "RenderType"="Opaque" }
         LOD 200
         
         CGPROGRAM
         #pragma surface surf Standard fullforwardshadows
 
         #pragma target 3.0
 
         #pragma shader_feature TOGGLE
         #pragma shader_feature TOGGLE2
         #pragma shader_feature TOGGLE3
 
         sampler2D _MainTex, _DetailTex, _Detail2Tex, _Detail3Tex, _Lightmaps;
 
         struct Input {
             float2 uv_MainTex;
             float2 uv2_LightmapTex;
         };
 
         half _Glossiness;
         half _Metallic;
         fixed4 _Color;
 
         UNITY_INSTANCING_CBUFFER_START(Props)
         UNITY_INSTANCING_CBUFFER_END
 
         half4 detailDouble(half4 albedo, half4 detail)
         {
             #ifdef TOGGLE
                 return ((albedo.a)*(albedo*detail)*2)+(albedo*(1-albedo.a));
             #else
                 return albedo;
             #endif
         }
 
         half4 detail2Double(half4 albedo, half4 detail)
         {
             #ifdef TOGGLE2
                 return ((1-albedo.a)*((albedo*detail)*2))+(albedo*albedo.a);
             #else
                 return albedo;
             #endif
         }
 
         half4 detail3Double(half4 albedo, half4 detail)
         {
             #ifdef TOGGLE3
                 return (albedo*detail)*2;
             #else
                 return albedo;
             #endif
         }
 
         void surf (Input IN, inout SurfaceOutputStandard o) {
             fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
             fixed4 d = tex2D (_DetailTex, IN.uv_MainTex*100);
             fixed4 d2 = tex2D (_Detail2Tex, IN.uv_MainTex*30);
             fixed4 d3 = tex2D (_Detail3Tex, IN.uv_MainTex*12);
             fixed4 lm = tex2D (_Lightmaps, IN.uv2_LightmapTex);
             c = detailDouble(c,d);
             c = detail2Double(c,d2);
             c = detail3Double(c, d3);
             o.Emission = lm.rgb;
             o.Albedo = c.rgb;
             o.Metallic = _Metallic;
             o.Smoothness = _Glossiness;
             o.Alpha = c.a;
         }
         ENDCG
     }
     FallBack "Diffuse"
 }

Does anyone know what the issue is? Thank you.

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
0

Answer by Pangamini · Jan 28, 2018 at 01:02 PM

Well that's pretty simple, you are not using the uv2 information anywhere. IN.uv_MainTex contains the main uv transformed by the texture scale/offset. You need to write your own vertex shader, read the actual uv2 channel information from the vertex and pass that into the surface shader.

Also, try to avoid calculating UVs in the pixel shader (surface shader is just a part of it), I am referring to IN.uv_MainTex*30 . It's far more erfficient to have the final UV calculated in vertex and having it interpolated, both because you avoid the multiplication per-pixel, but more important, the GPU can send those UVs to texture sampling units before the pixel shader even starts (at least that's what I believe, though I can't find any reference to back this statement)

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

169 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Custom Surface shader don't work with fresnel reflection and normal map at the same time 0 Answers

Among Us Masking (RGB) Question 0 Answers

ShaderGraph Y-Axis Billboard 0 Answers

Shader graph: how to treat color as vector4? 1 Answer

Toon Basic shader turns objects pink in 5.3.4f1 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