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
1
Question by hellojbb1234 · Sep 01, 2017 at 07:32 PM · shader

incorrec number of arguments to numeric type constructor

their are four numbers in the float 4 but it still gives me an error. The error is at test.vertex = float4(p0 - w0, p0 + w0, p1 - w1, p1 + w1);

 // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
 
 // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
 
 Shader "Custom/Geom_Grass" {
     Properties{
         _MainTex("Main Texture", 2D) = "white"{}
     _Color("Color", Color) = (1,1,1,1)
         _GrassHeight("Grass Height", float) = 3
         _GrassWidth("Grass Width", float) = 0.1
         _Glossiness("Smoothness", Range(0,1)) = 0.5
         _Metallic("Metallic", Range(0,1)) = 0.0
         _Gravity("Gravity", float) = 0
         _Length("Length", float) = 3
         _Width("Width", float) = .1
         _Steps ("Steps", float) = 3
     }
         SubShader{
         Tags{ "RenderType" = "Opaque" "LightMode" = "ForwardBase" }
         
         LOD 200
         Cull off
         ZWrite off
 
      Pass
         {
             CGPROGRAM
           #pragma vertex vert
             #pragma fragment frag
 #pragma multi_compile_fwdbase
             // make fog work
             #pragma multi_compile_fog
             
             #include "UnityCG.cginc"
             #include "AutoLight.cginc"
             struct appdata
             {
                 float4 vertex : POSITION;
                 float4 normal : NORMAL;
                 float2 uv : TEXCOORD0;
             };
 
             struct v2f
             {
                 float2 uv : TEXCOORD0;
                 float4 normal : NORMAL;
 
                 float4 worldPosition: TEXCOORD1;
                 float4 vertex : POSITION;
             };
             
 
              
 
             sampler2D _MainTex;
             float4 _MainTex_ST;
             
             v2f vert (appdata v)
             {
                 v2f o;
                 o.vertex = UnityObjectToClipPos(v.vertex);
                 o.uv = TRANSFORM_TEX(v.uv, _MainTex);
                 o.normal = v.normal;
                 o.worldPosition = mul(unity_ObjectToWorld, v.vertex).xyzw;
 
 
                 return o;
             }
             
           
 
          
         float _Length;
         float _Width;
         float _Gravity;
         float _Steps;
  
 // This struct is the input data from the geometry shader.
 // Simply convert the data from the vertex shader to world position
         
 
           struct geomInput
                {
                    float4 pos : POSITION;
                    float4 nor : NORMAL;
                };
 
     [maxvertexcount(80)] // Don't mind this value for now
     void geom(triangle v2f input[3], inout TriangleStream<v2f> stream)
     {
     // Because access the input data directly tend to make the code a mess, I usually repack everything in clean variables
  
     float4 P1 = input[0].vertex;
     float4 P2 = input[1].vertex;
     float4 P3 = input[2].vertex;
  
     float4 N1 = input[0].normal;
     float4 N2 = input[1].normal;
     float4 N3 = input[2].normal;
     
     float4 P = (P1+P2+P3)/3.0f;
     float4 N = (N1+N2+N3)/3.0f;
     v2f test = (v2f)0;
 
     float4 T = float4(normalize((P2-P1).xyz), 0.0f);
     for( int i = 0; i < _Steps; i++ )
     {
     // Retrieve the normalized time along the strand.
     // It will be used to interpolate all the data from the bottom to the top of the strand.
     // t0 is the current step of the strand we are drawing.
     // t1 is the next step to be drawn. It will be t0 at the next iteration.
     // You could store its value for optimization.
      
         
 
     float t0 = (float)i / _Steps;
     float t1 = (float)(i+1) / _Steps;
  
     // Make our normal bend down with gravity.
     // The further we are on the strand, and the longer it is, the more it bends.
     // We then normalize this new direction, and scale it by the length at the current iteration of the loop.
  
     float4 p0 = normalize(N - (float4(0, _Length * t0, 0, 0) * _Gravity * t0)) * (_Length * t0);
     float4 p1 = normalize(N - (float4(0, _Length * t1, 0, 0) * _Gravity * t1)) * (_Length * t1);
     
     
     test.normal = input[i].normal;
     
     test.uv = input[i].uv;
 
     // Interpolate the width, and scale the lateral direction vector with it
  
     float4 w0 = T * lerp(_Width, 0, t0);
     float4 w1 = T * lerp(_Width, 0, t1);
 
 
     test.vertex = float4(p0 - w0, p0 + w0, p1 - w1, p1 + w1);
 
     stream.Append(test);
 
 
     }
 
 
 }
     fixed4 frag(v2f i) : SV_Target
     {
         // sample the texture
         fixed4 col = tex2D(_MainTex, i.uv);
     float3 lightdir = float3(1, 1, 0);
     // apply fog
     float ndotl = dot(i.normal, normalize(lightdir));
 
 
     return col * ndotl;
     }
 
 
 ENDCG
 
 }
 
 }
 Fallback "Diffuse"
 }

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 Bunny83 · Sep 02, 2017 at 12:01 AM

p0 and w0 are float4 variables. So you actually pass 4 float4 variables to the float4 constructor.

I'm not sure what this line is supposed to do, but currently you basically pass 16 float values to the constructor.

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 Bunny83 · Sep 02, 2017 at 02:35 AM 1
Share

PS: your geometry shader is supposed to generate new triangles. However currently you just push a single vertex during one step. A triangle needs 3 vertices.

Also what's your input geometry looks like? This shader works on a triangle input and for each triangle in the input you have to create some sort of replacement geometry.

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

108 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

Related Questions

How to force the compilation of a shader in Unity? 5 Answers

Shader to a Camera 1 Answer

How do i make particles be under the Player? 0 Answers

Add shadow receiver to 3D text shader. 0 Answers

Access mesh for TextMesh or GuiText 2 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