I am sending data to my modified version of the instancedModel-Shader.
I am encoding the data (3 bools and 3 small ints) to a single int (in the DrawShaderInstancing-Method of InstancedModelPart.cs) as follows:
I represent the int I encode to by AAAAXYZABBBBBBBBCCCCCCCCDDDDDDDD and I encode:
bool Potential Pillar => encoded to (X)
bool Potential Connection => encoded to (Y)
bool BaseSquare => encoded to (Z)
int OwnedType [>0 and <=10] => encoded to (BBBBBBBB)
int BasicType [>0 and <=10] => encoded to (CCCCCCCC)
int Owner[>0 and <=10] => encoded to (DDDDDDDD)
as follows:
(those that are not familiar with the InstancedModelPart-class can just ignore the fact that I use an array of ints and encode to a certain index)
| tempPotentialBaseOwnedBasicOwnerCombo[index] = 65536 * (int)gameSquareInstanceDataArray[i + index].ownedType; |
| tempPotentialBaseOwnedBasicOwnerCombo[index] += 256 * (int)gameSquareInstanceDataArray[i + index].basicType; |
| tempPotentialBaseOwnedBasicOwnerCombo[index] += (int)gameSquareInstanceDataArray[i + index].owner; |
| if (gameSquareInstanceDataArray[i + index].baseSquare) |
| { |
| tempPotentialBaseOwnedBasicOwnerCombo[index] += 67108864; // 2^26; |
| } |
| if (gameSquareInstanceDataArray[i + index].potentialConnection) |
| { |
| tempPotentialBaseOwnedBasicOwnerCombo[index] += 134217728; // 2^27; |
| } |
| if (gameSquareInstanceDataArray[i + index].potentialPillar) |
| { |
| tempPotentialBaseOwnedBasicOwnerCombo[index] += 268435456; // 2^28; |
| } |
i set the Parameter by
| effect.Parameters["InstancePotentialOwnedBasicOwnerCombo"].SetValue(tempPotentialBaseOwnedBasicOwnerCombo); |
and in the shader file (InstancedModel.fx) (namely in the PixelShader that revceives the int for the present instance) I retrieve the data as follows:
| bool potentialPillar = (input.PotentialOwnedBasicOwner >= 268435456); |
| input.PotentialOwnedBasicOwner = input.PotentialOwnedBasicOwner % 268435456; |
| bool potentialConnection = (input.PotentialOwnedBasicOwner >= 134217728); |
| input.PotentialOwnedBasicOwner = input.PotentialOwnedBasicOwner % 134217728; |
| bool baseSquare = (input.PotentialOwnedBasicOwner >= 67108864); |
| input.PotentialOwnedBasicOwner = input.PotentialOwnedBasicOwner % 67108864; |
| int ownedType = input.PotentialOwnedBasicOwner / 65536; |
| input.PotentialOwnedBasicOwner = input.PotentialOwnedBasicOwner % 65536; |
| int basicType = input.PotentialOwnedBasicOwner / 256; |
| input.PotentialOwnedBasicOwner = input.PotentialOwnedBasicOwner % 256; |
| int owner = input.PotentialOwnedBasicOwner; |
(I encode all that stuff in order to save registers in the gpu because I don't want to decrease the number MAX_SHADER_MATRICES in InstancedModel.cs)
My problem is the following:
As long as I didn't encode the bool baseSquare everything worked fine.
But once I added that value things displayed wrongly on the screen.
Now comes the mysterious part:
I deleted from the shader every computation that referred to the bool baseSquare (except for the decoding above).
When I leave the three lines
if (gameSquareInstanceDataArray[i + index].baseSquare)
{
tempPotentialBaseOwnedBasicOwnerCombo[index] += 67108864; // 2^26;
}
in InstancedModelPart.cs things still display wrongly.
When I comment them out, everything is fine. Adding that value somehow seems to ruin my encoding or perhaps rather the integer's transfer to the gpu?
I found someone with a (perhaps) similar problem here, but with no answers:
http://www.gamedev.net/community/forums/topic.asp?topic_id=536241
---------------------------------
EDIT:
I changed my game logic by including the value that was given by the baseSquare-boolean into the enum basicType.
Everything works fine now. However it remains for me a total mystery:
I was able to encode 2 bools + 3 small ints correctly and decode them in the shader and use them all.
Once I added the 3rd bool (independently whether I used 2^26 or 2^29 to encode it) the graphics went wrong.
As soon as I commented the += 67108864 out, it worked again.
Adding that value didn't *** my coding - I checked that via Convert.ToString(tempPotentialBaseOwnedBasicOwnerCombo[index], 2) in InstancedModelPart.cs.
Also the encoding worked fine if I set baseSquare = true; manually in the shader (as long as += 67108864 was commented out).
I did not yet describe the "graphics bug" that occured so I will describe it here for anyone who wants to try an resolve this problem for others:
Basically there was just a wrong color used which is usally chosen according to the "owner" value that is decoded last.
The color that should have been used was the one for player 1 but it used the color for player 0. Maybe the decoding in the shader somehow "miscaluclated" something and so I had an error of +/- 1? Can't imagine anything else...