on 14-05-2012 01:10 AM
I'm testing the basic model and found an strange behaviour: when the object is scaled the light is also scaled... but not in all objects.
A simple way to test it is with the BasicModelSample doing those changes:
On function Draw:
Matrix4 view = Matrix4.LookAt(...
Matrix4 view = Matrix4.LookAt( new Vector3( 0.0f, 5.0f, 2500.0f ),
new Vector3( 0.0f, 5.0f, 0.0f ),
new Vector3( 0.0f, 1.0f, 0.0f ) ) ;
Matrix4 world = Matrix4.RotationY(...
Matrix4 world = Matrix4.RotationY( FMath.Radians( turn * 5 ) ) * Matrix4.Scale(100, 100, 100) ;
The main character illumination looks right but the sword is really bright, a lot more than without the scaling.
Is this normal behaviour or is a bug?
Is there any way to scale objects without corrupting illumination parameters?
on 07-06-2012 01:20 PM
Any reason why you are multiplying with the world matrix ? Also can I please ask why you are altering the view matrix.
In my understanding the scaling is done in the vertex shader and then the output is given by multiplying with the worldviewprojection matrix.
World Matrix = Object Space to World space
View Matrix = Camera Matrix
Projection matrix = Used for giving the scene perspective(Example Orthographic projection or a view Frustum)
Multiplying these 3 matrices gives the WorldViewProj matrix which is then multiplied with our final object.
void main( float4 in a_Position : POSITION,
float4 out v_Position : POSITION,
uniform float4x4 WorldViewProj
a_Position.xyz = a_Position * 4.0f; (scaling the vertices by multiplying)
v_Position = mul( a_Position, WorldViewProj ); (transforming the object onto the screen)
This is my understanding but I am unsure of how you are performing scaling in the BasicModel Example.My above example will scale objects in the shader catalog example. It would be great if you could explain your ideas a little bit more.
on 09-06-2012 09:19 PM
Not wanting to speak for gusmanb but there is no reason why you can't combine your world matrix with a scaling matrix. In fact doing it this way would be somewhat less expensive than doing the scaling in the shader.
If you perform the scaling in the shader you have an extra cost of 1 additional multiply per vertex while if you apply the scale by multiplying the world matrix with a scale matrix then the scaling will happen implicitly as part of the transform into screen space.
However, one side effect of applying a scaling to your world matrix is it will also scale the vertex normals used for lighting I suspect that gusmanb's problem is due to the normals being scaled by 100, whereas the lighting calculations expect normals that are unit vectors (length 1)
To solve this problem if you normalise the vertex normals after they have been transformed by the normalMatrix (Inverse Transpose of the ModelView matrix) then that will get them back to unit length.
on 09-06-2012 10:21 PM
Hmmm, I've just looked at the BasicModel sample and while it seems that lighting is performed, it doesn't seem to be occuring within the shaders?? Certainly the .vcg and .fcg files that are part of the SampleLib don't perform any lighting. Indeed the shaders don't seem to be being used at for this sample.as I modified Texture.fcg to return a single fixed colour and saw no changes.
It seems to me that the BasicModel class by default at least makes use of shaders that we don't have access too.
I've personally moved away from BasicModel and written my own model class as I had too many problems getting the supplied BasicModel class to behave as I require.
Website ©2013 Sony Computer Entertainment Europe
All content, game titles, trade names and/or trade dress, trademarks, artwork and associated imagery are trademarks and/or copyright material of their respective owners. All rights reserved. [more info]