HLSL Shaders: Arguing Semantics..
HLSL Shaders: Arguing Semantics..
HLSL Shaders: Arguing Semantics..
HLSL Shaders: Arguing Semantics..
HLSL Shaders: Arguing Semantics..
HLSL Shaders: Arguing Semantics.. HLSL Shaders: Arguing Semantics.. HLSL Shaders: Arguing Semantics.. HLSL Shaders: Arguing Semantics.. HLSL Shaders: Arguing Semantics.. HLSL Shaders: Arguing Semantics.. HLSL Shaders: Arguing Semantics.. HLSL Shaders: Arguing Semantics..
HLSL Shaders: Arguing Semantics.. HLSL Shaders: Arguing Semantics..
HLSL Shaders: Arguing Semantics..
Go Back  Xtreme Visual Basic Talk > > > > HLSL Shaders: Arguing Semantics..


Reply
 
Thread Tools Display Modes
  #1  
Old 05-28-2009, 12:04 PM
Joe_Dert Joe_Dert is offline
Freshman
 
Join Date: Mar 2009
Posts: 26
Default HLSL Shaders....


Well, I was wanting some help with getting a 3D shader working in 2d, but I figured it out myself.. (The shader was being rendered to a screen aligned quad, so I just had to remove, and rewrite the vertex shader portion to work under the pixel shader instead..)

Here is the code for anyone who is interested... (It's code converted from a Render Monkey example... fire.fx..)

Code:
float time_0_X;

float4 layer_speed;

float distortion_amount0;
float distortion_amount1;
float distortion_amount2;

float4 height_attenuation;

texture fire_base_Tex;
texture fire_distortion_Tex;
texture fire_opacity_Tex;

float2 glitch_fix1;

sampler fire_base = sampler_state
{
   Texture = (fire_base_Tex);
}; // Fire Texture

sampler fire_distortion = sampler_state
{
   Texture = (fire_distortion_Tex);
}; // Fire Distortion Texture

sampler fire_opacity = sampler_state
{
   Texture = (fire_opacity_Tex);
}; // Fire Opacity Texture

// Bias and double a value to take it from 0..1 range to -1..1 range
float4 bx2(float x)
{
   return 2.0f * x - 1.0f;
}

float4 main( float2 Tex : TEXCOORD0  ) : COLOR0
{

   float2 tc0= Tex;
   float2 tc1; 
   float2 tc2;

   tc1.x = Tex.x;
   tc1.y = Tex.y + layer_speed.x * time_0_X;
   tc2.x =  Tex.x;
   tc2.y = Tex.y + layer_speed.y * time_0_X;

   // Sample noise map three times with different texture coordinates
   float2 noise0 = tex2D(fire_distortion, tc1);
   float2 noise1 = tex2D(fire_distortion, tc2);
 
   // Weighted sum of signed noise
   float2 noiseSum = bx2(noise0.r) * distortion_amount0 + bx2(noise1.r) * distortion_amount1;

   // Perturb base coordinates in direction of noiseSum as function of height (y)
   float2 perturbedBaseCoords= tc0 + noiseSum * (tc0.y + height_attenuation.y); // = tc0 + noiseSum * (tc0.y * height_attenuation.x + height_attenuation.y);

   // Sample base and opacity maps with perturbed coordinates
   float4 base;
   float4 opacity;

   // Used to hide a few graphic bugs(Like y wrap around.)
   // This is for the y coords, the x coords could use one too..
   // just mimic this for Tex.x using appropriate values..
   if(Tex.y < glitch_fix1.x)
   {
   base = tex2D(fire_base, tc0);
   opacity = tex2D(fire_opacity, tc0);
   base.a = 0.0F;
   opacity.a = 0.0F;
   }

   if(Tex.y < glitch_fix1.y)
   {
   	if(Tex.y > glitch_fix1.x)
   	{
   		base = tex2D(fire_base, perturbedBaseCoords);
   		opacity = tex2D(fire_opacity, perturbedBaseCoords);
	}
   }
   else
   {
   base = tex2D(fire_base, tc0);
   opacity = tex2D(fire_opacity, tc0);
   base.a = 0.0F;
   opacity.a = 0.0F;
   }

   return base * opacity;
}

technique Fire
{
   pass Single_Pass
   {
      PixelShader = compile ps_2_0 main();
   }

}
Here are the parameters I'm using for it.. (I'm using XNA for my rendering..)

Code:
            Fire.Parameters("fire_base_Tex").SetValue(FireBase)
            Fire.Parameters("fire_distortion_Tex").SetValue(FireDistort)
            Fire.Parameters("fire_opacity_Tex").SetValue(FireOpacity)
            Fire.Parameters("distortion_amount0").SetValue(0.12F)
            Fire.Parameters("distortion_amount1").SetValue(0.09F)
            Fire.Parameters("distortion_amount2").SetValue(0.07F)
            Fire.Parameters("glitch_fix1").SetValue(New Vector2(0.16F, 0.85F))
            Fire.Parameters("height_attenuation").SetValue(New Vector4(0.44F, 0.19F, 0.0F, -1.0F))
            Fire.Parameters("layer_speed").SetValue(New Vector4(0.68F, 0.52F, 0.75F, 1.0F))
            FireTimer += gt.ElapsedGameTime.Milliseconds / 800
            Fire.Parameters("time_0_X").SetValue(FireTimer)
            Fire.CommitChanges()

Last edited by Joe_Dert; 05-28-2009 at 05:14 PM. Reason: Added more information on shader use...
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
HLSL Shaders: Arguing Semantics..
HLSL Shaders: Arguing Semantics..
HLSL Shaders: Arguing Semantics.. HLSL Shaders: Arguing Semantics..
HLSL Shaders: Arguing Semantics..
HLSL Shaders: Arguing Semantics..
HLSL Shaders: Arguing Semantics.. HLSL Shaders: Arguing Semantics.. HLSL Shaders: Arguing Semantics.. HLSL Shaders: Arguing Semantics.. HLSL Shaders: Arguing Semantics.. HLSL Shaders: Arguing Semantics.. HLSL Shaders: Arguing Semantics..
HLSL Shaders: Arguing Semantics..
HLSL Shaders: Arguing Semantics..
 
HLSL Shaders: Arguing Semantics..
HLSL Shaders: Arguing Semantics..
 
-->