lope
03-18-2006, 03:03 PM
Hello,
I got a question about OpenGL vertex/fragment programs, in this special case it's about an vf-program for Doom3, but the question is more common and not limited to Doom3:
First I must say, that I must use the assembler language, no Cg/GLSL. I want to create a really simple texturing-shader, which calculates texture coordinates and colors the fragment accordingly, so it should just texture an object.
My first attempt looks as follows:
!!ARBvp1.0
OPTION ARB_position_invariant ;
# no action in the vertex program
END
#================================================= =====================
!!ARBfp1.0
OPTION ARB_precision_hint_fastest;
TEMP R0;
MUL R0, fragment.position, program.env[1];
MUL R0, R0, program.env[0];
TEX result.color, R0, texture[1], 2D;
END
The following things are important and specific to Doom3:
- When I multiply fragment.postition with program.env[1], I get the fragment.position in 0.0 to 1.0 values.
- When I multiply that result with program.env[0], I get the real screen coordinates of the pixel
- texture[1] was set in the material for the object (Doom3 material file), which is a simple TGA diffuse texture.
This attempt is of course not want I wanted to have as the result. The shader does not texture the object, but shows at that position, where the pixels of the object are on the screen, the texture, so as if the object is a "hole in the screen" and the texture lies behind it (hard to explain).
I realized that the texture coordinates must be calculated in a more complicated way, so the object is textured correctly. But I just don't know, how to do it.
The Doom3 engine sets several program.env[n] vars - It would be great if someone know, how a simple texturing shader must look like. If someone needs to know other .env[n] and their meaning, I would post them here, of course.
On Nehe's tutorials page, I found the following texturing-shader (http://nehe.gamedev.net/data/articles/article.asp?article=21), which is written in GLSL:
// vertex program
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 program
void main()
{
// Sampling The Texture And Passing It To The Frame Buffer
gl_FragColor = texture2D(my_color_texture, texture_coordinate);
}
As far as I understand it, that GLSL code should do simple texturing. But sadly, I need that in assembler, and so far I didn't manage to get it working.
I would appreciative any help you can offer me in writing a simple opengl texturing-shader in assembler.
Thank you very much in advance
I got a question about OpenGL vertex/fragment programs, in this special case it's about an vf-program for Doom3, but the question is more common and not limited to Doom3:
First I must say, that I must use the assembler language, no Cg/GLSL. I want to create a really simple texturing-shader, which calculates texture coordinates and colors the fragment accordingly, so it should just texture an object.
My first attempt looks as follows:
!!ARBvp1.0
OPTION ARB_position_invariant ;
# no action in the vertex program
END
#================================================= =====================
!!ARBfp1.0
OPTION ARB_precision_hint_fastest;
TEMP R0;
MUL R0, fragment.position, program.env[1];
MUL R0, R0, program.env[0];
TEX result.color, R0, texture[1], 2D;
END
The following things are important and specific to Doom3:
- When I multiply fragment.postition with program.env[1], I get the fragment.position in 0.0 to 1.0 values.
- When I multiply that result with program.env[0], I get the real screen coordinates of the pixel
- texture[1] was set in the material for the object (Doom3 material file), which is a simple TGA diffuse texture.
This attempt is of course not want I wanted to have as the result. The shader does not texture the object, but shows at that position, where the pixels of the object are on the screen, the texture, so as if the object is a "hole in the screen" and the texture lies behind it (hard to explain).
I realized that the texture coordinates must be calculated in a more complicated way, so the object is textured correctly. But I just don't know, how to do it.
The Doom3 engine sets several program.env[n] vars - It would be great if someone know, how a simple texturing shader must look like. If someone needs to know other .env[n] and their meaning, I would post them here, of course.
On Nehe's tutorials page, I found the following texturing-shader (http://nehe.gamedev.net/data/articles/article.asp?article=21), which is written in GLSL:
// vertex program
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 program
void main()
{
// Sampling The Texture And Passing It To The Frame Buffer
gl_FragColor = texture2D(my_color_texture, texture_coordinate);
}
As far as I understand it, that GLSL code should do simple texturing. But sadly, I need that in assembler, and so far I didn't manage to get it working.
I would appreciative any help you can offer me in writing a simple opengl texturing-shader in assembler.
Thank you very much in advance