flat assembler
Message board for the users of flat assembler.
Index
> Tutorials and Examples > OpenGL Terrain example |
Author |
|
Hotwire 21 Mar 2022, 16:22
Hello there!
I've decided to upload simple example with terrain generation and per-pixel lighting with the help of ARB vertex and fragment programs. Examples uses glut library for simplicity(for obvious reasons not included in the archive). Randomness is provided by rand function from msvcrt.dll. Controls are very simple 'N' - draw normals; 'W' - wireframe mode; 'C' - switch on/off culling. Terrain is generated by functions glxGenTerrain (located in GLX\Terrain.asm) Vertex Program is the following Code: Terr db '!!ARBvp1.0' db 'PARAM LT=state.light[0].position;' db 'PARAM mvp[4]={state.matrix.mvp};' db 'PARAM mdl[4]={state.matrix.modelview};' db 'PARAM minvrt[4]={state.matrix.modelview.invtrans};' db 'TEMP V;' db 'DP4 result.position.x,mvp[0],vertex.position;' db 'DP4 result.position.y,mvp[1],vertex.position;' db 'DP4 result.position.z,mvp[2],vertex.position;' db 'DP4 result.position.w,mvp[3],vertex.position;' db 'DP4 V.x,mdl[0],vertex.position;' db 'DP4 V.y,mdl[1],vertex.position;' db 'DP4 V.z,mdl[2],vertex.position;' db 'DP4 V.w,mdl[3],vertex.position;' db 'ADD result.texcoord[3],LT,-V;' db 'ADD result.texcoord[4],minvrt[3],-V;' db 'DP3 result.texcoord[2].x,minvrt[0],vertex.normal;' db 'DP3 result.texcoord[2].y,minvrt[1],vertex.normal;' db 'DP3 result.texcoord[2].z,minvrt[2],vertex.normal;' db 'MOV result.texcoord[0],vertex.texcoord[0];' db 'MOV result.texcoord[7],V;' db 'END' Fragment program is the following Code: Terf db '!!ARBfp1.0' db 'PARAM sp=0.0;' db 'PARAM Vec={1.0,-1.0,3.0,-0.1};' db 'PARAM SM=state.material.front.shininess;' db 'PARAM LT=state.light[0].position;' db 'PARAM AC=state.lightprod[0].ambient;' db 'PARAM DC=state.lightprod[0].diffuse;' db 'PARAM SC=state.lightprod[0].specular;' db 'PARAM mdl[4]={state.matrix.modelview.invtrans};' db 'TEMP R0,R1,R3,R2,hV,cP,N,R13;' db 'ADD R1,fragment.texcoord[3],fragment.texcoord[4];' db 'DP3 R1.w,R1,R1;' db 'RSQ R1.w,R1.w;' db 'MUL R1.xyz,R1,R1.w;' db 'DP3 R0.w,fragment.texcoord[3],fragment.texcoord[3];' db 'RSQ R0.w,R0.w;' db 'MUL R0.xyz,fragment.texcoord[3],R0.w;' db 'MOV N,fragment.texcoord[2];' db 'DP3 N.w,N,N;' db 'RSQ N.w,N.w;' db 'MUL N.xyz,N,N.w;' db 'DP3 R3.x,R0,N;' db 'DP3 R3.y,R1,N;' db 'MOV R3.w,SM.x;' db 'LIT R2,R3;' db 'MAD R0,R2.y,DC,AC;' db 'MAD R1.xyz,R2.z,SC,R0;' db 'TEX R0,fragment.texcoord[0],texture[0],2D;' db 'ADD result.color,R0,R1;' db 'END' result looks as follows If someone is interested I will wrote some sort of tutorial.
|
|||||||||||
21 Mar 2022, 16:22 |
|
Mikl___ 23 Mar 2022, 22:23
Hi Hotwire!
Will you can attach a exe-file to the message? Thank you! |
|||
23 Mar 2022, 22:23 |
|
bitRAKE 24 Mar 2022, 00:22
I can compile it with fasm out of the box, but only get a black screen. It responds to keys and does cleanly exit with ESC.
Code: glGenProgramsNV=1882370800 glLoadProgramNV=1882432288 glBindProgramNV=1882296352 glProgramParameter4fNV=1882487888 glTrackMatrixNV=1882559408 glActiveTexture=1882287968 glMultiTexCoord2f=1882447296 glMultiTexCoord3f=1882449536 glGenProgramsARB=1882370688 glBindProgramARB=1882296240 glProgramStringARB=1882488784 glMultiTexCoord4f=1882451776 glMultiTexCoord4fv=1882452000 glProgramLocalParameter4fARB=1882486208 glGenVertexArrays=1882372480 glBindVertexArray=1882298144 glGenBuffers=1882369456 glBindBuffer=1882294000 glBufferData=1882302624 glVertexAttribPointer=1882616464 glEnableVertexAttribArray=1882357552 glGenerateMipmap=1882372704 glGetError = 0 Line = -1, Position = 0 glGetError = 0 Line = -1, Position = 0 VAO = 1 VBO = 1 TBO = 2 NBO = 3 NBO = 4 NV = 21600 Code of the pressed key = 27 [process exited with code 3804444] (Don't think that's helpful.)
_________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||||||||||
24 Mar 2022, 00:22 |
|
Hotwire 28 Mar 2022, 15:41
I've uploaded executable and glut32
https://www.mediafire.com/file/z3xknewz5n0tzwx/forum.zip/file For the texture to be loaded it should be located at "res\textures\Grass.bmp". You are free to change this. Any bmp file with 2^n x 2^n resolution is valid. Also I slightly modified the source code I've tested this code only on my laptop with Windows 7 and Nvidia graphics card. For the example to work properly I have to ask manually to execute it with with Nvidia GPU otherwise it runs with Intel GPU which doesn't support fragment programs. I have pretty old one.
|
|||||||||||
28 Mar 2022, 15:41 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.