Login | Register 
FEATURES
APPLICATIONS
DOWNLOADS
EDUCATION
BLOG
WIKI
FORUM
STORE

Get position of light from lightcomp

General discussion about anything TouchDesigner

Get position of light from lightcomp

Postby acroscene » Thu Dec 06, 2018 7:25 pm

Hi!

Im doing the learnopengl.com tutorials for lights and have some problems figuring out how to get the position of the light from the lightcomp into my code.

Im passing the normals in worldspace from the vertex shader to the fragment shader for making the calculation in the fragment shader:

Code: Select all
   // Normals
   vec3 worldSpaceNorm = normalize(TDDeformNorm(N));
   oVert.worldSpaceNorm.xyz = worldSpaceNorm;
   
   // fragment position
   oVert.worldSpacePos.xyz = worldSpacePos.xyz;


I then passing the lightposition as an uniform into the shader but how can I pass in the position of the light from the light comp?

I have been reading this:
https://docs.derivative.ca/Write_a_GLSL ... c_Uniforms

but cannot get it right

thanks
Attachments
light.toe
(6.22 KiB) Downloaded 160 times
acroscene
 
Posts: 37
Joined: Fri Mar 10, 2017 3:47 pm

Re: Get position of light from lightcomp

Postby nettoyeur » Thu Dec 06, 2018 7:53 pm

edit: see malcolm's better answer below
Last edited by nettoyeur on Fri Dec 07, 2018 12:34 pm, edited 1 time in total.
Idzard Kwadijk | freelance TouchDesigner consultant | LinkedIn
Checkout ChopChopChop.org - the TouchDesigner marketplace!
nettoyeur
 
Posts: 970
Joined: Mon Oct 15, 2012 12:00 pm
Location: Amsterdam, The Netherlands

Re: Get position of light from lightcomp

Postby malcolm » Thu Dec 06, 2018 11:47 pm

Check out the docs here:
https://docs.derivative.ca/Write_a_GLSL_Material
specifically, the uTDLights uniform. That has the position already for you
User avatar
malcolm
Staff
 
Posts: 4223
Joined: Tue Nov 13, 2007 1:11 am

Re: Get position of light from lightcomp

Postby acroscene » Fri Dec 07, 2018 12:20 pm

So easy. It was all there. Sorry, didnt read properly ...

Code: Select all
uTDLights[0].position.xyz


As well as camera position for calculating specular light. For pulling the xyz position for the camera from the TDMatrix struct. Is it correct to write:
Code: Select all
uTDMats[0].cam[0].xyz


At least it doesnt give me any error and behaves more or less as expected.

Thanks
acroscene
 
Posts: 37
Joined: Fri Mar 10, 2017 3:47 pm

Re: Get position of light from lightcomp

Postby acroscene » Mon Dec 10, 2018 9:06 am

I was wrong.

Code: Select all
uTDMats[0].cam[0].xyz


doesnt provide me of the position of the camera from the cam comp and I cannot find it in the documentation.

My calculation for ambient diffuse and specular behaves as expected as long i hardcode the camera position i worldspace but I guess I can pull the position from the camera comp the same way as I can get the light position?

In the example below I have hardcoded the position.
Code: Select all
vec3 viewDir = normalize(uCamPos - iVert.worldSpacePos);


Is it possible to get it from the camcomp without creating my own uniform?
acroscene
 
Posts: 37
Joined: Fri Mar 10, 2017 3:47 pm

Re: Get position of light from lightcomp

Postby malcolm » Mon Dec 10, 2018 2:19 pm

The position of the camera can be obtained from

Code: Select all
uTDMats[TDCameraIndex()].camInverse[3].xyz


This is pulling out the translation values from the inverse camera matrix, which is the position of the camera.
User avatar
malcolm
Staff
 
Posts: 4223
Joined: Tue Nov 13, 2007 1:11 am


Return to General TouchDesigner Discussion

Who is online

Users browsing this forum: Google [Bot] and 12 guests