Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

  • 0
Sign in to follow this  
V3ndetta

Basic shader related question

Question

I am learning to write shaders in unity3d and I got the following code(so far following the tutotrial):

 

Please login or register to see this code.

 

At the

Please login or register to see this code.

am I storing the points of the object? Or am I storing only 1 position, and what is that one position? I know from the definition of vertex that it is a data structure used to describe certain attributes, like the position of a point in 2D or 3D space, but what exactly am I storing there?

Share this post


Link to post
Share on other sites

5 answers to this question

Recommended Posts

  • 1

You can use too a float4 (or half4 for optimized code) with colors and consequently lights, but in this case, float4 color is equal to red, green, blue and alpha values. I am working on a bundle with more than 70 filters for Unity. This semantic seems to me really complicated for novice and consequently clever and elaborated. Often, by changing a few parameters, you have a totally different displaying. Now my computer becomes a lab :)

 

Please login or register to see this link. on a blue and red cubes, and a green sphere...

Please login or register to see this link. (but final sum divide by 0) - Please login or register to see this link. :)

Share this post


Link to post
Share on other sites

  • 1

Basically when you use a float4 as a position in a shader code, you define X, Y, Z values in space and another one which is named "the fourth coordinate of the matrix model". It is useful for movement and transformation when you combine some points in space. It represents an affine transformation - a linear transformation together with a translation. Obviously, if a position is static (or reached), this value is equal to 1. When you translate a position, it increases starting at 0. Here you can read an explanation which is not more clear than what I said :)

Please login or register to see this link.

Imagine a translation on Y axis :

first position : 0, 0, 0 - 0

second position : 0, 1, 0 - 1

  • Like 1

Share this post


Link to post
Share on other sites
  • 1
Please login or register to see this code.

Is the position of the vertex in local space (model space) ....in extremely basic terms it uses x,y,z and the fourth is used to display a 3d object onto a 2d screen (the fourth component should be 1  for points and it needs to be 0 for directions)

 

this may help  Please login or register to see this link.

Share this post


Link to post
Share on other sites
  • 0

Thanks for the answers. So the x,y and z positions could also be used for the lighting of the model, for example if the object is static the xyz will be 0, and we calculate the light shining on it, angles and other stuff we need to take in consideration based on these right? The object is moved, the position values increase, and we basically change the way is reflected off the object again by updating the calculations. Sorry if it's a dumb thing I just said, it's literally mind numbing getting into these.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...