Author Topic: 3D shading and environment test  (Read 19589 times)

Offline matchy

  • Prof. Inline
  • *****
  • Posts: 1543
    • View Profile
Re: 3D shading and environment test
« Reply #45 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.  :-[

Offline erico

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4215
    • View Profile
    • Portfolio
Re: 3D shading and environment test
« Reply #46 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.

Offline matchy

  • Prof. Inline
  • *****
  • Posts: 1543
    • View Profile
Re: 3D shading and environment test
« Reply #47 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
 


« Last Edit: 2012-Jul-30 by matchy »

Offline kanonet

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1142
    • View Profile
    • My GLBasic code archiv
Re: 3D shading and environment test
« Reply #48 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
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Offline matchy

  • Prof. Inline
  • *****
  • Posts: 1543
    • View Profile
Re: 3D shading and environment test
« Reply #49 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%

Offline mentalthink

  • Prof. Inline
  • *****
  • Posts: 3366
  • Integrated Brain
    • View Profile
Re: 3D shading and environment test
« Reply #50 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,

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1635
  • Particle Hawk
    • View Profile
Re: 3D shading and environment test
« Reply #51 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
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2628
    • View Profile
Re: 3D shading and environment test
« Reply #52 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?
Cheers,

Ian.

“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration.”
(E. W. Dijkstra)

Offline kanonet

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1142
    • View Profile
    • My GLBasic code archiv
Re: 3D shading and environment test
« Reply #53 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. ;)
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Offline kanonet

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1142
    • View Profile
    • My GLBasic code archiv
Re: 3D shading and environment test
« Reply #54 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.

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
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Offline erico

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4215
    • View Profile
    • Portfolio
Re: 3D shading and environment test
« Reply #55 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:

Offline kanonet

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1142
    • View Profile
    • My GLBasic code archiv
Re: 3D shading and environment test
« Reply #56 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.
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Offline erico

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4215
    • View Profile
    • Portfolio
Re: 3D shading and environment test
« Reply #57 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.

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2628
    • View Profile
Re: 3D shading and environment test
« Reply #58 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.  :)
Cheers,

Ian.

“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration.”
(E. W. Dijkstra)

Offline matchy

  • Prof. Inline
  • *****
  • Posts: 1543
    • View Profile
Re: 3D shading and environment test
« Reply #59 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/