shadow system

I am trying to use the shadow mapping system in my game. I have several different displayRegions, but I only want shadows in one of them (my main displayRegion). This is the window I want my shadows in:

        # Camera setup
        self.my_cam3 = Camera("cam3") 
        self.my_camera3 = render.attachNewNode(self.my_cam3) 
        self.my_camera3.setName("camera3")
        self.my_camera3.setPos(0,-20,155)
        self.my_camera3.lookAt(self.Mod1)
        self.my_camera3.node().getLens().setAspectRatio(4.0/2.0)
        
        # Disable the default DisplayRegion, which covers the whole screen. 
        self.dr = base.camNode.getDisplayRegion(0) 
        self.dr.setActive(0) # disable ( use displayRegion 0 )
            
        # DisplayRegions. 
        self.window = self.dr.getWindow() 
        self.dr3 = self.window.makeDisplayRegion(0.026, 0.975, 0.35, 0.98) 
        self.dr3.setSort(self.dr.getSort())

        # Setup camera. 
        self.dr3.setCamera(self.my_camera3)

So now my main camera is self.my_camera3.

This is the part of the shadow system I need help with:

       self.LCam = base.makeCamera(LBuffer)
        self.LCam.node().setScene(render)
        self.LCam.node().getLens().setFov(40)
        self.LCam.node().getLens().setNearFar(10,100)

        # default values
        self.pushBias = 1
        self.ambient = 0.2
        self.cameraSelection = 0
        self.lightSelection = 0
    
        # setting up shader
        render.setShaderInput('light',self.LCam)
        render.setShaderInput('Ldepthmap',Ldepthmap)
        render.setShaderInput('ambient',self.ambient,0,0,1.0)
        render.setShaderInput('texDisable',0,0,0,0)
        render.setShaderInput('scale',1,1,1,1)
        render.setShaderInput('push',self.pushBias,self.pushBias,self.pushBias,0)
    
        # Put a shader on the Light camera.
        lci = NodePath(PandaNode("Light Camera Initializer"))
        lci.setShader(Shader.load('caster.sha'))
        self.LCam.node().setInitialState(lci.getState())
    
        # Put a shader on the Main camera.
        # Some video cards have special hardware for shadow maps.
        # If the card has that, use it.  If not, use a different
        # shader that does not require hardware support.

        mci = NodePath(PandaNode("Main Camera Initializer"))
        if (base.win.getGsg().getSupportsShadowFilter()):
            mci.setShader(Shader.load('shadow.sha'))
        else:
            mci.setShader(Shader.load('shadow-nosupport.sha'))
        base.cam.node().setInitialState(mci.getState())

How would I get this to work on my display window?

Can I get help from one of the moderators please?
This is the second question I posted and have not got any help.
I don’t know if what I posted was confusing or stupid, but I tried to put it as best as I could. I would really appreciated some help, because I need to use displayRegions, and I would really like to get the shadows and cartoon shaders demos used on my main window and camera. Please help.

Try putting the shader on the camera of your second display region:

self.my_cam3.setInitialState(mci.getState())

Instead of:

base.cam.node().setInitialState(mci.getState())

Isn’t it the exact problem the last time you want disp.reg + shader ??
You should have learned from it.

Thank you very much pro-rsoft.
I was putting this instead:

self.my_camera3.setInitialState(mci.getState())

I kept getting the error: AttributeError: ‘libpanda.my_camera3’ object has no attribute ‘setInitialState’

Could you give me a little input as to why this does not work even though it is attached to the camera (self.my_cam3)?

I tried what you said, but now my sky is black, and my water transparent. I believe this is because my light camera isn’t set right.
I have this light as my sun:

        # Light1 - Sunlight
        self.Light1 = PointLight('light1') 
        self.Light1.setColor(VBase4(2.5, 2.5, 2.5, 1)) 
        self.pointLight1 = render.attachNewNode(self.Light1) 
        self.pointLight1.setPos(0, 0, 300) 

When I replace

self.LCam.setInitialState(lci.getState())

with

self.Light1.setInitialState(lci.getState())

or

self.pointLight1.setInitialState(lci.getState())

I get this error:
AttributeError: ‘libpanda.PointLight’ object has no attribute ‘setInitialState’

Any idea how I might correct that?

Thanks for the correction ynjh_jo, but give a novice a break. I did look at that post, but at the time it looked so different to what I was trying to do. From the vantage point of someone who’s learning (perhaps a little slowly), it’s not as simple as it appears to someone who is probably 10 times as advanced. So sometimes a little reminder like, “Hey, look here at this post!” Or, “Do this!” can help us to learn too. Everyone has some skill in something, but everyone isn’t able to master every skill. Where one excels above another in one skill, the other excels above him in another skill. Sorry, I sometimes get carried away. I do teaching, so I know it really calls for patience with some persons. Thanks though. I really do appreciate your input, and I have learned a lot from you.

self.my_cam3 is the actual Camera, self.my_camera3 is a NodePath pointing to that camera node. Check the manual about NodePaths & the scene graph for more info.

A camera is not a point light and a point light does not implement setState.
You need to create a camera in order to have shadows, normal lights cant cast shadows. In the case of a point light, you might be best off with a camera with a 180, 180 fov or so. (2 cameras if needed.)

I don’t see any shadows. My sky is now lighted, but my water is transparent. Shoud I remove my pointlight entirely and replace it with a camera? I have this:

        # Light1 - Sunlight
        self.Light1 = PointLight('light1') 
        self.Light1.setColor(VBase4(2.5, 2.5, 2.5, 1)) 
        self.pointLight1 = render.attachNewNode(self.Light1) 
        self.pointLight1.setPos(0, 0, 300) 
        
        # Camera setup 
        self.my_cam3 = Camera("cam3") 
        self.my_camera3 = render.attachNewNode(self.my_cam3) 
        self.my_camera3.setName("camera3") 
        self.my_camera3.setPos(0,-20,155) 
        self.my_camera3.lookAt(self.Mod1) 
        self.my_camera3.node().getLens().setAspectRatio(4.0/2.0) 
        
        # Disable the default DisplayRegion, which covers the whole screen. 
        self.dr = base.camNode.getDisplayRegion(0) 
        self.dr.setActive(0) # disable ( use displayRegion 0 ) 
            
        # DisplayRegions. 
        self.window = self.dr.getWindow() 
        self.dr3 = self.window.makeDisplayRegion(0.026, 0.975, 0.35, 0.98) 
        self.dr3.setSort(self.dr.getSort()) 

        # Setup camera. 
        self.dr3.setCamera(self.my_camera3)
        
        self.LCam = base.makeCamera(LBuffer)
        ## self.LCam.setPos(0,0,300)
        self.LCam.node().setScene(render)
        self.LCam.node().getLens().setFov(180)
        self.LCam.node().getLens().setNearFar(10,100)
        
        # default values
        self.pushBias = 1
        self.ambient = 0.2
        self.cameraSelection = 0
        self.lightSelection = 0
    
        # setting up shader
        render.setShaderInput('light',self.LCam)
        render.setShaderInput('Ldepthmap',Ldepthmap)
        render.setShaderInput('ambient',self.ambient,0,0,1.0)
        render.setShaderInput('texDisable',0,0,0,0)
        render.setShaderInput('scale',1,1,1,1)
        render.setShaderInput('push',self.pushBias,self.pushBias,self.pushBias,0)
    
        # Put a shader on the Light camera.
        lci = NodePath(PandaNode("Light Camera Initializer"))
        lci.setShader(Shader.load('caster.sha'))
        self.LCam.node().setInitialState(lci.getState())
    
        # Put a shader on the Main camera.
        # Some video cards have special hardware for shadow maps.
        # If the card has that, use it.  If not, use a different
        # shader that does not require hardware support.

        mci = NodePath(PandaNode("Main Camera Initializer"))
        if (base.win.getGsg().getSupportsShadowFilter()):
            mci.setShader(Shader.load('shadow.sha'))
        else:
            mci.setShader(Shader.load('shadow-nosupport.sha'))
        self.my_cam3.setInitialState(mci.getState())

If this is all I need then the problem lies somewhere else. If that’s the case, I’ll try to figure out what’s wrong.

OK I made a decision. I place a displayRegion in the shadow mapping demo just as it is in my game, and it worked, which means something is clashing somewhere else in my code. So I decided what I will do is gradually place all my codes in the shadow mapping demo. This way I can locate the problem, and get my shadows working. Thanks very much for your help pro-rsoft. I just have one last question on the shadow system. What is the cause of this error, and is there any way to remove it? (Sorry, that’s two questions)

:display:gsg:glgsg(error): at 2637 of c:\temp\mkpr\panda\src\glstuff\glGraphicsStateGuardian_src.cxx : GL error 1282

Woah, are you still using 1.5.2? 1.5.4 has already been released, in case you don’t know.

Hard to say what the error is in this case. It’s failing at the beginning of release_texture, so the actual error could be anywhere.

I didn’t want to upgrade until I had my shaders working. I will upgrade shortly though. I got my shadows working now, and so I am happy about that. I’d be a lot happier if I could get my cartoon shaders working also. The reason is I haven’t decided which I will eventually use. I love the cartoon shaders, but I’ll let my friends help me with the decision. Could you look at the post ‘Cartoon Shaders on Display Regions’ and help me out on that? I basically want a number of display regions affected by the shaders, but only one is showing up. I’d appreciate your help on this one also. Thanks