AKA, unbounded assumptions inside. I'm trying to write my own shader/partially rewrite the default fab shader (prelight_pa_unit_fab.fs) so it isn't so damn incoherent, and I'm experimenting with some stuff. I found that you could replace its main function with the contents of prelight_pa_unit.fs to get regular unit rendering, so I did that with the rest of the code saved for reference. I then modified the main() function to this pastebin: http://pastebin.com/vBbiP4DF which effectively adds a very simple bubble inflate display as the animation progresses. Consider the following code: <code> vec3 normalizedPosition = v_ModelPosition / model_radius; float distanceFromModelCenterSquared = dot(normalizedPosition, normalizedPosition); </code> To my understanding, line 1 normalizes v_ModelPosition to a unit size model position, then line 2 takes that and calculates the distance squared for that normalized vector. Then we move onto the if: <code> if (distanceFromModelCenterSquared > build_fraction) { discard; } </code> Which states, roughly, if this pixel's distance from the model is farther out from the center of the model than it should be to be rendered for the current build progress, don't render this pixel. But when you plug that code into the fab shader, you get odd results. Try building a mex and a power generator with the pastebin as your main function. You'll note the power generator fully "inflates" in about 30-40% of the build progress, and a mex inflates across pretty much the entire build time. This depends on my understanding of a few things being correct: - v_ModelPosition is actually the local position of the model pixel that's being rendered relative to unit position - model_radius is actually the model's bounding sphere size - build_fraction goes 0-1 I have a feeling either one of these assumptions are incorrect or that shader data I'm pulling from is wildly inaccurate but not in a way that matters for the default fab shader. Can i get some clarification so i'm not so bewildered here? lol tl;dr: bgolus or whoever the shader guy is, help plz
Your shader code is correct, you're not doing anything wrong. However, I'm going to give you two corrections. The model_radius value isn't quite the bounding sphere. A true bounding sphere would be centered around the center of the bounding box of the model where as this value is measured from the model's origin. Sometimes this is the same location, but in the case of our models where the origin is on the ground and the majority of the model extents are above that it is not. However that's irrelevant to the issue you're seeing. The model_radius is being calculated from the bounding box of the model taking the measurement from the model's origin to the furthest corner. This means the shorter building will have more "wasted radius" than the tall thin building. These might help show you what I mean. The black line is at the height of the origin, or "ground plane". The grey area is roughly the shape of the two econ buildings. The blue outline would be the bounding box. The straight red line is the distance from the origin to the furthest corner above the origin, and the red circle is the resulting range around the model. You'll notice the top of the metal extractor is almost to the edge of the circle, where as the top and even edges of the generator are a good distance away. And this is just the 2d representation of the issue, the third dimension just makes it that much further.
Alright, that makes sense. Basically, what I want to do is a vertically centered radial expansion sweep effect as part of my fab effect, and it's going to be a pain in the *** if I have to deal with that. Is it possible to obtain bounding box size as part of that shader?
Not at the moment, though it wouldn't take much to pass that data to the shader now. Eventually I want to pipe more generic data to shaders for this kind of thing, but for now I do not. Also, what you really want for what you're doing is a distance from the origin of the model to the furthest vertex. I had this data originally but I was extracting it manually from 3ds max for every single unit. Now I'm getting the bounds from in game and using the distance to corner, which isn't correct but is close enough for the expansion effect I do.
Also, what's in BuildInfo2? the only use I've seen is in wire_anim and it's a completely black box number.
It's a value to scale the speed of the wire undulation. It's the amount of metal required to build a unit divided by the rate at which the commander fab tool builds, or at least the rate it built at when I wrote the code. It means you get a relative idea of the speed something is building. The rest of the vector is unused at the moment.