   passing a bool value in vertex structure
  I need to pass a bool-value in my vertex structure. The structure contains only a Vector3 for POSITION0 and this bool value. Is there a semantic for a single bool value?Or do you have any other idea on how to achieve my goal?I'm basically trying to pass a value which indicates if a vertex is being selected. In that case it needs to have another color, which I set in the shader.   
  Use a float to indicate the influence of the selection color.Vec4 outColor = Lerp(normalColor, selectionColor, selectionColorWeight);The float can be 0.0 or 1.0 if you want to obtain binary control.   ;  You could change it to a Vector4 input for position, and put a 0.0f or 1.0f in the W componentOr try to pack it in some other input attribute similarlyOtherwise you'll just have to add another attribute   ;  Yeah having a float indicating a 0 or 1 value is a way. But I usually want to save as much space as possible. 10.000 vertices would have a total amount of 40.000 bytes on my graphics card, where I actually only need 5.000 bytes. And I want to save as much memory as possible.   ;  Shaders / GPU's work with floats/vectors, not bytes or bools. 10.000 vertices won't take 40.000 bytes by the way, even more :)If you use 32 bit floats for your vectors (which is common, I don't think you can change that), each vector component already takes 4 bytes:vector3 = 3x4 = 12 bytes per vertexvector4 = 4x4 = 16 bytes per vertexIn addition, bools aren't stored as 1 bit on a normal CPU either. On PLC's maybe, but for the CPU its just a byte. The reason is that CPU's are better with bytes than bits. A 32-bit CPU preferes 32 bit values. It's ta memory versus performance trade off.If you use the vector.w for the binary value, you need 16 x 10.000 = 160.000 bytes (if you use tenthousand vertices)... Which is only 157 kb. I wouldn't worry about it. I also pass thousands and thousands of vertices that also include tangents, texcoords, normal, biTangents, materialProperties, blend values, and so on. Only if you plan HUGE worls or very-high polygon models, you might think again. But ussually they fix that just by not rendering everything at the same time and/or LOD.Anyway, you can store the bool as a single bit by using bit shifting or masking. For example, bit 0 from the 32-bit vector.w 'carrier' will hold your bool. I'm not 100% sure, but I thought shaders also have bit shift functions to peel that single bit out of a bigger number. Or you can stuff bytes into a bigger 32 bit number and unpack them later on in the shader. So you can store 4 small numbers into 1 big number.Unpacking requires some extra energy from your shader of course, plus it doesn't save memory unless you can store that bit together with other values. If you have 4 bool values, it might be worth trying to pack them as 4 bytes into the vector.w component, instead of using 4 seperate float values.Greetings,Rick   ;  I actually meant that 10.000 vertices need 40.000 bytes only for the additional float values. I only need 1 bit, but I have to waste another 31 on it. That's my problem.40kB might not be that much, but I'd like to keep the used memory as little as possible anyways. I always thought that game programming is about optimizing everything as good as I can.My question seem answered.spek you brought up another 2 questions which seem a bit offtopic in here, but I'll take the risk:Quote:vector3 = 3x4 = 12 bytes per vertexvector4 = 4x4 = 16 bytes per vertexI've seen this too often. Why would I store a Vector3 value as a float4 in the shader? There are 3 floats, not 4. Am I waisting another byte there? ;PQuote:In addition, bools aren't stored as 1 bit on a normal CPU either. On PLC's maybe, but for the CPU its just a byte. The reason is that CPU's are better with bytes than bits. A 32-bit CPU preferes 32 bit values. It's ta memory versus performance trade off.Does this mean that if I have many many bits separately, it will take 32 bits for each, even though 31 aren't used? And is it more useful to take some bits together like in a struct to safe this memory?Don't call me a peanut counter. I'd just like to know the full background here ;)Thanks.   ;  The reason that the GPU goes not into bits or bytes is because of its architecture. In 99% of the cases, it works with floats & vectors, so its specialized on that. Just like a 64 bit CPU likes to work with int64 or double datatypes. Yep, that can be considered as a waste, but therefore we keep adding more and more memory. I think performance is ussually more important than memory for high-speed/realtime applications such as games.About using a float4... good question. Maybe ite laziness or it might become usefull some day. But maybe it also helps optimizing a little bit. I'm really not sure about what I'm about to say now, but if you look at shader Assembler code, it seems that the GPU 'work registers' are float4 types. So in the end your float2 or float3 will be used in a float4 anyway. Just like when you add 2 bytes, the CPU still uses 2 32-bit registers. Still odd though, since passing bigger vectors means using more memory, but also a larger "transfer cost" (bandwidth, etc.). Anyway, I try to keep the vectors compact as well, but maybe someone here can go deeper into the GPU architecture and explain this...As for the other 'bit' question, I believe BOOL's are stored as a single byte (8 bits) by default. The C language doesn't even have a BOOL by default if I remember correctly. So yes, if you have lots of BOOL's it can be worth packing them together into a byte or another format. 8 BOOL's = 8 bytes, while you could also store them into a single byte. The downside is that it takes more work to read and write these bits. Nice for the memory usage, not that nice for the performance. Before packing them, first ask yourself if its really worth the trouble. Especially if you need those bits very often.Rick;Quote:8 BOOL's = 8 bytesI guess you mean 8 bools = 8 bits = 1 byte.Quote:So in the end your float2 or float3 will be used in a float4 anyway.When I pass texture coordinates, I would use float2. Do I have to use float4 as well because of what you wrote? Is there any case where I need to pass another type than float4 when I want to pass floats?   ;  8 bits = 1 byte, but since BOOL's are actually stored as bytes, 8 BOOL's make eight bytes. Unless you specifically pack them all together into 1 byte (with bit shifting or something).As for the texcoords, I ussually pass them as float2 as well. But since you asked why some programs are using all four components, I was looking for an explanation. I wouldn't store texcoords into a float4 structure since 50% of the memory and bandwidth usage would be wasted. But, once the shader starts working with them it could still use float4 registers to temporarey store these (smaller) numbers in. However, don't confuse working registers with memory. CPU's and GPU's have a small set of 'slots' that are temporarely used for doing calculations such as adding, subtracting or in the case of GPU's; normalizing, matrix multiplies and dot products. Maybe, very maybe, it takes less energy to port float4 values that come into the vertex/fragment shader towards the work registers. I doubt it though... Like I said, this requires a deeper knowledge of the GPU architecture, which I don't have :) For now I would just pass the coordinates like you are already doing.Ow, I forgot to mention that some coordinate systems might actually use all 4 components (xyz and w). If you don't pass the W component it will get a default value. But it could be used for scaling, or in case you have 2 sets of texture coordinates. For example, xy = texcoord.xy, zw = lightMapTexcoord.xy.   