[SOLVED] No shadow, light goes throught model

Get answers to all your basic programming questions. No Ogre questions, please!
Post Reply
2ant
Gnoblar
Posts: 13
Joined: Wed Jan 25, 2023 2:20 pm

[SOLVED] No shadow, light goes throught model

Post by 2ant »

Hi, i'm new with Ogre and i tried puting a spotlight in a basic scene and the light goes throught the model and doesn't cast shadow.

Image

Code: Select all

from Ogre._Ogre import PF_X8R8G8B8, PF_DEPTH16, PF_DEPTH32

import Ogre
import Ogre.Bites
import Ogre.RTShader

def main():
    ctx = Ogre.Bites.ApplicationContext("PySample")

    ctx.initApp()

    root = ctx.getRoot()
    scn_mgr = root.createSceneManager()
    scn_mgr.shadowTechnique = Ogre.SHADOWTYPE_STENCIL_ADDITIVE


    shadergen = Ogre.RTShader.ShaderGenerator.getSingleton()
    shadergen.addSceneManager(scn_mgr)  # must be done before we do anything with the scene

    scn_mgr.setShadowTextureCountPerLightType(Ogre.Light.LT_SPOTLIGHT, 1 )
    scn_mgr.setShadowTextureSettings(1024, 1, PF_X8R8G8B8);
    scn_mgr.setShadowFarDistance(500)
    scn_mgr.setShadowTexturePixelFormat(PF_DEPTH32)
    scn_mgr.setShadowCameraSetup(Ogre.FocusedShadowCameraSetup.create())


    light = scn_mgr.createLight("MainLight",Ogre.Light.LT_SPOTLIGHT)
    light.setCastShadows(True)
    light.diffuseColour = (0.0, 0.0, 1.0)
    light.specularColour = (0.0, 0.0, 1.0)
    lightnode = scn_mgr.getRootSceneNode().createChildSceneNode()
    lightnode.setPosition(0, 2, 5)
    lightnode.attachObject(light)

    cam = scn_mgr.createCamera("myCam")
    cam.setNearClipDistance(5)
    cam.setAutoAspectRatio(True)
    camnode = scn_mgr.getRootSceneNode().createChildSceneNode()
    camnode.setPosition(0, 20, 0)
    camnode.attachObject(cam)


    # map input events to camera controls
    camman = Ogre.Bites.CameraMan(camnode)

    camman.setStyle(Ogre.Bites.CS_ORBIT)
    #camman.setYawPitchDist(0, 0.3, 50)
    ctx.addInputListener(camman)

    # and tell it to render into the main window
    vp = ctx.getRenderWindow().addViewport(cam)
    vp.setBackgroundColour((.3, .3, .3))

    # finally something to render
    ent = scn_mgr.createEntity("Sinbad.mesh")
    ent.setCastShadows(True)
    node = scn_mgr.getRootSceneNode().createChildSceneNode()
    node.attachObject(ent)


    node3 = scn_mgr.getRootSceneNode().createChildSceneNode()

    plane = Ogre.Plane((0, 1, 0,0))

    mm = Ogre.MeshManager.getSingleton()
    mm.createPlane('ground', Ogre.ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME,
                   plane, 100, 100, 20, 20, True, 1, 1, 1, (0, 0, 1))

    ent3 = scn_mgr.createEntity("GroundEntity", "ground")
    ent3.setMaterialName("Examples/GrassFloor")
    ent3.setCastShadows(True)
    node3.attachObject(ent3)
    node3.translate((0, 0, -5))

    root.startRendering() # blocks until queueEndRendering is called

    ctx.closeApp()

if __name__ == "__main__":
    main()

What do i miss ?

Last edited by 2ant on Thu Feb 02, 2023 2:57 pm, edited 1 time in total.
User avatar
sercero
Bronze Sponsor
Bronze Sponsor
Posts: 450
Joined: Sun Jan 18, 2015 4:20 pm
Location: Buenos Aires, Argentina
x 156

Re: No shadow, light goes throught model

Post by sercero »

I think you should perhaps play more with the Spotlight parameters, because what you are seeing is perfectly possible with a spotlight

Another thing you could try is another type of light to see if there are no problems with the shaders or the scene in general.

A directional light will be a good test of shadows.

paroj
OGRE Team Member
OGRE Team Member
Posts: 1995
Joined: Sun Mar 30, 2014 2:51 pm
x 1075
Contact:

Re: No shadow, light goes throught model

Post by paroj »

Code: Select all

scn_mgr.shadowTechnique = Ogre.SHADOWTYPE_STENCIL_ADDITIVE

this is not a valid usage of Ogre. You must use setShadowTechnique

2ant
Gnoblar
Posts: 13
Joined: Wed Jan 25, 2023 2:20 pm

Re: No shadow, light goes throught model

Post by 2ant »

Thank you for your ideas sercero, my specific problem was syntax related.

Thank you paroj, i'm trying some stuff and the pyOgre examples sometimes have other syntaxes and pycharm does not always show an error and i have only partial autocomplete.

Using

Code: Select all

scn_mgr.setShadowTechnique (Ogre.SHADOWTYPE_STENCIL_ADDITIVE)

fixed my problem but now i have a new question that i will make another post for.

Post Reply