Single Mesh using UV2 for Advanced Multi-texturing

👉 BlitzCoder will be building a new platform and other plans to preserve and continue the Blitz legacy.

To be able to achieve this goal, we need your support by becoming a Patreon Paid Member 👈


Tweet blitz3d code-archives tutorials mesh

I noticed a lot of effects like this by fredborg rely on at least 2 meshes on top using copymesh and entity blending to achieve their results.

This is still a proof of concept and simple demo to use UV2 and masking to just use a single mesh to achieve the same effect.


; Multi-Mesh vs Single (using UV2) for Advanced Multi-texturing Capabilities
; By RonTek

Graphics3D 640,480,0,2 

; Mask
size = 64
Global mask = CreateTexture(size,size,1+2)
ScaleTexture mask,.25,.25 ; let's do stripes
TextureBlend mask,3 ; inverts black to white for multiply


Color 255,255,255
For y = 0 To size-1 
    For x = 0 To size-1
        If y = (size/2)-1 Then Color 0,0,0
        Plot x,y

SetBuffer BackBuffer()

Type MatMesh
    Field mesh
    Field submesh
End Type

CameraClsColor camera,100,150,250
RotateEntity light,45,45,0 

cube1 = mat(CreateSphere(32))
cube2 = mat2(CreateSphere(32))

PositionEntity cube1,-2,0,5
PositionEntity cube2,2,0,5

Color 255,255,255

While Not KeyDown( 1 )

    TurnEntity cube1,.5,.5,.5
    TurnEntity cube2,.5,.5,.5
    WireFrame KeyDown(17)


    Text 10,FontHeight()*1,"Tris: "+TrisRendered()
    Text 10,FontHeight()*2.5,"Left: Multi-Mesh"
    Text 10,FontHeight()*4,"Right: Single Mesh (UV2)"



; Proof of Concept, Single Mesh using UV2
Function mat2(mesh)

    EntityFX mesh,1

    red = CreateTexture(2,2)
    Color 255,0,0
    Oval 0,0,2,2,1
    SetBuffer BackBuffer()  
    TextureCoords red,0 ; set to default UV1
    EntityTexture mesh,red,0,0

    yel = CreateTexture(2,2)
    Color 255,255,0
    Oval 0,0,2,2,1
    SetBuffer BackBuffer()  

    TextureCoords mask,1 ; now setting to UV2
    EntityTexture mesh,mask,0,1

    EntityTexture mesh,yel,0,2

    Return mesh

End Function

; Old Method using another mesh (CopyMesh) on top with Blending
Function mat(mesh)
    entity.MatMesh = New MatMesh

    EntityFX mesh,1

    entity\mesh = mesh
    EntityColor entity\mesh,255,255,0

    entity\submesh = CopyMesh(mesh,mesh)
    ;entity\submesh = CreateSphere(8,mesh) Lower resolution option
    EntityFX entity\submesh,1   
    EntityColor entity\submesh,255,0,0
    mask2 = mask    
    EntityBlend entity\submesh,2 ; multiply to hide white
    EntityTexture entity\submesh,mask2
    EntityFX    entity\submesh,1

    Return entity\mesh
End Function

Reply To Topic (minimum 10 characters)

Please log in to reply