vs 2010 매니지먼트 directx의 16

개요
그리고 3D를 하고 싶어요.
shadertoy의 인코딩을 이식해 보았습니다.
사진.

샘플 코드
#define PI          3.14159265359
#define TWOPI       6.28318530718
struct VS_IN {
    float4 Pos: POSITION;
    float4 color: COLOR;
};
struct VS_OUT {
    float4 Pos: POSITION;
    float4 color: COLOR;
    float2 coord: TEXCOORD;
};
VS_OUT VSmain(VS_IN In)
{
    VS_OUT output = (VS_OUT) 0;
    output.Pos = In.Pos;
    output.color = In.color;
    output.coord = In.Pos.xy;
    return output;
}
float linearstep(float edge0, float edge1, float x)
{
    float t = (x - edge0) / (edge1 - edge0);
    return clamp(t, 0.0, 1.0);
}
float smootherstep(float edge0, float edge1, float x)
{
    float t = (x - edge0) / (edge1 - edge0);
    float t1 = t * t * t * (t * (t * 6. - 15.) + 10.);
    return clamp(t1, 0.0, 1.0);
}
void plot(float2 r, float y, float lineThickness, float3 color, inout float3 pixel)
{
    if (abs(y - r.y) < lineThickness) pixel = color;
}
float4 PSmain(VS_OUT In): COLOR
{
    float2 r = In.coord;
    float3 bgCol = float3(1.0, 1.0, 1.0);
    float3 axesCol = float3(0.0, 0.0, 1.0);
    float3 gridCol = float3(0.5, 0.5, 0.5);
    float3 col1 = float3(0.841, 0.582, 0.594);
    float3 col2 = float3(0.884, 0.850, 0.648);
    float3 col3 = float3(0.348, 0.555, 0.641);
    float3 pixel = bgCol;
    const float tickWidth = 0.1;
    float x = r.x;
    float y = r.y;
    if (abs(sin(PI * r.x) - y) < 0.02) pixel = col1;
    if (abs(0.25 * linearstep(-0.5, 0.5, x) + 0.1 - y) < 0.01) pixel = col3;
    if (abs(0.25 * smootherstep(-0.5, 0.5, x) - 0.9 - y) < 0.01) pixel = col3;
    plot(r, 0.5 * clamp(sin(TWOPI * x), 0.0, 1.0) - 0.7, 0.015, col2, pixel);
    plot(r, 0.6 * exp(-10.0 * (x + 0.8) * (x + 0.8)) - 0.1, 0.015, col2, pixel);
    return float4(pixel, 1.0);
}

technique MyTechnique
{
    pass MyPass
    {
        VertexShader = compile vs_2_0 VSmain();
        PixelShader = compile ps_2_0 PSmain();
    }
}


이상.

좋은 웹페이지 즐겨찾기