• Advertisement

vanattab

Member
  • Content count

    24
  • Joined

  • Last visited

Everything posted by vanattab

  1. What makes an RTS great?

    I really, really like RTS that have fewer more powerful units. Like in the best RTS of all time Company of Heroes the player typically has only a large handful of units 10-15 ish. Each infintry unit is really a squad of soldiers but they act as one unit. I don't like games were you just build a massive army of 40 units group them up and just click the center of the enemys base. CoH battles are all about micro-management and environmental interaction. If you have not tried it you can pick up all three games on steam pretty cheap. Also different races are a must IMO but it makes game balance hard and is a lot of extra work. Also having a couple of types of resources is ok but don't go overboard keep the game play focused on interesting and fun battle mechanics, not tedious base management. It’s not fun building a million harvesters and having to constantly keep an eye on them but it is fun to fight for control of the ore this is why CoH's capture of territories is so good.
  2. Note: Sorry I know I have been posting tons of newbie questions on here lately but I really don't understand this problem. I am trying to write an HLSL pixel shader for a project I am working on. Basically want I want to do is if a texture has a pixel with a float value of 0.52 (on scale of 0-255 is 132.6) I want to output 133 60% of the time and output 132 40% of the time. Write now I am just trying to output the fractional remainder of the RGB value (i.e. the chance to bump the pixel up) however I always get a value of zero) I think this is because the colors are getting quantized to a 0-255 scale before they reach the shader but I don't know why this would be because I am useing the A32B32G32R32f format which should be able to store plenty of information about the colors. Here is my very simple shader code. I am using SlimDX (DX9) if that matters. [source lang="cpp"]sampler2D Tex0 : register(s0); float4 DitherByChance(float2 coords : TEXCOORD0) : COLOR { float4 newColor = float4(0, 0, 0, 0); // The pixel color to return double4 oldColor = tex2D(Tex0, coords); double scale = 0.0039215686274509803921568627451; // 1 / 255 double rPercentChance = frac(oldColor.r / scale); //Chance to round red channel up double gPercentChance = frac(oldColor.g / scale); //Chance to round green channel up double bPercentChance = frac(oldColor.b / scale); //Chance to round blue channel up newColor.r = rPercentChance; newColor.g = gPercentChance; newColor.b = bPercentChance; newColor.a = 1; return newColor; } technique DitherViaChance { pass Pass1 { PixelShader = compile ps_2_0 DitherByChance(); } }[/source] Here is the relevant VB code [source lang="vb"] Public Overrides Sub RenderScene() 'ditherBC.Technique = ditherBC.GetTechnique("DitherViaChance") Me.device.BeginScene() spriteRender.Begin(SpriteFlags.None) ditherBC.Begin() ditherBC.BeginPass(0) 'NOTE tex IS CREATED WITH createCharacterTexture()' spriteRender.Draw(tex, New Rectangle(0, 0, 50, 50), New Color4(1, 1, 1)) spriteRender.End() ditherBC.EndPass() ditherBC.End() Me.device.EndScene() End Sub Public Function createCharacterTexture() As Texture Dim RtsHelper As RenderToSurface = New RenderToSurface(device, 100, 100, Format.A32B32G32R32F) Dim texture As Texture = New Texture(device, 100, 100, 1, Usage.RenderTarget, Format.A32B32G32R32F, Pool.Default) Dim sloanFont As Font = New Font(device, 98, 98, FontWeight.Normal, 1, False, CharacterSet.Default, Precision.Default, FontQuality.ClearTypeNatural, PitchAndFamily.Default, "Sloan") RtsHelper.BeginScene(texture.GetSurfaceLevel(0), New Viewport(0, 0, 100, 100)) sloanFont.DrawString(Nothing, "A", 1, 1, New SlimDX.Color4()) RtsHelper.EndScene(Filter.None) Font.Dispose() RtsHelper.Dispose() Return texture End Function [/source]
  3. [quote name='kauna' timestamp='1350394324' post='4990706'] I think that he doesn't expect the values to be limited to 1/255 increments. They should have the same accuracy as a floating point value. That's the problem since the beginning. That's why I proposed to write a pixel shader to fill the buffer with a desired floating point value just to narrow down the problem. Cheers! [/quote] I tried writting a simple texture shader to fill the texture as you suggested but I got an odd error and I am not sure why? This was my shader code: [source lang="cpp"]sampler2D Tex0 : register(s0); float4 fill128( float2 coords : TEXCOORD0) : COLOR { return float4(1, 0.612549, 0.612549, 0.612549); }[/source] In my application code I then compile the shader as so: [source lang="vb"]psByteCode = ShaderBytecode.CompileFromFile("filePath", "fill128", "ps_2_b", ShaderFlags.None) shader = New TextureShader(psByteCode.Data) ... .... ..... ' '''''''' Then in my rendering code before I call device.BeginScene() I call TestTexture.Fill(shader) [/source] But I get the following error on the TestTexture.Fill(shader) call. SlimDX X9Exception with a msg of: [quote] Additional Infromation: E_FAIL: An undetermined error occurred. [/quote]
  4. [quote name='L. Spiro' timestamp='1350337740' post='4990540'] Then what is not behaving as expected? You have values that, when multiplied by 255.0f, result in whole numbers, 1.0f, 2.0f, 3.0f, etc. There is no fraction, so you are obviously going to get 0.0f every time. No mystery here. This is exactly what you should expect. If it is not what you desire, you should change it to be whatever exactly it is that you desire. L. Spiro [/quote] I believe you misunderstand what I am trying to do. I am working on a color vision test to test for color blindness and I would like to be able to display more colors then is possible on an 8bit / per channel display (i.e. 24bit/32bit depth). Say for example I want to display 10bits of color per channel (0-1024), this is equivalent to being able to display 0.25 increments of the 8bit (0-255) scale. For example say I want to render a large letter "A" with a floating point value of 0.503921... on a scale of 0-255 this is 128.50 the way I want to mimic this on an 8bit display is to render half the pixels as 128 and half the pixels as 129. When viewed at a reasonable distance the eye averages over the pixels and interprets the color of the letter as 128.5. Please see the picture below as a reference to want I am talking about. When looking at the image imagine that one of the colors of green is 128 and the other is 129 and that each box was only 1 pixel not 16. Your eye will interpret this as 128.5. Note in the below example it is perfectly uniform in my basic random chance model this is not necessarily true. [img]www.users.muohio.edu/vanattab/BasicDithering.png[/img] In order to implement this with SlimDX and DirectX 9 what I tried was creating a 128Bit surface (I also tried 64Bit for floating point format and regular) so that I can store color to a higher depth. A 64Bit surface should be able to store 2^16 = 65536 possible values (24/32Bit is 2^8=256). So when I render the "A" to a 64 bit surface the color data should be stored in increments of (1/65536) not (1/255). In my pixel shader I then want to get multiply that floating point number by 255 and should get a number like 128.5 if you take the above example. When I then take the frac(of that number) I should get .5 which corresponds to the % chance that I want scale the color value up to 129. But that is not happening for some reason even though I am drawing the text to a 64bit format the color seems to be quantized to 24/32bit format. Does that make sense now?
  5. The frac(oldColor * 255) call always returns 0. While the oldColor values are 0-1 floating point numbers they only are changed in increments of (1/255)
  6. Could you elaborate? I am using D3D9 via the SlimDX wrapper. Maybe SlimDX is taking a float color but converting it to 0-255 before passing it to DirectX?
  7. [b]From L. Spiro:[/b] [quote]After re-reading his original post I think that is what he expects too, but that is a fairly crazy way to get it. Just multiply by 255.0. Divisions are slow. [/quote] Yeah thats what I was oinganlly doing but in my quest to try and figure out what was going on I changed it to see if it made any diffrence. (not sure why I thought it would) [b]From L. Spiro:[/b] [quote]Why not return the unaltered texture values? return oldColor;See what happens. [/quote] Yes I have done that. And it seems to work but it would not give me any more infromation because when rasterized to the screen it would definatly be quantized to values of 0-255. Thanks for the tip to combine the three lines to one that is good to know. [b]From Adam_42:[/b] [quote]The way DrawString() works is that it uses a texture to hold an image of each character in the font. It's that texture which is almost certainly 8-bit and causing you problems. You want to draw something other than text - a triangle with a different colour at each vertex should do the trick. [/quote] This does not apper to be the problem. ...At least not the only problem. If create a surface like this: [source lang="vb"]Dim tex As Texture = New Texture(device, 100, 100, 1, Usage.RenderTarget, Format A32B32G32R32F, Pool.Defualt)[/source] And then do a device.ColorFill() as so: [source lang="vb"]device.ColorFill(tex.GetSurfaceLevel(0), New Color4(1, 0.53, 0.52, 0.52)[/source] I still get an all black output when you would expect an all 0.6 gray output. I have tried locking the surface and filling all the data with random bits using the Random.NextByte() method which seems to work fine because when I pass it through the Effect I get random colored pixels. (Note: not the same random pixels that get displayed when I don't pass it through the effect). Is there some kind of Format settings for the device object its self? Do I (can I even?) need to set the backbuffer to a 128bit surface? I am really at a loss here.
  8. Yes that is correct. I create at RenderToSurface object with a 128bit format so that I can render some text directly to a surface. I then I create a 128bit texture with one surface to act as the rendertarget. I am not sure if there is such a thing as diffrent bit formats for the Color class. I think if I create a color of 0.52 , 0.52, 0.52 it does not get converted until it get rendered onto the texture but I don't know. "Otherwise, can you confirm that your shader is outputting values correctly?" Yes If I manual but in 0.52 instead of oldColor.r (should be 0.52) I get the expected result.
  9. I am trying get 3 new random floats into my pixel shader for each pixel. Based on what I have read here, here, and also here, I believe that I need to generate a large texture containing random RGB values and then during each draw call randomly generate a couple of texture coordinate offset values to produce a pseudo-random effect. Is the only way to do this through the LockRect and UnlockRect API? I hope not. Also when do the floating point color values get quantized. For example if I do a ColorFill on a texture and set it too a RGB of ( 0.52, 0.52, 0.52 ) which on a 0-255 scale is ( 132.6, 132.6, 132. 6 ) when I access that texture in my pixel shader will I get a value of 0.52 or 0.52156....i.e. (133).
  10. I am trying to write an HLSL pixel shader for a project I am working on. Basically want I want to do is if a texture has a pixel with a float value of 0.52 (on scale of 0-255 is 132.6) I want to output 133 60% of the time and output 132 40% of the time. Write now I am just trying to output the fractional remainder of the RGB value (i.e. the chance to bump the pixel up) however I always get a value of zero) I think this is because the colors are getting quantized to a 0-255 scale before they reach the shader but I don't know why this would be because I am useing the A32B32G32R32f format which should be able to store plenty of information about the colors. Here is my very simple shader code. I am using SlimDX (DX9) if that matters. [CODE] sampler2D Tex0 : register(s0); float4 DitherByChance(float2 coords : TEXCOORD0) : COLOR { float4 newColor = float4(0, 0, 0, 0); // The pixel color to return double4 oldColor = tex2D(Tex0, coords); double scale = 0.0039215686274509803921568627451; // 1 / 255 double rPercentChance = frac(oldColor.r / scale); //Chance to round red channel up double gPercentChance = frac(oldColor.g / scale); //Chance to round green channel up double bPercentChance = frac(oldColor.b / scale); //Chance to round blue channel up newColor.r = rPercentChance; newColor.g = gPercentChance; newColor.b = bPercentChance; newColor.a = 1; return newColor; } technique DitherViaChance { pass Pass1 { PixelShader = compile ps_2_0 DitherByChance(); } } [/CODE] Here is my SlimDX code too if you want to look: [CODE] Public Class TextStimulusDisplay Inherits BaseStimulusDisplay Protected ditherByChanceEffect As PixelShader Protected psByteCode As ShaderBytecode Protected gStream As DataStream Protected ditherBC As Effect Protected tex As Texture Protected spriteRender As Sprite Public displaySettings As DisplaySettings Public charText As Texture Public randomText As Texture Protected rando As Random Public Sub New(ByVal displaysettings As DisplaySettings, Optional ByVal WindowedMode As Boolean = False) MyBase.New(New Size(displaysettings.xResolution, displaysettings.yResolution), WindowedMode) Me.displaySettings = displaysettings End Sub Public Overrides Sub CreateDeviceResources() MyBase.CreateDeviceResources() ditherBC = Effect.FromFile(device, Application.StartupPath & "\effects\DitherByChance.fx", ShaderFlags.Debug) rando = New Random() randomText = New Texture(device, 100, 100, 1, Usage.Dynamic, Format.A32B32G32R32F, Pool.Default) Dim data(80000) As Byte rando.NextBytes(data) Dim dataBox As DataRectangle = randomText.GetSurfaceLevel(0).LockRectangle(LockFlags.None) dataBox.Data.Seek(0, IO.SeekOrigin.Begin) dataBox.Data.Write(data, 0, data.Length) dataBox.Data.Close() randomText.GetSurfaceLevel(0).UnlockRectangle() device.SetTexture(1, randomText) 'psByteCode = ShaderBytecode.CompileFromFile(Application.StartupPath & "\effects\DitherByChance.fx", "DitherByChance", "ps_2_0", ShaderFlags.None) 'ditherByChanceEffect = New PixelShader(device, psByteCode) 'device.PixelShader = ditherByChanceEffect spriteRender = New Sprite(device) spriteRender.Transform = Matrix.Identity tex = createCharacterTexture() End Sub Public Overrides Sub ReleaseDeviceResources() MyBase.ReleaseDeviceResources() End Sub Public Overrides Sub RenderScene() 'ditherBC.Technique = ditherBC.GetTechnique("DitherViaChance") Me.device.BeginScene() spriteRender.Begin(SpriteFlags.None) ditherBC.Begin() ditherBC.BeginPass(0) spriteRender.Draw(tex, New Rectangle(0, 0, 50, 50), New Color4(1, 1, 1)) 'spriteRender.Draw(randomText, New Rectangle(0, 0, 1000, 1000), New Color4(1, 1, 1)) spriteRender.End() ditherBC.EndPass() ditherBC.End() Me.device.EndScene() End Sub Public Function createCharacterTexture() As Texture Dim RtsHelper As RenderToSurface = New RenderToSurface(device, 100, 100, Format.A32B32G32R32F) Dim texture As Texture = New Texture(device, 100, 100, 1, Usage.RenderTarget, Format.A32B32G32R32F, Pool.Default) Dim sloanFont As Font = New Font(device, 98, 98, FontWeight.Normal, 1, False, CharacterSet.Default, Precision.Default, FontQuality.ClearTypeNatural, PitchAndFamily.Default, "Sloan") RtsHelper.BeginScene(texture.GetSurfaceLevel(0), New Viewport(0, 0, 100, 100)) sloanFont.DrawString(Nothing, "A", 1, 1, New SlimDX.Color4()) RtsHelper.EndScene(Filter.None) Font.Dispose() RtsHelper.Dispose() Return texture End Function End Class [/CODE]
  11. I am writing I SlimDX application to test color contrast sensitivity thresholds of the human visual system. The subject is presented with a large letter that is at low contrast with with the background and asked to identify the letter. However I need the ability to display more colors then is available with a simple 8bit per channel color depth. (i.e. rgb values 0-255). The way I plan to due this is through a simple "dithering" algorithm implemented as an HLSL pixel shader. Basically if request slimDX to render the text to a surface with a color of Color4( 0.55f, 0.55f, 0.55f ) which corresponds to a rgb value of ( 140.25 , 140.25 , 140.25 ) I want each color channel of each pixel to have a 25% chance of being set to 141 and a 75% chance of getting set to 140. This should (in the limit of many pixels) lead to a letter that appears as a shade of gray one 1/4 of the way in-between 140 and 141. I am however getting errors in my prototype shader code when trying to compile with fxc. I am getting an Illegal character code when I compile and I don't know why. Also if you are a HLSL guru please look over my code and make any comments that strike you. Note I got the HLSL random function from an answer to this question. http://stackoverflow.com/questions/5149544/can-i-generate-a-random-number-inside-a-pixel-shader Below is my shader code. Please forgive me if there a many mistakes as its my first HLSL code: [CODE] float4 DitherByChance(float2 coords : TEXCOORD0) : COLOR { float4 newColor; // The pixel color to return float4 oldColor = tex2D(s0, coords); // Note I know that as the code stands now rCutOff = gCutOff = bCutOff I will sort a fix for this out later float rCutOff = random(coords); // A random float that determines if the red channel will be rounded up or down float gCutOff = random(coords); // A random float that determines if the green channel will be rounded up or down float bCutOff = random(coords); // A random float that determines if the blue channel will be rounded up or down float rPercentChance = frac(oldColor.r * 255); //Chance to round red channel up float gPercentChance = frac(oldColor.g * 255); //Chance to round green channel up float bPercentChance = frac(oldColor.b * 255); //Chance to round blue channel up //In the code below (1/255) is the floating point represntaion of an incress of one on the 0-255 RGB scale if (rCutOff <= rPercentChance) newColor.r = oldColor.r + ((1 - rPercentChance) / 255); //Bump up one r value else newColor.r = oldColor.r - rPercentChance * (1 / 255); //Bump down to ensure r is not rounded up if (gCutOff <= gPercentChance) newColor.g = oldColor.g + ((1 - gPercentChance) / 255); //Bump up one g value else newColor.b = oldColor.b - bPercentChance * (1 / 255); //Bump down to ensure g is not rounded up if (bCutOff <= bPercentChance) newColor.b = oldColor.b + ((1 - bPercentChance) / 255); //Bump up one b value else newColor.b = oldColor.b - bPercentChance * (1 / 255); //Bump down to ensure b is not rounded up return newColor; } // Input: It uses texture coords as the random number seed. // Output: Random number: [0,1), that is between 0.0 and 0.999999... inclusive. // Author: Michael Pohoreski // Copyright: Copyleft 2012 :-) float random( vec2 p ) { // We need irrationals for pseudo randomness. // Most (all?) known transcendental numbers will (generally) work. const vec2 r = vec2( 23.1406926327792690, // e^pi (Gelfond's constant) 2.6651441426902251); // 2^sqrt(2) (Gelfond–Schneider constant) return fract( cos( mod( 123456789., 1e-7 + 256. * dot(p,r) ) ) ); } [/CODE]
  12. [quote name='MJP' timestamp='1349415858' post='4987021'] I'm not sure why you'd get an "illegal character" error. Perhaps the encoding of the file you saved is incorrect? I think fxc can only work with plain ANSI text files. Anyway I had to make a few changes to get your shader to compile. You need to declare a sampler2D named s0, since you try to use one. The random function needs to be declared before DitherByChance, since that function uses it. Also the random code you got was in GLSL, and had to be converted. Here's a new version: [code] sampler2D s0; // Input: It uses texture coords as the random number seed. // Output: Random number: [0,1), that is between 0.0 and 0.999999... inclusive. // Author: Michael Pohoreski // Copyright: Copyleft 2012 :-) float random( float2 p ) { // We need irrationals for pseudo randomness. // Most (all?) known transcendental numbers will (generally) work. const float2 r = float2( 23.1406926327792690, // e^pi (Gelfond's constant) 2.6651441426902251); // 2^sqrt(2) (Gelfond–Schneider constant) return frac( cos( fmod( 123456789., 1e-7 + 256. * dot(p,r) ) ) ); } float4 DitherByChance(float2 coords : TEXCOORD0) : COLOR { float3 newColor; // The pixel color to return float4 oldColor = tex2D(s0, coords); // Note I know that as the code stands now rCutOff = gCutOff = bCutOff I will sort a fix for this out later float rCutOff = random(coords); // A random float that determines if the red channel will be rounded up or down float gCutOff = random(coords); // A random float that determines if the green channel will be rounded up or down float bCutOff = random(coords); // A random float that determines if the blue channel will be rounded up or down float rPercentChance = frac(oldColor.r * 255); //Chance to round red channel up float gPercentChance = frac(oldColor.g * 255); //Chance to round green channel up float bPercentChance = frac(oldColor.b * 255); //Chance to round blue channel up //In the code below (1/255) is the floating point represntaion of an incress of one on the 0-255 RGB scale if (rCutOff <= rPercentChance) newColor.r = oldColor.r + ((1 - rPercentChance) / 255); //Bump up one r value else newColor.r = oldColor.r - rPercentChance * (1 / 255); //Bump down to ensure r is not rounded up if (gCutOff <= gPercentChance) newColor.g = oldColor.g + ((1 - gPercentChance) / 255); //Bump up one g value else newColor.b = oldColor.b - bPercentChance * (1 / 255); //Bump down to ensure g is not rounded up if (bCutOff <= bPercentChance) newColor.b = oldColor.b + ((1 - bPercentChance) / 255); //Bump up one b value else newColor.b = oldColor.b - bPercentChance * (1 / 255); //Bump down to ensure b is not rounded up return float4(newColor, 1.0f); } [/code] [/quote] Thank you so much! My file was indeed encoded in UTF-8 which does blow up fxc. Your conversion of the GLSL code fixed the rest of my problems. I am struggling right now with figuring out how to use my effect when rendering 2d textures with spritebatch but if I can't figure it out I will post my problems here again. Thanks you again for your help.
  13. I Basically what I am trying to do is be able to display a red (or green or blue) letter with more then 256 possible shades. For example normally if I have a blue letter 'A' with an rgb value of (0 , 0 , 100) the next blue level up would be an rgb (0, 0 , 101). I want to be to show an 'A' that "APPEARS" to have an rgb value of (0, 0, 100.25). Basically I want to do this by making 3/4th of the pixels in the "A" have (0,0,100) and 1/4th have a value of (0,0,101). I noticed that there is a dither filter in DX but from reading about it I don't think it is quite what I want but I am not sure. The reason I don't think I can use the built in dithering is because from what I have read here: [url="http://www.toymaker.info/Games/html/render_states.html#blends"]http://www.toymaker.info/Games/html/render_states.html#blends[/url] the built in dithering is legacy code that only works when rendering to a 16bit surface. I need a way to dither from a pixel format that is > 8bits per channel down to 8bits per channel. Does any one know of a way I could implement this dithering. I don't know anything about writing pixel shaders but do you think that might be the right approach? If I could figure out a way to determine which pixels made up the letter I would could try a simple dithering technique where I just go through each pixel and based on a 25% probability bump the color up one but this would be less then ideal. Does anyone have any experience with dithering in DirectX and know of any techniques that would make this possible. NOTE: I am using SlimDX (DX9) but could switch to DX10/11 if needed
  14. NOTE: For technical reasons I need to target DX9 (not 10/11), I am offering $25 total via PayPal to any poster(s) who provide help leading to a resolution of this issue. I know that's not much but I am very poor and hopefully that is at least enough incentive to read my ridiculously long post. I am having some trouble with figuring out how I should structure my program. I will first describe the general description of my program and then go into the things I have tried and the issues I have run into. I am not developing a game but rather a suite of computerized tests to test human vision. I am writing the program in VB.Net but converting between .Net languages is relativity trivial so if your going to post some code don't go out of your way to post it as VB if your better with C#. Even examples in other languages would be appreciated. I know the post is a little long but I want to be as clear as possible about the issues I am having. Thanks in advance! Design: The program lunches a “Main Menu” VB.Net form that has lots of options to select different types of test and configure different options for the tests. When the user clicks the RunTest button for a specific test a TestObject representing that test is created. The TestObject constructor creates a StimulusDisplayObject(SDO) which is derived from the SlimDX RenderForm class. The job of the SDO class is to manage the SlimDX device object and render the different stimuli to the screen. It contains a list of StimulusObjects(SO) which are essentially just a DX surface that was loaded from an .bmp image and some location information that to tell the SDO class where to draw the surface on the screen. After the SDO is created the TestObject.BeginTest() method is called that is just a loop that presents a number of trials to the observer. The loop creates some SO objects and adds them to the list of SO objects of the SDO class to be displayed. Problems: Because the stimuli I preset for the tests is fairly static and I usually only had to change the image that was displayed to the screen once every sec or two at the most, I did not have the scene rendering continually at as high of an FPS as possible. I simply had a SDO.RenderScene() that would get called from the TestObject whenever something need to be changed on the screen. This worked pretty well until I tried to handle DeviceLostExceptions and similar issues I arise from when the user ALT-TABs, CTRL-ALT-Delete, Covers the window (when in windowed mode), etc..) I have not found an effective way to handle these types of errors without having the scene continually rendering. So I decided to try rewriting the SDO class to use SlimDXs MessagePump.Run() functionality to render the scene constantly, however this causes exceptions because The MessagePump.Run() conflicts with the MessagePump of the “Main Menu” Form (At least I think that is what this error message means: “Additional information: Starting a second message loop on a single thread is not a valid operation.”). I decided to try creating the SDO object in a new thread but then I can't communicate between the the TestObject and the SDO Object to add/remove/change the SO objects. I am not 100% sure that creating a multithreaded application is the best approach because I have read that DX and Threading leads to programing nightmares but I don't see any other solutions. I think I need to learn to use some kind of thread synchronization but I am very very new to threading and I want to make sure I am not heading down a road that is doomed to fail before I invest a long period of time learning to synchronized threads. If creating a multithreaded application is the best choice is there any DX/SlimDX threading issues I should be aware of? Any examples of simple SlimDX threaded programs that synchronize data across threads? Thanks for taking the time to read this post and I will extremely grateful to any advice you can give.
  15. [quote name='Mike.Popoloski' timestamp='1348674766' post='4984004'] There's nothing inherently wrong with only rendering when you need to. The reason games do it is because there are typical objects animating and camera movement constantly, so the changes have to be rendered anyway. If you give more information on what was going wrong with device lost scenarios, it might be a better approach to try to fix those and continue going the way you were before. If you want to render continuously though, that's also viable. The idea is that you *replace* the Application.Run() method with MessagePump.Run(). You can run as many forms as you want on the same message loop. MessagePump.Run() internally hooks the application "Idle" event and constantly calls your provided callback whenever there are no window messages in the queue. You can put your rendering code inside that loop, and then you can add objects to be rendered to some shared list whenever you need to run one of your tests. [/quote] Thanks for the help Mike. I am working on rewritting some of the code now. I was haveing trouble trying to handle the DeviceLostExceptions when not rendering on demand. I tried to have some render code that looked something like: [source lang="vb"]Sub RenderScene() ...Some Code Try device.present() Catch e as devLostEx DevLost = true recover() RenderScene() End Try End Sub Sub recover() While DevLost Try device.testCoop Catch DevLostEx 'Do nothing Catch DevNotReset ...Dispose defult pool stuff device.reset() recreate defult pool stuff DevLost = false End Try End While End Sub[/source] That was with MDX9 not SlimDX. It just seemed to hang and never recover. I am not sure why. Anyway I have got a SlimDX basic class rendering contiually and handleing device lost exceptions fine. I am running it in its own thread and am just using synclock to protect data when I pass new objects to the display. I think the code would be a little slow if I need to render really fast because I synclock most of the SlimDX code but I don't think it will be a big issue for me. I am however running in to some trouble. I can't find a SlimDX replacment for the MDX9 Surface.FromImage() method. Also someone said that the DeviceEx class as some better features for passing data between threads so should I be using that class? Thanks for any help you can provide.
  16. I am trying to get the MDX9 Surface.FromBitmap() functionality with SlimDX. I think I need to use the SlimDX.DX9.Surface.FromFile() method but all of the overloads of that method take a colorKey argument. What do I do if I want to render all of the colors?
  17. Also I am getting a D3DXERR_INVALIDDATA exception when I call the Surface.FromFile( ) method. I know that the path to the file is correct. [source lang="vb"] Public Overridable Sub CreateDeviceResources() Dim str As String = Application.StartupPath & "\phoriaRing.bmp" test = Surface.CreateOffscreenPlain(device, 150, 150, Format.A8R8G8B8, Pool.Default) Surface.FromFile(test, str, Filter.Default, 8) End Sub[/source] I tried enabling the debug runtime but its not much help: [CODE] Direct3D9: (INFO) :======================= Hal HWVP device selected Direct3D9: (INFO) :HalDevice Driver Style b Direct3D9: :Subclassing window 000d04ba Direct3D9: :StartExclusiveMode Direct3D9: (INFO) :Using FF to VS converter Direct3D9: (INFO) :Using FF to PS converter Direct3D9: (INFO) :Enabling multi-processor optimizations Direct3D9: (INFO) :DDI threading started D3D9 Helper: Warning: Default value for D3DRS_POINTSIZE_MAX is 5.80233e-315f, not 5.51222e-315f. This is ok. A first chance exception of type 'SlimDX.Direct3D9.Direct3D9Exception' occurred in SlimDX.dll An unhandled exception of type 'SlimDX.Direct3D9.Direct3D9Exception' occurred in SlimDX.dll Additional information: D3DXERR_INVALIDDATA: Invalid data (-2005529767) [/CODE] Ok I managed to get the Surface.FromFileInStream() working but I have to know the Size of the image and everything in advance. What if I don't know the size of the image. I guess I could load the File in a Image object and then record the information and then do a FromFileInStream but that seems like poor efficiency. There has to be a better way.
  18. Yes it is. At least I think it is. When I am running the test one monitor and have the mainMenu form opened on the other monitor the mainMenu buttons and textboxes are still responsive. How would I go about adding the update call to the forms messagePump.
  19. I am trying to convert the SlimDX device creation tutorial from DX11 to DX9. It is a very simple tutorial where you create a windows add a dx9 device and fill the screen with a solid color. However I am getting a D3DERR_NOTAVAILABLE error thrown when I try and create the device. All the code seems to make sense and it looks very similar to the C# code used in the samples. Any Ideas? NOTE: I create a instance of the BaseDisplayclass and call the InitSlimDX method in another class. [source lang="vb"]Imports SlimDX.Windows Imports SlimDX.Direct3D9 Imports SlimDX Imports Device = SlimDX.Direct3D9.Device Imports Resource = SlimDX.Direct3D9.Resource Imports System.Windows.Forms.ThreadExceptionDialog Imports System.IO Public Class BaseDisplay Inherits RenderForm 'SlimDX Class Vars Protected device As Device = Nothing Protected backBuffer As Surface Protected presentParams As PresentParameters Public Sub New() Show() End Sub Public Sub InitSlimDX() Dim d3d As Direct3D = New Direct3D() Dim primaryAdaptor As AdapterInformation = d3d.Adapters().First() presentParams = New PresentParameters() With presentParams .BackBufferWidth = Me.ClientSize.Width .BackBufferHeight = Me.ClientSize.Height End With Me.device = New Device(d3d, primaryAdaptor.Adapter, DeviceType.Hardware, Me.Handle, CreateFlags.HardwareVertexProcessing, presentParams) Me.device.BeginScene() backBuffer = device.GetBackBuffer(0, 0) Me.device.ColorFill(backBuffer, New Color4(Color.CornflowerBlue)) Me.device.EndScene() Me.device.Present() End Sub Public Overloads Sub Dispose() device.Dispose() MyBase.Dispose() End Sub End Class[/source]
  20. I figured out what my problem was. Earlier I was messing with my DX9 settings in the DirectX control panel and for some reason I enabled the "Software Only" setting which disabled hardware acceleration. disabling this option fixed the issue. Thanks.
  21. I am trying to work my way through converting the 2nd SlimDX tutorial to Vb.Net and am having some trouble. I slightly changed the tutorial in the sense that I am creating a display class that inherits from the RenderForm Class. But I am getting an InvalidOperationException in the MessagePump.Run() function. The error message says "Starting a second message loop on a single thread is not a valid operation. Use Form.ShowDialog instead." I will just post the whole code becasue its only 70 lines or so. This is the DisplayClass: [source lang="vb"]Imports SlimDX.Windows Imports SlimDX.Direct3D11 Imports SlimDX.DXGI Imports SlimDX Imports Device = SlimDX.Direct3D11.Device Imports Resource = SlimDX.Direct3D11.Resource Public Class BaseStimulusDisplay Inherits RenderForm Protected device As Device = Nothing Protected swapChain As SwapChain = Nothing Protected renderTarget As RenderTargetView Protected context As DeviceContext Protected viewport As Viewport Public Sub New() Dim description As New SwapChainDescription() With description .BufferCount = 1 .Usage = Usage.RenderTargetOutput .OutputHandle = Me.Handle .IsWindowed = True .ModeDescription = New ModeDescription(0, 0, New Rational(60, 1), Format.B8G8R8A8_UNorm) .SampleDescription = New SampleDescription(1, 0) .Flags = SwapChainFlags.AllowModeSwitch .SwapEffect = SwapEffect.Discard End With 'Create the device with the SwapChain if I am haveing trouble debuging code. I might want to try to use the other ' device creation flags such as the debug flag device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, description, device, swapChain) Using resource As Texture2D = SlimDX.Direct3D11.Resource.FromSwapChain(Of Texture2D)(swapChain, 0) renderTarget = New RenderTargetView(device, resource) End Using context = device.ImmediateContext viewport = New Viewport(0.0F, 0.0F, Me.ClientSize.Width, Me.ClientSize.Height) context.OutputMerger.SetTargets(renderTarget) context.Rasterizer.SetViewports(viewport) Using factory As Factory = swapChain.GetParent(Of Factory)() factory.SetWindowAssociation(Me.Handle, WindowAssociationFlags.IgnoreAltEnter) End Using End Sub Private Sub toggleFullscreen(ByVal sender As System.Object, ByVal args As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown If args.Alt And args.KeyCode = Keys.Enter Then swapChain.IsFullScreen = Not swapChain.IsFullScreen End If End Sub Private Sub displayLoop() context.ClearRenderTargetView(renderTarget, New Color4(0.5F, 0.5F, 1.0F)) swapChain.Present(0, PresentFlags.None) End Sub Public Sub run() MessagePump.Run(Me, AddressOf displayLoop) End Sub Public Overloads Sub Dispose() swapChain.Dispose() renderTarget.Dispose() device.Dispose() MyBase.Dispose() End Sub End Class[/source] And this is the main startup form of my code: [source lang="vb"]Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim form As New BaseStimulusDisplay() form.run() End Sub End Class[/source]
  22. Never mind. I found a solution. Thanks for the help.
  23. Ok, So I set the BaseStimulusDisplay object as the start-up object/form and got rid of the other form all together which made the code work. I also called the .run method (which runs the messagePump() at the end of the constructor. That made the program run as I wanted however I want to be able to start and stop these "SlimDX windows" from a regular Visual Basic Form Application. How would I do this if the SlimDX messagePump and the form messagePump are mutually exclusive?
  • Advertisement