2011年8月18日星期四

隨風擺動——GLSL Shader

大家看過了Bashcraft後 (未看第二集的按此)
係咪好想知道片中點解D草同樹葉會擺動呢
其實當中用了GLSL mod
在此亦都曾經提及過
只不過mod的原創者已不再更新
所以要到另外的地方下載

首先到Dax Wikia 下載mod(下圖)
注意: 裝了modloader的請下載下面那個(glsl_unofficial_1.7.3_ml.zip)

下載後開啟壓縮檔
並把所有檔案複制到minecraft.jar(用解壓程式開啟)中

(如果已用MCPatcher啟用了HD Texture的話可以跳過這一部)
在此下載MCPatcher
運行下載了的.exe
選"HD Textures"(下圖)
然後按Patch (程式會自動為你Backup舊檔)

回到glsl mod的壓縮檔
把裡面的/Shaders Folder解壓並開啟
會見到下圖的視窗
(DoF即景深, Depth of  View)
因為glsl mod本身並不設草的擺動
所以我們需要修改少少Code!


先開啟base.vsh
用notepad的話用走樣
我個人就較鐘意用notepad++
找到以下字句
並在 tex==15 || 後 加上 tex == 39 || tex == 56 || tex == 63 || tex == 79

應該會變成以下這樣:
if ((tex == 12 || tex == 13  || tex == 15 || tex == 39 || tex == 56 || tex == 63 || tex == 79)&& renderType == 1)  {
        float t = float(mod(worldTime, 500))/500.0;
        vec2 pos = position.xz/16.0;
        if (round(16.0*gl_MultiTexCoord0.t) <= floor(16.0*gl_MultiTexCoord0.t)) {
            position.x -= (sin(PI2*(2.0*pos.x + pos.y - 3.0*t)) + 0.6)/8.0;
        }
    }
#endif


加了的字句
其實係叫該函數
(其實實質不是函數, 不過...都差不多啦)
把texture id(下圖)為39, 56, 63 及79都擺動


完成後儲存檔案
並連同其他Shader檔案
(.DS Store, base.fsh, base.vsh, final.fsh)
複制到minecraft.jar中的/Shaders 中
(不想要景深的可把final.fsh刪除)


完成啦!

如果不想要樹葉擺動的話
(我覺得好食資源)
可以把WAVING_LEAVES 刪除
整個檔案變成這樣:
#define CURVATURE
#define WAVING_WHEAT
#define WAVING_PLANTS


#ifdef CURVATURE
const float FLAT_RADIUS          = 84.0;
const float WORLD_RADIUS         = 212.0;
const float WORLD_RADIUS_SQUARED = WORLD_RADIUS*WORLD_RADIUS;
#endif

const float PI = 3.1415926535897932384626433832795;
const float PI2 = 6.283185307179586476925286766559;

uniform float sunVector;
uniform float moonVector;
uniform int worldTime;
uniform int renderType;

varying float texID;

int getTextureID(vec2 coord);

void main() {
    vec4 position = gl_Vertex;
#ifdef WAVING_WHEAT
    int tex = getTextureID(gl_MultiTexCoord0.st);
    if (87 < tex && tex < 96 && renderType != 0) {
        float t = float(mod(worldTime, 200))/200.0;
        vec2 pos = position.xz/16.0;
        if (round(16.0*gl_MultiTexCoord0.t) <= floor(16.0*gl_MultiTexCoord0.t)) {
            position.x += (sin(PI2*(2.0*pos.x + pos.y - 3.0*t)) + 0.6)/20.0;
        }
    }
    position = gl_ModelViewMatrix * position;
#endif
#ifdef CURVATURE
    if (gl_Color.a != 0.8) {
        // Not a cloud.

        float dist = (length(position) - FLAT_RADIUS)/WORLD_RADIUS;

        if (dist > 0) {
            dist *= dist;
            position.y -= WORLD_RADIUS - sqrt(max(1.0 - dist, 0.0)) * WORLD_RADIUS;
        }

    }
#endif
#ifdef WAVING_PLANTS
if ((tex == 12 || tex == 13  || tex == 15 || tex == 39 || tex == 56 || tex == 63 || tex == 79)&& renderType == 1)  {
        float t = float(mod(worldTime, 500))/500.0;
        vec2 pos = position.xz/16.0;
        if (round(16.0*gl_MultiTexCoord0.t) <= floor(16.0*gl_MultiTexCoord0.t)) {
            position.x -= (sin(PI2*(2.0*pos.x + pos.y - 3.0*t)) + 0.6)/8.0;
        }
    }
#endif


#if defined(CURVATURE) || defined(WAVING_WHEAT) || defined(WAVING_PLANTS)
    gl_Position = gl_ProjectionMatrix * position;
#else
    gl_Position = ftransform();
#endif

    if (renderType != 0) {
        texID = float(getTextureID(gl_MultiTexCoord0.st));
    }
    else {
        texID = -1.0;
    }

    gl_FrontColor = gl_BackColor = gl_Color;
    gl_TexCoord[0] = gl_MultiTexCoord0;
    gl_FogFragCoord = gl_Position.z;
}

int getTextureID(vec2 coord) {
    int i = int(floor(16*coord.s));
    int j = int(floor(16*coord.t));
    return i + 16*j;
}


如果大家仲想玩多D
仲有waving water同waving lava
不過我覺得好食RAM


5 則留言:

  1. 唔得呀,邊到有15呀

    回覆刪除
  2. 你試下用"Ctrl+F"搵
    (雖然你應該試過 = =)

    回覆刪除
  3. Therе arе νaгiouѕ fаctors why persons favοг thіs belt.


    Неге is my blοg poѕt:
    holygrailwest.com

    回覆刪除
  4. Most lаdiеs get stretch maгκs
    аt sοme point іn their liveѕ from getting a іnfant.


    Feеl frее tο surf
    to my web page http://www.Zapatosviajeros.com/

    回覆刪除
  5. Thе only fаctor to do ρrior
    to chooѕing up аnу brand, is to thоrοughly studу іt and seek the adѵice
    of a speсiаlist.

    Ηere is my web blog :: trilastin Coupon Code

    回覆刪除