Afternoon, All.

I've attached a *Vertex Shader* example. To re-assemble it, you may need the updated *d3d8types.inc* file (Here).

There's still a problem with switching the *ZBuffer* on. I'll post an update once I've figured out how to solve it.

It's almost identical to the *matrices* Tut, except for the replacement for the Shader code.

Cheers,
Scronty

<edit>
I've fixed the ZBuffer problem. I wasn't clearing it. Call me a Newbie ;P !

Cheers,
Scronty
Posted on 2001-11-03 04:46:34 by Scronty
dang, pretty good. I didn't even know DX had that capability :)

BTW, I figured out those grid things, and also a new way to have an entire grid -without- garbage vertexes. I'll post the code in a few days...
Posted on 2001-11-03 09:14:17 by Kenny
Look at all the pretty colors. Great work Scronty.

I still can't get Caleb's demo working. :( Must be the GeForce3?
Posted on 2001-11-03 13:19:20 by bitRAKE
Hello BitRake - I'm sorry to hear that it won't work until now ... but I don't believe that's a gForce3-problem :confused: .

If there are any more people having problems to run this intro, please let me know ! (Well I'm in examination now until march 2002 :( , so please do not expect fast responses)


Hello Scronty !

Could you expand your vertex-shader-example using much more vertices ? This example works even without any hardware-vertex-shader (well, DirectX emulates this feature if it is not implemented in hardware, I know that) but it will be nice to see how fast this (emulation) is !



Hello to all together ! I need some help ...

I have this problem: Many games / intros and at least also my intro will start only a few times in a Win2k-session. After that DirectX fails to initialize completely or (like Max Payne) there will no blitting to screen anymore and I have to reboot ! What's going wrong :confused: ?


Greetings, Caleb
Posted on 2001-11-03 17:24:37 by Caleb
Caleb, I must have had an old version - D/L a fresh copy off your page and all is good! Very cool spinning star field - if I put my face close enough to the monitor screen, I feel like I'm floating. :)
Posted on 2001-11-04 10:42:54 by bitRAKE
Originally posted by Scronty

It's almost identical to the *matrices* Tut, except for the replacement for the Shader code.

Cheers,
Scronty


Hi Scronty!

Just a silly newbie question:

"Why would you want to do this anyway? I've looked at the code and don't see that much to gain. However, I only understand streams to a small extent.

I've read what you have in the 'd3d8types.inc' and what microsoft says about them in the help file, but I'm not sure of their benefits (since couldn't you do this before streams anyway)?

Well, that's it... back to my still defunct landscape generation... I think I have alot more to understand...

-=Sliver=-

ps. http://www.dx8g.com --didn't seem to work..
Posted on 2001-11-04 16:49:47 by Sliver
Afternoon, Sliver.

If www.dx8g.com isn't working, try:
http://homepage.dtn.ntl.com/anthony.mcmahon/dx/ .


The *Vertex Shader* is exactly that - an example.
It's probably as basic as you can get. All it does, is replace the *SetTransform*s.

The idea is to show how to get the *Vertex Shaders* working.

Most of the modern pretty (uh, I mean *special*) effects in games nowadays, use *Vertex Shaders* and *Pixel Shaders*. They're usually kept inside their own separate file, which is loaded at runtime.

They're also used to do *Vertex Blending*, i.e. seamless animation :).

Look under "Advanced Topics in DirectX Graphics" in the P/SDK. Or visit nVidias' site for more info on what you can use them for.

Anyhoo. That proggy was only the first example. I'm currently working on another, however I don't know how long it'll take. (bl**dy dolphins). M$ C++ is a real mess.

Cheers,
Scronty
Posted on 2001-11-04 23:45:31 by Scronty
Check this out...

I took your code Scronty and changed it a bit... Makes pretty pictures...

What it does is this: Takes a 8bit greyscale raw image file and makes a heightmap off of it. The image file can be any size, but must be a square (1x1 - 65536x65536 pixels). The only bug in the program is if it can't find "heightmap.raw" then it crashes
Posted on 2001-11-05 12:37:33 by Kenny
Anyhoo. That proggy was only the first example. I'm currently working on another, however I don't know how long it'll take. (bl**dy dolphins). M$ C++ is a real mess.

Cheers,
Scronty


Hey Scronty and everybody...

Need help in converting C++ to asm... I'm working on a drawindexprimitive example, but I need to convert this part of the c++ code to asm



int FLAG_SIZE = 50
FlagVertices = new CUSTOMVERTEX [ NUM_FLAG_VERTICIES];

for (int ix = 0; ix < FLAG_SIZE+1; ix++)
for (int iy = 0; iy < FLAG_SIZE+1; iy++)
{
FLOAT tu = ix/(FLOAT)FLAG_SIZE
FLOAT tv = iy/(FLOAT)FLAG_SIZE

FlagVertices[ix+iy*(FLAG_SIZE+1)].x = (float) (ix-FLAG_SIZE/2);
FlagVertices[ix+iy*(FLAG_SIZE+1)].y = 3*(cos(iy)/3)+cos(ix/3)
FlagVertices[ix+iy*(FLAG_SIZE+1)].z = iy -FLAG_SIZE/2
FlagVertices[ix+iy*(FLAG_SIZE+1)].nx = 0.0
FlagVertices[ix+iy*(FLAG_SIZE+1)].ny = 1.0
FlagVertices[ix+iy*(FLAG_SIZE+1)].nz = 0.0
FlagVertices[ix+iy*(FLAG_SIZE+1)].tu = (float)tu*4
FlagVertices[ix+iy*(FLAG_SIZE+1)].tv = (float)tv*4

};


Now I can really do the 2 for loops... not a problem... I can also do the complex equations... what I don't know is how to advance the loop

for example

push esi
ASSUME esi:PTR CUSTOMVERTEX
mov eax, offset FlagVertices
mov esi, eax

mov ecx, 0

;do for loop
@OuterLoop:
push ecx
@InnerLoop:
push ecx

; do stuff here
;filling customvertex

;now advance loop...
;????

The problem is that the code skips around alot
0
51
102
153
204
....
then in adds to ix so now it is
1
52
103
154
205

how do you account for it...
Should I reset the pointer back to the original after the complete of each pass?

Someone please help me out....
Posted on 2001-11-09 23:55:56 by Sliver
The way I do my loops which works fine for me is like this:

push ecx | mov ecx 0
L1: | push ecx | mov ecx 0
L2: | push ecx
...
pop ecx | inc ecx | cmp ecx xxx | jb L2<
pop ecx | inc ecx | cmp ecx xxx | jb L1<
pop ecx
Posted on 2001-11-10 01:25:49 by Kenny
And in MASM:
LOOPSIZE EQU 50


mov ecx,LOOPSIZE
L1: push ecx

mov ecx,LOOPSIZE
L2: ;(do some stuff here...)
dec ecx
jne L2 ;use jns if you'd like to loop with ecx=0

pop ecx
dec ecx
jne L1 ;use jns if you'd like to loop with ecx=0
Posted on 2001-11-10 01:40:27 by bitRAKE
You have a problem with the wonderful world of SpAsm? :grin:

Hey, good code :) I forgot inc/dec modified the flags... *sigh* it's late...
Posted on 2001-11-10 01:48:19 by Kenny
No problem, just like to speak to a larger audience. ;)

I like SpAsm. :alright:

It's all ASM :)
Posted on 2001-11-10 02:24:57 by bitRAKE


int FLAG_SIZE = 50
FlagVertices = new CUSTOMVERTEX [ NUM_FLAG_VERTICIES];

for (int ix = 0; ix < FLAG_SIZE+1; ix++)
for (int iy = 0; iy < FLAG_SIZE+1; iy++)
{
FLOAT tu = ix/(FLOAT)FLAG_SIZE
FLOAT tv = iy/(FLOAT)FLAG_SIZE

FlagVertices[ix+iy*(FLAG_SIZE+1)].x = (float) (ix-FLAG_SIZE/2);
FlagVertices[ix+iy*(FLAG_SIZE+1)].y = 3*(cos(iy)/3)+cos(ix/3)
FlagVertices[ix+iy*(FLAG_SIZE+1)].z = iy -FLAG_SIZE/2
FlagVertices[ix+iy*(FLAG_SIZE+1)].nx = 0.0
FlagVertices[ix+iy*(FLAG_SIZE+1)].ny = 1.0
FlagVertices[ix+iy*(FLAG_SIZE+1)].nz = 0.0
FlagVertices[ix+iy*(FLAG_SIZE+1)].tu = (float)tu*4
FlagVertices[ix+iy*(FLAG_SIZE+1)].tv = (float)tv*4

};


Ok, maybe I wasn't clear... I *didn't* want to know how to do a for loop

The problem with the code is:
FlagVertices

at ix = 0 and iy = 0 the FlagVertices[] would be equivalent to
FlagVertices[0]
at ix = 0 and iy = 1 the FlagVertices[] would be
FlagVertices[51]
at ix = 0 and iy = 2 the FlagVertices[] would be
FlagVertices[102]

after the first iteration of the loop the iy resets and the loop adds 1 to ix, SO:

at ix = 1 and iy = 0 the FlagVertices[] would be equivalent to
FlagVertices[1]
at ix = 1 and iy = 1 the FlagVertices[] would be
FlagVertices[52]
at ix = 1 and iy = 2 the FlagVertices[] would be
FlagVertices[103]

Do you see the patern?

Your loop fills up the code like this:

going across -> then shifts down

[0][0]
[0][0][0][0][0]
[0][0][0][0][0]

the c++ loop I described fills it up by going down and then shifting across
[0][0][0]
[0][0][0]
[0][0][0][0]
[0][0][0][0]

You can hopefully see why this loop is difficult to write:

So in conclusion I need to know how to advance the *pointer* to FlagVertices as in



mov eax, iy
mov edx, FLAG_SIZE +1
imul eax, edx
mov edx, size CUSTOMVERTEX
imul eax, edx
add esi, eax


or something like that... I'd appreciate any detailed responses on this issue (since I'm trying the best I can to convey the problem)

-=Sliver=-
Posted on 2001-11-10 16:09:55 by Sliver
Oh, that's all :)
LOOPSIZE EQU 50

; for inner loop
iy EQU <ecx>
ix EQU <[esp]>

mov ecx,LOOPSIZE
L1: push ecx

mov ecx,LOOPSIZE
L2: mov eax,LOOPSIZE + 1
mul iy ; trashes edx, of course
add eax,ix
; now we have the index in eax ;)
; have to multiple it by the array item size
mov edx,sizeof CUSTOMVERTEX
mul edx
mov ebx,eax

ASSUME esi:PTR CUSTOMVERTEX

mov [esi + ebx].x,eax

mov [esi + ebx].y,eax

mov [esi + ebx].z,eax

mov [esi + ebx].nx,0.0

mov [esi + ebx].ny,1.0

mov [esi + ebx].nz,0.0

mov [esi + ebx].tu,eax

mov [esi + ebx].tv,eax

ASSUME esi:nothing

dec ecx
jns L2

pop ecx
dec ecx
jns L1
Maybe I'm wrong, but I don't see anything in that algorithm that requires you to transverse the array in a specific way. My loop code didn't assign any relivance to the values - it's a square array - just swap the values! What is the problem?
Posted on 2001-11-10 18:49:52 by bitRAKE
I should say right off that I appreciate your help and time in this matter :) But I have 2 questions about it...

LOOPSIZE EQU 50

; for inner loop
iy EQU <ecx>
ix EQU <[esp]>


I've never seen this done before... Why do you do he 2 equ's with ix and iy if you don't seem to use them... and what would this be doing anyway... (again I've never seen this done)



ASSUME esi:PTR CUSTOMVERTEX

mov [esi + ebx].x,eax


Could this have been done by storing the number in just esi like:



; now we have the index in eax
; have to multiple it by the array item size
mov edx,sizeof CUSTOMVERTEX
mul edx
mov esi,eax

ASSUME esi:PTR CUSTOMVERTEX

mov [esi].x,eax


Or is their something special about this?

Thanks again bitRAKE and KEnny :)

-=Sliver=-

----EDIT----
Another problem arose... :(
I really thought you could do this:



push esi
ASSUME esi:PTR WORD
mov eax, OFFSET FlagIndices
mov esi, eax

mov ecx, 0
@OuterLoop1:
push ecx

mov ecx, 0
@InnerLoop1:
push ecx

;FlagIndices[i++] = (ix+0) + (iy+1) * (FLAG_SIZE+1)
fld ix
fld iy
fld1
fadd
fld FLAG_SIZEplusONE
fmul
fadd
fstp [esi].WORD ; error here
add esi, size WORD



Now I know WORD isn't a struct, but I just thought it would work... don't know why... can someone please give me a good way to change this code so I can skip through and store the code in the offset FlagIndices?

Thanks
Posted on 2001-11-11 15:53:46 by Sliver
Silver, I do use those EQU - look again, please. They are only used for easy reading of the conversion, or to easily confuse the naive. ;) I put the array index into EBX to make things easier later on, and to keep ESI constant thoughout the algorithm - this hopefully reduces coding errors. Ignore the moves in the center of the code I posted - you will be getting the values off the FPU stack (ie. fld .x is more likely what you'll be coding).

Does the FPU allow you to load/store WORDs? I don't think there is a REAL2? ;) I don't understand what your trying to do? Definitely, don't name a structure element 'WORD'.
MySTRUC STRUCT

WORD dd ? ; this is bad
MySTRUC STRUCT
ASSUME esi:PTR WORD is usage similar as mov ax, WORD PTR , I don't think this is what you mean. ASSUME produces no code, but assigns a type to a register. Please, attach some code and we will solve your problem.
Posted on 2001-11-11 20:40:03 by bitRAKE
Originally posted by bitRAKE
Please, attach some code and we will solve your problem.


Please excuse my naive nature... I'm C++ oriented and asm still
tends to be somewhat hard for me to wrap my mind around...

Ask and ye shall recieve... here is most of the C++ code that I'm
trying to port... (it's not very long in C++ as you can see)

----EDIT----

See below for all the code plus and example of what it's supposed to do
Posted on 2001-11-11 21:15:40 by Sliver
I've decided to post all the codes + the C++ coding example I'm converting (with application to see what it will eventually do)... It won't compile due to my errors in code and an include problem with "SetIndices"

I also found that I screwed up and am not updating the "ix" and "iy" variables in my code (which BitRAKE did successfully)... If anyone wants to mess around with the code too :) be my guest the only requirement is that the finish product must be posted as a learning example....

Ok back to work...

Sliver
Posted on 2001-11-11 22:10:27 by Sliver
Yeap, you wanted WORD. ;)

You don't need to use the FPU for the FlagIndices loops - they are all integers. In fact an optimized solution would do both loops in parallel, but forget than until the codes working.
;	for(WORD i=0, ix=0; ix<FLAG_SIZE; ix++ )

; for(WORD iy=0; iy<FLAG_SIZE; iy++ )
; {
; FlagIndices[i++] = (ix+0) + (iy+1)*(FLAG_SIZE+1);
; FlagIndices[i++] = (ix+0) + (iy+0)*(FLAG_SIZE+1);
; FlagIndices[i++] = (ix+1) + (iy+0)*(FLAG_SIZE+1);
; FlagIndices[i++] = (ix+0) + (iy+1)*(FLAG_SIZE+1);
; FlagIndices[i++] = (ix+1) + (iy+0)*(FLAG_SIZE+1);
; FlagIndices[i++] = (ix+1) + (iy+1)*(FLAG_SIZE+1);
; };

FLAG_SIZE EQU 50

; for inner loop
iy EQU <ecx>
ix EQU <[esp]>

lea edi,FlagIndices
mov ecx,FLAG_SIZE
L1: push ecx

mov ecx,FLAG_SIZE
L2: mov eax,FLAG_SIZE
mul iy ; this value is used through loop
; line 1
add eax,iy
stosw
; line 2
sub eax,iy
stosw
; line 3
add eax,ix
stosw
; line 4
sub eax,ix
add eax,iy
stosw
; line 5
add eax,ix
sub eax,iy
stosw
; line 6
add eax,iy
stosw

dec ecx
jns L2

pop ecx
dec ecx
jns L1
This solution is by no mean optimal, but I think it works. ;) I think an optimized version would be a little bigger textwise than the C/C++ version. I want to see what VS.NET came up with for this? brb...even this is far better than what VS.NET came up with - I'm very disappointed. I think VC++ gets confused with the WORDs, too. :)

Edit: Opps, but it's fixed now - I think. ;)
Posted on 2001-11-11 22:41:09 by bitRAKE