MiniB3d for FreeBasic

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
ITomi
Posts: 83
Joined: Jul 31, 2015 11:23
Location: Hungary

Re: MiniB3d for FreeBasic

Postby ITomi » Nov 13, 2016 8:30

I tried to attach the weapon entity to the camera, but when I use the "turnentity" command at the camera, the weapon is disappear (when I use "moveentity", the weapon moves correctly with it ahead and backward):

Code: Select all

var weapon=createsprite(camera)
scalesprite weapon,0.5,0.5
entitytexture weapon,weapon1tex
positionentity weapon,entityx#(camera),entityy#(camera),entityz#(camera)+1

Do
        'TurnEntity skydome,0.1,0,0
       
        if multikey(sc_up) then moveentity camera,0,0,0.1
        if multikey(sc_down) then moveentity camera,0,0,-0.1
        if multikey(sc_left) then turnentity camera,0,0.1,0
        if multikey(sc_right) then turnentity camera,0,-0.1,0
       
        updateworld
        renderworld
        Flip
Loop Until MultiKey(sc_q)
angros47
Posts: 1293
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Postby angros47 » Nov 13, 2016 10:10

The solution is simple: replace "entityz#(camera)+1" with "entityz#(camera)+1.1".

The camera range, by default, is 1 to 1000, so objects that are at a distance from the camera smaller than 1 are not rendered. And you put the sprite at a distance of 1, that is the limit: when you turn the camera, smallest rounding errors makes the sprite to be closer than 1, and so it is not rendered any more, and it disappears.
ITomi
Posts: 83
Joined: Jul 31, 2015 11:23
Location: Hungary

Re: MiniB3d for FreeBasic

Postby ITomi » Nov 13, 2016 13:16

Thank you, Anngros47, I didn't know it, but works!
And one more question: is there a background color to the sprite entities in 3d mode, that I will make it partially transparent? E.g. the colors around the weapon.
angros47
Posts: 1293
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Postby angros47 » Nov 13, 2016 18:44

If the image is a png, it can have a alpha channel, that makes it partially transparent
ITomi
Posts: 83
Joined: Jul 31, 2015 11:23
Location: Hungary

Re: MiniB3d for FreeBasic

Postby ITomi » Nov 14, 2016 14:08

I tried with .jpg, .bmp and .png formats, but the pixels are remain around the weapon. Where is the background color and which is? The bottom-left corner or other?
angros47
Posts: 1293
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Postby angros47 » Nov 14, 2016 15:26

The image must be in png, must have transparency set, and must be loaded with the masked flag (4)
ITomi
Posts: 83
Joined: Jul 31, 2015 11:23
Location: Hungary

Re: MiniB3d for FreeBasic

Postby ITomi » Nov 15, 2016 10:08

OK, I load with the masked flag:

Code: Select all

var weapontex=loadtexture("images\weapons\pistol.png",4)

but how and where can I set its transparency? In a drawing program (e.g. Paint) or with a command?
angros47
Posts: 1293
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Postby angros47 » Nov 15, 2016 16:03

In a drawing program (it is sometimes called alpha channel)
ITomi
Posts: 83
Joined: Jul 31, 2015 11:23
Location: Hungary

Re: MiniB3d for FreeBasic

Postby ITomi » Nov 15, 2016 17:23

Huhhh, thanks, Angros47, it succesfully done! :-)
(It seems that Windows7's Paint is not a suitable program for this, but I found better tools.)
ITomi
Posts: 83
Joined: Jul 31, 2015 11:23
Location: Hungary

Re: MiniB3d for FreeBasic

Postby ITomi » Dec 06, 2016 9:19

How can I check if an entity is in front of the camera within a certain distance?
I would like check the collisions and I can compute the distance between two 3d objects, so on the basis of it I can stop the movement, but I can't check whether an entity is in the range of the camera or beside or behind of it.
angros47
Posts: 1293
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Postby angros47 » Dec 10, 2016 4:43

EntityPick does what you need, look at this:

http://www.blitzbasic.com/b3ddocs/comma ... entitypick

Also, EntityInView and EntityDistance can help
angros47
Posts: 1293
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Postby angros47 » Aug 08, 2017 21:58

Version 1.20 is online

Added:
-Custom shaders now can also use the entity textures
-Experimental post processor

Fixed:
-Bug in isosurfaces when using custom shaders
-Bug in RotateEntity and PointEntity, that caused issue with the scale of an entity when it was in a nested structure
-Bug in calculating light in geospheres
angros47
Posts: 1293
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Postby angros47 » Aug 12, 2017 12:17

An example of postfx (gaussian blur)

Code: Select all

#include "openb3d.bi"

screen 18,  32, , &h10002

   
Graphics3d 640,480,32,1,1

var camera=createcamera(0)
cameraclscolor camera,0,0,255

var shader=loadshader("gauss","gaussian.vert","gaussian.frag")
setinteger shader, "RenderTex",0
setinteger shader, "Width",640
setinteger shader, "Height",480

var fx=createpostfx(camera,2)
hideentity camera

AddRenderTarget fx,0,1,1
Postfxbuffer fx,0,0,1,0
AddRenderTarget fx,1,1,0
Postfxbuffer fx,1,1,1,0
PostFXShader fx,0,shader
PostFXShaderPass fx,0,"PassNum",1
PostFXShader fx,1,shader
PostFXShaderPass fx,1,"PassNum",2


var cube=createcube()
entitycolor cube,255,0,0

var plane=createplane()
moveentity plane,0,-1.4,15


var light=createlight()
moveentity light,10,10,-3
pointentity light,cube
moveentity camera,-2,0,-5

createshadow cube

dim key as string
do

   key=inkey
        if key=chr(255)+"H" then turnentity cube,1,0,0,0
        if key=chr(255)+"P" then turnentity cube,-1,0,0,0
        if key=chr(255)+"M" then turnentity cube,0,-1,0,0
        if key=chr(255)+"K" then turnentity cube,0,1,0,0
   updateworld 1
   renderworld
sleep 1
   flip
loop until key=chr(27)



gaussian.vert

Code: Select all

#version 120

varying vec3 Position;
varying vec3 Normal;
varying vec2 TexCoord;


void main()
{
   TexCoord = gl_MultiTexCoord0.st;
   Normal = normalize(gl_NormalMatrix * gl_Normal);
   Position = vec3(gl_ModelViewMatrix * gl_Vertex);
   
   gl_Position = ftransform();
}


gaussian.frag

Code: Select all

#version 120

uniform int PassNum;

uniform sampler2D RenderTex;

uniform int Width;
uniform int Height;

varying vec3 Position;
varying vec3 Normal;
varying vec2 TexCoord;

float PixOffset[7] = float[] (0.0,1.5,3.0,4.5,6.0,7.5,9.0);
//float PixOffset[5] = float[] (0.0,1.5,3.0,4.5,6.0);
//float PixOffset[5] = float[] (0.0,0.1,0.2,0.3,0.4);
//float Weight[5] = float[] (0.75,1.0,1.5,1.0,0.75);
float Weight[5] = float[] (0.05,0.14,0.2,0.14,0.05);
//float Weight[5] = float[] (0.001,0.02,0.23,0.02,0.001);
//float Weight[7] = float[] (0.015625,0.09375,0.234375,0.3125,0.234375,0.09375,0.015625);
//float Weight[7] = float[] (0.01562,0.0937,0.2343,0.3125,0.2343,0.0937,0.0156);

vec4 Pass1()
{
   float dy = 1.0 / float(Height);
   vec4 sum = texture2D(RenderTex,TexCoord) * Weight[0];
   for ( int i = 1; i < 5; i++)
   {
      sum += texture2D(RenderTex, TexCoord + vec2(0.0,PixOffset[i]) * dy ) * Weight[i];
      sum += texture2D(RenderTex, TexCoord - vec2(0.0,PixOffset[i]) * dy ) * Weight[i];
   }
   return sum;
}

vec4 Pass2()
{
   float dx = 1.0 / float(Width);
   vec4 sum = texture2D(RenderTex, TexCoord) * Weight[0];
   for ( int i = 1; i < 5; i++)
   {
      sum += texture2D(RenderTex, TexCoord + vec2(PixOffset[i],0.0) * dx ) * Weight[i];
      sum += texture2D(RenderTex, TexCoord - vec2(PixOffset[i],0.0) * dx ) * Weight[i];
   }
   return sum;
}


void main()
{
   if (PassNum == 1)
   {
      gl_FragColor = Pass1();
   }
   if (PassNum == 2)
   {
      gl_FragColor = Pass2();
   }
}
Kronos
Posts: 9
Joined: Dec 10, 2012 19:53

Re: MiniB3d for FreeBasic

Postby Kronos » Aug 12, 2017 15:51

Hi Angros,

Are you aware of any issues with the Animate function?
I can LoadAnimMesh a .b3d model and everything looks correct, but when I set the Animate function , model is animating but appears to be rotated 180 degrees around the Y axis. Any lighting on the model is also flipped 180 degrees.

The only commands I am using are

LoadAnimMesh("D:\Models\goblin.b3d");
Animate(goblin,1,1.5f,0,0);
angros47
Posts: 1293
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Postby angros47 » Aug 12, 2017 15:59

The issue is caused by the fact that the model has been rotated by the animation program, so, when it is not animated, it is in a position, but when is animating, all frames of the animation have it rotated. Unfortunately, OpenB3D does not update the normals, when performing an animation (usually, the difference is minimal, and in complex model updating normals would double the time for animation, and memory occupation), so, if the model is suddenly rotated by 180, all the normals will be inverted, and this will affect the lighting. The animated mesh has been made by you? Or converted by you in b3d format? If so, perhaps you should check your export settings

Return to “Libraries”

Who is online

Users browsing this forum: No registered users and 1 guest