GLSL for Minecraft:我如何设置云的位置?

时间:2014-06-22 15:45:10

标签: glsl minecraft

我正在使用gl_FragCoord.xy,但云被锁定在玩家眼睛或相机位置。如果你回头看,他们会和你一起移动。但我希望云拥有自己的静态位置。我用worldposition = gbufferModelViewInverse * fragposition尝试了但结果很难看。如果我看着日出或日落并且有镜子效果,云层就会伸展开来。如果我看日落,他们就像在日出时一样有样品。

现在我的问题是:我怎样才能让玩家看向左边,看不到云在玩家眼中移动?这很难解释,所以我试图创建一个简单的图片:

Example image

以下是我的代码中的一部分:

float hash( float n )
{
    return fract(sin(n)*43758.5453);
}

float noise( in vec2 x )
{
    vec2 p = floor(x);
    vec2 f = fract(x);
        f = f*f*(3.0-2.0*f);
        float n = p.x + p.y*57.0;
        float res = mix(mix( hash(n+  0.0), hash(n+  1.0),f.x), mix( hash(n+ 57.0), hash(n+ 58.0),f.x),f.y);
        return res;
}

float fbm( vec2 p )
{
        float f = 0.0;
        f += 0.50000*noise( p ); p = p*2.02;
        f += 0.25000*noise( p ); p = p*2.03;
        f += 0.12500*noise( p ); p = p*2.01;
        f += 0.06250*noise( p ); p = p*2.04;
        f += 0.03125*noise( p );
        return f/0.984375;
}

#define CLOUD_COVER         0.55
#define CLOUD_SHARPNESS     0.015

// Wind - Used to animate the clouds
vec2 wind_vec = vec2(0.001 + frameTimeCounter*0.005, 0.003 + frameTimeCounter * 0.005);

// Set up domain
vec2 q = (gl_FragCoord.xy / 2024);
vec2 p = -1.0 + 3.0 * q + wind_vec;

// Create noise using fBm
float f = fbm( 4.0*p );

float cover = CLOUD_COVER;
float sharpness = CLOUD_SHARPNESS;

float c = f - (1.0 - cover);
if ( c < 0.0 )
c = 0.0;

f = 1.0 - (pow(sharpness, c));

color += f/15*TimeDay;
color += vec3(0.03, 0.19, 0.99)*f/1000*TimeMidnight;

0 个答案:

没有答案