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 /
avatar image
0
Question by Reverend-Speed · Nov 14, 2019 at 02:10 PM · shadertextureshader programminguv mapping

Why is my UV'd texture displaying wrapped with the wrong scale?

Hey folks. Still getting to grips with shaders here and I'm having an issue where my UV unwrapped texture for my creature is either appearing multiple times on the creature surface or (if I mark the texture clamped) is only showing part of the texture stretched across the creature. alt text

Shader code follows:

 Shader "Custom/CaveCreatureShader2"
 {
     Properties
     {
         _MainTex ("C", 2D) = "white" {}
         // How much creature vs cave material.
         _PercentCreature ("Percentage Creature", Range(0,1)) = 0
 
         // Standard shader
         _Color("Color", Color) = (1,1,1,1)
         _CreatureTex("Albedo (RGB)", 2D) = "white" {}
         _Glossiness("Smoothness", Range(0,1)) = 0.5
         _Metallic("Metallic", Range(0,1)) = 0.0
     }
     SubShader
     {
         Tags { "RenderType"="Opaque" }
         LOD 100
 
         //Pass
         //{
             CGPROGRAM
 
             #include "UnityCG.cginc"
 
             #pragma vertex vert
             // Use 'custom stupid' lighting...
             #pragma surface surf CustomStupid vertex:vert
             
             #include "UnityPBSLighting.cginc"
 
 
             //fixed4 _Color;
 
             struct appdata
             {
                 float4 vertex : POSITION;
                 float2 uv : TEXCOORD0;
             };
 
             struct Input
             {
                 float2 uv_MainTex;
 
                 //--- TRIPLANAR STUFF ---//
 
                 float3 worldNormal;
                 float3 worldPos;
 
                 float3 localPos; // Local position of vertex
             };
 
             // Helper funcs!
             float4 tex3D_2D(in float3 pos, in float3 normal, sampler2D tex) {
                 return     tex2Dlod(tex, float4(pos.y, pos.z, 0, 0)) * abs(normal.x)
                       + tex2Dlod(tex, float4(pos.x, pos.z, 0, 0)) * abs(normal.y)
                       + tex2Dlod(tex, float4(pos.x, pos.y, 0, 0)) * abs(normal.z);
             }
 
             sampler2D _MainTex;
             sampler2D _CreatureTex;
 
             // float4 _MainTex_ST;
             float _PercentCreature;
             half _Glossiness;
             half _Metallic;
 
             void vert (inout appdata_full v, out Input o)
             {
                 UNITY_INITIALIZE_OUTPUT(Input, o);
 
                 o.localPos = v.vertex.xyz;
             }
 
             // Apply bump map.
             float3 material_TextureBump(in sampler2D tex, inout float3 normal, float3 p) {
                 // TEMP!!
                 const float scale = 0.04;
                 const float normScale = 0.03;
 
                 normal = normalize(normal);
                 float3 col = tex3D_2D(p*scale, normal, tex).rgb;
 
                 return col;
             }
 
             float3 getLights(in float3 color, in float3 pos, in float3 normal) {
                 float3 lightValue = 0.1 * float3(1, 1, 1);
 
                 const float lightStr = 0.5;
                 const float3 lightDir = float3(1, 1, 0);
 
                 float diff = max(lightStr * dot(-lightDir, normal), 0.0);
                 float3 diffuse = diff * lightValue;
 
                 lightValue = color * diffuse;
 
                 return lightValue;
             }
 
             half4 LightingCustomStupid(SurfaceOutputStandard s, half3 viewDir, UnityGI gi) {
                 float p = 0; // Disable custom lighting for the time being... Doesn't play nicely.
                 return lerp(half4(s.Albedo, 1), LightingStandard(s, viewDir, gi), p);
             }
 
             inline void LightingCustomStupid_GI(
                 SurfaceOutputStandard s,
                 UnityGIInput data,
                 inout UnityGI gi)
             {
                 LightingStandard_GI(s, data, gi);
             }
 
             void surf(Input IN, inout SurfaceOutputStandard o)
             {
                 float3 p = IN.worldPos;
                 float3 lp = IN.localPos * 10;  // TODO: Tweak scaling.
                 float3 n = IN.worldNormal;
 
                 // Then, we get the color of the world at that point, based on our material ids.
                 // Interpolated between cave and wall colours
                 float3 colorBase = 
                     material_TextureBump(_MainTex, n, p) * (1-_PercentCreature) + // Cave/Wall texture
                     tex2D(_CreatureTex, IN.uv_MainTex).rgb * _PercentCreature;     // Creature texture
 
 
                 float3 light = getLights(colorBase, p, n);
 
                 // The ambient color is applied.
                 const float3 _AmbientColor = float4(13.0,13.0,13.0,255).rgb / 255;
                 float3 color = colorBase * _AmbientColor;
 
                 // And lights are added.
                 color += light;
 
                 // Dist to camera
                 float dist = distance(p, _WorldSpaceCameraPos) / 35;
 
                 // Fog!
                 const float4 FogColor = float4(169, 190, 191, 255) / 255.0;
                 const float FogDensity = 0.01;
                 color = lerp(color, FogColor, 1.0-exp2(-FogDensity * dist * dist));
 
                 o.Albedo = color.rgb;
                 
                 o.Metallic = _Metallic;
                 o.Smoothness = _Glossiness;
                 o.Alpha = 1;
 
             }
             ENDCG
         //}
     }
 }
 

I'm really confused. Can anybody help me get the creature texture appearing as a normal skinned image? Running out of time here, so a fast response would be appreciated...!

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

0 Replies

· Add your reply
  • Sort: 

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

215 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 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

Overlaying a Darkening Texture over Certain UVs with a Shader 0 Answers

Shader: Mask Without a Texture? 2 Answers

How to remove a color from texture using Shader? 0 Answers

How to blend two textures? 1 Answer

Shader Graph texture limit? 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