TEXCOORD01N

it2024-03-22  70

https://docs.unity3d.com/2019.4/Documentation/Manual/SL-ShaderSemantics.html https://docs.unity3d.com/2019.4/Documentation/Manual/SL-VertexProgramInputs.html

providing vertex data to vertex programs for cg/hlsl vertex programs, the mesh vertex data is passed as inputs to the vertex shader function. each input needs to have semantic specified for it: for example, POSITION input is the vertex position, and NORMAL is the vertex normal.

often, vertex data inputs are declared in a structure, instead of listing them one by one. several commonly used vertex structures are defined in UnityCG.cginc include file, and in most cases it is enough just to use those. the structures are:

appdata_base: position, normal and one texture coordinate.appdata_tan: position, tangent, normal and one texture coordinate.appdata_full: position, tangent, normal, four texture coordinates and color.

UnityCG.cginc

struct appdata_base { float4 vertex : POSITION; float3 normal : NORMAL; float4 texcoord : TEXCOORD0; UNITY_VERTEX_INPUT_INSTANCE_ID }; struct appdata_tan { float4 vertex : POSITION; float4 tangent : TANGENT; float3 normal : NORMAL; float4 texcoord : TEXCOORD0; UNITY_VERTEX_INPUT_INSTANCE_ID }; struct appdata_full { float4 vertex : POSITION; float4 tangent : TANGENT; float3 normal : NORMAL; float4 texcoord : TEXCOORD0; float4 texcoord1 : TEXCOORD1; float4 texcoord2 : TEXCOORD2; float4 texcoord3 : TEXCOORD3; fixed4 color : COLOR; UNITY_VERTEX_INPUT_INSTANCE_ID };

to access different vertex data, u need to declare the vertex structure yourself, or add input parameters to the vertex shader. vertex data is identified by CG/HLSL semantics, and must be from the following list:

POSITION is the vertex position, typically a float3 or float4.NORMAL is the vertex normal, typically a float3.TEXCOORD0 is the first UV coordinate, typically float2, float3 or float4.TEXCOORD1, TEXCOORD2, TEXCOORD3 are the 2nd, 3rd and 4th UV coordinates, respectively.TANGNET is the tangent vector (used for normal mapping), typically a float4.COLOR is the per-vertex color, typically a float4.

when the mesh data contains fewer components than are needed by the vertex shader input, the rest are filled with zeroes, except for the .w component which defaults to 1. for example, mesh texture coordinates are often 2D vectors with just x and y components. if a vertex shader declares a float4 input with TEXCOORD0 semantic, the value received by the vertex shader will contain (x,y,0,1).

Vertex shader outputs and fragment shader inputs a vertex shader needs to output the final clip space position of a vertex, so that the GPU knows where on the screen to rasterize it, and at what depth. this output needs to have the SV_POSITION semantic, and be of a float4 type.

any other outputs (“interpolators” or “varyings”) produced by the vertex shader are whatever your particular shader needs. the values output from the vertex shader will be interpolated across the face of the rendered triangles, and the values at each pixel will be passed as inputs to the fragment shader.

many modern GPUs do not really care what semantics these variables have; however some old systems (most notably, shader model 2 GPUs on Direct3D 9) did have special rules about the semantics: 1. TEXCOORD0, TEXCOORD1 etc are used to indicate arbitrary high precision data such as texture coordinates and positions. 2. COLOR0 and COLOR1 semantics on vertex outputs and fragment inputs are for low-precision, 0-1 range data (like simple color values).

for best cross platform support, label vertex outputs and fragment inputs as TEXCOORDn semantics.

最新回复(0)