PB 6.00 - Exemples 3D - Shaders <<< Corrigés >>>

Généralités sur la programmation 3D
Avatar de l’utilisateur
Guillot
Messages : 672
Inscription : jeu. 25/juin/2015 16:18

PB 6.00 - Exemples 3D - Shaders <<< Corrigés >>>

Message par Guillot »

j'espère que ça marchera pour tout le monde cette foi !
la dernières version d'opengl (4.6) étant plus pointilleuse, la plupart bug si on ne définit pas le "fog", je l'ai donc ajouté au exemple
#PB_Material_ColorShader et #PB_Material_PerpixelShader peuvent présenter un défaut d'ombrage noir.
#PB_Material_PointSpriteSphereShader peut planter
pour ces 3, j' ai mis un exemple réécrit (avec CreateShadfer)

Code : Tout sélectionner

;  ----------------------------------------------------------------------------------------------------------
;   CreateShaderMaterial - #PB_Material_PointSpriteSphereShader , version corrigée
; ----------------------------------------------------------------------------------------------------------

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 : Tout sélectionner

;  ----------------------------------------------------------------------------------------------------------
;   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 : Tout sélectionner

;  ----------------------------------------------------------------------------------------------------------
;   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)
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)

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 : Tout sélectionner

; ----------------------------------------------------------------------------------------------------------
;   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 : Tout sélectionner

;  ----------------------------------------------------------------------------------------------------------
;   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 : Tout sélectionner

;  ----------------------------------------------------------------------------------------------------------
;   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(dot(normalize(lightdir + viewdir), normal),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)
Dernière modification par Guillot le dim. 19/mars/2023 11:13, modifié 5 fois.
Avatar de l’utilisateur
falsam
Messages : 7317
Inscription : dim. 22/août/2010 15:24
Localisation : IDF (Yvelines)
Contact :

Re: PB 6.00 - Exemples 3D - Shaders <<< Corrigés >>>

Message par falsam »

Hello Guillot.

Test des quatre codes. Cette fois çi c'est parfait. Bravo.
Configuration : Windows 11 Famille 64-bit - PB 6.20 x64 - AMD Ryzen 7 - 16 GO RAM
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
Avatar de l’utilisateur
SPH
Messages : 4937
Inscription : mer. 09/nov./2005 9:53

Re: PB 6.00 - Exemples 3D - Shaders <<< Corrigés >>>

Message par SPH »

Heu, le 3eme code fait une ombre un peu bizarre sur le tore.

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Intel Core i7 4770 64 bits - GTX 650 Ti
Version de PB : 6.12LTS- 64 bits
Avatar de l’utilisateur
Guillot
Messages : 672
Inscription : jeu. 25/juin/2015 16:18

Re: PB 6.00 - Exemples 3D - Shaders <<< Corrigés >>>

Message par Guillot »

merde !

j'ai fais une petite modif sur le 3e code, tu peux retester et me dire si c'est OK ?
sinon tu peux me mettre une copie d'ecran (est ce que la transition entre texture fonctionne ?)
et me donner ta version opengl
pour ça falsam à donner un petit code:

Code : Tout sélectionner

; Source : https://www.khronos.org/registry/OpenGL-Refpages/es2.0/xhtml/glGetString.xml
OpenWindow(#PB_Any, 0, 0, 0, 0, "",#PB_Window_Invisible)
OpenGLGadget(#PB_Any, 0, 0, 0, 0)

Debug "OpenGL Version : " + PeekS(glGetString_(#GL_VERSION), -1, #PB_UTF8)
Debug "Vendor : " + PeekS(glGetString_(#GL_VENDOR), -1, #PB_UTF8)
Debug "Vidéo Card : " + PeekS(glGetString_(#GL_RENDERER), -1, #PB_UTF8)
Avatar de l’utilisateur
SPH
Messages : 4937
Inscription : mer. 09/nov./2005 9:53

Re: PB 6.00 - Exemples 3D - Shaders <<< Corrigés >>>

Message par SPH »

Code 3 :
Image

Même "problème". Ce n'est pas "moche" mais je ne pense pas que tu l'as fais exprès.

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Intel Core i7 4770 64 bits - GTX 650 Ti
Version de PB : 6.12LTS- 64 bits
Avatar de l’utilisateur
Guillot
Messages : 672
Inscription : jeu. 25/juin/2015 16:18

Re: PB 6.00 - Exemples 3D - Shaders <<< Corrigés >>>

Message par Guillot »

merci pour ton aide
effectivement c'est bien un défaut l'ombrage noir en dessous du torre
j'ai fait des modifs, si tu peux tester, me dire si tu as toujours le probleme
si oui, peux tu m'envoyer le contenu du débogueur ?
(si tu enregistre le code préalablement, le débogueur pourra te donner plus d'info en cas de probleme de compilation du shader)

Code : Tout sélectionner

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

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)
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*8)
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(dot(normalize(lightdir+viewdir),normal),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)
DisableMaterialLighting(0,1)

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)
; ------------------------------------------------------------- info debug
fic.s=GetCurrentDirectory()+"Ogre"
CopyFile(fic+".log", fic+".tmp") 
If ReadFile(0,fic+".tmp",#PB_File_SharedRead)
  log.s=ReadString(0,#PB_File_IgnoreEOL)
  CloseFile(0)
  p=FindString(log,"sh0VPERROR"):If p:Debug  Mid(log,p-100,400):Debug "----------------------------":EndIf
  p=FindString(log,"sh0FPERROR"):If p:Debug  Mid(log,p-100,400):Debug "----------------------------":EndIf
EndIf
OpenWindow(1, 0, 0, 0, 0, "",#PB_Window_Invisible)
OpenGLGadget(1, 0, 0, 0, 0)
Debug "OpenGL Version : " + PeekS(glGetString_(#GL_VERSION), -1, #PB_UTF8)
Debug "Vendor : " + PeekS(glGetString_(#GL_VENDOR), -1, #PB_UTF8)
Debug "Vidéo Card : " + PeekS(glGetString_(#GL_RENDERER), -1, #PB_UTF8)
Avatar de l’utilisateur
falsam
Messages : 7317
Inscription : dim. 22/août/2010 15:24
Localisation : IDF (Yvelines)
Contact :

Re: PB 6.00 - Exemples 3D - Shaders <<< Corrigés >>>

Message par falsam »

Tes premiers codes étaient parfaits. Par contre voila ce que donne ton dernier code que tu veux faire tester à SPH.

Image

Log OGRE3D
10:59:28: Creating resource group General
10:59:28: Creating resource group Internal
10:59:28: Creating resource group Autodetect
10:59:28: SceneManagerFactory for type 'DefaultSceneManager' registered.
10:59:28: Registering ResourceManager for type Material
10:59:28: Registering ResourceManager for type Mesh
10:59:28: Registering ResourceManager for type Skeleton
10:59:28: MovableObjectFactory for type 'ParticleSystem' registered.
10:59:28: OverlayElementFactory for type Panel registered.
10:59:28: OverlayElementFactory for type BorderPanel registered.
10:59:28: OverlayElementFactory for type TextArea registered.
10:59:28: Registering ResourceManager for type Font
10:59:28: ArchiveFactory for archive type FileSystem registered.
10:59:28: ArchiveFactory for archive type Zip registered.
10:59:28: ArchiveFactory for archive type EmbeddedZip registered.
10:59:28: DDS codec registering
10:59:28: FreeImage version: 3.10.0
10:59:28: This program uses FreeImage, a free, open source image library supporting all common bitmap formats. See http://freeimage.sourceforge.net for details
10:59:28: Supported formats: bmp,ico,jpg,jif,jpeg,jpe,koa,iff,lbm,pbm,pbm,pcd,pcx,pgm,pgm,png,ppm,ppm,ras,tga,targa,tif,tiff,wap,wbmp,wbm,psd,cut,xbm,xpm,dds,gif,g3,sgi,j2k,j2c,jp2
10:59:28: PVRTC codec registering
10:59:28: Registering ResourceManager for type HighLevelGpuProgram
10:59:28: Registering ResourceManager for type Compositor
10:59:28: MovableObjectFactory for type 'Entity' registered.
10:59:28: MovableObjectFactory for type 'Light' registered.
10:59:28: MovableObjectFactory for type 'BillboardSet' registered.
10:59:28: MovableObjectFactory for type 'ManualObject' registered.
10:59:28: MovableObjectFactory for type 'BillboardChain' registered.
10:59:28: MovableObjectFactory for type 'RibbonTrail' registered.
10:59:28: *-*-* OGRE Initialising
10:59:28: *-*-* Version 1.8.2 (Byatis)
10:59:28: OpenGL Rendering Subsystem created.
10:59:28: Particle Emitter Type 'Point' registered
10:59:28: Particle Emitter Type 'Box' registered
10:59:28: Particle Emitter Type 'Ellipsoid' registered
10:59:28: Particle Emitter Type 'Cylinder' registered
10:59:28: Particle Emitter Type 'Ring' registered
10:59:28: Particle Emitter Type 'HollowEllipsoid' registered
10:59:28: Particle Affector Type 'LinearForce' registered
10:59:28: Particle Affector Type 'ColourFader' registered
10:59:28: Particle Affector Type 'ColourFader2' registered
10:59:28: Particle Affector Type 'ColourImage' registered
10:59:28: Particle Affector Type 'ColourInterpolator' registered
10:59:28: Particle Affector Type 'Scaler' registered
10:59:28: Particle Affector Type 'Rotator' registered
10:59:28: Particle Affector Type 'DirectionRandomiser' registered
10:59:28: Particle Affector Type 'DeflectorPlane' registered
10:59:28: PCZone Factory Type 'ZoneType_Default' registered
10:59:28: CPU Identifier & Features
10:59:28: -------------------------
10:59:28: * CPU ID: AuthenticAMD: AMD Ryzen 7 4800H with Radeon Graphics
10:59:28: * SSE: yes
10:59:28: * SSE2: yes
10:59:28: * SSE3: yes
10:59:28: * MMX: yes
10:59:28: * MMXEXT: yes
10:59:28: * 3DNOW: no
10:59:28: * 3DNOWEXT: no
10:59:28: * CMOV: yes
10:59:28: * TSC: yes
10:59:28: * FPU: yes
10:59:28: * PRO: yes
10:59:28: * HT: no
10:59:28: -------------------------
10:59:28: *** Starting Win32GL Subsystem ***
10:59:28: Registering ResourceManager for type Texture
10:59:28: SceneManagerFactory for type 'OctreeSceneManager' registered.
10:59:28: SceneManagerFactory for type 'BspSceneManager' registered.
10:59:28: Registering ResourceManager for type BspLevel
10:59:28: GLRenderSystem::_createRenderWindow "PureBasic Ogre", 480x270 windowed miscParams: FSAA=0 displayFrequency=0 externalWindowHandle=13305218 vsync=true
10:59:28: GL_VERSION = 4.6.0 NVIDIA 451.67
10:59:28: GL_VENDOR = NVIDIA Corporation
10:59:28: GL_RENDERER = GeForce GTX 1650 Ti/PCIe/SSE2
10:59:28: GL_EXTENSIONS = GL_AMD_multi_draw_indirect GL_AMD_seamless_cubemap_per_texture GL_AMD_vertex_shader_viewport_index GL_AMD_vertex_shader_layer GL_ARB_arrays_of_arrays GL_ARB_base_instance GL_ARB_bindless_texture GL_ARB_blend_func_extended GL_ARB_buffer_storage GL_ARB_clear_buffer_object GL_ARB_clear_texture GL_ARB_clip_control GL_ARB_color_buffer_float GL_ARB_compatibility GL_ARB_compressed_texture_pixel_storage GL_ARB_conservative_depth GL_ARB_compute_shader GL_ARB_compute_variable_group_size GL_ARB_conditional_render_inverted GL_ARB_copy_buffer GL_ARB_copy_image GL_ARB_cull_distance GL_ARB_debug_output GL_ARB_depth_buffer_float GL_ARB_depth_clamp GL_ARB_depth_texture GL_ARB_derivative_control GL_ARB_direct_state_access GL_ARB_draw_buffers GL_ARB_draw_buffers_blend GL_ARB_draw_indirect GL_ARB_draw_elements_base_vertex GL_ARB_draw_instanced GL_ARB_enhanced_layouts GL_ARB_ES2_compatibility GL_ARB_ES3_compatibility GL_ARB_ES3_1_compatibility GL_ARB_ES3_2_compatibility GL_ARB_explicit_attrib_location GL_ARB_explicit_uniform_location GL_ARB_fragment_coord_conventions GL_ARB_fragment_layer_viewport GL_ARB_fragment_program GL_ARB_fragment_program_shadow GL_ARB_fragment_shader GL_ARB_fragment_shader_interlock GL_ARB_framebuffer_no_attachments GL_ARB_framebuffer_object GL_ARB_framebuffer_sRGB GL_ARB_geometry_shader4 GL_ARB_get_program_binary GL_ARB_get_texture_sub_image GL_ARB_gl_spirv GL_ARB_gpu_shader5 GL_ARB_gpu_shader_fp64 GL_ARB_gpu_shader_int64 GL_ARB_half_float_pixel GL_ARB_half_float_vertex GL_ARB_imaging GL_ARB_indirect_parameters GL_ARB_instanced_arrays GL_ARB_internalformat_query GL_ARB_internalformat_query2 GL_ARB_invalidate_subdata GL_ARB_map_buffer_alignment GL_ARB_map_buffer_range GL_ARB_multi_bind GL_ARB_multi_draw_indirect GL_ARB_multisample GL_ARB_multitexture GL_ARB_occlusion_query GL_ARB_occlusion_query2 GL_ARB_parallel_shader_compile GL_ARB_pipeline_statistics_query GL_ARB_pixel_buffer_object GL_ARB_point_parameters GL_ARB_point_sprite GL_ARB_polygon_offset_clamp GL_ARB_post_depth_coverage GL_ARB_program_interface_query GL_ARB_provoking_vertex GL_ARB_query_buffer_object GL_ARB_robust_buffer_access_behavior GL_ARB_robustness GL_ARB_sample_locations GL_ARB_sample_shading GL_ARB_sampler_objects GL_ARB_seamless_cube_map GL_ARB_seamless_cubemap_per_texture GL_ARB_separate_shader_objects GL_ARB_shader_atomic_counter_ops GL_ARB_shader_atomic_counters GL_ARB_shader_ballot GL_ARB_shader_bit_encoding GL_ARB_shader_clock GL_ARB_shader_draw_parameters GL_ARB_shader_group_vote GL_ARB_shader_image_load_store GL_ARB_shader_image_size GL_ARB_shader_objects GL_ARB_shader_precision GL_ARB_shader_storage_buffer_object GL_ARB_shader_subroutine GL_ARB_shader_texture_image_samples GL_ARB_shader_texture_lod GL_ARB_shading_language_100 GL_ARB_shader_viewport_layer_array GL_ARB_shading_language_420pack GL_ARB_shading_language_include GL_ARB_shading_language_packing GL_ARB_shadow GL_ARB_sparse_buffer GL_ARB_sparse_texture GL_ARB_sparse_texture2 GL_ARB_sparse_texture_clamp GL_ARB_spirv_extensions GL_ARB_stencil_texturing GL_ARB_sync GL_ARB_tessellation_shader GL_ARB_texture_barrier GL_ARB_texture_border_clamp GL_ARB_texture_buffer_object GL_ARB_texture_buffer_object_rgb32 GL_ARB_texture_buffer_range GL_ARB_texture_compression GL_ARB_texture_compression_bptc GL_ARB_texture_compression_rgtc GL_ARB_texture_cube_map GL_ARB_texture_cube_map_array GL_ARB_texture_env_add GL_ARB_texture_env_combine GL_ARB_texture_env_crossbar GL_ARB_texture_env_dot3 GL_ARB_texture_filter_anisotropic GL_ARB_texture_filter_minmax GL_ARB_texture_float GL_ARB_texture_gather GL_ARB_texture_mirror_clamp_to_edge GL_ARB_texture_mirrored_repeat GL_ARB_texture_multisample GL_ARB_texture_non_power_of_two GL_ARB_texture_query_levels GL_ARB_texture_query_lod GL_ARB_texture_rectangle GL_ARB_texture_rg GL_ARB_texture_rgb10_a2ui GL_ARB_texture_stencil8 GL_ARB_texture_storage GL_ARB_texture_storage_multisample GL_ARB_texture_swizzle GL_ARB_texture_view GL_ARB_timer_query GL_ARB_transform_feedback2 GL_ARB_transform_feedback3 GL_ARB_transform_feedback_instanced GL_ARB_transform_feedback_overflow_query GL_ARB_transpose_matrix GL_ARB_uniform_buffer_object GL_ARB_vertex_array_bgra GL_ARB_vertex_array_object GL_ARB_vertex_attrib_64bit GL_ARB_vertex_attrib_binding GL_ARB_vertex_buffer_object GL_ARB_vertex_program GL_ARB_vertex_shader GL_ARB_vertex_type_10f_11f_11f_rev GL_ARB_vertex_type_2_10_10_10_rev GL_ARB_viewport_array GL_ARB_window_pos GL_ATI_draw_buffers GL_ATI_texture_float GL_ATI_texture_mirror_once GL_S3_s3tc GL_EXT_texture_env_add GL_EXT_abgr GL_EXT_bgra GL_EXT_bindable_uniform GL_EXT_blend_color GL_EXT_blend_equation_separate GL_EXT_blend_func_separate GL_EXT_blend_minmax GL_EXT_blend_subtract GL_EXT_compiled_vertex_array GL_EXT_Cg_shader GL_EXT_depth_bounds_test GL_EXT_direct_state_access GL_EXT_draw_buffers2 GL_EXT_draw_instanced GL_EXT_draw_range_elements GL_EXT_fog_coord GL_EXT_framebuffer_blit GL_EXT_framebuffer_multisample GL_EXTX_framebuffer_mixed_formats GL_EXT_framebuffer_multisample_blit_scaled GL_EXT_framebuffer_object GL_EXT_framebuffer_sRGB GL_EXT_geometry_shader4 GL_EXT_gpu_program_parameters GL_EXT_gpu_shader4 GL_EXT_multi_draw_arrays GL_EXT_multiview_texture_multisample GL_EXT_multiview_timer_query GL_EXT_packed_depth_stencil GL_EXT_packed_float GL_EXT_packed_pixels GL_EXT_pixel_buffer_object GL_EXT_point_parameters GL_EXT_polygon_offset_clamp GL_EXT_post_depth_coverage GL_EXT_provoking_vertex GL_EXT_raster_multisample GL_EXT_rescale_normal GL_EXT_secondary_color GL_EXT_separate_shader_objects GL_EXT_separate_specular_color GL_EXT_shader_image_load_formatted GL_EXT_shader_image_load_store GL_EXT_shader_integer_mix GL_EXT_shadow_funcs GL_EXT_sparse_texture2 GL_EXT_stencil_two_side GL_EXT_stencil_wrap GL_EXT_texture3D GL_EXT_texture_array GL_EXT_texture_buffer_object GL_EXT_texture_compression_dxt1 GL_EXT_texture_compression_latc GL_EXT_texture_compression_rgtc GL_EXT_texture_compression_s3tc GL_EXT_texture_cube_map GL_EXT_texture_edge_clamp GL_EXT_texture_env_combine GL_EXT_texture_env_dot3 GL_EXT_texture_filter_anisotropic GL_EXT_texture_filter_minmax GL_EXT_texture_integer GL_EXT_texture_lod GL_EXT_texture_lod_bias GL_EXT_texture_mirror_clamp GL_EXT_texture_object GL_EXT_texture_shadow_lod GL_EXT_texture_shared_exponent GL_EXT_texture_sRGB GL_EXT_texture_sRGB_R8 GL_EXT_texture_sRGB_decode GL_EXT_texture_storage GL_EXT_texture_swizzle GL_EXT_timer_query GL_EXT_transform_feedback2 GL_EXT_vertex_array GL_EXT_vertex_array_bgra GL_EXT_vertex_attrib_64bit GL_EXT_window_rectangles GL_EXT_import_sync_object GL_IBM_rasterpos_clip GL_IBM_texture_mirrored_repeat GL_KHR_context_flush_control GL_KHR_debug GL_EXT_memory_object GL_EXT_memory_object_win32 GL_EXT_win32_keyed_mutex GL_KHR_parallel_shader_compile GL_KHR_no_error GL_KHR_robust_buffer_access_behavior GL_KHR_robustness GL_EXT_semaphore GL_EXT_semaphore_win32 GL_KHR_shader_subgroup GL_KTX_buffer_region GL_NV_alpha_to_coverage_dither_control GL_NV_bindless_multi_draw_indirect GL_NV_bindless_multi_draw_indirect_count GL_NV_bindless_texture GL_NV_blend_equation_advanced GL_NV_blend_equation_advanced_coherent GL_NVX_blend_equation_advanced_multi_draw_buffers GL_NV_blend_minmax_factor GL_NV_blend_square GL_NV_clip_space_w_scaling GL_NV_command_list GL_NV_compute_program5 GL_NV_compute_shader_derivatives GL_NV_conditional_render GL_NV_conservative_raster GL_NV_conservative_raster_dilate GL_NV_conservative_raster_pre_snap GL_NV_conservative_raster_pre_snap_triangles GL_NV_conservative_raster_underestimation GL_NV_copy_depth_to_color GL_NV_copy_image GL_NV_depth_buffer_float GL_NV_depth_clamp GL_NV_draw_texture GL_NV_draw_vulkan_image GL_NV_ES1_1_compatibility GL_NV_ES3_1_compatibility GL_NV_explicit_multisample GL_NV_feature_query GL_NV_fence GL_NV_fill_rectangle GL_NV_float_buffer GL_NV_fog_distance GL_NV_fragment_coverage_to_color GL_NV_fragment_program GL_NV_fragment_program_option GL_NV_fragment_program2 GL_NV_fragment_shader_barycentric GL_NV_fragment_shader_interlock GL_NV_framebuffer_mixed_samples GL_NV_framebuffer_multisample_coverage GL_NV_geometry_shader4 GL_NV_geometry_shader_passthrough GL_NV_gpu_program4 GL_NV_internalformat_sample_query GL_NV_gpu_program4_1 GL_NV_gpu_program5 GL_NV_gpu_program5_mem_extended GL_NV_gpu_program_fp64 GL_NV_gpu_shader5 GL_NV_half_float GL_NV_light_max_exponent GL_NV_memory_attachment GL_NV_mesh_shader GL_NV_multisample_coverage GL_NV_multisample_filter_hint GL_NV_occlusion_query GL_NV_packed_depth_stencil GL_NV_parameter_buffer_object GL_NV_parameter_buffer_object2 GL_NV_path_rendering GL_NV_path_rendering_shared_edge GL_NV_pixel_data_range GL_NV_point_sprite GL_NV_primitive_restart GL_NV_query_resource GL_NV_query_resource_tag GL_NV_register_combiners GL_NV_register_combiners2 GL_NV_representative_fragment_test GL_NV_sample_locations GL_NV_sample_mask_override_coverage GL_NV_scissor_exclusive GL_NV_shader_atomic_counters GL_NV_shader_atomic_float GL_NV_shader_atomic_float64 GL_NV_shader_atomic_fp16_vector GL_NV_shader_atomic_int64 GL_NV_shader_buffer_load GL_NV_shader_storage_buffer_object GL_NV_shader_subgroup_partitioned GL_NV_shader_texture_footprint GL_NV_shading_rate_image GL_NV_stereo_view_rendering GL_NV_texgen_reflection GL_NV_texture_barrier GL_NV_texture_compression_vtc GL_NV_texture_env_combine4 GL_NV_texture_multisample GL_NV_texture_rectangle GL_NV_texture_rectangle_compressed GL_NV_texture_shader GL_NV_texture_shader2 GL_NV_texture_shader3 GL_NV_transform_feedback GL_NV_transform_feedback2 GL_NV_uniform_buffer_unified_memory GL_NV_vertex_array_range GL_NV_vertex_array_range2 GL_NV_vertex_attrib_integer_64bit GL_NV_vertex_buffer_unified_memory GL_NV_vertex_program GL_NV_vertex_program1_1 GL_NV_vertex_program2 GL_NV_vertex_program2_option GL_NV_vertex_program3 GL_NV_viewport_array2 GL_NV_viewport_swizzle GL_NVX_conditional_render GL_NVX_linked_gpu_multicast GL_NV_gpu_multicast GL_NVX_gpu_multicast2 GL_NVX_progress_fence GL_NVX_gpu_memory_info GL_NVX_multigpu_info GL_NVX_nvenc_interop GL_NV_shader_thread_group GL_NV_shader_thread_shuffle GL_KHR_blend_equation_advanced GL_KHR_blend_equation_advanced_coherent GL_OVR_multiview GL_OVR_multiview2 GL_SGIS_generate_mipmap GL_SGIS_texture_lod GL_SGIX_depth_texture GL_SGIX_shadow GL_SUN_slice_accum GL_WIN_swap_hint WGL_EXT_swap_control
10:59:28: Supported WGL extensions: WGL_ARB_buffer_region WGL_ARB_create_context WGL_ARB_create_context_no_error WGL_ARB_create_context_profile WGL_ARB_create_context_robustness WGL_ARB_context_flush_control WGL_ARB_extensions_string WGL_ARB_make_current_read WGL_ARB_multisample WGL_ARB_pbuffer WGL_ARB_pixel_format WGL_ARB_pixel_format_float WGL_ARB_render_texture WGL_ATI_pixel_format_float WGL_EXT_colorspace WGL_EXT_create_context_es_profile WGL_EXT_create_context_es2_profile WGL_EXT_extensions_string WGL_EXT_framebuffer_sRGB WGL_EXT_pixel_format_packed_float WGL_EXT_swap_control WGL_EXT_swap_control_tear WGL_NVX_DX_interop WGL_NV_DX_interop WGL_NV_DX_interop2 WGL_NV_copy_image WGL_NV_delay_before_swap WGL_NV_float_buffer WGL_NV_multisample_coverage WGL_NV_multigpu_context WGL_NV_render_depth_texture WGL_NV_render_texture_rectangle
10:59:28: ***************************
10:59:28: *** GL Renderer Started ***
10:59:28: ***************************
10:59:28: Registering ResourceManager for type GpuProgram
10:59:28: GLSL support detected
10:59:28: GL: Using GL_EXT_framebuffer_object for rendering to textures (best)
10:59:28: FBO PF_UNKNOWN depth/stencil support: D0S8 D16S0 D24S0 D32S0 Packed-D24S8
10:59:28: FBO PF_L8 depth/stencil support: D0S0 D0S8 D16S0 D24S0 D32S0 Packed-D24S8
10:59:28: FBO PF_A8 depth/stencil support: D0S0 D0S8 D16S0 D24S0 D32S0 Packed-D24S8
10:59:28: FBO PF_A4L4 depth/stencil support: D0S0 D0S8 D16S0 D24S0 D32S0 Packed-D24S8
10:59:28: FBO PF_BYTE_LA depth/stencil support: D0S0 D0S8 D16S0 D24S0 D32S0 Packed-D24S8
10:59:28: FBO PF_R5G6B5 depth/stencil support: D0S0 D0S8 D16S0 D24S0 D32S0 Packed-D24S8
10:59:28: FBO PF_B5G6R5 depth/stencil support: D0S0 D0S8 D16S0 D24S0 D32S0 Packed-D24S8
10:59:28: FBO PF_A4R4G4B4 depth/stencil support: D0S0 D0S8 D16S0 D24S0 D32S0 Packed-D24S8
10:59:28: FBO PF_A1R5G5B5 depth/stencil support: D0S0 D0S8 D16S0 D24S0 D32S0 Packed-D24S8
10:59:28: FBO PF_R8G8B8 depth/stencil support: D0S0 D0S8 D16S0 D24S0 D32S0 Packed-D24S8
10:59:28: FBO PF_B8G8R8 depth/stencil support: D0S0 D0S8 D16S0 D24S0 D32S0 Packed-D24S8
10:59:28: FBO PF_A8R8G8B8 depth/stencil support: D0S0 D0S8 D16S0 D24S0 D32S0 Packed-D24S8
10:59:28: FBO PF_B8G8R8A8 depth/stencil support: D0S0 D0S8 D16S0 D24S0 D32S0 Packed-D24S8
10:59:28: FBO PF_A2R10G10B10 depth/stencil support: D0S0 D0S8 D16S0 D24S0 D32S0 Packed-D24S8
10:59:28: FBO PF_A2B10G10R10 depth/stencil support: D0S0 D0S8 D16S0 D24S0 D32S0 Packed-D24S8
10:59:28: FBO PF_FLOAT16_RGB depth/stencil support: D0S0 D0S8 D16S0 D24S0 D32S0 Packed-D24S8
10:59:28: FBO PF_FLOAT16_RGBA depth/stencil support: D0S0 D0S8 D16S0 D24S0 D32S0 Packed-D24S8
10:59:29: FBO PF_FLOAT32_RGB depth/stencil support: D0S0 D0S8 D16S0 D24S0 D32S0 Packed-D24S8
10:59:29: FBO PF_FLOAT32_RGBA depth/stencil support: D0S0 D0S8 D16S0 D24S0 D32S0 Packed-D24S8
10:59:29: FBO PF_X8R8G8B8 depth/stencil support: D0S0 D0S8 D16S0 D24S0 D32S0 Packed-D24S8
10:59:29: FBO PF_X8B8G8R8 depth/stencil support: D0S0 D0S8 D16S0 D24S0 D32S0 Packed-D24S8
10:59:29: FBO PF_SHORT_RGBA depth/stencil support: D0S0 D0S8 D16S0 D24S0 D32S0 Packed-D24S8
10:59:29: FBO PF_R3G3B2 depth/stencil support: D0S0 D0S8 D16S0 D24S0 D32S0 Packed-D24S8
10:59:29: FBO PF_FLOAT16_R depth/stencil support: D0S0 D0S8 D16S0 D24S0 D32S0 Packed-D24S8
10:59:29: FBO PF_FLOAT32_R depth/stencil support: D0S0 D0S8 D16S0 D24S0 D32S0 Packed-D24S8
10:59:29: FBO PF_FLOAT16_GR depth/stencil support: D0S0 D0S8 D16S0 D24S0 D32S0 Packed-D24S8
10:59:29: FBO PF_FLOAT32_GR depth/stencil support: D0S0 D0S8 D16S0 D24S0 D32S0 Packed-D24S8
10:59:29: FBO PF_SHORT_RGB depth/stencil support: D0S0 D0S8 D16S0 D24S0 D32S0 Packed-D24S8
10:59:29: [GL] : Valid FBO targets PF_UNKNOWN PF_L8 PF_A8 PF_A4L4 PF_BYTE_LA PF_R5G6B5 PF_B5G6R5 PF_A4R4G4B4 PF_A1R5G5B5 PF_R8G8B8 PF_B8G8R8 PF_A8R8G8B8 PF_B8G8R8A8 PF_A2R10G10B10 PF_A2B10G10R10 PF_FLOAT16_RGB PF_FLOAT16_RGBA PF_FLOAT32_RGB PF_FLOAT32_RGBA PF_X8R8G8B8 PF_X8B8G8R8 PF_SHORT_RGBA PF_R3G3B2 PF_FLOAT16_R PF_FLOAT32_R PF_FLOAT16_GR PF_FLOAT32_GR PF_SHORT_RGB
10:59:29: RenderSystem capabilities
10:59:29: -------------------------
10:59:29: RenderSystem Name: OpenGL Rendering Subsystem
10:59:29: GPU Vendor: nvidia
10:59:29: Device Name: GeForce GTX 1650 Ti/PCIe/SSE2
10:59:29: Driver Version: 4.6.0.0
10:59:29: * Fixed function pipeline: yes
10:59:29: * Hardware generation of mipmaps: yes
10:59:29: * Texture blending: yes
10:59:29: * Anisotropic texture filtering: yes
10:59:29: * Dot product texture operation: yes
10:59:29: * Cube mapping: yes
10:59:29: * Hardware stencil buffer: yes
10:59:29: - Stencil depth: 8
10:59:29: - Two sided stencil support: yes
10:59:29: - Wrap stencil values: yes
10:59:29: * Hardware vertex / index buffers: yes
10:59:29: * Vertex programs: yes
10:59:29: * Number of floating-point constants for vertex programs: 1024
10:59:29: * Number of integer constants for vertex programs: 0
10:59:29: * Number of boolean constants for vertex programs: 0
10:59:29: * Fragment programs: yes
10:59:29: * Number of floating-point constants for fragment programs: 1024
10:59:29: * Number of integer constants for fragment programs: 0
10:59:29: * Number of boolean constants for fragment programs: 0
10:59:29: * Geometry programs: yes
10:59:29: * Number of floating-point constants for geometry programs: 2048
10:59:29: * Number of integer constants for geometry programs: 0
10:59:29: * Number of boolean constants for geometry programs: 0
10:59:29: * Supported Shader Profiles: arbfp1 arbvp1 fp20 fp30 fp40 glsl gp4fp gp4gp gp4vp gpu_fp gpu_gp gpu_vp nvgp4 vp30 vp40
10:59:29: * Texture Compression: yes
10:59:29: - DXT: yes
10:59:29: - VTC: yes
10:59:29: - PVRTC: no
10:59:29: * Scissor Rectangle: yes
10:59:29: * Hardware Occlusion Query: yes
10:59:29: * User clip planes: yes
10:59:29: * VET_UBYTE4 vertex element type: yes
10:59:29: * Infinite far plane projection: yes
10:59:29: * Hardware render-to-texture: yes
10:59:29: * Floating point textures: yes
10:59:29: * Non-power-of-two textures: yes
10:59:29: * Volume textures: yes
10:59:29: * Multiple Render Targets: 8
10:59:29: - With different bit depths: yes
10:59:29: * Point Sprites: yes
10:59:29: * Extended point parameters: yes
10:59:29: * Max Point Size: 2047
10:59:29: * Vertex texture fetch: yes
10:59:29: * Number of world matrices: 0
10:59:29: * Number of texture units: 32
10:59:29: * Stencil buffer depth: 8
10:59:29: * Number of vertex blend matrices: 0
10:59:29: - Max vertex textures: 32
10:59:29: - Vertex textures shared: yes
10:59:29: * Render to Vertex Buffer : yes
10:59:29: * GL 1.5 without VBO workaround: no
10:59:29: * Frame Buffer objects: yes
10:59:29: * Frame Buffer objects (ARB extension): no
10:59:29: * Frame Buffer objects (ATI extension): no
10:59:29: * PBuffer support: yes
10:59:29: * GL 1.5 without HW-occlusion workaround: no
10:59:29: * Separate shader objects: no
10:59:29: DefaultWorkQueue('Root') initialising on thread main.
10:59:29: Particle Renderer Type 'billboard' registered
10:59:29: Added resource location 'C:\Program Files\PureBasic601\examples\3D\Data\Textures' of type 'FileSystem' to resource group 'General'
10:59:29: Parsing scripts for resource group Autodetect
10:59:29: Finished parsing scripts for resource group Autodetect
10:59:29: Creating resources for group Autodetect
10:59:29: All done
10:59:29: Parsing scripts for resource group General
10:59:29: Finished parsing scripts for resource group General
10:59:29: Creating resources for group General
10:59:29: All done
10:59:29: Parsing scripts for resource group Internal
10:59:29: Finished parsing scripts for resource group Internal
10:59:29: Creating resources for group Internal
10:59:29: All done
10:59:29: Texture: mramor6x6.jpg: Loading 1 faces(PF_R8G8B8,600x600x1) with 9 hardware generated mipmaps from Image. Internal format is PF_X8R8G8B8,600x600x1.
10:59:29: Texture: soil_wall.jpg: Loading 1 faces(PF_R8G8B8,512x512x1) with 9 hardware generated mipmaps from Image. Internal format is PF_X8R8G8B8,512x512x1.
10:59:29: 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?
10:59:29: GLSL compiled: 0(12) : warning C7555: 'varying' is deprecated, use 'in/out' instead
0(13) : warning C7555: 'varying' is deprecated, use 'in/out' instead
0(14) : warning C7555: 'varying' is deprecated, use 'in/out' instead
0(15) : warning C7555: 'varying' is deprecated, use 'in/out' instead
0(16) : warning C7555: 'varying' is deprecated, use 'in/out' instead
0(17) : warning C7555: 'varying' is deprecated, use 'in/out' instead
0(21) : warning C7533: global variable gl_Vertex is deprecated after version 120
0(24) : warning C7533: global variable gl_Normal is deprecated after version 120
0(27) : warning C7533: global variable gl_TextureMatrix is deprecated after version 120
0(27) : warning C7533: global variable gl_MultiTexCoord0 is deprecated after version 120
0(28) : warning C7533: global variable gl_Color is deprecated after version 120

10:59:29: GLSL compiled: 0(15) : warning C7555: 'varying' is deprecated, use 'in/out' instead
0(16) : warning C7555: 'varying' is deprecated, use 'in/out' instead
0(17) : warning C7555: 'varying' is deprecated, use 'in/out' instead
0(18) : warning C7555: 'varying' is deprecated, use 'in/out' instead
0(19) : warning C7555: 'varying' is deprecated, use 'in/out' instead
0(20) : warning C7555: 'varying' is deprecated, use 'in/out' instead
0(32) : warning C7533: global variable gl_FragColor is deprecated after version 120
et le debug OpenGL
OpenGL Version : 4.6.0 NVIDIA 451.67
Vendor : NVIDIA Corporation
Vidéo Card : GeForce GTX 1650 Ti/PCIe/SSE2
Configuration : Windows 11 Famille 64-bit - PB 6.20 x64 - AMD Ryzen 7 - 16 GO RAM
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
Avatar de l’utilisateur
SPH
Messages : 4937
Inscription : mer. 09/nov./2005 9:53

Re: PB 6.00 - Exemples 3D - Shaders <<< Corrigés >>>

Message par SPH »

Guillot a écrit : ven. 17/mars/2023 10:14 merci pour ton aide
effectivement c'est bien un défaut l'ombrage noir en dessous du torre
j'ai fait des modifs, si tu peux tester, me dire si tu as toujours le probleme
si oui, peux tu m'envoyer le contenu du débogueur ?
(si tu enregistre le code préalablement, le débogueur pourra te donner plus d'info en cas de probleme de compilation du shader)

Code : Tout sélectionner

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

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)
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*8)
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(dot(normalize(lightdir+viewdir),normal),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)
DisableMaterialLighting(0,1)

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)
; ------------------------------------------------------------- info debug
fic.s=GetCurrentDirectory()+"Ogre"
CopyFile(fic+".log", fic+".tmp") 
If ReadFile(0,fic+".tmp",#PB_File_SharedRead)
  log.s=ReadString(0,#PB_File_IgnoreEOL)
  CloseFile(0)
  p=FindString(log,"sh0VPERROR"):If p:Debug  Mid(log,p-100,400):Debug "----------------------------":EndIf
  p=FindString(log,"sh0FPERROR"):If p:Debug  Mid(log,p-100,400):Debug "----------------------------":EndIf
EndIf
OpenWindow(1, 0, 0, 0, 0, "",#PB_Window_Invisible)
OpenGLGadget(1, 0, 0, 0, 0)
Debug "OpenGL Version : " + PeekS(glGetString_(#GL_VERSION), -1, #PB_UTF8)
Debug "Vendor : " + PeekS(glGetString_(#GL_VENDOR), -1, #PB_UTF8)
Debug "Vidéo Card : " + PeekS(glGetString_(#GL_RENDERER), -1, #PB_UTF8)
Même problème. Exactement pareil que le GIF de falsam ci dessus...

Le debug :
OpenGL Version : 4.6.0 NVIDIA 471.41
Vendor : NVIDIA Corporation
Vidéo Card : NVIDIA GeForce GTX 650 Ti/PCIe/SSE2

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Intel Core i7 4770 64 bits - GTX 650 Ti
Version de PB : 6.12LTS- 64 bits
Avatar de l’utilisateur
Guillot
Messages : 672
Inscription : jeu. 25/juin/2015 16:18

Re: PB 6.00 - Exemples 3D - Shaders <<< Corrigés >>>

Message par Guillot »

merci les gars,
falsam, je suis un peu étonné qu'avant, c'était nickel sur tout les exemples
peut etre que le bug de l'exemple 3 se voyait moins
dans la version modifiées pour SPH j'ai augmenté la luminosité ambiante, et pris des textures plus claire pour mettre en évidence le bug

j'ai modifié le code en virant la gestion de l'attenuation de la lumiere (et viré le debug), je vous laisse tester...

Code : Tout sélectionner

;  ----------------------------------------------------------------------------------------------------------
;   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*8)
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 vec2 ouv;%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);%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 vec2 ouv;%varying float ofogf;%%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);%float spe=pow(dot(normalize(lightdir+viewdir),normal),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)
DisableMaterialLighting(0,1)

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)
Avatar de l’utilisateur
SPH
Messages : 4937
Inscription : mer. 09/nov./2005 9:53

Re: PB 6.00 - Exemples 3D - Shaders <<< Corrigés >>> ou presque !!

Message par SPH »

Même avec ton dernier code, le bug est (encore) flagrant ! :oops:

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Intel Core i7 4770 64 bits - GTX 650 Ti
Version de PB : 6.12LTS- 64 bits
Avatar de l’utilisateur
falsam
Messages : 7317
Inscription : dim. 22/août/2010 15:24
Localisation : IDF (Yvelines)
Contact :

Re: PB 6.00 - Exemples 3D - Shaders <<< Corrigés >>> ou presque !!

Message par falsam »

SPH a écrit : sam. 18/mars/2023 11:43 Même avec ton dernier code, le bug est (encore) flagrant ! :oops:
Effectivement le résultat est identique au précèdent.
Configuration : Windows 11 Famille 64-bit - PB 6.20 x64 - AMD Ryzen 7 - 16 GO RAM
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
Avatar de l’utilisateur
Guillot
Messages : 672
Inscription : jeu. 25/juin/2015 16:18

Re: PB 6.00 - Exemples 3D - Shaders <<< Corrigés >>> ou presque !!

Message par Guillot »

et avec le bump ?

Code : Tout sélectionner

;  ----------------------------------------------------------------------------------------------------------
;   CreateShader - bump 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)
Add3DArchive(#PB_Compiler_Home + "examples\3D\Data\Textures\nvidia", #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*8)
CameraBackColor(0,$444488)
Fog(0,1,0,1000)

CreateShaderMaterial(0,#PB_Material_BumpShader)
DisableMaterialLighting(0,1)

LoadTexture(0,"dirt_grayrocky_diffusespecular.jpg")
LoadTexture(1,"dirt_grayrocky_normalheight.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)
Avatar de l’utilisateur
falsam
Messages : 7317
Inscription : dim. 22/août/2010 15:24
Localisation : IDF (Yvelines)
Contact :

Re: PB 6.00 - Exemples 3D - Shaders <<< Corrigés >>> ou presque !!

Message par falsam »

Guillot a écrit : sam. 18/mars/2023 11:39 falsam, je suis un peu étonné qu'avant, c'était nickel sur tout les exemples
M'enfin 8O 8O

Voici un petit gif du rendu de tes quatre premiers codes de ce sujet avant tes corrections.

Image

Je ne voyais pas de souci d'ombre sur le torus.
Configuration : Windows 11 Famille 64-bit - PB 6.20 x64 - AMD Ryzen 7 - 16 GO RAM
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
Avatar de l’utilisateur
Guillot
Messages : 672
Inscription : jeu. 25/juin/2015 16:18

Re: PB 6.00 - Exemples 3D - Shaders <<< Corrigés >>> ou presque !!

Message par Guillot »

t'es le pro tu gif animé !
sur l'exemple 3 on voit le probleme d'ombrage
et le bump ? (dernier post)
Avatar de l’utilisateur
falsam
Messages : 7317
Inscription : dim. 22/août/2010 15:24
Localisation : IDF (Yvelines)
Contact :

Re: PB 6.00 - Exemples 3D - Shaders <<< Corrigés >>> ou presque !!

Message par falsam »

Guillot a écrit : sam. 18/mars/2023 13:39 et le bump ? (dernier post)
Résultat en image

Image
Réalisé avec https://www.screentogif.com
Configuration : Windows 11 Famille 64-bit - PB 6.20 x64 - AMD Ryzen 7 - 16 GO RAM
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
Répondre