Dark Bit Factory & Gravity

PROGRAMMING => General coding questions => Topic started by: va!n on August 15, 2009

Title: Pixelshader - How to start?
Post by: va!n on August 15, 2009
I have coded a very simple effect by plotting it pixel by pixel like:

Code: [Select]
for y = 0 to 600-1
  for x = 0 to 800-1
     DrawPixel( x, y, lColor )
  next
next

I would like to restart learning/coding with VisualStudio and try to code a new 1k intro based on DirectX... Afaik such things would be smaller (exe) and even a lot faster when using PixelShader... How to set a pixel at x,y,color with pixelshader? Or must things be done in a complete other way?
Title: Re: Pixelshader - How to start?
Post by: Jim on August 16, 2009
Completely another way.
First, you need to choose Direct3D or OpenGL.
Then you need to set up the window and screen and drawing contexts with whichever API you chose.
Then you create the pixel shader.
The pixel shader will get triggered for every pixel rendered while it is active.
To get a full screen effect most people's main app just renders a fullscreen 2d quad to trigger the shader for every pixel, followed by a screen flip.
Inside the shader you will be handed the x,y position of the pixel being rendered (amongst other things).  You can then determine the output colour you want by running your fx function.

Jim
Title: Re: Pixelshader - How to start?
Post by: Jim on August 16, 2009
Check out this thread for a <1Kb DirectX shader framework:
http://www.dbfinteractive.com/forum/index.php?topic=2387 (http://www.dbfinteractive.com/forum/index.php?topic=2387)

Jim
Title: Re: Pixelshader - How to start?
Post by: ferris on August 19, 2009
K++ Jim, flawless answer :)
Title: Re: Pixelshader - How to start?
Post by: TinDragon on August 19, 2009
I have rbz 1k dx framework running under VC++ 2k8 express with crinkler but i seem to get a 2.5kb exe out of it, the other think I have noticed is that the process is still running in the taskmanager after you exit the example, this happens on both rbz original and my recompiled version. Is it due to the hack using the "edit" wndclass ?

Tbh i only set it up to try out crinkler so havent done anything else with it but thought I would post the problem incase noone's noticed, I am on vista 32bit incase anyones interested.

Cheers
Jon
Title: Re: Pixelshader - How to start?
Post by: Jim on August 19, 2009
Probably 2 things.
1) You need to configure the project not to include default libraries.  I think that's both a compiler and a linker option.
2) Since Vista, you need to ExitProcess(0) at the end of main() else it will crash.  In previous Windows versions you could just return 0.

Jim
Title: Re: Pixelshader - How to start?
Post by: TinDragon on August 19, 2009
1)Makes sense I espect on converting the project from the version rbz used its added that crap back on :) [edit] ah it seems I do have no default libs but its not using crinkler as the linker, will have to check this out must have something no 100%

2)I thought it might be the exitprocess(0) thing. Had seen that mentioned before.

Thanks for the info Jim, will no doubt prove handy when i start messing about more.

 :cheers:
Title: Re: Pixelshader - How to start?
Post by: Jim on August 19, 2009
You have to add /CRINKLER to the 'Additional Linker Options' section, and make sure you have crinker renamed as link.exe in the project directory.

Jim
Title: Re: Pixelshader - How to start?
Post by: TinDragon on August 19, 2009
have done that as well as adding the solution path, not its just not building at all, giving me a link error or a crash. if i change back to default linker it builds no probs just is 2.5k so it must be something with how its calling crinkler or something.

Buildlog shows this
Code: [Select]


Compiling...
Main.cpp
Linking...
Crinkler 1.1a (Jan 14 2009) (c) 2005-2009 Aske Simon Christensen & Rune Stubbe
Ignoring unknown argument '/INCREMENTAL:NO'
Ignoring unknown argument '/MANIFEST:NO'
Ignoring unknown argument '/NODEFAULTLIB'
Ignoring unknown argument '/OPT:NOWIN98'
Ignoring unknown argument '/DYNAMICBASE:NO'
Ignoring unknown argument '/MERGE:.rdata=.text'
Ignoring unknown argument '/MACHINE:X86'
Ignoring unknown argument '/NOLOGO'
Ignoring unknown argument '/ERRORREPORT:PROMPT'
Target: Release/Tiny_DX9.exe
Subsystem type: WINDOWS
Compression mode: FAST
Hash size: 100 MB
Hash tries: 20
Order tries: 0
Report: NONE
Transforms: NONE
Replace DLLs: NONE
Range DLLs: NONE
loading:
-ignore:4078: error: LNK: Cannot open file

Mind for my purposes atm 2.5kb is more than fine, would just be nice to sus why it's failing.
Title: Re: Pixelshader - How to start?
Post by: Jim on August 19, 2009
Can't think of anything offhand, unless you're using Windows 7, in which case no crinkled exes will run.
The 'Cannot Open File' thing looks odd - do you have the exe stuck in task manager - in which case the linker can't overwrite the exe?

Jim
Title: Re: Pixelshader - How to start?
Post by: TinDragon on August 19, 2009
Nope not on win7 only on vista sp1, there is no file to overwrite as i removed it just in case that was the problem and its not still running, probably something with the project/solution isnt 100% but I will live without crinkler, or try using it from the command line if i get desperate to make it 1K. Got to learn how to use and write the shaders yet and the size is well below what i can get out of bmax :)
Title: Re: Pixelshader - How to start?
Post by: ferris on August 19, 2009
The problem here is that MSVC is sending some parameter "ignore" to the linker, and crinkler somehow think's it's a file, and linking stops there. The 2.5k exe then is a leftover from the normal linker because it was never overwritten by crinkler.

I think :)
Title: Re: Pixelshader - How to start?
Post by: TinDragon on August 19, 2009
I removed the ignore which was from the framework i got from rbz site, but it now crashes when building with a link.exe error and i get a 0bytes .exe
here's the build log for that.
Code: [Select]
Compiling...
Main.cpp
Linking...
Crinkler 1.1a (Jan 14 2009) (c) 2005-2009 Aske Simon Christensen & Rune Stubbe
Ignoring unknown argument '/INCREMENTAL:NO'
Ignoring unknown argument '/MANIFEST:NO'
Ignoring unknown argument '/NODEFAULTLIB'
Ignoring unknown argument '/OPT:NOWIN98'
Ignoring unknown argument '/DYNAMICBASE:NO'
Ignoring unknown argument '/MERGE:.rdata=.text'
Ignoring unknown argument '/MACHINE:X86'
Ignoring unknown argument '/NOLOGO'
Ignoring unknown argument '/ERRORREPORT:PROMPT'
Target: Release/Tiny_DX9.exe
Subsystem type: WINDOWS
Compression mode: FAST
Hash size: 100 MB
Hash tries: 20
Order tries: 0
Report: NONE
Transforms: NONE
Replace DLLs: NONE
Range DLLs: NONE
loading:
  d3dx9.lib  d3d9.lib  kernel32.lib  user32.lib
  gdi32.lib  winspool.lib  comdlg32.lib  advapi32.lib
  shell32.lib  ole32.lib  oleaut32.lib  uuid.lib
  odbc32.lib  odbccp32.lib  .\Main.obj
Uncompressed size of code:   500
Uncompressed size of data:   269
|-- Estimating models for code ----------------------------|
Project : error PRJ0002 : Error result -1073741819 returned from 'C:\Users\jon\Documents\Visual Studio 2008\Projects\1K_PS_DX9_FrameWork\link.exe'.
it does seem to do more, not sure if it needs all those libs but as you can see i get an error and then a crash message. I am using the lastest version of crinkler from there website 1.1a i think it is. As I said tho I think it will be awhile before I have anything worth trying to get in 1K so I wouldnt lose any sleep trying to solve it :)
Title: Re: Pixelshader - How to start?
Post by: Rbz on August 20, 2009
No idea way it's crashing for you, anyway have you tried to compile it using a batch file or from msvc command prompt?

You can try something like this:
Code: [Select]
CRINKLER.exe /COMPMODE:slow /out:Tiny_DX9_Crinkler.exe /ENTRY:WinMain /subsystem:windows /LIBPATH:"C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib" /LIBPATH:"C:\Program Files\Microsoft DirectX SDK (February 2007)\Lib\x86" kernel32.lib user32.lib d3d9.lib d3dx9.lib Main.obj

Title: Re: Pixelshader - How to start?
Post by: va!n on August 20, 2009
@rbz:
thanks... i will take a closer look to the links/source soon..
Title: Re: Pixelshader - How to start?
Post by: TinDragon on August 20, 2009
@rbz, no i havent tried that yet, will give it ago and see what I get abit later and post back.  :)
Title: Re: Pixelshader - How to start?
Post by: TinDragon on August 20, 2009
Well i tried it with a batch file, it pretty much does the same thing as it was doing from inside VC, gets to the estimate bit then dies with a crash and i get a 0kb exe out   :(

Seems it dont like me :P
Title: Re: Pixelshader - How to start?
Post by: Clyde on August 20, 2009
Hows things with the Pixel Shaders Va!n dude?
Title: Re: Pixelshader - How to start?
Post by: ferris on August 21, 2009
Yeah JC2K, usually that happens on win7 so it must hate you're config or something. Sorry to hear!
Title: Re: Pixelshader - How to start?
Post by: TinDragon on August 21, 2009
@ferris, well I do have an xp machine i could try it on, as long as the final exe worked its not such a big deal then but I had trouble with some crinkler packed stuff failing, but some seems to work which i think is due to the many fixes that they have done to it over time. Will try it out next time i fire up the other machine :)