Game Development Community

Help with renderMonkey

by Danny Mejia · in Torque Game Engine Advanced · 05/01/2007 (6:48 pm) · 7 replies

I would like put the fire shader in renderMonkey. But all I have is a .FX file. I know I need to put the Vertex Shader in one file and the Pixel Shader in one file. But what about the other code. Here is the code from rendermonkey I know it big:

//**************************************************************//
// Effect File exported by RenderMonkey
//
// - Although many improvements were made to RenderMonkey FX
// file export, there are still situations that may cause
// compilation problems once the file is exported, such as
// occasional naming conflicts for methods, since FX format
// does not support any notions of name spaces. You need to
// try to create workspaces in such a way as to minimize
// potential naming conflicts on export.
//
// - Note that to minimize resulting name collisions in the FX
// file, RenderMonkey will mangle names for passes, shaders
// and function names as necessary to reduce name conflicts.
//**************************************************************//
//--------------------------------------------------------------//
// Fire Effects
//--------------------------------------------------------------//
//--------------------------------------------------------------//
// Fire
//--------------------------------------------------------------//
//--------------------------------------------------------------//
// Single Pass
//--------------------------------------------------------------//
string Fire_Effects_Fire_Single_Pass_ScreenAlignedQuad : ModelData = "../Media/Models/ScreenAlignedQuad.3ds";

float4 layer_speed
<
float4 UIMin = ( -10.00, -10.00, -10.00, -10.00 );
float4 UIMax = ( 10.00, 10.00, 10.00, 10.00 );
bool Normalize = false;
> = ( 0.69, 0.52, 0.75, 1.00 );
float time_0_X : Time0_X;

struct VS_OUTPUT
{
float4 Pos : POSITION;
float3 TexCoord0 : TEXCOORD0;
float3 TexCoord1 : TEXCOORD1;
float3 TexCoord2 : TEXCOORD2;
float3 TexCoord3 : TEXCOORD3;
};

VS_OUTPUT Fire_Effects_Fire_Single_Pass_Vertex_Shader_main (float4 vPosition: POSITION, float3 vTexCoord0 : TEXCOORD0)
{
VS_OUTPUT Out = (VS_OUTPUT) 0;

// Align quad with the screen
Out.Pos = float4 (vPosition.x, vPosition.y, 0.0f, 1.0f);

// Output TexCoord0 directly
Out.TexCoord0 = vTexCoord0;

// Base texture coordinates plus scaled time
Out.TexCoord1.x = vTexCoord0.x;
Out.TexCoord1.y = vTexCoord0.y + layer_speed.x * time_0_X;

// Base texture coordinates plus scaled time
Out.TexCoord2.x = vTexCoord0.x;
Out.TexCoord2.y = vTexCoord0.y + layer_speed.y * time_0_X;

// Base texture coordinates plus scaled time
Out.TexCoord3.x = vTexCoord0.x;
Out.TexCoord3.y = vTexCoord0.y + layer_speed.z * time_0_X;

return Out;
}

#1
05/01/2007 (6:49 pm)
Float distortion_amount2
<
float UIMin = -1.00;
float UIMax = 1.00;
> = 0.07;
float4 height_attenuation
<
float4 UIMin = ( -10.00, -10.00, -10.00, -10.00 );
float4 UIMax = ( 10.00, 10.00, 10.00, 10.00 );
bool Normalize = false;
> = ( 0.44, 0.29, 0.00, 1.00 );
float distortion_amount1
<
float UIMin = -1.00;
float UIMax = 1.00;
> = 0.09;
float distortion_amount0
<
float UIMin = -1.00;
float UIMax = 1.00;
> = 0.12;
texture fire_base_Tex
<
string path = "..\Media\Textures\FireBase.tga";
>;
sampler fire_base = sampler_state
{
Texture = (fire_base_Tex);
ADDRESSU = CLAMP;
ADDRESSV = CLAMP;
MAGFILTER = LINEAR;
MINFILTER = LINEAR;
MIPFILTER = LINEAR;
ADDRESSW = CLAMP;
};
texture fire_distortion_Tex
<
string path = "..\Media\Textures\FireDistortion.tga";
>;
sampler fire_distortion = sampler_state
{
Texture = (fire_distortion_Tex);
ADDRESSU = WRAP;
ADDRESSV = WRAP;
MAGFILTER = LINEAR;
MINFILTER = LINEAR;
MIPFILTER = LINEAR;
ADDRESSW = WRAP;
};
texture fire_opacity_Tex
<
string path = "..\Media\Textures\FireOpacity.tga";
>;
sampler fire_opacity = sampler_state
{
Texture = (fire_opacity_Tex);
ADDRESSU = CLAMP;
ADDRESSV = CLAMP;
MAGFILTER = LINEAR;
MINFILTER = LINEAR;
MIPFILTER = LINEAR;
ADDRESSW = CLAMP;
};

// 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 Fire_Effects_Fire_Single_Pass_Pixel_Shader_main (float4 tc0 : TEXCOORD0, float4 tc1 : TEXCOORD1,
float4 tc2 : TEXCOORD2, float4 tc3 : TEXCOORD3) : COLOR
{
// Sample noise map three times with different texture coordinates
float4 noise0 = tex2D(fire_distortion, tc1);
float4 noise1 = tex2D(fire_distortion, tc2);
float4 noise2 = tex2D(fire_distortion, tc3);

// Weighted sum of signed noise
float4 noiseSum = bx2(noise0) * distortion_amount0 + bx2(noise1) * distortion_amount1 + bx2(noise2) * distortion_amount2;

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

// Sample base and opacity maps with perturbed coordinates
float4 base = tex2D(fire_base, perturbedBaseCoords);
float4 opacity = tex2D(fire_opacity, perturbedBaseCoords);

return base * opacity;
}

//--------------------------------------------------------------//
// Fire_ASM
//--------------------------------------------------------------//
//--------------------------------------------------------------//
// Single Pass
//--------------------------------------------------------------//
string Fire_Effects_Fire_ASM_Single_Pass_ScreenAlignedQuad : ModelData = "../Media/Models/ScreenAlignedQuad.3ds";

//--------------------------------------------------------------//
// Vertex Shader
//--------------------------------------------------------------//
VertexShader Single_Pass_Vertex_Shader = asm
{
vs.1.1

dcl_position v0
dcl_texcoord v1

mov r0, v0 // align the quad with the screen
mov r0.w, c0.z
mov r0.z, c0.x
mov oPos, r0

mov oT0, v1

mov r0.xy, c1

mov r1, v1 // base tex0 coord plus scaled time
mad r1.y, c5.x, r0.y, r1.y

mov r2, v1 // base tex1 coord plus scaled time
mad r2.y, c5.y, r0.y, r2.y

mov r3, v1 // base tex2 coord plus scaled time
mad r3.y, c5.z, r0.y, r3.y

mov oT1, r1
mov oT2, r2
mov oT3, r3













};

//--------------------------------------------------------------//
// Pixel Shader
//--------------------------------------------------------------//
PixelShader Single_Pass_Pixel_Shader = asm
{
ps.1.4

texcrd r0.rgb, t0 ; base coord
texld r2, t1 ; noise0
texld r3, t2 ; noise1
texld r4, t3 ; noise2

mul r2.rgb, c1, r2_bx2 ; noise0 * dis0
mad r2.rgb, c2, r3_bx2, r2 ; noise1 * dis1 + noise0 * dis0
mad r2.rgb, c3, r4_bx2, r2 ; noise2 * dis2 + noise1 * dis1 + noise0 * dis0
+mad r0.a, r0.g, c4.x, c4.y ; scale and bias y coord of base map
mad r2.rgb, r2, r0.a, r0 ; mult distortion by scaled biased y coord

phase

texld r0, r2 ; index base map with distorted tex coord
texld r1, r2 ; index opacity map with distorted tex coord

mul r0, r1, r0 ; scale base color by opacity

};

//--------------------------------------------------------------//
// Technique Section for Fire Effects
//--------------------------------------------------------------//
technique Fire
{
pass Single_Pass
{
ZENABLE = TRUE;
FILLMODE = SOLID;
SHADEMODE = GOURAUD;
ZWRITEENABLE = TRUE;
ALPHATESTENABLE = FALSE;
LASTPIXEL = TRUE;
SRCBLEND = ONE;
DESTBLEND = ZERO;
CULLMODE = NONE;
ALPHAREF = 0x0;
ALPHAFUNC = LESS;
DITHERENABLE = FALSE;
ALPHABLENDENABLE = FALSE;
FOGENABLE = FALSE;
SPECULARENABLE = FALSE;
FOGCOLOR = 0xFFFFFFFF;
FOGTABLEMODE = NONE;
FOGSTART = 0.000000;
FOGEND = 0.000000;
FOGDENSITY = 0.000000;
STENCILENABLE = FALSE;
STENCILFAIL = KEEP;
STENCILZFAIL = KEEP;
STENCILPASS = KEEP;
STENCILFUNC = ALWAYS;
STENCILREF = 0x0;
STENCILMASK = 0xffffffff;
STENCILWRITEMASK = 0xffffffff;
TEXTUREFACTOR = 0x0;
WRAP0 = 0;
WRAP1 = 0;
WRAP2 = 0;
WRAP3 = 0;
WRAP4 = 0;
WRAP5 = 0;
WRAP6 = 0;
WRAP7 = 0;
CLIPPING = FALSE;
LIGHTING = FALSE;
AMBIENT = 0x11111111;
FOGVERTEXMODE = NONE;
COLORVERTEX = TRUE;
LOCALVIEWER = TRUE;
NORMALIZENORMALS = FALSE;
DIFFUSEMATERIALSOURCE = COLOR1;
SPECULARMATERIALSOURCE = COLOR2;
AMBIENTMATERIALSOURCE = COLOR2;
EMISSIVEMATERIALSOURCE = COLOR2;
VERTEXBLEND = DISABLE;
CLIPPLANEENABLE = 0;
POINTSIZE = 0.000000;
POINTSIZE_MIN = 0.000000;
POINTSPRITEENABLE = FALSE;
POINTSCALEENABLE = FALSE;
POINTSCALE_A = 0.000000;
POINTSCALE_B = 0.000000;
POINTSCALE_C = 0.000000;
MULTISAMPLEANTIALIAS = TRUE;
MULTISAMPLEMASK = 0xffffffff;
PATCHEDGESTYLE = DISCRETE;
POINTSIZE_MAX = 0.000000;
INDEXEDVERTEXBLENDENABLE = FALSE;
COLORWRITEENABLE = RED | GREEN | BLUE | ALPHA;
TWEENFACTOR = 0.000000;
BLENDOP = ADD;
POSITIONDEGREE = CUBIC;
NORMALDEGREE = LINEAR;
ZFUNC = ALWAYS;

VertexShader = compile vs_1_1 Fire_Effects_Fire_Single_Pass_Vertex_Shader_main();
PixelShader = compile ps_1_4 Fire_Effects_Fire_Single_Pass_Pixel_Shader_main();
}

}
#2
05/01/2007 (6:49 pm)
Technique Fire_ASM
{
pass Single_Pass
{
ZENABLE = TRUE;
FILLMODE = SOLID;
SHADEMODE = GOURAUD;
ZWRITEENABLE = TRUE;
ALPHATESTENABLE = FALSE;
LASTPIXEL = TRUE;
SRCBLEND = ONE;
DESTBLEND = ZERO;
CULLMODE = NONE;
ALPHAREF = 0x0;
ALPHAFUNC = LESS;
DITHERENABLE = FALSE;
ALPHABLENDENABLE = FALSE;
FOGENABLE = FALSE;
SPECULARENABLE = FALSE;
FOGCOLOR = 0xFFFFFFFF;
FOGTABLEMODE = NONE;
FOGSTART = 0.000000;
FOGEND = 0.000000;
FOGDENSITY = 0.000000;
STENCILENABLE = FALSE;
STENCILFAIL = KEEP;
STENCILZFAIL = KEEP;
STENCILPASS = KEEP;
STENCILFUNC = ALWAYS;
STENCILREF = 0x0;
STENCILMASK = 0xffffffff;
STENCILWRITEMASK = 0xffffffff;
TEXTUREFACTOR = 0x0;
WRAP0 = 0;
WRAP1 = 0;
WRAP2 = 0;
WRAP3 = 0;
WRAP4 = 0;
WRAP5 = 0;
WRAP6 = 0;
WRAP7 = 0;
CLIPPING = FALSE;
LIGHTING = FALSE;
AMBIENT = 0x11111111;
FOGVERTEXMODE = NONE;
COLORVERTEX = TRUE;
LOCALVIEWER = TRUE;
NORMALIZENORMALS = FALSE;
DIFFUSEMATERIALSOURCE = COLOR1;
SPECULARMATERIALSOURCE = COLOR2;
AMBIENTMATERIALSOURCE = COLOR2;
EMISSIVEMATERIALSOURCE = COLOR2;
VERTEXBLEND = DISABLE;
CLIPPLANEENABLE = 0;
POINTSIZE = 0.000000;
POINTSIZE_MIN = 0.000000;
POINTSPRITEENABLE = FALSE;
POINTSCALEENABLE = FALSE;
POINTSCALE_A = 0.000000;
POINTSCALE_B = 0.000000;
POINTSCALE_C = 0.000000;
MULTISAMPLEANTIALIAS = TRUE;
MULTISAMPLEMASK = 0xffffffff;
PATCHEDGESTYLE = DISCRETE;
POINTSIZE_MAX = 0.000000;
INDEXEDVERTEXBLENDENABLE = FALSE;
COLORWRITEENABLE = RED | GREEN | BLUE | ALPHA;
TWEENFACTOR = 0.000000;
BLENDOP = ADD;
POSITIONDEGREE = CUBIC;
NORMALDEGREE = LINEAR;
ZFUNC = ALWAYS;

VertexShader = (Single_Pass_Vertex_Shader);
PixelShader = (Single_Pass_Pixel_Shader);
}

}

Thanks for any help
#3
05/01/2007 (6:55 pm)
It's basic HLSL, so it should be very easy to port to TGEA. Also, you don't want to look at the ASM part of the shader. TGEA does not support ASM.
#4
05/01/2007 (7:18 pm)
Add this to your client/scripts/shaders.cs file:
new ShaderData( fire )
{
   DXVertexShaderFile     = "shaders/fireV.hlsl";
   DXPixelShaderFile      = "shaders/fireP.hlsl";
   pixVersion = 2.0;
};

And create 2 new .hlsl files named fireP and fireV.

fireV:
#define IN_HLSL
#include "shdrConsts.h"

struct VS_OUTPUT
{
   float4 Pos       : POSITION;
   float4 TexCoord0 : TEXCOORD0;
   float4 TexCoord1 : TEXCOORD1;
   float4 TexCoord2 : TEXCOORD2;
   float4 TexCoord3 : TEXCOORD3;
};

struct VS_INPUT
{
float4 Pos			: POSITION;
float4 texCoord		: TEXCOORD0;

};

VS_OUTPUT main(VS_INPUT In,
				uniform float4x4 modelview : register(VC_WORLD_PROJ)
				
)
{
   VS_OUTPUT Out;
   
   float4 layer_speed;
   layer_speed.x = 0.68753;		//MVitelli Pulled from RM shader
   layer_speed.y = 0.52000;
   layer_speed.z = 0.75340;
   layer_speed.w = 1.0; 
   
   float time_0_X;				//MVitelli No idea what to do here

   // Align quad with the screen
   Out.Pos = mul(modelview, In.Pos);
   
   //MVitelli This is similar to the water vertex shaders, but until there's a new class for this, let the material system handle all of the movement.

   // Output TexCoord0 directly
   Out.TexCoord0 = In.texCoord;

   // Base texture coordinates plus scaled time
   Out.TexCoord1 = In.texCoord;
   //Out.TexCoord1.x = In.texCoord.x;
   //Out.TexCoord1.y = In.texCoord.y + layer_speed.x * time_0_X;

   // Base texture coordinates plus scaled time
   Out.TexCoord2 = In.texCoord;
   //Out.TexCoord2.x = In.texCoord.x;
   //Out.TexCoord2.y = In.texCoord.y + layer_speed.y * time_0_X;

   // Base texture coordinates plus scaled time
   Out.TexCoord3 = In.texCoord;
   //Out.TexCoord3.x = In.texCoord.x;
   //Out.TexCoord3.y = In.texCoord.y + layer_speed.z * time_0_X;

   return Out;
}


fireP:
#define IN_HLSL
#include "shdrConsts.h"

struct VertData
{
float4 tc0 : TEXCOORD0; 
float4 tc1 : TEXCOORD1;
float4 tc2 : TEXCOORD2; 
float4 tc3 : TEXCOORD3;

};
//MVitelli ported RenderMonkey Fire Shader
// 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 (VertData In,
             uniform sampler2D fire_base : register(S0),
             uniform sampler2D fire_distortion : register(S1),
             uniform sampler2D fire_opacity	   : register(S2)
) : COLOR
{
   // Sample noise map three times with different texture coordinates
    float distortion_amount2 = 0.07230;
	float4 height_attenuation;
	height_attenuation.x = 0.44000;
	height_attenuation.y = 0.29000;
	height_attenuation.z = 0;
	height_attenuation.w = 1.0;
	float distortion_amount1 = 0.09100;
	float distortion_amount0 = 0.12300;

   float4 noise0 = tex2D(fire_distortion, In.tc1);
   float4 noise1 = tex2D(fire_distortion, In.tc2);
   float4 noise2 = tex2D(fire_distortion, In.tc3);

   // Weighted sum of signed noise
   float4 noiseSum = bx2(noise0) * distortion_amount0 + bx2(noise1) * distortion_amount1 + bx2(noise2) * distortion_amount2;
   //float4 noiseSum = distortion_amount0 * distortion_amount1 * distortion_amount2;

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

   // Sample base and opacity maps with perturbed coordinates
   float4 base = tex2D(fire_base, perturbedBaseCoords);
   float4 opacity = tex2D(fire_opacity, perturbedBaseCoords);
   
   float4 final = base;// * opacity;

   return final;
}
#5
05/01/2007 (7:20 pm)
Please note that I haven't tested this yet, but the ideal way to do this would be to set up a special class for this. As you can see, I commented out the animation lines in the vertex shader. Instead of making a new class, you could just use the material animation system. Please tell me if this works or if there are serious problems with it. Most of this port was just copied and pasted from the RM Fire file.
#6
05/01/2007 (7:54 pm)
Thanks that helps alot..Am go to try to put this into TGEA
#7
05/06/2007 (2:48 pm)
Hey Matt I have not had the time do this is it...I will let u know when I do