• Advertisement

DemonLord

Member
  • Content count

    10
  • Joined

  • Last visited

Community Reputation

344 Neutral

About DemonLord

  • Rank
    Member
  1. 2D sprites and ambient light

    I have a question about BlendState. Is it possible to make sprites outside of my spot light blend into dark ambient light with BlendState? [img]http://shrani.si/f/2g/xo/1uGIilZy/alpha.png[/img] I kinda made sprites in my spot light translucent and those far away normal but I don't really know if I can make them blend with the ambient light [img]http://public.gamedev.net//public/style_emoticons/default/sad.png[/img] This is what I use to make the effect on the screenschot: [CODE] private Color _ambientLight = new Color(.1f, .1f, .1f, .1f); // for HLSL public static BlendState BlendBlack = new BlendState { ColorBlendFunction = BlendFunction.Add, ColorSourceBlend = Blend.One, ColorDestinationBlend = Blend.One, AlphaBlendFunction = BlendFunction.Add, AlphaSourceBlend = Blend.SourceAlpha, AlphaDestinationBlend = Blend.One }; [/CODE] Any help or tip would be helpful. Thanx
  2. Hi. I want to make all sprites that are not in my spot light to be hardly visible. Only when I come near enough to light them up with my spot light should they be fully visible. This is how it looks: [media]http://www.youtube.com/watch?v=1IRtth-Ro2M[/media] Question is: How do I make sprites less visible when not in my spot light? Thanx for help.
  3. HLSL lights problem

    Hi. I have a problem with adding lights to my game (XNA 4.0). I've made an underwater effect (slight waving of the screen) but I can't get a spot light atop of my submarine to work. My goal is to attach a spot light in front of my submarine and darken the surroundings, to get more deep ocean feeling. I suspect I'm doing something wrong with RenderTarget2D, but don't know what (I'm not 100% sure how RenderTarget2D works) [media]http://www.youtube.com/watch?v=eixfVRMScq4[/media] Here's my Draw method and some other lights methods: [CODE] public override void Draw(GameTime gameTime) { ScreenManager.GraphicsDevice.Clear(Color.Transparent); // Set the render targets ScreenManager.GraphicsDevice.SetRenderTarget(colorMapRenderTarget); // Clear all render targets ScreenManager.GraphicsDevice.Clear(Color.Transparent); ScreenManager.GraphicsDevice.SetRenderTarget(null); ScreenManager.GraphicsDevice.SetRenderTarget(normalMapRenderTarget); // Clear all render targets ScreenManager.GraphicsDevice.Clear(Color.Transparent); DrawNormalMap(); // Deactive the rander targets to resolve them ScreenManager.GraphicsDevice.SetRenderTarget(null); GenerateShadowMap(); ScreenManager.GraphicsDevice.Clear(Color.Transparent); // Finally draw the combined Maps onto the screen DrawCombinedMaps(); /* Clear the screen */ ScreenManager.GraphicsDevice.SetRenderTarget(renderTarget); ScreenManager.GraphicsDevice.Clear(Color.Transparent); //Draw background DrawColorMap(); /********************* * Drawing all nodes * *********************/ //Drawing players spriteBatch.Begin(); foreach (Node node in Node.Nodes) node.Draw(spriteBatch); for (int i = 0; i < Player.Players.Length; i++) { PlayerShip ship = Player.Players[0].Ship; string text; if (ship != null) text = String.Format("Shield power: {1}", 0 + 1, ship.Health); else text = String.Format("P{0} <>", i + 1); spriteBatch.DrawString(font, text, new Vector2(10, 0 * 20 + 10), Color.White); } spriteBatch.End(); /* end drawing nodes */ /********************* * PostProcess.fx * * HLSL water effect * *********************/ ScreenManager.GraphicsDevice.SetRenderTarget(null); SceneTexture = renderTarget; ScreenManager.GraphicsDevice.Clear(Color.Transparent); spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque); { effectPost.CurrentTechnique.Passes[0].Apply(); { effectPost.Parameters["fTimer"].SetValue(m_Timer); spriteBatch.Draw(SceneTexture, new Rectangle(0, 0, gfx.PreferredBackBufferWidth, gfx.PreferredBackBufferHeight), Color.White); } } spriteBatch.End(); /* end HLSL water effect */ // If the game is transitioning on or off, fade it out to black. if (TransitionPosition > 0 || pauseAlpha > 0) { float alpha = MathHelper.Lerp(1f - TransitionAlpha, 1f, pauseAlpha / 2); ScreenManager.FadeBackBufferToBlack(alpha); } } #region Light Methods /***************************** * Combined Maps Draw method * *****************************/ private void DrawCombinedMaps() { lightCombinedEffect.CurrentTechnique = lightCombinedEffectTechnique; lightCombinedEffectParamAmbient.SetValue(1f); lightCombinedEffectParamLightAmbient.SetValue(4); lightCombinedEffectParamAmbientColor.SetValue(ambientLight.ToVector4()); lightCombinedEffectParamColorMap.SetValue(colorMapRenderTarget); lightCombinedEffectParamShadowMap.SetValue(shadowMapRenderTarget); lightCombinedEffectParamNormalMap.SetValue(normalMapRenderTarget); lightCombinedEffect.CurrentTechnique.Passes[0].Apply(); spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null, lightCombinedEffect); spriteBatch.Draw(colorMapRenderTarget, Vector2.Zero, Color.White); spriteBatch.End(); } /* end Combined Maps Draw method */ /*************************** * Normals Map Draw method * ***************************/ private void DrawNormalMap() { spriteBatch.Begin(); spriteBatch.Draw(bgNormals, Vector2.Zero, Color.White); spriteBatch.End(); } /* end Normals Map Draw method */ /********************************************** * Color Map Draw method - regular background * **********************************************/ private void DrawColorMap() { spriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.LinearWrap, null, null); spriteBatch.Draw(bg, Vector2.Zero, new Rectangle(0, (int)(-scrollY), bg.Width, bg.Height), Color.White); spriteBatch.End(); } /* end Color Map Draw method */ /******************************** * Shadow Map Generation method * ********************************/ private Texture2D GenerateShadowMap() { ScreenManager.GraphicsDevice.SetRenderTarget(shadowMapRenderTarget); ScreenManager.GraphicsDevice.Clear(Color.Transparent); foreach (var light in lights) { if (!light.IsEnabled) continue; // Draw all the light sources lightEffectParameterStrength.SetValue(light.ActualPower); lightEffectParameterPosition.SetValue(light.Position); lightEffectParameterLightColor.SetValue(light.Color); lightEffectParameterLightDecay.SetValue(light.LightDecay); // Value between 0.00 and 2.00 lightEffect.Parameters["specularStrength"].SetValue(specularStrength); if (light.LightType == LightType.Point) { lightEffect.CurrentTechnique = lightEffectTechniquePointLight; } else { lightEffect.CurrentTechnique = lightEffectTechniqueSpotLight; lightEffectParameterConeAngle.SetValue(((SpotLight)light).SpotAngle); lightEffectParameterConeDecay.SetValue(((SpotLight)light).SpotDecayExponent); lightEffectParameterConeDirection.SetValue(((SpotLight)light).Direction); } lightEffectParameterScreenWidth.SetValue(ScreenManager.GraphicsDevice.Viewport.Width); lightEffectParameterScreenHeight.SetValue(ScreenManager.GraphicsDevice.Viewport.Height); lightEffect.Parameters["ambientColor"].SetValue(ambientLight.ToVector4()); lightEffectParameterNormapMap.SetValue(normalMapRenderTarget); lightEffect.Parameters["ColorMap"].SetValue(colorMapRenderTarget); lightEffect.CurrentTechnique.Passes[0].Apply(); // Add Belding (Black background) ScreenManager.GraphicsDevice.BlendState = BlendBlack; } // Deactive the rander targets to resolve them ScreenManager.GraphicsDevice.SetRenderTarget(null); return shadowMapRenderTarget; } /* end Shadow Map Generation method */ public static BlendState BlendBlack = new BlendState() { ColorBlendFunction = BlendFunction.Add, ColorSourceBlend = Blend.One, ColorDestinationBlend = Blend.One, AlphaBlendFunction = BlendFunction.Add, AlphaSourceBlend = Blend.SourceAlpha, AlphaDestinationBlend = Blend.One }; #endregion [/CODE] Am I missing something or am I doing this completely wrong? I'd be thankful if anyone could point me in the right direction. Thanx.
  4. I'm making a top-down shoot'em up / bullet hell game in XNA. The game doesn't have a name yet, but I have a story line and plans to make a trilogy. Base engine is near completion, but I'm still experimenting some things that I want to include in the game. I've made some clips: [media]http://www.youtube.com/watch?v=BcY2kADexfU[/media] [media]http://www.youtube.com/watch?v=Rn9DIL8Q1Mc[/media] [media]http://www.youtube.com/watch?v=J6DBv4psyGk[/media] It's still far from complete, but I think it might be finished by the end of the year. The game will have around 30 levels per difficulty, upgradable weapons (buying and upgrading weapons between levels), ship will have a shield which will be slowly repaired by a repairbot, but if too much damage is taken and shield is gone - one hit = death. If you find this interesting, check my youtube channel for new clips: [url="http://www.youtube.com/user/Demonsaso"]http://www.youtube.com/user/Demonsaso[/url]
  5. [XNA] Problem moving 3D model with keyboard

    I'll use this topic for my new problem considering 3D model movement. Problem is when I move my model from center of the screen to the left (or right), model rolls nicely as I want it to, but when I reach the left side of the screen and start to move back towards the center, model moves right AND up towards the camera, what I don't want. [media]http://www.youtube.com/watch?v=2PhVdkTD6wc[/media] I don't know how to fix this. It seem as if the pivot point was somewhere below the model, but I imported the model into Maya and set pivot to center and export to FBX. (did I forgot something?) Here's the code for movement: [code] protected void UpdateInput(GameTime gameTime) { KeyboardState newState = Keyboard.GetState(); if (newState.IsKeyDown(Keys.Escape)) this.Exit(); float time = (float)gameTime.ElapsedGameTime.TotalMilliseconds; float moveX = 0.0f; float moveZ = 0.0f; if (newState.IsKeyDown(Keys.W)) moveX += modelSpeed * time; if (newState.IsKeyDown(Keys.S)) moveX -= modelSpeed * time; if (newState.IsKeyDown(Keys.A)) { moveZ -= modelSpeed * time; modelRotation -= 0.01f; if (modelRotation < -0.5f) modelRotation = -0.5f; } if (newState.IsKeyDown(Keys.D)) { moveZ += modelSpeed * time; modelRotation += 0.01f; if (modelRotation > 0.5f) modelRotation = 0.5f; } oldState = newState; modelPosition += new Vector3(moveX, 0, moveZ); } [/code] If anyone knows what might be the problem, please do tell.
  6. [XNA] Problem moving 3D model with keyboard

    Thanx a million! Man, I'm blind :[
  7. Hi. I have a problem moving 3D model, when I press two keys at the same time. Let's say I want to move my model from center of the screen (camera isn't moving) diagonaly to upper left corner. Even tho I press two keys, the model will move in the direction of the key pressed first or if I press A key after already holding down W key, the model will continue to travel upwards. Any ideas on how should I fix this? protected void UpdateInput(GameTime gameTime) { KeyboardState currentKeyState = Keyboard.GetState(); float time = (float)gameTime.ElapsedGameTime.TotalMilliseconds; float moveX = 0.0f; float moveZ = 0.0f; if (currentKeyState.IsKeyDown(Keys.W)) moveX += 0.1f* time; else if (currentKeyState.IsKeyDown(Keys.S)) moveX -= 0.1f * time; else if (currentKeyState.IsKeyDown(Keys.A)) moveZ -= 0.1f * time; else if (currentKeyState.IsKeyDown(Keys.D)) moveZ += 0.1f * time; modelPosition += new Vector3(moveX, 0, moveZ); } protected override void Update(GameTime gameTime) { KeyboardState keyboardState = Keyboard.GetState(PlayerIndex.One); if (keyboardState.IsKeyDown(Keys.Escape)) this.Exit(); UpdateInput(gameTime); modelPosition += modelVelocity; modelVelocity *= 0.95f; base.Update(gameTime); } Thanx.
  8. [XNA] Underwater caustics help

    Thanx for your help & tips guys.
  9. [XNA] Underwater caustics help

    I want to make an underwater environment using XNA. If anyone would be so kind to point me in the right direction as how to begin to make water caustics. I made terrain using heightmap, refraction + reflection plane with HLSL and above water looks nice (Reimer's XNA tutorials). But now I'd like to make underwater look something like the picture below, but I don't know how. I think I need something like this, but I don't know where and how to use it: but don't know if it must be just a texture or must it be animated. So, if anyone can point me to a good theory web page or even better, a tutorial on how to make water caustics, it would be great. Thnax
  10. C# and C++

    I'm learning C# + XNA for several months now and it's fairly easy to learn (and thanx goes to Andrew Russell for morale boosting on C# + XNA :) ). What I'd like to know is, what can be done in C++ more that in C# - I saw many times people refering to C++ as the mother of game dev - I'm interested in 2D games only (for now). [Edited by - DemonLord on April 6, 2010 6:42:23 AM]
  • Advertisement