A few misc cleanup things
- Render normals every frame for now - Pass 3x3 normal matrix as the top-left 3x3 submatrix of the viewModel matrix - Slightly darken the light
This commit is contained in:
parent
08094b4302
commit
4d61d05f4d
2 changed files with 5 additions and 9 deletions
|
@ -220,11 +220,9 @@ class Renderer: NSObject, MTKViewDelegate {
|
|||
uniforms[0].modelViewMatrix = modelViewMatrix
|
||||
rotation += 0.003
|
||||
|
||||
// Remove the fourth row and column from our model-view matrix and find its inverse-transpose, if it exists.
|
||||
// Remove the fourth row and column from our model-view matrix. Since we're only doing rotations and translations (no scales), this serves as our normal transform matrix.
|
||||
let rotSclModelViewMatrix = float3x3(modelViewMatrix.columns.0.xyz, modelViewMatrix.columns.1.xyz, modelViewMatrix.columns.2.xyz)
|
||||
if rotSclModelViewMatrix.determinant != 0 {
|
||||
uniforms[0].normalMatrix = rotSclModelViewMatrix.inverse.transpose
|
||||
}
|
||||
uniforms[0].normalMatrix = rotSclModelViewMatrix
|
||||
|
||||
uniforms[0].terrainDimensions = terrain.dimensions
|
||||
uniforms[0].terrainSegments = terrain.segments
|
||||
|
@ -266,10 +264,8 @@ class Renderer: NSObject, MTKViewDelegate {
|
|||
didScheduleAlgorithmIteration = true
|
||||
}
|
||||
|
||||
if didScheduleAlgorithmIteration || needsGeometryUpdate {
|
||||
terrain.scheduleGeometryUpdates(inCommandBuffer: commandBuffer, uniforms: dynamicUniformBuffer, uniformsOffset: uniformBufferOffset)
|
||||
}
|
||||
|
||||
terrain.scheduleGeometryUpdates(inCommandBuffer: commandBuffer, uniforms: dynamicUniformBuffer, uniformsOffset: uniformBufferOffset)
|
||||
|
||||
/// Delay getting the currentRenderPassDescriptor until we absolutely need it to avoid
|
||||
/// holding onto the drawable and blocking the display pipeline any longer than necessary
|
||||
let renderPassDescriptor = view.currentRenderPassDescriptor
|
||||
|
|
|
@ -49,7 +49,7 @@ vertex ColorInOut vertexShader(Vertex in [[stage_in]],
|
|||
|
||||
float3 lightDirection = -eyeCoords.xyz;
|
||||
float lightDotNormal = dot(normal, lightDirection);
|
||||
out.color = float4(abs(lightDotNormal) * float3(0.3), 1.0);
|
||||
out.color = float4(abs(lightDotNormal) * float3(0.2), 1.0);
|
||||
|
||||
out.texCoord = in.texCoord;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue