x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

camera space with fow in material

alt text

alt text

http://i.imgur.com/kR3QjEb.gif http://i.imgur.com/xtv3Z0n.gif

in gif evident that the normals are not considered properly in the camera Because in the transformation of normal are not taken into account the distortion of the camera FOV. How to calculate and transform the normals in camera space, taking into account the FOV?

Product Version: UE 4.13
Tags:
matcap_mat.jpg (227.9 kB)
more ▼

asked Nov 12 '16 at 07:38 AM in Rendering

avatar image

Sn_a_ke
147 9 16 21

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

You could do additional transform for normals that are already in camera space, using screen-aligned UVs. But for the effect you are after, there is a better solution.

Use Camera Vector Material Expression. It gives you a vector from pixel to the camera.

more ▼

answered Nov 12 '16 at 09:51 AM

avatar image

Deathrey
7.9k 130 31 293

avatar image Sn_a_ke Nov 12 '16 at 12:45 PM

yes camera vector is similar to what I need.

but I can not convert them with the world normal

if not too much trouble I'd be happy to get hint

avatar image Deathrey Nov 12 '16 at 02:50 PM

Take a dot product of camera vector and vertex/pixel normal.

avatar image Sn_a_ke Nov 12 '16 at 06:30 PM

I still can not get adjusted coordinates in the camera-space, taking into account the difference in the direction of pixels. the whole way transformation? Thanks.

avatar image Deathrey Nov 17 '16 at 02:37 PM

You should fully describe the effect you want to achieve instead.

avatar image Sn_a_ke Nov 17 '16 at 09:47 PM

Transform the pixels normal to camera space, given fov. And create camera aligned UV coordinates for the object. (matcap UV like in shaderFX in 3dsmax or maya).

While rotating the camera, "camera aligned UV" should not change. UV change should only be when the camera is moving.

avatar image Deathrey Nov 19 '16 at 12:21 AM

Transform the pixels normal to camera space, given fov.

Fov is completely absent from definition of camera space. Should it not be the case, you would have a multitude of spaces.

avatar image Sn_a_ke Nov 19 '16 at 05:09 AM

alt text alt text

that's what I mean by the camera-space, taking into account fov

alt text

It is approximated to the desired result, but still not the same. http://i.imgur.com/vg6dyZu.mp4 on gif seen a slight rotation of the UV when to rotate the camera.

avatar image Deathrey Nov 19 '16 at 10:37 AM

If you want a screen-aligned texture on your object, but one, that stays stationary while cam is rotating, why don't you just use screen aligned UVs, with addition of offset to compensate for camera rotation?

avatar image Sn_a_ke Nov 19 '16 at 11:06 AM

I tried, but I have difficulty with that ... if you showed how to do it, I would be grateful.

avatar image Deathrey Nov 23 '16 at 03:52 PM

Post a reference to the effect you are trying to achieve.

avatar image Sn_a_ke Nov 23 '16 at 08:08 PM

screen aligned UVs - normalWS matrix*camera direction vector, and that space is flat.

but I need to transform normalWS*(cameravectorWS*camera_direction_vectorWS), is curved space.

then convert RG in the UV

alt text and then if we consider the sphere of UV 0.5,0.5 center of the sphere will always look at the camera. And the spheres of the edge will always be in the tangent space perpendicular to the camera's view

avatar image Deathrey Nov 23 '16 at 08:50 PM

A reference of the effect, that was already implemented. Video, screen shot, or description or something like that. What you just posted is, as said above, as trivial as taking a dot between view dir and vertex normal.

avatar image Sn_a_ke Nov 24 '16 at 07:30 AM

http://i.imgur.com/wribBUn.mp4 http://i.imgur.com/yobzcHF.mp4

screen-aligned texture from pixel normals on my object, but one, that stays stationary while camera is rotating...

avatar image Deathrey Nov 24 '16 at 01:21 PM

You are terribly over-complicating things. Matcap UVs can be obtained like this: alt text Further read here.

avatar image Sn_a_ke Nov 24 '16 at 01:43 PM

but it is not oriented to the camera, it is oriented to screen Z, but not to the camera. It looks good only when it is in the center of the screen. alt text

The same material in the first question is, as an example

https://www.youtube.com/watch?v=OwA5qhQiRfg my last comment for this video http://i.imgur.com/UttOPth.gifv

avatar image Deathrey Nov 24 '16 at 11:48 PM

There is a formula in the link I've posted. Use this for custom node:

float3 R=C-2*dot(N,C)*N;

float D=2*sqrt( R.x*R.x + R.y*R.y + (R.z+1)*(R.z+1));

float U=(R.x/D)+0.5;

float V=(R.y/D)+0.5;

return float2(U,V);

Custom node should be set to float 2 output and have View-Space Camera vector as input C and view-space normal as input N.

For the distortion of the texture at the sides of a viewport, well.... your sphere isn't a sphere in the corner of a viewport anymore, so there will inevitably be some distortion. It will increase with larger FOVs. Typically, this is ignored. Have a proper padding in your matcap texture.

You could play around further and calculate divisor separately for U and V, introducing sort of compensation for position of the pixel on screen, but in the long term it is not worth the effort, no matter what kind of effect you are after.

avatar image Sn_a_ke Nov 26 '16 at 08:35 AM

it gives the same result as earlier ...

closest to the desired: alt text

but this is not a complete transformation, to get the full need something like this: alt text

avatar image Sn_a_ke Nov 20 '16 at 09:11 AM

I've got one of two problems: normalize the vector screen aligned UV to complete rotation. or get the UV after additional turn

alt text

(before the texture is no mask RG,, but essence not in it.) aligned RG after normalization does not match...

offset to compensate for camera rotation in custom node:

 float4 q;
 q.xyz = cross(v1, v2);
 q.w = sqrt((v1.Length ^ 2) * (v2.Length ^ 2)) + dot(v1, v2);
 return v1 + 2.0 * cross( cross( v1, q.xyz ) + q.w * v1, q.xyz );

avatar image Sn_a_ke Nov 20 '16 at 10:12 AM

alt text

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

this version is not bad http://i.imgur.com/7oR6y49.mp4

alt text

more ▼

answered Nov 27 '16 at 04:38 PM

avatar image

Sn_a_ke
147 9 16 21

avatar image annuschka Nov 29 '17 at 11:49 PM

This is a good starting point but it does not work on very high FOVs. My version is not correct, too (because I suck at math):

both versions with high FoV

I looked at the UV channels of spheres: They get distorted to ellipses and their axis rotate, but the UV gradient stays top-bottom/left-right which leads to wrong values (e.g. the "bottom" in the ellipse is not it's lowest point (I guess)). So my basic idea was to "modify" the UV gradient to the correct position and luckily the B channel of your version is exactly what we need:

UV Channels visualized

So here is my expansion of your version:

Nodes

  1. Just mixing the B channel into U and V does only work for half the screen. The other half needs an inverted B channel.

  2. The effect needs to fade or scale somehow. It's too strong. This is what I try to do in the center area. Basically I make a exponential radial gradient which I "zoom" in and out based on FoV. Well, this is all trial and error and not perfect. I'm sure someone can find a more elegant solution.

Here are all nodes of the material function on pastebin

And here are some images:

test matcaps

Also: It is super cheap! But it looks like a very complex material (at the first glance). This might be useful for mobile

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question