WorldSim3D Community

WorldSim3D English => WorldSim3D Techical Discussion => Topic started by: jepalza on November 04, 2015, 12:31:58 PM

Title: Loading Shaders and objects from BSP (beta)
Post by: jepalza on November 04, 2015, 12:31:58 PM
Thanks to Nikolas help, did try a beta test for load BSP entities and shaders, and this is the result:
(http://i772.photobucket.com/albums/yy6/afrikano67/bsp_shader2.jpg) (http://s772.photobucket.com/user/afrikano67/media/bsp_shader2.jpg.html)

(http://i772.photobucket.com/albums/yy6/afrikano67/bsp_shaders.jpg) (http://s772.photobucket.com/user/afrikano67/media/bsp_shaders.jpg.html)

IT'S GOOD!!!  :P

Goes to try it out in a big map, in order to look for errors (or not ;-) )


Edit:
another test, whith smoke or shinning from windows ;-)
(http://i772.photobucket.com/albums/yy6/afrikano67/good_shader.jpg) (http://s772.photobucket.com/user/afrikano67/media/good_shader.jpg.html)

 :P :P :P
Title: Re: Loading Shaders and objects from BSP (beta)
Post by: Alec - WS3D Developer on November 04, 2015, 02:55:09 PM
Wow! It looks just super-duper!  :o
Title: Re: Loading Shaders and objects from BSP (beta)
Post by: jepalza on November 04, 2015, 03:18:44 PM
In short (this afternoon), try to probe this example with my "old" BSP_Viewer and my WOW Camera like style. It will be spectacular!!  :) (Like a Quake III Arena game, but written in FreeBasic)

Edit:
With a very, very big map like SIMPSONS , is very slow, only two frames per second, fails a little textures and error like picture
(http://i772.photobucket.com/albums/yy6/afrikano67/simpson.jpg) (http://s772.photobucket.com/user/afrikano67/media/simpson.jpg.html) 
Title: Re: Loading Shaders and objects from BSP (beta)
Post by: Nikolas - WS3D Developer on November 04, 2015, 04:14:30 PM
Good result!
Quote
Too many vertices for 16 bit....
The maximum value is approximately equal to
Code: [Select]
Dim verts(0 to 32667) as wVERTSee the theme: http://worldsim3d.com/Forum/index.php?topic=139.15 (http://worldsim3d.com/Forum/index.php?topic=139.15)
If not enough, you need to split the level into parts.
Or come up with another way to optimize (now)
Title: Re: Loading Shaders and objects from BSP (beta)
Post by: jepalza on November 05, 2015, 08:41:18 AM
With SIMPSONS map is not possible, is a very big map. But is the only big map, it's alone.

Another picture, with my WOW like style camera :D
(http://i772.photobucket.com/albums/yy6/afrikano67/quake3_real_camera.jpg) (http://s772.photobucket.com/user/afrikano67/media/quake3_real_camera.jpg.html)

It's very real feel, like a QUAKE3 Arena
Title: Re: Loading Shaders and objects from BSP (beta)
Post by: jepalza on November 05, 2015, 08:55:05 AM
A little problem, if shaders is not in collision map:
(http://i772.photobucket.com/albums/yy6/afrikano67/shader_problem.jpg) (http://s772.photobucket.com/user/afrikano67/media/shader_problem.jpg.html)


But not at all must be in collision map:
(http://i772.photobucket.com/albums/yy6/afrikano67/shader_problem2.jpg) (http://s772.photobucket.com/user/afrikano67/media/shader_problem2.jpg.html)

Title: Re: Loading Shaders and objects from BSP (beta)
Post by: Nikolas - WS3D Developer on November 05, 2015, 02:14:39 PM
Need a recognition system Shader nodes to be divided into two groups:
1) collisions (boxes, lamps, pools, large objects, glass, etc.)
2) no collisions (torches, sunlight, fire, etc.).

Can offer algorithm:
1) Looking for the right Shader nodes (I'll work on that)
2) Read his name
3) If you want, then create a node for the selector triangles.

Perhaps you have a different algorithm?
Title: Re: Loading Shaders and objects from BSP (beta)
Post by: jepalza on November 05, 2015, 02:30:46 PM
Perhaps you have a different algorithm?

At this moment, no, sorry. I'm look into BSP structure, in order to investigate it.
Title: Re: Loading Shaders and objects from BSP (beta)
Post by: Nikolas - WS3D Developer on November 05, 2015, 02:39:20 PM
Then I'll try to implement the above algorithm
Title: Re: Loading Shaders and objects from BSP (beta)
Post by: jepalza on November 05, 2015, 03:36:50 PM
Look at this piece of code:
Code: [Select]
textures/sfx/beam_waterlight2
{
        qer_editorimage textures/sfx/beam_waterlight.tga
q3map_globaltexture
surfaceparm trans
        surfaceparm nomarks
        surfaceparm nonsolid // NONSOLID PARAMETER!!!!!
        surfaceparm nolightmap
q3map_surfacelight 50
        qer_trans 0.6
cull none
surfaceparm nomipmaps
        //nopicmip
{
map textures/sfx/beam_waterlight.tga
//tcMod scale 0.35 0.35
tcMod turb 0 0.015 0.5 0.07
tcMod Scroll .15 0
                blendFunc add
        }

}


Is part of shader "sfx.shader" from quake 3. It's used for my example of above (dracula map), for shinning dust throught windows.
If you read it, you see parameter "surfaceparm nonsolid" , it's same for beamlight shader, or for flames shader. Maybe is the best solution: read shader from "script" directory, and look for this parameter.
In other cases, like "pentagram" shader on the floor, this parameter is not exists. Mybe is only for light, flames, beams, shadows, etc
Title: Re: Loading Shaders and objects from BSP (beta)
Post by: Nikolas - WS3D Developer on November 05, 2015, 03:57:59 PM
I understand your idea. It would be useful, if you load the nodes "by hand"
I think I need to try two solutions.
Title: Re: Loading Shaders and objects from BSP (beta)
Post by: Nikolas - WS3D Developer on November 05, 2015, 06:19:21 PM
The problem is this:

When you create a Shader of nod all the SAME meshbuffer are attached to the SAME node.
This can be seen in screenshot 1.

I recompiled libIrrlicht.dlll, by changing the structure (highlighted in red).
The result is visible in the screenshot 2: each Shader node has an independent meshbuffer (included dimensional box).
struct Q3LevelLoadParameter
   {
      Q3LevelLoadParameter ()
         :defaultLightMapMaterial ( video::EMT_LIGHTMAP_M4 ),
         defaultModulate ( video::EMFN_MODULATE_4X ),
         defaultFilter ( video::EMF_BILINEAR_FILTER ),
         patchTesselation ( 8 ),
         verbose ( 0 ),
         startTime ( 0 ), endTime ( 0 ),
         mergeShaderBuffer ( 0 )(older value=1)
         cleanUnResolvedMeshes ( 1 ),
         loadAllShaders ( 0 ),
         loadSkyShader ( 0 ),
         alpharef ( 1 ),
         swapLump ( 0 ),
.....
To search for a node we can use this code:
Code: [Select]
Dim As wNode root=wGetRootSceneNode ( )
Dim As Any ptr position
Dim As wNode node= wGetNodeFirstChild ( root, position )
       Dim i As Integer
While wIsNodeLastChild ( root, position ) <>1
node=wGetNodeNextChild ( root,position )
If node<>0 Then
If wGetNodeType(node)=wSNT_Q3SHADER_SCENE_NODE Then
'Print *wGetNodeName(node)
Dim As String chortName=GetNoPathName(*wGetNodeName(node))
If chortName="timlamp" Then
Print "timlamp"
'wDebugDataVisible(node,value)
...............
collisions
...............
EndIf
EndIf
EndIf
        Wend

GetNoPathName- this my small  procedure:
Code: [Select]
Function GetNoPathName(ByVal tName As string) As String
Dim As Integer strLen=Len(tName)
Dim  i As Integer
Dim As Integer index
For i=1 To strLen
If Mid(tName,i,1)="/" Or Mid(tName,i,1)="\" Then
index=i
EndIf
Next
Dim As String newString=Right(tName,Len(tName)-index)
Return newString
End Function
So now we can work with each node as a separate object, including for possible collisions.

For collision (for example):

...
Dim As wSelector nodeSelector=wGetCollisionGroupFromBox(node )
wSetNodeTriangleSelector(node,nodeSelector)
wAddCollisionGroupToCombination (GLOBAL_SELECTOR, nodeSelector )

...

But, in screenshot 2 you can see the problem with the "liquid", as it was divided into several nodes.
Title: Re: Loading Shaders and objects from BSP (beta)
Post by: Nikolas - WS3D Developer on November 05, 2015, 06:50:15 PM
PS: In BSP-map in map-20kdm2.pk3
1) old variant: Nodes count: 24, fps=60
2) new variant: Nodes count: 128, fps=30
Думаю, все ненужные для коллизий или другого шейдерные ноды придется объединять.
(I think all unnecessary collisions or other Shader nodes will be merged.)
Title: Re: Loading Shaders and objects from BSP (beta)
Post by: jepalza on November 05, 2015, 09:22:38 PM
But, in screenshot 2 you can see the problem with the "liquid", as it was divided into several nodes.

Liquid is not a problem, is transparent, not necessary in collision map, but floor IS a problem. Several pieces of floor are shader, and if this shader is several nodes, we have a problem.  :(

Goes to probe your idea, in order to get another solution. Maybe, do can compile irrlitch code and help you.

2) new variant: Nodes count: 128, fps=30
:o and when the map is very big????

Example of BIG shader (several nodes?) in floor of "x3map06.bsp" (X3map_v1_final.pk3)
(http://i772.photobucket.com/albums/yy6/afrikano67/shader_floor.jpg) (http://s772.photobucket.com/user/afrikano67/media/shader_floor.jpg.html)
Title: Re: Loading Shaders and objects from BSP (beta)
Post by: Nikolas - WS3D Developer on November 05, 2015, 10:14:29 PM
Quote
Several pieces of floor are shader, and if this shader is several nodes, we have a problem.
Well, we will think over this problem.
For example,from Shader node to get the mesh (meshbuffer) using wGetNodeMesh, then apply the selector to a mesh of triangles

Quote
and when the map is very big?
I think all unnecessary collisions or other Shader nodes will be merged.

About Liquid: see screen.
Title: Re: Loading Shaders and objects from BSP (beta)
Post by: jepalza on November 06, 2015, 06:16:13 PM
Ok, understand you, but: all of this is made on worldsim3d engine (future)? or this work is for make on my own code? :-X
Title: Re: Loading Shaders and objects from BSP (beta)
Post by: Nikolas - WS3D Developer on November 06, 2015, 06:27:51 PM
I will try to make in addition to automatic loading Shader "manually". This allows you to work with Shader nodes selectively. In version 0.9.6 will be submitted to the test version (and earlier).
Title: Re: Loading Shaders and objects from BSP (beta)
Post by: Nikolas - WS3D Developer on November 09, 2015, 06:49:49 PM
At the moment still could do a manual download of quake3 shaders as follows. However, the problem of collisions is not solved. (!NEW FUNCTIONS!)
Code: [Select]
Dim k As Integer
For k=0 To  wGetQ3ShaderCount(BSPmesh)-1
Dim As UInteger shaderIndex=wGetQ3ShaderIndex(BSPMesh,k)
Dim As UInteger Ptr shader=wGetQ3Shader(BSPMesh,shaderIndex)
Dim As String shaderName=GetNoPathName(*wGetQ3ShaderName(shader))
Print "Q3Shader_Name: "+shaderName
Dim As wMeshBuffer buf=wGetQ3ShaderMeshBuffer(BSPMesh,k)
Dim As wNode node=wCreateQ3ShaderNode(buf,shader)
Next
BSPNode = wAddQ3LevelToScene(BSPMesh,0,"",0,0
This (last) parameter: 0- not to load the shaders, 1- load shaders

I was able to create a method of combining meshbuffers, but I can't I combine the effect Shader on ALL new meshbuffer :(
===================
This method can be used if you want to load shaders, NOT ALL, but selectively.
Title: Re: Loading Shaders and objects from BSP (beta)
Post by: Nikolas - WS3D Developer on November 09, 2015, 07:04:54 PM
Made a lot of new features for working with meshbuffers, there are no results yet.
Code: [Select]
Declare Function wCreateEmptyMeshBuffer()As wMeshBuffer

Declare Function wCreateEmptyMeshBufferLightMap()As wMeshBuffer

Declare Sub wRemoveMeshBuffer(ByVal buffer As wMeshBuffer)

Declare sub wMeshBufferLightMapSetMaterial(ByVal buffer As wMeshBuffer,ByVal  mat As wMaterial)

Declare sub wAddMeshBufferToMesh(_
ByVal mesh As wMesh,_
byval buffer As wMeshBuffer,_
byval isDropOriginal As Integer=1)

Declare Function wMeshBufferMerge(_
byval dest As wMeshBuffer,_
byval source As wMeshBuffer,_
byval isDropSource As integer=0)As wMeshBuffer

Declare function wMeshBufferCopy(_
byval source As wMeshBuffer,_
byval isDropSource As integer=0)As wMeshBuffer

Declare Function wMeshBufferLightMapMerge(_
Byval dest As wMeshBuffer,_
byval source As wMeshBuffer,_
byval isDropSource As integer=0)As wMeshBuffer

Declare function wMeshBufferLightMapCopy(_
byval source As wMeshBuffer,_
byval isDropSource As integer=0)As wMeshBuffer

Declare function wMeshCopy2(_   'for static meshes!!!
byval source As wMesh,_
byval isDropSource As integer=1)As wMesh
I don't understand how to combine the work of several q3 shaders in one....
Title: Re: Loading Shaders and objects from BSP (beta)
Post by: jepalza on November 09, 2015, 11:58:59 PM
and searching on web for shaders manuals, don't help you?
Maybe this:
https://graphics.stanford.edu/courses/cs448-00-spring/q3ashader_manual.pdf

Or looking Quake 3 arena code:
https://github.com/id-Software/Quake-III-Arena

I don't help you in any about engine, because the code is only yours.

This weekend goes to stude it in order to get any idea. (if can)