Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / How to use Per Pixel Ligh

Author
Message
Jonathan Archer
10
Years of Service
User Offline
Joined: 29th Jul 2013
Location: Italy
Posted: 5th Aug 2013 20:43 Edited at: 5th Aug 2013 20:43
Hello,

For my project I intend to use Per Pixel lighiting instead of normal lights of DBP (directional lights, spot lights...). Nevertheless, even if I isolated the code, I am unable to make it work. This is due surely to my inexperience with the use of shaders. I proceed in this way:

- Load the effect with Load effect;
- Apply the effect with set object effect to all of the object that light or are lighted;
- Write vec = make vector4(1) for some reason;
- When the light moves, It have to write set effect constant vector *,\"LightPosition\",1

Surely I mistook something because nothing happens and the light in mid-air that I created disappears.
Someone can explain me what I have to do?

These are the lights in mid-air.

Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 5th Aug 2013 23:06 Edited at: 5th Aug 2013 23:09
What is interesting about these shaded objects is how bright they are considering they appear to be unaffected by any of the lights.

Is there any chance you could post up a code sample or example of what you have done? There are a number of things that could be wrong here, I will need to see which one is occurring.

You will usually get a faster response of assistance around here if you post up your code, no matter how pointless it may seem. If you want to, you can post up the shader code and highlight the text, then hit the code button; and the same with the source code that deals with the shading.

Quote: " Write vec = make vector4(1) for some reason;"


Vectors are often used to pass coordinates into the shader, from your program. So when you set the constant vector in the shader, you told it to set the light position to the position stored in Vector 1. Most lighting shaders I have seen make use of the 4th vector element which is represented as W Vector4() in DBPRO. They tend to use the forth element as a means of passing the light range to the shader.

Jonathan Archer
10
Years of Service
User Offline
Joined: 29th Jul 2013
Location: Italy
Posted: 6th Aug 2013 12:27 Edited at: 6th Aug 2013 20:20
Actually, the scene is not affected by any light. The base of the waterfall is bright compared to the other objects because I used set object light *,0. The fact is that, as half of plane is under the matrix, if It is illuminated by a light, It remains dark. So, I had to provide for.
I post you all the project and I highlight the important parts (Do not mind if some part of code are inefficient; I will optimize it):


Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 6th Aug 2013 17:30
You should use code tags, not quotes.

Jonathan Archer
10
Years of Service
User Offline
Joined: 29th Jul 2013
Location: Italy
Posted: 6th Aug 2013 18:51
If I use quote, I think I cannot highlight the text in bold, isn't It?
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 6th Aug 2013 19:12
Correct, but quoting large chunks of code is annoying sometimes.

Jonathan Archer
10
Years of Service
User Offline
Joined: 29th Jul 2013
Location: Italy
Posted: 6th Aug 2013 20:22
You are right. Now I delete unimportant things
Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 6th Aug 2013 21:50
Interesting; object 89 appears a part of the scene that is assigned the per pixel lighting shader; yet its light source is set on itself; is this a self lit object?

Quote: "set vector4 1,object position x(89),object position y(89),object position z(89),0"


You didn't post shader, so I am having to guess that the zero at the end does not pass on the light range; some other shader constant does.

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 7th Aug 2013 13:14
It could be the reciprocal of range so a zero means no attenuation with distance.



Powered by Free Banners
Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 7th Aug 2013 15:20 Edited at: 7th Aug 2013 15:23
I doubt that, but we'll see.

Jonathan Archer
10
Years of Service
User Offline
Joined: 29th Jul 2013
Location: Italy
Posted: 7th Aug 2013 18:00
I download the shader here:
http://forum.thegamecreators.com/?m=forum_view&t=79849&b=8

The folder is "02 - Objects - Lighting/19 - Per Pixel lighting [Evolved] [SM1.4] & [SM2.0]"



In the sample example, It use not lights, so I did not make lights in my project.
In the previous photo, the object 89 is on the right. But when I apply him the effect, It disappears. For this, I wonder if It should be a self lit object.

Sorry If I reply vaguely sometimes, but I don't speak and understand english very well m(_ _)m
Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 7th Aug 2013 20:31 Edited at: 7th Aug 2013 20:33
So this is one of EVOLVED's shaders.

In this one the light range is stored in the constant called LIGHT_RANGE and there is only ONE light source. It will not cast light from more than 1 location. You were supposed to set this as the effect for your landscape and plants. Setting the light constants as the location, color and range of ONE light.

These are the variables in the shader that represent the constants in focus:

Quote: "// ````````````````````````````````````````
// TWEAKABLES
// ````````````````````````````````````````
float U <> = 1.0f;
float V <> = 1.0f;
float Height <> = 0.04;
float4 Light_Position <> = {100.0f, 100.0f, 100.0f, 0.0f};
float4 Light_Colour <> = {1.0f, 1.0f, 1.0f, 0.0f};
float Light_Range <> = 250.0f;"


Another thing to note is that this shader is also a bump mapper; something a little more complex.

I have no solid clue as to how you textured the object; its not in the code you posted. (It seems in this case just posting the whole thing would have made things clearer)

This shader like most, requires more than one texture to be given to an object. It needs 4 textures per object; a normal map, light map, height map and base texture. If you do not know what I am talking about, just state so.

There is another parameter available in the Texture Object command; this overload is set as follows: Texture Object [Object Number], [Stage Number], [Image Number]; notice how this was done in the code sample in the same folder that EVOLVED created:


Do you understand?

Post up the project in a ZIP file so I can see the problem. Meanwhile it might be a good idea to play around with EVOLVED's example program before you continue with your project. Take a look at the textures he created; look at the code and indicate anything you are not sure about.

Once you grasp the technique used; you can then create more light sources in the shader and we can help you.

Jonathan Archer
10
Years of Service
User Offline
Joined: 29th Jul 2013
Location: Italy
Posted: 8th Aug 2013 15:02
I think that you opened the wrong project. I did not refer to "16 - Parallax 2.0", but "19 - Per Pixel lighting [Evolved] [SM1.4] & [SM2.0]". In this project It is not used neither bump mapping nor multitextures.

I upload you my project.
http://www.speedyshare.com/qvA42/Monte-Myoboku.zip
The password is IoSoNoNaBbO

P.S: Don't take care, if the toads are turned on the wrong side.
Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 8th Aug 2013 23:45 Edited at: 8th Aug 2013 23:51
I know you did; it is project number 19 that I was referring to; as you indicated initially. However, your shader is less complex than the one in the Shader Pack I downloaded; perhaps your shader pack is the older one.

All of the objects you want affected by the lights need to be assigned this shader; not the lights themselves. The shader is to render things affected by the light source, not the light source itself.

Do the following with the shader in the loop. The shader needs to be told where the lights are manually because they are mobile, not static. It will not keep track of moving object positions on its own, (unless you programmed the shader to do so).

Use something like this, I have used named variables to illustrate:


You will not need to keep updating the color and light range if they do not change; in this instance, simply set the variables prior to the loop; after the shader is loaded.

Now at this stage whilst the program runs the light location is updated as the object moves; but there is yet to be any significant shading taking place, you now need to tell the shader what objects to shade... So, set all the objects that need to be lit on a per pixel basis like so:



Or perhaps we could apply them in one go by using an array like so:


Setting the object effect only needs to be done once, prior to the engine loop.

When you get that to work, the next step is to add extra lights to the shader.

I noticed that you are using the Matrix system for your terrain. Why so?

Jonathan Archer
10
Years of Service
User Offline
Joined: 29th Jul 2013
Location: Italy
Posted: 9th Aug 2013 17:14 Edited at: 9th Aug 2013 17:15
Hello Chris,

You was very clear, but I have a problem. I wrote this:



And an error appears: 3D Memory error at line 441 (this is Set Object Effect o, 1).

Maybe I mistooke something?

I do not speak English very well, so please be patient and write without abbreviations.

My jewel: Intel Core i5-2450M 2.5Ghz-3.1Ghz; 6GB RAM DDR3; NVIDIA Geforce GT 630M 2GB dedicated; 750GB HDD
Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 9th Aug 2013 23:32 Edited at: 9th Aug 2013 23:34
Typical.. now where did I see that error message before

...

Ahh

Quote: "Mike Johnshon: There is a limit on the amount of indices you can have per mesh. This is because we use 16 bit buffers resulting in a max of around 64,000 indices which gives a max of around 21,000 polygons. To solve this try breaking your object into more parts e.g. change from 1 large mesh to several meshes.

http://forum.thegamecreators.com/?m=forum_view&t=94841&b=15&msg=1064168#m1064168"


In other words, there is too much detail in one single limb or object. The engine has to use an indexed array of faces (polygons), normals (face angles) and UV coordinates, assigning them to vertices. This limit is what caused the crash when the set object effect command was called. But other commands can cause this problem; I personally had this issue with saving a complex object.

Find out which object caused the problem. Narrow down the set effect procedure to pin point which objects have too many indices; then reduce the complexity of that object. This is another reason why object complexity must be kept under control.

Jonathan Archer
10
Years of Service
User Offline
Joined: 29th Jul 2013
Location: Italy
Posted: 10th Aug 2013 15:14
So, what I wrote is correct, but the models must have less that 21,000 polygons? All of the models that I created have less than 10,000 polygons... except one, that has 81,000. This means that I have to fix this model? :S

I do not speak English very well, so please be patient and write without abbreviations.

My jewel: Intel Core i5-2450M 2.5Ghz-3.1Ghz; 6GB RAM DDR3; NVIDIA Geforce GT 630M 2GB dedicated; 750GB HDD
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 10th Aug 2013 15:28
Quote: "This means that I have to fix this model?"

Just split it into limbs.

Jonathan Archer
10
Years of Service
User Offline
Joined: 29th Jul 2013
Location: Italy
Posted: 10th Aug 2013 15:54 Edited at: 10th Aug 2013 15:54
I do not know really how to do it. I never worked with limbs. XD
But I can reduce the polygons with Blender, so if you confirm me that this is a possible solution, I do it

I do not speak English very well, so please be patient and write without abbreviations.

My jewel: Intel Core i5-2450M 2.5Ghz-3.1Ghz; 6GB RAM DDR3; NVIDIA Geforce GT 630M 2GB dedicated; 750GB HDD
Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 10th Aug 2013 16:32 Edited at: 10th Aug 2013 16:33
You can do what Mobiius said in Blender, select a number of polygons in edit mode then press [P] to seperate the selected polygons. You will be shown a menu and the required option is 'Selection'. Now a new limb has been created.

In Blender, everything in the scene overview list that has a triangle icon with 3 vertices is classified as a limb, even if the object contains no mesh.

Now to apply the shader use, Set Limb Effect, instead of Set Object Effect. Get the object limb count and then use this count to act on each limb in the object.

I am still guessing that this will work; if it fails then try using the Decimate modifier in Blender to reduce the polygon count; or simplify it in Sculptris.

Note that the polygon count is indicated in the top menu to the right hand side. If you haven't gotten round to understanding modifiers yet then let me know. Hopefully the splitting into limbs idea will work.

So, what happens when this object is removed from the scene, does the lighting work?

Jonathan Archer
10
Years of Service
User Offline
Joined: 29th Jul 2013
Location: Italy
Posted: 12th Aug 2013 11:32
Can I see how many limb there are in Blender?

So, I tried to reduce the polygons of the object, but I did not solve the problem. After, I eliminated this object from the scene and 3D Memory error at line 441 does not appear, but now the vector at line 22 does not exist (that is Set Vector4 1,Object Position X(1),Object Position Y(1),Object Position Z(1),0). So, I noticed some error and I fixed the code:



Now, the game starts, but no light is emitted.

I do not speak English very well, so please be patient and write without abbreviations.

My jewel: Intel Core i5-2450M 2.5Ghz-3.1Ghz; 6GB RAM DDR3; NVIDIA Geforce GT 630M 2GB dedicated; 750GB HDD
Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 12th Aug 2013 14:39 Edited at: 12th Aug 2013 14:42
Quote: "vec = make vector4(1)"


If this line of code was executed prior to the set vector command, then the vector4 error should not have occurred.

I must leave my office for a while. If you update the project you uploaded so I can see what went wrong, when I return or if someone else gets a chance, the problem can be resolved.

Also, if possible, upload the object with the problem so I can test it out in the project. It seems strange that the memory limit problem occurred when the polygon count was reduced.

Quote: "Can I see how many limb there are in Blender?"


You can look at the top menu status bar where it says Object 0/3, as shown in the attached image. The first number indicates the number of objects currently selected. In Blender anything that can contain a position is classified as an 'Object'; and when exported each object becomes a LIMB. Cameras and lights are objects that do not get exported. An additional root limb is created by the DirectX exporter.

Because your shader pack seems different than the one I downloaded; could you post a screenshot or demo of what the original shader project your downloaded looks like, revealing how the lighting will look?

Attachments

Login to view attachments
Jonathan Archer
10
Years of Service
User Offline
Joined: 29th Jul 2013
Location: Italy
Posted: 13th Aug 2013 17:29
I uploaded the new project. The password is IoSoNoNaBbO

http://www.speedyshare.com/uf3sp/Monte-Myoboku.zip

The model that I reduced is "Rospo di pietra (17).x".

Here there is the screen of the saple project of the shader.



I do not speak English very well, so please be patient and write without abbreviations.

Intel Core i5-2450M 2.5Ghz-3.1Ghz; 6GB RAM DDR3; NVIDIA Geforce GT 630M 2GB; 750GB HDD
chafari
Valued Member
17
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 13th Aug 2013 20:15
Monte Myoboku.zip

Reported as extreamly damage for PC with my anti virus

I'm not a grumpy grandpa
Jonathan Archer
10
Years of Service
User Offline
Joined: 29th Jul 2013
Location: Italy
Posted: 13th Aug 2013 22:01
Are you sure? My antivirus reported that there are not viruses :\

I do not speak English very well, so please be patient and write without abbreviations.

Intel Core i5-2450M 2.5Ghz-3.1Ghz; 6GB RAM DDR3; NVIDIA Geforce GT 630M 2GB; 750GB HDD
Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 14th Aug 2013 00:45 Edited at: 14th Aug 2013 00:53
OK the scene lighting did not affect any visible object because the shader was only applied to one limb in each object, not all of the limbs. In blender limb zero is the root limb which happens to have no mesh.

A loop like the following can be used to apply the shader to all limbs:



If you install Matrix1 utilities, one of many improvements to the language can shorten the code as shown here:


I have stored the limb count in a local variable because of speed potential and habit.

Remember that the only reason why we are not using the easy method of applying the shader to the whole objects is because of the polygon count issue with your attached 3D models. However this did not solve the problem; therefore the easiest thing to do is to reduce the polygon count.

The lighting also works if you omit the troublesome 25 megabyte super object your created. It took me 10 minutes to import that 80,000 polygon toad into Blender; as you are aware this contains to much detail; and I think it could look much better with just 5000 polygons and a bit of smoothing and sharpening applied in the right places.

Because the toad was generated with strangely orchestrated polygons, some shaders may not look fantastic with your models; and some of blenders modifiers have no use.

When I imported the model, it contained only one limb. So it seems you did not split this model up.

I was not able to decimate the mesh because the polygon topology is pretty bad.

Your light range is too low. Set LightRange# to something higher than 2000. When you eventually get the light system to work, you will notice that all of the objects become black. Increasing the light range causes the light attenuation to expand enough to reach the objects, and the falloff will gradually fade the textures to black.

Splitting the mesh did not fix the problem and as I mentioned I could not decimate it due to its irregular polygon structure.

I have attached the change to the model saved as an X file and Blend file with the mesh chopped up into 4 pieces; all for reference. I used the box selection tool [B key] and the seperation tool [P key]. I named the files 'Toad' because I know nothing about Naruto and have no idea what is going on in the scene and it looks like a toad.


Another tip;

Quote: "
Angolo_Pianta1_Basso:
r=rnd(135)
If r<75 then goto Angolo_Pianta1_Basso
Yrotate object o+30,r
"


A better way to rotate an object between 75 and 135 degrees is to do the following:



If you install Matrix1, you can get a handy Random() function that returns a floating point result. Not-to-mention a Limb Has Mesh() function, useful for filtering limb queries for limbs with meshes.

Quote: "Monte Myoboku.zip

Reported as extreamly damage for PC with my anti virus "


No issue on my machine; what anti-virus package do you have installed?

Attachments

Login to view attachments
chafari
Valued Member
17
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 14th Aug 2013 00:58
I'm using the free AVG . I read some false positives with this one

I'm not a grumpy grandpa
Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 14th Aug 2013 03:39
Me too.

Jonathan Archer
10
Years of Service
User Offline
Joined: 29th Jul 2013
Location: Italy
Posted: 15th Aug 2013 18:42
I put your advices into practise and, eliminating the toads, I could see the shader. The effect is amazing!

The object you spitted is of 80000. But I reduced it to 17000 polygons. The name was "Rospo di pietra (17).x". This object is essential for the scene. We cannot try to split it instead of the other one?

Before, you asked me why I use the matrix instead of a 3D object, is not it? I did not think it sincerely. But now how I have to apply the shader to the matrix?

Thank you for the advices that you gave me until now!

I do not speak English very well, so please be patient and write without abbreviations.

Intel Core i5-2450M 2.5Ghz-3.1Ghz; 6GB RAM DDR3; NVIDIA Geforce GT 630M 2GB; 750GB HDD
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 15th Aug 2013 18:50
You can't apply shaders to matrices.

Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 17th Aug 2013 07:12
I was thinking what Mobiius stated; you would want to use shaders on the terrain, but it is a matrix, not a terrain.

Have you heard of Blitz Terrain and Advanced Terrain? Do a forum search and you should find a number of good example projects explaining how to develop terrains. You can still use your height-map image to define the shape of the land, but working with terrains is not as straight forward as it would seem for learners.

Take a look at some of the terrain projects and tell us what you think.

If you do not wish to use such plugins, you could always learn how to create terrains in Blender.


Quote: "
The object you spitted is of 80000. But I reduced it to 17000 polygons. The name was "Rospo di pietra (17).x". This object is essential for the scene. We cannot try to split it instead of the other one?"


Jonathan Archer
10
Years of Service
User Offline
Joined: 29th Jul 2013
Location: Italy
Posted: 17th Aug 2013 15:54
Yes, I have heard of Blitz Terrain. I found some sample projects and I had a look at the commands. It looks easy to use, but I think that It is a little too excessive for my expectations. My matrix, like you see, is not complex at all. Precisely, I confined myself to record the height of each segment in the file "Dati/Matrice.dat".



I would like simply to make a terrein identical to that of now, but I don't see commands to plan out width and depth and the number of segments. I cannot plan the height of each 3D segment. I can use Blender to make the terrain, but It should be difficult to make it identical to this, is not it? Unfortunately, I always used DBC, so I do not get used this and maybe my statements look stupid.

Thank you again for your support!

I do not speak English very well, so please be patient and write without abbreviations.

Intel Core i5-2450M 2.5Ghz-3.1Ghz; 6GB RAM DDR3; NVIDIA Geforce GT 630M 2GB; 750GB HDD
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 17th Aug 2013 16:59
Matrices are slower than terrains, can't be textured like terrains, can't have shaders applied to them, can't be moved/rotated and are just generally poo. (lol)

Login to post a reply

Server time is: 2024-04-18 12:27:59
Your offset time is: 2024-04-18 12:27:59