mein neuster Shader verhält sich irrational. Er widersagt jeder Logik. Ich weiß nicht, ob ich ihn in ein Internat schicken soll oder ob ich ihn irgendwie anderweitig zur Vernunft bringen kann. Hat jemand Ideen für Erziehungsmethoden?
Das Problem; zwei imo identische Codes führen zu unterschiedlichen Ergebnissen:
Code: Alles auswählen
struct inner
{
float4 position : POSITION;
float4 color : COLOR;
float3 normal : NORMAL;
float4 shadowCoords: TEXCOORD0;
float2 texCoords : TEXCOORD1;
float3 boneWeights : TEXCOORD2;
float4 boneIndices : TEXCOORD3;
};
struct outer
{
float4 position : POSITION;
float4 color : COLOR;
float4 shadowCoords: TEXCOORD0;
float2 texCoords : TEXCOORD1;
float3 normal : TEXCOORD2;
};
outer main(inner IN,
uniform float4x4 ModelViewProj,
uniform float4x4 ShadowTextureMatrix,
uniform bool activateAnimation,
uniform float4 BoneMatrices[150]
)
{
outer OUT;
float3 objPos;
float4 allWeights = float4(IN.boneWeights, 1.0f - IN.boneWeights.x - IN.boneWeights.y - IN.boneWeights.z);
if(activateAnimation)
{
for(float n = 0; n < 4; ++n)
{
float3x4 matrix = float3x4( BoneMatrices[IN.boneIndices[n] * 3],
BoneMatrices[IN.boneIndices[n] * 3 + 1],
BoneMatrices[IN.boneIndices[n] * 3 + 2]);
objPos+= mul(matrix, IN.position) * allWeights[n];
}
}
else
objPos = IN.position.xyz;
OUT.position = mul(ModelViewProj, float4(objPos, 1));
OUT.shadowCoords = mul(ShadowTextureMatrix, IN.position);
OUT.color = IN.color;// * dot(float3(1,1,1), IN.normal);//float4(0.4f, 0.4f, 0.4f, 0.f) + float4(dot(float3(sin(counter),cos(counter),sin(counter / 3.f)), IN.normal) * float3(1,1,(1 + sin(counter))/2.0f),1);
OUT.normal = IN.normal;//mul(WorldInverseTranspose, float4(IN.normal,1.f)).xyz;
OUT.texCoords = IN.texCoords;
return OUT;
}
Der folgende Code funktioniert jedoch:
Code: Alles auswählen
struct inner
{
float4 position : POSITION;
float4 color : COLOR;
float3 normal : NORMAL;
float4 shadowCoords: TEXCOORD0;
float2 texCoords : TEXCOORD1;
float3 boneWeights : TEXCOORD2;
float4 boneIndices : TEXCOORD3;
};
struct outer
{
float4 position : POSITION;
float4 color : COLOR;
float4 shadowCoords: TEXCOORD0;
float2 texCoords : TEXCOORD1;
float3 normal : TEXCOORD2;
};
outer main(inner IN,
uniform float4x4 ModelViewProj,
uniform float4x4 ShadowTextureMatrix,
uniform bool activateAnimation,
uniform float4 BoneMatrices[150]
)
{
outer OUT;
float3 objPos;
float4 allWeights = float4(IN.boneWeights, 1.0f - IN.boneWeights.x - IN.boneWeights.y - IN.boneWeights.z);
OUT.shadowCoords = mul(ShadowTextureMatrix, IN.position);
if(activateAnimation)
{
for(float n = 0; n < 4; ++n)
{
float3x4 matrix = float3x4( BoneMatrices[IN.boneIndices[n] * 3],
BoneMatrices[IN.boneIndices[n] * 3 + 1],
BoneMatrices[IN.boneIndices[n] * 3 + 2]);
objPos+= mul(matrix, IN.position) * allWeights[n];
}
}
else
objPos = IN.position.xyz;
OUT.position = mul(ModelViewProj, float4(objPos, 1));
OUT.color = IN.color;// * dot(float3(1,1,1), IN.normal);//float4(0.4f, 0.4f, 0.4f, 0.f) + float4(dot(float3(sin(counter),cos(counter),sin(counter / 3.f)), IN.normal) * float3(1,1,(1 + sin(counter))/2.0f),1);
OUT.normal = IN.normal;//mul(WorldInverseTranspose, float4(IN.normal,1.f)).xyz;
OUT.texCoords = IN.texCoords;
return OUT;
}
Wie kann das sein? Im generierten GLSL-Code wurden beide Varianten bis auf die Verschiebung ebenfalls gleich kompiliert und die Kopie von IN.texCoords -> OUT.texCoords findet beide Male statt.