Help us understand the problem. What is going on with this article?

vs2010でmanaged directx その16

More than 1 year has passed since last update.

概要

c#で、3Dやりたかった。
shadertoyのコードを移植してみた。

写真

image

サンプルコード

#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();
    }
}


以上。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away