dans la derniere version (5.71 b2) j'ai fais ajouter aux scripts materiels des exemples un script generique (utilisant MaterialTextureAliases) pour le normal mapping
j'ai lancer un appel contribution pour ajouter des scripts génèrique, mais pour l'instant rien...
(il comporte une fonction pour creer une normal map a partir de la luminosité des pixels)
Code : Tout sélectionner
; ----------------------------------------------------------------------------------------------------------
; MaterialTextureAliases
;
; This demo work only on Windows (Script HLSL)
; ----------------------------------------------------------------------------------------------------------
Structure Vector3
x.f
y.f
z.f
EndStructure
Procedure.f lng3D(*v.Vector3)
ProcedureReturn Sqr(*V\x * *V\x + *V\y * *V\y + *V\z * *V\z)
EndProcedure
Procedure Norme3D(*V.Vector3,l.f=1)
Protected.f lm = l / lng3d(*v)
*V\x * lm
*V\y * lm
*V\z * lm
EndProcedure
Procedure.i textureArray2NM(texture,Array hm.l(2),amplitude.f)
Protected i,j,n,dx,dy,h00,h10,h01
Protected.f x,y,z,l, max=255/amplitude,max2=max*max
Protected.vector3 p
dx=ArraySize(hm(),2)+1
dy=ArraySize(hm(),1)+1
Dim bmp.l(dy-1,dx-1)
For j=0 To dy-1
For i=0 To dx-1
h00=hm(j,i)
h10=hm(j,(i+1) % dx)
h01=hm((j+1) % dy,i)
p\x=h00-h10
p\y=h00-h01
l=p\x*p\x+p\y*p\y:If l>max2:l=max2:EndIf
p\z=Sqr(max2-l)
Norme3D(p,127)
bmp(j,i)=RGBA(p\z+128,p\y+128,p\x+128,255)
Next
Next
n=CreateTexture(texture,dx,dy):If texture=-1:texture=n:EndIf
StartDrawing(TextureOutput(texture)):CopyMemory(@bmp(0,0),DrawingBuffer(),dx*dy*4):StopDrawing()
ProcedureReturn texture
EndProcedure
Procedure.i textureHM2NM(imgNM,imgHM,amplitude.f)
Protected i,j,dx,dy,c
StartDrawing(TextureOutput(imgHM))
dx=OutputWidth()
dy=OutputHeight()
Dim hm.l(dy-1,dx-1)
Dim bmp.l(dy-1,dx-1)
CopyMemory(DrawingBuffer(),@bmp(0,0),dx*dy*4)
StopDrawing()
For j=0 To dy-1
For i=0 To dx-1
c=bmp(j,i)
hm(j,i)=Red(c)+Green(c)+Blue(c)
Next
Next
ProcedureReturn textureArray2NM(imgNM,hm(),amplitude/3)
EndProcedure
;>>>>>>>>>>>>>>>>>>>> BUG GetScriptMaterial <<<<<<<<<<<<<<<<<<<<
Procedure.i GetScriptMaterial_(material.i,name.s)
Protected m,mtemp=GetScriptMaterial(-1,name)
m=CopyMaterial(mtemp,material)
If material=-1:material=m:EndIf
FreeMaterial(mtemp)
ProcedureReturn material
EndProcedure
Macro GetScriptMaterial(material,name):GetScriptMaterial_(material,name):EndMacro
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
#MeshNumber=4
#Gap=4
Define i, a.f,ai.f
InitEngine3D(#PB_Engine3D_DebugLog):InitSprite():InitKeyboard():InitMouse()
ExamineDesktops()
ex=DesktopWidth (0)
ey=DesktopHeight(0)
OpenWindow(0, 0,0, ex,ey, "MaterialTextureAliases - [Esc] quit",#PB_Window_Maximize)
OpenWindowedScreen(WindowID(0), 0, 0, ex, ey, 0, 0, 0)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/scripts/MaterialScripts_Generic", #PB_3DArchive_FileSystem )
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
Parse3DScripts()
;--------------------------------------- scene ---------------------------------------
CreateCamera(0, 0, 0, 100, 100):MoveCamera(0,0,10,-4):CameraLookAt(0,0,0,0)
CreateLight(0, $ffffff, 0, 4, 0):SetLightColor(0,#PB_Light_SpecularColor, $ffffff)
AmbientColor($222222)
LoadTexture(1,"ValetCoeur.jpg")
LoadTexture(2,"Wood.jpg")
LoadTexture(3,"grass.jpg")
LoadTexture(4,"MRAMOR6X6.jpg")
CreateCube(1,3)
CreateSphere(2,2,32,32)
CreateTorus(3,1.5,1,32,32)
CreateCylinder(4,2,4,32,1,1)
For i=1 To #MeshNumber
BuildMeshTangents(i)
textureHM2NM(10+i,i,4)
GetScriptMaterial(i,"ParallaxOcclusionMapping")
MaterialTextureAliases(i,TextureID(i),TextureID(10+i),0,0)
MaterialFilteringMode(i,#PB_Material_Anisotropic,4)
CreateEntity(i,MeshID(i),MaterialID(i))
RotateEntity(i,Random(360),Random(360),Random(360))
Next
Repeat
While WindowEvent():Wend
ExamineMouse()
ExamineKeyboard()
a+0.005
For i=1 To #MeshNumber
ai=a+i*2*#PI/#MeshNumber
MoveEntity(i,#Gap *Cos(ai),0,#Gap *Sin(ai),#PB_Absolute)
RotateEntity(i,0.2,0.3,0.5,#PB_Relative)
Next
RenderWorld()
FlipBuffers()
Until MouseButton(#PB_MouseButton_Left) Or KeyboardReleased(#PB_Key_Escape)