//================================================================== // // //================================================================== //================================================================== // 定数 //================================================================== Texture2D g_texture_diffuse; float4 g_Outline; // 顔の矩形 float4 g_DrawUV; // 描画する際のトリミング位置. float4 g_Volume; // 各エフェクトかかり具合. float4 g_ScreenSize; //================================================================== // 定数(2) ※シェーダー内のみ //================================================================== // サンプルステート SamplerState samLinear { Filter = MIN_MAG_MIP_LINEAR; AddressU = Wrap; AddressV = Wrap; }; SamplerState samPoint { Filter = MIN_MAG_MIP_POINT; AddressU = Wrap; AddressV = Wrap; }; SamplerState samPointMipLinear { Filter = MIN_MAG_POINT_MIP_LINEAR; AddressU = Wrap; AddressV = Wrap; }; //================================================================== // グローバル変数(設定) //================================================================== // ライト(nsEffect::stLightParam) cbuffer cbLightParam { float4 g_SR_light_diffuse; // ディヒューズカラー float4 g_SR_light_specular; // スペキュラカラー float4 g_SR_light_ambient; // アンビエントカラー float4 g_SR_light_direction; // 方向(ビュー空間座標) int g_SR_light_enable; // 有効かどうか float g_SR_light_constant_attenuation; // 一定減衰率 }; cbuffer cbSetUpModelData { matrix g_SR_matrix_wvp; // モデル→プロジェクション matrix g_SR_matrix_wv; // モデル→ビュー } cbuffer cbSetUpNodeData { matrix g_SR_matrix_model; // モデリング座標 } float leap( float start, float end, float per ) { float ret = start * per + end * ( 1.0f - per ); return ret; } /// ペジェ曲線. /// x1,y1始点 /// x2,y2制御点 /// x3,y3終点 float2 GetQB( float t, float x1, float y1, float x2, float y2, float x3, float y3 ) { float tp = 1 - t; float x = t*t*x3 + 2*t*tp*x2 + tp*tp*x1; float y = t*t*y3 + 2*t*tp*y2 + tp*tp*y1; return float2( x, y ); } /// ペジェ曲線. /// x1,y1始点 /// x2,y2制御点 /// x3,y3制御点 /// x4,y4終点 float2 GetQB4( float t, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4 ) { float tp = 1 - t; float x = t*t*t*x4 + t*t*tp*x3 + t*tp*tp*x2 + tp*tp*tp*x1; float y = t*t*t*y4 + t*t*tp*y3 + t*tp*tp*y2 + tp*tp*tp*y1; return float2( x, y ); } //================================================================== // シェーダーの入力 //================================================================== // 頂点シェーダーの入力 struct VS_INPUT { float4 m_position : POSITION; // 座標 float2 m_uv: TEXCOORD; // UV }; // ピクセルシェーダーの入力 struct PS_INPUT { //※ TEXCOORD13まで。(合計16個まで?) float4 m_position : SV_POSITION; // 頂点座標 float2 m_uv : TEXCOORD0; // UV }; //================================================================== // シェーダー //================================================================== // 頂点シェーダー PS_INPUT NORMAL_VS( VS_INPUT input ) { // 出力 PS_INPUT output = (PS_INPUT)0; //--- // 頂点座標 // 頂点座標(入力) output.m_position = input.m_position; //--- // UV // UV // 変換 output.m_uv = input.m_uv; return output; } // ピクセルシェーダー float4 NORMAL_PS( PS_INPUT input ) : SV_TARGET { // 出力 float4 output; // ディフューズテクスチャ output = g_texture_diffuse.Sample( samLinear, input.m_uv ); return saturate(output); } // ピクセルシェーダー float4 FILTER_PS( PS_INPUT input ) : SV_TARGET { // 出力 float4 output; float check = 0.0f; // ディフューズテクスチャ output = g_texture_diffuse.Sample( samLinear, input.m_uv ); if( input.m_uv.x < g_Outline.x ) { check = 1.0f; } else if( input.m_uv.y < g_Outline.y ) { check = 1.0f; } else if( input.m_uv.x > g_Outline.z ) { check = 1.0f; } else if( input.m_uv.y > g_Outline.w ) { check = 1.0f; } if( check == 1.0f ) { output.r = 1.0f; if( output.g < 0.5f ) { output.g = 0.5f; } } return saturate(output); } // ピクセルシェーダー float4 MIRROR_PS( PS_INPUT input ) : SV_TARGET { // 出力 float4 output; float2 UV; /// 90 float u1 = ( g_DrawUV.x + g_DrawUV.z ) * 0.5f; float v1 = ( g_DrawUV.y + g_DrawUV.w ) * 0.5f; UV.y = input.m_uv.y; UV.x = input.m_uv.x; if( input.m_uv.x >= u1 ) { UV.x = u1 - ( input.m_uv.x - u1 ); } // ディフューズテクスチャ output = g_texture_diffuse.Sample( samLinear, UV ); return saturate(output); } // ピクセルシェーダー float4 ENLARGED2_PS( PS_INPUT input ) : SV_TARGET { // 出力 float4 output; float2 UV; /// 中心位置. float u1 = ( g_Outline.x + g_Outline.z ) * 0.5f; float v1 = ( g_Outline.y + g_Outline.w ) * 0.5f; /// float center_u1 = u1 - g_Outline.x; float center_v1 = v1 - g_Outline.y; float center_u2 = g_Outline.z - u1; float center_v2 = g_Outline.w - v1; UV = input.m_uv.xy; output = float4( 0.0f, 0.0f, 0.0f, 1.0f ); if( u1 > input.m_uv.x ) { if( input.m_uv.x > g_Outline.x ) { float x = ( input.m_uv.x - g_Outline.x ); float t = x / center_u1; float check = center_u1 * 0.5f; float control = leap( center_u1, check, g_Volume.x * 0.9f ); float2 qb = GetQB( t, 0, 0, control, 0.5f, center_u1, 5.0f ); UV.x = g_Outline.x + leap( qb.x, x, g_Volume.x ); } } if( u1 < input.m_uv.x ) { if( input.m_uv.x < g_Outline.z ) { float x = ( g_Outline.z - input.m_uv.x ); float t = x / center_u2; float check = center_u2 * 0.5f; float control = leap( center_u2, check, g_Volume.x * 0.9f ); float2 qb = GetQB( t, 0, 0, control, 0.5f, center_u2, 5.0f ); UV.x = g_Outline.z - leap( qb.x, x, g_Volume.x ); } } if( v1 > input.m_uv.y ) { if( input.m_uv.y > g_Outline.y ) { float x = input.m_uv.y - g_Outline.y; float t = x / center_v1; float check = center_v1 * 0.5f; float control = leap( center_v1, check, g_Volume.x * 0.9f ); float2 qb = GetQB( t, 0, 0, control, 0.5f, center_v1, 5.0f ); UV.y = g_Outline.y + leap( qb.x, x, g_Volume.x ); } } if( v1 < input.m_uv.y ) { if( input.m_uv.y < g_Outline.w ) { float x = g_Outline.w - input.m_uv.y; float t = x / center_v2; float check = center_v2 * 0.5f; float control = leap( center_v2, check, g_Volume.x * 0.9f ); float2 qb = GetQB( t, 0, 0, control, 0.5f, center_v2, 5.0f ); UV.y = g_Outline.w - leap( qb.x, x, g_Volume.x ); } } // ディフューズテクスチャ output = g_texture_diffuse.Sample( samLinear, UV ); return saturate(output); } // ピクセルシェーダー float4 SQUEEZE2_PS( PS_INPUT input ) : SV_TARGET { // 出力 float4 output; float2 UV; /// 中心位置. float u1 = ( g_Outline.x + g_Outline.z ) * 0.5f; float v1 = ( g_Outline.y + g_Outline.w ) * 0.5f; /// float center_u1 = u1 - g_Outline.x; float center_v1 = v1 - g_Outline.y; float center_u2 = g_Outline.z - u1; float center_v2 = g_Outline.w - v1; UV = input.m_uv.xy; output = float4( 0.0f, 0.0f, 0.0f, 1.0f ); if( u1 > input.m_uv.x ) { if( input.m_uv.x > g_Outline.x ) { float x = ( input.m_uv.x - g_Outline.x ); float t = x / center_u1; float check = center_u1 * 0.5f; float control = leap( 0, check, g_Volume.x * 0.9f ); float2 qb = GetQB( t, 0, 0, control, 0.5f, center_u1, 5.0f ); UV.x = g_Outline.x + leap( qb.x, x, g_Volume.x ); } } if( u1 < input.m_uv.x ) { if( input.m_uv.x < g_Outline.z ) { float x = ( g_Outline.z - input.m_uv.x ); float t = x / center_u2; float check = center_u2 * 0.5f; float control = leap( 0, check, g_Volume.x * 0.9f ); float2 qb = GetQB( t, 0, 0, control, 0.5f, center_u2, 5.0f ); UV.x = g_Outline.z - leap( qb.x, x, g_Volume.x ); } } if( v1 > input.m_uv.y ) { if( input.m_uv.y > g_Outline.y ) { float x = input.m_uv.y - g_Outline.y; float t = x / center_v1; float check = center_v1 * 0.5f; float control = leap( 0, check, g_Volume.x * 0.9f ); float2 qb = GetQB( t, 0, 0, control, 0.5f, center_v1, 5.0f ); UV.y = g_Outline.y + leap( qb.x, x, g_Volume.x ); } } if( v1 < input.m_uv.y ) { if( input.m_uv.y < g_Outline.w ) { float x = g_Outline.w - input.m_uv.y; float t = x / center_v2; float check = center_v2 * 0.5f; float control = leap( 0, check, g_Volume.x * 0.9f ); float2 qb = GetQB( t, 0, 0, control, 0.5f, center_v2, 5.0f ); UV.y = g_Outline.w - leap( qb.x, x, g_Volume.x ); } } // ディフューズテクスチャ output = g_texture_diffuse.Sample( samLinear, UV ); return saturate(output); } // ピクセルシェーダー float4 BW_PS( PS_INPUT input ) : SV_TARGET { // 出力 float4 output; // ディフューズテクスチャ output = g_texture_diffuse.Sample( samLinear, input.m_uv ); float r = ( output.r * 0.25f ) + ( output.g * 0.625f ) + ( output.b * 0.125f ); if( g_Volume.x > 0.0f ) { if( r > g_Volume.x ) { r = 1.0f; } else { r = 0.0f; } } output.r = r; output.g = r; output.b = r; return saturate(output); } // ピクセルシェーダー float4 DOT_PS( PS_INPUT input ) : SV_TARGET { // 出力 float4 output; float2 UV; /// 中心位置. float u1 = ( g_Outline.x + g_Outline.z ) * 0.5f; float v1 = ( g_Outline.y + g_Outline.w ) * 0.5f; /// float center_u1 = u1 - g_Outline.x; float center_v1 = v1 - g_Outline.y; float center_u2 = g_Outline.z - u1; float center_v2 = g_Outline.w - v1; UV = round ( input.m_uv.xy * 16.0f ) / 16.0f; float offset_x = 1/448.0f; float offset_y = 1/640.0f; float2 UV_offset; output = float4( 0.0f, 0.0f, 0.0f, 1.0f ); int count = 0; // ディフューズテクスチャ for( int ii = -7 ; ii <= 7 ; ii++ ) { for( int jj = -7 ; jj <= 7 ; jj++ ) { UV_offset = float2( UV.x + offset_x * ii, UV.y + offset_y * jj ); output += g_texture_diffuse.Sample( samLinear, UV_offset ); count++; } } // output = g_texture_diffuse.Sample( samLinear, UV ); // UV_offset = float2( UV.x - offset_x * 3, UV.y ); // output += g_texture_diffuse.Sample( samLinear, UV_offset ); // UV_offset = float2( UV.x - offset_x * 2, UV.y ); // output += g_texture_diffuse.Sample( samLinear, UV_offset ); // UV_offset = float2( UV.x - offset_x * 1, UV.y ); // output += g_texture_diffuse.Sample( samLinear, UV_offset ); // UV_offset = float2( UV.x + offset_x * 1, UV.y ); // output += g_texture_diffuse.Sample( samLinear, UV_offset ); // UV_offset = float2( UV.x + offset_x * 2, UV.y ); // output += g_texture_diffuse.Sample( samLinear, UV_offset ); // UV_offset = float2( UV.x + offset_x * 3, UV.y ); // output += g_texture_diffuse.Sample( samLinear, UV_offset ); // UV_offset = float2( UV.x, UV.y - offset_y * 3 ); // output += g_texture_diffuse.Sample( samLinear, UV_offset ); // UV_offset = float2( UV.x, UV.y - offset_y * 2 ); // output += g_texture_diffuse.Sample( samLinear, UV_offset ); // UV_offset = float2( UV.x, UV.y - offset_y * 1 ); // output += g_texture_diffuse.Sample( samLinear, UV_offset ); // UV_offset = float2( UV.x, UV.y + offset_y * 1 ); // output += g_texture_diffuse.Sample( samLinear, UV_offset ); // UV_offset = float2( UV.x, UV.y + offset_y * 2 ); // output += g_texture_diffuse.Sample( samLinear, UV_offset ); // UV_offset = float2( UV.x, UV.y + offset_y * 3 ); // output += g_texture_diffuse.Sample( samLinear, UV_offset ); output /=count; output = round ( output.xyzw * 16.0f ) / 16.0f; return saturate(output); } // ブレンドステート BlendState SrcAlphaBlending { AlphaToCoverageEnable = FALSE; BlendEnable[0] = TRUE; SrcBlend = SRC_ALPHA; DestBlend = INV_SRC_ALPHA; BlendOp = ADD; SrcBlendAlpha = ONE; DestBlendAlpha = INV_SRC_ALPHA; BlendOpAlpha = ADD; RenderTargetWriteMask[0] = 0x0F; }; // テクニック(通常) technique10 Normal { pass P0{ //SetBlendState( SrcAlphaBlending, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF ); SetVertexShader( CompileShader( vs_4_0, NORMAL_VS() ) ); SetGeometryShader( NULL ); SetPixelShader( CompileShader( ps_4_0, NORMAL_PS() ) ); } } // テクニック(フィルター) technique10 Filter { pass P0{ //SetBlendState( SrcAlphaBlending, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF ); SetVertexShader( CompileShader( vs_4_0, NORMAL_VS() ) ); SetGeometryShader( NULL ); SetPixelShader( CompileShader( ps_4_0, FILTER_PS() ) ); } } // テクニック(鏡) technique10 Mirror { pass P0{ //SetBlendState( SrcAlphaBlending, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF ); SetVertexShader( CompileShader( vs_4_0, NORMAL_VS() ) ); SetGeometryShader( NULL ); SetPixelShader( CompileShader( ps_4_0, MIRROR_PS() ) ); } } // テクニック(引き伸ばし) technique10 Enlarged2 { pass P0{ //SetBlendState( SrcAlphaBlending, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF ); SetVertexShader( CompileShader( vs_4_0, NORMAL_VS() ) ); SetGeometryShader( NULL ); SetPixelShader( CompileShader( ps_4_0, ENLARGED2_PS() ) ); } } // テクニック(押しつぶし) technique10 Squeeze2 { pass P0{ //SetBlendState( SrcAlphaBlending, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF ); SetVertexShader( CompileShader( vs_4_0, NORMAL_VS() ) ); SetGeometryShader( NULL ); SetPixelShader( CompileShader( ps_4_0, SQUEEZE2_PS() ) ); } } // テクニック(ドット) technique10 Dot { pass P0{ //SetBlendState( SrcAlphaBlending, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF ); SetVertexShader( CompileShader( vs_4_0, NORMAL_VS() ) ); SetGeometryShader( NULL ); SetPixelShader( CompileShader( ps_4_0, DOT_PS() ) ); } } // テクニック(白黒) technique10 BW { pass P0{ //SetBlendState( SrcAlphaBlending, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF ); SetVertexShader( CompileShader( vs_4_0, NORMAL_VS() ) ); SetGeometryShader( NULL ); SetPixelShader( CompileShader( ps_4_0, BW_PS() ) ); } }