PB 6.00 - Shader test

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

PB 6.00 - Shader test

Post by pf shadoko »

Hi,

The new shaders functions don't seem to work on all the machines
I would like to know if the bug is frequent or rare
can you test the following program and just tell me if the result seems to be correct
it's a simple fade between 2 textures (in perpixel)

Code: Select all

InitEngine3D(#PB_Engine3D_DebugLog):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*3)
CameraBackColor(0,$444488)

vert_pg.s="%%#version 120%%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 120%%uniform vec4 P69;//+69 0%uniform vec4 P70;//+70 0%uniform vec4 P67;//+67 0%uniform float P36;//+36%uniform vec4 P30;//+30%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;%varying float ofogf;%%void main()%{%vec3 normal=normalize(onormal);%vec3 viewdir=normalize(oviewdir);%vec3 lightdir=normalize(olightdir);%%vec4 tcolor=vec4(mix(texture2D(tx1,ouv),texture2D(tx2,ouv),blend))*ovcolor;%%float dif=max(dot(lightdir,normal),0)*olightatt;%float spe=pow(dot(normalize(lightdir+viewdir),normal),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")
LoadTexture(01,"MRAMOR6X6.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)
box_80
Enthusiast
Enthusiast
Posts: 115
Joined: Mon Sep 03, 2012 8:52 pm

Re: PB 6.00 - Shader test

Post by box_80 »

Seem to work with my old GeForece 8400 GS graphic card.
User avatar
Caronte3D
Addict
Addict
Posts: 1355
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: PB 6.00 - Shader test

Post by Caronte3D »

Works on my laptop but has some glitches (faces on the shsdow zone blinking some times).
Win10 - NVIDIA GFORCE MX250
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1282
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: PB 6.00 - Shader test

Post by Paul »

Fails with DirectX9 and DirectX11.
Default OpenGL seems to work and I see two different textures fading back and forth but the light and shadow doesn't seem correct. Can't tell if the results are correct without knowing what it is suppose to look like.
Maybe you could post a video of what it should look like so we have something to compare to?

(GeForce RTX2070 SUPER / 516.59 Game Drivers)
Image Image
User avatar
DK_PETER
Addict
Addict
Posts: 904
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: PB 6.00 - Shader test

Post by DK_PETER »

I just tested your shader example.
Works on Ubuntu and Windows 10.
Linux is strict with paths - must be : "examples/3d/Data/Textures"

Example works but it shows a white artifact and pitch dark shadow (Both OS)
Changing any parameter (it doesn't matter which one) fixes the artifact and pitch black shadow. :)
So I can't tell you why it works or what's happening.

Before changing any parameter:
https://ibb.co/YX94svK

Edit: By any parameter I mean the first one:

Code: Select all

vert_pg.s="%%#version 120%%uniform mat4 P24(<-this one);//+24(<-not this one)%uniform vec4 P77;//+77%uniform....

Anyway. Great work.
Configuration in signature:
Last edited by DK_PETER on Sat Jul 16, 2022 1:55 pm, edited 1 time in total.
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.
juergenkulow
Enthusiast
Enthusiast
Posts: 581
Joined: Wed Sep 25, 2019 10:18 am

Re: PB 6.00 - Shader test

Post by juergenkulow »

If you insert a Delay(100) after FlipBuffers(), then you can see the artifacts in slow motion.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: PB 6.00 - Shader test

Post by Psychophanta »

Wow, you seem to try to write in position 0. So, invalid memory error here in a ATI
:o
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
DeanH
Enthusiast
Enthusiast
Posts: 274
Joined: Wed May 07, 2008 4:57 am
Location: Adelaide, South Australia
Contact:

Re: PB 6.00 - Shader test

Post by DeanH »

Very impressive! Just tested it on a 4 yr old HP 600 desktop at work. (Win 10 21H2.) Some rectangles flicker when the ring is face on. Do not see it happen when edge on. 64-bit PB 6.
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: PB 6.00 - Shader test

Post by fsw »

Works on a MacBook with Apple Silicon as well.

Replace this:

Code: Select all

Add3DArchive(#PB_Compiler_Home + "examples\3D\Data\Textures", #PB_3DArchive_FileSystem)
with this:

Code: Select all

CompilerIf #PB_Compiler_OS = #PB_OS_MacOS Or #PB_Compiler_OS = #PB_OS_Linux
        ; on macOS #PB_Compiler_Home = /Applications/PureBasic.app/Contents/Resources/
        Add3DArchive(#PB_Compiler_Home + "examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
CompilerElseIf #PB_Compiler_OS = #PB_OS_Windows
        Add3DArchive(#PB_Compiler_Home + "examples\3D\Data\Textures", #PB_3DArchive_FileSystem)
CompilerElse
        MessageRequester("ERROR", "Operating system was not recognized!" + #CRLF$ + "Maybe it's Haiku OS... :P")
        End
CompilerEndIf
Done.

I am to provide the public with beneficial shocks.
Alfred Hitshock
User avatar
pf shadoko
Enthusiast
Enthusiast
Posts: 385
Joined: Thu Jul 09, 2015 9:07 am

Re: PB 6.00 - Shader test

Post by pf shadoko »

thank you for your answers

damn! I'm obviously the only one (or almost) where it works
(I don't have another machine at my disposal, so it will be complicated to solve the problem... but with your help I will find it)

can you look at the file 'Ogre.log' (cf manual :InitEngine3D) ?
if it ends with :
"Can't assign material Torus to SubEntity of E0 because this Material does not exist. Have you forgotten to define it in a .material script?"
I'm not interested
but if you have lines after that, post them

@ paul :
3D is now only opengl (default system)

@ DK_PETER :
thanks for the screenshot
I think your modification makes the shader crash, the display goes to default mode (fixed pipeline), that's why the display looks good, but without fading (and without perpixel)

@ fsw :
good point
but we can just replace all the "\" by "/", it works under windows too !
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1282
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: PB 6.00 - Shader test

Post by Paul »

pf shadoko wrote: Tue Jul 19, 2022 3:27 pm @ paul :
3D is now only opengl (default system)
Too bad, 3D use to look great on Windows with nVidia using DirectX, where OpenGL was always sketchy. Textures were messed up, shadows didn't work properly or were completely black.

Now being stuck with OpenGL only, I'm forced to view bad textures and shadows.
For me, without DirectX the 3D is no longer usable. :cry:
Image Image
box_80
Enthusiast
Enthusiast
Posts: 115
Joined: Mon Sep 03, 2012 8:52 pm

Re: PB 6.00 - Shader test

Post by box_80 »

When looking at it again. There is a small imperfection. Kind hope it was something minor to fix, but more it think about it. It probability a glitch. Have to change my opinion to not working perfectly.
User avatar
DK_PETER
Addict
Addict
Posts: 904
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: PB 6.00 - Shader test

Post by DK_PETER »

@Shadoko
Agreed. I crash the shader and it reverts automatically to 'normal'.

The debug logfile shows no other lines after the one you mentioned. (Ubuntu and Windows 10 both)

Here's an animated gif of the torus:

https://www.dropbox.com/s/njajg3swgudnm ... f.gif?dl=0
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
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: PB 6.00 - Shader test

Post by Psychophanta »

Psychophanta wrote: Sun Jul 17, 2022 8:36 pm Wow, you seem to try to write in position 0. So, invalid memory error here in a ATI
:o
Bump and beware:
Not even compiles in some computers from 2017. :shock:
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
SPH
Enthusiast
Enthusiast
Posts: 561
Joined: Tue Jan 04, 2011 6:21 pm

Re: PB 6.00 - Shader test

Post by SPH »

Fonctionne impec sur an old computer !

beautyful

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 6.12LTS - 64 bits
Post Reply