In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is about how to pass the vertex shader and pixel shader parameters of HLSL Effect. The editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.
HLSL is basically written in the habit of C, but if you look at it entirely from the perspective of C, I personally find it most difficult to understand that the parameters of the two functions of the vertex shader and the pixel shader are passed.
Here is an example of my understanding of the simplest effect framework in HLSL.
Uniform extern float4x4 gWVP
Struct OutputVS
{
Float4 posH: POSITION0
Float4 color: COLOR0
}
OutputVS ColorVS (float3 posL: POSITION0, float4 c: COLOR0)
{
/ / Zero out our output.
OutputVS outVS = (OutputVS) 0
/ / Transform to homogeneous clip space.
OutVS.posH = mul (float4 (posL, 1.0f), gWVP)
/ / Just pass the vertex color into the pixel shader.
OutVS.color = c
/ / Done--return the output.
Return outVS
}
Float4 ColorPS (float4 c: COLOR0): COLOR
{
Return c
}
Technique ColorTech
{
Pass P0
{
/ / Specify the vertex and pixel shader associated with this pass.
VertexShader = compile vs_2_0 ColorVS ()
PixelShader = compile ps_2_0 ColorPS ()
}
}
The first is the defined OutputVS, which is the output as a vertex shader, never mind. Look at the parameters in the vertex shader function: OutputVS ColorVS (float3 posL: POSITION0, float4 c: COLOR0) {} compared with C language functions, what puzzles beginners most is where the two parameters float3 posL: POSITION0, float4 c: COLOR0 come from? In fact, these two parameters are fixed and passed in by the pipeline of Directx. In Directx we all define our vertex format and register it / / first define our vertex format struct VertexCol {VertexCol (): pos (0.0f, 0.0f, 0.0f), col (0x00000000) {} VertexCol (float x, float y, float z, D3DCOLOR c): pos (xQuery z), col (c) {} VertexCol (const D3DXVECTOR3 & v, D3DCOLOR c): pos (v), col (c) {} D3DXVECTOR3 pos D3DCOLOR col; static IDirect3DVertexDeclaration9* Decl;}; D3DVERTEXELEMENT9 VertexColElements [] = {{0,0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0}, {0,12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0}, D3DDECL_END ()}; HR (gd3dDevice- > CreateVertexDeclaration (VertexColElements, & VertexCol::Decl)); / / = = / then tell Directx our vertex format before calling functions like IDirect3DDevice9::Draw** (). HR (gd3dDevice- > SetVertexDeclaration (VertexCol::Decl)); / / = so the vertex component we defined in D3DVERTEXELEMENT9 {. D3DDECLUSAGE_POSITION, 0} is passed to float3 posL: POSITION0 in the vertex shader parameter, and {... D3DDECLUSAGE_COLOR, 0} is passed to float4 c: COLOR0 in the vertex shader parameters. After the vertex shader is calculated, the OutputVS of each pixel is obtained and output to the pixel shader. / / = = float4 ColorPS (float4 c: COLOR0): COLOR
{
Return c
}
For example, the float4 c: COLOR0 of the pixel shader above comes from float4 color: COLOR0 in OutputVS.
The pixel shader then outputs the calculated color value of each pixel, which is what we see on the screen.
The above is how to pass the parameters of vertex shader and pixel shader of HLSL Effect. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.