Skip to content

Instantly share code, notes, and snippets.

@dnevera
Created June 3, 2018 09:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dnevera/c73652fe3408356e6ffca781dcb08fbb to your computer and use it in GitHub Desktop.
Save dnevera/c73652fe3408356e6ffca781dcb08fbb to your computer and use it in GitHub Desktop.
using namespace metal;
#include <SceneKit/scn_metal>
// Стандартные параметры модели (узла)
typedef struct {
float4x4 modelTransform;
float4x4 modelViewTransform;
float4x4 normalTransform;
float4x4 modelViewProjectionTransform;
} NodeBuffer;
// Стандартные параметры вершины
typedef struct {
float3 position [[ attribute(SCNVertexSemanticPosition) ]];
float3 normal [[ attribute(SCNVertexSemanticNormal) ]];
} VertexInput;
// Результат вершинного шейдера
typedef struct {
float4 position [[position]];
float2 texCoords;
float3 rgb;
float3 surfaceColor;
} VertexOutput;
// Основной вершинный шейдер программы
vertex VertexOutput projectionVertex(VertexInput in [[ stage_in ]],
texture3d<float, access::sample> lut3d [[texture(0)]],
constant SCNSceneBuffer &scn_frame [[buffer(0)]],
constant NodeBuffer &scn_node [[buffer(1)]]
)
{
VertexOutput vert;
// конвертируем координаты [-1:1] в представление цветов: [0:1]
vert.rgb = (in.position+1) * 0.5;
// прикладываем LUT
vert.rgb = lut3d.sample(IMProcessing::lutSampler, vert.rgb).rgb;
// вычисляем новую позицию вершины
float3 pos = (vert.rgb - 0.5) * 2;
// позиционируем в соответствии с проекцией
vert.position = scn_node.modelViewProjectionTransform * float4(pos, 1.0);
return vert;
}
// Фрагментный шейдер программы
fragment float4 materialFragment(VertexOutput in [[stage_in]])
{
// текущий семпл
return float4(in.rgb, 0.6);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment