Get face normals rendering
This commit is contained in:
parent
f28e6e08df
commit
296af144ce
5 changed files with 90 additions and 41 deletions
|
@ -27,19 +27,30 @@ typedef struct
|
|||
{
|
||||
float4 position [[position]];
|
||||
float3 normal;
|
||||
float4 color;
|
||||
float2 texCoord;
|
||||
} ColorInOut;
|
||||
|
||||
#pragma mark - Geometry Shaders
|
||||
|
||||
vertex ColorInOut vertexShader(Vertex in [[stage_in]],
|
||||
constant packed_float3 *faceNormals [[buffer(BufferIndexFaceNormals)]],
|
||||
constant Uniforms &uniforms [[buffer(BufferIndexUniforms)]])
|
||||
constant float3 *faceNormals [[buffer(BufferIndexFaceNormals)]],
|
||||
constant Uniforms &uniforms [[buffer(BufferIndexUniforms)]],
|
||||
uint vid [[vertex_id]])
|
||||
{
|
||||
ColorInOut out;
|
||||
|
||||
out.position = uniforms.projectionMatrix * uniforms.modelViewMatrix * float4(in.position, 1.0);
|
||||
out.normal = uniforms.normalMatrix * in.normal;
|
||||
float4 vertexCoords = float4(in.position, 1.0);
|
||||
float4 eyeCoords = uniforms.modelViewMatrix * vertexCoords;
|
||||
out.position = uniforms.projectionMatrix * eyeCoords;
|
||||
|
||||
float3 normal = normalize(uniforms.normalMatrix * in.normal);
|
||||
out.normal = normal;
|
||||
|
||||
float3 lightDirection = -eyeCoords.xyz;
|
||||
float lightDotNormal = dot(normal, lightDirection);
|
||||
out.color = float4(abs(lightDotNormal) * float3(0.3), 1.0);
|
||||
|
||||
out.texCoord = in.texCoord;
|
||||
|
||||
return out;
|
||||
|
@ -49,20 +60,14 @@ fragment float4 fragmentShader(ColorInOut in [[stage_in]],
|
|||
constant Uniforms & uniforms [[ buffer(BufferIndexUniforms) ]],
|
||||
texture2d<half> colorMap [[ texture(TextureIndexColor) ]])
|
||||
{
|
||||
constexpr sampler colorSampler(mip_filter::linear,
|
||||
mag_filter::linear,
|
||||
min_filter::linear);
|
||||
|
||||
half4 colorSample = colorMap.sample(colorSampler, in.texCoord.xy);
|
||||
|
||||
return float4(1.0);
|
||||
return in.color;
|
||||
}
|
||||
|
||||
#pragma mark - Normal Shaders
|
||||
|
||||
vertex float4 normalVertexShader(constant packed_float3 *positions [[buffer(BufferIndexMeshPositions)]],
|
||||
constant packed_float3 *normals [[buffer(BufferIndexNormals)]],
|
||||
constant Uniforms &uniforms [[buffer(BufferIndexUniforms)]],
|
||||
vertex float4 normalVertexShader(constant packed_float3 *positions [[buffer(NormalBufferIndexPoints)]],
|
||||
constant packed_float3 *normals [[buffer(NormalBufferIndexNormals)]],
|
||||
constant Uniforms &uniforms [[buffer(NormalBufferIndexUniforms)]],
|
||||
uint instID [[instance_id]],
|
||||
uint vertID [[vertex_id]])
|
||||
{
|
||||
|
@ -71,7 +76,7 @@ vertex float4 normalVertexShader(constant packed_float3 *positions [[buffer(Buff
|
|||
{
|
||||
v += 0.25 * normals[instID];
|
||||
}
|
||||
float4 out = uniforms.projectionMatrix * uniforms.modelViewMatrix * float4(v, 1.0);
|
||||
float4 out = uniforms.projectionMatrix * uniforms.modelViewMatrix * float4(v, 1);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue