Skip to content

Commit

Permalink
Docs: Instancing - use real code snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
paroj committed Dec 8, 2021
1 parent f5f671c commit e03e19a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 29 deletions.
40 changes: 11 additions & 29 deletions Docs/src/instancing.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ Files:
See `Examples/Instancing/RTSS/Robot` for an example on how to use instancing with the [RTSS: Run Time Shader System](@ref rtss)

Add to the Vertex Shader input example:
```
```cpp
...
float4 blendIdx : BLENDINDICES,
uniform float3x4 worldMatrix3x4Array[80],
...
```

Vertex position calculation example:
```
```cpp
int idx = int(blendIdx[0]);
float4 worldPos = float4( mul( worldMatrix3x4Array[idx], position ).xyz, 1.0f );
oClipPos = mul( viewProjMatrix, worldPos );
Expand Down Expand Up @@ -104,7 +104,7 @@ texture_unit InstancingVTF
}
```

Add to Vertex Shader input example:
Vertex Shader input example:
```
...
float4 m01 : TEXCOORD1,
Expand All @@ -114,15 +114,8 @@ Add to Vertex Shader input example:
```

Vertex position calculation example:
```
float3x4 worldMatrix;
worldMatrix[0] = tex2D( matrixTexture, m01.xy );
worldMatrix[1] = tex2D( matrixTexture, m01.zw );
worldMatrix[2] = tex2D( matrixTexture, m23.xy );
float4 worldPos = float4( mul( worldMatrix, position ).xyz, 1.0f );
oClipPos = mul( viewProjMatrix, worldPos );
...
```

@snippet Samples/Media/materials/programs/HLSL_Cg/VTFInstancing.cg world_pos

## HW VTF {#InstancingTechniquesHWVTF}

Expand Down Expand Up @@ -154,14 +147,8 @@ Vertex Shader input example:
```

Vertex position calculation example:
```
float3x4 worldMatrix;
worldMatrix[0] = tex2D( matrixTexture, m03.xw + mOffset );
worldMatrix[1] = tex2D( matrixTexture, m03.yw + mOffset );
worldMatrix[2] = tex2D( matrixTexture, m03.zw + mOffset );
float4 worldPos = float4( mul( worldMatrix, position ).xyz, 1.0f );
oClipPos = mul( viewProjMatrix, worldPos );
```

@snippet Samples/Media/materials/programs/HLSL_Cg/HW_VTFInstancing.cg world_pos

### HW VTF LUT {#InstancingTechniquesHW}

Expand Down Expand Up @@ -199,20 +186,15 @@ Files:
See `Examples/Instancing/RTSS/Robot` for an example on how to use instancing with the [RTSS: Run Time Shader System](@ref rtss)
Vertex Shader input example:
```
```cpp
...
float4 mat14 : TEXCOORD1,
float4 mat24 : TEXCOORD2,
float4 mat34 : TEXCOORD3,
float3x4 worldMatrix : TEXCOORD1,
...
```

Vertex position calculation example:
```
float3x4 worldMatrix;
worldMatrix[0] = mat14;
worldMatrix[1] = mat24;
worldMatrix[2] = mat34;
```cpp
...
float4 worldPos = float4( mul( worldMatrix, position ).xyz, 1.0f );
oClipPos = mul( viewProjMatrix, worldPos );
...
Expand Down
2 changes: 2 additions & 0 deletions Samples/Media/materials/programs/HLSL_Cg/HW_VTFInstancing.cg
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,14 @@ VS_OUTPUT main_vs( in VS_INPUT input,
worldPos = float4(calculateBlendPosition(input.Position, blendDQ), 1.0);
worldNorm = calculateBlendNormal(input.Normal, blendDQ);
#else
//! [world_pos]
float3x4 worldMatrix;
worldMatrix[0] = tex2Dlod( matrixTexture, float4(input.m03.xw + input.mOffset, 0, 0) );
worldMatrix[1] = tex2Dlod( matrixTexture, float4(input.m03.yw + input.mOffset, 0, 0) );
worldMatrix[2] = tex2Dlod( matrixTexture, float4(input.m03.zw + input.mOffset, 0, 0) );

worldPos = float4( mul( worldMatrix, input.Position ).xyz, 1.0f );
//! [world_pos]
worldNorm= mul( (float3x3)(worldMatrix), input.Normal );
#endif

Expand Down
2 changes: 2 additions & 0 deletions Samples/Media/materials/programs/HLSL_Cg/VTFInstancing.cg
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,14 @@ VS_OUTPUT main_vs( in VS_INPUT input,
worldPos = float4(calculateBlendPosition(input.Position, blendDQ), 1.0);
worldNorm = calculateBlendNormal(input.Normal.xyz, blendDQ);
#else
//! [world_pos]
float3x4 worldMatrix;
worldMatrix[0] = tex2Dlod( matrixTexture, float4(input.m01.xy, 0, 0) );
worldMatrix[1] = tex2Dlod( matrixTexture, float4(input.m01.zw, 0, 0) );
worldMatrix[2] = tex2Dlod( matrixTexture, float4(input.m23.xy, 0, 0) );

worldPos = float4( mul( worldMatrix, input.Position ).xyz, 1.0f );
//! [world_pos]
worldNorm= mul( (float3x3)(worldMatrix), input.Normal );
#endif

Expand Down

0 comments on commit e03e19a

Please sign in to comment.