Just My Life & My Work

[GLSL] Texture Mapping Shader

Texture Mapping Shader需要用到貼圖,OpenGL application可以做到,這次使用GLSL來實做,效果幾乎一模一樣。

vertex shader程式碼:

varying vec2 texture_coordinate;

void main()
{
    // Transforming The Vertex
    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;

    // Passing The Texture Coordinate Of Texture Unit 0 To The Fragment Shader
    texture_coordinate = vec2(gl_MultiTexCoord0);
}

fragment shader程式碼:

varying vec2 texture_coordinate;
uniform sampler2D my_color_texture;

void main()
{
    // Sampling The Texture And Passing It To The Frame Buffer
    gl_FragColor = texture2D(my_color_texture, texture_coordinate);
}
crate cube

由ShaderDesigner呈現的crate cube。

crate

貼圖crate。

開始覺得NeHe故布疑陣,這次的bug是全域變數不在程式碼欄中,他是想讓複製貼上的懶人有多一點可以努力的空間,思考過後會更瞭解實做過程。

參考:NeHe Texture Mapping Shader

隨意留個言吧:)~

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料

標籤雲