GLBasic forum

Main forum => Media Section => Topic started by: matchy on 2012-Jul-28

Title: 3D shading and environment test
Post by: matchy on 2012-Jul-28
http://www.youtube.com/watch?v=5k2FRHlL5tI
 :good:
Title: Re: 3D shading and environment test
Post by: erico on 2012-Jul-28
hmmm, I think I have been to this place before...maybe it was on a dream? ;)

Looks good, the fog and the player light source+shadows.

I kind of see an attempt on a normal map too but it is not producing the supposed result.
Am I correct? Maybe adding some bump to the walls would help the felling of 3d.

Overall, it´s looking great! :good:

Title: Re: 3D shading and environment test
Post by: matchy on 2012-Jul-28
Oh yes, thanks erico... this is a multi-player test arena but only trailing the environment now, especially getting shadows to works correctly for multiple walls and multiple player spot lights (not shown), but more about players later. I'm still trying to get to a nice stage where you can server it on your server again. ;) There is currently a bump map but I don't know if I created it correctly (invert and grayscale from original) and I don't think that it does look right. Note the first half of the video is in Lo-res 30fps camera and the second half of video is hi-res 15fps screen caps. So now I'm waiting on mentalthink for that as he is kindly helping with some of the graphics. At the moment I am focused on map generation designs and algorithms rather than manually mapped arenas and fixed textures.

Generally, these sort of trials leads to ideas of games, such as the short distance dark areas reminds me of Doom 3, but that is not the aim for now because ultimately the lighting environment is just a visual enhancement rather than part of the main game-play but the graphics stuff give me a break from the comms stuff.  :whistle: Casually, I suppose this is a start to documenting this open project, which the source code is available on request. As it is a multi-player game, more that one is required to test and create for these types of projects.
Title: Re: 3D shading and environment test
Post by: mentalthink on 2012-Jul-28
Very Nice!!!, don´t worry about more stuff I do something more... About the BumpMapping... I think the best way it´s not use the black and white tones images... I think it´s better make another image diferent to diffuse map...

I love this lighting... it´s very very dark feeling... some extrange sounds... can be look nice nice!!!

Very good Job.. I like a lot!!!
Title: Re: 3D shading and environment test
Post by: matchy on 2012-Jul-28
Yeah cool MT... background sounds would suit well and it would be easy to go for the spooky approach in theme. :good: :good:

Here's the texture and bump (size reduced) that is used.



[attachment deleted by admin]
Title: Re: 3D shading and environment test
Post by: erico on 2012-Jul-29
But isen´t the black and white image the correct stuff for the bump?

I never tried bump map on glbasic, but on the demos it seemed to work fine on the black and white picture as it should.
Could it be that the shadow mode is cancelling the bump?

edit: oh, I see those bumps now, they should produce the effect.
Overall, really great textures and set of colors! :good:
Maybe level up those bumps to see if it makes any difference?

edit2: specular highlights could be key to show up on them, specially as they are metal and should have a high specular level.

edit3: are those black and white real bump images? or inverted desaturated images?
Title: Re: 3D shading and environment test
Post by: mentalthink on 2012-Jul-29
@erico, about the bump... I do sometimes another texture not excatly the same, for put scractch and dust and all this details... About the specular, this can be great... I have to study how do it whit OpenGlES 1.0, in OpenGL standard, in a PC I think can´t be too much trouble...

@Matchy, about the sounds I send a couple of sound from a library adquired someweeks ago, very very impresive sounds, after you can chosse a program like Music Maker, for add amd make ambiental extrange sounds, it´s have a strange synthetizer automatizated and very easy to use...
Title: Re: 3D shading and environment test
Post by: matchy on 2012-Jul-29
erico, that bump map was hand made by me by guessing invert, grayscale, auto-contrast but I haven't really got back into bump and sphere mapping in GLB lately. So I'll experiment with those also but a shiny metallic painted wall effect I'll might try for.

mentalthink, the sounds effects would be great although I wish to use sfxr. Ultimately with all initial media, everything will be preferably produced by pure glb code in some form, like the textures.
Title: Re: 3D shading and environment test
Post by: erico on 2012-Jul-29
erico, that bump map was hand made by me by guessing invert, grayscale, auto-contrast but I haven't really got back into bump and sphere mapping in GLB lately. So I'll experiment with those also but a shiny metallic painted wall effect I'll might try for.

Ok, are you using photoshop or gimp?
Try a HIGH PASS filter to neutralize things a bit after the invert and grayscale.
Title: Re: 3D shading and environment test
Post by: erico on 2012-Jul-29
With a HIGH PASS filter you should be able to get rid of the majority of shades from the photo texture.
Then you work levels to your suit.

Something like this I´m appending over the photo images you uploaded.
But preferably darker on the levels.

edit: by using just BW versions of your texture images on your bump, it is hard to see anything because of the shade on the color texture. You understand that better by the first-left texture, mine dosen´t have that triangle white on the middle. Those are the shades you want to get rid when making bumps :)

[attachment deleted by admin]
Title: Re: 3D shading and environment test
Post by: erico on 2012-Jul-29
Mental, I agree, we must have control over specular and diffuse somehow. It is of the greatest importance.
Please excuse my intrude on the thread, I haven´t done much on 3d to ever come up with anything.

Understand I´m just trying to help things out whatever way I can. :-[
Title: Re: 3D shading and environment test
Post by: mentalthink on 2012-Jul-29
intrude?¿...  :-* :-* your knowledges...
 :nw: :nw: :nw:
Title: Re: 3D shading and environment test
Post by: matchy on 2012-Jul-29
Photoshop is what I use although this is just for testing. It would be better if I were to generate simpler but similar design texture and bump map in code and see how that looks.
Title: Re: 3D shading and environment test
Post by: erico on 2012-Jul-29
Photoshop:

Filter > Other > High pass...

Then use levels to achieve strong black and white, it should be enough!

If you prefer to use in code, its ok of course, but give a go on external packages, it is always good!
Gimp can do the same.

I wonder why high pass is kind of hidden in photoshop while it is an important tool to create edges... I don´t like adobe :(
but ssshhh don´t tell everyone!:)

Edit again: I ´m doing photoshop work today on the grave shift, if you need me to give a go on creating bump for it, send me that file on ericomont@[gouoglestufff].com
Title: Re: 3D shading and environment test
Post by: kanonet on 2012-Jul-29
Specular light is easy to do in OpenGL (dont know about |ES) and has been done (Diffuse is easy too). Ive send it to Gernot with other code ideas for bugfixes and feature adds. I dont want to publish it till I know if Gernot includes it in V11, but if you need it, write a PM. :P

@bumpmapping:
please notice that bumpmapping is broken/ does not work on Intel graphic cards. I tried it on 3 (or was it 4) different generations and it did not work on any of them (but it did on ATI and NVidia). Was reported long time ago...
Matchy are you still using my 3D lib? If yes, did you include bumpmapping, cuz i did not and its quite a bit work. If someone needs it, i can include it in a future version... :whistle:

BTW: your game does look way better since the last time i saw it, really nice work. Did you manage to get it working faster in internet games? Keep me updated. :whip: :nana:
Title: Re: 3D shading and environment test
Post by: erico on 2012-Jul-29
me too me too, keep me updated too! Just because you all lost that day dosen´t mean you are going to skip me! :P :-[

ps: that is really interesting Kanonet, the specular and diffuse! I will wait for the next iteration of GLB as currently I´m only doing 2d stuff, but heck, all this 3d stuff is bugging my mind!
Title: Re: 3D shading and environment test
Post by: matchy on 2012-Jul-29
erico, I am more intersted in designing the texture rather than fix texture. For now, you are welcome to submit you own creative versions.

kanonet, I have used your libraries but disconnected again so that I can product the desired shadows and spots. Either way, I don't to get too carried away with the graphics again without having some sort of game play at least to test and administer. Last time we chatted I had asked you about a sample net program because it's neat to have the lib but pointless with a program.
Title: Re: 3D shading and environment test
Post by: Hemlos on 2012-Jul-29
Hi guys,
Looking good matchy!

I have been testing bump mapping alot, and i would have to say that ericos approach can be effective.
Inducing the height differences on the texture this way, is an effective although quick and dirty solution.

The key is to have at least 2 very contrasting grey colors.
Where the 2 colors adjoin, this is where specifically the "bump" will map to your surface.

As opposed to black and white, as these can cause anomalies, inducing invisible surfaces.

Below are two examples of bump maps.
One of these screenshots uses a wide variation of grey colors.
The other is using only 2 colors.



[attachment deleted by admin]
Title: Re: 3D shading and environment test
Post by: matchy on 2012-Jul-29
Okay Helmos, here are some samples. Without bump, with bump and original large texture.  :)

[attachment deleted by admin]
Title: Re: 3D shading and environment test
Post by: matchy on 2012-Jul-29
Here are screenshot with no bump, bump and alt bump.

[attachment deleted by admin]
Title: Re: 3D shading and environment test
Post by: matchy on 2012-Jul-29
What about the blue tinge that LOADBUMPTEXTURE creates. If it is LOADSPRITE normally then the second textured in overlayed (I found....handy!).
 

[attachment deleted by admin]
Title: Re: 3D shading and environment test
Post by: Hemlos on 2012-Jul-29
Good question, I'll do some more testing.
I suspect this is happenning when you use more grey variations.
Ie. distorted grey bump maps, as opposed to bump maps with only 2 colors.

I'm not 100% sure, I'll test in a few hours.
Title: Re: 3D shading and environment test
Post by: erico on 2012-Jul-29
Within 3d packages, that blue tinted one is an image normal map, similar to a bump map when it comes to results.
Can GLB read those?
Title: Re: 3D shading and environment test
Post by: Hemlos on 2012-Jul-29

LOADBUMPTEXTURE is not the cause of the blue tint.
I am actually having a hard time reproducing this effect.  :blink:
Its odd because i used to get this alot too.
Perhaps it is the map, or lighting causing it.

In order for me to figgure this out for you, i will need the object, the texture and the bumpmap.
Title: Re: 3D shading and environment test
Post by: erico on 2012-Jul-29
Inside a 3d package, let´s suppose you have an object full of stuff, bumps, displace, high poly count, etc.
Suppose you would like to export this object into a reduced poly version + bump and texture, then, it is usual to export a normal map like that tinted blue image so it simulates those missing polygons.
Title: Re: 3D shading and environment test
Post by: Hemlos on 2012-Jul-30
@erico
The blueing is something to do with opengl directly.
I just cant remember what exactly i did to fix it with my software.
Title: Re: 3D shading and environment test
Post by: Hemlos on 2012-Jul-30
The reason i am posting this, is because if the order here is different; you may get mixed results of rendering, an error/crash, or possibly blueing.
Ever since i ordered the commands in this way, i get no rendering problems at all.
This is the order in which i rendered the objects:

Code: GLBasic [Select]
X_MAKE3D
X_CAMERA
X_SPOT_LT -1 //note: not 100% compatible with celshading. Also note, other ADDITIONAL lights will produce EXTRA darkness on the bumped object!
ALPHAMODE
X_SCALING
X_CULLMODE
X_MOVEMENT
X_SETTEXTURE t1,t2
X_DRAWOBJ

Again, as i said earlier if you still get blueing, when you do not want this result send me the obj/tex/bump or post it here and i will check it out.

Here is the results(screenshot) without a texture, and only a bumpmap(notice, no blue surface)

edit: ps. i will test your textures now that i have some time...be back in a few with the results.

[attachment deleted by admin]
Title: Re: 3D shading and environment test
Post by: erico on 2012-Jul-30
Bump and normal image map is the same on my end(as far as results on a 3d soft).
The normal map is actually able to produce diagonals in a better fashion then the bump.

Reason it has a mix of 3 colors instead of only 2 from the black and white bump.

Of course open gl will accept the blue normal stuff when it comes to games, as it is the standard on reducing million polygons to few polygons + normal image map. Direct X should accept it too.

The normal image map (blue stuff) is only actually important when reducing details from packages, not important at all when building polygons by code, since you are building what you actually need. In this case, that you are building the polygons straight to the game, either by code or software, a bump will do. Normal image map is only important when exporting and reducing, lets say, a Zbrush 3 zillions polygons model and displaces for a game.

Which brings me the question... applying a bump map (BW black and white) and applying an image normal map (blue stuff) actually requires different reading to perform correctly. Can GLB read the normal one? By the examples, it seems the BW stuff goes ok.

According to what Matchy posted, it is hard to read the bump, as that requires movement from the lights, so I will give a go on simple 3d object display I did over a Gernot´s youtube example to give it a try. But for sure, what Matchy got on the normals looks to me as normals map being used somehow as texture and colours, which raised my first ever question on an attempt to use image normal map :S 

edit 2: The normal image map, the blue stuff, combines 3 colors in an attempt to tell the renderer where the normals(fake normals here, not real polygon ones) are going over the surface, so you get a better 3d feeling then the BW stuff, which only attempts for height and not diagonals.
Title: Re: 3D shading and environment test
Post by: matchy on 2012-Jul-30
Helmos, The texture and map have been posted in this thread and the object is a simple quad. When I moved, there doesn't seem to be any change in the bump lighting, just the yellow/blue shading.
Title: Re: 3D shading and environment test
Post by: Hemlos on 2012-Jul-30
@matchy:
Ok i made a quad object(2 triangles, size 256x256), and i used your textures and bumpmaps(i altered the size and posted them in texture.rar below).
The textures need to be power of 2, (ie. 64x64,128x128, etc), otherwise your texture will not scale properly on an object of same size.
I fixed the images the best i could, in the .rar file.(not perfect because i had to rescale them in mspaint)


[attachment deleted by admin]
Title: Re: 3D shading and environment test
Post by: matchy on 2012-Jul-30
Tried your maps and still the same thing blue tinge buddy and you should post GLB screenshots.
Title: Re: 3D shading and environment test
Post by: erico on 2012-Jul-30
considering bump maps, the post you did before this one, the second image, seems to show bump correctly(as far as control to depth goes). Did you use the bump map or the normal image map?

I´m sorry Matchy that it seems the thread has been hijacked(by me) about 3d stuff, I never meant to, I will give a go on those textures too and try a simple 3d viewer on my end. My hopes is that it helps you somehow. I´m sure you have more important stuff to do on this then the 3d visuals...heck that net code is beyond my understanding by far and I claim it will never be on my end.

About doing textures out of my mind, it depends on what art directionig you want with this, and ampos stuff is by far looking soo great!
Don´t forget the "kicked can" sound! :)

I will try to come up with stuff that actually helps on what you have now, sorry.
Title: Re: 3D shading and environment test
Post by: Hemlos on 2012-Jul-30
@matchy:
1. what do you mean glb screenshots? i am using SAVESPRITE
I just used now, SETTRANPARENCY  0x8000ff, and the result was pink instead of white pixels...i also switched to BMP instead of png.
Seem there is a bug here.

2. Do you try ordering the code like i showed also?
Make sure you are proper ordering the rendering x_codes.
http://www.glbasic.com/forum/index.php?topic=8395.msg71066#msg71066

@erico:
i used matchys walls_1.png, and walls_4_bump.png, i edited them to be 256x256 though.
Title: Re: 3D shading and environment test
Post by: erico on 2012-Jul-30
I just used now, SETTRANPARENCY  0x8000ff, and the result was pink instead of white pixels...i also switched to BMP instead of png.
Seem there is a bug here.

Could it be that GLB supports exporting normal image maps then? Should be great for people doing a modeler with it!
Title: Re: 3D shading and environment test
Post by: Hemlos on 2012-Jul-30
TBH i dont know what you mean by exporting normal maps.
In glb normals are vectors.

These are the images i edited.
http://www.glbasic.com/forum/index.php?action=dlattach;topic=8395.0;attach=5261

Title: Re: 3D shading and environment test
Post by: erico on 2012-Jul-30
Oh, but where are the blue ones? Did they come out of GLB?
Title: Re: 3D shading and environment test
Post by: Hemlos on 2012-Jul-30
The blue ones are an error in the code.
Its not glbasic with this issue, it is opengl naturally depending on the way the code is ordered/used.
I know this for certain, because i had the same results with my object analyzer when i first implemented the bumpmaps.
Title: Re: 3D shading and environment test
Post by: Hemlos on 2012-Jul-30
@bumpmapping:
please notice that bumpmapping is broken/ does not work on Intel graphic cards. I tried it on 3 (or was it 4) different generations and it did not work on any of them (but it did on ATI and NVidia). Was reported long time ago...
Matchy are you still using my 3D lib? If yes, did you include bumpmapping, cuz i did not and its quite a bit work. If someone needs it, i can include it in a future version... :whistle:

Do your cards support this extension: GL_ARB_texture_env_dot3 ?
If im not mistaking, this is the bumpmap thingy.
http://www.glbasic.com/forum/index.php?topic=3631.0 (http://www.glbasic.com/forum/index.php?topic=3631.0)
Title: Re: 3D shading and environment test
Post by: matchy on 2012-Jul-30
1. what do you mean glb screenshots? i am using SAVESPRITE
2. Do you try ordering the code like i showed also?

For some reason from a glance, I thought your screenshot were from 3ds or some editor.  :D :D

Here's my algo for shadows. I don't think there a problem with it but is there with the order. I mean I like cullmode up the top because i rarely use both together. In this case, only one spot light is use otherwise they would need to be repeated.
Code: GLBasic [Select]
X_MADE3D
X_CULLMODE 1
X_CAMERA
X_SPOT 1
X_FOG

repeat twice
X_SPOT 1 or -3 // second time for shadows
        X_ALPHAMODE 0
        X_SCALING
        X_SETTEXTURE
        X_MOVEMENT
        X_DRAWOBJ
end repeat
 

...hijacked(by me) ....
... and ampos stuff
....Don´t forget the "kicked can" sound! :)
...I will try to come up with stuff...

No problems about the thread hijack all is good for me. More media content and improvement is appreciated but anything to add to the game would be super cool for all.  8)

Cans?  :coke: I have not seen ampos lately.

Title: Re: 3D shading and environment test
Post by: erico on 2012-Jul-30
OPS! :-[

Sorry I meant Mentalthink, not ampos, really sorry for that...
Title: Re: 3D shading and environment test
Post by: mentalthink on 2012-Jul-30
I´m not sure about this, but blue tint  images (Normal Maps) and Bump, not are the same... the effect it´s very similar but the inner calculus are very differents...

Another point, I think it´s better for the walls use, Displacement... OpenGL can do this... OpenGL 2.0 I´m not sure... but displacement really makes the extrusion, if you are near of the wall you really show the bricks going out the geometry (you need to add more division to the mesh), but bump when you are near to the wall only see the plane...

I´m not sure about the speed of the game, but the results are awesoming better than bump...



[attachment deleted by admin]
Title: Re: 3D shading and environment test
Post by: erico on 2012-Jul-30
Totally right.

But the displace will need a high poly mesh. You could actually freeze the displace into an object and use it without having to calculate the displace in code, unless you want to animate that as for example in water.

The bump will display only height while the normal will display that but will also deal diagonals, it will look better.
As for getting close, having a higher resolution texture for either bump or normal may help.

Sorry Mental I got confused by ampos couple posts ago :-[
Title: Re: 3D shading and environment test
Post by: mentalthink on 2012-Jul-30
@erico Sorry Mental I got confused by ampos couple posts ago :-[

Don´t worry we both are spanish =D =D =D . 
Title: Re: 3D shading and environment test
Post by: Hemlos on 2012-Jul-30

For some reason from a glance, I thought your screenshot were from 3ds or some editor.  :D :D

Here's my algo for shadows. I don't think there a problem with it but is there with the order. I mean I like cullmode up the top because i rarely use both together. In this case, only one spot light is use otherwise they would need to be repeated.

hehe its my new version of object analyser, unreleased.
its not finished yet, but this thread has helped to figgure out a couple things for it.

this is how you get rid of the blueing:

Code: GLBasic [Select]
        IF Bumpmapping
                X_SPOT_LT -1, 0x808080, cx,cy,cz,-cx,-cy,-cz, 360
        ENDIF

If you move this light around, you will see changes in the bumps because it is sensitive to this light position.

ps. this is not the regular light, it is id -1, additionally, you can use regular spot light too.
You can position the bumplight, from a room light source, like a lamp to show proper shadowing on the walls.
And dont forget LOADBUMPTEXTURE
Title: Re: 3D shading and environment test
Post by: erico on 2012-Jul-30
Hey mental, just notices the (6000E app does not display bump!)  :D
Try a 1.500 dollars app, should be able to render everything in realtime on the viewport :P :nana:
But apart from VPR on lightwave, it also dosen´t show bump on open gl, at least not with my gfx card.
Funky that the free sculptris shows it...

Tried a bump map and a normal map on an external package, this is what I get.

It won´t actually help much on the GLB side but at least that is what I expect.
You can see the result is pretty similar, but the normal map seems to be a bit blurred on the mip mapping side of things.

[attachment deleted by admin]
Title: Re: 3D shading and environment test
Post by: matchy on 2012-Jul-30
Helmos, the -1 for spot did the trick but it's a very thin edge so I need to experiment with that. Now I'd like to produce something like the image erico has posted.  :-[
Title: Re: 3D shading and environment test
Post by: erico on 2012-Jul-30
The white shinnings on those images comes from the specular level being very high, 100%.
That object is a simple one with rgb 127 like a middle grey color plus the bumps.
The specular threshold (ie how big that shinning ball gets, in a simple way of saying) is about 50%.

So as far as specular goes, it would be nice to be able to deal them directly inside GLB, like intensity and size.
It seems mental´s doings with open gl can bring that up and so as Kanonet said too.
Title: Re: 3D shading and environment test
Post by: matchy on 2012-Jul-30
Ah yes I see those can be set in the declared in inline c kanonet's lib. Helmos, have you got an import function for reading a material data file (eg. 3dsmax, obj)?
Anyone recommend settings to try out?
 
Code: GLBasic [Select]
FUNCTION LIGHT_SETTINGS:
        INLINE
                #define GL_NORMALIZE                                            0x0BA1
                #define GL_FRONT_AND_BACK                                       0x0408
                #define GL_AMBIENT                                                      0x1200
                #define GL_DIFFUSE                                                      0x1201
                #define GL_SPECULAR                                                     0x1202
                #define GL_SHININESS                                            0x1601
                glEnable(GL_NORMALIZE);
                float v[4] = { 0.5f, 0.5f, 0.5f, 1.0f };
                glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, v);
                glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, v);
                glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, v );
                glMaterialf( GL_FRONT_AND_BACK, GL_SHININESS, 50.0f );
        ENDINLINE
ENDFUNCTION
 


Title: Re: 3D shading and environment test
Post by: kanonet on 2012-Jul-30
Matchy this alone wont do the job, but almost. :P
Btw i did not want this to spread around before i know how Gernot decided about this... anyway its to late now, so here is the full project for everyone, small and easy: its sets everything to nice medium values, but if you want you can alter all values, but you need to know what you do (or you should like experimenting^^).

Find it on my website: http://www.kanonet.de/downloads/lightsfixes
Title: Re: 3D shading and environment test
Post by: matchy on 2012-Jul-30
At this stage I will try anything and so far bump map is making things look better.

Any chance of mocking up this function for now? How about some samples of different materials?
X_SETMATERIAL diffuse%, specular%, emission%
Title: Re: 3D shading and environment test
Post by: mentalthink on 2012-Jul-30
@Kanonet, I don´t know about your library, I take a fast look, and it´s very impressive, good work, it´s very easy than mine... I have a bit more of control, but the specular hotspot runs too much better than in my library...
THanks I think I learn a lot of your Code...

Regards,
Title: Re: 3D shading and environment test
Post by: Hemlos on 2012-Jul-30
Helmos, the -1 for spot did the trick but it's a very thin edge so I need to experiment with that. Now I'd like to produce something like the image erico has posted.  :-[

It looks grey because there is no original colored texture, only a bumpmap texture. ie X_SETTEXTURE 999,1 //999=nothing

a .mtl is simply a txt file, should be easy enough to open it in notepad
Title: Re: 3D shading and environment test
Post by: bigsofty on 2012-Jul-31
Ah yes I see those can be set in the declared in inline c kanonet's lib. Helmos, have you got an import function for reading a material data file (eg. 3dsmax, obj)?
Anyone recommend settings to try out?
 
Code: GLBasic [Select]
FUNCTION LIGHT_SETTINGS:
        INLINE
                #define GL_NORMALIZE                                            0x0BA1
                #define GL_FRONT_AND_BACK                                       0x0408
                #define GL_AMBIENT                                                      0x1200
                #define GL_DIFFUSE                                                      0x1201
                #define GL_SPECULAR                                                     0x1202
                #define GL_SHININESS                                            0x1601
                glEnable(GL_NORMALIZE);
                float v[4] = { 0.5f, 0.5f, 0.5f, 1.0f };
                glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, v);
                glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, v);
                glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, v );
                glMaterialf( GL_FRONT_AND_BACK, GL_SHININESS, 50.0f );
        ENDINLINE
ENDFUNCTION
 

Small question, why not use GL_FRONT instead of GL_FRONT_AND_BACK, I would assume that GLB does back-face culling already?
Title: Re: 3D shading and environment test
Post by: kanonet on 2012-Jul-31
I may be wrong with this, but why i did it this way is:
It does not set cullmode or something it just assigns the materials to both faces. In most cases the user will just draw front faces (X_CULLMODE 1), at least this is what i do, if he does, just assigning the materials to front face would be fine. But if he draw backfaces (X_CULLMODE 0 or -1) than the materials would not be assigned to that, so back faces will get lighted different. Cause my code was meant to work for all users (i hope^^) without thinking to much about it, i decided to assign it to both faces, if you just render front faces, you will lose nothing, but if you render back faces you will be happy. ;)
Title: Re: 3D shading and environment test
Post by: kanonet on 2012-Jul-31
Sorry for double post. :whistle:

Any chance of mocking up this function for now? How about some samples of different materials?
X_SETMATERIAL diffuse%, specular%, emission%
Ive done it, the functions is ready now, but got two more parameters, its called now:
SETMATERIALS ambient%, diffuse%, specular%, emission%, shininess
Just see the code. You find everything on my website (http://www.kanonet.de/downloads/lightsfixes).

There are several lists of materials in the internet just one example that i found (dont know how good it is): http://globe3d.sourceforge.net/g3d_html/gl-materials__ads.htm
All values in this lists are in the range from 0..1 but my function needs to get called with RGB() so it needs input from 0..255, so you need to multiply values from this lists (besides shininess which stays the same). Or you just call it inline/write your own function that accept values 0..1.

Note that this is advanced stuff, if you dont know how to use it, you obviously dont need it. Or if you are such an poor artist like i am, you dont need it either. :P
Title: Re: 3D shading and environment test
Post by: erico on 2012-Aug-01
Hey Kanonet, the RGB stuff you mentioned...
...Does it mean that we will be able to tell the color of the specular highlight separeted from the diffuse color? Heck, this would be superb! :good:
Title: Re: 3D shading and environment test
Post by: kanonet on 2012-Aug-01
Yes and no.

No not with this what i posted in last post, this is for setting up the materials, not the lights! To say it in theory: displayed lighting color is based on material*light and specular light is set to white, so if you change the specular value for material you change the result to the same. So the effect should be the same, but technically you have not changed the light color. Changing the specular light color is easily possible too, i did it in an earlier version of this project, but removed it, caused i liked that GLB has set it to white, so we can change it with materials. And if the result looks nice, how cares how we got it? :nana:
If it should be needed i could add direct specular light control later too (but i dont think it is need?), but not today...

If you want to know about OpenGL lighting + object materials, there are some good explanations/tutorials in the net. If you know what it is about, just load the project and test it for yourself.

BTW using RGB was just to reduce amount of parameters and make the code easier to read, instead of this i could also let you input 3 parameters instead of each RGB... but then the function would have 13 parameters, what would be a bit heavy IMO.
Title: Re: 3D shading and environment test
Post by: erico on 2012-Aug-01
ok, as I understand, the specular is actually a fake reflection from the light source, so primarily, it should obey the light color, and that same light color is also going to tint the surface diffuse color. 3d packages goes the way you said, specular is always white, but there is an option to tint specular color according to the light color.

Now, since specular is actually a fake light source reflection(when it comes to color and position only, not the amount it spreads) it may be interesting for material dealing to be able to state the color on the material level as a priority, not light. Some coat materials in real life will paint every reflection to the color of the coat, so even if some light is blue, it is going to produce green on this special coated green material, and only for this material.

If I understood what you said, I believe your specular color should be material first, light color second or just white if people don´t care or don´t specify.

Great work done, if you had done this before and changed for white for simplicity, I would say don´t, most of the 3d packages on the 90s has specular on white for similar reasons.

Great work done, I´m still to run a test on glb 3d on all these reasons we are discussin but am afraid I may only be able to do so next week in luck.
Sorry for all my talking, I know talking is easier then doing.
Title: Re: 3D shading and environment test
Post by: bigsofty on 2012-Aug-01
I may be wrong with this, but why i did it this way is:
It does not set cullmode or something it just assigns the materials to both faces. In most cases the user will just draw front faces (X_CULLMODE 1), at least this is what i do, if he does, just assigning the materials to front face would be fine. But if he draw backfaces (X_CULLMODE 0 or -1) than the materials would not be assigned to that, so back faces will get lighted different. Cause my code was meant to work for all users (i hope^^) without thinking to much about it, i decided to assign it to both faces, if you just render front faces, you will lose nothing, but if you render back faces you will be happy. ;)
Ah, fair enough.  :)
Title: Re: 3D shading and environment test
Post by: matchy on 2012-Aug-01
Any chance of mocking up this function for now? How about some samples of different materials?
X_SETMATERIAL diffuse%, specular%, emission%
Ive done it, the functions is ready now, but got two more parameters, its called now:
SETMATERIALS ambient%, diffuse%, specular%, emission%, shininess

Awesome!!! You know what else would be epic? An import function to go long for obj mtl file data for material/light data and texture file names. ;)
http://www.gamedev.net/topic/605949-from-wavefront-mtl-file-to-opengl/
Title: Re: 3D shading and environment test
Post by: erico on 2012-Aug-01
would be great!

when exporting a model from lightwave to OBJ, it creates an mtl file for that reason.
Still, if an object, lets say a ball, has top part to one material and lower part to another, I´m not sure this gets going to the mtl.
I´m sure smooth/flat surfaces go out fine.
Title: Re: 3D shading and environment test
Post by: mentalthink on 2012-Aug-01
I think a good point without too much problems to send the data of the mesh... It´saving from the 3D Suite a .txt file or .dat... I think from .obj or .3ds or another format can be a tedious works... Make a "plugin" for export the data could´t too much complex, the standar in the 3D industry now it´s python... I don´t touch too much, but all the people say it´s easy... and after whit a function material properties, read whit some tag the correct material, whit an special name or something...

I´m not sure 100%, don´t look too much, but I think when I export from 3d max, the geometry remenber the material I did in 3DS max, the specular shinnes , amount etc... not sure 100%.

Title: Re: 3D shading and environment test
Post by: erico on 2012-Aug-01
ops...the mtl does retain material areas and most of the parameters, good!
Though I lost the smoothing set parameters and gained a vertex normal map, which is not visually producing the same.
here goes the obj+mtl should you guys wanna take a look.

there is a pic showing the stuff.

material names seems ok, but on the obj it added a _smooth to the materials I set a smooth threshold.(1,2,3)

Yep. a plugin on python would be nice too Mental!

[attachment deleted by admin]