- Home /
Modifying the model matrix??
I've been playing with some large-scale planet rendering concepts, and I've encountered this:
http://www.gamasutra.com/view/feature/2984/a_realtime_procedural_universe_.php
Specifically this:
"I solved both of these problems by scaling down the size and the distance of planetary bodies by modifying the model matrix. Using a defined constant for the desired far clipping plane, which I'll call FCP for now, I exponentially scale down the distance so that everything past FCP/2 (out to infinity) is scaled down to fall between FCP/2 and FCP."
I understand that conceptually, but is it possible to scale the model matrix's distance in Unity? Would I just scale my planet mesh down along the camera's look axis?
Answer by Bunny83 · Jan 10, 2013 at 09:47 PM
In Unity the Transform component covers the functionality of the ModelMatrix (also called world matrix). The model matrix is just a "TSR" matrix (Translation, Scaling, Rotation). It corresponds with the Transforms localPosition, localScale and localRotation. Unity can build a matrix from those 3 seperate vectors.
You can access the matrix with the localToWorldMatrix property of a transform component. However you usually just use the localScale to change the scale.
Thought as much... but to me the "exponential scaling" implies some kind of skewing is going on... any thoughts?
No, i don't think so. He just scales down the worls position and the scale (uniformly). The point is the scaling factor. It has to be calculated in a way that values in the range FCP/2 ro infinity are mapped to values in the range of FCP/2 to FCP.
The distance of an object from the far clipping plane has to be calculated by yourself. $$anonymous$$aybe it's possible to do it in the shader, but that wouls complicate things if you want to use built-in shaders.
However the question is more about what exact formula he used to map [FCP/2, ininity] to [FCP/2, FCP]
I think you can assume that at infinity, the scale factor is zero. You could do a linear interpolation of 1 to 0 from FCP/2 to FCP, but more likely that will be exponential, so you could try squaring that, or cubing it, and see how it looks. I'm not sure there's a real good formula for it (using exp or log or whatnot), just whatever looks best.
I can calculate the distance from FCP, but let's say I have a single mesh (like an icosphere). I guess I'm asking how I scale only the parts of it that are more distant than FCP/2. That seems to be what he's suggesting, right?
That's irrelevant. We talk about really great distances. Single objects keep their shape. It's just to get them back into the viewing area where otherwise the FCP would clip them. Just moving them closer would make them appear larger (sure since it'S closer) to compensate that you have to scale the object down:
transform.localScale = originScale * factor;
Your answer
Follow this Question
Related Questions
Scaling the GUI using a matrix issues 2 Answers
texture detail on large scale objects 0 Answers
How can I scale the insides of a ScrollView 0 Answers
How to make a localToWorld matrix for shader parameters? 1 Answer
How to Decompose a TRS Matrix? 3 Answers