je viens de comprendre le fonctionnement de la brillance
et j'en suis tout ébloui (ouarf !)
(je sens que je vais en mettre de partout)
pour ce faire:
definir la couleur speculaire de la lumiere
SetLightColor(..., #PB_Light_SpecularColor, couleur)
perso, je comprends pas la réalité physique de ce parametre, ce qui est responsable du reflet, c'est la matiere. (peut etre pour certains effets...)
moi, je pense que ce parametre devrait etre automatiquement definit au moment de la création de la lumiere (avec la meme couleur)
si certain ont un avis eclairé (re ouarf !) sur le sujet, j'attends leur commentaire
ensuite, definir la couleur réfléchie par la matiere et sa diffusion
SetMaterialColor(..., #PB_Material_SpecularColor, couleur)
MaterialShininess(..., diffusion)
plus la valeur de diffusion est faible plus la matiere est mate, plus elle est élevée, plus elle est brillante
Note: une valeur faible donne une reflet global beaucoup plus lumineux. du coup, on est obliger d'ajuster l'intensité de la lumiere réfléchie à la brillance, dommage
j'ai adapté ma demo 'mesh axial' pour vous monter le resultat
c'est bôôôô !
Code : Tout sélectionner
;Mesh Axial, brillance - Pf shadoko - 2015
EnableExplicit
Global.w ex,ey,dx,dx1,dy,dy1,nb
;###############################################################################
;###############################################################################
;###############################################################################
Structure coo2d
x.f
y.f
EndStructure
Procedure Bspline(Array pe.coo2d(1), Array PS.coo2d(1),nd.w)
Protected.f t,tt
Protected np,i,j,jj,k,c
Protected Dim m.w(4, 4)
Protected Dim ttt.f(4)
np = ArraySize(pe())
Protected Dim PS((np - 2) * nd)
m(0, 0) = -1: m(1, 0) = 3: m(2, 0) = -3: m(3, 0) = 1
m(0, 1) = 2: m(1, 1) = -5: m(2, 1) = 4: m(3, 1) = -1
m(0, 2) = -1: m(1, 2) = 0: m(2, 2) = 1: m(3, 2) = 0
m(0, 3) = 0: m(1, 3) = 2: m(2, 3) = 0: m(3, 3) = 0
If pe(np - 1)\X = pe(1)\X And pe(np - 1)\Y = pe(1)\Y
pe(0) = pe(np - 2): pe(np) = pe(2)
Else
pe(0) = pe(1):pe(np) = pe(np - 1)
EndIf
For jj = 0 To np - 3
For i = 0 To nd - 1
t = i / nd
For j = 0 To 3
ttt(j) = 0: tt = 0.5
For k = 3 To 0 Step -1: ttt(j) + tt * m(j, k) : tt * t: Next
PS(c)\X + ttt(j) * pe(j + jj)\X
PS(c)\Y + ttt(j) * pe(j + jj)\Y
Next
c + 1
Next
Next
PS(c) = pe(np - 1)
EndProcedure
Procedure string2coo2d(Array s.coo2d(1),t.s) ;pas tres élégant !
Protected Dim a.f(0, 0)
Protected n
t="0,0/"+t+"/0,0"
ParseJSON(0, "[["+ReplaceString(t,"/","],[")+"]]")
ExtractJSONArray(JSONValue(0), a())
n=ArraySize(a())
Dim s.coo2d(n)
CopyMemory(@a(0,0),@s(0),4*2*(n+1))
EndProcedure
Procedure.f lg2D(x.f,y.f)
ProcedureReturn Sqr(x.f*x.f+y.f*y.f)
EndProcedure
Procedure CreateAxialMesh(mesh,Array profils.coo2d(1),Array section.coo2d(1))
Macro profilsJ()
ar=r
ah=h
r=profils(j)\x
h=profils(j)\y
v+lg2D(r-ar,h-ah)
EndMacro
Protected i,j,r.f,h.f,ar.f,ah.f,a.f,v.f,vv.f,n,n1,m
n=ArraySize(section()):n1=n+1
m=ArraySize(profils())
r=profils(0)\x:h=profils(0)\y:v=0
For j=0 To m:profilsJ():Next:vv=v
r=profils(0)\x:h=profils(0)\y:v=0
CreateMesh(mesh,#PB_Mesh_TriangleList,#PB_Mesh_Dynamic)
For j=0 To m
profilsJ()
For i=0 To n
MeshVertexPosition(section(i)\x* r,h,section(i)\y* r)
MeshVertexTextureCoordinate(i/n,v/vv)
MeshVertexNormal(0,0,0)
MeshVertexColor($ffffff)
Next
Next
For j=0 To m-1
For i=0 To n-1
MeshFace(i+j*n1,i+(j+1)*n1,(i%n1+1)+j*n1)
MeshFace((i%n1+1)+(j+1)*n1,(i%n1+1)+j*n1,i+(j+1)*n1)
Next
Next
FinishMesh(1)
NormalizeMesh(mesh)
;UpdateMeshBoundingBox(mesh)
;BuildMeshTangents(Mesh)
EndProcedure
Procedure CreateAxialMeshCustom(mesh,ProfilList.s,ProfilSubDiv,sectionList.s,SectionSubDiv)
Protected Dim profil.coo2d(0)
Protected Dim profils.coo2d(0)
string2coo2d(profil(),ProfilList)
Bspline(profil(),profils(),ProfilSubDiv)
Protected Dim section.coo2d(0)
Protected Dim sections.coo2d(0)
string2coo2d(section(),sectionList)
Bspline(section(),sections(),SectionSubDiv)
CreateAxialMesh(mesh,profils(),sections())
EndProcedure
Procedure CreateAxialMeshCircular(mesh,ProfilList.s,ProfilSubDiv=16 ,cercleSubDiv=16)
Protected i,a.f
Protected Dim profil.coo2d(0)
Protected Dim profils.coo2d(0)
string2coo2d(profil(),ProfilList)
Bspline(profil(),profils(),ProfilSubDiv)
Protected Dim section.coo2d(cercleSubDiv)
For i=0 To cercleSubDiv:a=Radian(360/cercleSubDiv)*i:section(i)\x=Cos(a):section(i)\y=Sin(a):Next
CreateAxialMesh(mesh,profils(),section())
EndProcedure
;###############################################################################
;###############################################################################
;###############################################################################
Procedure degrade(Array pal.l(1),l,c1.l,c2.l)
Dim pal(l-1)
CreateImage(0,l,1,32)
StartDrawing(ImageOutput(0))
DrawingMode(#PB_2DDrawing_Gradient)
GradientColor(0.0,c1)
GradientColor(1.0,c2)
LinearGradient(0,0,l-1,0)
Box(0,0,l,1)
CopyMemory(DrawingBuffer(),@pal(0),l*4)
StopDrawing()
FreeImage(0)
EndProcedure
Procedure generematiere(num,dx,dy,c1,c2,type,brillance=$ffffff,transparence=0)
Protected i,j,y
Protected Dim pal.l(0):degrade(pal(),256,c1,c2)
CreateTexture(num,dx,dy)
StartDrawing(TextureOutput(num))
Select type
Case 1; point (assiette /pomme / coupe)
DrawingMode(#PB_2DDrawing_AllChannels )
For j=0 To dy-1:For i=0 To dx-1:Plot(i,j,pal(Random(255))):Next:Next
Case 2; tissu (boite)
For i=0 To 2000:Line(Random(dx),0,1,dy,pal(Random(127)+128)):Line(0,Random(dy),dx,1,pal(Random(127))):Next
Case 3; brasselet
For i=-dx To dx:LineXY(i,0,i+dx,dy,pal(Bool(i & 30)*255)):Next
Case 4; vase
For j=0 To dy-1:For i=0 To dx-1:y=((Cos(i*4*#PI/dx)*255)): Plot(i ,j,pal((j*5+y) & 255)):Next:Next
Case 5; verre
Box(0,0,dx,dy,$555555):For j=0 To dy Step 8:Box (0,j,dx,1,$5555ff):Next;:Box (j,0,2,dy,$0000ff)
EndSelect
StopDrawing()
CreateMaterial(num, TextureID(num))
If brillance: SetMaterialColor(num, #PB_Material_SpecularColor, brillance):MaterialShininess(num, 80):EndIf
If transparence:MaterialBlendingMode(num, #PB_Material_Color):MaterialCullingMode(num,#PB_Material_NoCulling):EndIf
EndProcedure
Procedure scene()
Protected i,j,k,c,x,y,dx=8,dy=8
;######################################## cameras
CreateCamera(0, 0, 0, 100, 100):MoveCamera(0, 900, 500, 0, #PB_Absolute):CameraLookAt(0, 0, -50, 0):CameraBackColor(0, $333333)
CreateCamera(1, 0, 0,100,100):CameraBackColor(1, $333333); (miroir)
;######################################## lumieres
CreateLight(0,$ffffff, 10000, 5000, 5000):SetLightColor(0, #PB_Light_SpecularColor, $ffffff)
CreateLight(1,$ffffff, -5000, 5000,10000):SetLightColor(1, #PB_Light_SpecularColor, $ffffff)
AmbientColor($222222)
;######################################## textures / matieres
CreateRenderTexture(0,CameraID(1),ex,ey)
CreateMaterial(0, TextureID(0))
SetMaterialColor(0,#PB_Material_DiffuseColor,$ffffff):MaterialBlendingMode(0,#PB_Material_Color)
generematiere(1,256,256,$aa7722,$ffaa33,1,$444444) :ScaleMaterial(1,0.25*16,0.25*2)
generematiere(2,256,256,$aa8844,$ccaa66,1,$444444)
generematiere(3,128,256,$443300,$222200,1,$888888)
generematiere(4,64,64,$6666aa,$444488,1,$ffffff,1)
generematiere(5,256,256,$0000ff,$ffcc22,3)
generematiere(6,256,256,$88aa55,$ccaa99,4,$888888) :ScaleMaterial(6,0.25,0.25)
generematiere(7,256,256,0,0,5,$ffffff,1)
generematiere(8,8,8,$999900,$cc0000,1,$444444)
generematiere(9,256,256,$ff8800,$88ff88,2,$444444) :ScaleMaterial(9,0.25,0.25)
generematiere(100,1,1,$ffffff,$ffffff,1):SetMaterialColor(100,#PB_Material_SelfIlluminationColor,$ffffff);lumiere
;######################################## mesh/entity
;vitre
CreateAxialMeshCircular(1,"500,0/0,0",8,32)
CreateEntity(1, MeshID(1), MaterialID(0),0,0,0)
;table
CreateAxialMeshCircular(9,"500,0/0,0",16,32)
CreateEntity(9, MeshID(9), MaterialID(3),0,-1,0)
;coupes
CreateAxialMeshCircular(10,"0,0/50,1/10,20/10,100/55,200/50,200/0,100",4,32)
CreateEntity(10, MeshID(10), MaterialID(4),0,0,-300)
CreateEntity(11, MeshID(10), MaterialID(4),200,0,-320)
;assiette
CreateAxialMeshCircular(12,"0,0/80,1/160,46/160,49/156,50/76,5/0,5",1,8)
CreateEntity(12, MeshID(12), MaterialID(2),250,0,250)
;vases
CreateAxialMeshCircular(13,"0,0/80,1/120,150/80,250/110,300/100,300/75,250/75,20/0,20",8,32)
CreateEntity(13, MeshID(13), MaterialID(6),-0,0,0)
;boite
CreateAxialMeshCircular(14,"0,0/80,1/110,70/85,140/90,140/90,150/10,160/20,190/0,200",8,4)
CreateEntity(14, MeshID(14), MaterialID(1),-200,0,-200)
;brasselet !!!! pour faire un tore, le premier point doit etre similaire au premier !!!!
CreateAxialMeshCircular(15,"45,15/45,0/55,15/45,30/45,15",4,32)
CreateEntity(15, MeshID(15), MaterialID(5),400,0,100)
;verre
CreateAxialMeshCircular(16,"0,0/50,1/51,2/60,150/59,152/58,152/57,150/46,6/45,5/0,5",1,32)
CreateEntity(16, MeshID(16), MaterialID(7),0,0,200)
CreateEntity(17, MeshID(16), MaterialID(7),-200,0,200)
;truc (custom (ici on definit la section))
CreateAxialMeshCustom(17,"0,0/56,1/62,34/64,40/61,43/58,40/60,34/52,6/0,4",4,"-0.8,0/-1,-1/1,-1/0.8,0/1,1/-1,1/-0.8,0",8)
CreateEntity(18, MeshID(17), MaterialID(9),300,0,-100)
;pommes
CreateAxialMeshCircular(18,"0,10/20,0/45,30/50,80/20,100/2,90/2,105/0,110",4,32)
CreateEntity(19, MeshID(18), MaterialID(8),70,10,0) :AttachEntityObject(12,"",EntityID(19))
CreateEntity(20, MeshID(18), MaterialID(8),-20,10,-50):AttachEntityObject(12,"",EntityID(20))
CreateEntity(21, MeshID(18), MaterialID(8),-20,10,50) :AttachEntityObject(12,"",EntityID(21))
For i=9 To 18:AttachEntityObject(1,"",EntityID(i)):Next
CreateSphere(100,10)
For i=0 To 1:CreateEntity(100+i,MeshID(100),MaterialID(100)):Next
EndProcedure
Procedure rendermirror2(entity,mesh,nx.f,ny.f,nz.f,camP,camM)
Protected c,n,mx,my
Protected.f xp,yp,zp,dxp,dyp,dzp
Protected Dim T.PB_MeshVertex(0)
xp=CameraX(camP):dxp=CameraDirectionX(camP)
yp=CameraY(camP):dyp=CameraDirectionY(camP)
zp=CameraZ(camP):dzp=CameraDirectionZ(camP)
CameraDirection(camM,dxp,-dyp,dzp)
MoveCamera(camM,xp,-yp,zp,#PB_Absolute)
mx=CameraViewWidth (camp) ;###################################### marche pas avec la camera 1(RTT),
my=CameraViewHeight(camp) ;###################################### -> probleme si resolutions differentes
n=MeshVertexCount(mesh)-1
GetMeshData(mesh,0,t(),#PB_Mesh_Vertex|#PB_Mesh_UVCoordinate ,0,n)
For c=0 To n
With t(c)
ConvertLocalToWorldPosition(EntityID(entity),\x,\y,\z)
\u= CameraProjectionX(1,GetX(), 0,GetZ())/mx
\v= CameraProjectionY(1,GetX(), 0,GetZ())/my
EndWith
Next
SetMeshData(mesh,0,t(),#PB_Mesh_Vertex|#PB_Mesh_UVCoordinate,0,MeshVertexCount(mesh)-1)
EndProcedure
Define.f KeyX, KeyY,keyz, MouseX, MouseY,time,v,a,x,y,z,r.l
Define i,j,c,px,py,p,fdf,rot=1
InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()
AntialiasingMode(#PB_AntialiasingMode_x4 )
OpenWindow(0, 0, 0, 0,0, " Mesh Axial",#PB_Window_Maximize)
ex=WindowWidth (0,#PB_Window_InnerCoordinate)
ey=WindowHeight(0,#PB_Window_InnerCoordinate)
OpenWindowedScreen(WindowID(0), 0, 0, ex, ey, 0, 0, 0)
;{ menu
Macro DT(t1,t2)
DrawText(4,p,t1)
DrawText(40,p,t2)
p+16
EndMacro
CreateSprite(0,120,184,#PB_Sprite_AlphaBlending)
StartDrawing(SpriteOutput(0))
DrawingMode(#PB_2DDrawing_AlphaClip|#PB_2DDrawing_Outlined )
Box(0,0,120,184)
BackColor($0000ff)
dt("Déplacements:","")
dt("[Left]","")
dt("[Right]","")
dt("[Up]","")
dt("[Down]","")
dt("Mouse+wheel","")
dt("","")
dt("Commandes:","")
dt("[F1]","fil de fer")
dt("[F2]","Rotation")
dt("[Esc]","Quitter")
StopDrawing()
;}
scene()
Repeat
WindowEvent()
ExamineMouse()
MouseX = -MouseDeltaX() * 0.05
MouseY = -MouseDeltaY() * 0.05
ExamineKeyboard()
keyx=(-Bool(KeyboardPushed(#PB_Key_Left)<>0)+Bool(KeyboardPushed(#PB_Key_Right)<>0))*4
keyz=(-Bool(KeyboardPushed(#PB_Key_Down)<>0)+Bool(KeyboardPushed(#PB_Key_Up )<>0))*4+MouseWheel()*50
RotateCamera(0, MouseY, MouseX, 0, #PB_Relative):MoveCamera (0, KeyX, keyy, -keyz)
If KeyboardReleased(#PB_Key_F1):fdf=1-fdf:If fdf:CameraRenderMode(0,#PB_Camera_Wireframe):Else:CameraRenderMode(0,#PB_Camera_Textured):EndIf:EndIf
If KeyboardReleased(#PB_Key_F2):rot=1-rot:EndIf
RotateEntity(1,0,0.2*rot,0,#PB_Relative)
For i=0 To 1
y=i*200+300
x=Cos(a*(i+2))*500
z=Sin(a*(i+2))*500
MoveEntity(100+i,x,y,z,0)
MoveLight(i,x,y,z,0)
a+0.001
Next
rendermirror2(1,1,0,1,0,0,1)
time+RenderWorld()/200
DisplayTransparentSprite(0, 8,8,128)
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
End