Graphics

Reply
Accepted Solution

Noob question regarding point lights

Hello all, I'm starting to play around with the SDK and I'm trying to implement a light manager system, specially after following this nice tutorial http://www.gamefromscratch.com/post/2012/04/30/Exporting-from-Blender-to-PS-Suite-Part-2.aspx 

 

I found that the BasicProgram has in its BasicParameters support for directional lights via the SetLightDirection property, but I see no support for either types of lights or light position.

 

So is there any way to add point and eventually spot lights to a scene through the BasicProgram? Or should I create a custom shader and then load it as a BasicProgram? (in which case I would really appreciate any example of a basic shader loaded through the BasicProgram constructor)

 

Please use plain text.

Re: Noob question regarding point lights

Hi:

 

Well you can add it easly. Use this http://http.developer.nvidia.com/CgTutorial/cg_tutorial_chapter05.html part "5.5.2 Adding a Spotlight Effect" to understand wich parameters you need to add to the shader(use the same shader will work =)  means copy/paste it) and then add the needed code in the BasciModel to set does parameters and thats it.

 

Cheers,

Please use plain text.

Re: Noob question regarding point lights

Alright this is not a complete solution but here it goes, also keep in mind that I might have a lot of mistakes in my interpretation so please correct me if I'm wrong.

 

So if you want to load a model using the BasicModel class, you will have to use a BasicProgram to render it. The thing is that BasicProgram only support directional lights in its properties (BasicProperties), if you use the default version of the BasicProgram. Now the constructor is able to create a new BasicProgram from a cgx, with the condition that the cgx has the parameters that any BasicProgram uses in the correct index.

 

This means that you need to create a vertex shader with all the properties that the BasicProgram shader uses, and then you can add your own properties to the shader and access them through the SetUniformValue method (as BasicProgram inherits from ShaderProgram).

 

In my opinion it would be nice if Sony added the framework for the shader in their documentation, but it might be just me not knowing how to work with the SDK.

 

After you have all these parameters set, you can apply the shader structure to which Alex kindly pointed to. 

Please use plain text.

Re: Noob question regarding point lights

Hi:

 

Yes. It's not a complete soultion, but you now are in the correct path. You just need to add the extra needed data extending BasicModel and adding the needed SetUniformParam to get the cgx working.

Give me some time and I will probably post the code.

 

Cheers,

Please use plain text.

Re: Noob question regarding point lights

Hi Alex, 

 

I think I was able to fill in the BasicProgram parameters in the shader yesterday, although I have been struggling with the way they handle multiple world matrixes, also, it seem as we need to define an array of lights (light parameters) in the shader, but it puzzles me the actual size that has to be used (for now I have it at 4). 

 

Currently this is my parameter list for a really basic vertex shader:

 

void main(uniform bool 		EnableLighting,		//0
          uniform bool 		EnableFog,			//1
          uniform int  		WorldCount,			//2
          uniform int		LightCount,			//3
          uniform float4x4	ViewProjection,		//4
          uniform float3	EyePosition,		//5
          uniform float4	FogVector,			//6
          uniform float3	FogColor,			//7
          uniform float4x4	WorldMatrix[4],		//8
          uniform float3	LightDirection[4],	//9
          uniform float3	LightDiffuse[4],	//10
          uniform float3	LightSpecular[4],	//11
          uniform float3	LightAmbient,		//12
          uniform float3	MaterialDiffuse,	//13
          uniform float3	MaterialSpecular,	//14
          uniform float3	MaterialAmbient,	//15
          uniform float3	MaterialEmission,	//16
          uniform float3	MaterialFactor,		//17
          float4 in a_Position    : POSITION,	//18
          float2 in a_TexCoord    : TEXCOORD0,	//19
          float4 in a_VertexColor : COLOR0,		//20
          float4 in a_Normal	  : NORMAL,		//21
          float  in a_Weight	  : BLENDWEIGHT,//22
          float4 out v_Position   : POSITION,	//23
          float2 out v_TexCoord   : TEXCOORD0,	//24
          float4 out v_Color      : COLOR0)		//25
{
...
}

 It seems as the multiple world matrixes are related to the animation of the object (I'm using the BasicModelSample from the SDK provided samples), I can't figure out how to actuallty use them.

 

Once I figure that out it will be just a matter of adding the extra light parameters to the shader in order for it to process point and spot lights (which should not be a problem)

Please use plain text.

Re: Noob question regarding point lights

Hi:

 

Fast question :Are you planning to use more than one light afecting the model?

 

Cheers,

Please use plain text.

Re: Noob question regarding point lights

Not for now, but eventually; however, the thing is that the way the BasicProgram instantiates its parameters requires you to have an array of lights in the shader, which means that they process their lights array inside the shader rather than outside.

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を一度ログアウトし、再度ログインしてください。