PDA

View Full Version : OpenGL Vertex/Fragment Shader in ASM, simple texturing-shader?


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

Goz
03-18-2006, 05:07 PM
No idea in OpenGL but it can't be much different to DirectX ...

vs_2_0
dcl_position v0
dcl_color v1
dcl_texcoord v2

dp4 oPos.x, v0, c0
dp4 oPos.y, v0, c1
dp4 oPos.z, v0, c2
dp4 oPos.w, v0, c3

mov oD0, v1
mov oT0, v2


ps_2_0
dcl v0
dcl t0
dcl_2d s0

texld r0, t0, s0
mov oC0, r0

Sorry if thats no help ...

Reedbeta
03-18-2006, 08:37 PM
Instead of fragment.position, you want to use fragment.texcoord[0]. And I don't think you need any of the program.env variables to do simple texturing.

mysticman
03-20-2006, 03:35 AM
http://www.codesampler.com/oglsrc/oglsrc_9.htm#ogl_arb_shader_simple_vs2ps