Some problems with N3XTD

Advanced game related topics
User avatar
A.D.
User
User
Posts: 98
Joined: Tue Oct 06, 2009 9:11 pm

Some problems with N3XTD

Post by A.D. »

EDIT: Sorry for posting in the wrong topic. Plz move to "game programming" or "coding questions". Thanx

Hi there !!!

First of all thanx to Tmyke for his great work. I heard rumors that you are helping with the new ogre implementation. Anyway I hope you will make the N3XTD-Site online again in the meanwhile. But now to my topic...i've got some problems using N3XTD. I hope somebody can help me.

When i'm lightening an object it's seems to be rendered flatshaded. When i flag the materialnode to #EMF_GOURAUD_Shading the engine renders just a bunch of points, but no gouraudshading! Another thing i don't understand is when i'm using XShaders for e.g. Phong, the render resolution is not the same as without the xshader. All looks very pixellated. I hope somebody can help me a little bit. The last thing i would like to now if it is possible to use specularmaps for rendering entities. Do i need a shader for it?

Regards
Alexander

Here is the code i'm using:

Code: Select all

;PB-Version 4.41

;IncludePath  #PB_Compiler_Home + "Includes\"   :   IncludeFile "n3xtD_PB.pbi"
IncludePath "includes"   :   IncludeFile "n3xtD_PB.pbi"

Global *nView.l, Quit.l
Global Fullscreen.l = 0
Global   anglex.f, angley.f, flagXDown.w
Global   mox.f, omx.f, moy.l, omy.l

;ilogfile(#True)
iSetAntiAlias(#True)

File.s = OpenFileRequester("3DS öffnen", "", "3ds | *.3ds", 0)

If Not Fullscreen
 *nView = ICreateGraphics3D(1024,768, 32, #False, #True,#EDT_DIRECT3D9)  
Else
 ExamineDesktops()
 *nView = ICreateGraphics3D(DesktopWidth(0),DesktopHeight(0),32, #True, #True, #EDT_direct3d9) 
EndIf

If *nView = #Null : End : EndIf

;SetCurrentDirectory("media/") 

*light.ILight = iCreateLight($FFFFFF, 1000) 
iPositionNode(*light, 0,100,-50)
;iTypeLight(*light,2)
 
Global *Objekt.IObject = iLoad3DObject(File)
Global *Mesh.IMesh = iCreateMesh(*Objekt)

iPositionNode(*Mesh, 0,0,0)
;iMaterialFlagNode(*Mesh,#EMF_ANISOTROPIC_FILTER, #True)
iMaterialFlagNode(*Mesh,#EMF_GOURAUD_SHADING,#True)
;imaterialflagnode(*mesh,#EMF_ZWRITE_ENABLE , 1)
;imaterialflagnode(*mesh,#EMF_LIGHTING , #False)
;iScaleMeshBuffer( iMeshGeometry(*Mesh), 20,20,20)

Define *Cam.ICamera = iCreateCamera()
iPositionNode(*Cam, 0,10,-30)

;iAddToNodeXEffect(*mesh, #EET_PHONG) 
;iAddToNodeXEffect(*mesh, #EET_MRWIGGLE)

;AddShadowLightXEffect( 150.0,0,150.0,    200,0,0  ,$FFFFFF, 1.0, 16000.0, 35.0 , 768, 0)
;iAmbientColorXEffect($ffffffff)
;iClearColorXEffect($ffffff00)

;iAddFilePostProcessingXEffect("Shaders/PP_DX_Bloom1.fx")

Repeat
 
  If evt = #PB_Event_CloseWindow
    quit = 1
  EndIf
  If iGetKeyDown(#KEY_ARROW_UP)
    iMoveNode(*Cam, 0,0,0.5)
  EndIf
  If iGetKeyDown(#KEY_ARROW_DOWN)
    iMoveNode(*Cam, 0,0,-0.5)
  EndIf
  If igetkeydown(#key_arrow_left)
    imovenode(*cam , -0.5 , 0 , 0 )
  EndIf
  If igetkeydown(#key_arrow_right)
    imovenode(*cam , 0.5 , 0 , 0)
  EndIf
 
  If iGetMouseEvent(#MOUSE_BUTTON_LEFT)
        If flagXDown=0
           omx = iGetMouseX()
           omy = iGetMouseY()
           flagXDown=11
        Else
           moy = iGetMouseY()-omy
           angley=(moy/10.0)
           omy= iGetMouseY()
           mox = iGetMouseX()-omx
           anglex=(mox/10.0)
           omx= iGetMouseX()
           iTurnNode(*Cam, angley, anglex,0)
        EndIf
  Else
            flagXDown=0
  EndIf

iTurnNode(*Mesh, 0,0.05,0)

If iGetKeyDown(#KEY_ESCAPE) : Quit=1 : EndIf

iBeginScene()
iDrawScene()
iEndScene()

Until Quit=1

iFreeEngine()

End
I copied the XShader Folder into my working folder. Im not using the Media folder at the moment.
Repeat
PureBasic
ForEver
User avatar
Innesoft
Enthusiast
Enthusiast
Posts: 105
Joined: Mon Jan 18, 2010 10:30 am
Location: UK
Contact:

Re: Some problems with N3XTD

Post by Innesoft »

Be sure to set the material flag #EMF_NORMALIZE_NORMALS whenever you scale a node or a meshbuffer, since scaling in Irrlicht also scales the normals out of the -1,1 range (stupidly)
When i'm lightening an object it's seems to be rendered flatshaded. When i flag the materialnode to #EMF_GOURAUD_Shading the engine renders just a bunch of points, but no gouraudshading!
It sounds to me like the N3xtD build you're using has a typo in the enumeration (meaning the flag values are off by 1, Gouraud and PointCloud are right next to each-other). Make sure in N3xtD-Constantes.pbi, the material enumeration reads as follows...

Code: Select all

; MATERIAL flag
#EMF_WIREFRAME            = 0
#EMF_POINTCLOUD           = 2 
#EMF_GOURAUD_SHADING      = 4
#EMF_LIGHTING             = 8
#EMF_ZBUFFER              = $10
#EMF_ZWRITE_ENABLE        = $20
#EMF_BACK_FACE_CULLING    = $40
#EMF_FRONT_FACE_CULLING   = $80
#EMF_BILINEAR_FILTER      = $100
#EMF_TRILINEAR_FILTER     = $200
#EMF_ANISOTROPIC_FILTER   = $400
#EMF_FOG_ENABLE           = $800
#EMF_NORMALIZE_NORMALS    = $1000
#EMF_TEXTURE_WRAP         = $2000
#EMF_ANTI_ALIASING        = $4000
#EMF_COLOR_MASK           = $8000
#EMF_COLOR_MATERIAL       = $10000
The last thing i would like to now if it is possible to use specularmaps for rendering entities. Do i need a shader for it?
Yes, you will need a shader for this.. see the 'metal' shader in the link below (I assume you're using HLSL)..
http://www.robg3d.com/shaders.html

As for XEffects, I haven't touched it so can't help.
User avatar
A.D.
User
User
Posts: 98
Joined: Tue Oct 06, 2009 9:11 pm

Re: Some problems with N3XTD

Post by A.D. »

I replaced the constants and there isn't the pointcloud anymore but still it is flatshaded. The same thing with N3XTD_20! I dont know what i am doing wrong. Thanks for the shaderlink. It seems that i will have much other things to solve before... Arghh, why can't things work properly at once when coding... :evil:

-> XShaders: Mmmh, the meshes look very pixellated. If this is not a bug, i think they are pretty useless for me.

Alexander
Repeat
PureBasic
ForEver
User avatar
Innesoft
Enthusiast
Enthusiast
Posts: 105
Joined: Mon Jan 18, 2010 10:30 am
Location: UK
Contact:

Re: Some problems with N3XTD

Post by Innesoft »

Now I've re-read your first post, I noticed you're loading a .3ds model.. the .3ds loader for Irrlicht is buggy and will look flat-shaded on some models - this is caused by the normals in the model itself and afaik it can't be fixed by changing the material flag (also not a N3xtD bug... it's Irrlicht itself).

Image

Stick with .obj, .x, .b3d, and .ms3d formats, as these are supported properly. A .3ds model will look ok with pixel shaders, but otherwise avoid this format in Irrlicht if you're using dynamic lights.

Irrlicht/N3xtD takes some getting used to, since each has their own bugs.. so experiment with the basics before you even touch shaders/Xeffects. Stick with it though, because right now it's the best option for 3D in PB.
User avatar
A.D.
User
User
Posts: 98
Joined: Tue Oct 06, 2009 9:11 pm

Re: Some problems with N3XTD

Post by A.D. »

Thanks! One bug less.
Repeat
PureBasic
ForEver
User avatar
A.D.
User
User
Posts: 98
Joined: Tue Oct 06, 2009 9:11 pm

Re: Some problems with N3XTD

Post by A.D. »

Hi there, unfortunately i need help again :?

In the first code i've created a particle explosion effect. In the next one i tried to prepare the code for implementation. I used a structure and a linkedlist
to store the n3xtd pointers, but the particles are only rendered in pure white... :cry:

Here are both codes and a link to my zip:

(i know its chaos, but its only the creationphase of the explosion)

Code: Select all

IncludePath  #PB_Compiler_Home + "Includes\N3xtd\"   :   IncludeFile "n3xtD_PB.pbi"


Global    anglex.f, angley.f, flagXDown.w
Global    mox.f, omx.f, moy.l, omy.l

Global *app.l, Quit.l, Fullscreen = 1


If Not Fullscreen
 *app = ICreateGraphics3D(1024,768, 32, #False, #True,#EDT_DIRECT3D9)  
Else
 ExamineDesktops()
 *app = ICreateGraphics3D(DesktopWidth(0),DesktopHeight(0),32, #True, #True, #EDT_DIRECT3D9) 
EndIf
;SetCurrentDirectory("media/") 

*cube.IMesh = iCreateSphere(1,4,#Null) : iVisibleNode(*cube,#False) 
*cube2.IMesh = iCreateSphere(1,32,#Null) : iVisibleNode(*cube2,#False) 
*cube4.IMesh = iCreateCube(4,#Null) : iVisibleNode(*cube4,#False) 


*part.IParticleSystem = iCreateParticleSystem(#False, #Null)
*mesh_emitter.IParticle = iCreateParticleMeshEmitter(*part, *cube, #True,0,0,0, 80,  -1, #True, 1, 1,$00FFFFC5,$00FC4C22,500,500,90,10,10,10,10) 
iAddEmitterParticleSystem(*part, *mesh_emitter ) : iFadeOutParticleSystem( *part)
iMaterialFlagNode(*part,  #EMF_LIGHTING, #False )
iMaterialFlagNode(*part,  #EMF_ZWRITE_ENABLE, #False )
iLoadTextureNode(*part, "particle1.png") 
iMaterialTypeNode(*part,  #EMT_TRANSPARENT_VERTEX_ALPHA )
iRotationParticleSystem(*part,0,0,50)

*part2.IParticleSystem = iCreateParticleSystem(#False, #Null)
*mesh_emitter2.IParticle = iCreateParticleMeshEmitter(*part2, *cube2, #True,0,0,0, 80,  -1, #True,1,1,$FFD7B728,$FF9F871D,600,1100,140,0.1,0.1,0.1,0.1) 

iAddEmitterParticleSystem(*part2, *mesh_emitter2 ) : iFadeOutParticleSystem( *part2)
iMaterialFlagNode(*part2,  #EMF_LIGHTING, #False )
iMaterialFlagNode(*part2,  #EMF_ZWRITE_ENABLE, #False )
iLoadTextureNode(*part2, "particle1.png") 
iMaterialTypeNode(*part2,  #EMT_TRANSPARENT_VERTEX_ALPHA )

*part3.IParticleSystem = iCreateParticleSystem(#False, #Null)
*mesh_emitter3.IParticle = iCreateParticleMeshEmitter(*part3, *cube, #True,0,0,0, 70,  -1, #True,1,1,$00D7B728,$FF808080,800,1000,20,0.3,0.3,0.5,0.5) 

iAddEmitterParticleSystem(*part3, *mesh_emitter3 ) : iFadeOutParticleSystem( *part3)
iMaterialFlagNode(*part3,  #EMF_LIGHTING, #False )
iMaterialFlagNode(*part3,  #EMF_ZWRITE_ENABLE, #False )
iLoadTextureNode(*part3, "particle3.png") 
iMaterialTypeNode(*part3,  #EMT_TRANSPARENT_VERTEX_ALPHA )
iRotationParticleSystem(*part3,0,0,40)
;iDirectionParticle(*mesh_emitter3, 0,0.05,0)
;iGravityParticleSystem(*part2,0,-0.05,0,1000)
;iAttractionParticleSystem(*part2,2,5,9,24,#False,#True,#True,#True)

*part4.IParticleSystem = iCreateParticleSystem(#False, #Null)
*mesh_emitter4.IParticle = iCreateParticleMeshEmitter(*part4, *cube4, #True,0,0,0, 280,  -1, #True,1,1,$00111111,$00111111,600,1300,50,15,15,20,20) 

iAddEmitterParticleSystem(*part4, *mesh_emitter4 ) : iFadeOutParticleSystem(*part4)
iMaterialFlagNode(*part4,  #EMF_LIGHTING, #False )
iMaterialFlagNode(*part4,  #EMF_ZWRITE_ENABLE, #False )
iLoadTextureNode(*part4, "particle4.png") 
iMaterialTypeNode(*part4,  #EMT_TRANSPARENT_VERTEX_ALPHA )


Define *cam.ICamera = iCreateCamera( )
iPositionNode(*cam, 0,1,-20)


Repeat
 
  If iGetKeyDown(#KEY_ARROW_UP)
    iMoveNode(*cam, 0,0,0.5)
  EndIf
  If iGetKeyDown(#KEY_ARROW_DOWN)
    iMoveNode(*cam, 0,0,-0.5)
      EndIf
  If iGetMouseEvent(#MOUSE_BUTTON_LEFT)
          If flagXDown=0
              omx = iGetMouseX()
              omy = iGetMouseY()
              flagXDown=11
          Else
              moy = iGetMouseY()-omy
              angley=(moy/10.0)
              omy= iGetMouseY()
              mox = iGetMouseX()-omx
              anglex=(mox/10.0)
              omx= iGetMouseX()
              iTurnNode(*cam, angley, anglex,0)
          EndIf
  Else
               flagXDown=0
  EndIf

If iGetKeyDown(#KEY_SPACE)
  ;If iNodeVisible(*part) : iVisibleNode(*part,#False) : Else : iVisibleNode(*part,#True) : EndIf 
  EndIf


    If iGetKeyDown(#KEY_ESCAPE)
    Quit=1
  EndIf

  ;iMoveNode (*part,0,1,0)


  iBeginScene(0,0,0)
  iDrawScene()
  iEndScene()


Until Quit=1

iFreeEngine()


Here is the other one, which doesnt work properly:

Code: Select all

IncludePath  #PB_Compiler_Home + "Includes\N3xtd\"   :   IncludeFile "n3xtD_PB.pbi"


Global    anglex.f, angley.f, flagXDown.w
Global    mox.f, omx.f, moy.l, omy.l

Global *app.l, Quit.l

Declare CreateExplosion(x.f,y.f,z.f)

Structure ExplosionFX
  *p1.IParticleSystem
  *p2.IParticleSystem
  *p3.IParticleSystem
  *p4.IParticleSystem
  *e1.IParticle
  *e2.IParticle
  *e3.IParticle
  *e4.IParticle
  *m1.IMesh
  *m2.IMesh
  *m3.IMesh
  x.f
  y.f
  z.f
EndStructure

Global NewList Explosions.ExplosionFX()


Procedure CreateExplosion(x.f,y.f,z.f)
  
  AddElement(Explosions())
  
  Explosions()\m1 = iCreateSphere(1,4,#Null) 
  Explosions()\m2 = iCreateCube(4,#Null)
  Explosions()\m3 = iCreateSphere(1,32,#Null) 
  iVisibleNode(Explosions()\m1,#False) 
  iVisibleNode(Explosions()\m2,#False) 
  iVisibleNode(Explosions()\m3,#False) 
  
  Explosions()\p1 = iCreateParticleSystem(#False, #Null)
  Explosions()\p2 = iCreateParticleSystem(#False, #Null);Explosions()\p1)
  Explosions()\p3 = iCreateParticleSystem(#False, #Null);Explosions()\p1)
  Explosions()\p4 = iCreateParticleSystem(#False, #Null);Explosions()\p1)
   
  Explosions()\e1 = iCreateParticleMeshEmitter(Explosions()\p1, Explosions()\m1,#True,0,0,0,80,-1,#True,1,1,$00FFFFC5,$00FC4C22,500,500,90,10,10,10,10)
  Explosions()\e2 = iCreateParticleMeshEmitter(Explosions()\p2, Explosions()\m2,#True,0,0,0,70,-1,#True,1,1,$FFD7B728,$FF9F871D,600,1100,140,0.1,0.1,0.1,0.1) 
  Explosions()\e3 = iCreateParticleMeshEmitter(Explosions()\p3, Explosions()\m1,#True,0,0,0,80,-1,#True,1,1,$00D7B728,$FF808080,800,1000,20,0.3,0.3,0.5,0.5)
  Explosions()\e4 = iCreateParticleMeshEmitter(Explosions()\p4, Explosions()\m3,#True,0,0,0,80,-1,#True,1,1,$00111111,$00111111,600,1300,50,15,15,20,20)
  
  iLoadTextureNode(Explosions()\p1, "particle1.png") 
  iLoadTextureNode(Explosions()\p2, "particle1.png") 
  iLoadTextureNode(Explosions()\p3, "particle3.png") 
  iLoadTextureNode(Explosions()\p4, "particle4.png") 
  
  iAddEmitterParticleSystem(Explosions()\p1, Explosions()\e1) : iFadeOutParticleSystem(Explosions()\p1) : iRotationParticleSystem(Explosions()\p1,0,0,50)
  iAddEmitterParticleSystem(Explosions()\p2, Explosions()\e2) : iFadeOutParticleSystem(Explosions()\p2)
  iAddEmitterParticleSystem(Explosions()\p3, Explosions()\e3) : iFadeOutParticleSystem(Explosions()\p3) : iRotationParticleSystem(Explosions()\p3,0,0,40)
  iAddEmitterParticleSystem(Explosions()\p4, Explosions()\e4) : iFadeOutParticleSystem(Explosions()\p4)
  
   iMaterialFlagNode(Explosions()\p1,#EMF_LIGHTING,#False)
   iMaterialFlagNode(Explosions()\p1,#EMF_ZWRITE_ENABLE, #False)
   iMaterialTypeNode(Explosions()\p1,#EMT_TRANSPARENT_VERTEX_ALPHA)
   
   iMaterialFlagNode(Explosions()\p2,#EMF_LIGHTING,#False)
   iMaterialFlagNode(Explosions()\p2,#EMF_ZWRITE_ENABLE, #False)
   iMaterialTypeNode(Explosions()\p2,#EMT_TRANSPARENT_VERTEX_ALPHA)
   
   iMaterialFlagNode(Explosions()\p3,#EMF_LIGHTING,#False)
   iMaterialFlagNode(Explosions()\p3,#EMF_ZWRITE_ENABLE, #False)
   iMaterialTypeNode(Explosions()\p3,#EMT_TRANSPARENT_VERTEX_ALPHA)
   
   iMaterialFlagNode(Explosions()\p4,#EMF_LIGHTING,#False)
   iMaterialFlagNode(Explosions()\p4,#EMF_ZWRITE_ENABLE, #False)
   iMaterialTypeNode(Explosions()\p4,#EMT_TRANSPARENT_VERTEX_ALPHA)
 
  
;   iPositionNode(Explosions()\p1,x,y,z)
;   iPositionNode(Explosions()\p2,x,y,z)
;   iPositionNode(Explosions()\p3,x,y,z)
;   iPositionNode(Explosions()\p4,x,y,z)
  
    
EndProcedure


*app = iCreateGraphics3D(800,600, 32, #False, #True, #EDT_DIRECT3D9)
If *app= #Null: End : EndIf
 

Define *cam.ICamera = iCreateCamera( )
iPositionNode(*cam, 0,1,-20)


CreateExplosion(0,0,0)

Repeat
 
  If iGetKeyDown(#KEY_ARROW_UP)
    iMoveNode(*cam, 0,0,0.5)
  EndIf
  If iGetKeyDown(#KEY_ARROW_DOWN)
    iMoveNode(*cam, 0,0,-0.5)
      EndIf
  If iGetMouseEvent(#MOUSE_BUTTON_LEFT)
          If flagXDown=0
              omx = iGetMouseX()
              omy = iGetMouseY()
              flagXDown=11
          Else
              moy = iGetMouseY()-omy
              angley=(moy/10.0)
              omy= iGetMouseY()
              mox = iGetMouseX()-omx
              anglex=(mox/10.0)
              omx= iGetMouseX()
              iTurnNode(*cam, angley, anglex,0)
          EndIf
  Else
               flagXDown=0
  EndIf

If iGetKeyUp(#KEY_SPACE)
   ;CreateExplosion(0,0,0)
  EndIf


    If iGetKeyUp(#KEY_ESCAPE)
    Quit=1
  EndIf

  

  iBeginScene(0,0,0)
  iDrawScene()
  iEndScene()


Until Quit=1

iFreeEngine()
http://www.file-upload.net/download-282 ... X.zip.html

Hope somebody can help!

Alex
Repeat
PureBasic
ForEver
User avatar
Innesoft
Enthusiast
Enthusiast
Posts: 105
Joined: Mon Jan 18, 2010 10:30 am
Location: UK
Contact:

Re: Some problems with N3XTD

Post by Innesoft »

In the first code i've created a particle explosion effect. In the next one i tried to prepare the code for implementation. I used a structure and a linkedlist
to store the n3xtd pointers, but the particles are only rendered in pure white
Both work here, so maybe I'm using a different N3xtD build (tried with 2 different build20's I have lying around). Here's a couple things I'd check..

1. Firstly, your particle3.png is not a power2 texture. (43x44).. either scale or expand it to 64x64, as some cards will not like this
2. Things being rendered pure white in irrlicht is usually due to fog issues. try disabling fog in your materials, and setting the fog-mode to eponential with 0.0 density, or linear with a huge range.
3. If it works for me but not you, it's either; (a)your n3xtD build is bugged or (b)a graphics card/driver issue, but since your material constants were messed up before, it's probably (a)
4. Clue: To get the "particlefx1.pb" example to work here, I had to comment out InitParticleFX() since mine doesn't have that, so I'm guessing InitParticleFx() does something with materials that causes the problem? See if it works without it.
User avatar
A.D.
User
User
Posts: 98
Joined: Tue Oct 06, 2009 9:11 pm

Re: Some problems with N3XTD

Post by A.D. »

I found the bug! Very silly bug !
Explosions()\m1 = iCreateSphere(1,4,#Null)
Explosions()\m2 = iCreateCube(4,#Null)
Explosions()\m3 = iCreateSphere(1,32,#Null)
corrected:

Code: Select all

Explosions()\m1 = iCreateSphere(1,4,#Null) 
Explosions()\m2 = iCreateSphere(1,32,#Null)
Explosions()\m3 = iCreateCube(4,#Null)


I haven't been coding for a longer period. Think i have to get used to it again :mrgreen:
Thanks for testing my code, Innesoft!

Alexander
Repeat
PureBasic
ForEver
User avatar
A.D.
User
User
Posts: 98
Joined: Tue Oct 06, 2009 9:11 pm

Re: Some problems with N3XTD

Post by A.D. »

Hi again !!!

Code: Select all

Explosions()\e1 = iCreateParticleMeshEmitter(Explosions()\p1, Explosions()\m1,#True,0,0,0,80,-1,#True,1,1,$00FFFFC5,$00FC4C22,500,500,90,10,10,10,10)
As you can see, i'm using a single particle for each emitter to make my explosion. The problem is that it takes 500ms until my particle is emitted due to N3XTD evenly spreads the amount of particles to a second. So everytime my explosion delays for 500ms. Is there a way to avoid this? Could i import a specific command from the n3xtd.lib to change the behaviour of the emitter? Unfortunately i cannot find the source code of the engine anymore.

Greetings
A.D.
Repeat
PureBasic
ForEver
Post Reply