Expand&Stablilize Viewport Vectors

z

one day i would turn this to some real shit


There is an idea come out month ago,i want to make a scene which a dragon rush into a painter with some cool animations.But i found that i can't do animations.So i thought about using a spawned mesh blueprint instead.This artcle is talking about the rendering part.I could describe how i made this dragon further if anyone interested.


The first one is sphere.Usually when we sample a cubemap,we use the reflection vector which calculated by our camera vector and object surface normal.But this time i wanna a interactive sphere(hard to explain in word,check the result,we display the texture in the same position on the sphere and objects pass though).So obviously we need to use camera vector to sample the texture.But if we only use the default camera vector to sample,the displayed area may not be what we expected and will shrink or expand when our cam moves.Let's do some operations on it.



See the pic above,we have cam postion,actor position and a unique sphere radiu,so we can got a vector from cam to sphere center,all vectors from cam to sphere surface and the biggest angle compare to the center vector.Put all this vectors in a uniform sphere.

OA in the pic means the vector to the sphere center,OP just represent any vector to the surface,and OP' is target vector we wanna move OP to.Cause OAP and OAP' are two isosceles triangle,we can easily get the angle a,then the length of CP according to the Sine Law,multiply CP and the opposite direcion of our camera vector OP,we can get the vector PC.add AP and PC,we can get the vector AC,which is the same direction as AP'.Then check a nother Sine Law(don't know what that was called,just check the red part),we can get the length of AP',normalize the vector AC then multiply the length of AP',we can get the vector AP',then simplily OP' came out,that's what we need.Whole calculation showed underneath and you can copy this then CTRL+V to paste in your UE4 material editor.



The another situation is using a plane to sample a texture2d,this is much easier.we don't have to deal much with vectors.Just push the point on other object's surface to the plane.Only thing need to mention is the dist from cam to the plane.The simple way is keep the plane orthemetric.Then the plane function would be x or y or z=n.But if you want to rotate the plane to a specific angle.Dont Calculate the plane function!!!Just pass the world to local tranform matrix of the plane to your shader,tranfer your camera position to the plane's local position.Here we just make things simple.



Also whole calculation here and copy this to your UE4 material editor.



I can almost sure that those aren't the best solution for both the situation,just share my thought about it.If you guys know a simper or more optimized way to do that,please let me know.And for anyone who are interested,you can try this.I believe you can make some real cool effects with this.Enjoy.


Now add myProject File.