V3d_SpotLight setDirection doesn't work

Handle(Graphic3d_CLight) m_light =  new V3d_SpotLight(gp_Pnt(0.0, 0.0, 5000.0), V3d_XposYneg, Quantity_NOC_WHITE);
m_AISLightSource = new AIS_LightSource(m_light);

doesn't matter what I do, the spotlight always points down (z-). Also when I change with setDirection(gp_Dir(...));

the m_AISLightSource shows the cone in the correct given direction, but the light doesn't move at all. Position m_light is changing ok.

I have no problem with V3d_DirectionalLight

gkv311 n's picture

Could you share some reproducible sample and screenshots? Which OCCT version you are using?

In Draw Harness spotlight could be defined via vlight command, and both vlight NAME -dir DX DY DZ and interactive vmanipulator work as expected for me:

pload MODELING VISUALIZATION
vclear
vinit View1
vlight -clear
vbackground -color GRAY
vrenderparams -shadingModel PHONG
vlight amblight -type AMBIENT -color WHITE -intensity 0.1
box b 0 0 0 30 30 30
vdisplay b -dispMode 1
vsetmaterial b Brass
vfit
vlight spot -type SPOTLIGHT -pos 15 -10 15 -dir 0 1 0 -color RED -display
vmanipulator m -attach spot -adjustPosition location

I've also tried samples/qt/OCCTOverview sample and changing spotlight direction in samples/OCCTOverview/code/Viewer3dSamples.cxxseems to be worked:

void Viewer3dSamples::SpotLight3dSample()
{
  // Spot light source creation
  Handle(V3d_SpotLight) aSpotLight = 
    new V3d_SpotLight(gp_Pnt(100.0, 0.0, 0.0), gp_Dir(-1.0, 0.0, 0.0), Quantity_NOC_RED);
  aSpotLight->SetIntensity(5000);
  myView->SetLightOn(aSpotLight);

  aSpotLight->SetDirection(gp_Dir(-1.0, 0.0, 0.25));

  Handle(AIS_LigthSource) aPrs = new AIS_LigthSource(aSpotLight);
  myContext->Display(aPrs, true);
}

spot.png

Attachments: 
Daniel Duesentrieb's picture

In your example I only see the cone but not the light and shadow. This is working here as well.

Spot1.png = setPosition(0,0,3000) setDirection(gp_Dir(1,0,-1)

Spot2.png = setPosition(0,0,3000) setDirection(gp_Dir(1,0,0)

Spot3.png = setPosition(1000,0,3000) setDirection(gp_Dir(1,0,0)

Shadow makes no sense. To me it looks like V3d_SpotLight is behaving like a V3d_PositionalLight

m_light->SetConcentration
m_light->SetSmoothRadius
m_light->SetAttenuation

Whatever (in range) values I put in, nothing changes.

Other problem:

Handle(Graphic3d_CLight ) m_light = new V3d_SpotLight(gp_Pnt(0.0, 0.0, 5000.0), V3d_XposYneg, Quantity_NOC_WHITE);
m_light->SetCastShadows(true); << crash here

Thanks!

PS: using 7.9.0

Daniel Duesentrieb's picture

please see spot4.png. this is what your sample code is doing.

void Viewer3dSamples::SpotLight3dSample()
{
  // Spot light source creation
  Handle(V3d_SpotLight) aSpotLight = 
    new V3d_SpotLight(gp_Pnt(100.0, 0.0, 0.0), gp_Dir(-1.0, 0.0, 0.0), Quantity_NOC_RED);
  aSpotLight->SetIntensity(5000);
  myView->SetLightOn(aSpotLight);

  aSpotLight->SetDirection(gp_Dir(-1.0, 0.0, 0.25));

  Handle(AIS_LigthSource) aPrs = new AIS_LigthSource(aSpotLight);
  myContext->Display(aPrs, true);
}
Attachments: 
gkv311 n's picture

Shadow makes no sense. To me it looks like V3d_SpotLight is behaving like a V3d_PositionalLight

I see you are using Path Tracing in your screenshots. Indeed, Path-Tracing engine doesn't implement handling of Spot light sources - it treats them as positional sources (within OpenGl_View::updateRaytraceLightSources()). For that reason you'll not find such light sources in RayTracing, for example:

Daniel Duesentrieb's picture

thank you

will this work in the near future?
and what is the point of having V3d_SpotLight if it doesn't work?

gkv311 n's picture

and what is the point of having V3d_SpotLight if it doesn't work?

The list of light source types V3d_AmbientLight, V3d_PositionalLight, V3d_DirectionalLight, V3d_SpotLight originates from light sources that could be defined within legacy OpenGL API glLight(). And these types should still work within Phong and PBR shading models in OCCT viewer.

Path-Tracing engine has been added to OCCT Viewer later than light source API, and currently provides a mixture of properties, supported by legacy Phong (including non-physical properties like Graphic3d_CLight::LinearAttenuation()), by model PBR (like Graphic3d_CLight::Intensity()) and Path-Tracing engines (see Ray-Tracing / Path-Tracing light properties section within Graphic3d_CLight documentation).

I cannot say why Spot light source type hasn't been implemented within Path-Tracing engine - maybe developers haven't considered it useful enough, or postponed implementation for later and forgotten...

Daniel Duesentrieb's picture

Thank you for taking the time to explain.
So there is still hope that this will come one day.

Daniel Duesentrieb's picture

Found a workaround. Better then nothing:

Put a positional light into a cylinder and control the radius with adjusting the z of the light withing the cylinder. looks kind of ok.

Attachments: