I have not really considered concepts of shading, lighting, etc. I have only just gotten to working with solid shapes in 3D (I use my own mechanics for this)...
To make some sorta effect, I thought maybe the color of things could change or get darker or something the further away it is in 3D space..
in Java there is a gradientPaint tool that will change the color or paint from colorOrPaintA to colorOrPaintB along the line described by pointA and pointB. So, I need to figure out where the steapest line (greates difference in z) on a polygon in 3D space is; The line must go from a point on one edge to a point on antoher (or from the corners, but that is not very likely).
Does anybody know how to find this line (make a routine that does this)?
0 ·
Comments
The correct way of doing shading is to shade each pixel (costly) or to calculate the shading on the edges or on the vertices and then interpolate through them.
Take a look at the Goraud algorithm, it's quite simple and gives good results.
nICO
[hr]
[italic]How beautiful, if Sorrow had not made sorrow more beautiful than Beauty itself.[/italic]
JOHN KEATS
So back to the question: DOES ANYBODY KNOW HOW TO FIND THE STEEPEST SLOPE/LINE ACROSS A PLANE?
:
: So back to the question: DOES ANYBODY KNOW HOW TO FIND THE STEEPEST SLOPE/LINE ACROSS A PLANE?
:
Let me explain a little more:
What I can do is find the line with the steepest slope, and do a gradient along that line in correlation to the Z or distance from "camera" from endpoint to endpoint
:
Sorry, I did not understand well the problem...
Ok, let's do a practical example on how you can do this:
You have a situation like this:
[code]
^ z
 *P3

P1*  *P2

T> x

 L

C

[/code]
C is the camera pos, T is the camera target, P1,P2,P3 the points of a triangle, L the light.
Note that you should repeat this process for each triangle in your object (I assume you have objects formed of triangles).
Stated that you can represent each point as a vector emerging from the
origin, you can calculate the vectors LP1, LP2 and LP3.
Find the vector that has the lower module (in our example LP2) and you know the gradient orientation (ie the LP2 direction).
Now you calculate the intersection beetween LP2 and P1P3 lines, that we call I (ok, my drawing sucks, but I cannot do something better ;))
[code]
^z

 I *P3

P1*  *P2

T> x

 L

C

[/code]
So, if the object color was (in RGB) (100,100,100), you can define the color of P2 and I based on the distance from L.
You should create a parameter that represent the maximum distance that the light can lit, suppose it's 500 units.
So, if LP2 is 100 and LI is 110 you just do:
1(100/500) = 0.8
1(110/500) = 0.78
So the gradient should be oriented on the P2I direction and its colors should be the 80% and 78% of the object color (so, in our example 80,80,80 and 78,78,78).
I hope this can help you. To have better shading you can always use a non linear approach when choosing the color (a quadratic or cubic approach is visually much more appealing but, as you're using Java, I think it would slow down too much the program).
nICO
[hr]
[italic]How beautiful, if Sorrow had not made sorrow more beautiful than Beauty itself.[/italic]
JOHN KEATS