RenderMonkey and XNA 4.0

Started by
4 comments, last by B 11 years, 5 months ago
Hey guys, so i'm new here, and also, rather new to XNA.

we're a couple of guys having programmed a lot in other languages (Like c#, pascal, C++, and game maker language), but only GML was used for making actual games. Now we're trying to accomplish the same, in XNA. We are having little problems, but the project is rather ambitious, and as such we have run into some rather high-end problems, in our first project.
I realize it may be stupid to make your first project very ambitous, but as i said, we haven't had too many problems so far.

Now, we wanted water in the game, and pretty quickly realized that shaders should be used to solve this. At first we tried to make them ourselves, but that would be reinventing the wheel, and never be as good, as what stuff like RenderMonkey offers.

Now i downloaded RenderMonkey, found a default water shader, exported it and all that jazz, however my problem is that when i use the shader in XNA, it just doesn't render the object. I've used other shaders (Those i made myself) with no problems, but this one is massive, and i'm afraid i don't set all parameters needed.
The even more strange thins is, that if anything is drawn BEFORE the object that i use the shader on, these things will become "undrawn", meaning they dissappear. This leads me to suspect that it could be something other than just unset parameters.

But being a noob, to shaders, i'm highly confused, and would like someone pointing me in the right direction.

Attached code:

HLSL shader code (Probably wrong color coded, as HLSL was not an option):
[source lang="csharp"]//*************************************************************//
// Effect File exported by RenderMonkey 1.6
//
// - 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.
//**************************************************************//

//--------------------------------------------------------------//
// Reflection Refraction and Water Effects
//--------------------------------------------------------------//
//--------------------------------------------------------------//
// DepthAttenuatedReflection
//--------------------------------------------------------------//
//--------------------------------------------------------------//
// Normal
//--------------------------------------------------------------//
string Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Normal_Skull : ModelData = "C:\\Program Files (x86)\\AMD\\RenderMonkey 1.82\\Examples\\Media\\Models\\Skull.3ds";

float4x4 view_proj_matrix : ViewProjection;
float4x4 view_matrix : View;
float height
<
string UIName = "height";
string UIWidget = "Numeric";
bool UIVisible = true;
float UIMin = 0.00;
float UIMax = 200.00;
> = float( 96.00 );
float objectScale
<
string UIName = "objectScale";
string UIWidget = "Numeric";
bool UIVisible = true;
float UIMin = 0.00;
float UIMax = 10.00;
> = float( 2.00 );
struct VS_OUTPUT
{
float4 Pos: POSITION;
float2 texCoord: TEXCOORD0;
float3 normal: TEXCOORD1;
float3 viewVec: TEXCOORD2;
};

VS_OUTPUT Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Normal_Vertex_Shader_main( float4 Pos: POSITION,
float3 normal: NORMAL,
float2 texCoord: TEXCOORD0)
{
VS_OUTPUT Out;

// Scale and move object
Pos.xyz *= objectScale;
Pos.y += height;

Out.Pos = mul(view_proj_matrix, Pos);

// Eye-space lighting
Out.normal = mul(view_matrix, normal);
Out.viewVec = -mul(view_matrix, Pos);
Out.texCoord = texCoord;

return Out;
}










float4 lightDir
<
string UIName = "lightDir";
string UIWidget = "Direction";
bool UIVisible = false;
float4 UIMin = float4( -10.00, -10.00, -10.00, -10.00 );
float4 UIMax = float4( 10.00, 10.00, 10.00, 10.00 );
bool Normalize = false;
> = float4( 0.58, 0.58, -0.58, 1.00 );
texture Wood_Tex
<
string ResourceName = "C:\\Program Files (x86)\\AMD\\RenderMonkey 1.82\\Examples\\Media\\Textures\\Wood.dds";
>;
sampler BaseMap2 = sampler_state
{
Texture = (Wood_Tex);
MAGFILTER = LINEAR;
MINFILTER = LINEAR;
MIPFILTER = LINEAR;
};
float4 Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Normal_Pixel_Shader_main(float2 texCoord: TEXCOORD0, float3 norm: TEXCOORD1, float3 viewVec: TEXCOORD2) : COLOR {
float4 base = tex2D(BaseMap2, texCoord);

float3 normal = normalize(norm);

// Simple lighting
float diffuse = saturate(dot(lightDir, normal));
float specular = pow(saturate(dot(reflect(-normalize(viewVec), normal), lightDir)), 16);

return base * (diffuse + 0.2) + 0.5 * specular;
}








//--------------------------------------------------------------//
// Reflected
//--------------------------------------------------------------//
string Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Reflected_Skull : ModelData = "C:\\Program Files (x86)\\AMD\\RenderMonkey 1.82\\Examples\\Media\\Models\\Skull.3ds";

texture RT_Tex : RenderColorTarget
<
float2 ViewportRatio={1.0,1.0};
string Format="D3DFMT_A8R8G8B8";
float ClearDepth=1.000000;
int ClearColor=0;
>;
float4x4 Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Reflected_Vertex_Shader_view_proj_matrix : ViewProjection;
float4x4 Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Reflected_Vertex_Shader_view_matrix : View;
float Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Reflected_Vertex_Shader_height
<
string UIName = "Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Reflected_Vertex_Shader_height";
string UIWidget = "Numeric";
bool UIVisible = true;
float UIMin = 0.00;
float UIMax = 200.00;
> = float( 96.00 );
float Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Reflected_Vertex_Shader_objectScale
<
string UIName = "Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Reflected_Vertex_Shader_objectScale";
string UIWidget = "Numeric";
bool UIVisible = true;
float UIMin = 0.00;
float UIMax = 10.00;
> = float( 2.00 );
float reflectivePlane
<
string UIName = "reflectivePlane";
string UIWidget = "Numeric";
bool UIVisible = true;
float UIMin = -100.00;
float UIMax = 100.00;
> = float( 50.00 );
struct Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Reflected_Vertex_Shader_VS_OUTPUT {
float4 Pos: POSITION;
float2 texCoord: TEXCOORD0;
float3 normal: TEXCOORD1;
float3 viewVec: TEXCOORD2;
float dist: TEXCOORD3;
};

Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Reflected_Vertex_Shader_VS_OUTPUT Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Reflected_Vertex_Shader_main(float4 Pos: POSITION, float3 normal: NORMAL,
float2 texCoord: TEXCOORD0){
Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Reflected_Vertex_Shader_VS_OUTPUT Out;

// Scale, mirror and translate
Pos.xyz *= Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Reflected_Vertex_Shader_objectScale;
Pos.y = -Pos.y - Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Reflected_Vertex_Shader_height - 2 * reflectivePlane;

Out.Pos = mul(Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Reflected_Vertex_Shader_view_proj_matrix, Pos);
// Eye-space
Out.normal = mul(Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Reflected_Vertex_Shader_view_matrix, normal);
Out.viewVec = -mul(Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Reflected_Vertex_Shader_view_matrix, Pos);
Out.texCoord = texCoord;
Out.dist = 0.0035 * (reflectivePlane - Pos.z);

return Out;
}














float4 Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Reflected_Pixel_Shader_lightDir
<
string UIName = "Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Reflected_Pixel_Shader_lightDir";
string UIWidget = "Direction";
bool UIVisible = false;
float4 UIMin = float4( -10.00, -10.00, -10.00, -10.00 );
float4 UIMax = float4( 10.00, 10.00, 10.00, 10.00 );
bool Normalize = false;
> = float4( 0.58, 0.58, -0.58, 1.00 );
sampler Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Reflected_Pixel_Shader_BaseMap2 = sampler_state
{
Texture = (Wood_Tex);
};
float4 Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Reflected_Pixel_Shader_main( float2 texCoord: TEXCOORD0,
float3 norm : TEXCOORD1,
float3 viewVec : TEXCOORD2,
float dist: TEXCOORD3) : COLOR
{
float3 base = tex2D(Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Reflected_Pixel_Shader_BaseMap2, texCoord);

float3 normal = normalize(norm);

// Simple lighting
float diffuse = saturate(dot(Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Reflected_Pixel_Shader_lightDir, normal));
float specular = pow(saturate(dot(reflect(-normalize(viewVec), normal), Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Reflected_Pixel_Shader_lightDir)), 16);

return float4(base * (diffuse + 0.2) + 0.5 * specular, dist);
}









//--------------------------------------------------------------//
// Prepare Blur
//--------------------------------------------------------------//
string Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Prepare_Blur_Skull : ModelData = "C:\\Program Files (x86)\\AMD\\RenderMonkey 1.82\\Examples\\Media\\Models\\Skull.3ds";

texture Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Prepare_Blur_RT : RenderColorTarget
<
float2 ViewportRatio={1.0,1.0};
string Format="D3DFMT_A8R8G8B8";
float ClearDepth=1.000000;
int ClearColor=0;
>;
float4x4 Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Prepare_Blur_Vertex_Shader_view_proj_matrix : ViewProjection;
float Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Prepare_Blur_Vertex_Shader_objectScale
<
string UIName = "Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Prepare_Blur_Vertex_Shader_objectScale";
string UIWidget = "Numeric";
bool UIVisible = true;
float UIMin = 0.00;
float UIMax = 10.00;
> = float( 2.00 );
float Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Prepare_Blur_Vertex_Shader_height
<
string UIName = "Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Prepare_Blur_Vertex_Shader_height";
string UIWidget = "Numeric";
bool UIVisible = true;
float UIMin = 0.00;
float UIMax = 200.00;
> = float( 96.00 );
float Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Prepare_Blur_Vertex_Shader_reflectivePlane
<
string UIName = "Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Prepare_Blur_Vertex_Shader_reflectivePlane";
string UIWidget = "Numeric";
bool UIVisible = true;
float UIMin = -100.00;
float UIMax = 100.00;
> = float( 50.00 );
struct Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Prepare_Blur_Vertex_Shader_VS_OUTPUT
{
float4 Pos: POSITION;
float2 dist: TEXCOORD0;
};

Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Prepare_Blur_Vertex_Shader_VS_OUTPUT Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Prepare_Blur_Vertex_Shader_main(float4 Pos: POSITION, float3 normal: NORMAL)
{
Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Prepare_Blur_Vertex_Shader_VS_OUTPUT Out;

// Scale, mirror and translate
Pos.xyz *= Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Prepare_Blur_Vertex_Shader_objectScale;
Pos.y = -Pos.y - Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Prepare_Blur_Vertex_Shader_height - 2 * Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Prepare_Blur_Vertex_Shader_reflectivePlane;

// Depth
float dist = 0.0035 * (Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Prepare_Blur_Vertex_Shader_reflectivePlane - Pos.z);
Out.dist = dist;

// Mirror normal
float3 nNorm = float3(normal.xy, -normal.z);

// Expand along normal according to depth
Pos.xyz += 10 * dist * nNorm;
Out.Pos = mul(Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Prepare_Blur_Vertex_Shader_view_proj_matrix, Pos);

return Out;
}




float4 Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Prepare_Blur_Pixel_Shader_main(float2 dist: TEXCOORD0) : COLOR
{
return float4( dist, dist );
}




//--------------------------------------------------------------//
// Depth fade Blur
//--------------------------------------------------------------//
string Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Depth_fade_Blur_Disc : ModelData = "C:\\Program Files (x86)\\AMD\\RenderMonkey 1.82\\Examples\\Media\\Models\\Disc.3ds";

float4x4 Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Depth_fade_Blur_Vertex_Shader_view_proj_matrix : ViewProjection;
float Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Depth_fade_Blur_Vertex_Shader_reflectivePlane
<
string UIName = "Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Depth_fade_Blur_Vertex_Shader_reflectivePlane";
string UIWidget = "Numeric";
bool UIVisible = true;
float UIMin = -100.00;
float UIMax = 100.00;
> = float( 50.00 );
struct Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Depth_fade_Blur_Vertex_Shader_VS_OUTPUT
{
float4 Pos: POSITION;
float2 texCoord: TEXCOORD0;
float3 eyeLinear: TEXCOORD1;
};

Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Depth_fade_Blur_Vertex_Shader_VS_OUTPUT Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Depth_fade_Blur_Vertex_Shader_main(float4 Pos: POSITION)
{
Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Depth_fade_Blur_Vertex_Shader_VS_OUTPUT Out;

// Flip, scale, mirror and translate
float4 pos = float4(6 * Pos.x, 2 * Pos.y - 14 - Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Depth_fade_Blur_Vertex_Shader_reflectivePlane, 6 * Pos.z, 1);
float4 pPos = mul(Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Depth_fade_Blur_Vertex_Shader_view_proj_matrix, float4(pos.xyz,1));

Out.Pos = pPos;
// Object-linear texgen
Out.texCoord.x = Pos.x * 0.01;
Out.texCoord.y = Pos.z * 0.01;

// Eye-linear texgen
Out.eyeLinear.x = 0.5 * (pPos.z + pPos.x);
Out.eyeLinear.y = 0.5 * (pPos.z - pPos.y);
Out.eyeLinear.z = pPos.z;

return Out;
}


float bumpiness
<
string UIName = "bumpiness";
string UIWidget = "Numeric";
bool UIVisible = true;
float UIMin = 0.00;
float UIMax = 0.25;
> = float( 0.02 );
texture Fieldstone_Base_Tex
<
string ResourceName = "C:\\Program Files (x86)\\AMD\\RenderMonkey 1.82\\Examples\\Media\\Textures\\Fieldstone.tga";
>;
sampler BaseMap = sampler_state
{
Texture = (Fieldstone_Base_Tex);
MAGFILTER = LINEAR;
MINFILTER = ANISOTROPIC;
MIPFILTER = LINEAR;
MAXANISOTROPY = 16;
};
texture Fieldstone_Bump_Tex
<
string ResourceName = "C:\\Program Files (x86)\\AMD\\RenderMonkey 1.82\\Examples\\Media\\Textures\\FieldstoneBumpDOT3.tga";
>;
sampler BumpMap = sampler_state
{
Texture = (Fieldstone_Bump_Tex);
MAGFILTER = LINEAR;
MINFILTER = ANISOTROPIC;
MIPFILTER = LINEAR;
MAXANISOTROPY = 16;
};
sampler reflection = sampler_state
{
Texture = (RT_Tex);
MAGFILTER = LINEAR;
MINFILTER = ANISOTROPIC;
MIPFILTER = LINEAR;
MAXANISOTROPY = 16;
};
const float2 offsets[12] =
{
-0.326212, -0.405805,
-0.840144, -0.073580,
-0.695914, 0.457137,
-0.203345, 0.620716,
0.962340, -0.194983,
0.473434, -0.480026,
0.519456, 0.767022,
0.185461, -0.893124,
0.507431, 0.064425,
0.896420, 0.412458,
-0.321940, -0.932615,
-0.791559, -0.597705,
};

float4 Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Depth_fade_Blur_Pixel_Shader_main( float2 texCoord: TEXCOORD0,
float3 eyeLinear: TEXCOORD1) : COLOR
{
float4 base = tex2D(BaseMap, texCoord);
float4 bump = tex2D(BumpMap, texCoord) * 2 - 1;

bump = normalize(bump);

// Sample position, offset for some bumpiness
float2 mid = eyeLinear.xy / eyeLinear.z + bump.xy * bumpiness;

float4 refl = tex2D(reflection, mid);

// Blur the reflection according to depth
float4 blurred = refl;
for (int i = 0; i < 12; i++){
blurred += tex2D(reflection, mid + 0.02 * refl.a * refl.a * offsets);
}

// Fade with depth
float depthFade = saturate(1 - 0.5 * refl.a);

return base * 0.35 + depthFade * (blurred / 13);
}



//--------------------------------------------------------------//
// Refraction
//--------------------------------------------------------------//
//--------------------------------------------------------------//
// SceneToTexture
//--------------------------------------------------------------//
string Reflection_Refraction_and_Water_Effects_Refraction_SceneToTexture_Skull : ModelData = "C:\\Program Files (x86)\\AMD\\RenderMonkey 1.82\\Examples\\Media\\Models\\Skull.3ds";

texture Reflection_Refraction_and_Water_Effects_Refraction_SceneToTexture_RT : RenderColorTarget
<
float2 ViewportRatio={1.0,1.0};
string Format="D3DFMT_A8R8G8B8";
float ClearDepth=1.000000;
int ClearColor=0;
>;
float4x4 Reflection_Refraction_and_Water_Effects_Refraction_SceneToTexture_Vertex_Shader_view_proj_matrix : ViewProjection;
float4x4 Reflection_Refraction_and_Water_Effects_Refraction_SceneToTexture_Vertex_Shader_view_matrix : View;
struct Reflection_Refraction_and_Water_Effects_Refraction_SceneToTexture_Vertex_Shader_VS_OUTPUT {
float4 Pos: POSITION;
float2 texCoord: TEXCOORD0;
float3 normal: TEXCOORD1;
};

Reflection_Refraction_and_Water_Effects_Refraction_SceneToTexture_Vertex_Shader_VS_OUTPUT Reflection_Refraction_and_Water_Effects_Refraction_SceneToTexture_Vertex_Shader_main(float4 Pos: POSITION, float3 normal: NORMAL, float2 texCoord: TEXCOORD0){
Reflection_Refraction_and_Water_Effects_Refraction_SceneToTexture_Vertex_Shader_VS_OUTPUT Out;

Out.Pos = mul(Reflection_Refraction_and_Water_Effects_Refraction_SceneToTexture_Vertex_Shader_view_proj_matrix, Pos);
Out.normal = mul(Reflection_Refraction_and_Water_Effects_Refraction_SceneToTexture_Vertex_Shader_view_matrix, normal);
Out.texCoord = texCoord;

return Out;
}





float4 Reflection_Refraction_and_Water_Effects_Refraction_SceneToTexture_Pixel_Shader_lightDir
<
string UIName = "Reflection_Refraction_and_Water_Effects_Refraction_SceneToTexture_Pixel_Shader_lightDir";
string UIWidget = "Direction";
bool UIVisible = false;
float4 UIMin = float4( -10.00, -10.00, -10.00, -10.00 );
float4 UIMax = float4( 10.00, 10.00, 10.00, 10.00 );
bool Normalize = false;
> = float4( 0.27, -0.53, -0.80, 0.00 );
sampler Reflection_Refraction_and_Water_Effects_Refraction_SceneToTexture_Pixel_Shader_BaseMap = sampler_state
{
Texture = (Wood_Tex);
ADDRESSU = WRAP;
ADDRESSV = WRAP;
MAGFILTER = LINEAR;
MINFILTER = ANISOTROPIC;
MIPFILTER = LINEAR;
MAXANISOTROPY = 16;
};
float4 Reflection_Refraction_and_Water_Effects_Refraction_SceneToTexture_Pixel_Shader_main(float2 texCoord: TEXCOORD0, float3 normal: TEXCOORD1) : COLOR {
float4 base = tex2D(Reflection_Refraction_and_Water_Effects_Refraction_SceneToTexture_Pixel_Shader_BaseMap, texCoord);

// Basic lighting
float diffuse = 0.5 * dot(Reflection_Refraction_and_Water_Effects_Refraction_SceneToTexture_Pixel_Shader_lightDir, normal) + 0.5;

return diffuse * base;
}




//--------------------------------------------------------------//
// SceneToFB
//--------------------------------------------------------------//
string Reflection_Refraction_and_Water_Effects_Refraction_SceneToFB_Skull : ModelData = "C:\\Program Files (x86)\\AMD\\RenderMonkey 1.82\\Examples\\Media\\Models\\Skull.3ds";

float4x4 Reflection_Refraction_and_Water_Effects_Refraction_SceneToFB_Vertex_Shader_view_proj_matrix : ViewProjection;
float4x4 Reflection_Refraction_and_Water_Effects_Refraction_SceneToFB_Vertex_Shader_view_matrix : View;
struct Reflection_Refraction_and_Water_Effects_Refraction_SceneToFB_Vertex_Shader_VS_OUTPUT {
float4 Pos: POSITION;
float2 texCoord: TEXCOORD0;
float3 normal: TEXCOORD1;
};

Reflection_Refraction_and_Water_Effects_Refraction_SceneToFB_Vertex_Shader_VS_OUTPUT Reflection_Refraction_and_Water_Effects_Refraction_SceneToFB_Vertex_Shader_main(float4 Pos: POSITION, float3 normal: NORMAL, float2 texCoord: TEXCOORD0){
Reflection_Refraction_and_Water_Effects_Refraction_SceneToFB_Vertex_Shader_VS_OUTPUT Out;

Out.Pos = mul(Reflection_Refraction_and_Water_Effects_Refraction_SceneToFB_Vertex_Shader_view_proj_matrix, Pos);
Out.normal = mul(Reflection_Refraction_and_Water_Effects_Refraction_SceneToFB_Vertex_Shader_view_matrix, normal);
Out.texCoord = texCoord;

return Out;
}



float4 Reflection_Refraction_and_Water_Effects_Refraction_SceneToFB_Pixel_Shader_lightDir
<
string UIName = "Reflection_Refraction_and_Water_Effects_Refraction_SceneToFB_Pixel_Shader_lightDir";
string UIWidget = "Direction";
bool UIVisible = false;
float4 UIMin = float4( -10.00, -10.00, -10.00, -10.00 );
float4 UIMax = float4( 10.00, 10.00, 10.00, 10.00 );
bool Normalize = false;
> = float4( 0.27, -0.53, -0.80, 0.00 );
sampler Reflection_Refraction_and_Water_Effects_Refraction_SceneToFB_Pixel_Shader_BaseMap = sampler_state
{
Texture = (Wood_Tex);
};
float4 Reflection_Refraction_and_Water_Effects_Refraction_SceneToFB_Pixel_Shader_main(float2 texCoord: TEXCOORD0, float3 normal: TEXCOORD1) : COLOR {
float4 base = tex2D(Reflection_Refraction_and_Water_Effects_Refraction_SceneToFB_Pixel_Shader_BaseMap, texCoord);

// Basic lighting
float diffuse = 0.5 * dot(Reflection_Refraction_and_Water_Effects_Refraction_SceneToFB_Pixel_Shader_lightDir, normal) + 0.5;

return diffuse * base;
}






//--------------------------------------------------------------//
// Refraction
//--------------------------------------------------------------//
string Reflection_Refraction_and_Water_Effects_Refraction_Refraction_Disc : ModelData = "C:\\Program Files (x86)\\AMD\\RenderMonkey 1.82\\Examples\\Media\\Models\\Disc.3ds";

float4x4 Reflection_Refraction_and_Water_Effects_Refraction_Refraction_Vertex_Shader_view_proj_matrix : ViewProjection;
struct Reflection_Refraction_and_Water_Effects_Refraction_Refraction_Vertex_Shader_VS_OUTPUT {
float4 Pos: POSITION;
float3 texCoord: TEXCOORD0;
float3 eyeLinear: TEXCOORD1;
};

Reflection_Refraction_and_Water_Effects_Refraction_Refraction_Vertex_Shader_VS_OUTPUT Reflection_Refraction_and_Water_Effects_Refraction_Refraction_Vertex_Shader_main(float4 Pos: POSITION){
Reflection_Refraction_and_Water_Effects_Refraction_Refraction_Vertex_Shader_VS_OUTPUT Out;

// Translate
Pos += float4(-8,-20,-8,1);

float4 sPos = mul(Reflection_Refraction_and_Water_Effects_Refraction_Refraction_Vertex_Shader_view_proj_matrix, float4(Pos.xzy,1));
Out.Pos = sPos;

// Eye-linear texgen
Out.eyeLinear.x = 0.5 * (sPos.z + sPos.x);
Out.eyeLinear.y = 0.5 * (sPos.z - sPos.y);
Out.eyeLinear.z = sPos.z;
// Object-linear texgen
Out.texCoord = 0.5 + 0.01 * Pos.xyz;

return Out;
}





float time_0_X : Time0_X;
float4 color
<
string UIName = "color";
string UIWidget = "Color";
bool UIVisible = true;
> = float4( 0.40, 0.78, 1.00, 1.00 );
texture Noise_Tex
<
string ResourceName = "C:\\Program Files (x86)\\AMD\\RenderMonkey 1.82\\Examples\\Media\\Textures\\NoiseVolume.dds";
>;
sampler Noise = sampler_state
{
Texture = (Noise_Tex);
ADDRESSU = WRAP;
ADDRESSV = WRAP;
ADDRESSW = WRAP;
MAGFILTER = LINEAR;
MINFILTER = LINEAR;
MIPFILTER = LINEAR;
};
sampler renderTexture = sampler_state
{
Texture = (RT_Tex);
MIPFILTER = NONE;
};
const float3 offY = float3(0.31, 0.24, 0.43);
const float3 offZ = float3(0.47, 0.19, 0.78);

float4 Reflection_Refraction_and_Water_Effects_Refraction_Refraction_Pixel_Shader_main(float3 texCoord: TEXCOORD0, float3 eyeLinear: TEXCOORD1) : COLOR {
float3 noiseCoord = texCoord.xyz * 0.3;
// Slight flow downwards
noiseCoord.z += 0.1 * time_0_X;
float noisy = tex3D(Noise, noiseCoord).r;

// Some noise for watery effect
noiseCoord.x = 0.1 * time_0_X;
noiseCoord.y = texCoord.y * 2;
noiseCoord.z = texCoord.z + 0.2 * time_0_X + noisy;

// Create a normal from three noise components
float3 normal;
normal.x = tex3D(Noise, noiseCoord).x;
normal.y = tex3D(Noise, noiseCoord + offY).x;
normal.z = tex3D(Noise, noiseCoord + offZ).x;
normal = normalize(normal * 2 - 1);

// Simply offset the texture coord for cheap refraction effect
float2 coord = eyeLinear.xy / eyeLinear.z;
float4 refr = tex2D(renderTexture, coord + 0.02 * normal.xy);

return (color - noisy) * (1 - refr) + refr;
}



//--------------------------------------------------------------//
// Ocean
//--------------------------------------------------------------//
//--------------------------------------------------------------//
// Sky
//--------------------------------------------------------------//
string Reflection_Refraction_and_Water_Effects_Ocean_Sky_Sky_Sphere : ModelData = "C:\\Program Files (x86)\\AMD\\RenderMonkey 1.82\\Examples\\Media\\Models\\Sphere.3ds";

float4x4 Reflection_Refraction_and_Water_Effects_Ocean_Sky_Vertex_Shader_view_proj_matrix : ViewProjection;
float4 view_position : ViewPosition;
struct Reflection_Refraction_and_Water_Effects_Ocean_Sky_Vertex_Shader_VS_OUTPUT {
float4 Pos: POSITION;
float3 pos: TEXCOORD0;
};

Reflection_Refraction_and_Water_Effects_Ocean_Sky_Vertex_Shader_VS_OUTPUT Reflection_Refraction_and_Water_Effects_Ocean_Sky_Vertex_Shader_main(float4 Pos: POSITION){
Reflection_Refraction_and_Water_Effects_Ocean_Sky_Vertex_Shader_VS_OUTPUT Out;

// Lock environment to view position
Out.Pos = mul(Reflection_Refraction_and_Water_Effects_Ocean_Sky_Vertex_Shader_view_proj_matrix, float4(Pos.xyz + view_position, 1));
Out.pos = Pos.yzx;

return Out;
}






texture skyBox_Tex
<
string ResourceName = "C:\\Program Files (x86)\\AMD\\RenderMonkey 1.82\\Examples\\Media\\Textures\\Snow.dds";
>;
sampler skyBox = sampler_state
{
Texture = (skyBox_Tex);
ADDRESSU = CLAMP;
ADDRESSV = CLAMP;
MAGFILTER = LINEAR;
MINFILTER = LINEAR;
MIPFILTER = LINEAR;
};
float4 Reflection_Refraction_and_Water_Effects_Ocean_Sky_Pixel_Shader_main(float3 pos: TEXCOORD0) : COLOR {
return texCUBE(skyBox, pos);
}


//--------------------------------------------------------------//
// Water
//--------------------------------------------------------------//
string Reflection_Refraction_and_Water_Effects_Ocean_Water_Quad : ModelData = "C:\\Program Files (x86)\\AMD\\RenderMonkey 1.82\\Examples\\Media\\Models\\ScreenAlignedQuad.3ds";

float4x4 Reflection_Refraction_and_Water_Effects_Ocean_Water_Vertex_Shader_view_proj_matrix : ViewProjection;
float4 scale
<
string UIName = "scale";
string UIWidget = "Direction";
bool UIVisible = true;
float4 UIMin = float4( 0.00, 0.00, 0.00, 0.00 );
float4 UIMax = float4( 0.01, 0.01, 0.01, 0.01 );
bool Normalize = false;
> = float4( 0.01, 0.01, 0.01, 1.00 );
float4 Reflection_Refraction_and_Water_Effects_Ocean_Water_Vertex_Shader_view_position : ViewPosition;
struct Reflection_Refraction_and_Water_Effects_Ocean_Water_Vertex_Shader_VS_OUTPUT {
float4 Pos: POSITION;
float3 pos: TEXCOORD0;
float3 normal: TEXCOORD1;
float3 vVec: TEXCOORD2;
};

Reflection_Refraction_and_Water_Effects_Ocean_Water_Vertex_Shader_VS_OUTPUT Reflection_Refraction_and_Water_Effects_Ocean_Water_Vertex_Shader_main(float4 Pos: POSITION, float3 normal: NORMAL){
Reflection_Refraction_and_Water_Effects_Ocean_Water_Vertex_Shader_VS_OUTPUT Out;

// Get some size on the water
Pos.xy *= 1000;
Pos.z = -30;

Out.Pos = mul(Reflection_Refraction_and_Water_Effects_Ocean_Water_Vertex_Shader_view_proj_matrix, Pos);
Out.pos = Pos.xyz * scale;
Out.vVec = Pos - Reflection_Refraction_and_Water_Effects_Ocean_Water_Vertex_Shader_view_position;
Out.normal = normal;

return Out;
}













float waveSpeed
<
string UIName = "waveSpeed";
string UIWidget = "Numeric";
bool UIVisible = true;
float UIMin = 0.00;
float UIMax = 1.00;
> = float( 0.34 );
float noiseSpeed
<
string UIName = "noiseSpeed";
string UIWidget = "Numeric";
bool UIVisible = true;
float UIMin = 0.00;
float UIMax = 1.00;
> = float( 0.18 );
float fadeBias
<
string UIName = "fadeBias";
string UIWidget = "Numeric";
bool UIVisible = true;
float UIMin = 0.00;
float UIMax = 1.00;
> = float( 0.30 );
float fadeExp
<
string UIName = "fadeExp";
string UIWidget = "Numeric";
bool UIVisible = true;
float UIMin = 0.00;
float UIMax = 8.00;
> = float( 6.08 );
float Reflection_Refraction_and_Water_Effects_Ocean_Water_Pixel_Shader_time_0_X : Time0_X;
float4 waterColor
<
string UIName = "waterColor";
string UIWidget = "Color";
bool UIVisible = true;
> = float4( 0.20, 0.35, 0.68, 1.00 );
sampler Reflection_Refraction_and_Water_Effects_Ocean_Water_Pixel_Shader_Noise = sampler_state
{
Texture = (Noise_Tex);
ADDRESSU = WRAP;
ADDRESSV = WRAP;
ADDRESSW = WRAP;
MAGFILTER = LINEAR;
MINFILTER = LINEAR;
MIPFILTER = LINEAR;
};
sampler Reflection_Refraction_and_Water_Effects_Ocean_Water_Pixel_Shader_skyBox = sampler_state
{
Texture = (skyBox_Tex);
ADDRESSU = CLAMP;
ADDRESSV = CLAMP;
MAGFILTER = LINEAR;
MINFILTER = LINEAR;
MIPFILTER = LINEAR;
};
float4 Reflection_Refraction_and_Water_Effects_Ocean_Water_Pixel_Shader_main(float3 pos: TEXCOORD0, float3 normal: TEXCOORD1, float3 vVec: TEXCOORD2) : COLOR {
pos.x += waveSpeed * Reflection_Refraction_and_Water_Effects_Ocean_Water_Pixel_Shader_time_0_X;
pos.z += noiseSpeed * Reflection_Refraction_and_Water_Effects_Ocean_Water_Pixel_Shader_time_0_X;

float4 noisy = tex3D(Reflection_Refraction_and_Water_Effects_Ocean_Water_Pixel_Shader_Noise, pos);

// Signed noise
float3 bump = 2 * noisy - 1;
bump.xy *= 0.15;
// Make sure the normal always points upwards
bump.z = 0.8 * abs(bump.z) + 0.2;
// Offset the surface normal with the bump
bump = normalize(normal + bump);

// Find the reflection vector
float3 reflVec = reflect(vVec, bump);
float4 refl = texCUBE(Reflection_Refraction_and_Water_Effects_Ocean_Water_Pixel_Shader_skyBox, reflVec.yzx);

float lrp = 1 - dot(-normalize(vVec), bump);

// Interpolate between the water color and reflection
return lerp(waterColor, refl, saturate(fadeBias + pow(lrp, fadeExp)));
}



//--------------------------------------------------------------//
// OceanWater_ASM
//--------------------------------------------------------------//
//--------------------------------------------------------------//
// Ocean Sky Pass
//--------------------------------------------------------------//
string Reflection_Refraction_and_Water_Effects_OceanWater_ASM_Ocean_Sky_Pass_Screen_Aligned_Quad_Ocean : ModelData = "C:\\Program Files (x86)\\AMD\\RenderMonkey 1.82\\Examples\\Media\\Models\\ScreenAlignedQuad-Ocean.3ds";

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

dcl_position v0
dcl_normal v1
dcl_texcoord v2
dcl_tangent v3
dcl_binormal v4

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

mov r4, v2 // output base tex coord
sub r4.y, c0.z, r4.y
mov oT4, r4

mov r0, c1.xxxx // frac(time*cloud0vel)
mul r1, c9.xyxy, r0
//frc r1.xy, r1

mul r2, c9.zwzw, r0 // frac(time*cloud0disvel)
//frc r2.xy, r2

mad oT0, r4.yx, c10.xyxy, r1.xy
mad oT1, r4.yx, c10.zwzw, r2.xy

mul r1, c11.xyxy, r0 // frac(time*cloud0vel)
//frc r1.xy, r1

mul r2, c11.zwzw, r0 // frac(time*cloud0disvel)
//frc r2.xy, r2

mad oT2, r4.yx, c12.xyxy, r1.xy
mad oT3, r4.yx, c12.zwzw, r2.xy























};

//--------------------------------------------------------------//
// Pixel Shader
//--------------------------------------------------------------//
PixelShader Reflection_Refraction_and_Water_Effects_OceanWater_ASM_Ocean_Sky_Pass_Pixel_Shader_ = asm
{

ps.1.4

texld r0, t1
texld r1, t3
texcrd r2.rgb, t0
texcrd r3.rgb, t2

mad r0.rgb, c1, r0_bx2, r2 // distort base map coords by cloud coords
mad r1.rgb, c3, r1_bx2, r3 // distort base map coords by cloud coords

phase

texld r0, r0
texld r1, r1
texld r2, t4

mov_x2 r3.rgb, r2.a // alpha of horizon
+mul_sat r3.a, 1-r0.a, 1-r1.a // mask edges for cloud glow

mad_sat r0.rgb, 1-r0.a, c2, c2.a // scale&bias invrted clouds layer 0
+mov_x2_sat r0.a, r0.a // boost cloud alpha

mad_sat r1.rgb, 1-r1.a, c4, c4.a // scale&bias invertex cloud layer 1
+mov_x2_sat r1.a, r1.a // boost cloud alpha

lrp r0.rgb, r1.a, r1, r0 // combine cloud layers
+mov r4.a, c5.a

mul_x2 r3, r3.a, r3

mad_x2 r3, r3, c5, r4.a
mul r0.rgb, r3, r0
+add_d2_sat r0.a, r0.a, r1.a

lrp_sat r0, r0.a, r0, r2













};

//--------------------------------------------------------------//
// Ocean Water Pass
//--------------------------------------------------------------//
string Reflection_Refraction_and_Water_Effects_OceanWater_ASM_Ocean_Water_Pass_Ocean_Surface : ModelData = "C:\\Program Files (x86)\\AMD\\RenderMonkey 1.82\\Examples\\Media\\Models\\OceanSurface.3ds";

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

dcl_position v0
dcl_normal v1
dcl_texcoord v2
dcl_tangent v3
dcl_binormal v4

//============================================//
// use tex coords as input to sinusoidal warp //
//============================================//
mul r0, c14, v2.x
mad r0, c15, v2.y, r0


mov r1, c16.x // time...
mad r0, r1, c13, r0 // add scaled time to move bumps according to freq
add r0, r0, c12 // starting time offset
frc r0.xy, r0 // take frac of all 4 components
frc r1.xy, r0.zwzw //
mov r0.zw, r1.xyxy //

mul r0, r0, c10.x // mul by fixup (due to inaccuracy)
sub r0, r0, c0.y // subtract 0.5
mul r0, r0, c1.w // mul tex coords by 2pi (coords range from -pi to pi)

mul r5, r0, r0 // (wave vec)^2
mul r1, r5, r0 // (wave vec)^3
mul r6, r1, r0 // (wave vec)^4
mul r2, r6, r0 // (wave vec)^5
mul r7, r2, r0 // (wave vec)^6
mul r3, r7, r0 // (wave vec)^7
mul r8, r3, r0 // (wave vec)^8

mad r4, r1, c2.y, r0 // (wave vec) ((wave vec)^3)/3!
mad r4, r2, c2.z, r4 // + ((wave vec)^5)/5!
mad r4, r3, c2.w, r4 // ((wave vec)^7/7!

mov r0, c0.z // 1
mad r5, r5, c3.x, r0 // -(wave vec)^2/2!
mad r5, r6, c3.y, r5 // +(wave vec)^4/4!
mad r5, r7, c3.z, r5 // -(wave vec)^6/6!
mad r5, r8, c3.w, r5 // +(wave vec)^8/8!

sub r0, c0.z, c0.x //... 1-wave scale
mul r4, r4, r0 // scale sin
mul r5, r5, r0 // scale cos

dp4 r0, r4, c11 // mul by wave heights

mul r0.xyz, v1, r0 // mul wave mag at this vertex by normal
add r0.xyz, r0, v0 // add to position
mov r0.w, c0.z // homogenous component

m4x4 oPos, r0, c4 // Outpos = ObjSpace * World-view-proj matrix

mul r1, r5, c11 // cos * wave height
dp4 r9.x, -r1, c14 // normal x offset
dp4 r9.yzw, -r1, c15 // normal y offset and tangent offset
mov r5, v1 // starting normal
mad r5.xy, r9, c10.y, r5 //warped normal move nx, ny according to
// cos*wavedir*waveheight
mov r4, v3 // tangent
mad r4.z, -r9.x, c10.y, r4.z // warped tangent vector

dp3 r10.x, r5, r5 // normalize the normal
rsq r10.y, r10.x
mul r5, r5, r10.y

dp3 r10.x, r4, r4 // normalize the tangent
rsq r10.y, r10.x
mul r4, r4, r10.y

mul r3, r4.yzxw, r5.zxyw // xprod to find binormal
mad r3, r4.zxyw, -r5.yzxw, r3


mov r6, c8 // get eye pos into object space
m4x4 r2, r6, c20

sub r2, r2, r0 // find view vector

dp3 r10.x, r2, r2 // normalize view vector
rsq r10.y, r10.x
mul r2, r2, r10.y

mov r0, c16.x
mul r0, r0, c18.xyxy
frc r0.xy, r0 // frac of incoming time
add r0, v2, r0 // add time to tex coords
mov oT0, r0 // output tex coords

mov r0, c16.x
mul r0, r0, c18.zwzw
frc r0.xy, r0 // frac of incoming time
add r0, v2, r0 // add time to tex coords
mov oT1, r0.yxzw // output distorted tex coord1

mov oT2, r2 // pass in view vector (world space)
mov oT3, r3 // tangent
mov oT4, r4 // binormal
mov oT5, r5 // normal










};

//--------------------------------------------------------------//
// Pixel Shader
//--------------------------------------------------------------//
PixelShader Reflection_Refraction_and_Water_Effects_OceanWater_ASM_Ocean_Water_Pass_Pixel_Shader_ = asm
{

ps.1.4

def c0, 0.5, 0.5, 0.5, 1.0

texld r0, t0 // bump map 0
texld r1, t1 // bump map 1
texcrd r2.rgb, t2 // view vec
texcrd r3.rgb, t3 // tangent
texcrd r4.rgb, t4 // binormal
texcrd r5.rgb, t5 // normal

add_d4 r0.xy, r0_bx2, r1_bx2 // scaled avg of 2 bumpmap xy offsets

mul r1.rgb, r0.x, r3 // put bump maps into world space
mad r1.rgb, r0.y, r4, r1
mad r1.rgb, r0.z, r5, r1

dp3 r0.rgb, r1, r2 // V.N
mad r2.rgb, r1, r0_x2, -r2 // R = 2N(V.N)-V

mov_sat r0.rgb, r0_x2 // 2 * V.N (sample over range of 1D map)

phase

texld r2, r2 // env map
texld r3, r0 // index frenel map using 2*N.V

mul r2.rgb, r2, r2 // square env map
+mul r2.a, r2.g, r2.g // use green of env as specular
mul r2.rgb, r2, 1-r0.r // fresnel term
+mul r2.a, r2.a, r2.a // specular ^4

add_d4_sat r2.rgb, r2, r3_x2 // += water color
+mul r2.a, r2.a, r2.a // specular ^8

mad_sat r0, r2.a, c1, r2 // += specular * specular color










};

//--------------------------------------------------------------//
// Technique Section for Reflection Refraction and Water Effects
//--------------------------------------------------------------//
technique DepthAttenuatedReflection
{
pass Normal
{
CULLMODE = CCW;

VertexShader = compile vs_1_1 Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Normal_Vertex_Shader_main();
PixelShader = compile ps_2_0 Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Normal_Pixel_Shader_main();
}

pass Reflected
<
string Script = "RenderColorTarget0 = RT_Tex;"
"ClearColor = (0, 0, 0, 0);"
"ClearDepth = 1.000000;";
>
{
CULLMODE = CW;
COLORWRITEENABLE = RED | GREEN | BLUE;

VertexShader = compile vs_1_1 Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Reflected_Vertex_Shader_main();
PixelShader = compile ps_2_0 Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Reflected_Pixel_Shader_main();
}

pass Prepare_Blur
<
string Script = "RenderColorTarget0 = Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Prepare_Blur_RT;"
"ClearColor = (0, 0, 0, 0);"
"ClearDepth = 1.000000;";
>
{
CULLMODE = CW;
COLORWRITEENABLE = ALPHA;

VertexShader = compile vs_1_1 Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Prepare_Blur_Vertex_Shader_main();
PixelShader = compile ps_2_0 Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Prepare_Blur_Pixel_Shader_main();
}

pass Depth_fade_Blur
{
CULLMODE = CCW;
COLORWRITEENABLE = RED | GREEN | BLUE | ALPHA;

VertexShader = compile vs_1_1 Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Depth_fade_Blur_Vertex_Shader_main();
PixelShader = compile ps_2_0 Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Depth_fade_Blur_Pixel_Shader_main();
}

}

technique Refraction
{
pass SceneToTexture
<
string Script = "RenderColorTarget0 = Reflection_Refraction_and_Water_Effects_Refraction_SceneToTexture_RT;"
"ClearColor = (0, 0, 0, 0);"
"ClearDepth = 1.000000;";
>
{
VertexShader = compile vs_1_1 Reflection_Refraction_and_Water_Effects_Refraction_SceneToTexture_Vertex_Shader_main();
PixelShader = compile ps_2_0 Reflection_Refraction_and_Water_Effects_Refraction_SceneToTexture_Pixel_Shader_main();
}

pass SceneToFB
{
VertexShader = compile vs_1_1 Reflection_Refraction_and_Water_Effects_Refraction_SceneToFB_Vertex_Shader_main();
PixelShader = compile ps_2_0 Reflection_Refraction_and_Water_Effects_Refraction_SceneToFB_Pixel_Shader_main();
}

pass Refraction
{
VertexShader = compile vs_1_1 Reflection_Refraction_and_Water_Effects_Refraction_Refraction_Vertex_Shader_main();
PixelShader = compile ps_2_0 Reflection_Refraction_and_Water_Effects_Refraction_Refraction_Pixel_Shader_main();
}

}

technique Ocean
{
pass Sky
{
ZENABLE = FALSE;
CULLMODE = CW;

VertexShader = compile vs_1_1 Reflection_Refraction_and_Water_Effects_Ocean_Sky_Vertex_Shader_main();
PixelShader = compile ps_2_0 Reflection_Refraction_and_Water_Effects_Ocean_Sky_Pixel_Shader_main();
}

pass Water
{
ZENABLE = TRUE;
CULLMODE = NONE;

VertexShader = compile vs_1_1 Reflection_Refraction_and_Water_Effects_Ocean_Water_Vertex_Shader_main();
PixelShader = compile ps_2_0 Reflection_Refraction_and_Water_Effects_Ocean_Water_Pixel_Shader_main();
}

}

technique OceanWater_ASM
{
pass Ocean_Sky_Pass
{
FILLMODE = SOLID;
ZWRITEENABLE = FALSE;
CULLMODE = CW;
ZFUNC = ALWAYS;

VertexShader = (Reflection_Refraction_and_Water_Effects_OceanWater_ASM_Ocean_Sky_Pass_Vertex_Shader_);
PixelShader = (Reflection_Refraction_and_Water_Effects_OceanWater_ASM_Ocean_Sky_Pass_Pixel_Shader_);
}

pass Ocean_Water_Pass
{
FILLMODE = SOLID;
ZWRITEENABLE = TRUE;
CULLMODE = NONE;
ZFUNC = LESS;

VertexShader = (Reflection_Refraction_and_Water_Effects_OceanWater_ASM_Ocean_Water_Pass_Vertex_Shader_);
PixelShader = (Reflection_Refraction_and_Water_Effects_OceanWater_ASM_Ocean_Water_Pass_Pixel_Shader_);
}

}
[/source]

The function that draws the object:
[source lang="csharp"]protected void DrawModelWaterShader(Model model, Matrix worldMatrix, GameTime gameTime)
{
ModelMesh mesh = model.Meshes[0];
ModelMeshPart meshPart = mesh.MeshParts[0];

// Set parameters
time.SetValue(totalTime);
viewPos.SetValue(new Vector4(cameraPosition,0));
viewMat.SetValue(viewMatrix);
projMat.SetValue(projectionMatrix);

FSBump.SetValue(Content.Load<Texture2D>("FieldstoneBumpDOT3"));
FSBase.SetValue(Content.Load<Texture2D>("Fieldstone"));
Wood.SetValue(Content.Load<Texture2D>("Wood"));
Noise.SetValue(Content.Load<Texture3D>("NoiseVolume"));
Sky.SetValue(Content.Load<Texture2D>("Wood"));

waveSpeed.SetValue(0.34f);
fadeExp.SetValue(6.08f);
fadeBias.SetValue(0.3f);
noiseSpeed.SetValue(0.18f);
scale.SetValue(new Vector4(0.01001f,0.00554f,0.01f,1.0f));
WColor.SetValue(new Vector4(0.195489f,0.345865f,0.68421f,1f));


//set the vertex source to the mesh's vertex buffer
graphics.GraphicsDevice.SetVertexBuffer(meshPart.VertexBuffer, meshPart.VertexOffset);

//set the current index buffer to the sample mesh's index buffer
graphics.GraphicsDevice.Indices = meshPart.IndexBuffer;


effect.CurrentTechnique = effect.Techniques["OceanWater_ASM"];

for (int i = 0; i < effect.CurrentTechnique.Passes.Count; i++)
{
//EffectPass.Apply will update the device to
//begin using the state information defined in the current pass
effect.CurrentTechnique.Passes.Apply();

//theMesh contains all of the information required to draw
//the current mesh

//Error HERE, so something is set up strangely in the shader :S
graphics.GraphicsDevice.DrawIndexedPrimitives(
PrimitiveType.TriangleList, 0, 0,
meshPart.NumVertices, meshPart.StartIndex, meshPart.PrimitiveCount);
}
}[/source]
In case you wonder where i got the values from, they were copied from what i could see they were sat to in RenderMonkey
Advertisement
Bump, i have been looking it over, and i have inverted the matrixes, and changed the matrixes from left hand, to right-hand mode. It did work so that now other things doesn't draw black, if drawed before, but the problem of the object being invisible, still persists...
You realise that this isn't valid HLSL code right:

string Reflection_Refraction_and_Water_Effects_DepthAttenuatedReflection_Normal_Skull : ModelData = "C:\\Program Files (x86)\\AMD\\RenderMonkey 1.82\\Examples\\Media\\Models\\Skull.3ds";

float4x4 view_proj_matrix : ViewProjection;
float4x4 view_matrix : View;
float height
<
string UIName = "height";
string UIWidget = "Numeric";
bool UIVisible = true;
float UIMin = 0.00;
float UIMax = 200.00;
> = float( 96.00 );
float objectScale
<
string UIName = "objectScale";
string UIWidget = "Numeric";
bool UIVisible = true;
float UIMin = 0.00;
float UIMax = 10.00;
> = float( 2.00 );


The UI named elements all refer to rendermonkey specifics.

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion

Yes, i realized that, but i read somewhere else, that while it was a good idea to clean it up, it shouldn't be a problem to leave it there at first. And i do set those attributes manually. I'll try to clean it up though, and see if that helps ^^

Edit: Nope, that didn't seem to help. But thanks for at least pointing it out!
Where are all the variables coming from that you are calling "SetValue" on? Can you also print the error please as I am having to do psychic debugging here and that's not really one of my Super Powers.

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion

There are no errors whatsoever, the object just doesn't get rendered :(

I can post the set value variables, sorry about that:

[source lang="java"]public void SetupRealOceanShaderParameters()
{
// Bind the parameters with the shader.
time = effect.Parameters["time_0_X"];
viewPos = effect.Parameters["view_position"];
viewMat = effect.Parameters["view_matrix"];
projMat = effect.Parameters["view_proj_matrix"];

FSBump = effect.Parameters["Fieldstone_Bump_Tex"];
FSBase = effect.Parameters["Fieldstone_Base_Tex"];
Wood = effect.Parameters["Wood_Tex"];
Noise = effect.Parameters["Noise_Tex"];
Sky = effect.Parameters["skyBox_Tex"];

waveSpeed = effect.Parameters["waveSpeed"];
fadeExp = effect.Parameters["fadeExp"];
fadeBias = effect.Parameters["fadeBias"];
noiseSpeed = effect.Parameters["noiseSpeed"];
scale = effect.Parameters["scale"];
WColor = effect.Parameters["waterColor"];
}[/source]

The function is called from the LoadContent function.

This topic is closed to new replies.

Advertisement