• Dear Cerberus X User!

    As we prepare to transition the forum ownership from Mike to Phil (TripleHead GmbH), we need your explicit consent to transfer your user data in accordance with our amended Terms and Rules in order to be compliant with data protection laws.

    Important: If you accept the amended Terms and Rules, you agree to the transfer of your user data to the future forum owner!

    Please read the new Terms and Rules below, check the box to agree, and click "Accept" to continue enjoying your Cerberus X Forum experience. The deadline for consent is April 5, 2024.

    Do not accept the amended Terms and Rules if you do not wish your personal data to be transferred to the future forum owner!

    Accepting ensures:

    - Continued access to your account with a short break for the actual transfer.

    - Retention of your data under the same terms.

    Without consent:

    - You don't have further access to your forum user account.

    - Your account and personal data will be deleted after April 5, 2024.

    - Public posts remain, but usernames indicating real identity will be anonymized. If you disagree with a fictitious name you have the option to contact us so we can find a name that is acceptable to you.

    We hope to keep you in our community and see you on the forum soon!

    All the best

    Your Cerberus X Team

shadows

Rich

Well-known member
CX Code Contributor
3rd Party Module Dev
Tutorial Author
3rd Party Tool Dev
Joined
Sep 9, 2017
Messages
451
Hi
Is there an example for shadows please?
I think i remeber an example of primitives casting shadows, but cant find it in the examples folder
thankyou
Rich
 
It is a mojo2 example.

examples/mojo2/rendererdemo

544
 
thank you... guess what im playing with tonight ;-)
 
i was playing with the renderdemo last night with success... I'm not sure it was the simplest of examples especially when canvas has built in methods like SetLightPosition() etc, so i decided to play with the canvas methods this morning with mixed results.

Im trying to use canvas.SetShadowMap(Image) and not getting any shadows..
I have the below block of code.
Code:
Strict

Import mojo2

Class myClass Extends App
    Field canvas:Canvas

    Field fore_img:Image
    Field fore_cnvs:Canvas
    
    Field back_img:Image
    Field back_cnvs:Canvas
    
    Field block_img:Image
    
    Method OnCreate:Int()
        ' load in default demo tile
        block_img = Image.Load("t3.png")

        ' Set up random for ground       
        fore_img = New Image(400,400,0,0)
        fore_cnvs = New Canvas(fore_img)
        fore_cnvs.Clear(0,0,0,0)
        fore_cnvs.SetColor 0,0,0,1
        Local i:Int=0
        While i<20
        fore_cnvs.DrawRect(Rnd(400),Rnd(400),32,32)
        i=i+1
        Wend
        fore_cnvs.Flush()
        
        ' set up background
        back_img = New Image(400,400,0,0)
        back_cnvs = New Canvas(back_img)
        back_cnvs.SetAmbientLight(0.5,0.5,0.5,0.5)
        back_cnvs.SetLightPosition(0,100,100,-100)
        back_cnvs.SetLightColor(0,1,.5,1)
        back_cnvs.SetLightRange(0,400)
        back_cnvs.SetLightType(0,1)
'        back_cnvs.SetShadowMap(fore_img)
        back_cnvs.Flush()
        
        SetUpdateRate(60)               
        canvas = New Canvas
        Return 0
    End
    
    Method DrawBack:Void()
         back_cnvs.Clear(0,0,0,0)
        
        Local y:Int=0
        While y<400
        Local x:Int=0
        While x<400
        back_cnvs.DrawImage block_img,x,y
        x=x+128
        Wend
        y=y+128
        Wend
    End

    Method OnUpdate:Int()
        Return 0
    End
    
    Method OnRender:Int()
        ' Clear the canvas with a black color.
        canvas.Clear (0,0.5,0)   

        ' position light       
        back_cnvs.SetLightPosition(0,MouseX(),MouseY(),-100)
        
        ' draw background
        DrawBack()
        back_cnvs.Flush()

        ' draw back and fore to cnvs
        canvas.DrawImage back_img,0,0
        canvas.DrawImage fore_img,0,0
                
        ' draw cnvs
        canvas.Flush

        Return 0
    End
End

Function Main:Int()
    New myClass       
    Return 0
End

im expecting the fore_img to cast shadows onto the back_img. It uses the default demo t3.png for its normals etc
Line 40 sets the shadow map

With line 40...
545


without line 40..
546


Is the shadow map a different coord system? Where are my shadows?
Im assuming Im issing something very obvious

Has anyone got a demo of canvas.SetShadowMap please?

Rich
 
Ive played around with it a bit more.
This time i drew black sqaures onto a white background

Cerberus:
        ' Set up random for ground      
        fore_img = New Image(400,400,0,0)
        fore_cnvs = New Canvas(fore_img)
        fore_cnvs.Clear(1,1,1)
        fore_cnvs.SetColor 0,0,0
        Local i:Int=0
        While i<20
            fore_cnvs.DrawRect(Rnd(400),Rnd(400),32,32)
            i=i+1
        Wend
        fore_cnvs.Flush()
and then dont draw it on top of back_img

Now i get this
547

It looks like the ShadowMap is just a static shadow image that I have to build and doesnt change based on light sources.
Not what i was expecting.
Looks like i need to work with shadowcasters still...
 
Yeah, I am wondering too. Debugging the source didn't give me any clue.
 
Thanks for looking.

canvas.AddShadowCaster(shadowCaster,0,0) doesnt do anything to the output when I flush the canvas to the image.
Ive also tried canvas.Render() and have the same output (just textured floor with a single light)

Lights seem to work, but not shadows.
Do Shadows work with Canvas's or just Renderers?
 
I recall having to do some head scratching when re-writing the demo. If shadows generally don't work as they should it would be worth knowing for sure.
 
Last edited:
The shadowcaster approach is working fine. The shadowmap feature of images and drawlists are a myth at the moment.
 
Back
Top Bottom