zoukankan      html  css  js  c++  java
  • [Unity] Shader

    CG语言中:

    不支持 switch 语句(可以写,但不能很好的执行。)

    循环语句中, 循环次数不能大于 1024 ,否则会报错。

    If...ELSE 条件判断语句:

    if (true) {

    } else {

    }

    If...ELSE IF...ELSE... 嵌套语句

    if (true) {

    } else if (true) {

    } else {

    }

    While语句:

    while (bool) {

    }

    Do...While语句:

    do {

    } while (bool)

    For 循环语句:

    for (int i=0; i < xxx; i++) {

    }

    示例代码

    Shader "Custom/001" {
        SubShader {
    
            pass {
                CGPROGRAM
                #pragma vertex vert
                #pragma fragment frag
    
    
                void vert(in float2 objPos: POSITION, out float4 pos: POSITION, out float4 col: COLOR) {
                    pos = float4(objPos,0,1);
                    if (pos.x < 0 && pos.y < 0) {
                        col = float4(1,0,0,1);
                    } else if (pos.x < 0)  {
                        col = float4(0,1,0,1);
                    } else if (pos.y > 0) {
                        col = float4(1,1,0,1);
                    } else
                        col = float4(0,0,1,1);
                } 
    
    
                void frag(inout float4 col: COLOR) {
                    int i = 0;
                    while (i < 10) {
                        i++;
                    }
                    if (i == 10)
                        col = float4(0,0,0,1);
    
                    i = 0;
                    do {
                        i++;
                    } while (i < 10);
                    if (i == 10)
                        col = float4(1,1,1,1);
    
                    for (i=0; i < 10; i++) {
    
                    }
                    if (i == 10)
                        col = float4(0.5,0.5,0,1);
    
    
                }
    
                ENDCG
            }
        }
    
    }
  • 相关阅读:
    常用录屏工具
    python常用工具库介绍
    修改anaconda3 jupyter notebook 默认路径
    【转载】面试那些事【三】
    【转载】面试那些事【二】
    【转载】面试那些事【一】
    Myeclipse 激活代码 8.6以前的版本
    ddd
    Java 算法
    Java 水仙花数
  • 原文地址:https://www.cnblogs.com/yangyxd/p/5403838.html
Copyright © 2011-2022 走看看