?

Log in

I love it when a plan comes together... - Oolite (progress) [entries|archive|friends|userinfo]
oolite

[ website | Oolite ]
[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

Links
[Links:| Bulletin Board RSS Feed Atom Feed ]

I love it when a plan comes together... [Aug. 8th, 2006|06:24 pm]
oolite
[Current Mood |cheerfulcheerful]

Yay. I implemented shaders.

I'm working through the possibilities for how they can interact with the ship, currently I have hooks fo rthe shaders to send them a 'time' value, the engine _level of the ship, and the main weapon laser_heat_level.

As a test the cobra 3.5 now replaces one of its textures with a shader that mixes together four source textures to add decals, a glow for the windows, and an engine glow to a base texture.

The addition to shipdata.plist looks like this:
        <key>shaders</key>
        <dict>
            <key>cob035.png</key><!-- replace this texture -->
            <dict>
                <key>textures</key>
                <array>
                    <string>cob035.png</string><!-- passed as tex0 -->
                    <string>cob035-decal.png</string><!-- passed as tex1 -->
                    <string>cob035-flatglow.png</string><!-- passed as tex2 -->
                    <string>cob035-engineglow.png</string><!-- passed as tex3 -->
                </array>
                <key>glsl</key><!-- complex fragment shader code - simply add the glowmap to the texture -->
                <string>
                uniform sampler2D tex0;
                uniform sampler2D tex1;
                uniform sampler2D tex2;
                uniform sampler2D tex3;
                                
                uniform float engine_level;
                                
                void main()
                {
                    vec4 base =     texture2D(tex0, gl_TexCoord[0].st);
                    vec4 decal =    texture2D(tex1, gl_TexCoord[0].st);
                    vec4 glow1 =    texture2D(tex2, gl_TexCoord[0].st);
                    vec4 glow2 =    texture2D(tex3, gl_TexCoord[0].st);
                    gl_FragColor = gl_Color * ((1.0 - decal.a) * base + decal.a * decal) + glow1 * glow1.a + glow2 * glow2.a * engine_level;
                }
                </string>
            </dict>
        </dict>


There are some pics here: http://pics.livejournal.com/aegidian/gallery/0000agt1
Link