Mathy

Members
  • Content count

    100
  • Joined

  • Last visited

Community Reputation

104 Neutral

About Mathy

  • Rank
    Member
  1. I am now trying to use LockRectangle of the Texture object. However, I don't know exactly how to use it. I found various documentation all over, and people with the same problems on these forums, but no direct solution to the problem. How do I use it if I (for instance) wish to make the whole texture white?
  2. I am trying to fill a rectangle in SlimDX with a specific color programmatically, by dynamically creating a texture with the specified color. However, it does not work, and draws weird black squares instead. The class is listed below. using System; using System.Collections.Generic; using System.Linq; using System.Text; using SlimDX.Direct3D9; using System.Drawing; using SlimDX; namespace Morbus2D4.Interface { class Rectangle : Morbus2D4.Interface.Base.InterfaceBaseObject { private System.Drawing.Rectangle rectangle; private Texture texture; private SlimDX.Color4 colorToUse = new SlimDX.Color4(Color.White); public Rectangle(Device device, int x, int y, int width, int height) { rectangle = new System.Drawing.Rectangle(x, y, width, height); texture = new Texture(device, width, height, 0, Usage.None, Format.X8R8G8B8, Pool.Default); } public SlimDX.Color4 color { get { return colorToUse; } set { colorToUse = value; } } public override void doAct() { } public override void doTransform(SlimDX.Direct3D9.Sprite sprite) { sprite.Transform = Matrix.Identity; } public override void doRender(SlimDX.Direct3D9.Sprite sprite) { sprite.Draw(texture, rectangle, colorToUse); } } } Any ideas?
  3. I almost got the right result now, except for a weird phenomenon! http://img80.imageshack.us/img80/2696/wtfx.png Check that out. The glow looks almost flawless, except for the fact that in the right half-circle of a sphere, the shadow is like double as intense as the previous one. Here's my vertex shader function, inspired by a DirectX 9.0b SDK sample: glowOutput doVirusGlow(virusInput input, float4x4 instanceTransform, instanceData iInput) { float4 worldPosition = mul(input.position, instanceTransform); float4 worldNormal = mul(input.normal, instanceTransform); glowOutput output = (glowOutput)0; float3 N = normalize(mul(worldNormal, (float3x3)View)); // normal (view space) float3 P = mul(worldPosition, View) + GlowThickness * N; // displaced position (view space) float3 A = float3(0, 0, 1); // glow axis float power; power = dot(N, A); power *= power; power = -power; power *= power; output.position = mul(float4(P, 1), Projection); // projected position output.diffuse = (GlowColor * power) + GlowAmbient; // modulated glow color + glow ambient return output; } As you can see, I added "power = -power" to get the effect you told me about. Now the shadow is just acting up (it was also doing this before). Since you've been a great help so far, could you help me identify the problem?
  4. I am currently looking for a code that can basically add a glow to a sphere without a texture, since I have this theory that adding a texture to every sphere when there are many of them will slow things down. So I noticed the NVidia shader called Post Glow Balloon, located here: http://developer.download.nvidia.com/shaderlibrary/webpages/screenshots/shaders/post_glowBalloon.html This kind of creates a "force field" around my sphere, but I want it to be a glow. In other words, I want it to reverse the colors, so that the yellow-ish color is close to the sphere's center, and the black-ish color is away from the sphere. Is there any way I can do that? Is it recommended for me to switch to texture-based shaders and have a texture for every sphere? I'd love your recommendations on this.
  5. Shader for sphere glow?

    Okay, now there is transparency. I had to add something that wasn't added correctly to the shader. However, now the results are entirely different. The GlowAmbient color is the one that is in the inner-circle of the glow, and the GlowColor is the color that is in the outer-circle of the glow. Not opposite, as it should be. Right now, the glow fades from transparent to red. It should fade from red to transparent.
  6. Shader for sphere glow?

    This almost works! The glow can be seen, but there is no transparency. The glow is entirely green with the colors defined as following: float4 GlowColor = float4(0.0f, 1.0f, 0.0f, 1.0f); float4 GlowAmbient = float4(0.0f, 1.0f, 0.0f, 0.0f); It's almost as if it ignores the alpha channel. Any suggestions?
  7. I heard there's a simple way of implementing a sphere glow in a pixel/vertex shader. How can this be done? I am not using textures or anything. My spheres are entirely rendered with colors.
  8. Fair enough. But why did you (Hodgman) say that it is a n^2 operation in the sample, when they talk about taking the average position from nearby boids in the link to the sample? Isn't that already only taking nearby boids into account? If not, how would I change its shader to do so?
  9. What is the difference between n^2 and O(n^2)? And thanks for the information so far by the way. Also, how would I modify the current shader in the sample to only look for close items?
  10. Well, does anyone know if the sample would be able to be built in a DirectX 9 version too?
  11. I just realized the example in the SDK runs very slowly, at 1.5 FPS. Is that because my graphics card does not support DirectX 10, which the sample basically uses? What can I expect for framerate if I change it to DirectX 9? Oh, and would DirectX 9 even support such operations needed for the boids example?
  12. Quote:Original post by MJP Have you had a look at this? Wow! This indeed looks interesting - does that support both targetting, and avoidance of other objects and such?
  13. Is there any way that I can emulate the boids algorithm on the GPU? I already have a hardware instancing shader set up and everything. However, I can't get to think of how this should be done. The reason for it is that I am having issues with a boids algorithm simulation when it goes up to approximately 2500 units on my laptop. The framerate drops like crazy.
  14. I'm doing instancing, which works fine apparently. However, after a random amount of time, I am getting a System.IO.EndOfStreamException on the following line: dataStream.WriteRange(instanceData.ToArray()); How come? How can a write function even get an error that says "Attempted to read past the end of the stream."? Sounds incredibly weird to me. Especially when I am doing this right before, for extra security: dataStream.Position = 0; The full error-details are here: System.IO.EndOfStreamException: Attempted to read past the end of the stream. at SlimDX.DataStream.WriteRange[T](T[] data, Int32 offset, Int32 count) at Morbus2D4.Shaders.Instancing.performInstancing(Device& device, EffectHandle& instancingMethod, VertexBuffer& vertexBuffer, IndexBuffer& indexBuffer, VertexDeclaration& vertexDeclaration, List`1 instanceData, Int32 amountOfInstances, VertexBuffer& instanceDataStream, Int16& vertexCount, Int16& indexCount) in C:\Users\Mathy\Documents\Visual Studio 2010\Projects\Morbus2D4\Morbus2D4\Page data\Game\Shaders\Instancing\Instancing.cs:line 76
  15. I almost figured it out. This is my shader code now: VertexShaderOutput doComputerInstancing(computerInput input, float4x4 instanceTransform, float state) { VertexShaderOutput output; float4 worldPosition = mul(input.position, instanceTransform*2); float4 viewPosition = mul(worldPosition, View); output.position = mul(viewPosition, Projection); if(dot(float3(input.normal.x,input.normal.y,input.normal.z+1),input.normal)<0.25) { output.color = float4(1,1,1,1); } return output; } The problem with this code is that now the white stroke effect is based on the camera position. If I move the camera to the right of the objects, the stroke becomes more intense to the right rather than left, as if it was an inner shadow effect. I need it to ignore the perspective view I have.