我正在试图弄清楚如何在DirectX中调试像素和顶点着色器,我尝试使用Pix for Windows但发现它非常错误并且实际上不可操作.有没有替代方案可以让我在自己的应用程序中调试这些着色器?
如何在不使用任何按位运算的情况下对32位整数实现rightrotate(和leftrotate)运算?
我需要这个,因为高级着色器语言(HLSL)不允许在数字上按位进行,我需要rightrotate用于我正在尝试实现的特定着色器.
使用着色器模型 2.0,您可以拥有 256 个常量寄存器。我一直在研究各种着色器,并试图找出单个寄存器的构成?
例如,在我的实例化着色器中,我在函数外部的顶部声明了以下变量:
float4x4 InstanceTransforms[40];
float4 InstanceDiffuses[40];
float4x4 View;
float4x4 Projection;
float3 LightDirection = normalize(float3(-1, -1, -1));
float3 DiffuseLight = 1;
float3 AmbientLight = 0.66;
float Alpha;
texture Texture;
Run Code Online (Sandbox Code Playgroud)
我消耗了多少寄存器?我如何计算它们?
这个问题可能看起来很简单,但我无法找到HLSL如何处理自己的坐标系.
我只想知道位于(0,0)的位置(左上角或左下角),因为我是这些着色器概念的初学者,我无法自己扣除它
谢谢你的帮助!
我想知道如何使用C#在HLSL着色器效果中设置p类型参数?float2e
e.Parameters["p.x"].SetValue(1);
e.Parameters["p.y"].SetValue(2);
Run Code Online (Sandbox Code Playgroud)
好像不行.
我正在尝试创建带有凹凸贴图的着色器。
我具有对象的真实法线,并且具有凹凸贴图采样法线。我想做的是旋转采样法线,以使采样法线在实际法线方向上“向上”旋转。
我一直在从事数学工作,但似乎做得不好……Y在这个世界上崭露头角。
// Vertex shader sends this matrix to the pixel shader
OUT.normal[0] = mul((float3x3)world, normal);
float3 temptan = cross(normal, float3(0, 0, 1));
temptan = normalize(temptan);
OUT.normal[2] = mul((float3x3)world, temptan);
OUT.normal[1] = cross(OUT.normal[0], OUT.normal[2]); calculating binormal (in world space)
// Pixel Shader:
// Get normal from bump texture
float3 normal = tex2D(normalmap, texCoord);
normal = normal * 2 - 1;
// Swap Z and Y, since Z is up on the texture, but Y is up in this world. …Run Code Online (Sandbox Code Playgroud) 常量缓冲区,在顶点着色器源中声明
cbuffer c_buffer : register(b0)
{
matrix <float, 4, 4> u_mvpMatrix;
matrix <float, 4, 4> m44;
matrix <float, 3, 3> m33;
matrix <float, 2, 3> m23;
matrix <float, 3, 2> m32;
matrix <float, 1, 3> m13;
}
Run Code Online (Sandbox Code Playgroud)
用于编译着色器的命令
fxc /nologo /E main /T vs_4_0_level_9_3 /Fh vertex_bytes.h /Vn bytes
Run Code Online (Sandbox Code Playgroud)
最后,生成的vetex_output.h中的注释
// Buffer Definitions:
//
// cbuffer c_buffer
// {
//
// float4x4 u_mvpMatrix; // Offset: 0 Size: 64
// float4x4 m44; // Offset: 64 Size: 64 [unused]
// float3x3 m33; // …Run Code Online (Sandbox Code Playgroud) 在 hlsl 着色器中设置全局参数的正确方法是什么?如果我有以下全局参数:
float4x4 World;
float4x4 View;
float4x4 Projection;
Run Code Online (Sandbox Code Playgroud)
我在顶点着色器中使用它们:
void VertexShaderFunction( in float4 inputPosition : POSITION, in float4 colorIn : COLOR, out float4 posOut : SV_POSITION, out float4 colorOut : COLOUR)
{
//Set values for output
float4 worldPosition = mul(inputPosition, World);
float4 viewPosition = mul(worldPosition, View);
float4 position = mul(viewPosition, Projection);
posOut = position;
colorOut = colorIn;
}
Run Code Online (Sandbox Code Playgroud)
那么当相机移动时,如何从 c++ 代码 fe 设置这些全局值?我应该创建另一个着色器,它只是设置我可以像这样作为缓冲区访问的这些值吗?
void SetProjectionMatrix(float4x4 inputMatrix : MATRIX){
Projection = inputMatrix;
}
Run Code Online (Sandbox Code Playgroud)
请告诉我实现这一目标的正确方法是什么。
为了正确地将Normal(不是位置的方向)从Object空间转换为World space,我们将它与Model matrix/_World2Object matrix(在Unity中)的逆相乘.
那么为什么Tangent(它与法线相切并且也是方向 - 它不是一个位置)与Model Matrix/_Object2World(在Unity中)相乘以将其转换为世界空间?
例如:代码:用于在着色器中读取切线空间法线的代码:
o.normalWorld = normalize( mul(v.normal, _World2Object) );
o.tangentWorld = normalize( mul(_Object2World, v.tangent) );
o.binormalWorld = normalize( cross(o.normalWorld, o.tangentWorld) * v.tangent.w );
Run Code Online (Sandbox Code Playgroud) 我仍在使用我自己的自定义游戏引擎开发我的科幻视频游戏.现在,我想在我的游戏和引擎中实现战斗系统.虽然几乎所有东西都很清楚,但我想知道如何制作合适的激光束,如星球大战,星际迷航,巴比伦5等等.
我做了一些在线研究,但是我找不到合适的文章.我很确定我搜索了错误的关键字/标签.你能给我一些提示如何实现激光束等效果吗?我想,了解我在线研究所需的正确技术或术语就足够了......
hlsl ×10
directx ×4
shader ×4
3d ×2
directx-11 ×2
graphics ×2
xna ×2
buffer ×1
bump-mapping ×1
c# ×1
c#-4.0 ×1
c++ ×1
cg ×1
direct3d11 ×1
game-engine ×1
math ×1
matrix ×1
offset ×1
pixel ×1
vertex ×1