-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
839 additions
and
173 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// Filename: fire.ps | ||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
|
||
///////////// | ||
// GLOBALS // | ||
///////////// | ||
Texture2D fireTexture : register(t0); | ||
Texture2D noiseTexture : register(t1); | ||
Texture2D alphaTexture : register(t2); | ||
SamplerState SampleType; | ||
SamplerState SampleType2; | ||
|
||
cbuffer DistortionBuffer | ||
{ | ||
float2 distortion1; | ||
float2 distortion2; | ||
float2 distortion3; | ||
float distortionScale; | ||
float distortionBias; | ||
}; | ||
|
||
|
||
////////////// | ||
// TYPEDEFS // | ||
////////////// | ||
struct PixelInputType | ||
{ | ||
float4 position : SV_POSITION; | ||
float2 tex : TEXCOORD0; | ||
float2 texCoords1 : TEXCOORD1; | ||
float2 texCoords2 : TEXCOORD2; | ||
float2 texCoords3 : TEXCOORD3; | ||
}; | ||
|
||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
// Pixel Shader | ||
//////////////////////////////////////////////////////////////////////////////// | ||
float4 FirePixelShader(PixelInputType input) : SV_TARGET | ||
{ | ||
float4 noise1; | ||
float4 noise2; | ||
float4 noise3; | ||
float4 finalNoise; | ||
float perturb; | ||
float2 noiseCoords; | ||
float4 fireColor; | ||
float4 alphaColor; | ||
|
||
|
||
// Sample the same noise texture using the three different texture coordinates to get three different noise scales. | ||
noise1 = noiseTexture.Sample(SampleType, input.texCoords1); | ||
noise2 = noiseTexture.Sample(SampleType, input.texCoords2); | ||
noise3 = noiseTexture.Sample(SampleType, input.texCoords3); | ||
|
||
// Move the noise from the (0, 1) range to the (-1, +1) range. | ||
noise1 = (noise1 - 0.5f) * 2.0f; | ||
noise2 = (noise2 - 0.5f) * 2.0f; | ||
noise3 = (noise3 - 0.5f) * 2.0f; | ||
|
||
// Distort the three noise x and y coordinates by the three different distortion x and y values. | ||
noise1.xy = noise1.xy * distortion1.xy; | ||
noise2.xy = noise2.xy * distortion2.xy; | ||
noise3.xy = noise3.xy * distortion3.xy; | ||
|
||
// Combine all three distorted noise results into a single noise result. | ||
finalNoise = noise1 + noise2 + noise3; | ||
|
||
// Perturb the input texture Y coordinates by the distortion scale and bias values. | ||
// The perturbation gets stronger as you move up the texture which creates the flame flickering at the top effect. | ||
perturb = ((1.0f - input.tex.y) * distortionScale) + distortionBias; | ||
|
||
// Now create the perturbed and distorted texture sampling coordinates that will be used to sample the fire color texture. | ||
noiseCoords.xy = (finalNoise.xy * perturb) + input.tex.xy; | ||
|
||
// Sample the color from the fire texture using the perturbed and distorted texture sampling coordinates. | ||
// Use the clamping sample state instead of the wrap sample state to prevent flames wrapping around. | ||
fireColor = fireTexture.Sample(SampleType2, noiseCoords.xy); | ||
|
||
// Sample the alpha value from the alpha texture using the perturbed and distorted texture sampling coordinates. | ||
// This will be used for transparency of the fire. | ||
// Use the clamping sample state instead of the wrap sample state to prevent flames wrapping around. | ||
alphaColor = alphaTexture.Sample(SampleType2, noiseCoords.xy); | ||
|
||
// Set the alpha blending of the fire to the perturbed and distored alpha texture value. | ||
fireColor.a = alphaColor; | ||
|
||
return fireColor; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// Filename: fire.vs | ||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
|
||
///////////// | ||
// GLOBALS // | ||
///////////// | ||
cbuffer MatrixBuffer | ||
{ | ||
matrix worldMatrix; | ||
matrix viewMatrix; | ||
matrix projectionMatrix; | ||
}; | ||
|
||
cbuffer NoiseBuffer | ||
{ | ||
float frameTime; | ||
float3 scrollSpeeds; | ||
float3 scales; | ||
float padding; | ||
}; | ||
|
||
|
||
////////////// | ||
// TYPEDEFS // | ||
////////////// | ||
struct VertexInputType | ||
{ | ||
float4 position : POSITION; | ||
float2 tex : TEXCOORD0; | ||
}; | ||
|
||
struct PixelInputType | ||
{ | ||
float4 position : SV_POSITION; | ||
float2 tex : TEXCOORD0; | ||
float2 texCoords1 : TEXCOORD1; | ||
float2 texCoords2 : TEXCOORD2; | ||
float2 texCoords3 : TEXCOORD3; | ||
}; | ||
|
||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
// Vertex Shader | ||
//////////////////////////////////////////////////////////////////////////////// | ||
PixelInputType FireVertexShader(VertexInputType input) | ||
{ | ||
PixelInputType output; | ||
|
||
|
||
// Change the position vector to be 4 units for proper matrix calculations. | ||
input.position.w = 1.0f; | ||
|
||
// Calculate the position of the vertex against the world, view, and projection matrices. | ||
output.position = mul(input.position, worldMatrix); | ||
output.position = mul(output.position, viewMatrix); | ||
output.position = mul(output.position, projectionMatrix); | ||
|
||
// Store the texture coordinates for the pixel shader. | ||
output.tex = input.tex; | ||
|
||
// Compute texture coordinates for first noise texture using the first scale and upward scrolling speed values. | ||
output.texCoords1 = (input.tex * scales.x); | ||
output.texCoords1.y = output.texCoords1.y + (frameTime * scrollSpeeds.x); | ||
|
||
// Compute texture coordinates for second noise texture using the second scale and upward scrolling speed values. | ||
output.texCoords2 = (input.tex * scales.y); | ||
output.texCoords2.y = output.texCoords2.y + (frameTime * scrollSpeeds.y); | ||
|
||
// Compute texture coordinates for third noise texture using the third scale and upward scrolling speed values. | ||
output.texCoords3 = (input.tex * scales.z); | ||
output.texCoords3.y = output.texCoords3.y + (frameTime * scrollSpeeds.z); | ||
|
||
return output; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.