PB 6.00 - 3D Examples - Shaders <<< Fixed >>>

Everything related to 3D programming
User avatar
pf shadoko
Enthusiast
Enthusiast
Posts: 285
Joined: Thu Jul 09, 2015 9:07 am

PB 6.00 - 3D Examples - Shaders <<< Fixed >>>

Post by pf shadoko »

I hope it will work for everyone this time !
the last version of opengl (4.6) being more punctilious, most of them bug if you don't define the "fog", so I added it to the example
#PB_Material_ColorShader and #PB_Material_PerpixelShader can have a black shading defect.
#PB_Material_PointSpriteSphereShader may crash
for these 3, I put a rewritten example (with CreateShadfer)
(there are other shaders, these examples only show those that can bug)
it will corrected in next PB version

Code: Select all

;  ----------------------------------------------------------------------------------------------------------
;   CreateShaderMaterial - #PB_Material_PointSpriteSphereShader
; ----------------------------------------------------------------------------------------------------------

Procedure.f POM(v.f)
    ProcedureReturn (Random(2000)-1000)*0.001*v
EndProcedure

InitEngine3D():InitSprite():InitKeyboard():InitMouse()

ExamineDesktops()
OpenWindow(0, 0,0, DesktopWidth(0)*0.8,DesktopHeight(0)*0.8, "CreateShaderMaterial - [Esc] quit",#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0), WindowHeight(0), 0, 0, 0)

CreateCamera(0, 0, 0, 100, 100):MoveCamera(0,0,2,-100):CameraLookAt(0,0,0,0)
CreateLight(0,$ffffff, 0,0, 0)
AmbientColor($222222)

CreateMesh(0,#PB_Mesh_PointList)
For i=0 To 100000
	MeshVertex(pom(200),pom(200),pom(200),Random(64,8)*0.05,  0,RGB(Random(255),Random(255),Random(255)))
Next
FinishMesh(1)

;CreateShaderMaterial(0,#PB_Material_PointSpriteSphereShader) ; don't work with last opengl version , use this :
vert_pg.s="%%%%#version 130%%uniform mat4 P20;//+20%uniform mat4 P8;//+8%uniform mat4 P12;//+12%uniform vec4 P108;//+108%uniform vec4 P43;//+43 0%uniform vec4 P44;//+44 0%uniform vec4 P76;//+76%uniform vec4 P41;//+41 0%uniform float size;//-1%%varying vec4 ocolor;%varying vec3 oldir;%varying vec3 ovdir;%%void main(void)%{%gl_Position=ftransform();%float vsize;if(size<0)vsize=gl_MultiTexCoord0.x;else vsize=size;%vec4 wv_pos=P20*gl_Vertex;%vec4 projVoxel=P12*vec4(vsize,vsize,wv_pos.z,wv_pos.w);%vec2 projSize=P108.xy*projVoxel.xy/projVoxel.w;%gl_PointSize=0.5*projSize.x;%%oldir=normalize((P8*P43).xyz-wv_pos.xyz);%ovdir=normalize((P8*P76).xyz-wv_pos.xyz);%%float Dist=distance(P44,gl_Vertex);%float lightatt=1.0/(P41.y+P41.z*Dist+P41.w*Dist*Dist);%ocolor=gl_Color*lightatt;%}%%%%%"
frag_pg.s="%%%%#version 130%%uniform float P36;//+36%uniform vec4 P67;//+67%uniform vec4 P69;//+69%uniform vec4 P70;//+70%uniform vec4 P31;//+31%uniform vec4 P30;//+30%%varying vec4 ocolor;%varying vec3 oldir;%varying vec3 ovdir;%%void main(void)%{%vec2 pc=gl_PointCoord*2-1;%float l2=dot(pc,pc);%if(l2>1)discard;%vec3 pdir=vec3(pc.x,-pc.y,sqrt(1-l2));%vec3 rdir=reflect(-ovdir,pdir);%float spe=pow(clamp(dot(oldir,rdir),0,1),P36);%float dif=max(dot(oldir,pdir),0);%gl_FragColor=vec4(ocolor.rgb*(P67.rgb+P69.rgb*dif),ocolor.a)+P70*spe;%}%%%%%"
CreateShader(0,vert_pg,frag_pg)
CreateShaderMaterial(0,0)


SetMaterialAttribute(0,#PB_Material_PointSprite,1)
MaterialShininess(0,64,$ffffff)

CreateEntity(0,MeshID(0),MaterialID(0))

Define.f a,da,r,MouseX,Mousey,depx,depz,dist,fly=1

Repeat
	While WindowEvent():Wend
	ExamineKeyboard()
	ExamineMouse()
	depx=(-Bool(KeyboardPushed(#PB_Key_Left))+Bool(KeyboardPushed(#PB_Key_Right)))*0.5
	depz=(-Bool(KeyboardPushed(#PB_Key_Down))+Bool(KeyboardPushed(#PB_Key_Up   ))+fly)*0.2+MouseWheel()*5
	MouseX = -MouseDeltaX() *  0.05
	MouseY = -MouseDeltaY() *  0.05
	RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
	dist+(depz-dist)*0.05:MoveCamera  (0, depX, 0, -dist)
	
	RenderWorld()
	FlipBuffers()    
Until KeyboardReleased(#PB_Key_Escape) Or MouseButton(3)

Code: Select all

;  ----------------------------------------------------------------------------------------------------------
;   CreateShaderMaterial - #PB_Material_CubicEnvBumpShader
; ----------------------------------------------------------------------------------------------------------

#PB_Material_CubicEnvBumpShader=$10009

InitEngine3D():InitSprite():InitKeyboard():InitMouse()

ExamineDesktops()
OpenWindow(0, 0,0, DesktopWidth(0)*0.8,DesktopHeight(0)*0.8, "CreateShaderMaterial - [Esc] quit",#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0), WindowHeight(0), 0, 0, 0)

Add3DArchive(#PB_Compiler_Home + "examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3D/Data/Textures/nvidia", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3D/Data/Packs/desert.zip", #PB_3DArchive_Zip)
Add3DArchive(GetCurrentDirectory(), #PB_3DArchive_FileSystem )
Parse3DScripts()

SkyBox("desert07.jpg")

Macro lt(face):LoadTexture(-1,"desert07_"+face+".jpg"):EndMacro
tx_Cubic=CreateCubicTexture(-1,lt("RT"),lt("LF"),lt("UP"),lt("DN"),lt("FR"),lt("BK"))
tx_rock_diff=LoadTexture(-1,"dirt_grayrocky_diffusespecular.jpg")
tx_rock_normal=LoadTexture(-1,"dirt_grayrocky_normalheight.jpg")

CreateCamera(0, 0, 0, 100, 100):MoveCamera(0,0,2,0):CameraLookAt(0,2,0,10)
CreateLight(0, $ffffff, 8000, 5700,4500);  ;light on the sun of the skybox !
AmbientColor($444444)
Fog(0,1,0,1000)

CreateCylinder(0,1.5,2,32,1,1)
CreateCapsule(1,1,1.5)
CreateSphere(2,1.5,32,32)
CreateTorus(3,1.5,0.6,32,32)
CreateCube(4,2.5)

For i=0 To 9
	CreateShaderMaterial(i,#PB_Material_CubicEnvBumpShader)
	MaterialShaderTexture(i,TextureID(tx_Cubic),TextureID(tx_rock_diff),TextureID(tx_rock_normal),0)
	SetMaterialAttribute(i,#PB_Material_TAM,#PB_Material_ClampTAM,0)
	SetMaterialColor(i,3,RGB(128+Random(127),128+Random(127),128+Random(127)))
	MaterialShininess(i,32*Pow(2,Random(5)),$ffffff)
	MaterialShaderParameter(i,#PB_Shader_Fragment,"bumpy",#PB_Shader_Float,Random(3,0)/3,0,0,0)
	MaterialShaderParameter(i,#PB_Shader_Fragment,"glossy",#PB_Shader_Float,Random(3,1)/6,0,0,0)
	CreateEntity(i,MeshID(i%5),MaterialID(i)):RotateEntity(i,Random(360),Random(360),Random(360),#PB_Absolute)
Next

Define.f a,da,r,MouseX,Mousey,depx,depz,dist

Repeat
	While WindowEvent():Wend
	ExamineKeyboard()
	ExamineMouse()
	depx=(-Bool(KeyboardPushed(#PB_Key_Left))+Bool(KeyboardPushed(#PB_Key_Right)))*0.1
	depz=(-Bool(KeyboardPushed(#PB_Key_Down))+Bool(KeyboardPushed(#PB_Key_Up   )))*0.1+MouseWheel()*2
	MouseX = -MouseDeltaX() *  0.05
	MouseY = -MouseDeltaY() *  0.05
	RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
	dist+(depz-dist)*0.05:MoveCamera  (0, depX, 0, -dist)
	da+0.001
	For i=0 To 9
		a.f=i*2*#PI/10+da
		MoveEntity(i,Cos(a)*8,2,Sin(a)*8,#PB_Absolute)
		RotateEntity(i,0.2,0.2,0.2,#PB_Relative)
	Next
	RenderWorld()
	FlipBuffers()    
Until KeyboardReleased(#PB_Key_Escape) Or MouseButton(3)

Code: Select all

;  ----------------------------------------------------------------------------------------------------------
;   CreateShader - Blend textures example
; ----------------------------------------------------------------------------------------------------------

InitEngine3D():InitSprite():InitKeyboard():InitMouse()

ExamineDesktops()
OpenWindow(0, 0,0, DesktopWidth(0)*0.8,DesktopHeight(0)*0.8, "CreateShader - [Esc] quit",#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0), WindowHeight(0), 0, 0, 0)

Add3DArchive(#PB_Compiler_Home + "examples/3D\Data/Textures", #PB_3DArchive_FileSystem)
Parse3DScripts()


CreateCamera(0, 0, 0, 100, 100):MoveCamera(0,0,3,-6):CameraLookAt(0,0,0,0)
CreateLight(0,$ffffff, -10000, 10000, 0)
AmbientColor($111111*5)
CameraBackColor(0,$444488)
Fog(0,1,0,1000)

vert_pg.s="%%%#version 130%%uniform mat4 worldviewproj_matrix;//+24%uniform vec4 camera_pos_os;//+77%uniform vec4 light_pos_os;//+44 0%uniform vec4 light_att;//+41 0%uniform vec4 fog_params;//+31%%varying vec3 oviewdir;%varying vec3 olightdir;%varying vec3 onormal;%varying vec4 ovcolor;%varying float olightatt;%varying vec2 ouv;%%void main()%{%oviewdir=normalize(camera_pos_os.xyz-gl_Vertex.xyz);%olightdir=normalize(light_pos_os.xyz-gl_Vertex.xyz);%gl_Position=worldviewproj_matrix*gl_Vertex;%onormal=gl_Normal;%float Dist=distance(light_pos_os,gl_Vertex);%olightatt=1.0/(light_att.y+light_att.z*Dist+light_att.w*Dist*Dist);%ouv=(gl_TextureMatrix[0]*gl_MultiTexCoord0).xy;%ovcolor=gl_Color;%}%%%%"
frag_pg.s="%%%#version 130%%uniform vec4 diffuse_ml;//+69 0%uniform vec4 specular_ml;//+70 0%uniform vec4 ambient_ml;//+67 0%uniform float shininess;//+36%uniform float blend;//0.5%%uniform sampler2D tx1;//0%uniform sampler2D tx2;//1%%varying vec3 oviewdir;%varying vec3 olightdir;%varying vec3 onormal;%varying vec4 ovcolor;%varying float olightatt;%varying vec2 ouv;%%void main()%{%vec3 normal=normalize(onormal);%vec3 viewdir=normalize(oviewdir);%vec3 lightdir=normalize(olightdir);%%vec4 tcolor=vec4(mix(texture(tx1,ouv),texture(tx2,ouv),blend))*ovcolor;%%float dif=max(dot(lightdir,normal),0)*olightatt;%float spe=pow(max(dot(normalize(lightdir+viewdir),normal),0),shininess);%gl_FragColor=vec4(tcolor.rgb,1)*(ambient_ml+diffuse_ml*dif)+specular_ml*tcolor.a*spe;%}%%%"

CreateShader(0,vert_pg,frag_pg)
CreateShaderMaterial(0,0)
LoadTexture(0, "mramor6x6.jpg")
LoadTexture(1,"soil_wall.jpg")  
MaterialShaderTexture(0,TextureID(0),TextureID(1),0,0)
MaterialShininess(0,64,$ffffff)
ScaleMaterial(0,0.125,0.5)
MaterialFilteringMode(0,#PB_Material_Anisotropic)
CreateTorus(0,2,1,32,32)
CreateEntity(0,MeshID(0),MaterialID(0))


Define.f MouseX,Mousey,depx,depz,dist,val,blend

Repeat
	While WindowEvent():Wend
	ExamineKeyboard()
	ExamineMouse()
	RotateEntity(0,0.2,0.2,0.2, #PB_Relative)
	
	val+0.02:blend=(Sin(val)+1)/2
	MaterialShaderParameter(0,1,"blend",1,blend,0,0,0)
	
	RenderWorld()
	FlipBuffers()    
Until KeyboardReleased(#PB_Key_Escape) Or MouseButton(3)

Code: Select all

; ----------------------------------------------------------------------------------------------------------
;   CreateShaderMaterial - #PB_Material_CubicEnvBumpShader   -   Environment mapping
; ----------------------------------------------------------------------------------------------------------
#PB_Material_CubicEnvBumpShader=$10009

Define.f a,da,r,MouseX,Mousey,depx,depz,dist

InitEngine3D():InitSprite():InitKeyboard():InitMouse()

ExamineDesktops()
OpenWindow(0, 0,0, DesktopWidth(0)*0.8,DesktopHeight(0)*0.8, "Environment mapping - [Esc] quit",#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0), WindowHeight(0), 0, 0, 0)

Add3DArchive(#PB_Compiler_Home + "examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3D/Data/Textures/nvidia", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3D/Data/Packs/desert.zip", #PB_3DArchive_Zip)
Add3DArchive(GetCurrentDirectory(), #PB_3DArchive_FileSystem )
Parse3DScripts()

SkyBox("desert07.jpg")
CreateCamera(0, 0, 0, 100, 100):MoveCamera(0,0,2,0):CameraLookAt(0,0,0,10)
CreateLight(0, $ffffff, 8000, 5700,4500);  ;light on the sun of the skybox !
AmbientColor($444444)
Fog(0,1,0,1000)

; Ground
LoadTexture(0, "MRAMOR6X6.jpg")
CreateMaterial(0,TextureID(0))
CreatePlane(0,256,256,1,1,32,32)
CreateEntity(0,MeshID(0),MaterialID(0))

; objects
CreateSphere(0,1.5,32,32)
CreateCapsule(1,1,1.5)
CreateCylinder(2,1.5,2,32,1,1)
CreateTorus(3,1.5,0.6,32,32)
CreateCube(4,2.5)

tx_rock_diff=LoadTexture(-1,"dirt_grayrocky_diffusespecular.jpg")
tx_rock_normal=LoadTexture(-1,"dirt_grayrocky_normalheight.jpg")

Dim tx_Cubic(50)

For j=0 To 6
	For i=0 To 6
		c+1
		CreateShaderMaterial(c,#PB_Material_CubicEnvBumpShader)
		tx_Cubic(c) = CreateCubeMapTexture(#PB_Any, 512,#PB_Texture_ManualUpdate, "")
		MaterialShaderTexture(c,TextureID(tx_Cubic(c)),TextureID(tx_rock_diff),TextureID(tx_rock_normal),0)
		SetMaterialAttribute(c,#PB_Material_TAM,#PB_Material_ClampTAM,0)
		SetMaterialColor(c,3,RGBA(127*Random(2),127*Random(2),127*Random(2),0))
		MaterialShaderParameter(c,1,"bumpy",1,  Random(1,0)*0.2,0,0,0)
		MaterialShaderParameter(c,1,"glossy",1, Random(2,1)*0.2,0,0,0)
		CreateEntity(c,MeshID(c%5),MaterialID(c), (i-3)*8,2,(j-3)*8)
		RotateEntity(c,Random(360),Random(360),Random(360),#PB_Absolute)
		EntityCubeMapTexture(tx_Cubic(c), c)  ; <- associate the entity to position the cubic texture
	Next
Next

; get the cubic texture (2 pass for better result)
For j=0 To 1
	For i=1 To c
		UpdateRenderTexture(tx_Cubic(i))
	Next
Next

; apply the ground reflection
CreateCamera(1,0,0,100,100)
CreateRenderTexture(1,CameraID(1),ScreenWidth()/1,ScreenHeight()/1)
AddMaterialLayer(0,TextureID(1),#PB_Material_ModulateX2)
SetMaterialAttribute(0,#PB_Material_ProjectiveTexturing,1,1)

Repeat
	While WindowEvent():Wend
	ExamineKeyboard()
	ExamineMouse()
	depx=(-Bool(KeyboardPushed(#PB_Key_Left))+Bool(KeyboardPushed(#PB_Key_Right)))*0.1
	depz=(-Bool(KeyboardPushed(#PB_Key_Down))+Bool(KeyboardPushed(#PB_Key_Up   )))*0.1+MouseWheel()*2
	MouseX = -MouseDeltaX() *  0.05
	MouseY = -MouseDeltaY() *  0.05
	RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
	dist+(depz-dist)*0.05:MoveCamera  (0, depX, 0, -dist)
	CameraReflection(1,0,EntityID(0))
	RenderWorld()
	FlipBuffers()    
Until KeyboardReleased(#PB_Key_Escape) Or MouseButton(3)

Code: Select all

;  ----------------------------------------------------------------------------------------------------------
;   CreateShaderMaterial - #PB_Material_PerpixelShader, corrected version
; ----------------------------------------------------------------------------------------------------------

InitEngine3D():InitSprite():InitKeyboard():InitMouse()

ExamineDesktops()
OpenWindow(0, 0,0, DesktopWidth(0)*0.8,DesktopHeight(0)*0.8, "CreateShader - [Esc] quit",#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0), WindowHeight(0), 0, 0, 0)

Add3DArchive(#PB_Compiler_Home + "examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(GetCurrentDirectory(), #PB_3DArchive_FileSystem )
Parse3DScripts()


CreateCamera(0, 0, 0, 100, 100):MoveCamera(0,0,3,-6):CameraLookAt(0,0,0,0)
CreateLight(0,$ffffff, -10000, 10000, 0)
AmbientColor($111111*5)
CameraBackColor(0,$444488)
Fog(0,1,0,1000)

; CreateShaderMaterial(0,#PB_Material_PerpixelShader) may have a black shading defect, use this code instead
vert_pg.s="%#version 130%%uniform mat4 P24;//+24%uniform vec4 P77;//+77%uniform vec4 P44;//+44 0%uniform vec4 P41;//+41 0%uniform vec4 P31;//+31%%varying vec3 oviewdir;%varying vec3 olightdir;%varying vec3 onormal;%varying vec4 ovcolor;%varying float olightatt;%varying vec2 ouv;%varying float ofogf;%%void main()%{%oviewdir=normalize(P77.xyz-gl_Vertex.xyz);%olightdir=normalize(P44.xyz-gl_Vertex.xyz);%gl_Position=P24*gl_Vertex;%onormal=gl_Normal;%float Dist=distance(P44,gl_Vertex);%olightatt=1.0/(P41.y+P41.z*Dist+P41.w*Dist*Dist);%ouv=(gl_TextureMatrix[0]*gl_MultiTexCoord0).xy;%ovcolor=gl_Color;%if(P31.z>0)ofogf=min(gl_Position.z*P31.w,1);%}%%"
frag_pg.s="%#version 130%%uniform vec4 P69;//+69 0%uniform vec4 P70;//+70 0%uniform vec4 P67;//+67 0%uniform float P36;//+36%uniform vec4 P30;//+30%%uniform sampler2D diffuseMap;//0%%varying vec3 oviewdir;%varying vec3 olightdir;%varying vec3 onormal;%varying vec4 ovcolor;%varying float olightatt;%varying vec2 ouv;%varying float ofogf;%%void main()%{%vec3 normal=normalize(onormal);%vec3 viewdir=normalize(oviewdir);%vec3 lightdir=normalize(olightdir);%%vec4 tcolor=vec4(texture(diffuseMap,ouv))*ovcolor;%%float dif=max(dot(lightdir,normal),0)*olightatt;%float spe=pow(max(dot(normalize(lightdir+viewdir),normal),0),P36);%vec4 color=vec4(tcolor.rgb,1)*(P67+P69*dif)+P70*tcolor.a*spe;%gl_FragColor=mix(color,P30,ofogf);%}%"
CreateShader(0,vert_pg,frag_pg)
CreateShaderMaterial(0,0)

LoadTexture(0,"soil_wall.jpg")  
MaterialShaderTexture(0,TextureID(0),0,0,0)
MaterialShininess(0,64,$ffffff)
ScaleMaterial(0,0.125,0.5)
MaterialFilteringMode(0,#PB_Material_Anisotropic)
CreateTorus(0,2,1,32,32)
CreateEntity(0,MeshID(0),MaterialID(0))

Define.f MouseX,Mousey,depx,depz,dist,val,blend

Repeat
	While WindowEvent():Wend
	ExamineKeyboard()
	ExamineMouse()
	RotateEntity(0,0.2,0.2,0.2, #PB_Relative)	
	RenderWorld()
	FlipBuffers()    
Until KeyboardReleased(#PB_Key_Escape) Or MouseButton(3)

Code: Select all

;  ----------------------------------------------------------------------------------------------------------
;   CreateShaderMaterial - #PB_Material_ColorShader, corrected version
; ----------------------------------------------------------------------------------------------------------

InitEngine3D():InitSprite():InitKeyboard():InitMouse()

ExamineDesktops()
OpenWindow(0, 0,0, DesktopWidth(0)*0.8,DesktopHeight(0)*0.8, "CreateShader - [Esc] quit",#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0), WindowHeight(0), 0, 0, 0)

CreateCamera(0, 0, 0, 100, 100):MoveCamera(0,0,3,-6):CameraLookAt(0,0,0,0)
CreateLight(0,$ffffff, -10000, 10000, 0)
AmbientColor($111111*5)
CameraBackColor(0,$444488)
Fog(0,1,0,1000)

; CreateShaderMaterial(0,#PB_Material_ColorShader) may have a black shading defect, use this code instead
vert_pg.s="%%#version 130%%uniform mat4 worldviewproj_matrix;//+24%uniform vec4 camera_pos_os;//+77%uniform vec4 light_pos_os;//+44 0%uniform vec4 light_att;//+41 0%uniform vec4 fog_params;//+31%%varying vec3 oviewdir;%varying vec3 olightdir;%varying vec3 onormal;%varying vec4 ovcolor;%varying float olightatt;%varying float ofogf;%%void main()%{%oviewdir = normalize(camera_pos_os.xyz - gl_Vertex.xyz);%olightdir = normalize(light_pos_os.xyz - gl_Vertex.xyz);%gl_Position = worldviewproj_matrix * gl_Vertex;%onormal = gl_Normal;%float Dist = distance(light_pos_os,gl_Vertex);%olightatt = 1/(light_att.y + light_att.z * Dist + light_att.w * Dist * Dist);%ovcolor = gl_Color;%if (fog_params.z > 0) ofogf = min(gl_Position.z * fog_params.w,1);%}%%%%%%"
frag_pg.s="%%#version 130%%uniform vec4 diffuse_ml;//+69 0%uniform vec4 specular_ml;//+70 0%uniform vec4 ambient_ml;//+67 0%uniform float shininess;//+36%uniform vec4 fog_colour;//+30%%varying vec3 oviewdir;%varying vec3 olightdir;%varying vec3 onormal;%varying vec4 ovcolor;%varying float olightatt;%varying float ofogf;%%void main()%{%vec3 normal=normalize(onormal);%vec3 viewdir=normalize(oviewdir);%vec3 lightdir=normalize(olightdir);%float dif=max(dot(lightdir, normal), 0)*olightatt;%float spe=pow(max(dot(normalize(lightdir + viewdir), normal),0),shininess);%vec4 color=(ambient_ml + diffuse_ml * dif) + specular_ml* spe;%gl_FragColor=mix(color ,fog_colour, ofogf);%}%%%%%%"
CreateShader(0,vert_pg,frag_pg)
CreateShaderMaterial(0,0)
SetMaterialColor(0,#PB_Material_AmbientColor|#PB_Material_DiffuseColor,$ff)
MaterialShininess(0,64,$ffffff)

CreateTorus(0,2,1,32,32)
CreateEntity(0,MeshID(0),MaterialID(0))

Define.f MouseX,Mousey,depx,depz,dist,val,blend

Repeat
	While WindowEvent():Wend
	ExamineKeyboard()
	ExamineMouse()
	RotateEntity(0,0.2,0.2,0.2, #PB_Relative)	
	RenderWorld()
	FlipBuffers()    
Until KeyboardReleased(#PB_Key_Escape) Or MouseButton(3)
Last edited by pf shadoko on Tue Mar 21, 2023 6:58 am, edited 2 times in total.
User avatar
DK_PETER
Addict
Addict
Posts: 898
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: PB 6.00 - 3D Examples - Shaders <<< Fixed >>>

Post by DK_PETER »

Hi

All examples works using PB 6.01 LTS.
Best regards
Peter
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: PB 6.00 - 3D Examples - Shaders <<< Fixed >>>

Post by mk-soft »

Texture folders for linux must be change ...
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Caronte3D
Addict
Addict
Posts: 1027
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: PB 6.00 - 3D Examples - Shaders <<< Fixed >>>

Post by Caronte3D »

Yeah! All examples woks nice! PB 6.01 LTS x86 Windows10
Thanks!
User avatar
idle
Always Here
Always Here
Posts: 5042
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: PB 6.00 - 3D Examples - Shaders <<< Fixed >>>

Post by idle »

last one CreateShaderMaterial, I get a red torus with black on it, is that right?
User avatar
pf shadoko
Enthusiast
Enthusiast
Posts: 285
Joined: Thu Jul 09, 2015 9:07 am

Re: PB 6.00 - 3D Examples - Shaders <<< Fixed >>>

Post by pf shadoko »

@idle :
oops, I forgot to correct that one, well seen
now is it good ?
User avatar
idle
Always Here
Always Here
Posts: 5042
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: PB 6.00 - 3D Examples - Shaders <<< Fixed >>>

Post by idle »

yes, that's working now thanks.
User avatar
Caronte3D
Addict
Addict
Posts: 1027
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: PB 6.00 - 3D Examples - Shaders <<< Fixed >>>

Post by Caronte3D »

I was think that was part of the shader effect :lol:
Post Reply