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*.normal;*
_ test.uv = input*.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”
}