Model

Reply

BasicModel shader bug with scaling?

Hi.

 

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:

 

replace

Matrix4 view = Matrix4.LookAt(...

 with

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 ) ) ;

 and

Matrix4 world = Matrix4.RotationY(...

 with

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?

 

Thanks.

Please use plain text.

Re: BasicModel shader bug with scaling?

Thank you for the report, we'll look into it.
PlayStation®Mobile Dev Team
Please use plain text.

Re: BasicModel shader bug with scaling?

Hi gusmanb,

 

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.

 

Example

 

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.

 

Thanks 

Kyoufu wo oshiete yarou!
Please use plain text.

Re: BasicModel shader bug with scaling?

 

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.

 

Claire

 

 

 

Please use plain text.

Re: BasicModel shader bug with scaling?

 

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.

 

Claire

 

 

 

 

 

 

 

Please use plain text.
Announcements

Welcome to the PlayStation Mobile Developer Forums


This is a community for the discussion of technical topics with other developers and SCE engineers. Posting ideas/requests are also appreciated. Join the discussion!

PlayStation®Mobile開発者フォーラムでは世界中の開発者の皆様と一緒に、議論や情報交換が可能です。SCEも議論に参加し、皆様の開発をサポートします。アイデアやリクエストも大歓迎です。ぜひご参加ください。

PSM Developer Registration (for free) on PSM DevPortal is required to post on the forum.
Please sign out then sign in again to the forum and PSM DevPortal after you have completed the registration.

フォーラムへ投稿をするにはPSM DevPortalへの登録(無料)が必要です。
登録後はフォーラムと PSM DevPortalを一度ログアウトし、再度ログインしてください。