Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 AsurZar · Oct 13, 2019 at 08:49 AM · surface shaderuv coordinates

Problems with uv for surface shader

 Shader "Ocean/OceanSurface" 
 {
     Properties
     {
         // texture
         _HeightMap("Height Map", 2D) = "white"{}
         _NormalMap("Normal Map", 2D) = "white"{}
         // water scale : x - height scale, y - height offset, z - choppy y scale, w - water tile size
         _WaterScale("Scale Data", Vector) = (1, 1, 1, 1)
     }
         
         SubShader
         {
           Tags { "RenderType" = "Opaque" }
           CGPROGRAM
           #pragma surface surf Lambert vertex:vert
 
         sampler2D_float _HeightMap;
         sampler2D _NormalMap;
         float4 _WaterScale;
 
           struct Input 
           {
               float2 uv_MainTex;
               float2 uv_BumpMap;
               float2 uv_ocean;
           };
 
           void vert(inout appdata_full v, out Input o) 
           {
               UNITY_INITIALIZE_OUTPUT(Input,o);
               // uv
               o.uv_ocean = float2(v.vertex.x / _WaterScale.w, v.vertex.z / _WaterScale.w);
               //o.uv_ocean = float2(v.vertex.x / 1.0f, v.vertex.z / 1.0f);
               // map for fetch
               float HeightChoppyMap = tex2Dlod(_HeightMap, float4(o.uv_ocean, 0.0f, 0.0f));
               // height
               v.vertex.y = (HeightChoppyMap * _WaterScale.x + _WaterScale.y);
           }
 
           void surf(Input IN, inout SurfaceOutput o) 
           {
               // case 1
               o.Albedo = float3(IN.uv_MainTex.x, IN.uv_MainTex.y, 0.5f);
               // case 2
               //o.Albedo = float3(IN.uv_ocean.x, IN.uv_ocean.y, 0.5f);
               //o.Albedo = tex2D(_NormalMap, IN.uv_MainTex);
               //o.Normal = 2.0f * tex2D(_NormalMap, IN.uv_MainTex) - 1.0f;
               //o.Albedo = o.Normal;
           }
           ENDCG
     }
         Fallback "Diffuse"
 }

Generation of mesh:

     Mesh createMesh(int width, int height, float widthSize, float heightSize)
     {
         Vector3[] vertices = new Vector3[width * height];
         Vector2[] texcoords = new Vector2[width * height];
         int[] indices = new int[(width - 1) * (height - 1) * 6];
 
         for (int x = 0; x < width; x++)
         {
             for (int y = 0; y < height; y++)
             {
                 Vector2 uv = new Vector3((float)x / (float)(width - 1), (float)y / (float)(height - 1));
                 Vector3 pos = new Vector3((float)x / (float)width * widthSize, 0, (float)y / (float)height * heightSize);
                 texcoords[x + y * width] = uv;
                 vertices[x + y * width] = pos;
             }
         }
         int num = 0;
         for (int x = 0; x < width - 1; x++)
         {
             for (int y = 0; y < height - 1; y++)
             {
                 indices[num++] = x + y * width;
                 indices[num++] = x + (y + 1) * width;
                 indices[num++] = (x + 1) + y * width;
 
                 indices[num++] = x + (y + 1) * width;
                 indices[num++] = (x + 1) + (y + 1) * width;
                 indices[num++] = (x + 1) + y * width;
             }
         }
 
         Mesh mesh = new Mesh();
         mesh.vertices = vertices;
         mesh.uv = texcoords;
         mesh.triangles = indices;
         mesh.UploadMeshData(false);
         mesh.RecalculateNormals();
         mesh.RecalculateTangents();
 
         return mesh;
     }
 }
 

alt text

As you can see it's blue, in shader: // case 1 o.Albedo = float3(IN.uv_MainTex.x, IN.uv_MainTex.y, 0.5f); // case 2 //o.Albedo = float3(IN.uv_ocean.x, IN.uv_ocean.y, 0.5f);

This means uv is 0, and this is the same for both cases, what could be wrong?

issue-uv.jpg (370.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
0
Best Answer

Answer by AsurZar · Oct 13, 2019 at 05:32 PM

Just needs to rename from uv_ocean to oceanUV to make works custom coordinates, also uv_MainTex not working without _MainTex

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

111 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

Related Questions

Basic surface shader question ... 0 Answers

Creating a billboarding surface shader 1 Answer

Luminance to Alpha 0 Answers

Referencing the current pixel's world coordinates in the SURF block of a shader 1 Answer

How do I add alpha writes to this shader? 0 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