Page 1 of 2

PB 6.00 - Shader test

Posted: Tue Jul 12, 2022 12:12 pm
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)

Re: PB 6.00 - Shader test

Posted: Thu Jul 14, 2022 5:04 pm
by box_80
Seem to work with my old GeForece 8400 GS graphic card.

Re: PB 6.00 - Shader test

Posted: Thu Jul 14, 2022 10:04 pm
by Caronte3D
Works on my laptop but has some glitches (faces on the shsdow zone blinking some times).
Win10 - NVIDIA GFORCE MX250

Re: PB 6.00 - Shader test

Posted: Fri Jul 15, 2022 2:16 am
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)

Re: PB 6.00 - Shader test

Posted: Fri Jul 15, 2022 10:10 pm
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:

Re: PB 6.00 - Shader test

Posted: Sat Jul 16, 2022 6:06 am
by juergenkulow
If you insert a Delay(100) after FlipBuffers(), then you can see the artifacts in slow motion.

Re: PB 6.00 - Shader test

Posted: Sun Jul 17, 2022 8:36 pm
by Psychophanta
Wow, you seem to try to write in position 0. So, invalid memory error here in a ATI
:o

Re: PB 6.00 - Shader test

Posted: Sun Jul 17, 2022 11:52 pm
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.

Re: PB 6.00 - Shader test

Posted: Tue Jul 19, 2022 12:17 am
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.

Re: PB 6.00 - Shader test

Posted: Tue Jul 19, 2022 3:27 pm
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 !

Re: PB 6.00 - Shader test

Posted: Tue Jul 19, 2022 4:29 pm
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:

Re: PB 6.00 - Shader test

Posted: Tue Jul 19, 2022 10:30 pm
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.

Re: PB 6.00 - Shader test

Posted: Wed Jul 20, 2022 10:58 am
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

Re: PB 6.00 - Shader test

Posted: Thu Jul 21, 2022 11:43 am
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:

Re: PB 6.00 - Shader test

Posted: Sun Jul 31, 2022 9:03 pm
by SPH
Fonctionne impec sur an old computer !

beautyful