Unity3d 矩阵正交性和从着色器获取值
我的第一个问题是,Unity3d 矩阵正交性和从着色器获取值,unity3d,glsl,shader,hlsl,cg,Unity3d,Glsl,Shader,Hlsl,Cg,我的第一个问题是,\u Object2World矩阵是正交的吗?我的意思是,\u Object2World的逆转置是否等于\u Object2World矩阵 _Object2World = Inverse Transpose (_Object2World ) //is orthogonal ? 因为我测试了最后两行的正态变换,得到了相同的结果: V2F vertexProgram(vertexInput input) { V2F output; float4x4 mod
\u Object2World
矩阵是正交的吗?我的意思是,\u Object2World
的逆转置是否等于\u Object2World
矩阵
_Object2World = Inverse Transpose (_Object2World ) //is orthogonal ?
因为我测试了最后两行的正态变换,得到了相同的结果:
V2F vertexProgram(vertexInput input)
{
V2F output;
float4x4 modelMatrix = _Object2World;
float4x4 modelMatrixInverse = _World2Object;
float4x4 modelMatrixInverseTranspose = transpose(modelMatrixInverse);
output.viewDir = float3(mul(modelMatrix, input.vertex) -
float4(_WorldSpaceCameraPos, 1.0));
//output.normalDir = mul(_Object2World,float4(input.normal,0));
output.normalDir = mul(modelMatrixInverseTranspose,float4(input.normal,0));
}
最后一个问题,我想从着色器中获取一个值,因此我为着色器定义了一个统一属性,如下所示:
Properties{
_MyCustom ("Custome",Float)=0;
}
SubShader{
Pass{
V2F vertexProgram(APPINPUT input){
.
.
.
//I want to debug this Condition and watch it's result.//
if(Condition1==Condition2) _MyCustom=-1;
}
}
}
但是下面的代码不会更新属性。如何查看条件是否满足?回答第一个问题:这取决于应用于对象的变换。如果这些变换都是正交的(即仅平移、旋转、反射和不缩放),则生成的对象到世界矩阵也将是正交的
回答第二个问题:不能从着色器程序中修改属性并在主代码中读回它们。如果您想在常规计算中使用着色器,请查看。Condition11=Condition2是一项作业。如果我放弃了该条件,也不起作用。如果您有多个问题,请分别提问。这使得那些只能回答一个问题的人更容易回答,也使得以后的问题更容易找到。