zoukankan      html  css  js  c++  java
  • WPF九宫格HLSL版

      偶遇需要再WPF里面处理九宫格,因不喜截图缩放,即写成了HLSL的Effcect

    sampler2D input : register(s0);
    
    /// <summary>The float of the Left.</summary>
    /// <minValue>1</minValue>
    /// <maxValue>20</maxValue>
    /// <defaultValue>20</defaultValue>
    float Left : register(C0);
    
    /// <summary>The float of the Top.</summary>
    /// <minValue>1</minValue>
    /// <maxValue>20</maxValue>
    /// <defaultValue>20</defaultValue>
    float Top : register(C1);
    
    /// <summary>The float of the Right.</summary>
    /// <minValue>1</minValue>
    /// <maxValue>20</maxValue>
    /// <defaultValue>20</defaultValue>
    float Right : register(C2);
    
    /// <summary>The float of the Bottom.</summary>
    /// <minValue>1</minValue>
    /// <maxValue>20</maxValue>
    /// <defaultValue>20</defaultValue>
    float Bottom : register(C3);
    
    /// <summary>The float of the Width.</summary>
    /// <minValue>5</minValue>
    /// <maxValue>200</maxValue>
    /// <defaultValue>46</defaultValue>
    float Width : register(C4);
    
    /// <summary>The float of the Height.</summary>
    /// <minValue>5</minValue>
    /// <maxValue>200</maxValue>
    /// <defaultValue>46</defaultValue>
    float Height : register(C5);
    
    /// <summary>The float of the ShowWidth.</summary>
    /// <minValue>50</minValue>
    /// <maxValue>1200</maxValue>
    /// <defaultValue>750</defaultValue>
    float ShowWidth : register(C6);
    
    /// <summary>The float of the ShowHeight.</summary>
    /// <minValue>50</minValue>
    /// <maxValue>1200</maxValue>
    /// <defaultValue>700</defaultValue>
    float ShowHeight : register(C7);
    
    float4 main(float2 uv : TEXCOORD) : COLOR 
    { 
    
        float realwidth = uv.x * ShowWidth;
        float realheight = uv.y * ShowHeight;
    
        //Set color of no scale
        float x = uv.x * ShowWidth / Width;
        float y = uv.y * ShowHeight / Height;
    
        //Scale X
        if(realwidth >= Left && realwidth <= (ShowWidth - Right))
        {
            x = ((uv.x * ShowWidth - Left) / (ShowWidth - Left - Right) * (Width - Left - Right) + Left) / Width;
        }
        // Real color of max x
        else if(realwidth > (ShowWidth - Right) )
        {
            x = 1 - (1- uv.x) * ShowWidth / Width;
        }
    
        //Scale Y
        if(realheight >= Top && realheight <= ShowHeight - Bottom )
        {
            y = ((uv.y * ShowHeight - Top) / (ShowHeight - Top - Bottom) * (Height - Top - Bottom) + Top ) / Height;
        }
        //Real color of max y
        else if(realheight > ShowHeight - Bottom )  
        {
            y =  1 - (1- uv.y) * ShowHeight / Height;
        }
    
        return tex2D(input, float2(x ,y)) ;
    }
    View Code
  • 相关阅读:
    插件有感-做东西有感
    国家电网-元数据管理系统-流程跳转有感-3层结构
    干了2个月java开发最深的体会
    BL老师的建议,数学不好的,大数据一票否决--后赋从java转大数据
    极快瑞的函数式编程,Jquery涉及的一些函数
    距离第一天去实习过去了56天 ::写写自己的想法
    两种同步模式:状态同步和帧同步
    unity制作人物残影-绘制的方法
    unity对敏感词库处理的记录
    unity 读取外部exe程序控制台信息
  • 原文地址:https://www.cnblogs.com/jiailiuyan/p/4838448.html
Copyright © 2011-2022 走看看