Advertisement
Guest User

Untitled

a guest
May 9th, 2018
430
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 2.86 KB | None | 0 0
  1. --- a/MetalTexturedMesh/AAPLMathUtilities.m
  2. +++ b/MetalTexturedMesh/AAPLMathUtilities.m
  3. @@ -314,7 +314,7 @@ quaternion_float quaternion_slerp(quaternion_float q0, quaternion_float q1, floa
  4.      return q0 * cosf(angleInc) + q2 * sinf(angleInc);
  5.  }
  6.  
  7. -vector_float3 AAPL_SIMD_OVERLOAD quaternion_rotate_vector(quaternion_float q, vector_float3 v) {
  8. +vector_float3  quaternion_rotate_vector(quaternion_float q, vector_float3 v) {
  9.  
  10.      vector_float3 qp = vector_make(q.x, q.y, q.z);
  11.      float w = q.w;
  12. diff --git a/MetalTexturedMesh/Renderer.swift b/MetalTexturedMesh/Renderer.swift
  13. index 549a082..760d1e9 100644
  14. --- a/MetalTexturedMesh/Renderer.swift
  15. +++ b/MetalTexturedMesh/Renderer.swift
  16. @@ -40,7 +40,7 @@ class Renderer : NSObject, MTKViewDelegate
  17.          // Clear to solid white
  18.          view.clearColor = MTLClearColorMake(1, 1, 1, 1)
  19.          // Use a BGRA 8-bit normalized texture for the drawable
  20. -        view.colorPixelFormat = .bgra8Unorm
  21. +        view.colorPixelFormat = .bgra8Unorm_srgb
  22.          // Use a 32-bit depth buffer
  23.          view.depthStencilPixelFormat = .depth32Float
  24.  
  25. diff --git a/MetalTexturedMesh/Shaders.metal b/MetalTexturedMesh/Shaders.metal
  26. index 2308954..c5ee748 100644
  27. --- a/MetalTexturedMesh/Shaders.metal
  28. +++ b/MetalTexturedMesh/Shaders.metal
  29. @@ -50,15 +50,5 @@ fragment half4 fragment_lit_textured(VertexOut fragmentIn [[stage_in]],
  30.                                       texture2d<float, access::sample> tex2d [[texture(0)]],
  31.                                       sampler sampler2d [[sampler(0)]])
  32.  {
  33. -    // Sample the texture to get the surface color at this point
  34. -    half3 surfaceColor = half3(tex2d.sample(sampler2d, fragmentIn.texCoords).rrr);
  35. -    // Re-normalize the interpolated surface normal
  36. -    half3 normal = normalize(half3(fragmentIn.normal));
  37. -    // Compute the ambient color contribution
  38. -    half3 color = ambientLightIntensity * surfaceColor;
  39. -    // Calculate the diffuse factor as the dot product of the normal and light direction
  40. -    float diffuseFactor = saturate(dot(normal, -lightDirection));
  41. -    // Add in the diffuse contribution from the light
  42. -    color += diffuseFactor * diffuseLightIntensity * surfaceColor;
  43. -    return half4(color, 1);
  44. +    return half4(0, 0.157, 0.202, 1);
  45.  }
  46. diff --git a/MetalTexturedMesh/ViewController.swift b/MetalTexturedMesh/ViewController.swift
  47. index c286161..516d70a 100644
  48. --- a/MetalTexturedMesh/ViewController.swift
  49. +++ b/MetalTexturedMesh/ViewController.swift
  50. @@ -17,7 +17,8 @@ class ViewController: NSViewController {
  51.          super.viewDidLoad()
  52.  
  53.          let metalView = self.view as! MTKView
  54. -
  55. +        metalView.colorPixelFormat = .bgra8Unorm_srgb
  56. +        NSLog("color pixel format is \(metalView.colorPixelFormat)");
  57.          // We initialize our renderer object with the MTKView it will be drawing into
  58.          renderer = Renderer(mtkView:metalView)
  59.      }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement