-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pass lights into the shader in drawObject.ts
.
#11
Conversation
drawObject.ts
.drawObject.ts
.
src/renderer/commands/drawObject.ts
Outdated
*/ | ||
export function drawObject( | ||
regl: REGL.regl | ||
regl: REGL.regl, | ||
numLights: number = 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we can make numLights
be a prop we pass in? so like the regl.prop( ... )
things from before. regl.prop('something')
is a shortcut for (context, props, batchId) => props['something']
, so we can maybe use a function like that to do the numLights
assertion
src/renderer/commands/drawObject.ts
Outdated
'lightIntensities[0]': 256, | ||
'lightColors[0]': [1, 1, 1] | ||
numLights: numLights, | ||
...buildLightMetadata(numLights, maxLights) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we also add information about lights to the parameters that get passed in? so like defining an interface for a light containing a position, intensity, and color that you can use when building metadata instead of always using multiple copies of the hardcoded light I had before
src/renderer/commands/drawObject.ts
Outdated
* Shader to draw a single object with Phong shading to the screen | ||
* Shader to draw a single object with Phong shading to the screen. | ||
* | ||
* @param {REGL.regl} regl: The regl object we're drawing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: regl
is like a factory to build a function to draw an object rather than the object being drawn
src/renderer/commands/drawObject.ts
Outdated
|
||
return visibleLightsJSON | ||
.concat(nonVisibleLightsJSON) | ||
.reduce((accum: {}, obj: {}) => { return { ...accum, ...obj }; }, {}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌
src/renderer/commands/drawObject.ts
Outdated
): REGL.DrawCommand<REGL.DefaultContext, DrawObjectProps> { | ||
if (numLights > maxLights) { | ||
throw new RangeError('numLights must be less than or equal to maxLights.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we put the actual number of lights at the end of the error message? And maybe the requested number of lights?
I'm not sure if it's bad practice to make the error message dynamic like that, but I think it would be useful to have
"numLights (24) must be less than or equal to maxLights (20)"
src/renderer/Renderer.ts
Outdated
* @param {REGL.Vec3} lightPositions A vector of length 3 denoting the x, y, z point where the light resides in the | ||
* vector-space. | ||
* @param {REGL.Vec3} lightColors A vector of length 3 denoting _. | ||
* @param {REGL.Vec3} lightIntensities A vector of length 3 denoting _. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use some help with these descriptions @davepagurek 😳
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lightColor
is avec3
representing the r, g, and b values of the light's color, where each channel is in [0, 1]lightIntensity
is a number affecting specular reflection where a lower number produces a softer, larger reflection and a higher number produces a smaller, harder reflection
src/renderer/commands/drawObject.ts
Outdated
@@ -64,7 +66,7 @@ export function drawObject( | |||
frag: ` | |||
precision mediump float; | |||
|
|||
const int MAX_LIGHTS = 1; // TODO(davepagurek) [#10] Increase this to allow more lights | |||
const int MAX_LIGHTS = ${regl.prop('maxLights')}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is currently giving me an error. I'm a bit unfamiliar with regl
, so I'd appreciate any help @davepagurek.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is because regl.prop('maxLights')
returns a function, not a value. I think you just want maxLights
directly since it's passed in at the shader's compile time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so actually I think keeping maxLights
as a second argument in addition to a regl instance is good
import REGL = require('regl'); | ||
|
||
export interface LightMetadata { | ||
lightPositions: REGL.Vec3[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since this is the data for one light (maybe just call it Light
?), these properties should be singular, i.e. lightPosition: REGL.Vec3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. 👍
|
||
export const blankLightMetadata: LightMetadata = { | ||
lightPositions: [0, 0, 0], | ||
lightIntensities: [0, 0, 0], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Intensity should just be a scalar instead of an array. Unfortunately it looks like typescript is bad at actually typechecking REGL.anything
types
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, my linter was complaining. Should it be lightIntensities
or just lightIntensity
then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just the singular I think
src/renderer/commands/drawObject.ts
Outdated
const visibleLightsJSON: {}[] = range(maxLights).map((index: number) => { | ||
return { | ||
[`lightPositions[${index}]`]: (_context, props, _batch_id) => { | ||
const light: LightMetadata = props.lights[index]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think technically the type for light
here would be LightMetadata | undefined
lightIntensity: 256 | ||
} | ||
|
||
xdescribe('addLight', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/renderer/Renderer.ts
Outdated
}) | ||
indices: o.indices, | ||
numLights: this.lights.length, | ||
maxLights: this.maxLights, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tiny nit: we can take out maxLights
here since we pass it in along with regl
earlier so this prop doesn't get used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one small change taking out a prop we don't use, after that lgtm!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[DELETED]
Pass lights into the shader in `drawObject.ts`.
Changes
drawObject.ts
#10Renderer
class, and change them dynamically at runtime (i.e., with theaddLight
andremoveLight
methods)Examples
One Light
Two Lights