我想将 C#代码中的坐标值发送到Unity中的着色器代码。
public class SendWorldPositionToShaderProgram : MonoBehaviour {
void Start () {
Renderer renderer = GetComponent<Renderer>();
renderer.material.SetVector("_WorldPosition", transform.position);
}
}
}
Shader "Custom/MyRotateShader2" {
Properties {
_WorldPosition("WorldPosition", Vector) = (0, 0, 0, 0)
}
SubShader {
Tags
{
"RenderType" = "Opaque"
}
CGPROGRAM
#pragma surface surf Lambert vertex:vertex_program
#include "UnityCG.cginc"
float4 _WorldPosition;
void vertex_program(inout appdata_full v)
{
float4 wp = _WorldPosition;
wp.x; // is not real coordinate!
wp.y; // not too!
wp.z; // not too!
}
void surf( Input IN, inout SurfaceOutput o)
{
...
}
ENDCG
}
FallBack "Diffuse"
}