示例#1
0
vki.Add_Built_In_Header(
    'rand_xorwow.shinc', '''
struct V5
{
    uint v0;
    uint v1;
    uint v2;
    uint v3;
    uint v4;
};

struct RNGState 
{
    V5 v;
    uint d;
};

uint rand(inout RNGState state)
{
    uint t;
    t = (state.v.v0 ^ (state.v.v0 >> 2));
    state.v.v0 = state.v.v1;
    state.v.v1 = state.v.v2;
    state.v.v2 = state.v.v3;
    state.v.v3 = state.v.v4;
    state.v.v4 = (state.v.v4 ^ (state.v.v4 << 4)) ^ (t ^ (t << 1));
    state.d += 362437;
    return state.v.v4 + state.d;
}

float rand01(inout RNGState state)
{
    uint64_t urand = rand(state);
    return float(urand) / float(1UL << 32);
}

vec3 rand_in_unit_sphere(inout RNGState rstate)
{
    vec3 ret;
    do{
        ret = vec3(rand01(rstate)*2.0 - 1.0, rand01(rstate)*2.0 - 1.0, rand01(rstate)*2.0 - 1.0);
    } while (length(ret) > 1.0);
    return ret;
}

vec2 rand_in_unit_disk(inout RNGState rstate)
{
    vec2 ret;
    do {
        ret = vec2(rand01(rstate)*2.0 - 1.0, rand01(rstate)*2.0 - 1.0);
    } while (length(ret) > 1.0);
    return ret;
}

vec3 rand_on_unit_sphere(inout RNGState rstate)
{
    float theta = rand01(rstate) * radians(360.0);
    float z = rand01(rstate)*2.0 - 1.0;
    float r = 1.0 - z*z;
    if (r<0.0) r = 0.0;
    r = sqrt(r);
    vec3 ret;
    ret.z = z;
    ret.x = r*cos(theta);
    ret.y = r*sin(theta);
    return ret;
}

vec2 rand_on_unit_circle(inout RNGState rstate)
{
    float theta = rand01(rstate) * radians(360.0);
    vec2 ret;
    ret.x = cos(theta);
    ret.y = sin(theta);
    return ret;
}
''')
示例#2
0
import VkInline as vki
from VkInline.SVCombine import *
import glm

vki.Add_Built_In_Header(
    'spectrum.shinc', '''

mat3 mat_rgb2xyz = mat3(
0.412453, 0.212671, 0.019334,
0.357580, 0.715160, 0.119193,
0.180423, 0.072169, 0.950227);

mat3 mat_xyz2rgb = mat3(
3.240479, -0.969256, 0.055648,
-1.537150, 1.875991, -0.204043,
-0.498535, 0.041556, 1.057311);

vec3 rgb2xyz(in vec3 rgb)
{
    return mat_rgb2xyz * rgb;
}

vec3 xyz2rgb(in vec3 xyz)
{
    return mat_xyz2rgb * xyz;
}
''')

vki.Add_Inlcude_Filename('spectrum.shinc')