[游戏开发][Shader]GLSLSandBox转Unity-CG语言

 官网

GLSL Sandbox Galleryicon-default.png?t=N7T8https://glslsandbox.com/

屏幕坐标计算

fragCoord与_ScreenParams

mat2矩阵转换 vec2向量

在GLSL里mat2(a, b, c, d)函数返回vec2

但是在CG语言里 没有mat2函数,用下面的值替换mat2方法

vec2(a * 1. +c * 1., b * 1. + d * 1.);

举例:
//GLSL代码
vec2 rot(in vec2 p, float theta)
{
    float c = cos(theta);
    float s = sin(theta);
    return mat2(c, -s, s, c) * p;
}

//CG代码
vec2 rot(in vec2 p, float theta)
{
    float c = cos(theta);
    float s = sin(theta);
    return vec2(c * 1. + s * 1., -s * 1. + c * 1.);
}

猜你喜欢

转载自blog.csdn.net/liuyongjie1992/article/details/133072590