MiniB3d for FreeBasic

Headers, Bindings, Libraries for use with FreeBASIC, Please include example of use to help ensure they are tested and usable.
Post Reply
Westbeam
Posts: 239
Joined: Dec 22, 2009 9:24
Contact:

Re: MiniB3d for FreeBasic

Post by Westbeam »

Uhm, next problem ... again with shaders ._.
I'm trying to implement a light scattering shader(this one), but somehow every mesh I apply the shader on(with ShadeEntity or ShadeMesh) appears just black?

This is my code:

Code: Select all

Dim Shared As Any Ptr rayshader
rayshader=loadshader("MyShader", Exepath+"/data/shader/rays_vert.glsl",Exepath+"/data/shader/rays_frag.glsl")	'Map.bi
setfloat rayshader, "Exposure", 0.0034
setfloat rayshader, "Decay", 1.0
setfloat rayshader, "Density", 0.84
setfloat rayshader, "Weight", 5.65
Chdir Exepath+"/data/gfx/star1"
shadertexture rayshader, loadtexture("sunshine1.bmp"), "myTexture",0

' ...
ShadeMesh obj1, rayshader
ShadeEntity obj2, rayshader
I think I need to tell the program where the light source is, but you said on page 38, that vec2 parameters are not supported(the shader got a vec2 parameter for the light position). Is there another solution?
angros47
Posts: 2386
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Post by angros47 »

In this case, you should be able to set the light position using setfloat2

Code: Select all

setfloat2 rayshader, lightPositionOnScreen, 1,1,1

Anyway, there is a mistake in your code: GLSL (the language used to program shaders) is case sensitive, so the names used for variables must match exactly: you used "setfloat rayshader, "Exposure", 0.0034", while in the shader there is the line "uniform float exposure;" (in GLSL, like in C, "Exposure" and "exposure" are different variables).

Likely the shader appears just black because the main variables are all set to 0, since you didn't set them (you set other variables, with similar names)
Westbeam
Posts: 239
Joined: Dec 22, 2009 9:24
Contact:

Re: MiniB3d for FreeBasic

Post by Westbeam »

You mean

Code: Select all

setfloat2 rayshader, "lightPositionOnScreen", 1,1
?

Looks even weirder :D , it textures every mesh, I did "ShadeEntity" on, with the shadertexture and shows random white bugs:
http://s14.directupload.net/images/141021/m5pic2le.png
angros47
Posts: 2386
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Post by angros47 »

Westbeam wrote:You mean

Code: Select all

setfloat2 rayshader, "lightPositionOnScreen", 1,1
?
Yes, sorry.

Looks even weirder :D , it textures every mesh, I did "ShadeEntity" on, with the shadertexture and shows random white bugs:
http://s14.directupload.net/images/141021/m5pic2le.png
On what kind of entity you applied ShadeEntity? Was it a mesh, or a terrain, or a geosphere?
Westbeam
Posts: 239
Joined: Dec 22, 2009 9:24
Contact:

Re: MiniB3d for FreeBasic

Post by Westbeam »

Meshes
angros47
Posts: 2386
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Post by angros47 »

Does the same happens when you use ShadeMesh?

What if you use ShadeSurface? Your mesh has one or many surfaces?
Westbeam
Posts: 239
Joined: Dec 22, 2009 9:24
Contact:

Re: MiniB3d for FreeBasic

Post by Westbeam »

Doesn't matter, ShadeMesh, ShadeEntity and ShadeSurface do the same. :/
angros47
Posts: 2386
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Post by angros47 »

I tried to reproduce your issue with no success: I created two meshes, applied the shader to one of them, and the other is not affected by the shader.

Try doing a very simple program, with two or three meshes, using the shader: if you get the same bug, post your code.
Westbeam
Posts: 239
Joined: Dec 22, 2009 9:24
Contact:

Re: MiniB3d for FreeBasic

Post by Westbeam »

Code: Select all

#Include once "inc/libs/openb3d.bi"
#Define Render_OpenGL
#Include once "inc/libs/2d.bi"

ScreenRes 1024,768,32
Graphics3D 1024,768,32

Var cam=CreateCamera()
Var light=CreateLight()

Var cube1=CreateCube()
PositionEntity cube1,-2,0,6
Var cube2=CreateCube()
PositionEntity cube2,2,0,6

Var rayshader=loadshader("MyShader", Exepath+"/data/shader/rays_vert.glsl",Exepath+"/data/shader/rays_frag.glsl")	'Map.bi
setfloat rayshader, "exposure", 0.0034
setfloat rayshader, "decay", 1.0
setfloat rayshader, "density", 0.84
setfloat rayshader, "weight", 5.65
setfloat2 rayshader, "lightPositionOnScreen", 1,1

ShadeEntity cube1,rayshader

Do
	Sleep 1,1
	RenderWorld()
	UpdateWorld
	ScreenLock
		Cls
		
	ScreenUnlock
	ScreenSync
Loop Until Inkey=Chr(27)
ClearWorld
End
"cube1" looks like a black/white LSD-trip :(
angros47
Posts: 2386
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Post by angros47 »

I suppose that the files rays_vert.glsl and rays_frag.glsl are the files vert_simpleTexture.glsl and frag_simpleTexture.glsl renamed.

I tested your code, I got this:

Image

If you don't use 2d.bi, is there any change?
Westbeam
Posts: 239
Joined: Dec 22, 2009 9:24
Contact:

Re: MiniB3d for FreeBasic

Post by Westbeam »

If you don't use 2d.bi, is there any change?
Yes, a seg-fault ;)
angros47
Posts: 2386
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Post by angros47 »

Have you added the correct switches to screenres to enter opengl mode?
Westbeam
Posts: 239
Joined: Dec 22, 2009 9:24
Contact:

Re: MiniB3d for FreeBasic

Post by Westbeam »

Like this?

Code: Select all

#Include once "inc/libs/openb3d.bi"
#Define Render_OpenGL

ScreenRes 1024,768,32,,&h02
Graphics3D 1024,768,32

Var cam=CreateCamera()
Var light=CreateLight()

Var cube1=CreateCube()
PositionEntity cube1,-2,0,6
Var cube2=CreateCube()
PositionEntity cube2,2,0,6

Var rayshader=loadshader("MyShader", Exepath+"/data/shader/rays_vert.glsl",Exepath+"/data/shader/rays_frag.glsl")	'Map.bi
setfloat rayshader, "exposure", 0.0034
setfloat rayshader, "decay", 1.0
setfloat rayshader, "density", 0.84
setfloat rayshader, "weight", 5.65
setfloat2 rayshader, "lightPositionOnScreen", 1,1

ShadeEntity cube1,rayshader

Do
	Sleep 1,1
	RenderWorld()
	UpdateWorld
Loop Until Inkey=Chr(27)
ClearWorld
End
Gives me a black window.
angros47
Posts: 2386
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Post by angros47 »

You forgot "flip" after "RenderWorld"
Westbeam
Posts: 239
Joined: Dec 22, 2009 9:24
Contact:

Re: MiniB3d for FreeBasic

Post by Westbeam »

Oh thanks, but it's still the same, random white points on a black cube :(
Post Reply